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

Commit0c83eb2

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 parentb4842a8 commit0c83eb2

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6029,6 +6029,12 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
60296029
case ATT_TABLE | ATT_MATVIEW | ATT_INDEX:
60306030
msg = _("\"%s\" is not a table, materialized view, or index");
60316031
break;
6032+
case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX:
6033+
msg = _("\"%s\" is not a table, materialized view, index, or partitioned index");
6034+
break;
6035+
case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX | ATT_FOREIGN_TABLE:
6036+
msg = _("\"%s\" is not a table, materialized view, index, partitioned index, or foreign table");
6037+
break;
60326038
case ATT_TABLE | ATT_MATVIEW | ATT_FOREIGN_TABLE:
60336039
msg = _("\"%s\" is not a table, materialized view, or foreign table");
60346040
break;
@@ -6041,6 +6047,9 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
60416047
case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_FOREIGN_TABLE:
60426048
msg = _("\"%s\" is not a table, materialized view, index, or foreign table");
60436049
break;
6050+
case ATT_TABLE | ATT_PARTITIONED_INDEX:
6051+
msg = _("\"%s\" is not a table or partitioned index");
6052+
break;
60446053
case ATT_VIEW:
60456054
msg = _("\"%s\" is not a view");
60466055
break;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ ALTER INDEX attmp_idx ALTER COLUMN 4 SET STATISTICS 1000;
120120
ERROR: column number 4 of relation "attmp_idx" does not exist
121121
ALTER INDEX attmp_idx ALTER COLUMN 2 SET STATISTICS -1;
122122
DROP TABLE attmp;
123+
-- fails with incorrect object type
124+
CREATE VIEW at_v1 AS SELECT 1 as a;
125+
ALTER TABLE at_v1 ALTER COLUMN a SET STATISTICS 0;
126+
ERROR: "at_v1" is not a table, materialized view, index, partitioned index, or foreign table
127+
DROP VIEW at_v1;
123128
--
124129
-- rename - check on both non-temp and temp tables
125130
--
@@ -4111,6 +4116,11 @@ ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 3, R
41114116
ERROR: every hash partition modulus must be a factor of the next larger modulus
41124117
DETAIL: The new modulus 3 is not a factor of 4, the modulus of existing partition "hpart_1".
41134118
DROP TABLE fail_part;
4119+
-- fails with incorrect object type
4120+
CREATE VIEW at_v1 AS SELECT 1 as a;
4121+
ALTER TABLE at_v1 ATTACH PARTITION dummy default;
4122+
ERROR: "at_v1" is not a table or partitioned index
4123+
DROP VIEW at_v1;
41144124
--
41154125
-- DETACH PARTITION
41164126
--

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,8 @@ ALTER FOREIGN TABLE ft1 DROP COLUMN c9;
880880
ALTER FOREIGN TABLE ft1 SET SCHEMA foreign_schema;
881881
ALTER FOREIGN TABLE ft1 SET TABLESPACE ts; -- ERROR
882882
ERROR: relation "ft1" does not exist
883+
ALTER FOREIGN TABLE foreign_schema.ft1 SET TABLESPACE ts; -- ERROR
884+
ERROR: "ft1" is not a table, materialized view, index, or partitioned index
883885
ALTER FOREIGN TABLE foreign_schema.ft1 RENAME c1 TO foreign_column_1;
884886
ALTER FOREIGN TABLE foreign_schema.ft1 RENAME TO foreign_table_1;
885887
\d foreign_schema.foreign_table_1

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ ALTER INDEX attmp_idx ALTER COLUMN 2 SET STATISTICS -1;
158158

159159
DROPTABLE attmp;
160160

161+
-- fails with incorrect object type
162+
CREATEVIEWat_v1ASSELECT1as a;
163+
ALTERTABLE at_v1 ALTER COLUMN aSET STATISTICS0;
164+
DROPVIEW at_v1;
161165

162166
--
163167
-- rename - check on both non-temp and temp tables
@@ -2640,6 +2644,11 @@ ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 8, R
26402644
ALTERTABLE hash_parted ATTACH PARTITION fail_part FORVALUES WITH (MODULUS3, REMAINDER2);
26412645
DROPTABLE fail_part;
26422646

2647+
-- fails with incorrect object type
2648+
CREATEVIEWat_v1ASSELECT1as a;
2649+
ALTERTABLE at_v1 ATTACH PARTITION dummy default;
2650+
DROPVIEW at_v1;
2651+
26432652
--
26442653
-- DETACH PARTITION
26452654
--

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ ALTER FOREIGN TABLE ft1 DROP COLUMN IF EXISTS no_column;
408408
ALTER FOREIGN TABLE ft1 DROP COLUMN c9;
409409
ALTER FOREIGN TABLE ft1SET SCHEMA foreign_schema;
410410
ALTER FOREIGN TABLE ft1SET TABLESPACE ts;-- ERROR
411+
ALTER FOREIGN TABLEforeign_schema.ft1SET TABLESPACE ts;-- ERROR
411412
ALTER FOREIGN TABLEforeign_schema.ft1 RENAME c1 TO foreign_column_1;
412413
ALTER FOREIGN TABLEforeign_schema.ft1 RENAME TO foreign_table_1;
413414
\dforeign_schema.foreign_table_1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp