public inbox for [email protected]
help / color / mirror / Atom feedFrom: Paolo De Stefani <[email protected]>
To: Christophe Pettus <[email protected]>
Cc: Psycopg <[email protected]>
Subject: Re: Query with boolean parameter
Date: Sat, 19 Mar 2022 20:30:32 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Il 19/03/2022 17:35 Christophe Pettus ha scritto:
>> On Mar 19, 2022, at 05:10, Paolo De Stefani <[email protected]>
>> 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
view thread (7+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Query with boolean parameter
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox