Re: Minor issue

From: Frank Millman <frank(at)chagford(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Re: Minor issue
Date: 2020-05-26 13:16:03
Message-ID: cd80d720-4616-c409-dab2-ba835f706581@chagford.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 2020-05-26 3:08 PM, Rory Campbell-Lange wrote:
> On 26/05/20, Frank Millman (frank(at)chagford(dot)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

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2020-05-26 13:22:15 Async notifications in psycopg3
Previous Message Rory Campbell-Lange 2020-05-26 13:08:01 Re: Minor issue