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 1jdaGo-0003uz-UG for psycopg@arkaria.postgresql.org; Tue, 26 May 2020 14:09:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jdaGn-0000hr-Te for psycopg@arkaria.postgresql.org; Tue, 26 May 2020 14:09:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jdaGn-0000hg-Em for psycopg@lists.postgresql.org; Tue, 26 May 2020 14:09:29 +0000 Received: from campbell-lange.net ([178.79.140.51]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jdaGk-0006Su-PY for psycopg@postgresql.org; Tue, 26 May 2020 14:09:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=campbell-lange.net; s=it; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qETXtLqMmTlop8uAL0F4xITolOHvIawpXAE0ey8W2Pc=; b=u0Dyi9kzLTCWFjgm1spnpGTni d/wh7WxCJHgBr4eoBXMftRRThN4gbKcFsqp5Ypge0brI8Gc2G28x0yJ+NDAGayR8NZXLj5LtZh44e EKlEtY25Tr5Q1fzOLBdpZ0U4w+mgD8BL2aWf5okV2U+Jtm6RkXR1rSYgu9YmRHVK1+1rs=; Received: from [217.138.52.158] (helo=rory-t450s) by campbell-lange.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jdaGj-0005Qv-3H; Tue, 26 May 2020 14:09:25 +0000 Received: from rory by rory-t450s with local (Exim 4.92) (envelope-from ) id 1jdaGu-0007QW-8L; Tue, 26 May 2020 15:09:36 +0100 Date: Tue, 26 May 2020 15:09:36 +0100 From: Rory Campbell-Lange To: Frank Millman Cc: psycopg@postgresql.org Subject: Re: Minor issue Message-ID: <20200526140936.GA28120@campbell-lange.net> References: <92a25cd6-5b50-3074-0da6-7394db9e0f0a@chagford.com> <3f076465-0e4f-ff6b-6a7b-51ba7daf3bc3@chagford.com> <20200526130801.GA23081@campbell-lange.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 26/05/20, Frank Millman (frank@chagford.com) wrote: > > > On 2020-05-26 3:08 PM, Rory Campbell-Lange wrote: > > On 26/05/20, Frank Millman (frank@chagford.com) wrote: > > 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. That makes sense, apologies. However, this works as you suggest: In [33]: d.query(""" ...: select ...: 1 as a ...: /* ...: ,2 as b ...: */ ...: -- ,'hi' as c ...: -- ,%s as d ...: """, ("a string", )).results Out[33]: [Record(a=1)] This doesn't work (as you suggest): In [35]: d.query(""" ...: select ...: 1 as a ...: /* ...: ,2 as b ...: */ ...: -- ,'hi' as c ...: -- ,%s as d ...: """, ()).results ERROR:root:An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line string', (1, 0)) But this works: In [34]: d.query(""" ...: select ...: 1 as a ...: /* ...: ,2 as b ...: */ ...: -- ,'hi' as c ...: -- ,%s as d ...: """).results Out[34]: [Record(a=1)] So perhaps simply don't provide the tuple in this case? This will also probably work for your other backends. Rory