Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jdZRW-0001gb-67 for psycopg@arkaria.postgresql.org; Tue, 26 May 2020 13:16:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jdZRV-0002b0-43 for psycopg@arkaria.postgresql.org; Tue, 26 May 2020 13:16:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jdZRU-0002al-VD for psycopg@lists.postgresql.org; Tue, 26 May 2020 13:16:28 +0000 Received: from securemail-y9.synaq.com ([196.35.198.49]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jdZRR-0003Ve-Hw for psycopg@postgresql.org; Tue, 26 May 2020 13:16:27 +0000 Received: from [197.90.32.26] (helo=[192.168.0.8]) by securemail-pl-omx1.synaq.com with esmtpa (Exim 4.92.3) (envelope-from ) id 1jdZRE-0005bQ-9j for psycopg@postgresql.org; Tue, 26 May 2020 15:16:12 +0200 Subject: Re: Minor issue To: psycopg@postgresql.org References: <92a25cd6-5b50-3074-0da6-7394db9e0f0a@chagford.com> <3f076465-0e4f-ff6b-6a7b-51ba7daf3bc3@chagford.com> <20200526130801.GA23081@campbell-lange.net> From: Frank Millman Message-ID: Date: Tue, 26 May 2020 15:16:03 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <20200526130801.GA23081@campbell-lange.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-SYNAQ-Pinpoint-Information: Please contact SYNAQ for more information X-SYNAQ-Pinpoint-ID: 1jdZRE-0005bQ-9j X-SYNAQ-Pinpoint: Found to be clean X-SYNAQ-Pinpoint-SpamCheck: not spam, SpamAssassin (not cached, score=-1.1, required 9, autolearn=disabled, ALL_TRUSTED -1.00, DCC_REPUT_13_19 -0.10) X-Pinpoint-From: frank@chagford.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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