DROP TABLE CASCADE doesn't drop dependencies

Поиск
Список
Период
Сортировка
От Robins Tharakan
Тема DROP TABLE CASCADE doesn't drop dependencies
Дата
Msg-id CAEP4nAzV3RGu7hgh7dXC44UsnDeFYEt4yZU_dnzmShNn33FGDQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: DROP TABLE CASCADE doesn't drop dependencies  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: DROP TABLE CASCADE doesn't drop dependencies  (Michael Paquier <michael@paquier.xyz>)
Список pgsql-bugs
Hi,

Is it expected for DROP TABLE CASCADE to find a related table but not drop it?

The case in point, is when the base table is used as a column type.

This can at least be reproduced in v9.6 and v10, where it silently drops the column! (Am not a developer, but wild guess the code that is supposed to check for an existing FK and drop just the FK, is dropping the column in this case).

In v12 (see below) it doesn't drop the column (or the table), but \d fails loudly.

###################
localhost postgres@t=# create table typ (b integer);
CREATE TABLE

localhost postgres@t=# create table tbl (abc typ);
CREATE TABLE

localhost postgres@t=# \d
         List of relations
┌────────┬──────┬───────┬──────────┐
│ Schema │ Name │ Type  │  Owner   │
├────────┼──────┼───────┼──────────┤
│ public │ tbl  │ table │ postgres │
│ public │ typ  │ table │ postgres │
└────────┴──────┴───────┴──────────┘
(2 rows)

localhost postgres@t=# drop table typ;
ERROR:  2BP01: cannot drop table typ because other objects depend on it
DETAIL:  column abc of table tbl depends on type typ
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
LOCATION:  reportDependentObjects, dependency.c:973

localhost postgres@t=# drop table typ cascade;
NOTICE:  00000: drop cascades to column abc of table tbl
LOCATION:  reportDependentObjects, dependency.c:997
DROP TABLE

localhost postgres@t=# \d
         List of relations
┌────────┬──────┬───────┬──────────┐
│ Schema │ Name │ Type  │  Owner   │
├────────┼──────┼───────┼──────────┤
│ public │ tbl  │ table │ postgres │
└────────┴──────┴───────┴──────────┘
(1 row)

localhost postgres@t=# select version();
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                  version                                                   │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ PostgreSQL 12devel on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(1 row)

localhost postgres@t=# \d tbl
ERROR:  42703: column c.relhasoids does not exist
LINE 1: ...riggers, c.relrowsecurity, c.relforcerowsecurity, c.relhasoi...
                                                             ^
LOCATION:  errorMissingColumn, parse_relation.c:3313
###################

-
robins

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

Предыдущее
От: Peter Geoghegan
Дата:
Сообщение: Re: BUG #15609: synchronous_commit=off insert performance regressionwith secondary indexes
Следующее
От: Tom Lane
Дата:
Сообщение: Re: DROP TABLE CASCADE doesn't drop dependencies