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 1jdZJI-0001Jr-Ph for psycopg@arkaria.postgresql.org; Tue, 26 May 2020 13:08:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jdZJH-0004XU-NV for psycopg@arkaria.postgresql.org; Tue, 26 May 2020 13:07:59 +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 1jdZJH-0004XN-F3 for psycopg@lists.postgresql.org; Tue, 26 May 2020 13:07:59 +0000 Received: from campbell-lange.net ([178.79.140.51]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jdZJA-0003Qp-FH for psycopg@postgresql.org; Tue, 26 May 2020 13:07:58 +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=4myRdewie9MCpkHLkpSCtooq+HUmN8MGpOHEosKRgps=; b=Cj2ETdKpi1SwhobQcnrA3Paud 4KDBMZA+1SgWl9Ql0u3WVTGWVYPtF4/nSos5CLFGTTwNLAFSVpuZLX7440NAMQM7huIld+d/EU5oU 0JB7KLGrVQXtnfVZ/evFOe+IjJGpBFLiR62bJNT4wLLg1nLMEsUjyZqsjFT0/mc3YxtdM=; 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 1jdZJ8-0005GO-10; Tue, 26 May 2020 13:07:50 +0000 Received: from rory by rory-t450s with local (Exim 4.92) (envelope-from ) id 1jdZJJ-0006tf-6A; Tue, 26 May 2020 14:08:01 +0100 Date: Tue, 26 May 2020 14:08:01 +0100 From: Rory Campbell-Lange To: Frank Millman Cc: psycopg@postgresql.org Subject: Re: Minor issue Message-ID: <20200526130801.GA23081@campbell-lange.net> References: <92a25cd6-5b50-3074-0da6-7394db9e0f0a@chagford.com> <3f076465-0e4f-ff6b-6a7b-51ba7daf3bc3@chagford.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3f076465-0e4f-ff6b-6a7b-51ba7daf3bc3@chagford.com> 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 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?