psycopg3 - parameters cannot be used for DDL commands?

From: Les <nagylzs(at)gmail(dot)com>
To: pgsql-interfaces(at)lists(dot)postgresql(dot)org
Subject: psycopg3 - parameters cannot be used for DDL commands?
Date: 2022-01-05 16:42:31
Message-ID: CAKXe9UDix+STcO8akzNNhjS4tEZd7xs203XNn72G35ELm81=WQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Example:

Traceback (most recent call last):
File "/usr/sbin/prepare_postgres", line 46, in <module>
pg_exec_postgres("ALTER USER postgres WITH PASSWORD %s",
[POSTGRES_PASSWORD])
File "/opt/util.py", line 101, in pg_exec_postgres
return pg_conn_postgres().execute(*args, **kwargs)
File "/usr/local/lib/python3.9/dist-packages/psycopg/connection.py", line
722, in execute
raise ex.with_traceback(None)
psycopg.errors.SyntaxError: syntax error at or near "$1"
LINE 1: ALTER USER postgres WITH PASSWORD $1
^
PostgreSQL server log:

2022-01-05 17:35:25.831 CET [58] ERROR: syntax error at or near "$1" at
character 35
2022-01-05 17:35:25.831 CET [58] STATEMENT: ALTER USER postgres WITH
PASSWORD $1

Passwords can also contain special characters. If I can't use parameters to
do this, then how should I quote them in a safe way?

Thank you,

Laszlo

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 2022-01-05 17:07:47 Re: psycopg3 - parameters cannot be used for DDL commands?
Previous Message Dave Cramer 2021-11-25 11:03:14 Re: PostgreSQL XA resource manager for C/C++ apps