* domainAddConstraint - code shared between CREATE and ALTER DOMAIN */
| 3560 | * domainAddConstraint - code shared between CREATE and ALTER DOMAIN |
| 3561 | */ |
| 3562 | static char * |
| 3563 | domainAddConstraint(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); |
no test coverage detected