Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS
Date
Msg-id CAKFQuwam6T+A7acAkSgC1GW1Afxudk3bas8NM7bMBhn+CL50RQ@mail.gmail.com
Whole thread Raw
In response to Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Wednesday, July 4, 2018, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Also, based on other messages, it seems like what the OP wants is
to be sure that "CREATE TABLE X" will succeed afterwards, so that
failing to get rid of view X will not do what he needs.

I read and agree that what should be possible, absent DROP RELATION, is for someone to execute both DROP VIEW and DROP TABLE with the same name, in any order, and not have the transaction abort with an error (if a table or view of the same name already exists).  Having done that the CREATE VIEW will succeed since either both were no-ops (no table or view of that name existed) or one was guaranteed to succeed and the other was a no-op (table or view existed - doesn't matter which).  As it stands now you have to know whether the existing object is a table or a view in order to get the order correct and the first run usually the table exists and the second run the view exists so the script has to be changed in between.

If this didn't involve an error mode the desire to leave things as-is would be more understandable to me.

David J.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: shared-memory based stats collector
Next
From: Tom Lane
Date:
Subject: Re: Cache invalidation after authentication (on-the-fly role creation)