Re: Fold NOT IN / <> ALL expressions containing NULL to FALSE

From: Rustam ALLAKOV <rustamallakov(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>
Subject: Re: Fold NOT IN / <> ALL expressions containing NULL to FALSE
Date: 2026-09-26 21:09:32
Message-ID: 179045697259.1129.5063435779954318539.pgcf@coridan.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi folks,
sharing some output of my saturday session with an agent.
hope this will somehow help.

Tested v4 on master (3c5d9d9). The issues from v2 review are
fixed, but It found some new ones.

The CASE WHEN folding in eval_const_expressions_mutator also runs at
DDL time via expression_planner(). Because of that, a partition key
that master accepts is now rejected as a constant:

CREATE TABLE pk (a int, b int) PARTITION BY LIST
((CASE WHEN a NOT IN (42, NULL) THEN 1 ELSE 0 END));

master: CREATE TABLE
v4: ERROR: cannot use constant expression as partition key

So a cluster that has such a table can't be moved to v4.

pg_dump from master and restore into v4 fails:

ERROR: cannot use constant expression as partition key
ERROR: relation "public.pk" does not exist

pg_upgrade from master to v4 fails in "Restoring database schemas in
the new cluster":

pg_restore: error: could not execute query: ERROR: cannot use
constant expression as partition key
...
CREATE TABLE "public"."pk" (
"a" integer,
"b" integer
)
PARTITION BY LIST ((
CASE
WHEN ("a" <> ALL (ARRAY[42, NULL::integer])) THEN 1
ELSE 0
END));

Regards,
--
Rustam Allakov

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-09-26 21:44:02 Re: Fix "unexpected logical decoding status change" error; from concurrent logical decoding activation
Previous Message Tom Lane 2026-09-26 19:27:52 Re: remove_useless_joins vs. bug #19560