Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3eea4dc

Browse files
committed
CREATE STATISTICS: improve misleading error message
I think the error message for a different condition was inadvertentlycopied.This problem seems to have been introduced by commita4d75c8.Author: Álvaro Herrera <alvherre@kurilemu.de>Reported-by: jian he <jian.universality@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Backpatch-through: 14Discussion:https://postgr.es/m/CACJufxEZ48toGH0Em_6vdsT57Y3L8pLF=DZCQ_gCii6=C3MeXw@mail.gmail.com
1 parentd1073c3 commit3eea4dc

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

‎src/backend/tcop/utility.c‎

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

18881889
/*
18891890
* CREATE STATISTICS will influence future execution plans

‎src/test/regress/expected/stats_ext.out‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ CREATE STATISTICS tst ON (x || 'x'), (x || 'x'), y FROM ext_stats_test;
5454
ERROR: duplicate expression in statistics definition
5555
CREATE STATISTICS tst (unrecognized) ON x, y FROM ext_stats_test;
5656
ERROR: unrecognized statistics kind "unrecognized"
57+
-- unsupported targets
58+
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.
61+
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.
64+
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.
67+
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.
70+
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.
73+
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.
76+
CREATE FUNCTION tftest(int) returns table(a int, b int) as $$
77+
SELECT $1, $1+i FROM generate_series(1,5) g(i);
78+
$$ LANGUAGE sql IMMUTABLE STRICT;
79+
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.
82+
DROP FUNCTION tftest;
5783
-- incorrect expressions
5884
CREATE STATISTICS tst ON (y) FROM ext_stats_test; -- single column reference
5985
ERROR: extended statistics require at least 2 columns

‎src/test/regress/sql/stats_ext.sql‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ CREATE STATISTICS tst ON x, x, y, x, x, (x || 'x'), (y + 1), (x || 'x'), (x || '
4040
CREATE STATISTICS tstON (x||'x'), (x||'x'), (y+1), (x||'x'), (x||'x'), (y+1), (x||'x'), (x||'x'), (y+1)FROM ext_stats_test;
4141
CREATE STATISTICS tstON (x||'x'), (x||'x'), yFROM ext_stats_test;
4242
CREATE STATISTICS tst (unrecognized)ON x, yFROM ext_stats_test;
43+
-- unsupported targets
44+
CREATE STATISTICS tstON aFROM (VALUES (x))AS foo;
45+
CREATE STATISTICS tstON aFROM fooNATURAL JOIN bar;
46+
CREATE STATISTICS tstON aFROM (SELECT*FROM ext_stats_test)AS foo;
47+
CREATE STATISTICS tstON aFROM ext_stats_test s TABLESAMPLE system (x);
48+
CREATE STATISTICS tstON aFROM XMLTABLE('foo' PASSING'bar' COLUMNS atext);
49+
CREATE STATISTICS tstON aFROM JSON_TABLE(jsonb'123','$' COLUMNS (itemint));
50+
CREATEFUNCTIONtftest(int) returns table(aint, bint)as $$
51+
SELECT $1, $1+iFROM generate_series(1,5) g(i);
52+
$$ LANGUAGE sql IMMUTABLE STRICT;
53+
CREATE STATISTICS alt_stat2ON aFROM tftest(1);
54+
DROPFUNCTION tftest;
4355
-- incorrect expressions
4456
CREATE STATISTICS tstON (y)FROM ext_stats_test;-- single column reference
4557
CREATE STATISTICS tstON y+ zFROM ext_stats_test;-- missing parentheses

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp