Re: refactor AlterDomainAddConstraint (alter domain add constraint)

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2024-12-09T08:41:48Z
Lists: pgsql-hackers

Attachments

hi.
ALTER DOMAIN ADD CONSTRAINT syntax more simple than CREATE DOMAIN.
So in gram.y, I changed DomainConstraintElem to the following:

DomainConstraintElem:
            CHECK '(' a_expr ')'
                {
                    Constraint *n = makeNode(Constraint);
                    n->contype = CONSTR_CHECK;
                    n->location = @1;
                    n->raw_expr = $3;
                    n->cooked_expr = NULL;
                    n->initially_valid = true;
                    $$ = (Node *) n;
                }
            | CHECK '(' a_expr ')' NOT VALID
                {
                    Constraint *n = makeNode(Constraint);
                    n->contype = CONSTR_CHECK;
                    n->location = @1;
                    n->raw_expr = $3;
                    n->cooked_expr = NULL;
                    n->initially_valid = false;
                    n->skip_validation = true;
                    $$ = (Node *) n;
                }
            | NOT NULL_P
                {
                    Constraint *n = makeNode(Constraint);
                    n->contype = CONSTR_NOTNULL;
                    n->location = @1;
                    n->keys = list_make1(makeString("value"));
                    n->initially_valid = true;
                    $$ = (Node *) n;
                }


Now everything is the same as alter domain synopsis.
It all looks so simple.

Commits

  1. Fix bogus grammar for a CREATE CONSTRAINT TRIGGER error

  2. Remove dead code