pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING 4+ messages / 1 participants [nested] [flat]
* pgsql: Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING @ 2019-09-25 21:30 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2019-09-25 21:30 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING DEFAULTS. LIKE INCLUDING DEFAULTS tried to copy the attrdef expression without copying the state of the attgenerated column. This is in fact wrong, because GENERATED and DEFAULT expressions are not the same kind of animal; one can contain Vars and the other not. We *must* copy attgenerated when we're copying the attrdef expression. Rearrange the if-tests so that the expression is copied only when the correct one of INCLUDING DEFAULTS and INCLUDING GENERATED has been specified. Per private report from Manuel Rigger. Tom Lane and Peter Eisentraut Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/b81a9c2fc52509025c635fa08ecaec1bad21441b Modified Files -------------- src/backend/parser/parse_utilcmd.c | 12 ++-- src/test/regress/expected/create_table_like.out | 74 +++++++++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 20 +++++++ 3 files changed, 100 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING @ 2019-09-25 21:30 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2019-09-25 21:30 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING DEFAULTS. LIKE INCLUDING DEFAULTS tried to copy the attrdef expression without copying the state of the attgenerated column. This is in fact wrong, because GENERATED and DEFAULT expressions are not the same kind of animal; one can contain Vars and the other not. We *must* copy attgenerated when we're copying the attrdef expression. Rearrange the if-tests so that the expression is copied only when the correct one of INCLUDING DEFAULTS and INCLUDING GENERATED has been specified. Per private report from Manuel Rigger. Tom Lane and Peter Eisentraut Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/658d391d87c13a4b27425a2fd014f2162956ad4d Modified Files -------------- src/backend/parser/parse_utilcmd.c | 12 ++-- src/test/regress/expected/create_table_like.out | 74 +++++++++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 20 +++++++ 3 files changed, 100 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix handling of generated columns in ALTER TABLE. @ 2020-01-08 14:43 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2020-01-08 14:43 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of generated columns in ALTER TABLE. ALTER TABLE failed if a column referenced in a GENERATED expression had been added or changed in type earlier in the ALTER command. That's because the GENERATED expression needs to be evaluated against the table's updated tuples, but it was being evaluated against the original tuples. (Fortunately the executor has adequate cross-checks to notice the mismatch, so we just got an obscure error message and not anything more dangerous.) Per report from Andreas Joseph Krogh. Back-patch to v12 where GENERATED was added. Discussion: https://postgr.es/m/VisenaEmail.200.231b0a41523275d0.16ea7f800c7@tc7-visena Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/4ac8aaa36fa24639989849c8109f8b52e9544fd1 Modified Files -------------- src/backend/commands/tablecmds.c | 33 ++++++++++- src/test/regress/expected/generated.out | 97 ++++++++++++++++++++++++++------- src/test/regress/sql/generated.sql | 31 +++++++++-- 3 files changed, 132 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix handling of generated columns in ALTER TABLE. @ 2020-01-08 14:43 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2020-01-08 14:43 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of generated columns in ALTER TABLE. ALTER TABLE failed if a column referenced in a GENERATED expression had been added or changed in type earlier in the ALTER command. That's because the GENERATED expression needs to be evaluated against the table's updated tuples, but it was being evaluated against the original tuples. (Fortunately the executor has adequate cross-checks to notice the mismatch, so we just got an obscure error message and not anything more dangerous.) Per report from Andreas Joseph Krogh. Back-patch to v12 where GENERATED was added. Discussion: https://postgr.es/m/VisenaEmail.200.231b0a41523275d0.16ea7f800c7@tc7-visena Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c24f3b70efc243bb44a6a4121032f19e2d6e813e Modified Files -------------- src/backend/commands/tablecmds.c | 33 ++++++++++- src/test/regress/expected/generated.out | 97 ++++++++++++++++++++++++++------- src/test/regress/sql/generated.sql | 31 +++++++++-- 3 files changed, 132 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2020-01-08 14:43 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-09-25 21:30 pgsql: Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING Tom Lane <tgl@sss.pgh.pa.us> 2019-09-25 21:30 pgsql: Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING Tom Lane <tgl@sss.pgh.pa.us> 2020-01-08 14:43 pgsql: Fix handling of generated columns in ALTER TABLE. Tom Lane <tgl@sss.pgh.pa.us> 2020-01-08 14:43 pgsql: Fix handling of generated columns in ALTER TABLE. Tom Lane <tgl@sss.pgh.pa.us>
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