From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: wondertx@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15853: DROP TABLE CASCADE drops sequence that other tables depend on
Date: Sat, 15 Jun 2019 12:43:33 -0400
Message-ID: <22527.1560617013@sss.pgh.pa.us> (raw)
In-Reply-To: <20190615161358.GA31948@alvherre.pgsql>
References: <20190615161358.GA31948@alvherre.pgsql>
Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> On 2019-Jun-15, PG Bug reporting form wrote:
>> The following SQL executed will drop the sequence `t_id_seq`:
>> CREATE TABLE t(id SERIAL, value INT NOT NULL);
>> CREATE TABLE t_bak LIKE t INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING
>> COMMENTS INCLUDING CONSTRAINTS);
>> DROP TABLE t CASCADE;
>> This will drop default value of column `value` in t_bak.
> Yes. The reason the sequence is dropped is that it is owned by the t.id
> column, so when the column goes away, so does the sequence. And this
> cascades to that default value.
Yeah, not a bug. The OP might find that generated-as-identity columns
work more to his liking than SERIAL does: copying them with LIKE creates
an independent new sequence.
regression=# create table src (f1 int generated always as identity);
CREATE TABLE
regression=# create table dest (like src including identity);
CREATE TABLE
regression=# \d+ dest
Table "public.dest"
Column | Type | Collation | Nullable | Default | Storag
e | Stats target | Description
--------+---------+-----------+----------+------------------------------+-------
--+--------------+-------------
f1 | integer | | not null | generated always as identity | plain
| |
Access method: heap
regression=# insert into dest default values;
INSERT 0 1
regression=# insert into dest default values;
INSERT 0 1
regression=# table dest;
f1
----
1
2
(2 rows)
regression=# drop table src;
DROP TABLE
regression=# insert into dest default values;
INSERT 0 1
regression=# insert into dest default values;
INSERT 0 1
regression=# table dest;
f1
----
1
2
3
4
(4 rows)
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, alvherre@2ndquadrant.com, wondertx@gmail.com
Subject: Re: BUG #15853: DROP TABLE CASCADE drops sequence that other tables depend on
In-Reply-To: <22527.1560617013@sss.pgh.pa.us>
References: <20190615161358.GA31948@alvherre.pgsql> <22527.1560617013@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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