8000 Refactor subtype field of AlterDomainStmt · sthagen/postgres-postgres@8ec04c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ec04c8

Browse files
committed
Refactor subtype field of AlterDomainStmt
AlterDomainStmt.subtype used characters for its subtypes of commands, SET|DROP DEFAULT|NOT NULL and ADD|DROP|VALIDATE CONSTRAINT, which were hardcoded in a couple of places of the code. The code is improved by using an enum instead, with the same character values as the original code. Note that the field was documented in parsenodes.h and that it forgot to mention 'V' (VALIDATE CONSTRAINT). Author: Quan Zongliang <quanzongliang@yeah.net> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Discussion: https://postgr.es/m/41ff310b-16bd-44b9-a3ef-97e20f14b709@yeah.net
1 parent 170673a commit 8ec04c8

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15726,7 +15726,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
1572615726
{
1572715727
AlterDomainStmt *stmt = (AlterDomainStmt *) stm;
1572815728

15729-
if (stmt->subtype == 'C') /* ADD CONSTRAINT */
15729+
if (stmt->subtype == AD_AddConstraint)
1573015730
{
1573115731
Constraint *con = castNode(Constraint, stmt->def);
1573215732
AlterTableCmd *cmd = makeNode(AlterTableCmd);

src/backend/parser/gram.y

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11665,7 +11665,7 @@ AlterDomainStmt:
1166511665
{
1166611666
AlterDomainStmt *n = makeNode(AlterDomainStmt);
1166711667

11668-
n->subtype = 'T';
11668+
n->subtype = AD_AlterDefault;
1166911669
n->typeName = $3;
1167011670
n->def = $4;
1167111671
$$ = (Node *) n;
@@ -11675,7 +11675,7 @@ AlterDomainStmt:
1167511675
{
1167611676
AlterDomainStmt *n = makeNode(AlterDomainStmt);
1167711677

11678-
n->subtype = 'N';
11678+
n->subtype = AD_DropNotNull;
1167911679
n->typeName = $3;
1168011680
$$ = (Node *) n;
1168111681
}
@@ -11684,7 +11684,7 @@ AlterDomainStmt:
1168411684
{
1168511685
AlterDomainStmt *n = makeNode(AlterDomainStmt);
1168611686

11687-
n->subtype = 'O';
11687+
n->subtype = AD_SetNotNull;
1168811688
n->typeName = $3;
1168911689
$$ = (Node *) n;
1169011690
}
@@ -11693,7 +11693,7 @@ AlterDomainStmt:
1169311693
{
1169411694
AlterDomainStmt *n = makeNode(AlterDomainStmt);
1169511695

11696-
n->subtype = 'C';
11696+
n->subtype = AD_AddConstraint;
1169711697
n->typeName = $3;
1169811698
n->def = $5;
1169911699
$$ = (Node *) n;
@@ -11703,7 +11703,7 @@ AlterDomainStmt:
1170311703
{
1170411704
AlterDomainStmt *n = makeNode(AlterDomainStmt);
1170511705

11706-
n->subtype = 'X';
11706+
n->subtype = AD_DropConstraint;
1170711707
n->typeName = $3;
1170811708
n->name = $6;
1170911709
n->behavior = $7;
@@ -11715,7 +11715,7 @@ AlterDomainStmt:
1171511715
{
1171611716
AlterDomainStmt *n = makeNode(AlterDomainStmt);
1171711717

11718-
n->subtype = 'X';
11718+
n->subtype = AD_DropConstraint;
1171911719
n->typeName = $3;
1172011720
n->name = $8;
1172111721
n->behavior = $9;
@@ -11727,7 +11727,7 @@ AlterDomainStmt:
1172711727
{
1172811728
AlterDomainStmt *n = makeNode(AlterDomainStmt);
1172911729

11730-
n->subtype = 'V';
11730+
n->subtype = AD_ValidateConstraint;
1173111731
n->typeName = $3;
1173211732
n->name = $6;
1173311733
$$ = (Node *) n;

src/backend/tcop/utility.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ ProcessUtilitySlow(ParseState *pstate,
13431343
*/
13441344
switch (stmt->subtype)
13451345
{
1346-
case 'T': /* ALTER DOMAIN DEFAULT */
1346+
case AD_AlterDefault:
13471347

13481348
/*
13491349
* Recursively alter column default for table and,
@@ -1353,30 +1353,30 @@ ProcessUtilitySlow(ParseState *pstate,
13531353
AlterDomainDefault(stmt->typeName,
13541354
stmt->def);
13551355
break;
1356-
case 'N': /* ALTER DOMAIN DROP NOT NULL */
1356+
case AD_DropNotNull:
13571357
address =
13581358
AlterDomainNotNull(stmt->typeName,
13591359
false);
13601360
break;
1361-
case 'O': /* ALTER DOMAIN SET NOT NULL */
1361+
case AD_SetNotNull:
13621362
address =
13631363
AlterDomainNotNull(stmt->typeName,
13641364
true);
13651365
break;
1366-
case 'C': /* ADD CONSTRAINT */
1366+
case AD_AddConstraint:
13671367
address =
13681368
AlterDomainAddConstraint(stmt->typeName,
13691369
stmt->def,
13701370
&secondaryObject);
13711371
break;
1372-
case 'X': /* DROP CONSTRAINT */
1372+
case AD_DropConstraint:
13731373
address =
13741374
AlterDomainDropConstraint(stmt->typeName,
13751375
stmt->name,
13761376
stmt->behavior,
13771377
stmt->missing_ok);
13781378
break;
1379-
case 'V': /* VALIDATE CONSTRAINT */
1379+
case AD_ValidateConstraint:
13801380
address =
13811381
AlterDomainValidateConstraint(stmt->typeName,
13821382
stmt->name);

src/include/nodes/parsenodes.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,17 +2536,20 @@ typedef struct AlterCollationStmt
25362536
* this command.
25372537
* ----------------------
25382538
*/
2539+
typedef enum AlterDomainType
2540+
{
2541+
AD_AlterDefault = 'T', /* SET|DROP DEFAULT */
2542+
AD_DropNotNull = 'N', /* DROP NOT NULL */
2543+
AD_SetNotNull = 'O', /* SET NOT NULL */
2544+
AD_AddConstraint = 'C', /* ADD CONSTRAINT */
2545+
AD_DropConstraint = 'X', /* DROP CONSTRAINT */
2546+
AD_ValidateConstraint = 'V', /* VALIDATE CONSTRAINT */
2547+
} AlterDomainType;
2548+
25392549
typedef struct AlterDomainStmt
25402550
{
25412551
NodeTag type;
2542-
char subtype; /*------------
2543-
* T = alter column default
2544-
* N = alter column drop not null
2545-
* O = alter column set not null
2546-
* C = add constraint
2547-
* X = drop constraint
2548-
*------------
2549-
*/
2552+
AlterDomainType subtype; /* subtype of command */
25502553
List *typeName; /* domain to work on */
25512554
char *name; /* column or constraint name to act on */
25522555
Node *def; /* definition of default or constraint */

src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ AlterDatabaseSetStmt
7474
AlterDatabaseStmt
7575
AlterDefaultPrivilegesStmt
7676
AlterDomainStmt
77+
AlterDomainType
7778
AlterEnumStmt
7879
AlterEventTrigStmt
7980
AlterExtensionContentsStmt

0 commit comments

Comments
 (0)
0