Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS
Дата
Msg-id CAFj8pRD-Lq=9ZTHuAdq1RYW4EN0O5Pr0cvCUZs5=MUzs2dLCXQ@mail.gmail.com
обсуждение исходный текст
Ответ на Unexpected behavior of DROP VIEW/TABLE IF EXISTS  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-hackers


2018-06-26 17:48 GMT+02:00 David G. Johnston <david.g.johnston@gmail.com>:
On Tuesday, June 26, 2018, Pavel Stehule <pavel.stehule@gmail.com> wrote:
2018-06-26 17:23 GMT+02:00 Peter Moser <pitiz29a@gmail.com>:
Hi,
I want to delete a table X, that may not exist, hence I execute

        DROP TABLE IF EXISTS X;

However, if X is a view, I get an error

        ERROR: "X" is not a table
        HINT: Use DROP VIEW to remove a view.
        SQL state: 42809

That is unexpected and also difficult to handle

DROP TABLE should to remove table and nothing else, like DROP VIEW should to drop just view and nothing else. It is safeguard.

Peter isn't asking for drop table to drop a view though, he's asking for the documented behavior:

"Do not throw an error if the table does not exist. A notice is issued in this case."

This is different issue.


There is no Table named X in the database so the command should be a noop with a notice.  I would concur, though I'm open to just fixing it in v12 and back patching a documentation bug fix stating the exception due to relations sharing a namespace but there be lacking a corresponding shared namespace "drop relation" command.

There are two points

a) documentation issue
b) different behave for DROP TABLE IF EXISTS command

My note is related to @b. I understand to the motivation, but I am not sure if it is good idea. Tables and views shares one namespace.

Often usage of DROP TABLE IF EXISTS is together with CREATE TABLE

Now if some does bad reference in DROP TABLE command, then this command fails (first). If we do proposed change, then DROP TABLE do nothing, and CREATE TABLE fails.

So I am not sure, if proposed change is practical because views and tables shares same namespace and current behave has sense too.

Regards

Pavel


David J.


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Arthur Zakirov
Дата:
Сообщение: Re: ALTER TABLE does not check for column existence before startingoperations
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Unexpected behavior of DROP VIEW/TABLE IF EXISTS