Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly - Mailing list pgsql-sql

From Andrew Sullivan
Subject Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
Date
Msg-id 20060526105037.GB5492@phlogiston.dyndns.org
Whole thread Raw
In response to Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly  ("andi" <andi@mobile-elab.com>)
Responses Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
List pgsql-sql
On Fri, May 26, 2006 at 05:11:26PM +0700, andi wrote:
> select rank() over(order by testeridpk ) as rank , * from tester;
> 
> I get the result is like this, 
> 
> 
> RANK   TESTERIDPK       TESTER_NAME
> 
> 1     10                TESSS
> 
> 2     90                NAMAAA
> 
> 3     100               UUUUUUUU
> 
> 
> How in postgres sql I get the same result , please help me, because iam
> really frustating with this duty.

There's no built in for that that I know of.  You could use a
temporary sequence to do it:

BEGIN;
CREATE SEQUENCE tempseq;
SELECT nextval('tempseq') as rank, testeridpk, tester_name FROM testersORDER BY testeridpk;
ROLLBACK;

which, I _think_, will get you what you want (i.e. that's not
tested).  The ROLLBACK is just there to clean up the sequence.

A

-- 
Andrew Sullivan  | ajs@crankycanuck.ca
"The year's penultimate month" is not in truth a good way of saying
November.    --H.W. Fowler


pgsql-sql by date:

Previous
From: "Penchalaiah P."
Date:
Subject: hi how to use encryption for incomtax in postgresql
Next
From: Andrew Sullivan
Date:
Subject: Re: hi how to use encryption for incomtax in postgresql