I have a python list of values and a postgresql table with a certain column in it. I'd like to know for each element in my python list whether there is any row in the table with that ID.
For example, suppose I have this python list:
vals = [4, 8, 15, 16, 23, 42]
and also that the query:
select my_col from my_table;
gives:
[4, 5, 6, 7, 8]
Then I'd like a query that returns:
[True, True, False, False, False, False]
I could loop through the list and execute a new "select exists" for each value, but I wondered if there was a way to do it in a single call?
I am restricted to postgresql 9.0
select
? One to make that result into sets
, then just[x in s for x in vals]
? – Alex Martelli Jan 8 at 17:48