🌐 AI搜索 & 代理 主页
Skip to content

Commit 3888391

Browse files
committed
CREATE STATISTICS: improve misleading error message
The previous change (commit f225473) was still not on target, because it talked about relation kinds, which are not what is being checked here. Provide a more accurate message. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CACJufxEZ48toGH0Em_6vdsT57Y3L8pLF=DZCQ_gCii6=C3MeXw@mail.gmail.com
1 parent c11ac81 commit 3888391

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/backend/tcop/utility.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,8 +1883,7 @@ ProcessUtilitySlow(ParseState *pstate,
18831883
if (!IsA(rel, RangeVar))
18841884
ereport(ERROR,
18851885
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1886-
errmsg("cannot create statistics on the specified relation"),
1887-
errdetail("CREATE STATISTICS only supports tables, foreign tables and materialized views.")));
1886+
errmsg("CREATE STATISTICS only supports relation names in the FROM clause")));
18881887

18891888
/*
18901889
* CREATE STATISTICS will influence future execution plans

src/test/regress/expected/stats_ext.out

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,22 @@ CREATE STATISTICS tst (unrecognized) ON x, y FROM ext_stats_test;
5656
ERROR: unrecognized statistics kind "unrecognized"
5757
-- unsupported targets
5858
CREATE STATISTICS tst ON a FROM (VALUES (x)) AS foo;
59-
ERROR: cannot create statistics on the specified relation
60-
DETAIL: CREATE STATISTICS only supports tables, foreign tables and materialized views.
59+
ERROR: CREATE STATISTICS only supports relation names in the FROM clause
6160
CREATE STATISTICS tst ON a FROM foo NATURAL JOIN bar;
62-
ERROR: cannot create statistics on the specified relation
63-
DETAIL: CREATE STATISTICS only supports tables, foreign tables and materialized views.
61+
ERROR: CREATE STATISTICS only supports relation names in the FROM clause
6462
CREATE STATISTICS tst ON a FROM (SELECT * FROM ext_stats_test) AS foo;
65-
ERROR: cannot create statistics on the specified relation
66-
DETAIL: CREATE STATISTICS only supports tables, foreign tables and materialized views.
63+
ERROR: CREATE STATISTICS only supports relation names in the FROM clause
6764
CREATE STATISTICS tst ON a FROM ext_stats_test s TABLESAMPLE system (x);
68-
ERROR: cannot create statistics on the specified relation
69-
DETAIL: CREATE STATISTICS only supports tables, foreign tables and materialized views.
65+
ERROR: CREATE STATISTICS only supports relation names in the FROM clause
7066
CREATE STATISTICS tst ON a FROM XMLTABLE('foo' PASSING 'bar' COLUMNS a text);
71-
ERROR: cannot create statistics on the specified relation
72-
DETAIL: CREATE STATISTICS only supports tables, foreign tables and materialized views.
67+
ERROR: CREATE STATISTICS only supports relation names in the FROM clause
7368
CREATE STATISTICS tst ON a FROM JSON_TABLE(jsonb '123', '$' COLUMNS (item int));
74-
ERROR: cannot create statistics on the specified relation
75-
DETAIL: CREATE STATISTICS only supports tables, foreign tables and materialized views.
69+
ERROR: CREATE STATISTICS only supports relation names in the FROM clause
7670
CREATE FUNCTION tftest(int) returns table(a int, b int) as $$
7771
SELECT $1, $1+i FROM generate_series(1,5) g(i);
7872
$$ LANGUAGE sql IMMUTABLE STRICT;
7973
CREATE STATISTICS alt_stat2 ON a FROM tftest(1);
80-
ERROR: cannot create statistics on the specified relation
81-
DETAIL: CREATE STATISTICS only supports tables, foreign tables and materialized views.
74+
ERROR: CREATE STATISTICS only supports relation names in the FROM clause
8275
DROP FUNCTION tftest;
8376
-- incorrect expressions
8477
CREATE STATISTICS tst ON (y) FROM ext_stats_test; -- single column reference

0 commit comments

Comments
 (0)