CREATE TABLE LIKE with INHERITS skips checks on generated columns

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: CREATE TABLE LIKE with INHERITS skips checks on generated columns
Date: 2026-11-17 01:45:34
Message-ID: CAGRkXqT6yNbLRHquEqUBayADDS9Gh0H-KZHVMgnLvku4ebzx5w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

I ran into this while extending the patch in [1] to plain inheritance,
as Zsolt suggested.

CREATE TABLE ... (LIKE ...) INHERITS adds the copied defaults and
generation expressions after the table is created. That path skips the
checks the explicit syntax gets. In the worst case a stored generated
column is never computed:

create table p (a int, b int generated always as (a * 10) stored);
create table s (b int, v int generated always as (b * 2) stored);
create table c (like s including generated) inherits (p);
insert into c (a) values (1);
select * from c;
a | b | v
---+----+---
1 | 10 |
(1 row)

The patch does the same checks as the explicit syntax. When the copied
expression replaces an inherited one, it first drops the internal
dependency like SET EXPRESSION does. The tests are in a separate patch.

[1] https://postgr.es/m/E1xFKs5-0000000116b-2Cge@gemulon.postgresql.org

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-11-17 02:04:46 Re: CREATE TABLE LIKE with INHERITS skips checks on generated columns
Previous Message shihao zhong 2026-11-17 01:43:57 Re: pgsql: Don't trust NOT NULL on virtual generated columns of partitioned