Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly

From: Richard Huxton <dev(at)archonet(dot)com>
To: andi <andi(at)mobile-elab(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
Date: 2006-05-24 15:03:26
Message-ID: 447475BE.8050200@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jorge Godoy 2006-05-24 15:21:52 Re: [SQL] (Ab)Using schemas and inheritance
Previous Message Alban Hertroys 2006-05-24 14:48:10 Re: [SQL] (Ab)Using schemas and inheritance