DROP TABLE CASCADE doesn't drop dependencies - Mailing list pgsql-bugs

From Robins Tharakan
Subject DROP TABLE CASCADE doesn't drop dependencies
Date
Msg-id CAEP4nAzV3RGu7hgh7dXC44UsnDeFYEt4yZU_dnzmShNn33FGDQ@mail.gmail.com
Whole thread Raw
Responses 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>)
List 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 by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: BUG #15609: synchronous_commit=off insert performance regressionwith secondary indexes
Next
From: Tom Lane
Date:
Subject: Re: DROP TABLE CASCADE doesn't drop dependencies