aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_utilcmd.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-09-25 17:30:42 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2019-09-25 17:30:42 -0400
commitb81a9c2fc52509025c635fa08ecaec1bad21441b (patch)
tree96cc5584df388970831b548ffdc455d695a6fd2b /src/backend/parser/parse_utilcmd.c
parentbffe1bd68457e43925c362d8728ce3b25bdf1c94 (diff)
downloadpostgresql-b81a9c2fc52509025c635fa08ecaec1bad21441b.tar.gz
postgresql-b81a9c2fc52509025c635fa08ecaec1bad21441b.zip
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
Diffstat (limited to 'src/backend/parser/parse_utilcmd.c')
-rw-r--r--src/backend/parser/parse_utilcmd.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 6e5768c66cf..ee475476248 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -1023,11 +1023,13 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
attmap[parent_attno - 1] = list_length(cxt->columns);
/*
- * Copy default, if present and the default has been requested
+ * Copy default, if present and it should be copied. We have separate
+ * options for plain default expressions and GENERATED defaults.
*/
if (attribute->atthasdef &&
- (table_like_clause->options & CREATE_TABLE_LIKE_DEFAULTS ||
- table_like_clause->options & CREATE_TABLE_LIKE_GENERATED))
+ (attribute->attgenerated ?
+ (table_like_clause->options & CREATE_TABLE_LIKE_GENERATED) :
+ (table_like_clause->options & CREATE_TABLE_LIKE_DEFAULTS)))
{
Node *this_default = NULL;
AttrDefault *attrdef;
@@ -1065,9 +1067,7 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
attributeName,
RelationGetRelationName(relation))));
- if (attribute->attgenerated &&
- (table_like_clause->options & CREATE_TABLE_LIKE_GENERATED))
- def->generated = attribute->attgenerated;
+ def->generated = attribute->attgenerated;
}
/*