Skip to content

Recommended workaround for () in a named parameter? #1612

Closed Answered by dvarrazzo
polynomialherder asked this question in Q&A
Discussion options

You must be logged in to vote

Psycopg doesn't put any constraint in the column names: brackets or any other character in column names is supported. It is true that Postgres doesn't offer limitation in column names, but it does with parameters: should you ever write queries in pure postgres parametric functions you could only use numbers as parameters ($1, $2, etc). Parameters substitution is a language inside the language and has its own limitations which are not related to the outermost one.

Query parameters in psycopg2 have their language, which is the one of Python string formatting: the limitation comes from there.

>>> "%(foo()s" % {"foo(": 10}
Traceback (most recent call last):
  File "<stdin>", line 1, in <modul…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@polynomialherder
Comment options

@dvarrazzo
Comment options

@polynomialherder
Comment options

@dvarrazzo
Comment options

Answer selected by polynomialherder
@polynomialherder
Comment options

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