public inbox for [email protected]
help / color / mirror / Atom feedWhy is there no ADD CONSTRAINT IF NOT EXISTS ?
2+ messages / 2 participants
[nested] [flat]
* Why is there no ADD CONSTRAINT IF NOT EXISTS ?
@ 2021-04-21 12:13 Stephen Carboni <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Stephen Carboni @ 2021-04-21 12:13 UTC (permalink / raw)
To: pgsql-novice
I can drop a constraint if it exists, but cannot simply add one if it does
not exist. Is there something especially difficult about supporting this?
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Why is there no ADD CONSTRAINT IF NOT EXISTS ?
@ 2021-04-21 14:08 Tom Lane <[email protected]>
parent: Stephen Carboni <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2021-04-21 14:08 UTC (permalink / raw)
To: Stephen Carboni <[email protected]>; +Cc: pgsql-novice
Stephen Carboni <[email protected]> writes:
> I can drop a constraint if it exists, but cannot simply add one if it does
> not exist. Is there something especially difficult about supporting this?
Probably some combination of (1) nobody got around to it yet and
(2) it's not entirely clear what the semantics ought to be.
Should we match on name, or contents of the constraint, and how
picky would a content match be?
There's a general problem with CREATE IF NOT EXISTS that you don't
really have any guarantee afterwards as to what are the details
of the object's definition. Personally I prefer CREATE OR REPLACE
semantics, where you do know what the object looks like afterwards.
However, C.O.R. doesn't work that well unless there's a very clear
unique identity (e.g. name) for the object. Since constraints are
often made without specifying a name, it's hard to be sure what
you're supposed to replace. I'm not sure whether C.I.N.E. would
have as bad of a problem with that, but it seems possible.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2021-04-21 14:08 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 12:13 Why is there no ADD CONSTRAINT IF NOT EXISTS ? Stephen Carboni <[email protected]>
2021-04-21 14:08 ` Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox