diff --git a/src/backend/distributed/deparser/qualify_statistics_stmt.c b/src/backend/distributed/deparser/qualify_statistics_stmt.c index b176b66c2..254005bd5 100644 --- a/src/backend/distributed/deparser/qualify_statistics_stmt.c +++ b/src/backend/distributed/deparser/qualify_statistics_stmt.c @@ -42,6 +42,12 @@ QualifyCreateStatisticsStmt(Node *node) relation->schemaname = get_namespace_name(schemaOid); } + if (list_length(stmt->defnames) < 1) + { + /* no name to qualify */ + return; + } + RangeVar *stat = makeRangeVarFromNameList(stmt->defnames); if (stat->schemaname == NULL) diff --git a/src/test/regress/expected/pg14.out b/src/test/regress/expected/pg14.out index dcf21f097..f2cc76285 100644 --- a/src/test/regress/expected/pg14.out +++ b/src/test/regress/expected/pg14.out @@ -1364,6 +1364,18 @@ SELECT count(*) FROM pg14.foreign_table; TRUNCATE foreign_table; ERROR: truncating foreign tables that are added to metadata can only be excuted on the coordinator \c - - - :master_port +SET search_path TO pg14; +-- an example with CREATE TABLE LIKE, with statistics with expressions +CREATE TABLE ctlt1 (a text CHECK (length(a) > 2) PRIMARY KEY, b text); +CREATE STATISTICS ctlt1_expr_stat ON (a || b) FROM ctlt1; +CREATE TABLE ctlt_all (LIKE ctlt1 INCLUDING ALL); +SELECT create_distributed_table('ctlt1', 'a'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +CREATE TABLE ctlt_all_2 (LIKE ctlt1 INCLUDING ALL); -- cleanup set client_min_messages to error; drop extension postgres_fdw cascade; diff --git a/src/test/regress/sql/pg14.sql b/src/test/regress/sql/pg14.sql index bda6c5b0d..2c400efca 100644 --- a/src/test/regress/sql/pg14.sql +++ b/src/test/regress/sql/pg14.sql @@ -706,6 +706,13 @@ SELECT count(*) FROM pg14.foreign_table; -- should error out TRUNCATE foreign_table; \c - - - :master_port +SET search_path TO pg14; +-- an example with CREATE TABLE LIKE, with statistics with expressions +CREATE TABLE ctlt1 (a text CHECK (length(a) > 2) PRIMARY KEY, b text); +CREATE STATISTICS ctlt1_expr_stat ON (a || b) FROM ctlt1; +CREATE TABLE ctlt_all (LIKE ctlt1 INCLUDING ALL); +SELECT create_distributed_table('ctlt1', 'a'); +CREATE TABLE ctlt_all_2 (LIKE ctlt1 INCLUDING ALL); -- cleanup set client_min_messages to error; drop extension postgres_fdw cascade;