mekbib.awoke
mekbib.awoke

Reputation: 1500

Postgres detach a primary key from a sequence

how can i detach a primary key of table from a sequence with out having to drop the table

Upvotes: 5

Views: 1971

Answers (1)

Tom-db
Tom-db

Reputation: 6878

With "detach" you mean probably, removing the default for the column to the next value of the sequence. For example, say you have a table definition like this:

 Column   |  Type   |                           Modifiers                            
------------+---------+----------------------------------------------------------------
 yourcolumn | integer | not null default nextval('yourtable_yourcolumn_seq'::regclass)

you want to remove this part: default nextval('yourtable_yourcolumn_seq'::regclass)

If so, you can do it with this statement:

ALTER TABLE yourtable ALTER COLUMN yourcolumn DROP DEFAULT;

Upvotes: 5

Related Questions