diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index c7cb26887..33a2b7212 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -1592,6 +1592,16 @@ UndistributeTable(Oid relationId) "because it is a foreign table."))); } + if (PartitionTable(relationId)) + { + Oid parentRelationId = PartitionParentOid(relationId); + char *parentRelationName = get_rel_name(parentRelationId); + ereport(ERROR, (errmsg("Cannot undistribute table " + "because it is a partition."), + errhint("Undistribute the partitioned table \"%s\" instead.", + parentRelationName))); + } + List *preLoadCommands = GetPreLoadTableCreationCommands(relationId, true); List *postLoadCommands = GetPostLoadTableCreationCommands(relationId); diff --git a/src/test/regress/expected/undistribute_table.out b/src/test/regress/expected/undistribute_table.out index 0d664d895..7fac4ec29 100644 --- a/src/test/regress/expected/undistribute_table.out +++ b/src/test/regress/expected/undistribute_table.out @@ -194,6 +194,11 @@ SELECT * FROM partitioned_table_6_10 ORDER BY 1, 2; 7 | 2 (1 row) +-- undistributing partitions are not supported +SELECT undistribute_table('partitioned_table_1_5'); +ERROR: Cannot undistribute table because it is a partition. +HINT: Undistribute the partitioned table "partitioned_table" instead. +-- we can undistribute partitioned parent tables SELECT undistribute_table('partitioned_table'); NOTICE: Undistributing the partitions of undistribute_table.partitioned_table NOTICE: Creating a new local table for undistribute_table.partitioned_table_1_5 diff --git a/src/test/regress/sql/undistribute_table.sql b/src/test/regress/sql/undistribute_table.sql index d019d89cc..ad133b5e2 100644 --- a/src/test/regress/sql/undistribute_table.sql +++ b/src/test/regress/sql/undistribute_table.sql @@ -77,6 +77,9 @@ SELECT * FROM partitioned_table ORDER BY 1, 2; SELECT * FROM partitioned_table_1_5 ORDER BY 1, 2; SELECT * FROM partitioned_table_6_10 ORDER BY 1, 2; +-- undistributing partitions are not supported +SELECT undistribute_table('partitioned_table_1_5'); +-- we can undistribute partitioned parent tables SELECT undistribute_table('partitioned_table'); SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid::regclass::text LIKE 'partitioned\_table%' ORDER BY 1;