Re: Minor issue - Mailing list psycopg

From Frank Millman
Subject Re: Minor issue
Date
Msg-id cd80d720-4616-c409-dab2-ba835f706581@chagford.com
Whole thread Raw
In response to Re: Minor issue  (Rory Campbell-Lange <rory@campbell-lange.net>)
Responses Re: Minor issue  (Rory Campbell-Lange <rory@campbell-lange.net>)
List psycopg

On 2020-05-26 3:08 PM, Rory Campbell-Lange wrote:
> On 26/05/20, Frank Millman (frank@chagford.com) wrote:
>> On 2020-05-26 2:11 PM, Daniele Varrazzo wrote:
>>> No, we don't want to add any intelligence in trying to figure out what
>>> is into a query. If you are comfortable that you will be using always
>>> the same pattern for comments you can easily clean the string yourself
>>> before passing it to psycopg.
>>>
>>> A better approach for you I guess would be to use named placeholders,
>>> so that an a missing placeholder wouldn't require you to change the
>>> arguments to execute.
> 
>> Ok, thanks.
>>
>> Frank
> 
> I must be missing something, because this works for me:
> 
>      In [28]: d.query("""
>          ...: select
>          ...:     1 as a
>          ...:     /*
>          ...:     ,2 as b
>          ...:     */
>          ...:     -- ,'hi' as c
>          ...:     ,%s as d
>          ...: """, ("a string", )).results
>      Out[28]: [Record(a=1, d='a string')]
> 
> (d.query is a wrapper around cursor_create, execute and fetchall).
> 
> Does using %s instead of {}.format help solve the issue?
> 

To reproduce my situation, you should place the '--' at the beginning of 
the following line (',%s as d').

As no parameters are now being substituted, I would expect to supply an 
empty tuple. In fact, the parameter is still required.

Frank



psycopg by date:

Previous
From: Rory Campbell-Lange
Date:
Subject: Re: Minor issue
Next
From: Daniele Varrazzo
Date:
Subject: Async notifications in psycopg3