From: Tom Lane <tgl@sss.pgh.pa.us>
To: Дмитрий Иванов <firstdismay@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16862: Unexpected result of checking for null "IS NOT NULL" in function
Date: Fri, 12 Feb 2021 13:57:48 -0500
Message-ID: <1561481.1613156268@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPL5KHr0EK7fSHvmPhnGn2nmEcZuPYR1BhKZ5W0ynoH9aHHJ0Q@mail.gmail.com>
References: <16862-c10a7401d2973a9b@postgresql.org>
<1552247.1613143392@sss.pgh.pa.us>
<CAPL5KHr0EK7fSHvmPhnGn2nmEcZuPYR1BhKZ5W0ynoH9aHHJ0Q@mail.gmail.com>
=?UTF-8?B?0JTQvNC40YLRgNC40Lkg0JjQstCw0L3QvtCy?= <firstdismay@gmail.com> writes:
> CREATE TABLE "public"."test" (
> "id" Bigint NOT NULL,
> "name" Character Varying NOT NULL,
> PRIMARY KEY ( "id" ) );
> -- -------------------------------------------------------------
> INSERT INTO "public"."test" ( "id", "name")
> VALUES ( 1, 'sdsdsdsdsd' );
> CREATE OR REPLACE VIEW "public"."vtest" AS SELECT test.id,
> test.name
> FROM test;;
> -- CREATE FUNCTION "class_is_actual3( int8, timestamp, timestamp )"
> CREATE OR REPLACE FUNCTION test_is_null_id(iid bigint, OUT tr BOOLEAN, OUT
> vr BOOLEAN)
> RETURNS RECORD
> LANGUAGE plpgsql
> AS $function$
> DECLARE
> t "test"%ROWTYPE;
> v "vtest"%ROWTYPE;
> BEGIN
> SELECT * INTO t FROM ONLY test WHERE id = iid;
> SELECT * INTO v FROM ONLY vtest WHERE id = iid;
> IF t IS NOT NULL THEN
> tr = true;
> ELSE
> tr = false;
> END IF;
> IF v IS NOT NULL THEN
> vr = true;
> ELSE
> vr = false;
> END IF;
> END;
> $function$;
> -- -------------------------------------------------------------
> SELECT * FROM test_is_null_id(1);
> ALTER TABLE "public"."test" ADD COLUMN "New_olumn" Bigint[] NULL;
> SELECT * FROM test_is_null_id(1);
OK, I appreciate the test case, but as far as I can see the database
is doing exactly what it's supposed to. After the ALTER ADD COLUMN
we have
# table test;
id | name | New_olumn
----+------------+-----------
1 | sdsdsdsdsd |
(1 row)
# table vtest;
id | name
----+------------
1 | sdsdsdsdsd
(1 row)
# SELECT * FROM test_is_null_id(1);
tr | vr
----+----
f | t
(1 row)
That looks fine to me: "test" now contains a column that is null,
so it doesn't pass the IS NOT NULL test. On the other hand,
"vtest" doesn't contain that column; all its columns are still non
null, so it does pass the IS NOT NULL test.
Note that "foo IS NOT NULL" is not the same as "NOT (foo IS NULL)"
when foo is of composite type. I agree that's confusing, but it's
required by the SQL spec. See
https://www.postgresql.org/docs/12/functions-comparison.html
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, firstdismay@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16862: Unexpected result of checking for null "IS NOT NULL" in function
In-Reply-To: <1561481.1613156268@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox