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

Commit85a8c3a

Browse files
committed
Fix unexpected error messages for various flavors of ALTER TABLE
Some commands of ALTER TABLE could fail with the following error:ERROR: "tab" is of the wrong typeThis error is unexpected, as all the code paths leading toATWrongRelkindError() should use a supported set of relkinds to generatecorrect error messages. This commit closes the gap with such mistakes,by adding all the missing relkind combinations. Tests are added tocheck all the problems found. Note that some combinations are not used,but these are left around as it could have an impact on applicationsrelying on this code.2ed532e has done a much larger refactoring on HEAD to make such errormessages easier to manage in the long-term, so nothing is needed there.Author: Kyotaro HoriguchiReviewed-by: Peter Eisentraut, Ahsan Hadi, Michael PaquierDiscussion:https://postgr.es/m/20210216.181415.368926598204753659.horikyota.ntt@gmail.comBackpatch-through: 11
1 parenteff751e commit85a8c3a

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5082,6 +5082,9 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
50825082
caseATT_TABLE |ATT_MATVIEW |ATT_INDEX:
50835083
msg=_("\"%s\" is not a table, materialized view, or index");
50845084
break;
5085+
caseATT_TABLE |ATT_MATVIEW |ATT_INDEX |ATT_PARTITIONED_INDEX:
5086+
msg=_("\"%s\" is not a table, materialized view, index, or partitioned index");
5087+
break;
50855088
caseATT_TABLE |ATT_MATVIEW |ATT_FOREIGN_TABLE:
50865089
msg=_("\"%s\" is not a table, materialized view, or foreign table");
50875090
break;
@@ -5094,6 +5097,9 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
50945097
caseATT_TABLE |ATT_MATVIEW |ATT_INDEX |ATT_FOREIGN_TABLE:
50955098
msg=_("\"%s\" is not a table, materialized view, index, or foreign table");
50965099
break;
5100+
caseATT_TABLE |ATT_PARTITIONED_INDEX:
5101+
msg=_("\"%s\" is not a table or partitioned index");
5102+
break;
50975103
caseATT_VIEW:
50985104
msg=_("\"%s\" is not a view");
50995105
break;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,11 @@ ERROR: remainder for hash partition must be less than modulus
39743974
ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 3, REMAINDER 2);
39753975
ERROR: every hash partition modulus must be a factor of the next larger modulus
39763976
DROP TABLE fail_part;
3977+
-- fails with incorrect object type
3978+
CREATE VIEW at_v1 AS SELECT 1 as a;
3979+
ALTER TABLE at_v1 ATTACH PARTITION dummy default;
3980+
ERROR: "at_v1" is not a partitioned table or index
3981+
DROP VIEW at_v1;
39773982
--
39783983
-- DETACH PARTITION
39793984
--

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,8 @@ ALTER FOREIGN TABLE ft1 DROP COLUMN c9;
885885
ALTER FOREIGN TABLE ft1 SET SCHEMA foreign_schema;
886886
ALTER FOREIGN TABLE ft1 SET TABLESPACE ts; -- ERROR
887887
ERROR: relation "ft1" does not exist
888+
ALTER FOREIGN TABLE foreign_schema.ft1 SET TABLESPACE ts; -- ERROR
889+
ERROR: "ft1" is not a table, materialized view, index, or partitioned index
888890
ALTER FOREIGN TABLE foreign_schema.ft1 RENAME c1 TO foreign_column_1;
889891
ALTER FOREIGN TABLE foreign_schema.ft1 RENAME TO foreign_table_1;
890892
\d foreign_schema.foreign_table_1

‎src/test/regress/sql/alter_table.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,11 @@ ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 8, R
25812581
ALTERTABLE hash_parted ATTACH PARTITION fail_part FORVALUES WITH (MODULUS3, REMAINDER2);
25822582
DROPTABLE fail_part;
25832583

2584+
-- fails with incorrect object type
2585+
CREATEVIEWat_v1ASSELECT1as a;
2586+
ALTERTABLE at_v1 ATTACH PARTITION dummy default;
2587+
DROPVIEW at_v1;
2588+
25842589
--
25852590
-- DETACH PARTITION
25862591
--

‎src/test/regress/sql/foreign_data.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ ALTER FOREIGN TABLE ft1 DROP COLUMN IF EXISTS no_column;
410410
ALTER FOREIGN TABLE ft1 DROP COLUMN c9;
411411
ALTER FOREIGN TABLE ft1SET SCHEMA foreign_schema;
412412
ALTER FOREIGN TABLE ft1SET TABLESPACE ts;-- ERROR
413+
ALTER FOREIGN TABLEforeign_schema.ft1SET TABLESPACE ts;-- ERROR
413414
ALTER FOREIGN TABLEforeign_schema.ft1 RENAME c1 TO foreign_column_1;
414415
ALTER FOREIGN TABLEforeign_schema.ft1 RENAME TO foreign_table_1;
415416
\dforeign_schema.foreign_table_1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp