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 1nVemk-0000Hk-14 for psycopg@arkaria.postgresql.org; Sat, 19 Mar 2022 19:30:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nVemi-0004Z7-UK for psycopg@arkaria.postgresql.org; Sat, 19 Mar 2022 19:30:44 +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 1nVemi-0004Yy-7j for psycopg@lists.postgresql.org; Sat, 19 Mar 2022 19:30:44 +0000 Received: from hedgehog.birch.relay.mailchannels.net ([23.83.209.81]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nVemb-0000dG-AZ for psycopg@postgresql.org; Sat, 19 Mar 2022 19:30:43 +0000 X-Sender-Id: cp7oy65bvo|x-authuser|paolo@paolodestefani.it Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 8529786192D; Sat, 19 Mar 2022 19:30:35 +0000 (UTC) Received: from lu-shared04.cpanelplatform.com (unknown [127.0.0.6]) (Authenticated sender: cp7oy65bvo) by relay.mailchannels.net (Postfix) with ESMTPA id 36CAD861AB5; Sat, 19 Mar 2022 19:30:34 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1647718234; a=rsa-sha256; cv=none; b=Rkd+GB2ON7aYDi2yoJadtWKPZF1DDfS8JPRGAJ84c9+j6hi7FY91DQBpug2qo7qOsUnT+o cFiDn7hLquO5UpfSxrQsNH9WtNo2HYDy8pDnyY5tLZCO28826XievMuOrnTz1PqftSaOy5 aPbjqRqkXKI8anojJV/Q3lLaQ8naJuFX9obbKbGaHN8IdBNXRXZjFu04RjRs8ZwIBFZ8B+ BgAbALf9/764dWsrXiVsmirZbyp5YjTYQyOXlORTXfCBfwHc7ZIMj/soAQH/zjK77fFUcU dbiRoi0WOy7SYWi5Xe8zaqdNNj938DmZLjNy/YwHQyJeJmSP5twEBru6JPbXAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1647718234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dJBHj0nwlwl+MghVSTvEUo3iwyIaD6f/vnPoQWcboIs=; b=yqe7viTKGmUvrMtyMWWNzhSa5EaB+lezZrCGQLnlOuvUgN2vlhMLQjGMhvEZnzuXvbT6k8 kLtpi9eAvb1qIOclDqratMRZPG/EJ3A6ETGFr0IuiW9Sff5o22pa+9vYmeuBojL2Sr880r ruhPMe9O/6pGmzPe3C3jcndZn5hA1ae9f3gf2L+qIpyk15VGPdeyvahTu1M5NuM5Y3nctL lYNqCYn+JL0ZtXQcsl8QSmYWT1g/bEAy0p7DcJJ5vVoT6OMA1fzeGOVZ+FXg/KEUyB1tIm LYuweEjqvjYyxkXpyN1QsdWvtRe1D4QsISjDKAPdc2xKELF9W8XLtBfd66LzXA== ARC-Authentication-Results: i=1; rspamd-c9cb649d9-78d2s; auth=pass smtp.auth=cp7oy65bvo smtp.mailfrom=paolo@paolodestefani.it X-Sender-Id: cp7oy65bvo|x-authuser|paolo@paolodestefani.it Received: from lu-shared04.cpanelplatform.com ([UNAVAILABLE]. [107.189.4.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.119.141.221 (trex/6.5.3); Sat, 19 Mar 2022 19:30:35 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: cp7oy65bvo|x-authuser|paolo@paolodestefani.it X-MailChannels-Auth-Id: cp7oy65bvo X-Drop-Arithmetic: 48aae0c516cf0610_1647718235255_2056509913 X-MC-Loop-Signature: 1647718235255:2759048671 X-MC-Ingress-Time: 1647718235254 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=paolodestefani.it; s=default; h=Content-Transfer-Encoding:Content-Type: Message-ID:References:In-Reply-To:Subject:Cc:To:From:Date:MIME-Version:Sender :Reply-To: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=dJBHj0nwlwl+MghVSTvEUo3iwyIaD6f/vnPoQWcboIs=; b=G1CDlAGuMaWFeC+4S4E5TN3W9t 9gcWzwpt+J3kmZ1gwifmbgmZGYtk39yzIf/2+Xv59pyeSlpdWLpfUP4P3bqtdh3NMDGK/P+0ct5n4 0Q+j2RxG1OvglXIhULAgRryW5Xn7199B09wIjr8EQuCHXNB3kmNWyQ6xMA0LqaCLLFEHj/iTfEGwU GB5S4w3vrxgtWxTTsPpkvA6WT1+B7oELyUA/SG+ZZmIYz1NiDYO6FWl3PYTWaQ/LTdE1946nWRj/t fYE3twRdFPpnZzWe6HO8klh97OKqEgY2bU0kW84I7pIqUsmqaFdVH6NtiL60g148NCkvd033QGZ2k OziBOThg==; Received: from [::1] (port=56254 helo=lu-shared04.cpanelplatform.com) by lu-shared04.cpanelplatform.com with esmtpa (Exim 4.95) (envelope-from ) id 1nVemW-00DHRk-7p; Sat, 19 Mar 2022 20:30:32 +0100 MIME-Version: 1.0 Date: Sat, 19 Mar 2022 20:30:32 +0100 From: Paolo De Stefani To: Christophe Pettus Cc: Psycopg Subject: Re: Query with boolean parameter In-Reply-To: References: <8df15d1263aaa1a9d36eacb0e5b9a28e@paolodestefani.it> <74FC637F-2D25-4CD0-A075-9CB5293FCA5B@thebuild.com> User-Agent: Roundcube Webmail/1.4.12 Message-ID: <6955bcd2bba7feaddb480df53fc8b558@paolodestefani.it> X-Sender: paolo@paolodestefani.it Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-AuthUser: paolo@paolodestefani.it List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Il 19/03/2022 17:35 Christophe Pettus ha scritto: >> On Mar 19, 2022, at 05:10, Paolo De Stefani >> wrote: >> Switching to psycopg 3 i have to consider many more differences than i >> expected > > There have been some changes in the way psycopg2 does parameter > substitution, although that one is an interesting case! You might > consider using IS DISTINCT FROM as Daniele suggested, or just =, > depending on how you want nulls handled. thanks to all for the suggestions i thimk i will use the '=' operator what do you mean with 'depending on how you want nulls handled' ??? test4=# create table test (a text, b boolean); CREATE TABLE test4=# insert into test values ('aaa', true), ('bbb', false), ('ccc', null); INSERT 0 3 test4=# select * from test; a | b -----+--- aaa | t bbb | f ccc | (3 rows) test4=# select * from test where b = true; a | b -----+--- aaa | t (1 row) test4=# select * from test where b is true; a | b -----+--- aaa | t (1 row) test4=# select * from test where b = null; a | b ---+--- (0 rows) test4=# select * from test where b is null; a | b -----+--- ccc | (1 row) I will use '= True' or '= False' in psycopg cur.execute with parameter substitution and 'IS NULL' without parameter when i need to check the null value -- Paolo De Stefani