Re: renumber table

Поиск
Список
Период
Сортировка
От David Wilson
Тема Re: renumber table
Дата
Msg-id e7f9235d0806191347x35d991ceoa887a71bfba6c9f5@mail.gmail.com
обсуждение исходный текст
Ответ на Re: renumber table  (Steve Clark <sclark@netwolves.com>)
Список pgsql-general
On Thu, Jun 19, 2008 at 7:54 AM, Steve Clark <sclark@netwolves.com> wrote:

> I am not sure that will do what I want. As an example
> suppose I have 5 rows and the idfield is 1,2,3,4,5
> now row 1 is updated, not the idfield but another column, then row 3 is
> deleted.
> Now I would like to renumber  them such that 1 is 1, 2 is 2, 4 is 4 , 5 is
> 4.
>
> I don't think what you wrote will necessarily keep them in the same relative
> order that they
> were before.

It's ugly and a hack, but if you could do:

1. rename the table
2. create a new copy of the table. give the idfield a sequence.
3. select all the records from the renamed table, ordering by idfield,
and insert all fields other than idfield into the new table.
4. drop the renamed table

You'll maintain ordering and have a nice sequential idfield.
--
- David T. Wilson
david.t.wilson@gmail.com

В списке pgsql-general по дате отправления:

Предыдущее
От: "Scott Marlowe"
Дата:
Сообщение: Re: finding firstname + lastname groups
Следующее
От: Charles Simard
Дата:
Сообщение: FW: finding firstname + lastname groups