hi.

in src/test/modules/test_ddl_deparse/sql/alter_table.sql:
----------------------------
ALTER TABLE parent ADD CONSTRAINT a_pos CHECK (a > 0);
CREATE TABLE part (
    a int
) PARTITION BY RANGE (a);

CREATE TABLE part1 PARTITION OF part FOR VALUES FROM (1) to (100);
CREATE TABLE part2 (a int);
ALTER TABLE part ATTACH PARTITION part2 FOR VALUES FROM (101) to (200);
ALTER TABLE part DETACH PARTITION part2;
DROP TABLE part2;
ALTER TABLE part ADD PRIMARY KEY (a);
ALTER TABLE parent ALTER COLUMN a SET NOT NULL;

----
The test initially focuses on the "parent" table, then switches to the "part"
table, and goes back to the "parent" table.
This seems weird?  so I slightly adjusted the order to cover the "parent"
table first, followed by the "part" table.

src/test/modules/test_ddl_deparse/sql/alter_table.sql
don't have ALTER TABLE ALTER COLUMN SET EXPRESSION,
so I added a test on it.
From 55fed544cab5addb108d61f43fe6d2286fcb6f40 Mon Sep 17 00:00:00 2001
From: jian he <jian.universal...@gmail.com>
Date: Sun, 24 Aug 2025 22:51:30 +0800
Subject: [PATCH v1 1/1] refactor test_ddl_deparse/sql/alter_table.sql

1. The test initially focuses on the "parent" table, then switches to the "part"
table, and goes back to the "parent" table.
This seemed inconsistent, so I slightly adjusted the order to cover the "parent"
table first, followed by the "part" table.

2. src/test/modules/test_ddl_deparse/sql/alter_table.sql
don't have ALTER TABLE ALTER COLUMN SET EXPRESSION,
so I add a test on it.

discussion: https://postgr.es/m/
---
 .../test_ddl_deparse/expected/alter_table.out | 41 ++++++++++---------
 .../test_ddl_deparse/sql/alter_table.sql      | 27 ++++++------
 2 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/src/test/modules/test_ddl_deparse/expected/alter_table.out b/src/test/modules/test_ddl_deparse/expected/alter_table.out
index 50d0354a341..f1c6f05fe17 100644
--- a/src/test/modules/test_ddl_deparse/expected/alter_table.out
+++ b/src/test/modules/test_ddl_deparse/expected/alter_table.out
@@ -41,25 +41,6 @@ ALTER TABLE parent ADD CONSTRAINT a_pos CHECK (a > 0);
 NOTICE:  merging constraint "a_pos" with inherited definition
 NOTICE:  DDL test: type alter table, tag ALTER TABLE
 NOTICE:    subcommand: type ADD CONSTRAINT (and recurse) desc constraint a_pos on table parent
-CREATE TABLE part (
-	a int
-) PARTITION BY RANGE (a);
-NOTICE:  DDL test: type simple, tag CREATE TABLE
-CREATE TABLE part1 PARTITION OF part FOR VALUES FROM (1) to (100);
-NOTICE:  DDL test: type simple, tag CREATE TABLE
-CREATE TABLE part2 (a int);
-NOTICE:  DDL test: type simple, tag CREATE TABLE
-ALTER TABLE part ATTACH PARTITION part2 FOR VALUES FROM (101) to (200);
-NOTICE:  DDL test: type alter table, tag ALTER TABLE
-NOTICE:    subcommand: type ATTACH PARTITION desc table part2
-ALTER TABLE part DETACH PARTITION part2;
-NOTICE:  DDL test: type alter table, tag ALTER TABLE
-NOTICE:    subcommand: type DETACH PARTITION desc table part2
-DROP TABLE part2;
-ALTER TABLE part ADD PRIMARY KEY (a);
-NOTICE:  DDL test: type alter table, tag ALTER TABLE
-NOTICE:    subcommand: type ADD CONSTRAINT (and recurse) desc constraint part_a_not_null on table part
-NOTICE:    subcommand: type ADD INDEX desc index part_pkey
 ALTER TABLE parent ALTER COLUMN a SET NOT NULL;
 NOTICE:  DDL test: type alter table, tag ALTER TABLE
 NOTICE:    subcommand: type SET NOT NULL (and recurse) desc constraint parent_a_not_null on table parent
@@ -117,11 +98,33 @@ NOTICE:  DDL test: type alter table, tag ALTER TABLE
 NOTICE:    subcommand: type ALTER COLUMN SET DEFAULT desc column c of table parent
 NOTICE:    subcommand: type ALTER COLUMN SET DEFAULT desc column c of table child
 NOTICE:    subcommand: type ALTER COLUMN SET DEFAULT desc column c of table grandchild
+CREATE TABLE part (
+	a int
+) PARTITION BY RANGE (a);
+NOTICE:  DDL test: type simple, tag CREATE TABLE
+CREATE TABLE part1 PARTITION OF part FOR VALUES FROM (1) to (100);
+NOTICE:  DDL test: type simple, tag CREATE TABLE
+CREATE TABLE part2 (a int);
+NOTICE:  DDL test: type simple, tag CREATE TABLE
+ALTER TABLE part ATTACH PARTITION part2 FOR VALUES FROM (101) to (200);
+NOTICE:  DDL test: type alter table, tag ALTER TABLE
+NOTICE:    subcommand: type ATTACH PARTITION desc table part2
+ALTER TABLE part DETACH PARTITION part2;
+NOTICE:  DDL test: type alter table, tag ALTER TABLE
+NOTICE:    subcommand: type DETACH PARTITION desc table part2
+DROP TABLE part2;
+ALTER TABLE part ADD PRIMARY KEY (a);
+NOTICE:  DDL test: type alter table, tag ALTER TABLE
+NOTICE:    subcommand: type ADD CONSTRAINT (and recurse) desc constraint part_a_not_null on table part
+NOTICE:    subcommand: type ADD INDEX desc index part_pkey
 CREATE TABLE tbl (
 	a int generated always as (b::int * 2) stored,
 	b text
 );
 NOTICE:  DDL test: type simple, tag CREATE TABLE
+ALTER TABLE tbl ALTER COLUMN a SET EXPRESSION AS (b::int * 3);
+NOTICE:  DDL test: type alter table, tag ALTER TABLE
+NOTICE:    subcommand: type SET EXPRESSION desc column a of table tbl
 ALTER TABLE tbl ALTER COLUMN a DROP EXPRESSION;
 NOTICE:  DDL test: type alter table, tag ALTER TABLE
 NOTICE:    subcommand: type DROP EXPRESSION desc column a of table tbl
diff --git a/src/test/modules/test_ddl_deparse/sql/alter_table.sql b/src/test/modules/test_ddl_deparse/sql/alter_table.sql
index 9ad1cf908d4..380ba266075 100644
--- a/src/test/modules/test_ddl_deparse/sql/alter_table.sql
+++ b/src/test/modules/test_ddl_deparse/sql/alter_table.sql
@@ -24,19 +24,6 @@ ALTER TABLE ONLY grandchild ADD CONSTRAINT a_pos CHECK (a > 0);
 -- Constraint, with recursion
 ALTER TABLE parent ADD CONSTRAINT a_pos CHECK (a > 0);
 
-CREATE TABLE part (
-	a int
-) PARTITION BY RANGE (a);
-
-CREATE TABLE part1 PARTITION OF part FOR VALUES FROM (1) to (100);
-
-CREATE TABLE part2 (a int);
-ALTER TABLE part ATTACH PARTITION part2 FOR VALUES FROM (101) to (200);
-ALTER TABLE part DETACH PARTITION part2;
-DROP TABLE part2;
-
-ALTER TABLE part ADD PRIMARY KEY (a);
-
 ALTER TABLE parent ALTER COLUMN a SET NOT NULL;
 ALTER TABLE parent ALTER COLUMN a DROP NOT NULL;
 ALTER TABLE parent ALTER COLUMN a SET NOT NULL;
@@ -62,11 +49,25 @@ ALTER TABLE parent ALTER COLUMN c TYPE numeric;
 
 ALTER TABLE parent ALTER COLUMN c SET DEFAULT 0;
 
+CREATE TABLE part (
+	a int
+) PARTITION BY RANGE (a);
+
+CREATE TABLE part1 PARTITION OF part FOR VALUES FROM (1) to (100);
+
+CREATE TABLE part2 (a int);
+ALTER TABLE part ATTACH PARTITION part2 FOR VALUES FROM (101) to (200);
+ALTER TABLE part DETACH PARTITION part2;
+DROP TABLE part2;
+
+ALTER TABLE part ADD PRIMARY KEY (a);
+
 CREATE TABLE tbl (
 	a int generated always as (b::int * 2) stored,
 	b text
 );
 
+ALTER TABLE tbl ALTER COLUMN a SET EXPRESSION AS (b::int * 3);
 ALTER TABLE tbl ALTER COLUMN a DROP EXPRESSION;
 
 ALTER TABLE tbl ALTER COLUMN b SET COMPRESSION pglz;
-- 
2.34.1

Reply via email to