I want to execute this sql via psyopg2:
select indexname from pg_indexes where (tablename, indexname) in (
('tab1', 'index1'),
('tab2', 'index2')
);
Here is the code:
cursor.execute(
'select tablename, indexname from pg_indexes where (tablename, indexname) IN %s;', [
[('tab1', 'col1'), ('tab2', 'col2')],
])
I get this exception:
ProgrammingError: syntax error at or near "ARRAY"
LINE 1: ...e from pg_indexes where (tablename, indexname) IN ARRAY[('ta...
How to pass a list of tuples to PostgreSQL vis psyopg2?
If you pass a tuple instead a list, it works:
cursor.execute(
'select tablename, indexname from pg_indexes where (tablename, indexname) IN %s;', [
tuple([('tab1', 'col1'), ('tab2', 'col2')]),
])
Don't ask my why it fails if you pass a list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With