Re: sequence in select

From: Jim Nasby <jnasby(at)pervasive(dot)com>
To: SunWuKung <Balazs(dot)Klein(at)t-online(dot)hu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: sequence in select
Date: 2006-06-22 19:22:03
Message-ID: BC39FD09-712B-45BD-8D7D-2CF94FB62745@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jun 22, 2006, at 9:10 AM, SunWuKung wrote:
> Hi,
> I put the following into a function. Is this always going to give me a
> sequence with an increment of 1 independently from other transactions?
> If not what would be the standard way to return a sequence from a
> query?
>
> CREATE TEMPORARY SEQUENCE rank_seq;
> SELECT nextval('rank_seq') FROM whatever ORDER BY id;
> DROP SEQUENCE rank_seq;

That will do what you want.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris Browne 2006-06-22 19:23:23 Re: OT: publicly available databases?
Previous Message Tom Lane 2006-06-22 19:15:58 Re: Out of memory error in 8.1.0 Win32