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.
pull/4508/head
Onur Tirtir 2021-02-03 19:33:54 +03:00 committed by GitHub
parent 3a403090fd
commit c0f2817b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);