Re: dropping sequences
I'm just getting around to dropping the sequence on my table (after a
hiatus)...
I would expect that you would first need to
ALTER TABLE ... COLUMN ... DROP DEFAULT
to remove the dependency on the sequence. Then drop sequence should work.
That doesn't seem to work, strangely -- I've executed the following command:
ALTER TABLE news ALTER COLUMN news_id DROP DEFAULT
Fine, and now my table looks like this:
be_db=# \d news;
Table "public.news"
+-[ RECORD 1 ]----------------------------+
| Column | news_id |
| Type | integer |
| Modifiers | not null |
+-[ RECORD 2 ]----------------------------+
| Column | news_date |
| Type | timestamp without time zone |
| Modifiers | not null |
+-[ RECORD 3 ]----------------------------+
| Column | expire_date |
| Type | date |
| Modifiers | not null |
+-[ RECORD 4 ]----------------------------+
| Column | news_title |
| Type | character varying(64) |
| Modifiers | not null default '' |
+-[ RECORD 5 ]----------------------------+
| Column | news_info |
| Type | text |
| Modifiers | not null |
+-[ RECORD 6 ]----------------------------+
| Column | user_id |
| Type | integer |
| Modifiers | not null |
+-----------+-----------------------------+
Indexes: news_pkey primary key btree (news_id)
Foreign Key constraints: $1 FOREIGN KEY (user_id) REFERENCES
users(user_id) ON UPDATE NO ACTION ON D
ELETE NO ACTION
But when I try to drop the sequence altogether:
be_db=# DROP SEQUENCE news_news_id_seq;
ERROR: Cannot drop sequence news_news_id_seq because table news column
news_id requires it
You may drop table news column news_id instead
Anybody have a suggestion? I just want to remove these sequences from
the database altogether. Am I going to have to drop the news_id column
altogether?
Erik
Import Notes
Reply to msg id not found: Pine.LNX.4.21.0306192331460.29248-100000@ponder.fairway2k.co.ukReference msg id not found: Pine.LNX.4.21.0306192331460.29248-100000@ponder.fairway2k.co.uk
Erik Price <eprice@ptc.com> writes:
But when I try to drop the sequence altogether:
be_db=# DROP SEQUENCE news_news_id_seq;
ERROR: Cannot drop sequence news_news_id_seq because table news column
news_id requires it
That's intentional: the sequence is part of the implementation of a
serial column, and you should not be able to remove it separately.
(You really shouldn't be able to dork with the column's DEFAULT
expression either, but we don't currently have a way to enforce that.)
Anybody have a suggestion? I just want to remove these sequences from
the database altogether. Am I going to have to drop the news_id column
altogether?
If you are really intent on deconstructing the sequence mechanism for
this column, you could find and delete the pg_depend row that represents
the dependency. Details are left as an exercise for the student ...
regards, tom lane