renumber table

From: Steve Clark <sclark(at)netwolves(dot)com>
To: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: renumber table
Date: 2008-06-18 20:58:51
Message-ID: 4859770B.9020502@netwolves.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello List,

I have acquired the task of maintaining and existing application that uses postgresql. I am only lightly versed
in sql and have the following problem I need to solve.

I have a table in which each row has a column - row_number. The row_numbers need to be sequential.
Everything is fine until a row in the middle of the table gets deleted, now I need to renumber the remaining
rows so they are sequential again. The table is small, typically less than a 100 rows. Is there a simple way
to do this in sql. I know I can dump the table to an external file and then use 'C' or a bash script to fix up the
row_numbers and then reload the table - but it seems there is probably a more elegant way to do this in sql.

Anyway thanks for any tips.

Steve

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-06-18 21:14:24 Re: Error when trying to drop a tablespace
Previous Message Cyril SCETBON 2008-06-18 20:44:34 Re: Error when trying to drop a tablespace