Search code examples
postgresqldatabase-schema

PostgreSQL change field sequence


There was a problem copying some tables from one schema to another and now I have a few tables with serial fields pointing another schema's sequences. I want to change that dependency.

I need to copy those sequences to the table schema and change the field to point the copies in the current table schema.

Table 1 definition:

CREATE TABLE schema1.table1
(
    gid integer NOT NULL DEFAULT nextval('schema2.table1_seq'::regclass),
    ...
)

I want it to point schema1.table1_seq . Is it posible?


Solution

  • Use ALTER TABLE:

    ALTER TABLE schema1.table1 ALTER gid SET DEFAULT nextval('schema1.table1_seq'::regclass);