syntax for drop if exists

Started by Andrew Dunstanabout 20 years ago3 messages
#1Andrew Dunstan
andrew@dunslane.net

I was just looking briefly at doing "drop if exists" as we discussed
recently.

The MySQL syntax is actually "drop table if exists foo ...".
Implementing this unfortunately generates a shift/reduce conflict,
unless I put IF in the func_name_keyword list, which strikes me as a bad
idea.

Alternatively, we could use the syntax "drop if exists table foo ..."
which seems more natural to me, and generates no conflict.

Or we could live with the conflict, which I think would be harmless
unless you wanted to delete a table called "if", in which case you might
need to say "drop table if exists if" ;-)

I'm inclined to live with it, annoying as it is. I looked around to see
what other DBs do - but AFAICS most don't support this.

Thoughts?

cheers

andrew

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#1)
Re: syntax for drop if exists

Andrew Dunstan <andrew@dunslane.net> writes:

The MySQL syntax is actually "drop table if exists foo ...".
Implementing this unfortunately generates a shift/reduce conflict,

What did you try exactly? I don't see any fundamental reason for
a conflict here. You may just need to rearrange the grammar to postpone
the reduction a bit.

Or we could live with the conflict,

Utterly unacceptable; see previous discussions.

regards, tom lane

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#2)
Re: syntax for drop if exists

Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

The MySQL syntax is actually "drop table if exists foo ...".
Implementing this unfortunately generates a shift/reduce conflict,

What did you try exactly? I don't see any fundamental reason for
a conflict here. You may just need to rearrange the grammar to postpone
the reduction a bit.

You're right, as usual. I had factored out the IF EXISTS bit into a
seperate rule. When I undid that and instead used 2 rules for DropStmt,
the problem disappeared. (This is because it gives bison more info about
the context of each IF - this has often caught me with bison - I should
have known better).

cheers

andrew