diff options
| author | Peter Eisentraut <peter@eisentraut.org> | 2021-07-08 09:38:52 +0200 |
|---|---|---|
| committer | Peter Eisentraut <peter@eisentraut.org> | 2021-07-08 09:44:51 +0200 |
| commit | 2ed532ee8c474e9767e76e1f3251cc3a0224358c (patch) | |
| tree | 3365ea8086789ae6b1b0ddf3a3edd16459075a7d /src/test | |
| parent | b9734c13f168ef0d487aa122e486ca9b6dd6aa59 (diff) | |
Improve error messages about mismatching relkind
Most error messages about a relkind that was not supported or
appropriate for the command was of the pattern
"relation \"%s\" is not a table, foreign table, or materialized view"
This style can become verbose and tedious to maintain. Moreover, it's
not very helpful: If I'm trying to create a comment on a TOAST table,
which is not supported, then the information that I could have created
a comment on a materialized view is pointless.
Instead, write the primary error message shorter and saying more
directly that what was attempted is not possible. Then, in the detail
message, explain that the operation is not supported for the relkind
the object was. To simplify that, add a new function
errdetail_relkind_not_supported() that does this.
In passing, make use of RELKIND_HAS_STORAGE() where appropriate,
instead of listing out the relkinds individually.
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/dc35a398-37d0-75ce-07ea-1dd71d98f8ec@2ndquadrant.com
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/alter_table.out | 9 | ||||
| -rw-r--r-- | src/test/regress/expected/create_table_like.out | 3 | ||||
| -rw-r--r-- | src/test/regress/expected/foreign_data.out | 6 | ||||
| -rw-r--r-- | src/test/regress/expected/indexing.out | 3 | ||||
| -rw-r--r-- | src/test/regress/expected/sequence.out | 3 | ||||
| -rw-r--r-- | src/test/regress/expected/stats_ext.out | 12 |
6 files changed, 24 insertions, 12 deletions
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index f81bdf513b6..8dcb00ac67a 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -1087,9 +1087,11 @@ ERROR: column "bar" of relation "atacc1" does not exist -- try creating a view and altering that, should fail create view myview as select * from atacc1; alter table myview alter column test drop not null; -ERROR: "myview" is not a table or foreign table +ERROR: ALTER action ALTER COLUMN ... DROP NOT NULL cannot be performed on relation "myview" +DETAIL: This operation is not supported for views. alter table myview alter column test set not null; -ERROR: "myview" is not a table or foreign table +ERROR: ALTER action ALTER COLUMN ... SET NOT NULL cannot be performed on relation "myview" +DETAIL: This operation is not supported for views. drop view myview; drop table atacc1; -- set not null verified by constraints @@ -1387,7 +1389,8 @@ select * from myview; (0 rows) alter table myview drop d; -ERROR: "myview" is not a table, composite type, or foreign table +ERROR: ALTER action DROP COLUMN cannot be performed on relation "myview" +DETAIL: This operation is not supported for views. drop view myview; -- test some commands to make sure they fail on the dropped column analyze atacc1(a); diff --git a/src/test/regress/expected/create_table_like.out b/src/test/regress/expected/create_table_like.out index 4dc5e6aa5fb..7ad5fafe936 100644 --- a/src/test/regress/expected/create_table_like.out +++ b/src/test/regress/expected/create_table_like.out @@ -504,9 +504,10 @@ DROP TABLE noinh_con_copy, noinh_con_copy1; CREATE TABLE ctlt4 (a int, b text); CREATE SEQUENCE ctlseq1; CREATE TABLE ctlt10 (LIKE ctlseq1); -- fail -ERROR: "ctlseq1" is not a table, view, materialized view, composite type, or foreign table +ERROR: relation "ctlseq1" is invalid in LIKE clause LINE 1: CREATE TABLE ctlt10 (LIKE ctlseq1); ^ +DETAIL: This operation is not supported for sequences. CREATE VIEW ctlv1 AS SELECT * FROM ctlt4; CREATE TABLE ctlt11 (LIKE ctlv1); CREATE TABLE ctlt11a (LIKE ctlv1 INCLUDING ALL); diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out index 5385f98a0fe..809d40a79a9 100644 --- a/src/test/regress/expected/foreign_data.out +++ b/src/test/regress/expected/foreign_data.out @@ -740,7 +740,8 @@ FDW options: (delimiter ',', quote '"', "be quoted" 'value') (1 row) CREATE INDEX id_ft1_c2 ON ft1 (c2); -- ERROR -ERROR: cannot create index on foreign table "ft1" +ERROR: cannot create index on relation "ft1" +DETAIL: This operation is not supported for foreign tables. SELECT * FROM ft1; -- ERROR ERROR: foreign-data wrapper "dummy" has no handler EXPLAIN SELECT * FROM ft1; -- ERROR @@ -864,7 +865,8 @@ LINE 1: ALTER FOREIGN TABLE ft1 ADD PRIMARY KEY (c7); ^ ALTER FOREIGN TABLE ft1 ADD CONSTRAINT ft1_c9_check CHECK (c9 < 0) NOT VALID; ALTER FOREIGN TABLE ft1 ALTER CONSTRAINT ft1_c9_check DEFERRABLE; -- ERROR -ERROR: "ft1" is not a table +ERROR: ALTER action ALTER CONSTRAINT cannot be performed on relation "ft1" +DETAIL: This operation is not supported for foreign tables. ALTER FOREIGN TABLE ft1 DROP CONSTRAINT ft1_c9_check; ALTER FOREIGN TABLE ft1 DROP CONSTRAINT no_const; -- ERROR ERROR: constraint "no_const" of relation "ft1" does not exist diff --git a/src/test/regress/expected/indexing.out b/src/test/regress/expected/indexing.out index c93f4470c92..193f7801912 100644 --- a/src/test/regress/expected/indexing.out +++ b/src/test/regress/expected/indexing.out @@ -137,7 +137,8 @@ select relname, relpartbound from pg_class (2 rows) alter table idxpart_c detach partition idxpart1_c; -ERROR: "idxpart_c" is not a table +ERROR: ALTER action DETACH PARTITION cannot be performed on relation "idxpart_c" +DETAIL: This operation is not supported for partitioned indexes. drop table idxpart; -- If a partition already has an index, don't create a duplicative one create table idxpart (a int, b int) partition by range (a, b); diff --git a/src/test/regress/expected/sequence.out b/src/test/regress/expected/sequence.out index 8b928b28882..71c2b0f1dff 100644 --- a/src/test/regress/expected/sequence.out +++ b/src/test/regress/expected/sequence.out @@ -21,7 +21,8 @@ CREATE SEQUENCE sequence_testx OWNED BY nobody; -- nonsense word ERROR: invalid OWNED BY option HINT: Specify OWNED BY table.column or OWNED BY NONE. CREATE SEQUENCE sequence_testx OWNED BY pg_class_oid_index.oid; -- not a table -ERROR: referenced relation "pg_class_oid_index" is not a table or foreign table +ERROR: sequence cannot be owned by relation "pg_class_oid_index" +DETAIL: This operation is not supported for indexes. CREATE SEQUENCE sequence_testx OWNED BY pg_class.relname; -- not same schema ERROR: sequence must be in same schema as table it is linked to CREATE TABLE sequence_test_table (a int); diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out index 8c214d8dfc5..62b05c79f9e 100644 --- a/src/test/regress/expected/stats_ext.out +++ b/src/test/regress/expected/stats_ext.out @@ -211,14 +211,18 @@ CREATE TABLE tststats.pt (a int, b int, c text) PARTITION BY RANGE (a, b); CREATE TABLE tststats.pt1 PARTITION OF tststats.pt FOR VALUES FROM (-10, -10) TO (10, 10); CREATE STATISTICS tststats.s1 ON a, b FROM tststats.t; CREATE STATISTICS tststats.s2 ON a, b FROM tststats.ti; -ERROR: relation "ti" is not a table, foreign table, or materialized view +ERROR: cannot define statistics for relation "ti" +DETAIL: This operation is not supported for indexes. CREATE STATISTICS tststats.s3 ON a, b FROM tststats.s; -ERROR: relation "s" is not a table, foreign table, or materialized view +ERROR: cannot define statistics for relation "s" +DETAIL: This operation is not supported for sequences. CREATE STATISTICS tststats.s4 ON a, b FROM tststats.v; -ERROR: relation "v" is not a table, foreign table, or materialized view +ERROR: cannot define statistics for relation "v" +DETAIL: This operation is not supported for views. CREATE STATISTICS tststats.s5 ON a, b FROM tststats.mv; CREATE STATISTICS tststats.s6 ON a, b FROM tststats.ty; -ERROR: relation "ty" is not a table, foreign table, or materialized view +ERROR: cannot define statistics for relation "ty" +DETAIL: This operation is not supported for composite types. CREATE STATISTICS tststats.s7 ON a, b FROM tststats.f; CREATE STATISTICS tststats.s8 ON a, b FROM tststats.pt; CREATE STATISTICS tststats.s9 ON a, b FROM tststats.pt1; |
