public inbox for [email protected]  
help / color / mirror / Atom feed
From: Frank Millman <[email protected]>
To: [email protected]
Subject: Re: Minor issue
Date: Tue, 26 May 2020 15:16:03 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<CA+mi_8YDBvXkns7odQQ5VLATyCXe2xFTw_KV5H19Q9aTyWEEog@mail.gmail.com>
	<[email protected]>
	<[email protected]>



On 2020-05-26 3:08 PM, Rory Campbell-Lange wrote:
> On 26/05/20, Frank Millman ([email protected]) 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





view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Minor issue
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox