diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 97a9725df7..d02e01cb20 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -6029,6 +6029,12 @@ ATWrongRelkindError(Relation rel, int allowed_targets) case ATT_TABLE | ATT_MATVIEW | ATT_INDEX: msg = _("\"%s\" is not a table, materialized view, or index"); break; + case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX: + msg = _("\"%s\" is not a table, materialized view, index, or partitioned index"); + break; + case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX | ATT_FOREIGN_TABLE: + msg = _("\"%s\" is not a table, materialized view, index, partitioned index, or foreign table"); + break; case ATT_TABLE | ATT_MATVIEW | ATT_FOREIGN_TABLE: msg = _("\"%s\" is not a table, materialized view, or foreign table"); break; @@ -6041,6 +6047,9 @@ ATWrongRelkindError(Relation rel, int allowed_targets) case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_FOREIGN_TABLE: msg = _("\"%s\" is not a table, materialized view, index, or foreign table"); break; + case ATT_TABLE | ATT_PARTITIONED_INDEX: + msg = _("\"%s\" is not a table or partitioned index"); + break; case ATT_VIEW: msg = _("\"%s\" is not a view"); break; diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index f81bdf513b..cfa1215c7f 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -120,6 +120,11 @@ ALTER INDEX attmp_idx ALTER COLUMN 4 SET STATISTICS 1000; ERROR: column number 4 of relation "attmp_idx" does not exist ALTER INDEX attmp_idx ALTER COLUMN 2 SET STATISTICS -1; DROP TABLE attmp; +-- fails with incorrect object type +CREATE VIEW at_v1 AS SELECT 1 as a; +ALTER TABLE at_v1 ALTER COLUMN a SET STATISTICS 0; +ERROR: "at_v1" is not a table, materialized view, index, partitioned index, or foreign table +DROP VIEW at_v1; -- -- rename - check on both non-temp and temp tables -- @@ -4111,6 +4116,11 @@ ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 3, R ERROR: every hash partition modulus must be a factor of the next larger modulus DETAIL: The new modulus 3 is not a factor of 4, the modulus of existing partition "hpart_1". DROP TABLE fail_part; +-- fails with incorrect object type +CREATE VIEW at_v1 AS SELECT 1 as a; +ALTER TABLE at_v1 ATTACH PARTITION dummy default; +ERROR: "at_v1" is not a table or partitioned index +DROP VIEW at_v1; -- -- DETACH PARTITION -- diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out index 5385f98a0f..90ba1ff595 100644 --- a/src/test/regress/expected/foreign_data.out +++ b/src/test/regress/expected/foreign_data.out @@ -880,6 +880,8 @@ ALTER FOREIGN TABLE ft1 DROP COLUMN c9; ALTER FOREIGN TABLE ft1 SET SCHEMA foreign_schema; ALTER FOREIGN TABLE ft1 SET TABLESPACE ts; -- ERROR ERROR: relation "ft1" does not exist +ALTER FOREIGN TABLE foreign_schema.ft1 SET TABLESPACE ts; -- ERROR +ERROR: "ft1" is not a table, materialized view, index, or partitioned index ALTER FOREIGN TABLE foreign_schema.ft1 RENAME c1 TO foreign_column_1; ALTER FOREIGN TABLE foreign_schema.ft1 RENAME TO foreign_table_1; \d foreign_schema.foreign_table_1 diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index dc0200adcb..b269444acb 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -158,6 +158,10 @@ ALTER INDEX attmp_idx ALTER COLUMN 2 SET STATISTICS -1; DROP TABLE attmp; +-- fails with incorrect object type +CREATE VIEW at_v1 AS SELECT 1 as a; +ALTER TABLE at_v1 ALTER COLUMN a SET STATISTICS 0; +DROP VIEW at_v1; -- -- 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 ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 3, REMAINDER 2); DROP TABLE fail_part; +-- fails with incorrect object type +CREATE VIEW at_v1 AS SELECT 1 as a; +ALTER TABLE at_v1 ATTACH PARTITION dummy default; +DROP VIEW at_v1; + -- -- DETACH PARTITION -- diff --git a/src/test/regress/sql/foreign_data.sql b/src/test/regress/sql/foreign_data.sql index 73f9f621d8..279786f4bf 100644 --- a/src/test/regress/sql/foreign_data.sql +++ b/src/test/regress/sql/foreign_data.sql @@ -408,6 +408,7 @@ ALTER FOREIGN TABLE ft1 DROP COLUMN IF EXISTS no_column; ALTER FOREIGN TABLE ft1 DROP COLUMN c9; ALTER FOREIGN TABLE ft1 SET SCHEMA foreign_schema; ALTER FOREIGN TABLE ft1 SET TABLESPACE ts; -- ERROR +ALTER FOREIGN TABLE foreign_schema.ft1 SET TABLESPACE ts; -- ERROR ALTER FOREIGN TABLE foreign_schema.ft1 RENAME c1 TO foreign_column_1; ALTER FOREIGN TABLE foreign_schema.ft1 RENAME TO foreign_table_1; \d foreign_schema.foreign_table_1