MCPcopy Create free account
hub / github.com/apache/cloudberry / domainAddConstraint

Function domainAddConstraint

src/backend/commands/typecmds.c:3562–3687  ·  view source on GitHub ↗

* domainAddConstraint - code shared between CREATE and ALTER DOMAIN */

Source from the content-addressed store, hash-verified

3560 * domainAddConstraint - code shared between CREATE and ALTER DOMAIN
3561 */
3562static char *
3563domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
3564 int typMod, Constraint *constr,
3565 const char *domainName, ObjectAddress *constrAddr)
3566{
3567 Node *expr;
3568 char *ccbin;
3569 ParseState *pstate;
3570 CoerceToDomainValue *domVal;
3571 Oid ccoid;
3572
3573 /*
3574 * Assign or validate constraint name
3575 */
3576 if (constr->conname)
3577 {
3578 if (ConstraintNameIsUsed(CONSTRAINT_DOMAIN,
3579 domainOid,
3580 constr->conname))
3581 ereport(ERROR,
3582 (errcode(ERRCODE_DUPLICATE_OBJECT),
3583 errmsg("constraint \"%s\" for domain \"%s\" already exists",
3584 constr->conname, domainName)));
3585 }
3586 else
3587 constr->conname = ChooseConstraintName(domainName,
3588 NULL,
3589 "check",
3590 domainNamespace,
3591 NIL);
3592
3593 /*
3594 * Convert the A_EXPR in raw_expr into an EXPR
3595 */
3596 pstate = make_parsestate(NULL);
3597
3598 /*
3599 * Set up a CoerceToDomainValue to represent the occurrence of VALUE in
3600 * the expression. Note that it will appear to have the type of the base
3601 * type, not the domain. This seems correct since within the check
3602 * expression, we should not assume the input value can be considered a
3603 * member of the domain.
3604 */
3605 domVal = makeNode(CoerceToDomainValue);
3606 domVal->typeId = baseTypeOid;
3607 domVal->typeMod = typMod;
3608 domVal->collation = get_typcollation(baseTypeOid);
3609 domVal->location = -1; /* will be set when/if used */
3610
3611 pstate->p_pre_columnref_hook = replace_domain_constraint_value;
3612 pstate->p_ref_hook_state = (void *) domVal;
3613
3614 /*
3615 * GPDB: transformExpr scribbles on the input, but we need to keep it intact
3616 * because we dispatch it afterwards.
3617 */
3618 constr = (Constraint *) copyObject(constr);
3619 expr = transformExpr(pstate, constr->raw_expr, EXPR_KIND_DOMAIN_CHECK);

Callers 2

DefineDomainFunction · 0.85
AlterDomainAddConstraintFunction · 0.85

Calls 13

ConstraintNameIsUsedFunction · 0.85
ChooseConstraintNameFunction · 0.85
make_parsestateFunction · 0.85
get_typcollationFunction · 0.85
transformExprFunction · 0.85
coerce_to_booleanFunction · 0.85
assign_expr_collationsFunction · 0.85
list_lengthFunction · 0.85
contain_var_clauseFunction · 0.85
nodeToStringFunction · 0.85
CreateConstraintEntryFunction · 0.85
errcodeFunction · 0.50

Tested by

no test coverage detected