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

Commitbbba59e

Browse files
committed
Remove ATT_TABLE for ALTER TABLE ... ATTACH/DETACH
Attempting these commands for a non-partitioned table would result in afailure when creating the relation in transformPartitionCmd(). Thisgives the possibility to throw an error earlier with a much better errormessage, thanks tod69a3f4.The extra test cases are from me. Note that FINALIZE uses a differentsubcommand and it had no coverage for its failure path withnon-partitioned tables.Author: Álvaro Herrera, Michael PaquierReviewed-by: Nathan BossartDiscussion:https://postgr.es/m/202409190803.tnis52adt2n5@alvherre.pgsql
1 parent75240f6 commitbbba59e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5107,19 +5107,17 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
51075107
break;
51085108
case AT_AttachPartition:
51095109
ATSimplePermissions(cmd->subtype, rel,
5110-
ATT_TABLE |ATT_PARTITIONED_TABLE | ATT_PARTITIONED_INDEX);
5110+
ATT_PARTITIONED_TABLE | ATT_PARTITIONED_INDEX);
51115111
/* No command-specific prep needed */
51125112
pass = AT_PASS_MISC;
51135113
break;
51145114
case AT_DetachPartition:
5115-
ATSimplePermissions(cmd->subtype, rel,
5116-
ATT_TABLE | ATT_PARTITIONED_TABLE);
5115+
ATSimplePermissions(cmd->subtype, rel, ATT_PARTITIONED_TABLE);
51175116
/* No command-specific prep needed */
51185117
pass = AT_PASS_MISC;
51195118
break;
51205119
case AT_DetachPartitionFinalize:
5121-
ATSimplePermissions(cmd->subtype, rel,
5122-
ATT_TABLE | ATT_PARTITIONED_TABLE);
5120+
ATSimplePermissions(cmd->subtype, rel, ATT_PARTITIONED_TABLE);
51235121
/* No command-specific prep needed */
51245122
pass = AT_PASS_MISC;
51255123
break;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,7 +3911,8 @@ CREATE TABLE unparted (
39113911
);
39123912
CREATE TABLE fail_part (like unparted);
39133913
ALTER TABLE unparted ATTACH PARTITION fail_part FOR VALUES IN ('a');
3914-
ERROR: table "unparted" is not partitioned
3914+
ERROR: ALTER action ATTACH PARTITION cannot be performed on relation "unparted"
3915+
DETAIL: This operation is not supported for tables.
39153916
DROP TABLE unparted, fail_part;
39163917
-- check that partition bound is compatible
39173918
CREATE TABLE list_parted (
@@ -4281,7 +4282,14 @@ DROP TABLE fail_part;
42814282
-- check that the table is partitioned at all
42824283
CREATE TABLE regular_table (a int);
42834284
ALTER TABLE regular_table DETACH PARTITION any_name;
4284-
ERROR: table "regular_table" is not partitioned
4285+
ERROR: ALTER action DETACH PARTITION cannot be performed on relation "regular_table"
4286+
DETAIL: This operation is not supported for tables.
4287+
ALTER TABLE regular_table DETACH PARTITION any_name CONCURRENTLY;
4288+
ERROR: ALTER action DETACH PARTITION cannot be performed on relation "regular_table"
4289+
DETAIL: This operation is not supported for tables.
4290+
ALTER TABLE regular_table DETACH PARTITION any_name FINALIZE;
4291+
ERROR: ALTER action DETACH PARTITION ... FINALIZE cannot be performed on relation "regular_table"
4292+
DETAIL: This operation is not supported for tables.
42854293
DROP TABLE regular_table;
42864294
-- check that the partition being detached exists at all
42874295
ALTER TABLE list_parted2 DETACH PARTITION part_4;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,8 @@ DROP TABLE fail_part;
27422742
-- check that the table is partitioned at all
27432743
CREATETABLEregular_table (aint);
27442744
ALTERTABLE regular_table DETACH PARTITION any_name;
2745+
ALTERTABLE regular_table DETACH PARTITION any_name CONCURRENTLY;
2746+
ALTERTABLE regular_table DETACH PARTITION any_name FINALIZE;
27452747
DROPTABLE regular_table;
27462748

27472749
-- check that the partition being detached exists at all

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp