ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
ADD <replaceable class="PARAMETER">domain_constraint</replaceable> [ NOT VALID ]
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
- DROP CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> [ RESTRICT | CASCADE ]
+ DROP CONSTRAINT [ IF EXISTS ] <replaceable class="PARAMETER">constraint_name</replaceable> [ RESTRICT | CASCADE ]
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable>
ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
</varlistentry>
<varlistentry>
- <term>DROP CONSTRAINT</term>
+ <term>DROP CONSTRAINT [ IF EXISTS ]</term>
<listitem>
<para>
This form drops constraints on a domain.
+ If <literal>IF EXISTS</literal> is specified and the constraint
+ does not exist, no error is thrown. In this case a notice is issued instead.
</para>
</listitem>
</varlistentry>
*/
void
AlterDomainDropConstraint(List *names, const char *constrName,
- DropBehavior behavior)
+ DropBehavior behavior, bool missing_ok)
{
TypeName *typename;
Oid domainoid;
SysScanDesc conscan;
ScanKeyData key[1];
HeapTuple contup;
+ bool found = false;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeTypeNameFromNameList(names);
conobj.objectSubId = 0;
performDeletion(&conobj, behavior);
+ found = true;
}
}
/* Clean up after the scan */
heap_close(conrel, RowExclusiveLock);
heap_close(rel, NoLock);
+
+ if (!found)
+ {
+ if (!missing_ok)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("constraint \"%s\" of domain \"%s\" does not exist",
+ constrName, TypeNameToString(typename))));
+ else
+ ereport(NOTICE,
+ (errmsg("constraint \"%s\" of domain \"%s\" does not exist, skipping",
+ constrName, TypeNameToString(typename))));
+ }
}
/*
COPY_STRING_FIELD(name);
COPY_NODE_FIELD(def);
COPY_SCALAR_FIELD(behavior);
+ COPY_SCALAR_FIELD(missing_ok);
return newnode;
}
COMPARE_STRING_FIELD(name);
COMPARE_NODE_FIELD(def);
COMPARE_SCALAR_FIELD(behavior);
+ COMPARE_SCALAR_FIELD(missing_ok);
return true;
}
n->typeName = $3;
n->name = $6;
n->behavior = $7;
+ n->missing_ok = false;
+ $$ = (Node *)n;
+ }
+ /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
+ | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
+ {
+ AlterDomainStmt *n = makeNode(AlterDomainStmt);
+ n->subtype = 'X';
+ n->typeName = $3;
+ n->name = $8;
+ n->behavior = $9;
+ n->missing_ok = true;
$$ = (Node *)n;
}
/* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
case 'X': /* DROP CONSTRAINT */
AlterDomainDropConstraint(stmt->typeName,
stmt->name,
- stmt->behavior);
+ stmt->behavior,
+ stmt->missing_ok);
break;
case 'V': /* VALIDATE CONSTRAINT */
AlterDomainValidateConstraint(stmt->typeName,
extern void AlterDomainAddConstraint(List *names, Node *constr);
extern void AlterDomainValidateConstraint(List *names, char *constrName);
extern void AlterDomainDropConstraint(List *names, const char *constrName,
- DropBehavior behavior);
+ DropBehavior behavior, bool missing_ok);
extern List *GetDomainConstraints(Oid typeOid);
char *name; /* column or constraint name to act on */
Node *def; /* definition of default or constraint */
DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
+ bool missing_ok; /* skip error if missing? */
} AlterDomainStmt;
insert into domcontest values (-5); --fails
ERROR: value for domain con violates check constraint "con_check"
insert into domcontest values (42);
+alter domain con drop constraint nonexistent;
+ERROR: constraint "nonexistent" of domain "con" does not exist
+alter domain con drop constraint if exists nonexistent;
+NOTICE: constraint "nonexistent" of domain "con" does not exist, skipping
-- Test ALTER DOMAIN .. CONSTRAINT .. NOT VALID
create domain things AS INT;
CREATE TABLE thethings (stuff things);
insert into domcontest values (-5); --fails
insert into domcontest values (42);
+alter domain con drop constraint nonexistent;
+alter domain con drop constraint if exists nonexistent;
+
-- Test ALTER DOMAIN .. CONSTRAINT .. NOT VALID
create domain things AS INT;
CREATE TABLE thethings (stuff things);