diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2024-01-04 15:45:35 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2024-01-04 16:28:54 +0100 |
commit | 5d06e99a3cfc23bbc217b4d78b8c070ad52f720e (patch) | |
tree | f19ee2c99bdfec654b28f4e6afdbae26c5ff0eb0 /src/backend/parser | |
parent | ae69c4fcf1337af399a788ab8d96af540bd1cd8e (diff) |
ALTER TABLE command to change generation expression
This adds a new ALTER TABLE subcommand ALTER COLUMN ... SET EXPRESSION
that changes the generation expression of a generated column.
The syntax is not standard but was adapted from other SQL
implementations.
This command causes a table rewrite, using the usual ALTER TABLE
mechanisms. The implementation is similar to and makes use of some of
the infrastructure of the SET DATA TYPE subcommand (for example,
rebuilding constraints and indexes afterwards). The new command
requires a new pass in AlterTablePass, and the ADD COLUMN pass had to
be moved earlier so that combinations of ADD COLUMN and SET EXPRESSION
can work.
Author: Amul Sul <sulamul@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAAJ_b94yyJeGA-5M951_Lr+KfZokOp-2kXicpmEhi5FXhBeTog@mail.gmail.com
Diffstat (limited to 'src/backend/parser')
-rw-r--r-- | src/backend/parser/gram.y | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 746365027c2..6b88096e8e1 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2417,6 +2417,16 @@ alter_table_cmd: n->name = $3; $$ = (Node *) n; } + /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */ + | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')' + { + AlterTableCmd *n = makeNode(AlterTableCmd); + + n->subtype = AT_SetExpression; + n->name = $3; + n->def = $8; + $$ = (Node *) n; + } /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */ | ALTER opt_column ColId DROP EXPRESSION { |