1

I am using psycopg2 and how can I delete rows that are older than a certain date? For example:

cursor.execute('DELETE FROM datatable WHERE date < %s', datetime.date(2012, 1, 1))

If I write like this, there will be TypeError: 'datetime.date' object does not support indexing. How can I do with it? Thanks!

1 Answer 1

3

Pass the second argument as a list or a tuple:

cursor.execute('DELETE FROM datatable WHERE date < %s', [datetime.date(2012, 1, 1)])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.