0
sql="select %s,tablename from pg_table_def where tablename like (%s)"

data=("schemaname","abc",)

cur.execute(sql,data)

If I pass a value as described above, then the select takes it as a string. Which is not the intention.

If I try

data=(schemaname,"abc",)

then it shows the error global name 'schemaname' is not defined.

1 Answer 1

2

You cannot parameterize object name (in this case, a column name) that way. You could instead resort to string manipulation:

column = "schemaname"
sql = "select {}, tablename from pg_table_def where tablename like (%s)".format(column) 
data= ("abc",)

cur.execute(sql,data)
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.