This is an automated email from the ASF dual-hosted git repository.
chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/cbdb-postgres-merge by this
push:
new b7723c06473 Fix some alter table errors
b7723c06473 is described below
commit b7723c06473101eca35373a1dda2e4ca856f2b0e
Author: Jinbao Chen <[email protected]>
AuthorDate: Sat Nov 29 15:58:38 2025 +0800
Fix some alter table errors
---
src/backend/commands/copyfromparse.c | 2 +-
src/backend/nodes/copyfuncs.funcs.c | 38 ++++++++++++++++++
src/backend/nodes/copyfuncs.switch.c | 3 ++
src/backend/nodes/outfuncs.c | 1 +
src/backend/nodes/readfuncs_common.c | 1 +
src/backend/utils/adt/ruleutils.c | 3 +-
src/test/regress/expected/alter_table.out | 66 ++++++++++++-------------------
src/test/regress/serial_schedule | 14 +++----
src/test/regress/sql/alter_table.sql | 4 +-
9 files changed, 79 insertions(+), 53 deletions(-)
diff --git a/src/backend/commands/copyfromparse.c
b/src/backend/commands/copyfromparse.c
index 657348119c4..9b6535c0eaf 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -1004,7 +1004,7 @@ NextCopyFromX(CopyFromState cstate, ExprContext *econtext,
* when all fields are processed in the QD.
*/
if (fldct > attr_count)
- ereport(PANIC,
+ ereport(ERROR,
(errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
errmsg("extra data
after last expected column")));
diff --git a/src/backend/nodes/copyfuncs.funcs.c
b/src/backend/nodes/copyfuncs.funcs.c
index 02ee4d0f556..f4f030b397f 100644
--- a/src/backend/nodes/copyfuncs.funcs.c
+++ b/src/backend/nodes/copyfuncs.funcs.c
@@ -6748,3 +6748,41 @@ _copyPathTarget(const PathTarget *from)
return newnode;
}
+
+static AlteredTableInfo *
+_copyAlteredTableInfo(const AlteredTableInfo *from)
+{
+ int i;
+
+ AlteredTableInfo *newnode = makeNode(AlteredTableInfo);
+
+ COPY_SCALAR_FIELD(relid);
+ COPY_SCALAR_FIELD(relkind);
+ newnode->oldDesc = CreateTupleDescCopyConstr(from->oldDesc);
+
+ for (i = 0; i < AT_NUM_PASSES; i++)
+ COPY_NODE_FIELD(subcmds[i]);
+
+ COPY_NODE_FIELD(constraints);
+ COPY_NODE_FIELD(newvals);
+ COPY_NODE_FIELD(afterStmts);
+ COPY_SCALAR_FIELD(verify_new_notnull);
+ COPY_SCALAR_FIELD(rewrite);
+ COPY_SCALAR_FIELD(dist_opfamily_changed);
+ COPY_SCALAR_FIELD(new_opclass);
+ COPY_SCALAR_FIELD(newTableSpace);
+ COPY_SCALAR_FIELD(chgPersistence);
+ COPY_SCALAR_FIELD(newrelpersistence);
+ COPY_NODE_FIELD(partition_constraint);
+ COPY_SCALAR_FIELD(validate_default);
+ COPY_NODE_FIELD(changedConstraintOids);
+ COPY_NODE_FIELD(changedConstraintDefs);
+ COPY_NODE_FIELD(changedIndexOids);
+ COPY_NODE_FIELD(changedIndexDefs);
+ COPY_STRING_FIELD(replicaIdentityIndex);
+ COPY_STRING_FIELD(clusterOnIndex);
+ COPY_NODE_FIELD(beforeStmtLists);
+ COPY_NODE_FIELD(constraintLists);
+
+ return newnode;
+}
diff --git a/src/backend/nodes/copyfuncs.switch.c
b/src/backend/nodes/copyfuncs.switch.c
index 2df2df3cfa4..c5dd53de3cf 100644
--- a/src/backend/nodes/copyfuncs.switch.c
+++ b/src/backend/nodes/copyfuncs.switch.c
@@ -1186,3 +1186,6 @@
case T_PathTarget:
retval = _copyPathTarget(from);
break;
+ case T_AlteredTableInfo:
+ retval = _copyAlteredTableInfo(from);
+ break;
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 5c65f457937..7a111597709 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -3352,6 +3352,7 @@ _outColumnDef(StringInfo str, const ColumnDef *node)
WRITE_BOOL_FIELD(is_from_type);
WRITE_INT_FIELD(attnum);
WRITE_INT_FIELD(storage);
+ WRITE_STRING_FIELD(storage_name);
WRITE_NODE_FIELD(raw_default);
WRITE_NODE_FIELD(cooked_default);
diff --git a/src/backend/nodes/readfuncs_common.c
b/src/backend/nodes/readfuncs_common.c
index c3eb8a30411..f895e4a4468 100644
--- a/src/backend/nodes/readfuncs_common.c
+++ b/src/backend/nodes/readfuncs_common.c
@@ -535,6 +535,7 @@ _readColumnDef(void)
READ_BOOL_FIELD(is_from_type);
READ_INT_FIELD(attnum);
READ_INT_FIELD(storage);
+ READ_STRING_FIELD(storage_name);
READ_NODE_FIELD(raw_default);
READ_NODE_FIELD(cooked_default);
diff --git a/src/backend/utils/adt/ruleutils.c
b/src/backend/utils/adt/ruleutils.c
index fd95fff5e09..797c92c27b3 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -8167,7 +8167,8 @@ get_name_for_var_field(Var *var, int fieldno,
}
Assert(dpns->plan && (IsA(dpns->plan,
CteScan) ||
IsA(dpns->plan, ShareInputScan) ||
-
IsA(dpns->plan, WorkTableScan)));
+
IsA(dpns->plan, WorkTableScan) ||
+
IsA(dpns->plan, SubqueryScan)));
tle =
get_tle_by_resno(dpns->inner_tlist, attnum);
if (!tle)
diff --git a/src/test/regress/expected/alter_table.out
b/src/test/regress/expected/alter_table.out
index 5c07e5e4e66..fc8bd2f7689 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -124,7 +124,8 @@ 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
+ERROR: ALTER action ALTER COLUMN ... SET STATISTICS cannot be performed on
relation "at_v1"
+DETAIL: This operation is not supported for views.
DROP VIEW at_v1;
--
-- rename - check on both non-temp and temp tables
@@ -2651,23 +2652,15 @@ View definition:
FROM at_view_1 v1;
explain (verbose, costs off) select * from at_view_2;
-<<<<<<< HEAD
- QUERY PLAN
-----------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
- Output: bt.id, bt.stuff, (to_json(ROW(bt.id, bt.stuff, NULL)))
+ Output: bt.id, bt.stuff, (to_json(ROW(bt.id, bt.stuff, 4)))
-> Seq Scan on public.at_base_table bt
- Output: bt.id, bt.stuff, to_json(ROW(bt.id, bt.stuff, NULL))
+ Output: bt.id, bt.stuff, to_json(ROW(bt.id, bt.stuff, 4))
+ Settings: constraint_exclusion = 'partition'
Optimizer: Postgres query optimizer
- Settings: constraint_exclusion=partition
(6 rows)
-=======
- QUERY PLAN
--------------------------------------------------------------
- Seq Scan on public.at_base_table bt
- Output: bt.id, bt.stuff, to_json(ROW(bt.id, bt.stuff, 4))
-(2 rows)
->>>>>>> REL_16_9
select * from at_view_2;
id | stuff | j
@@ -3642,6 +3635,7 @@ ALTER TABLE old_system_table DROP COLUMN othercol;
DROP TABLE old_system_table;
-- set logged
CREATE UNLOGGED TABLE unlogged1(f1 SERIAL PRIMARY KEY, f2 TEXT); -- has
sequence, toast
+ERROR: unlogged sequences are not supported
-- check relpersistence of an unlogged table
SELECT relname, relkind, relpersistence FROM pg_class WHERE relname ~
'^unlogged1'
UNION ALL
@@ -3649,21 +3643,20 @@ SELECT r.relname || ' toast table', t.relkind,
t.relpersistence FROM pg_class r
UNION ALL
SELECT r.relname || ' toast index', ri.relkind, ri.relpersistence FROM
pg_class r join pg_class t ON t.oid = r.reltoastrelid JOIN pg_index i ON
i.indrelid = t.oid JOIN pg_class ri ON ri.oid = i.indexrelid WHERE r.relname ~
'^unlogged1'
ORDER BY relname;
- relname | relkind | relpersistence
------------------------+---------+----------------
- unlogged1 | r | u
- unlogged1 toast index | i | u
- unlogged1 toast table | t | u
- unlogged1_f1_seq | S | u
- unlogged1_pkey | i | u
-(5 rows)
+ relname | relkind | relpersistence
+---------+---------+----------------
+(0 rows)
CREATE UNLOGGED TABLE unlogged2(f1 SERIAL PRIMARY KEY, f2 INTEGER REFERENCES
unlogged1); -- foreign key
+ERROR: unlogged sequences are not supported
CREATE UNLOGGED TABLE unlogged3(f1 SERIAL PRIMARY KEY, f2 INTEGER REFERENCES
unlogged3); -- self-referencing foreign key
+ERROR: unlogged sequences are not supported
ALTER TABLE unlogged3 SET LOGGED; -- skip self-referencing foreign key
+ERROR: relation "unlogged3" does not exist
ALTER TABLE unlogged2 SET LOGGED; -- fails because a foreign key to an
unlogged table exists
-ERROR: could not change table "unlogged2" to logged because it references
unlogged table "unlogged1"
+ERROR: relation "unlogged2" does not exist
ALTER TABLE unlogged1 SET LOGGED;
+ERROR: relation "unlogged1" does not exist
-- check relpersistence of an unlogged table after changing to permanent
SELECT relname, relkind, relpersistence FROM pg_class WHERE relname ~
'^unlogged1'
UNION ALL
@@ -3671,19 +3664,18 @@ SELECT r.relname || ' toast table', t.relkind,
t.relpersistence FROM pg_class r
UNION ALL
SELECT r.relname || ' toast index', ri.relkind, ri.relpersistence FROM
pg_class r join pg_class t ON t.oid = r.reltoastrelid JOIN pg_index i ON
i.indrelid = t.oid JOIN pg_class ri ON ri.oid = i.indexrelid WHERE r.relname ~
'^unlogged1'
ORDER BY relname;
- relname | relkind | relpersistence
------------------------+---------+----------------
- unlogged1 | r | p
- unlogged1 toast index | i | p
- unlogged1 toast table | t | p
- unlogged1_f1_seq | S | p
- unlogged1_pkey | i | p
-(5 rows)
+ relname | relkind | relpersistence
+---------+---------+----------------
+(0 rows)
ALTER TABLE unlogged1 SET LOGGED; -- silently do nothing
+ERROR: relation "unlogged1" does not exist
DROP TABLE unlogged3;
+ERROR: table "unlogged3" does not exist
DROP TABLE unlogged2;
+ERROR: table "unlogged2" does not exist
DROP TABLE unlogged1;
+ERROR: table "unlogged1" does not exist
-- set unlogged
CREATE TABLE logged1(f1 SERIAL PRIMARY KEY, f2 TEXT); -- has sequence, toast
-- check relpersistence of a permanent table
@@ -4400,7 +4392,8 @@ 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
+ERROR: ALTER action ATTACH PARTITION cannot be performed on relation "at_v1"
+DETAIL: This operation is not supported for views.
DROP VIEW at_v1;
--
-- DETACH PARTITION
@@ -4738,22 +4731,16 @@ create table attbl (p1 int constraint pk_attbl primary
key);
create table atref (c1 int references attbl(p1));
cluster attbl using pk_attbl;
alter table attbl alter column p1 set data type bigint;
-<<<<<<< HEAD
ERROR: cannot alter column with primary key or unique constraint
HINT: DROP the constraint first, and recreate it after the ALTER
-=======
->>>>>>> REL_16_9
alter table atref alter column c1 set data type bigint;
drop table attbl, atref;
create table attbl (p1 int constraint pk_attbl primary key);
alter table attbl replica identity using index pk_attbl;
create table atref (c1 int references attbl(p1));
alter table attbl alter column p1 set data type bigint;
-<<<<<<< HEAD
ERROR: cannot alter column with primary key or unique constraint
HINT: DROP the constraint first, and recreate it after the ALTER
-=======
->>>>>>> REL_16_9
alter table atref alter column c1 set data type bigint;
drop table attbl, atref;
/* End test case for bug #17409 */
@@ -4829,7 +4816,6 @@ DETAIL: Failing row contains (2, 1).
-- ...and doesn't when the partition is detached along with its own partition
alter table target_parted detach partition attach_parted;
insert into attach_parted_part1 values (2, 1);
-<<<<<<< HEAD
CREATE TABLE IF NOT EXISTS table_issue_15494(c0 boolean NULL);
ALTER TABLE table_issue_15494 ALTER c0 SET DEFAULT (6>5) IS NULL;
DROP TABLE table_issue_15494;
@@ -4885,7 +4871,6 @@ drop table atown_part;
reset role;
drop role atown_r1;
drop role atown_r2;
-=======
-- Test altering table having publication
create schema alter1;
create schema alter2;
@@ -4906,4 +4891,3 @@ drop publication pub1;
drop schema alter1 cascade;
drop schema alter2 cascade;
NOTICE: drop cascades to table alter2.t1
->>>>>>> REL_16_9
diff --git a/src/test/regress/serial_schedule b/src/test/regress/serial_schedule
index 93475d17313..dde52b45cd8 100644
--- a/src/test/regress/serial_schedule
+++ b/src/test/regress/serial_schedule
@@ -182,15 +182,15 @@ test: rangefuncs
test: prepare
test: conversion
test: truncate
-# test: alter_table
-# test: sequence
-# test: polymorphism
-# test: rowtypes
-# test: returning
+test: alter_table
+test: sequence
+test: polymorphism
+test: rowtypes
+test: returning
# # GPDB_83_MERGE_FIXME: the largeobject test is temporarily disabled due to
test errors
# ignore: largeobject
-# test: with
-# test: xml
+#test: with
+#test: xml
# test: partition_join
# test: partition_prune
# test: reloptions
diff --git a/src/test/regress/sql/alter_table.sql
b/src/test/regress/sql/alter_table.sql
index 04053342c69..c0d2058459a 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -3158,7 +3158,6 @@ insert into attach_parted_part1 values (2, 1);
alter table target_parted detach partition attach_parted;
insert into attach_parted_part1 values (2, 1);
-<<<<<<< HEAD
CREATE TABLE IF NOT EXISTS table_issue_15494(c0 boolean NULL);
ALTER TABLE table_issue_15494 ALTER c0 SET DEFAULT (6>5) IS NULL;
DROP TABLE table_issue_15494;
@@ -3194,7 +3193,7 @@ drop table atown_part;
reset role;
drop role atown_r1;
drop role atown_r2;
-=======
+
-- Test altering table having publication
create schema alter1;
create schema alter2;
@@ -3207,4 +3206,3 @@ alter table alter1.t1 set schema alter2;
drop publication pub1;
drop schema alter1 cascade;
drop schema alter2 cascade;
->>>>>>> REL_16_9
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]