BUG #15297: Irregular comparison rules for NULLs in tuples - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15297: Irregular comparison rules for NULLs in tuples
Date
Msg-id 153261212701.1395.18260320763646237974@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #15297: Irregular comparison rules for NULLs in tuples
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      15297
Logged by:          kena
Email address:      knz@thaumogen.net
PostgreSQL version: 10.4
Operating system:   FreeBSD + Linux
Description:

The SQL standard mandates ternary logic for values that involve NULL, where
NULL means "unknown".

This works in many cases correctly in pg:

"select NULL in (1,2)" -> returns NULL, correct
"select (1, NULL::int) in ((1, 1), (1, 2))" -> returns NULL, correct
"select 1 < NULL" -> returns NULL, correct
"select (1, NULL::int) > (1, 2)" -> returns NULL, correct

However as soon as a tuple/composite value contains itself composites, the
rule is not obeyed any more recursively:

"select (1, (1, NULL::int)) in ((1, (1, 0)), (1, (1, 2)))" -> returns false
!?

"select (1, (1, NULL::int)) > (1, (1, 2))"  -> returns true !?

Is this intended behavior? If so, where is it documented?

If not documented, any suggestion as to how to work around it?

Thanks in advance,

-- 
Raphael 'kena' Poss


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15296: Not able to get query result"information_schema.constraint_column_usage"
Next
From: PG Bug reporting form
Date:
Subject: BUG #15298: Array-array comparisons when arrays contain NULLs