* AlterDomainValidateConstraint * * Implements the ALTER DOMAIN .. VALIDATE CONSTRAINT statement. */
| 3149 | * Implements the ALTER DOMAIN .. VALIDATE CONSTRAINT statement. |
| 3150 | */ |
| 3151 | ObjectAddress |
| 3152 | AlterDomainValidateConstraint(List *names, const char *constrName) |
| 3153 | { |
| 3154 | TypeName *typename; |
| 3155 | Oid domainoid; |
| 3156 | Relation typrel; |
| 3157 | Relation conrel; |
| 3158 | HeapTuple tup; |
| 3159 | Form_pg_constraint con; |
| 3160 | Form_pg_constraint copy_con; |
| 3161 | char *conbin; |
| 3162 | SysScanDesc scan; |
| 3163 | Datum val; |
| 3164 | bool isnull; |
| 3165 | HeapTuple tuple; |
| 3166 | HeapTuple copyTuple; |
| 3167 | ScanKeyData skey[3]; |
| 3168 | ObjectAddress address; |
| 3169 | |
| 3170 | /* Make a TypeName so we can use standard type lookup machinery */ |
| 3171 | typename = makeTypeNameFromNameList(names); |
| 3172 | domainoid = typenameTypeId(NULL, typename); |
| 3173 | |
| 3174 | /* Look up the domain in the type table */ |
| 3175 | typrel = table_open(TypeRelationId, AccessShareLock); |
| 3176 | |
| 3177 | tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(domainoid)); |
| 3178 | if (!HeapTupleIsValid(tup)) |
| 3179 | elog(ERROR, "cache lookup failed for type %u", domainoid); |
| 3180 | |
| 3181 | /* Check it's a domain and check user has permission for ALTER DOMAIN */ |
| 3182 | checkDomainOwner(tup); |
| 3183 | |
| 3184 | /* |
| 3185 | * Find and check the target constraint |
| 3186 | */ |
| 3187 | conrel = table_open(ConstraintRelationId, RowExclusiveLock); |
| 3188 | |
| 3189 | ScanKeyInit(&skey[0], |
| 3190 | Anum_pg_constraint_conrelid, |
| 3191 | BTEqualStrategyNumber, F_OIDEQ, |
| 3192 | ObjectIdGetDatum(InvalidOid)); |
| 3193 | ScanKeyInit(&skey[1], |
| 3194 | Anum_pg_constraint_contypid, |
| 3195 | BTEqualStrategyNumber, F_OIDEQ, |
| 3196 | ObjectIdGetDatum(domainoid)); |
| 3197 | ScanKeyInit(&skey[2], |
| 3198 | Anum_pg_constraint_conname, |
| 3199 | BTEqualStrategyNumber, F_NAMEEQ, |
| 3200 | CStringGetDatum(constrName)); |
| 3201 | |
| 3202 | scan = systable_beginscan(conrel, ConstraintRelidTypidNameIndexId, true, |
| 3203 | NULL, 3, skey); |
| 3204 | |
| 3205 | /* There can be at most one matching row */ |
| 3206 | if (!HeapTupleIsValid(tuple = systable_getnext(scan))) |
| 3207 | ereport(ERROR, |
| 3208 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
no test coverage detected