pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Andrew Sullivan <ajs@crankycanuck.ca>
Cc: pgsql-sql@postgresql.org
Subject: Re: PLEASE  help ME , HOW TO GENERATE PRIMARY Keys on the fly
Date: Fri, 26 May 2006 09:08:20 -0500
Message-ID: <20060526140820.GA17450@wolff.to> (raw)
In-Reply-To: <20060526105037.GB5492@phlogiston.dyndns.org>
References: <20060526101207.5C4B35B0B83@svr4.postgresql.org>
	<20060526105037.GB5492@phlogiston.dyndns.org>

On Fri, May 26, 2006 at 06:50:37 -0400,
  Andrew Sullivan <ajs@crankycanuck.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.



view thread (11+ messages)  latest in thread

Message-ID: <20060526140820.GA17450@wolff.to>
Permalink:  ../20060526140820.GA17450@wolff.to/
Also on:    postgresql.org/message-id/20060526140820.GA17450@wolff.to

 · 

reply

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: bruno@wolff.to, ajs@crankycanuck.ca
  Subject: Re: PLEASE  help ME , HOW TO GENERATE PRIMARY Keys on the fly
  In-Reply-To: <20060526140820.GA17450@wolff.to>

* 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