[DB-SIG] intent of "numeric" paramstyle, wrt actual numbers not numerically ordered?

Marc-Andre Lemburg mal at egenix.com
Tue Dec 13 04:38:19 EST 2022


On 11.12.2022 11:17, Tony Locke wrote:
> 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.

Thanks for the added insight. The above is what we had in mind with
the numeric binding type, even though it is not explicitly spelled
out in PEP 249.

Perhaps I ought to add a footnote to the PEP to explain the mode
in more detail.

> On Fri, 2 Dec 2022 at 17:57, Marc-Andre Lemburg <mal at egenix.com 
> <mailto: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 <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
>     <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/  <https://www.egenix.com/>
>     >>> Python Product Development ...        https://consulting.egenix.com/  <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.egenix.com/company/contact/>
>                           https://www.malemburg.com/  <https://www.malemburg.com/>
> 
>     _______________________________________________
>     DB-SIG maillist  - DB-SIG at python.org <mailto:DB-SIG at python.org>
>     https://mail.python.org/mailman/listinfo/db-sig
>     <https://mail.python.org/mailman/listinfo/db-sig>
> 
> 
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> https://mail.python.org/mailman/listinfo/db-sig

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Dec 13 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/



More information about the DB-SIG mailing list