powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / что вернет запрос SELECT * from _test where _test is null ?
4 сообщений из 4, страница 1 из 1
что вернет запрос SELECT * from _test where _test is null ?
    #33903891
reuvenab
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
таблица
CREATE TABLE _test ( f1 int, f2 int, f3 int);
insert into _test values(1, 1, 1);
insert into _test values(2, 2, null);
insert into _test values(3, null, null);
insert into _test values(null, null, null);

ошибся в запросе и вместо
Код: plaintext
SELECT * from _test where _test.f1 is null 
написал
Код: plaintext
SELECT * from _test where _test is null 

запрос благополучно отработал

f1 | f2 | f3
----+----+----
(0 rows)

Код: plaintext
1.
2.
3.
4.
5.
6.
explain  SELECT * from _test where _test is null;
                      QUERY PLAN
-------------------------------------------------------
 Seq Scan on _test  (cost= 0 . 00 .. 27 . 70  rows= 9  width= 12 )
   Filter: (_test.* IS NULL)




какая-то тонкость Row constructor ?

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
select row(f1, f2) is null from _test;
 ?column?
----------
 f
 f
 f
 t

или это так где-то в стандарте определенно?

как объяснить ?
...
Рейтинг: 0 / 0
что вернет запрос SELECT * from _test where _test is null ?
    #33903992
4321
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
SELECT *, _test,_test IS NULL, row(_test.f1,_test.f2,_test.f3), row(_test.f1,_test.f2,_test.f3) IS NULL from _test;

интересно, что _test дает типизированный результат _test,
а row(_test.f1,_test.f2,_test.f3) - record,
для record IS NULL дает результат t,
а для типа он всегда f ???
(т.е. видимо пока где-то не описано как сравнивать тип - не возвращается t ни для одной записи)
...
Рейтинг: 0 / 0
что вернет запрос SELECT * from _test where _test is null ?
    #33904196
akie
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
reuvenabтаблица
CREATE TABLE _test ( f1 int, f2 int, f3 int);
insert into _test values(1, 1, 1);
insert into _test values(2, 2, null);
insert into _test values(3, null, null);
insert into _test values(null, null, null);

ошибся в запросе и вместо
Код: plaintext
SELECT * from _test where _test.f1 is null 
написал
Код: plaintext
SELECT * from _test where _test is null 

запрос благополучно отработал

f1 | f2 | f3
----+----+----
(0 rows)

Код: plaintext
1.
2.
3.
4.
5.
6.
explain  SELECT * from _test where _test is null;
                      QUERY PLAN
-------------------------------------------------------
 Seq Scan on _test  (cost= 0 . 00 .. 27 . 70  rows= 9  width= 12 )
   Filter: (_test.* IS NULL)




какая-то тонкость Row constructor ?

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
select row(f1, f2) is null from _test;
 ?column?
----------
 f
 f
 f
 t

или это так где-то в стандарте определенно?

как объяснить ?

конечно определено:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
8.7 <null predicate>
Function
Specify a test for a null value.
Format
<null predicate> ::= <row value predicand> <null predicate part 2>
<null predicate part 2> ::= IS [ NOT ] NULL
Syntax Rules
None.
Access Rules
None.
General Rules
1) Let R be the value of the <row value predicand>.
2) Case:
a) If R is the null value, then “R IS NULL” is True.
b) Otherwise:
i) The value of “R IS NULL” is
Case:
 1) If the value of every field in R is the null value, then True.
2) Otherwise, False. 
ii) The value of “R IS NOT NULL” is
Case:
1) If the value of no field in R is the null value, then True.
2) Otherwise, False.
                    
...
Рейтинг: 0 / 0
что вернет запрос SELECT * from _test where _test is null ?
    #33905218
reuvenab
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
akie

конечно определено:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.7 <null predicate>
Function

......

Format
1) If the value of no field in R is the null value, then True.
2) Otherwise, False.


наверно я не совсем точно определил вопрос.
вопрос был не по конструкции
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
select row(f1, f2) is null from _test;
 ?column?
----------
 f
 f
 f
 t
а по тому как интерпретировать
Код: plaintext
SELECT * from _test where _test is null 
мое предположение было что выражение <tablename> is null Postgres интерпретирует как row constructor
Код: plaintext
1.
2.
3.
4.
                      QUERY PLAN
-------------------------------------------------------
 Seq Scan on _test  (cost= 0 . 00 .. 27 . 70  rows= 9  width= 12 )
   Filter: (_test.* IS NULL)

но тогда его результаты
сюдя поведнию Row Constructor
которое Вы нам любезно разъянисли кажутся несколько нелогичными
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / что вернет запрос SELECT * from _test where _test is null ?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]