Fix handling of generated columns in ALTER TABLE.
authorTom Lane
Wed, 8 Jan 2020 14:42:53 +0000 (09:42 -0500)
committerTom Lane
Wed, 8 Jan 2020 14:42:53 +0000 (09:42 -0500)
commitc24f3b70efc243bb44a6a4121032f19e2d6e813e
tree66918b2ece7e0eb41a6a3f4922b5fc09631c1300
parenta1c003e5ff82f3dc9fc4bf7a32706e53ae6373bf
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
src/backend/commands/tablecmds.c
src/test/regress/expected/generated.out
src/test/regress/sql/generated.sql