Reputation: 3313
I have an existing table in a db, FK'd from several others, SQL below:
CREATE TABLE forecastsource (
source_id integer DEFAULT nextval(('public.forecastsource_source_id_seq'::text)::regclass) NOT NULL,
source_name character varying NOT NULL
);
I want to remove the autoincrement from the id field, and just move it to be a int field (without losing the current data in the table). How would I do that, other than dropping and recreating the table?
Upvotes: 22
Views: 21271
Reputation: 796
In my case this was right solution
ALTER TABLE tc_user ALTER COLUMN u_id DROP IDENTITY
Upvotes: 3
Reputation:
Just drop the default value:
ALTER TABLE forecastsource ALTER COLUMN source_id DROP DEFAULT;
You probably also want to drop the sequence then.
Upvotes: 37