postgresql - Select values from a list that aren't in a table? -


i'd following; what's easiest way?

select id (1,2,3) id not in (select id table) 

the idea not increase memory usage of python script loading table ids script first. way can think of build temporary table using query, little verbose.

select id (values (1),(2),(3)) s(id) except select id table 

to psycopg:

id_list = ['1','2','3'] q = """     select array_agg(id)     (         select id (values {}) s(id)         except         select id table     ) t; """.format(','.join(['%s'] * len(id_list)))  print cur.mogrify(q, [(id,) id in id_list]) # cur.execute(q, [(id,) id in id_list]) 

output:

select array_agg(id) (     select id (values ('1'),('2'),('3')) s(id)     except     select id table ) t; 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -