pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
DROP TABLE CASCADE doesn't drop dependencies
5+ messages / 3 participants
[nested] [flat]

* DROP TABLE CASCADE doesn't drop dependencies
@ 2019-02-03 23:22  Robins Tharakan <tharakan@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Robins Tharakan @ 2019-02-03 23:22 UTC (permalink / raw)
  To: 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


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: DROP TABLE CASCADE doesn't drop dependencies
@ 2019-02-03 23:42  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robins Tharakan <tharakan@gmail.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2019-02-03 23:42 UTC (permalink / raw)
  To: Robins Tharakan <tharakan@gmail.com>; +Cc: pgsql-bugs

Robins Tharakan <tharakan@gmail.com> writes:
> 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!

Dropping the column is exactly what is supposed to happen: the scope
of the dependency is defined to be just the column of that type, not
the table containing it.

Not sure if this is documented anyplace in the SGML docs, but I'm
pretty sure we have regression test cases for it.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: DROP TABLE CASCADE doesn't drop dependencies
@ 2019-02-04 00:28  Robins Tharakan <tharakan@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Robins Tharakan @ 2019-02-04 00:28 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

Thanks Tom for clarifying promptly (and effectively helping me out), since
that pointed me to find v9.6.6 related bug-fix around this, that is
currently affecting an upgrade.

The v12 DROP does seem like an unrelated issue though, which I happened to
notice coincidentally.
-
robins


On Mon, 4 Feb 2019 at 10:42, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Robins Tharakan <tharakan@gmail.com> writes:
> > 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!
>
> Dropping the column is exactly what is supposed to happen: the scope
> of the dependency is defined to be just the column of that type, not
> the table containing it.
>
> Not sure if this is documented anyplace in the SGML docs, but I'm
> pretty sure we have regression test cases for it.
>
>                         regards, tom lane
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: DROP TABLE CASCADE doesn't drop dependencies
@ 2019-02-04 01:03  Michael Paquier <michael@paquier.xyz>
  parent: Robins Tharakan <tharakan@gmail.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Michael Paquier @ 2019-02-04 01:03 UTC (permalink / raw)
  To: Robins Tharakan <tharakan@gmail.com>; +Cc: pgsql-bugs

On Mon, Feb 04, 2019 at 10:22:43AM +1100, Robins Tharakan wrote:
> 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
> ###################

You may want to check your version of psql here.  We do an effort with
downward compatibility, not upward.  And my guess here is that you are
connected to a v12 server, using at most a v11 psql client.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: DROP TABLE CASCADE doesn't drop dependencies
@ 2019-02-04 08:18  Robins Tharakan <tharakan@gmail.com>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 5+ messages in thread

From: Robins Tharakan @ 2019-02-04 08:18 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-bugs

Upgrading the client did help.

Apologies for the noise and thanks (again) for prompt responses!
-
robins


On Mon, 4 Feb 2019 at 12:03, Michael Paquier <michael@paquier.xyz> wrote:

> On Mon, Feb 04, 2019 at 10:22:43AM +1100, Robins Tharakan wrote:
> > 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
> > ###################
>
> You may want to check your version of psql here.  We do an effort with
> downward compatibility, not upward.  And my guess here is that you are
> connected to a v12 server, using at most a v11 psql client.
> --
> Michael
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-02-04 08:18 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-02-03 23:22 DROP TABLE CASCADE doesn't drop dependencies Robins Tharakan <tharakan@gmail.com>
2019-02-03 23:42 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-02-04 00:28   ` Robins Tharakan <tharakan@gmail.com>
2019-02-04 01:03 ` Michael Paquier <michael@paquier.xyz>
2019-02-04 08:18   ` Robins Tharakan <tharakan@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox