Re: How do I create unique IDs for an existing set of records

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: nickf(at)ontko(dot)com
Cc: "PGSQL-SQL" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: How do I create unique IDs for an existing set of records
Date: 2002-04-26 16:14:39
Message-ID: 26777.1019837679@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Nick Fankhauser" <nickf(at)ontko(dot)com> writes:
> I tried:

> update test set new_pk = (select nextval('test_new_pk_seq'));

> but it wants to update *all* of the rows to the current nextval (I was
> hoping it would evaluate nextval on each row).

Yeah, the sub-select is taken (perhaps mistakenly) as something that
can be evaluated only once, because it doesn't depend on the outer
query. You are overthinking the problem; this should work:

update test set new_pk = nextval('test_new_pk_seq');

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Nick Fankhauser 2002-04-26 16:17:51 Re: How do I create unique IDs for an existing set of records
Previous Message Tom Lane 2002-04-26 16:11:36 Re: Wierd error for COPY command