Re: psycopg3 - parameters cannot be used for DDL commands?

From: Dmitry Igrishin <dmitigr(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Les <nagylzs(at)gmail(dot)com>, pgsql-interfaces(at)lists(dot)postgresql(dot)org
Subject: Re: psycopg3 - parameters cannot be used for DDL commands?
Date: 2022-01-05 17:20:36
Message-ID: CAAfz9KNgYfJhHL5NKS1frPDo286sn-c0PNA6ZOF81f5TBByc=A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

ср, 5 янв. 2022 г. в 20:07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>
> Les <nagylzs(at)gmail(dot)com> writes:
> > 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
>
> Yeah, as a general rule parameters can only be used in DML commands
> (SELECT/INSERT/UPDATE/DELETE). Utility commands don't support them
> because they don't have expression-evaluation capability.
>
> (Perhaps this will change someday, but don't hold your breath.)
>
> > 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?
>
> Most client libraries should have a function to convert an arbitrary
> string into a safely-quoted SQL literal that you can embed into the
> command. I don't know psycopg3, so I don't know what it has for that.
My C++ library, - Pgfe, - can convert any named parameter into an
arbitrary part of SQL expression by using Sql_string::replace()
method. For example:
update :foo
could be replaced to
update foo set bar = 'baz' where id = 1
by using
s.replace("foo", R"(set bar='baz' where id = 1)").

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Les 2022-01-05 17:28:37 Re: psycopg3 - parameters cannot be used for DDL commands?
Previous Message Les 2022-01-05 17:19:12 Re: psycopg3 - parameters cannot be used for DDL commands?