Question on not-in and array-eq - Mailing list pgsql-hackers

From Zhenghua Lyu
Subject Question on not-in and array-eq
Date
Msg-id CO6PR05MB7506DFE29434911C9290F2DCB56F9@CO6PR05MB7506.namprd05.prod.outlook.com
Whole thread Raw
Responses Re: Question on not-in and array-eq
List pgsql-hackers
Hi,
    
   I run the following SQL in Postgres (14_STABLE), and got the results:  
zlyu=# create table t1(a int, b int);
CREATE TABLE
zlyu=# create table t2(a int, b int);
CREATE TABLE
zlyu=# insert into t1 values (null, 1);
INSERT 0 1
zlyu=# insert into t2 values (1, 1);
INSERT 0 1
zlyu=# select * from t1 where (a, b) not in (select * from t2);
 a | b
---+---
(0 rows)

zlyu=# select * from t1 where (a, b) in (select * from t2);
 a | b
---+---
(0 rows)

zlyu=# select * from t1 where array[a, b] in (select array[a,b] from t2);
 a | b
---+---
(0 rows)

zlyu=# select * from t1 where array[a, b] not in (select array[a,b] from t2);
 a | b
---+---
   | 1
(1 row)

I run the SQL without array expr​ in other DBs(orcale, sqlite, ...), they all behave
the same as Postgres.

It seems a bit confusing for me that 'not in' and 'in' the same subquery both return 0
rows, but the table contains data.

Also, manually using array expression behaves differently from the first SQL. For not in case,
I step in the code, and find array_eq will consider null = null as true, however ExecSubPlan will
consider null as unprovable and exclude that row.

How to understand the result? It seems SQL standard does not mention array operation for null
value.

Thanks!

pgsql-hackers by date:

Previous
From: Dagfinn Ilmari Mannsåker
Date:
Subject: Re: Readd use of TAP subtests
Next
From: Tom Lane
Date:
Subject: Re: Appetite for Frama-C annotations?