I'm trying to use psycopg2.sql.SQL to compose my query. I've referred to the docs but I'm unable to get this to execute. I keep getting the above programming error
Here's the example code:
import psycopg2.sql as sql
query = sql.SQL("SELECT id from {} where country={}".format(sql.Identifier('country_sector'), sql.Identifier('UK')))
cur = dbobj.conn.cursor()
cur.execute(query)
data = cur.fetchall()
And here is the error:
ProgrammingError: function identifier(unknown) does not exist
LINE 1: SELECT id from Identifier('country_sector') where country=Id...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
This suggests to me that I need to install some extension in postgres but a lot of googling has not helped.
Any advice much appreciated.
Identifier('country_sector')? What do you get?import psycopg2.sql as sqltoimport psycopg2 as sqlfrom psycopg2 import sqland you are usingimport psycopg2.sql as sqlThat is not the same Try to rewrite that part exactly as the documentation says.