diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2012-01-05 19:48:55 +0200 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2012-01-05 19:48:55 +0200 |
commit | 104e7dac28c56dcaf9b778dff60a5daefc3a0661 (patch) | |
tree | 5152172e545132186865eeb9ddf5903170011c94 /src/backend/commands/typecmds.c | |
parent | 2abefd9a92f3c02ad4f6030ac1578bbf314db368 (diff) | |
download | postgresql-104e7dac28c56dcaf9b778dff60a5daefc3a0661.tar.gz postgresql-104e7dac28c56dcaf9b778dff60a5daefc3a0661.zip |
Improve ALTER DOMAIN / DROP CONSTRAINT with nonexistent constraint
ALTER DOMAIN / DROP CONSTRAINT on a nonexistent constraint name did
not report any error. Now it reports an error. The IF EXISTS option
was added to get the usual behavior of ignoring nonexistent objects to
drop.
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r-- | src/backend/commands/typecmds.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 4bbbaf36c93..0f8af31feef 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -2264,7 +2264,7 @@ AlterDomainNotNull(List *names, bool notNull) */ void AlterDomainDropConstraint(List *names, const char *constrName, - DropBehavior behavior) + DropBehavior behavior, bool missing_ok) { TypeName *typename; Oid domainoid; @@ -2274,6 +2274,7 @@ AlterDomainDropConstraint(List *names, const char *constrName, SysScanDesc conscan; ScanKeyData key[1]; HeapTuple contup; + bool found = false; /* Make a TypeName so we can use standard type lookup machinery */ typename = makeTypeNameFromNameList(names); @@ -2317,6 +2318,7 @@ AlterDomainDropConstraint(List *names, const char *constrName, conobj.objectSubId = 0; performDeletion(&conobj, behavior); + found = true; } } /* Clean up after the scan */ @@ -2324,6 +2326,19 @@ AlterDomainDropConstraint(List *names, const char *constrName, 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)))); + } } /* |