This works fine:
cc.execute("select * from books where name like '%oo%'")
But if second argument passed:
cursor.execute("select * from books where name like '%oo%' OFFSET % LIMIT %", (0,1))
Psycopg errors:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
How to avoid this error?
First of all, you should use %%
to insert %
literal, otherwise, library will try to use all %
as placeholders. Second, it's better to specify %s
, where you want to insert values.
So, your code should look like:
cursor.execute("select * from books where name like '%%oo%%' OFFSET %s LIMIT %s", (0,1))
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