[DB-SIG] intent of "numeric" paramstyle, wrt actual numbers not numerically ordered?
Tony Locke
tlocke at tlocke.org.uk
Sun Dec 11 05:17:08 EST 2022
Sorry I'm a bit late to all of this. Here's what pg8000 does, together with
what it sends to PostgreSQL:
cursor.execute("SELECT :1, :2", (6, 0))
# Sent to server: "SELECT $1, $2"
# Result: ['6', '0']
cursor.execute("SELECT :2, :1", (6, 0))
# Sent to server: "SELECT $2, $1"
# Result: ['0', '6']
So the driver pg8000 just replaces ':' with '$' and sends it to the server,
and the server uses each numeric as an index into the parameter list, and
ignores the order in which the placeholders appear in the statement.
On Fri, 2 Dec 2022 at 17:57, Marc-Andre Lemburg <mal at egenix.com> wrote:
> On 02.12.2022 18:32, John Stevenson - BGS wrote:
>
> The documents officially state “named” as the paramstyle, but with
> cx_Oracle we often use the numeric style with executemany so that we can
> insert from lists of tuples. In this context, the useful “feature” of the
> numeric paramstyle is that you don’t need to transform your data into a
> dictionary.
>
>
>
>
> https://cx-oracle.readthedocs.io/en/latest/api_manual/module.html#cx_Oracle.paramstyle
>
>
>
> I haven’t tried binding the same value multiple times or using the
> placeholders in different orders, though.
>
> cx_Oracle seems to use "named" style, but simply binds by position when
> passing in a tuple instead of a dictionary (or keyword args). At least
> that's what the docs suggest:
>
> https://cx-oracle.readthedocs.io/en/latest/user_guide/bind.html
>
> I suppose that using "where a=:2 and b=:1" would still bind the first
> parameter value to "a" and the second to "b".
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Experts (#1, Dec 02 2022)
> >>> Python Projects, Coaching and Support ... https://www.egenix.com/
> >>> Python Product Development ... https://consulting.egenix.com/
> ________________________________________________________________________
>
> ::: We implement business ideas - efficiently in both time and costs :::
>
> eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
> D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
> Registered at Amtsgericht Duesseldorf: HRB 46611
> https://www.egenix.com/company/contact/
> https://www.malemburg.com/
>
> _______________________________________________
> DB-SIG maillist - DB-SIG at python.org
> https://mail.python.org/mailman/listinfo/db-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/db-sig/attachments/20221211/a0252edc/attachment.html>
More information about the DB-SIG
mailing list