From: Tom Lane <tgl@sss.pgh.pa.us>
To: nickf@ontko.com
Cc: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: How do I create unique IDs for an existing set of records
Date: Fri, 26 Apr 2002 12:14:39 -0400
Message-ID: <26777.1019837679@sss.pgh.pa.us> (raw)
In-Reply-To: <NEBBLAAHGLEEPCGOBHDGOELNENAA.nickf@ontko.com>
References: <NEBBLAAHGLEEPCGOBHDGOELNENAA.nickf@ontko.com>
"Nick Fankhauser" <nickf@ontko.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, nickf@ontko.com
Subject: Re: How do I create unique IDs for an existing set of records
In-Reply-To: <26777.1019837679@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox