Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql drop table

Tags:

postgresql

I have two tables (tbl and tbl_new) that both use the same sequence (tbl_id_seq). I'd like to drop one of those tables. On tbl, I've removed the modifier "not null default nextval('tbl_id_seq'::regclass)" but that modifier remains on tbl_new. I'm getting the following error:

ERROR: cannot drop table tbl because other objects depend on it DETAIL: default for table tbl_new column id depends on sequence tbl_id_seq

After reviewing http://www.postgresql.org/docs/9.1/static/sql-droptable.html It looks like there is only CASCADE and RESTRICT as options.

like image 519
Russell Avatar asked Feb 02 '26 05:02

Russell


1 Answers

You need to decouple the sequence and the table it "belongs" to:

ALTER SEQUENCE "tbl_id_seq" OWNED BY NONE;

I suppose it was created automatically (and "bound") by defining the tbl_id field of tbl as SERIAL.

like image 128
Milen A. Radev Avatar answered Feb 03 '26 22:02

Milen A. Radev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!