| From: | Bruno Wolff III <bruno(at)wolff(dot)to> | 
|---|---|
| To: | Andrew Sullivan <ajs(at)crankycanuck(dot)ca> | 
| Cc: | pgsql-sql(at)postgresql(dot)org | 
| Subject: | Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly | 
| Date: | 2006-05-26 14:08:20 | 
| Message-ID: | 20060526140820.GA17450@wolff.to | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-sql | 
On Fri, May 26, 2006 at 06:50:37 -0400,
  Andrew Sullivan <ajs(at)crankycanuck(dot)ca> wrote:
> 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.
The simplest solution is to add the rank information in your application as
it reads the result set.
> 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 testers
> 	ORDER 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.
Rollbacks will not reset sequence values. Use setval to do that.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrew Sullivan | 2006-05-26 14:22:54 | Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly | 
| Previous Message | Richard Huxton | 2006-05-26 12:30:59 | Re: hi how to use encryption for incomtax in postgresql |