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?
In MySQL, the syntax to reset the AUTO_INCREMENT column using the ALTER TABLE statement is: ALTER TABLE table_name AUTO_INCREMENT = value; table_name. The name of the table whose AUTO_INCREMENT column you wish to reset.
PostgreSQL has the data types smallserial, serial and bigserial; these are not true types, but merely a notational convenience for creating unique identifier columns. These are similar to AUTO_INCREMENT property supported by some other databases.
Just drop the default value:
ALTER TABLE forecastsource ALTER COLUMN source_id DROP DEFAULT;
You probably also want to drop the sequence then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With