Re: Query with boolean parameter

Поиск
Список
Период
Сортировка
От Paolo De Stefani
Тема Re: Query with boolean parameter
Дата
Msg-id 6955bcd2bba7feaddb480df53fc8b558@paolodestefani.it
обсуждение исходный текст
Ответ на Re: Query with boolean parameter  (Christophe Pettus <xof@thebuild.com>)
Список psycopg
Il 19/03/2022 17:35 Christophe Pettus ha scritto:
>> On Mar 19, 2022, at 05:10, Paolo De Stefani <paolo@paolodestefani.it> 
>> 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



В списке psycopg по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Query with boolean parameter
Следующее
От: Rich Shepard
Дата:
Сообщение: cur.execute() syntax error