Skip to content

Pass dynamic field name to query #803

Answered by Nothing4You
anselal asked this question in Q&A
Discussion options

You must be logged in to vote

values are escaped before being passed to the server as strings:

cursor.mogrify("INSERT INTO logs (id, %s) VALUES (%s, %s)", ('field_name', 'foo', 'bar'))
INSERT INTO logs (id, 'field_name') VALUES ('foo', 'bar')

therefore you can't pass column names as args.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@anselal
Comment options

@Nothing4You
Comment options

@anselal
Comment options

Answer selected by Nothing4You
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants