Re: ATTACH PARTITION seems to ignore column generation status
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Amit Langote <amitlangote09@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org,
Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Date: 2023-01-09T21:41:05Z
Lists: pgsql-hackers
Attachments
- disallow-generated-child-columns-2.patch (text/x-diff) patch
I wrote: > After thinking about this awhile, I feel that we ought to disallow > it in the traditional-inheritance case as well. The reason is that > there are semantic prohibitions on inserting or updating a generated > column, eg > regression=# create table t (f1 int, f2 int generated always as (f1+1) stored); > CREATE TABLE > regression=# update t set f2=42; > ERROR: column "f2" can only be updated to DEFAULT > DETAIL: Column "f2" is a generated column. > It's not very reasonable to have to recheck that for child tables, > and we don't. But if one does this: > regression=# create table pp (f1 int, f2 int); > CREATE TABLE > regression=# create table cc (f1 int, f2 int generated always as (f1+1) stored) inherits(pp); > NOTICE: merging column "f1" with inherited definition > NOTICE: merging column "f2" with inherited definition > CREATE TABLE > regression=# insert into cc values(1); > INSERT 0 1 > regression=# update pp set f2 = 99 where f1 = 1; > UPDATE 1 > regression=# table cc; > f1 | f2 > ----+---- > 1 | 99 > (1 row) > That is surely just as broken as the partition-based case. So what we need is about like this. This is definitely not something to back-patch, since it's taking away what had been a documented behavior. You could imagine trying to prevent such UPDATEs instead, but I judge it not worth the trouble. If anyone were actually using this capability we'd have heard bug reports. regards, tom lane
Commits
-
Fix check for child column generation status matching parent.
- a0fa18cc0d6e 16.0 landed
-
Doc: fix silly thinko in 8bf6ec3ba.
- d93d68aeeaee 16.0 landed
-
Improve handling of inherited GENERATED expressions.
- 8bf6ec3ba3a4 16.0 landed
-
Fix calculation of which GENERATED columns need to be updated.
- ad38e2f89116 13.10 landed
- 8cd190e13a22 14.7 landed
- 3f7836ff651a 16.0 landed
- 3706cc97aa36 15.2 landed