diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 72ad6507d7..100891861e 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -3013,11 +3013,22 @@ MergeAttributes(List *schema, List *supers, char relpersistence, { ColumnDef *coldef = lfirst(l); + /* + * Like above, prevent generated columns in partitions that + * are not present in the parent. + */ if (strcmp(coldef->colname, restdef->colname) == 0) { found = true; coldef->is_not_null |= restdef->is_not_null; + if (restdef->generated && !coldef->generated) + ereport(ERROR, + (errcode(ERRCODE_INVALID_COLUMN_DEFINITION), + errmsg("child column \"%s\" specifies generation expression", + restdef->colname), + errhint("A child table column cannot be generated unless its parent column is."))); + /* * Override the parent's default value for this column * (coldef->cooked_default) with the partition's local diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index bffa9f8dd0..f9218f48aa 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -740,11 +740,6 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("generated columns are not supported on typed tables"))); - if (cxt->partbound) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("generated columns are not supported on partitions"))); - if (saw_generated) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), diff --git a/src/test/regress/expected/generated.out b/src/test/regress/expected/generated.out index 3c10dabf6d..4a7b014982 100644 --- a/src/test/regress/expected/generated.out +++ b/src/test/regress/expected/generated.out @@ -680,7 +680,8 @@ CREATE TABLE gtest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RA CREATE TABLE gtest_child PARTITION OF gtest_parent ( f3 WITH OPTIONS GENERATED ALWAYS AS (f2 * 2) STORED ) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error -ERROR: generated columns are not supported on partitions +ERROR: child column "f3" specifies generation expression +HINT: A child table column cannot be generated unless its parent column is. CREATE TABLE gtest_child (f1 date NOT NULL, f2 text, f3 bigint GENERATED ALWAYS AS (2 * 2) STORED); ALTER TABLE gtest_parent ATTACH PARTITION gtest_child FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error ERROR: column "f3" in child table must not be a generated column