Can't join on null values

Started by David Newallalmost 22 years ago6 messagesbugs
Jump to latest
#1David Newall
davidn-postgres@rebel.net.au

PostgreSQL version: 7.4.3 (RPMs from ftp.au.postgresql.org)

Operating Sysem: Fedora Core 1

CREATE TABLE t1 (i INTEGER, j INTEGER);
INSERT INTO t1 VALUES (1, NULL);
CREATE TABLE t2 AS SELECT * FROM t1;
SELECT * FROM t1 JOIN t2 USING (i, j);
i | j
---+---
(0 rows)

I believe the one row, which is identically present in both table,
should be selected. The problem occurs because of the NULL value.

#2Peter Eisentraut
peter_e@gmx.net
In reply to: David Newall (#1)
Re: Can't join on null values

David Newall wrote:

PostgreSQL version: 7.4.3 (RPMs from ftp.au.postgresql.org)

Operating Sysem: Fedora Core 1

CREATE TABLE t1 (i INTEGER, j INTEGER);
INSERT INTO t1 VALUES (1, NULL);
CREATE TABLE t2 AS SELECT * FROM t1;
SELECT * FROM t1 JOIN t2 USING (i, j);
i | j
---+---
(0 rows)

I believe the one row, which is identically present in both table,
should be selected. The problem occurs because of the NULL value.

A join happens when two values are equal in the sense of the operator =.
But "NULL = NULL" is not true, so the behavior is correct.

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: David Newall (#1)
Re: Can't join on null values

Hello,

its not error. Only SQL specific :-) NULL <> NULL

Regards
Pavel Stehule

On Tue, 6 Jul 2004, David Newall wrote:

Show quoted text

PostgreSQL version: 7.4.3 (RPMs from ftp.au.postgresql.org)

Operating Sysem: Fedora Core 1

CREATE TABLE t1 (i INTEGER, j INTEGER);
INSERT INTO t1 VALUES (1, NULL);
CREATE TABLE t2 AS SELECT * FROM t1;
SELECT * FROM t1 JOIN t2 USING (i, j);
i | j
---+---
(0 rows)

I believe the one row, which is identically present in both table,
should be selected. The problem occurs because of the NULL value.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

#4Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: David Newall (#1)
Re: Can't join on null values

On Tue, 6 Jul 2004, David Newall wrote:

PostgreSQL version: 7.4.3 (RPMs from ftp.au.postgresql.org)

Operating Sysem: Fedora Core 1

CREATE TABLE t1 (i INTEGER, j INTEGER);
INSERT INTO t1 VALUES (1, NULL);
CREATE TABLE t2 AS SELECT * FROM t1;
SELECT * FROM t1 JOIN t2 USING (i, j);
i | j
---+---
(0 rows)

I believe the one row, which is identically present in both table,
should be selected. The problem occurs because of the NULL value.

NULL is not equal to NULL so I don't think the values for j meet
the join condition "for which the corresponding join columns have equal
values."

#5Peter Eisentraut
peter_e@gmx.net
In reply to: Pavel Stehule (#3)
Re: Can't join on null values

Pavel Stehule wrote:

its not error. Only SQL specific :-) NULL <> NULL

Au contraire, neither

NULL = NULL

nor

NULL <> NULL

is true.

#6David Newall
davidn-postgres@rebel.net.au
In reply to: Pavel Stehule (#3)
Re: Can't join on null values

People,

Thanks for your help with my problem with NULL values. Also, particular
thanks for a hint on where to find a copy of SQL-92 standard, something
I didn't already have. It was annoying to discover that UNIQUE didn't
have what I felt was the "obvious" meaning, but it doesn't and PostgreSQL
does operate correctly.

David