I'm trying to select specific dates from a PostgreSQL table with the following function:
cur.execute(""" SELECT * FROM posting_log WHERE hol_date = {}""".format(condition))
When I run this, however, I receive the following trace:
psycopg2.ProgrammingError: operator does not exist: date = integer
LINE 1: SELECT * FROM posting_log WHERE hol_date = 2018-10-10
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
The function is clearly picking up the date I want to check for, however thinks it's an integer and is unable to convert it to date format. What can I do to solve this?
I've tried the following solutions provided by this answer, however that simply throws an error saying the functions date and to_date do not exist:
SELECT date(condition::TEXT)
SELECT to_date(condition::text, 'YYYY-MM-DD')