Re: sequence

From: Manuel Sugawara <masm(at)fciencias(dot)unam(dot)mx>
To: Robert Morgan <robert_(at)ihug(dot)co(dot)nz>
Cc: postgres <pgsql-novice(at)postgresql(dot)org>
Subject: Re: sequence
Date: 2004-05-24 01:34:58
Message-ID: m31xla38vx.fsf@conexa.fciencias.unam.mx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Robert Morgan <robert_(at)ihug(dot)co(dot)nz> writes:

> Do I need to drop the existing column and create a new one using
> create sequence.....?

No, or at least not necessarily. You can create the sequence and then
alter the existing column definition to get its default value from
that sequence, for instance, suppose that your table name is foo and
the column's name is bar:

create sequence new_seq;
select setval('new_seq', select max(bar) from foo);
alter table foo alter column bar set default nextval(new_seq');

Regards,
Manuel.

In response to

  • sequence at 2004-05-23 21:47:17 from Robert Morgan

Browse pgsql-novice by date

  From Date Subject
Next Message Rajan Bhide 2004-05-24 05:40:46 Re: !!URGENT!! Should I keep INDEX on the table?
Previous Message ghaverla 2004-05-23 23:31:10 Re: phppgadmin on Debian/unstable (sort of)