pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedrenaming+recreating table w/default sequence causes dependency seq issue
4+ messages / 3 participants
[nested] [flat]
* renaming+recreating table w/default sequence causes dependency seq issue
@ 2012-08-08 00:10 Todd Kover <kovert@omniscient.com>
2012-08-08 03:37 ` Re: renaming+recreating table w/default sequence causes dependency seq issue Alvaro Herrera <alvherre@2ndquadrant.com>
2012-08-08 03:42 ` Re: renaming+recreating table w/default sequence causes dependency seq issue Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 4+ messages in thread
From: Todd Kover @ 2012-08-08 00:10 UTC (permalink / raw)
To: pgsql-bugs
I saw issues around renaming tables and not renaming sequences in the TODO
list but did not see anything about this. Apologies if I missed it.
This is with a 9.1.4 server (enterprisedb download on mac os/x lion) and also
seen on 9.1.3 built from netbsd pkgsrc.
It appears that something is amiss if you try to drop a table that has been
renamed that used to have a default mapping to a sequence:
Given this:
---<snip>---
drop table IF EXISTS foo;
drop table IF EXISTS foo_v26;
create table foo (id serial not null, bar integer );
alter table foo alter column id drop default;
alter table foo rename to foo_v26;
create table foo (id integer not null, bar integer );
alter table foo alter id SET DEFAULT nextval('foo_id_seq');
drop table foo_v26;
---<snip>---
everthing works as expected until the final drop, which says:
jazzhands=> drop table foo_v26;
ERROR: cannot drop table foo_v26 because other objects depend on it
DETAIL: default for table foo column id depends on sequence foo_id_seq
HINT: Use DROP ... CASCADE to drop the dependent objects too.
however...
jazzhands=> \d foo;
Table "public.foo"
Column | Type | Modifiers
--------+---------+--------------------------------------------------
id | integer | not null default nextval('foo_id_seq'::regclass)
jazzhands=> \d foo_v26;
Table "public.foo_v26"
Column | Type | Modifiers
--------+---------+-----------
id | integer | not null
Interestingly, I can drop table foo without any complaints.
It seems like the dependency did not move (it also seems like its
backwards but that's probably all me).
Sadly, if I move setting the default to after I drop the old table, the
sequence goes away, so I am still digging into a work around.
thanks,
-Todd
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: renaming+recreating table w/default sequence causes dependency seq issue
2012-08-08 00:10 renaming+recreating table w/default sequence causes dependency seq issue Todd Kover <kovert@omniscient.com>
@ 2012-08-08 03:37 ` Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 0 replies; 4+ messages in thread
From: Alvaro Herrera @ 2012-08-08 03:37 UTC (permalink / raw)
To: Todd Kover <kovert@omniscient.com>; +Cc: pgsql-bugs
Excerpts from Todd Kover's message of mar ago 07 20:10:25 -0400 2012:
> Given this:
> ---<snip>---
> drop table IF EXISTS foo;
> drop table IF EXISTS foo_v26;
>
> create table foo (id serial not null, bar integer );
> alter table foo alter column id drop default;
>
> alter table foo rename to foo_v26;
>
> create table foo (id integer not null, bar integer );
>
> alter table foo alter id SET DEFAULT nextval('foo_id_seq');
>
> drop table foo_v26;
> ---<snip>---
>
> everthing works as expected until the final drop, which says:
>
> jazzhands=> drop table foo_v26;
> ERROR: cannot drop table foo_v26 because other objects depend on it
> DETAIL: default for table foo column id depends on sequence foo_id_seq
> HINT: Use DROP ... CASCADE to drop the dependent objects too.
I think you need an ALTER SEQUENCE .. OWNED BY to fix up dependencies
for the sequence.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: renaming+recreating table w/default sequence causes dependency seq issue
2012-08-08 00:10 renaming+recreating table w/default sequence causes dependency seq issue Todd Kover <kovert@omniscient.com>
@ 2012-08-08 03:42 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-08-08 23:42 ` Re: renaming+recreating table w/default sequence causes dependency seq issue Todd Kover <kovert@omniscient.com>
1 sibling, 1 reply; 4+ messages in thread
From: Tom Lane @ 2012-08-08 03:42 UTC (permalink / raw)
To: Todd Kover <kovert@omniscient.com>; +Cc: pgsql-bugs
Todd Kover <kovert@omniscient.com> writes:
> I saw issues around renaming tables and not renaming sequences in the TODO
> list but did not see anything about this. Apologies if I missed it.
> This is with a 9.1.4 server (enterprisedb download on mac os/x lion) and also
> seen on 9.1.3 built from netbsd pkgsrc.
> It appears that something is amiss if you try to drop a table that has been
> renamed that used to have a default mapping to a sequence:
> Given this:
> ---<snip>---
> drop table IF EXISTS foo;
> drop table IF EXISTS foo_v26;
> create table foo (id serial not null, bar integer );
> alter table foo alter column id drop default;
> alter table foo rename to foo_v26;
> create table foo (id integer not null, bar integer );
> alter table foo alter id SET DEFAULT nextval('foo_id_seq');
> drop table foo_v26;
> ---<snip>---
> everthing works as expected until the final drop, which says:
> jazzhands=> drop table foo_v26;
> ERROR: cannot drop table foo_v26 because other objects depend on it
> DETAIL: default for table foo column id depends on sequence foo_id_seq
> HINT: Use DROP ... CASCADE to drop the dependent objects too.
I don't see any bug there. The ALTER DROP DEFAULT command does not
remove the sequence's dependence on foo.id; nor for that matter does
ALTER SET DEFAULT create an auto-drop dependency on the new table.
See ALTER SEQUENCE OWNED BY if you want to dissociate a serial column's
sequence from the column, or reattach it to another column.
Formally speaking, a "serial column" is shorthand for creating an
integer (or bigint) column, creating a sequence, associating them
as though by ALTER SEQUENCE OWNED BY, and setting the column's default
to nextval('sequence-name').
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: renaming+recreating table w/default sequence causes dependency seq issue
2012-08-08 00:10 renaming+recreating table w/default sequence causes dependency seq issue Todd Kover <kovert@omniscient.com>
2012-08-08 03:42 ` Re: renaming+recreating table w/default sequence causes dependency seq issue Tom Lane <tgl@sss.pgh.pa.us>
@ 2012-08-08 23:42 ` Todd Kover <kovert@omniscient.com>
0 siblings, 0 replies; 4+ messages in thread
From: Todd Kover @ 2012-08-08 23:42 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs
> I don't see any bug there. The ALTER DROP DEFAULT command does not
> remove the sequence's dependence on foo.id; nor for that matter
> does ALTER SET DEFAULT create an auto-drop dependency on the new
> table. See ALTER SEQUENCE OWNED BY if you want to dissociate a
> serial column's sequence from the column, or reattach it to another
> column.
>
> Formally speaking, a "serial column" is shorthand for creating an
> integer (or bigint) column, creating a sequence, associating them as
> though by ALTER SEQUENCE OWNED BY, and setting the column's default
> to nextval('sequence-name').
I stand corrected. It would be nice if \ds or \ds+ or something showed
this relationship so it was evident. That's more of a feature request
than a bug fix tho.
apologies for the misdirection.
-Todd
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2012-08-08 23:42 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-08-08 00:10 renaming+recreating table w/default sequence causes dependency seq issue Todd Kover <kovert@omniscient.com>
2012-08-08 03:37 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2012-08-08 03:42 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-08-08 23:42 ` Todd Kover <kovert@omniscient.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