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

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
Дата
Msg-id 447475BE.8050200@archonet.com
обсуждение исходный текст
Ответ на PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly  ("andi" <andi@mobile-elab.com>)
Список 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 по дате отправления:

Предыдущее
От: "Franco Bruno Borghesi"
Дата:
Сообщение: Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly
Следующее
От: "Worky Workerson"
Дата:
Сообщение: Warehouse Schema