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 1nVcyW-00034j-Me for psycopg@arkaria.postgresql.org; Sat, 19 Mar 2022 17:34:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nVcyU-0004pb-5D for psycopg@arkaria.postgresql.org; Sat, 19 Mar 2022 17:34:46 +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 1nVcyS-0004pQ-M9 for psycopg@lists.postgresql.org; Sat, 19 Mar 2022 17:34:45 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nVcyK-00021u-Q4 for psycopg@postgresql.org; Sat, 19 Mar 2022 17:34:44 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 7D1225C00BE; Sat, 19 Mar 2022 13:34:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 19 Mar 2022 13:34:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; bh=+E+Tr3oSpl3Dei 2TYCftvFeQxZ0LnAYlhyQP+LYOPMI=; b=yd5Q3ygZ5pxcyFsi2dqcHEns6XwxyR NCMU1HrK9pPkP5MGbAtwkslU4E0+OniStPEGCUgILn9k4b1Q901v5m37X1ZX86P5 StJBNHR3s/cPFLA7JltnViz+dxuyjwtMV62LO1DuFMa5/QCLou0My8No5LStBXDw bFws9pS/Ey/H9DSvUNLwXAppcXNNt4OCfgY0bJHshcWgvIplSOqAP7H0ABGuoIl8 3FX7SvPMcBu+il4luWu+xo69sKeB5wUNvdF1Fq8RNGZMoVorBkOBnIR+hquL3Fiu LhlfRZhI2Pf6TBao3apaOG3VP+fNmusgTs2AC2w8SwxPdd9B6OMrcd0g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=+E+Tr3oSpl3Dei2TYCftvFeQxZ0LnAYlhyQP+LYOP MI=; b=TNpdXIZ9diFMT+3zpzNYPkoqAKS9tnhb0UqjylY3rU3YmY0ihiQWDzE1K MWcvr+0RZOZIS5LkC2XxGchgAd8hY12jctkqJzfpFJ9c1sfSjB+2rNLfbiDG5FD8 8x/TitLlSsHs81ZyndMw0h+84qOKy813vmn8ku2W1eeQc9J1Q19B0cpXyktt7EWh XFkobYyqWqkXtOVPbCXfs4loLLyiLBGOo7To1macen5iNw/4GhBPoTP3cBCDbMrJ vvOEmZZ24QVaia018DJOMfOOo1KWxOBUnZJ7kTZvowCmtdt8KBA5w24/Hg67yRSn 8Kvbokn9cyJIVy7go/aG8oiGadwEA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudefkedguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepudfgueelgeevfffhgeeljeehhfettdegieelgefg heefffefveegjedtueetffdtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 19 Mar 2022 13:34:33 -0400 (EDT) Message-ID: <321f190b-d65d-d2f7-d5bb-2ce72aa0b70d@aklaver.com> Date: Sat, 19 Mar 2022 10:34:32 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: Query with boolean parameter Content-Language: en-US To: Paolo De Stefani , Christophe Pettus Cc: Psycopg References: <8df15d1263aaa1a9d36eacb0e5b9a28e@paolodestefani.it> <74FC637F-2D25-4CD0-A075-9CB5293FCA5B@thebuild.com> From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/19/22 05:10, Paolo De Stefani wrote: > Il 19/03/2022 01:00 Christophe Pettus ha scritto: >>> On Mar 18, 2022, at 16:56, Paolo De Stefani >>> wrote: >>> Is there any reason why the second query results in a syntax error? >> >> There's not IS operator in PostgreSQL (or in SQL).  IS NULL, IS NOT >> NULL, IS TRUE, and IS FALSE are in effect unary postfix operators, so >> you can't construct them that way via parameter substitution. > > Thanks, i see > > The problem is (for me) that with psycopg2 this works: > cur.execute('SELECT * FROM system.app_user WHERE can_edit_views IS TRUE') > cur.execute('SELECT * FROM system.app_user WHERE can_edit_views IS %s', > (True,)) > cur.execute('SELECT * FROM system.app_user WHERE can_edit_views IS %s', > (None,)) The only way I could get it to work: cur.execute(sql.SQL("select 'f' IS {}").format(sql.SQL('TRUE'))) or cur.execute(sql.SQL("select 'f' IS {}").format(sql.SQL(str(True)))) cur.fetchone() (False,) cur.execute(sql.SQL("select 'f' IS {}").format(sql.SQL('NULL'))) cur.fetchone() (False,) > > Switching to psycopg 3 i have to consider many more differences than i > expected > -- Adrian Klaver adrian.klaver@aklaver.com