diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index 92528b6c9..ca043acaf 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -126,6 +126,7 @@ static void DoCopyFromLocalTableIntoShards(Relation distributedRelation, DestReceiver *copyDest, TupleTableSlot *slot, EState *estate); +static void ErrorIfTemporaryTable(Oid relationId); /* exports for SQL callable functions */ PG_FUNCTION_INFO_V1(master_create_distributed_table); @@ -329,6 +330,7 @@ EnsureCitusTableCanBeCreated(Oid relationOid) EnsureCoordinator(); EnsureRelationExists(relationOid); EnsureTableOwner(relationOid); + ErrorIfTemporaryTable(relationOid); /* * We should do this check here since the codes in the following lines rely @@ -1166,6 +1168,20 @@ EnsureRelationCanBeDistributed(Oid relationId, Var *distributionColumn, } +/* + * ErrorIfTemporaryTable errors out if the given table is a temporary table. + */ +static void +ErrorIfTemporaryTable(Oid relationId) +{ + if (get_rel_persistence(relationId) == RELPERSISTENCE_TEMP) + { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot distribute a temporary table"))); + } +} + + /* * ErrorIfTableIsACatalogTable is a helper function to error out for citus * table creation from a catalog table. diff --git a/src/test/regress/expected/multi_create_table.out b/src/test/regress/expected/multi_create_table.out index dddef65eb..2f28b3fda 100644 --- a/src/test/regress/expected/multi_create_table.out +++ b/src/test/regress/expected/multi_create_table.out @@ -406,4 +406,11 @@ SELECT shardcount FROM pg_dist_colocation WHERE colocationid IN 13 (1 row) +CREATE TEMP TABLE temp_table(a int); +-- make sure temp table cannot be distributed and we give a good error +select create_distributed_table('temp_table', 'a'); +ERROR: cannot distribute a temporary table +select create_reference_table('temp_table'); +ERROR: cannot distribute a temporary table +DROP TABLE temp_table; DROP TABLE shard_count_table_3; diff --git a/src/test/regress/sql/multi_create_table.sql b/src/test/regress/sql/multi_create_table.sql index b347987eb..48210a187 100644 --- a/src/test/regress/sql/multi_create_table.sql +++ b/src/test/regress/sql/multi_create_table.sql @@ -265,4 +265,10 @@ SELECT shardcount FROM pg_dist_colocation WHERE colocationid IN SELECT colocation_id FROM citus_tables WHERE table_name = 'shard_count_table_3'::regclass ); +CREATE TEMP TABLE temp_table(a int); +-- make sure temp table cannot be distributed and we give a good error +select create_distributed_table('temp_table', 'a'); +select create_reference_table('temp_table'); +DROP TABLE temp_table; + DROP TABLE shard_count_table_3;