* AlterDomainAddConstraint * * Implements the ALTER DOMAIN .. ADD CONSTRAINT statement. */
| 3033 | * Implements the ALTER DOMAIN .. ADD CONSTRAINT statement. |
| 3034 | */ |
| 3035 | ObjectAddress |
| 3036 | AlterDomainAddConstraint(List *names, Node *newConstraint, |
| 3037 | ObjectAddress *constrAddr) |
| 3038 | { |
| 3039 | TypeName *typename; |
| 3040 | Oid domainoid; |
| 3041 | Relation typrel; |
| 3042 | HeapTuple tup; |
| 3043 | Form_pg_type typTup; |
| 3044 | Constraint *constr; |
| 3045 | char *ccbin; |
| 3046 | ObjectAddress address; |
| 3047 | |
| 3048 | /* Make a TypeName so we can use standard type lookup machinery */ |
| 3049 | typename = makeTypeNameFromNameList(names); |
| 3050 | domainoid = typenameTypeId(NULL, typename); |
| 3051 | |
| 3052 | /* Look up the domain in the type table */ |
| 3053 | typrel = table_open(TypeRelationId, RowExclusiveLock); |
| 3054 | |
| 3055 | tup = SearchSysCacheCopy1(TYPEOID, ObjectIdGetDatum(domainoid)); |
| 3056 | if (!HeapTupleIsValid(tup)) |
| 3057 | elog(ERROR, "cache lookup failed for type %u", domainoid); |
| 3058 | typTup = (Form_pg_type) GETSTRUCT(tup); |
| 3059 | |
| 3060 | /* Check it's a domain and check user has permission for ALTER DOMAIN */ |
| 3061 | checkDomainOwner(tup); |
| 3062 | |
| 3063 | if (!IsA(newConstraint, Constraint)) |
| 3064 | elog(ERROR, "unrecognized node type: %d", |
| 3065 | (int) nodeTag(newConstraint)); |
| 3066 | |
| 3067 | constr = (Constraint *) newConstraint; |
| 3068 | |
| 3069 | switch (constr->contype) |
| 3070 | { |
| 3071 | case CONSTR_CHECK: |
| 3072 | /* processed below */ |
| 3073 | break; |
| 3074 | |
| 3075 | case CONSTR_UNIQUE: |
| 3076 | ereport(ERROR, |
| 3077 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 3078 | errmsg("unique constraints not possible for domains"))); |
| 3079 | break; |
| 3080 | |
| 3081 | case CONSTR_PRIMARY: |
| 3082 | ereport(ERROR, |
| 3083 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 3084 | errmsg("primary key constraints not possible for domains"))); |
| 3085 | break; |
| 3086 | |
| 3087 | case CONSTR_EXCLUSION: |
| 3088 | ereport(ERROR, |
| 3089 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 3090 | errmsg("exclusion constraints not possible for domains"))); |
| 3091 | break; |
| 3092 |
no test coverage detected