Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS

From: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>
To: Peter Moser <pitiz29a(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS
Date: 2018-06-28 12:27:54
Message-ID: CAMsGm5cKaagUMUOAHuihgt=CV2NhrfDAZvGkggBOEwy3O4KqBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 28 June 2018 at 05:37, Peter Moser <pitiz29a(at)gmail(dot)com> wrote:
[....]

> In general my use-case is, that I want to delete an X in a certain
> namespace, where the type is not known in advance. I could query the
> catalog to get that information and then build a procedure to "execute" the
> right DROP command (as Pavel Stehule suggested), but that adds complexity
> to the application code, where it shouldn't be necessary IMHO.
>

I've dealt with this issue in some contexts by writing a procedure which
takes a regclass parameter and formats and executes an appropriate "DROP
[x]" command.

On a related note, I sometimes find myself wanting to drop a bunch of
tables and views and I find it inconvenient that I have to split up my drop
into two commands - one for the views and one for the tables.

This is a vote for a "DROP RELATION" command that doesn't care if the
objects are views, materialized views, tables, or a mix of those. Maybe
even index or sequence or the other possible values of pg_class.relkind,
although I don't normally think of those as relations.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2018-06-28 12:48:29 Re: SCRAM with channel binding downgrade attack
Previous Message Yugo Nagata 2018-06-28 11:53:07 Fix to not check included columns in ANALYZE on indexes