Skip to content

Commit 6256846

Browse files
author
Commitfest Bot
committed
[CF 5992] v3 - Fix ALTER TABLE DROP EXPRESSION with ONLY option
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5992 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CALdSSPigTFDUAsEmGtt3RdXYpbzWFpDcmwKasuxNDdXswDf19A@mail.gmail.com Author(s): Jian He
2 parents e633fa6 + fbf5ce9 commit 6256846

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8733,11 +8733,12 @@ ATPrepDropExpression(Relation rel, AlterTableCmd *cmd, bool recurse, bool recurs
87338733
* tables, somewhat similar to how DROP COLUMN does it, so that the
87348734
* resulting state can be properly dumped and restored.
87358735
*/
8736-
if (!recurse &&
8736+
if (!recurse && !recursing &&
87378737
find_inheritance_children(RelationGetRelid(rel), lockmode))
87388738
ereport(ERROR,
8739-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8740-
errmsg("ALTER TABLE / DROP EXPRESSION must be applied to child tables too")));
8739+
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8740+
errmsg("ALTER TABLE / DROP EXPRESSION must be applied to child tables too"),
8741+
errhint("Do not specify the ONLY keyword."));
87418742

87428743
/*
87438744
* Cannot drop generation expression from inherited columns.

src/test/regress/expected/generated_stored.out

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ CREATE TABLE gtest30 (
12641264
b int GENERATED ALWAYS AS (a * 2) STORED
12651265
);
12661266
CREATE TABLE gtest30_1 () INHERITS (gtest30);
1267+
CREATE TABLE gtest30_1_1 () INHERITS (gtest30_1);
12671268
ALTER TABLE gtest30 ALTER COLUMN b DROP EXPRESSION;
12681269
\d gtest30
12691270
Table "generated_stored_tests.gtest30"
@@ -1280,16 +1281,28 @@ Number of child tables: 1 (Use \d+ to list them.)
12801281
a | integer | | |
12811282
b | integer | | |
12821283
Inherits: gtest30
1284+
Number of child tables: 1 (Use \d+ to list them.)
1285+
1286+
\d gtest30_1_1
1287+
Table "generated_stored_tests.gtest30_1_1"
1288+
Column | Type | Collation | Nullable | Default
1289+
--------+---------+-----------+----------+---------
1290+
a | integer | | |
1291+
b | integer | | |
1292+
Inherits: gtest30_1
12831293

12841294
DROP TABLE gtest30 CASCADE;
1285-
NOTICE: drop cascades to table gtest30_1
1295+
NOTICE: drop cascades to 2 other objects
1296+
DETAIL: drop cascades to table gtest30_1
1297+
drop cascades to table gtest30_1_1
12861298
CREATE TABLE gtest30 (
12871299
a int,
12881300
b int GENERATED ALWAYS AS (a * 2) STORED
12891301
);
12901302
CREATE TABLE gtest30_1 () INHERITS (gtest30);
12911303
ALTER TABLE ONLY gtest30 ALTER COLUMN b DROP EXPRESSION; -- error
12921304
ERROR: ALTER TABLE / DROP EXPRESSION must be applied to child tables too
1305+
HINT: Do not specify the ONLY keyword.
12931306
\d gtest30
12941307
Table "generated_stored_tests.gtest30"
12951308
Column | Type | Collation | Nullable | Default

src/test/regress/expected/generated_virtual.out

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ CREATE TABLE gtest30 (
12321232
b int GENERATED ALWAYS AS (a * 2) VIRTUAL
12331233
);
12341234
CREATE TABLE gtest30_1 () INHERITS (gtest30);
1235+
CREATE TABLE gtest30_1_1 () INHERITS (gtest30_1);
12351236
ALTER TABLE gtest30 ALTER COLUMN b DROP EXPRESSION;
12361237
ERROR: ALTER TABLE / DROP EXPRESSION is not supported for virtual generated columns
12371238
DETAIL: Column "b" of relation "gtest30" is a virtual generated column.
@@ -1250,16 +1251,28 @@ Number of child tables: 1 (Use \d+ to list them.)
12501251
a | integer | | |
12511252
b | integer | | | generated always as (a * 2)
12521253
Inherits: gtest30
1254+
Number of child tables: 1 (Use \d+ to list them.)
1255+
1256+
\d gtest30_1_1
1257+
Table "generated_virtual_tests.gtest30_1_1"
1258+
Column | Type | Collation | Nullable | Default
1259+
--------+---------+-----------+----------+-----------------------------
1260+
a | integer | | |
1261+
b | integer | | | generated always as (a * 2)
1262+
Inherits: gtest30_1
12531263

12541264
DROP TABLE gtest30 CASCADE;
1255-
NOTICE: drop cascades to table gtest30_1
1265+
NOTICE: drop cascades to 2 other objects
1266+
DETAIL: drop cascades to table gtest30_1
1267+
drop cascades to table gtest30_1_1
12561268
CREATE TABLE gtest30 (
12571269
a int,
12581270
b int GENERATED ALWAYS AS (a * 2) VIRTUAL
12591271
);
12601272
CREATE TABLE gtest30_1 () INHERITS (gtest30);
12611273
ALTER TABLE ONLY gtest30 ALTER COLUMN b DROP EXPRESSION; -- error
12621274
ERROR: ALTER TABLE / DROP EXPRESSION must be applied to child tables too
1275+
HINT: Do not specify the ONLY keyword.
12631276
\d gtest30
12641277
Table "generated_virtual_tests.gtest30"
12651278
Column | Type | Collation | Nullable | Default

src/test/regress/sql/generated_stored.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,11 @@ CREATE TABLE gtest30 (
577577
b int GENERATED ALWAYS AS (a * 2) STORED
578578
);
579579
CREATE TABLE gtest30_1 () INHERITS (gtest30);
580+
CREATE TABLE gtest30_1_1 () INHERITS (gtest30_1);
580581
ALTER TABLE gtest30 ALTER COLUMN b DROP EXPRESSION;
581582
\d gtest30
582583
\d gtest30_1
584+
\d gtest30_1_1
583585
DROP TABLE gtest30 CASCADE;
584586
CREATE TABLE gtest30 (
585587
a int,

src/test/regress/sql/generated_virtual.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,11 @@ CREATE TABLE gtest30 (
628628
b int GENERATED ALWAYS AS (a * 2) VIRTUAL
629629
);
630630
CREATE TABLE gtest30_1 () INHERITS (gtest30);
631+
CREATE TABLE gtest30_1_1 () INHERITS (gtest30_1);
631632
ALTER TABLE gtest30 ALTER COLUMN b DROP EXPRESSION;
632633
\d gtest30
633634
\d gtest30_1
635+
\d gtest30_1_1
634636
DROP TABLE gtest30 CASCADE;
635637
CREATE TABLE gtest30 (
636638
a int,

0 commit comments

Comments
 (0)