pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: andi <andi@mobile-elab.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: PLEASE  help ME , HOW TO GENERATE PRIMARY Keys on the fly
Date: Wed, 24 May 2006 16:03:26 +0100
Message-ID: <447475BE.8050200@archonet.com> (raw)
In-Reply-To: <20060524103549.1E41C5AF071@svr4.postgresql.org>
References: <20060524103549.1E41C5AF071@svr4.postgresql.org>

andi wrote:
> Dear friends,
> 
> I have table
> 
> MD_CUSTOMER
> 
> MD_CUSTOMERIDPK integer primary key
> NAME                           varchar

OK - two columns.

> But my primary key is not in correct order like
> 
> MD_CUSTOMER
> 
> MD_CUSTOMERIDPK                     NAME
> 
> 10
> ANDI
> 
> 33
> TESTER
> 
> 100                                                            KKK

Not sure what you mean. What does it mean for your primary key to be in 
the "correct order"? I assume you know how to select rows in a specific 
order using the "ORDER BY" clause?


> , so I want to make other primary key to generate sequences 1, 2, 3, . and

How can you have *another* primary key? By definition there can only be 
one primary key.

> in MS SQL SERVER 2005
> 
> I can with Rank() function , but in Postgres how ?

If all you want to do is generate a series of numbers you might look at 
generate_series(), or if you'd like a "row number" then something like:

CREATE TEMPORARY SEQUENCE myseq;
SELECT *,nextval('myseq') FROM mytable;

I have to say though, I'm not sure what you're trying to do. I do get 
the feeling I'd think it was a bad idea once I found out though.

-- 
   Richard Huxton
   Archonet Ltd



view thread (11+ messages)  latest in thread

Message-ID: <447475BE.8050200@archonet.com>
Permalink:  ../447475BE.8050200@archonet.com/
Also on:    postgresql.org/message-id/447475BE.8050200@archonet.com

 · 

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: dev@archonet.com, andi@mobile-elab.com
  Subject: Re: PLEASE  help ME , HOW TO GENERATE PRIMARY Keys on the fly
  In-Reply-To: <447475BE.8050200@archonet.com>

* 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