BUG #14665: Wrong IS NULL result for composite type that has composite element

From: julius(dot)tuskenis(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14665: Wrong IS NULL result for composite type that has composite element
Date: 2017-05-23 13:53:27
Message-ID: 20170523135327.29942.17412@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14665
Logged by: Julius Tuskenis
Email address: julius(dot)tuskenis(at)gmail(dot)com
PostgreSQL version: 9.6.3
Operating system: Windows 10
Description:

According to the documentation
(https://www.postgresql.org/docs/9.4/static/functions-comparison.html) "If
the expression is row-valued, then IS NULL is true when the row expression
itself is null or when all the row's fields are null"

The problem is with the composite types that have composite types in them.
In cases then a subtype has all NULL fields the type is still evaluated NOT
NULL.

The code to reproduce the problem:

CREATE TYPE public.my_point AS
(x integer,
y integer);
ALTER TYPE public.my_point
OWNER TO postgres;

/*A pixel has a colored point */
CREATE TYPE public.my_pixel AS
(p public.my_point,
color integer);
ALTER TYPE public.my_pixel
OWNER TO postgres;

SELECT
(a).p IS NULL AS point_is_null
, (a).color IS NULL AS color_is_null
, (a) IS NULL as my_pixel_is_null
FROM (
VALUES
((ROW(1,2), 1)::my_pixel)
, ((ROW(1,2), NULL)::my_pixel)
, ((ROW(NULL,NULL), NULL)::my_pixel)
, ((NULL, NULL)::my_pixel)

) AS tbl(a);

RESULT:
f;f;f
f;t;f
t;t;f <-- components are NULL, but the result is not...
t;t;t

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-05-23 14:56:16 Re: BUG #14665: Wrong IS NULL result for composite type that has composite element
Previous Message Emre Hasegeli 2017-05-23 08:27:30 Re: BUG #14637: Tests fail with pl_PL.UTF-8 locale