pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19770: CREATE TABLE (LIKE ...) PARTITION BY copies a NO INHERIT not-null constraint; NULLs then go into par
2+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2026-10-27 700b422af7 a01d1a17e9 35f60e5cea Disallow NOT NULL NO INHERIT constraints on partitioned tables
* BUG #19770: CREATE TABLE (LIKE ...) PARTITION BY copies a NO INHERIT not-null constraint; NULLs then go into par
@ 2026-10-18 13:58 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2026-10-18 13:58 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: anncalla@163.com
The following bug has been logged on the website:
Bug reference: 19770
Logged by: Ann C
Email address: anncalla@163.com
PostgreSQL version: 18.6
Operating system: Ubuntu 24.04 x86_64
Description:
A not-null constraint marked NO INHERIT is rejected on a partitioned table
when it is declared directly:
ERROR: not-null constraints on partitioned tables cannot be NO INHERIT
But CREATE TABLE pp (LIKE p) PARTITION BY ... copies such a constraint from
p without an error. pg_constraint then has the constraint on pp with
connoinherit = true. The partitions do not get a not-null constraint, so
INSERT INTO pp VALUES (NULL) succeeds and the row is stored in the default
partition.
Queries on the parent are planned with c0 known to be NOT NULL, so "WHERE c0
IS NULL" becomes a constant false and returns 0 rows, although SELECT
count(*) FROM pp returns the NULL row and the partition itself finds it.
Expected: CREATE TABLE ... (LIKE p) PARTITION BY should fail with the same
error as the direct declaration (or copy the constraint without NO INHERIT).
Reproduced on 18.6 and 19beta4 (official Docker images). The ALTER
CONSTRAINT ... NO INHERIT path to the same state was fixed on 2026-05-22
("Prevent setting NO INHERIT on partitioned NOT NULL constraints"); this is
another path.
CREATE TABLE p (c0 int, CONSTRAINT p_nn NOT NULL c0 NO INHERIT);
CREATE TABLE q (c0 int NOT NULL NO INHERIT) PARTITION BY RANGE (c0);
-- ERROR: not-null constraints on partitioned tables cannot be NO INHERIT
CREATE TABLE pp (LIKE p) PARTITION BY RANGE (c0);
-- CREATE TABLE (no error)
SELECT conname, conrelid::regclass, contype, connoinherit
FROM pg_constraint WHERE conrelid = 'pp'::regclass;
-- p_nn | pp | n | t
CREATE TABLE pp_def PARTITION OF pp DEFAULT; -- column c0 is nullable in
pp_def
INSERT INTO pp VALUES (NULL); -- INSERT 0 1
SELECT count(*) FROM pp; -- 1
SELECT count(*) FROM pp WHERE c0 IS NULL; -- 0, expected 1
SELECT count(*) FROM pp_def WHERE c0 IS NULL; -- 1
EXPLAIN (COSTS OFF) SELECT count(*) FROM pp WHERE c0 IS NULL;
-- Aggregate
-- -> Result
-- One-Time Filter: false
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #19770: CREATE TABLE (LIKE ...) PARTITION BY copies a NO INHERIT not-null constraint; NULLs then go into par
@ 2026-10-21 08:34 Nitin Motiani <nitinmotiani@google.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 0 replies; 2+ messages in thread
From: Nitin Motiani @ 2026-10-21 08:34 UTC (permalink / raw)
To: anncalla@163.com; pgsql-bugs@lists.postgresql.org
Hi,
Thanks for the report. I have proposed a fix to this in
pgsql-hackers[1]. Please take a look.
Regards,
Nitin Motiani
Google
[1] https://www.postgresql.org/message-id/CAH5HC96YCzOy+9JZLQ4n0sMchVnharTOXrr4sbYuh=_d+ffjAA@mail.gmail...
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-10-21 08:34 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-18 13:58 BUG #19770: CREATE TABLE (LIKE ...) PARTITION BY copies a NO INHERIT not-null constraint; NULLs then go into par PG Bug reporting form <noreply@postgresql.org>
2026-10-21 08:34 ` Nitin Motiani <nitinmotiani@google.com>
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