| From: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> |
|---|---|
| To: | Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com> |
| Cc: | "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org> |
| Subject: | Re: Solving the SQL composition problem |
| Date: | 2017-01-03 16:33:56 |
| Message-ID: | CA+mi_8buw9cHkM5SdKBMJkG9+b-JYHHfHHGL4Qn2FrJj=trMRw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | psycopg |
On Mon, Jan 2, 2017 at 5:21 PM, Daniele Varrazzo
<daniele(dot)varrazzo(at)gmail(dot)com> wrote:
>
> A natural choice could be to use the str.format syntax for the query
> composition, or a subset of it. Hence my example could be:
>
> cur.execute(
> sql.SQL("insert into {} values (%s,
> %s)").format(sql.Identifier('my_table')),
> [10, 20])
That's now implemented in the branch; docs updated too:
http://initd.org/psycopg/docs/sql.html. In particular see
http://initd.org/psycopg/docs/sql.html#psycopg2.sql.SQL.format which
replaces the previous SQL % operator (no more supported). It is no
more necessary to specify value placeholders as %%s so it's easier to
switch between constant and parametrized queries.
-- Daniele
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Christophe Pettus | 2017-01-03 16:35:50 | Re: Solving the SQL composition problem |
| Previous Message | Jim Nasby | 2017-01-03 16:24:50 | Re: Solving the SQL composition problem |