Re: alter enum add value if not exists - Mailing list pgsql-hackers

From Tom Lane
Subject Re: alter enum add value if not exists
Date
Msg-id 7353.1348355159@sss.pgh.pa.us
Whole thread Raw
In response to Re: alter enum add value if not exists  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: alter enum add value if not exists  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
I wrote:
> ...  It strikes me though that if
> we're going to invent an opt_if_not_exists production in the grammar,
> there are a lot of other places where it should be used too, for
> consistency if nothing else.

BTW, I tried to do this and realized that it doesn't work, because IF
is not a reserved word.  The only way that opt_if_not_exists isn't
ambiguous is if it must appear before something that's not an
identifier, which is to say it works in ALTER TYPE ADD VALUE ... Sconst
and nowhere else.  Otherwise you have to spell it out with duplicate
productions so that bison doesn't have to make a shift/reduce decision
till it's seen the whole phrase.

If we're ever forced to make IF reserved for other reasons, we could
clean up a lot of both IF EXISTS and IF NOT EXISTS productions.

There are other ways we could refactor the productions involved to
reduce duplication; for instance I think that we could make it work for
CREATE TABLE IF NOT EXISTS by defining a nonterminal that expands to
either "qualified_name" or "IF NOT EXISTS qualified_name".  But that
seems ugly enough to not be much of an improvement, not least because
the nonterminal would need to return two separate pieces of info,
and that's not terribly easy in bison.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: alter enum add value if not exists
Next
From: Andrew Dunstan
Date:
Subject: Re: alter enum add value if not exists