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

From Richard Huxton
Subject Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
Date
Msg-id 447475BE.8050200@archonet.com
Whole thread Raw
In response to PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly  ("andi" <andi@mobile-elab.com>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: "Franco Bruno Borghesi"
Date:
Subject: Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
Next
From: "Worky Workerson"
Date:
Subject: Warehouse Schema