From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>, 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-05 18:59:54 |
Message-ID: | 505016e3-af5a-82e7-8e2d-095840b6bc98@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
On 01/03/2017 08:33 AM, Daniele Varrazzo wrote:
> 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.
Not sure it applies here, but I just ran across a blog from Armin
Ronacher. I don't always understand what he says, in this case I think I
do and it might be worth a look:
http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/
>
> -- Daniele
>
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Daniele Varrazzo | 2017-01-05 19:00:28 | Re: speed concerns with executemany() |
Previous Message | Federico Di Gregorio | 2017-01-05 17:32:18 | Re: speed concerns with executemany() |