From 10240299a0dc7fdda818c4449380ca4d23c5aa24 Mon Sep 17 00:00:00 2001 From: Hou Zhijie Date: Mon, 25 Jul 2022 11:30:18 +0800 Subject: [PATCH v3 3/3] Add support for some missed commands in test_ddl_deparse --- .../test_ddl_deparse/expected/alter_table.out | 49 ++++++++++++++++++++++ .../modules/test_ddl_deparse/sql/alter_table.sql | 28 +++++++++++++ .../modules/test_ddl_deparse/test_ddl_deparse.c | 30 +++++++++++-- 3 files changed, 104 insertions(+), 3 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 ec22d68..7b0cec5 100644 --- a/src/test/modules/test_ddl_deparse/expected/alter_table.out +++ b/src/test/modules/test_ddl_deparse/expected/alter_table.out @@ -36,3 +36,52 @@ NOTICE: DDL test: type alter table, tag ALTER TABLE NOTICE: subcommand: type SET NOT NULL desc column a of table part NOTICE: subcommand: type SET NOT NULL desc column a of table part1 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 desc column a of table parent +NOTICE: subcommand: type SET NOT NULL desc column a of table child +NOTICE: subcommand: type SET NOT NULL desc column a of table grandchild +ALTER TABLE parent ALTER COLUMN a ADD GENERATED ALWAYS AS IDENTITY; +NOTICE: DDL test: type simple, tag CREATE SEQUENCE +NOTICE: DDL test: type simple, tag ALTER SEQUENCE +NOTICE: DDL test: type alter table, tag ALTER TABLE +NOTICE: subcommand: type ADD IDENTITY desc column a of table parent +ALTER TABLE parent ALTER COLUMN a SET GENERATED BY DEFAULT; +NOTICE: DDL test: type simple, tag ALTER SEQUENCE +NOTICE: DDL test: type alter table, tag ALTER TABLE +NOTICE: subcommand: type SET IDENTITY desc column a of table parent +ALTER TABLE parent ALTER COLUMN a DROP IDENTITY; +NOTICE: DDL test: type alter table, tag ALTER TABLE +NOTICE: subcommand: type DROP IDENTITY desc column a of table parent +CREATE STATISTICS parent_stat (dependencies) ON a, c FROM parent; +NOTICE: DDL test: type simple, tag CREATE STATISTICS +ALTER TABLE parent ALTER COLUMN c TYPE numeric; +NOTICE: DDL test: type alter table, tag ALTER TABLE +NOTICE: subcommand: type ALTER COLUMN SET TYPE desc column c of table parent +NOTICE: subcommand: type ALTER COLUMN SET TYPE desc column c of table child +NOTICE: subcommand: type ALTER COLUMN SET TYPE desc column c of table grandchild +NOTICE: subcommand: type (re) ADD STATS desc statistics object parent_stat +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 DROP EXPRESSION; +NOTICE: DDL test: type alter table, tag ALTER TABLE +NOTICE: subcommand: type DROP EXPRESSION desc column a of table tbl +ALTER TABLE tbl ALTER COLUMN b SET COMPRESSION pglz; +NOTICE: DDL test: type alter table, tag ALTER TABLE +NOTICE: subcommand: type SET COMPRESSION desc column b of table tbl +CREATE TYPE comptype AS (r float8); +NOTICE: DDL test: type simple, tag CREATE TYPE +CREATE DOMAIN dcomptype AS comptype; +NOTICE: DDL test: type simple, tag CREATE DOMAIN +ALTER DOMAIN dcomptype ADD CONSTRAINT c1 check ((value).r > 0); +NOTICE: DDL test: type simple, tag ALTER DOMAIN +ALTER TYPE comptype ALTER ATTRIBUTE r TYPE bigint; +NOTICE: DDL test: type alter table, tag ALTER TYPE +NOTICE: subcommand: type ALTER COLUMN SET TYPE desc column r of composite type comptype +NOTICE: subcommand: type (re) ADD DOMAIN CONSTRAINT desc type dcomptype +ALTER TABLE tbl SET ACCESS METHOD heap; +NOTICE: DDL test: type alter table, tag ALTER TABLE +NOTICE: subcommand: type SET ACCESS METHOD desc 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 b098957..6c3d577 100644 --- a/src/test/modules/test_ddl_deparse/sql/alter_table.sql +++ b/src/test/modules/test_ddl_deparse/sql/alter_table.sql @@ -24,3 +24,31 @@ 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 ADD GENERATED ALWAYS AS IDENTITY; + +ALTER TABLE parent ALTER COLUMN a SET GENERATED BY DEFAULT; + +ALTER TABLE parent ALTER COLUMN a DROP IDENTITY; + +CREATE STATISTICS parent_stat (dependencies) ON a, c FROM parent; + +ALTER TABLE parent ALTER COLUMN c TYPE numeric; + +CREATE TABLE tbl ( + a int generated always as (b::int * 2) stored, + b text +); + +ALTER TABLE tbl ALTER COLUMN a DROP EXPRESSION; + +ALTER TABLE tbl ALTER COLUMN b SET COMPRESSION pglz; + +CREATE TYPE comptype AS (r float8); +CREATE DOMAIN dcomptype AS comptype; +ALTER DOMAIN dcomptype ADD CONSTRAINT c1 check ((value).r > 0); +ALTER TYPE comptype ALTER ATTRIBUTE r TYPE bigint; + +ALTER TABLE tbl SET ACCESS METHOD heap; diff --git a/src/test/modules/test_ddl_deparse/test_ddl_deparse.c b/src/test/modules/test_ddl_deparse/test_ddl_deparse.c index 4476c8a..0ad9b7a 100644 --- a/src/test/modules/test_ddl_deparse/test_ddl_deparse.c +++ b/src/test/modules/test_ddl_deparse/test_ddl_deparse.c @@ -102,7 +102,7 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) { CollectedATSubcmd *sub = lfirst(cell); AlterTableCmd *subcmd = castNode(AlterTableCmd, sub->parsetree); - const char *strtype; + const char *strtype = NULL; Datum values[2]; bool nulls[2]; @@ -132,6 +132,9 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_SetNotNull: strtype = "SET NOT NULL"; break; + case AT_DropExpression: + strtype = "DROP EXPRESSION"; + break; case AT_CheckNotNull: strtype = "CHECK NOT NULL"; break; @@ -147,6 +150,9 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_SetStorage: strtype = "SET STORAGE"; break; + case AT_SetCompression: + strtype = "SET COMPRESSION"; + break; case AT_DropColumn: strtype = "DROP COLUMN"; break; @@ -168,6 +174,9 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_ReAddConstraint: strtype = "(re) ADD CONSTRAINT"; break; + case AT_ReAddDomainConstraint: + strtype = "(re) ADD DOMAIN CONSTRAINT"; + break; case AT_AlterConstraint: strtype = "ALTER CONSTRAINT"; break; @@ -213,6 +222,9 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_DropOids: strtype = "DROP OIDS"; break; + case AT_SetAccessMethod: + strtype = "SET ACCESS METHOD"; + break; case AT_SetTableSpace: strtype = "SET TABLESPACE"; break; @@ -300,11 +312,23 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_DetachPartitionFinalize: strtype = "DETACH PARTITION ... FINALIZE"; break; - default: - strtype = "unrecognized"; + case AT_AddIdentity: + strtype = "ADD IDENTITY"; + break; + case AT_SetIdentity: + strtype = "SET IDENTITY"; + break; + case AT_DropIdentity: + strtype = "DROP IDENTITY"; + break; + case AT_ReAddStatistics: + strtype = "(re) ADD STATS"; break; } + if (strtype == NULL) + strtype = "unrecognized"; + values[0] = CStringGetTextDatum(strtype); if (OidIsValid(sub->address.objectId)) { -- 2.7.2.windows.1