From c0f2817b70d9130f0338028f78777d1334b19717 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Wed, 3 Feb 2021 19:33:54 +0300 Subject: [PATCH] Disallow using alter_table udfs with tables having any identity cols (#4635) pg_get_tableschemadef_string doesn't know how to deparse identity columns so we cannot reflect those columns when creating table from scratch. For this reason, we don't allow using alter_table udfs with tables having any identity cols. --- src/backend/distributed/commands/alter_table.c | 14 ++++++++++++++ .../expected/alter_table_set_access_method.out | 5 +++++ .../regress/sql/alter_table_set_access_method.sql | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/src/backend/distributed/commands/alter_table.c b/src/backend/distributed/commands/alter_table.c index 655272fcf..1849fb5cd 100644 --- a/src/backend/distributed/commands/alter_table.c +++ b/src/backend/distributed/commands/alter_table.c @@ -909,6 +909,20 @@ CreateTableConversion(TableConversionParameters *params) ereport(ERROR, (errmsg("cannot complete operation " "because no such table exists"))); } + + TupleDesc relationDesc = RelationGetDescr(relation); + if (RelationUsesIdentityColumns(relationDesc)) + { + /* + * pg_get_tableschemadef_string doesn't know how to deparse identity + * columns so we cannot reflect those columns when creating table + * from scratch. For this reason, error out here. + */ + ereport(ERROR, (errmsg("cannot complete command because relation " + "%s has identity column", + generate_qualified_relation_name(con->relationId)), + errhint("Drop the identity columns and re-try the command"))); + } relation_close(relation, NoLock); con->distributionKey = BuildDistributionKeyFromColumnName(relation, con->distributionColumn); diff --git a/src/test/regress/expected/alter_table_set_access_method.out b/src/test/regress/expected/alter_table_set_access_method.out index 54484dff7..0c2366e1c 100644 --- a/src/test/regress/expected/alter_table_set_access_method.out +++ b/src/test/regress/expected/alter_table_set_access_method.out @@ -676,6 +676,11 @@ SELECT relname, relkind v_ref | v (6 rows) +CREATE TABLE identity_cols_test (a int, b int generated by default as identity (increment by 42)); +-- errors out since we don't support alter_table.* udfs with tables having any identity columns +SELECT alter_table_set_access_method('identity_cols_test', 'columnar'); +ERROR: cannot complete command because relation alter_table_set_access_method.identity_cols_test has identity column +HINT: Drop the identity columns and re-try the command SET client_min_messages TO WARNING; DROP SCHEMA alter_table_set_access_method CASCADE; SELECT 1 FROM master_remove_node('localhost', :master_port); diff --git a/src/test/regress/sql/alter_table_set_access_method.sql b/src/test/regress/sql/alter_table_set_access_method.sql index 17c7438f8..69a9dd8d4 100644 --- a/src/test/regress/sql/alter_table_set_access_method.sql +++ b/src/test/regress/sql/alter_table_set_access_method.sql @@ -209,6 +209,10 @@ SELECT relname, relkind ) ORDER BY relname ASC; +CREATE TABLE identity_cols_test (a int, b int generated by default as identity (increment by 42)); +-- errors out since we don't support alter_table.* udfs with tables having any identity columns +SELECT alter_table_set_access_method('identity_cols_test', 'columnar'); + SET client_min_messages TO WARNING; DROP SCHEMA alter_table_set_access_method CASCADE; SELECT 1 FROM master_remove_node('localhost', :master_port);