In my flask app I am trying to pass a string to the query below:
tag = "Abcd"
conn = get_db_connection()
cur = conn.cursor()
cur.execute("SELECT * FROM database WHERE message LIKE %s ESCAPE ''", (tag,))
data = cur.fetchall()
cur.close()
conn.close()
I receive blank result.
I use psycopg2. My Postgres database has message containing "Abcd"
and it works fine if I simply do:
cur.execute("SELECT * FROM database WHERE message LIKE '%Abcd%'")
If I try to pass it as a variable "tag"
is my syntax for LIKE
query correct?