I’m new to Python and Psycopg2… I’am trying to do a query that uses IN sql statement and other WHERE clauses but I’m getting an error like this:
psycopg2.ProgrammingError: argument formats can't be mixed
From what I understand I’m mixing a Python tuple with strings, here is the SELECT statement:
cur2.execute("SELECT hash FROM jobsads_text\
WHERE\
date_inserted::timestamp::date - now()::timestamp::date <= 0\
AND date_inserted::timestamp::date - now()::timestamp::date >= -7\
AND hash NOT IN %s \
AND lower((%s)) LIKE '%(%s)%'\
ORDER BY date_inserted asc;", ((not_in_sql,), search_field, search_string))
I get error in the query above.
This query bellow runs OK:
cur2.execute("SELECT hash FROM jobsads_text\
WHERE\
date_inserted::timestamp::date - now()::timestamp::date <= 0\
AND date_inserted::timestamp::date - now()::timestamp::date >= -7\
AND hash NOT IN %s \
ORDER BY date_inserted asc;", (not_in_sql,))
My question is… How can I mix the tuple not_in_sql with the strings search_field and search_string?
Any clues?
Best Regards,
Will output this:
psycopg2 will not substitute identifiers like column names so you must substitute then before passing the query as the first argument of the method.