BUG #9048: Misleading error in transferring sequence between tables - Mailing list pgsql-bugs

From m.sakrejda@gmail.com
Subject BUG #9048: Misleading error in transferring sequence between tables
Date
Msg-id 20140131020328.13610.47977@wrigleys.postgresql.org
Whole thread Raw
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      9048
Logged by:          Maciek Sakrejda
Email address:      m.sakrejda@gmail.com
PostgreSQL version: 9.3.2
Operating system:   Ubuntu 13.04 64-bit
Description:

If I run the following SQL:

CREATE TABLE events (id serial);
ALTER TABLE events RENAME TO old_events;
CREATE TABLE events (LIKE old_events INCLUDING ALL);

ALTER TABLE old_events ALTER COLUMN id DROP DEFAULT;
DROP TABLE old_events;

The drop fails with:

ERROR:  cannot drop table old_events because other objects depend on it
DETAIL:  default for table events column id depends on sequence
events_id_seq
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

Following the HINT advice would technically resolve this particular issue,
but in this case, what I'd really like to do is transfer the sequence to the
new table (someone on IRC helpfully suggested "ALTER SEQUENCE events_id_seq
OWNED BY events.id", which is exactly what I was looking for).

It's especially confusing, since once I drop the default, there is no clear
relationship between the sequence and the old_events table:

maciek=# \d+ old_events
                       Table "public.old_events"
 Column |  Type   | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
 id     | integer | not null  | plain   |              |
Has OIDs: no

A '\d+' on the sequence itself does show the owner, but while the DETAIL
points out the sequence is the issue, it does not tell me about the
relationship to the parent table.

Could the error message suggest changing the ownership when there is
ownership but no functional dependency and there *is* a functional
dependency from another object?

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #9046: vacuum analyze fails on a table that has domain that is a date rage
Next
From: bashtanov@imap.cc
Date:
Subject: BUG #9050: pg_stat_statements() contains rows with the same dbid, userid and query