Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created a table like so:

create table doki_data_item2 (like doki_data_item including defaults);

but this new table uses the same sequence as the old table.

So two questions:

  1. How can I copy and table and the necessary sequences easily?
  2. How can I replace a sequence on one table with another sequence?
share|improve this question

Why don't you create a new sequence:

create sequence new_sequence;

Then create the new table

create table doki_data_item2 (like doki_data_item including defaults);

Finally modify the column that is using the old sequence to use the new one:

alter table doki_data_item2 alter column seq_column set default nextval('new_sequence');

You can obviously set various parameters for the newly created sequence to suit your needs.

share|improve this answer
Also ALTER SEQUENCE to set the sequence owner to the table. – Craig Ringer Feb 25 '14 at 14:47
ALTER SEQUENCE new_sequence OWNED BY doki_data_item2.seq_column; More explanation. – Erwin Brandstetter Feb 25 '14 at 22:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.