1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

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
This commit is contained in:
Michael Paquier
2025-07-03 16:34:28 +09:00
parent 170673a22f
commit 8ec04c8577
5 changed files with 26 additions and 22 deletions

View File

@ -15726,7 +15726,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
{
AlterDomainStmt *stmt = (AlterDomainStmt *) stm;
if (stmt->subtype == 'C') /* ADD CONSTRAINT */
if (stmt->subtype == AD_AddConstraint)
{
Constraint *con = castNode(Constraint, stmt->def);
AlterTableCmd *cmd = makeNode(AlterTableCmd);

View File

@ -11665,7 +11665,7 @@ AlterDomainStmt:
{
AlterDomainStmt *n = makeNode(AlterDomainStmt);
n->subtype = 'T';
n->subtype = AD_AlterDefault;
n->typeName = $3;
n->def = $4;
$$ = (Node *) n;
@ -11675,7 +11675,7 @@ AlterDomainStmt:
{
AlterDomainStmt *n = makeNode(AlterDomainStmt);
n->subtype = 'N';
n->subtype = AD_DropNotNull;
n->typeName = $3;
$$ = (Node *) n;
}
@ -11684,7 +11684,7 @@ AlterDomainStmt:
{
AlterDomainStmt *n = makeNode(AlterDomainStmt);
n->subtype = 'O';
n->subtype = AD_SetNotNull;
n->typeName = $3;
$$ = (Node *) n;
}
@ -11693,7 +11693,7 @@ AlterDomainStmt:
{
AlterDomainStmt *n = makeNode(AlterDomainStmt);
n->subtype = 'C';
n->subtype = AD_AddConstraint;
n->typeName = $3;
n->def = $5;
$$ = (Node *) n;
@ -11703,7 +11703,7 @@ AlterDomainStmt:
{
AlterDomainStmt *n = makeNode(AlterDomainStmt);
n->subtype = 'X';
n->subtype = AD_DropConstraint;
n->typeName = $3;
n->name = $6;
n->behavior = $7;
@ -11715,7 +11715,7 @@ AlterDomainStmt:
{
AlterDomainStmt *n = makeNode(AlterDomainStmt);
n->subtype = 'X';
n->subtype = AD_DropConstraint;
n->typeName = $3;
n->name = $8;
n->behavior = $9;
@ -11727,7 +11727,7 @@ AlterDomainStmt:
{
AlterDomainStmt *n = makeNode(AlterDomainStmt);
n->subtype = 'V';
n->subtype = AD_ValidateConstraint;
n->typeName = $3;
n->name = $6;
$$ = (Node *) n;

View File

@ -1343,7 +1343,7 @@ ProcessUtilitySlow(ParseState *pstate,
*/
switch (stmt->subtype)
{
case 'T': /* ALTER DOMAIN DEFAULT */
case AD_AlterDefault:
/*
* Recursively alter column default for table and,
@ -1353,30 +1353,30 @@ ProcessUtilitySlow(ParseState *pstate,
AlterDomainDefault(stmt->typeName,
stmt->def);
break;
case 'N': /* ALTER DOMAIN DROP NOT NULL */
case AD_DropNotNull:
address =
AlterDomainNotNull(stmt->typeName,
false);
break;
case 'O': /* ALTER DOMAIN SET NOT NULL */
case AD_SetNotNull:
address =
AlterDomainNotNull(stmt->typeName,
true);
break;
case 'C': /* ADD CONSTRAINT */
case AD_AddConstraint:
address =
AlterDomainAddConstraint(stmt->typeName,
stmt->def,
&secondaryObject);
break;
case 'X': /* DROP CONSTRAINT */
case AD_DropConstraint:
address =
AlterDomainDropConstraint(stmt->typeName,
stmt->name,
stmt->behavior,
stmt->missing_ok);
break;
case 'V': /* VALIDATE CONSTRAINT */
case AD_ValidateConstraint:
address =
AlterDomainValidateConstraint(stmt->typeName,
stmt->name);

View File

@ -2536,17 +2536,20 @@ typedef struct AlterCollationStmt
* this command.
* ----------------------
*/
typedef enum AlterDomainType
{
AD_AlterDefault = 'T', /* SET|DROP DEFAULT */
AD_DropNotNull = 'N', /* DROP NOT NULL */
AD_SetNotNull = 'O', /* SET NOT NULL */
AD_AddConstraint = 'C', /* ADD CONSTRAINT */
AD_DropConstraint = 'X', /* DROP CONSTRAINT */
AD_ValidateConstraint = 'V', /* VALIDATE CONSTRAINT */
} AlterDomainType;
typedef struct AlterDomainStmt
{
NodeTag type;
char subtype; /*------------
* T = alter column default
* N = alter column drop not null
* O = alter column set not null
* C = add constraint
* X = drop constraint
*------------
*/
AlterDomainType subtype; /* subtype of command */
List *typeName; /* domain to work on */
char *name; /* column or constraint name to act on */
Node *def; /* definition of default or constraint */

View File

@ -74,6 +74,7 @@ AlterDatabaseSetStmt
AlterDatabaseStmt
AlterDefaultPrivilegesStmt
AlterDomainStmt
AlterDomainType
AlterEnumStmt
AlterEventTrigStmt
AlterExtensionContentsStmt