changing the last_value in a sequence

From: "Aurangzeb M(dot) Agha" <aagha(at)bigfoot(dot)com>
To: PostgreSQL General List <pgsql-general(at)postgresql(dot)org>
Subject: changing the last_value in a sequence
Date: 2003-02-18 18:16:20
Message-ID: Pine.LNX.4.53.0302181004200.26012@cinemaspace.berkeley.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I've discovered a problem in our legacy software todo where, somewhere
along the road, over the last year, a "todo" item in our todo table got
"skipped".

This means that I have 689 records in the table when I should have 690.

I fixed this by inserting a record for the "missing" todo, and updating
it's id to be that of the "missing" todo.

But, I now realize that the problem is that the sequence on that table has
been updating (as it should), but that my insert for the missing todo
helped _for_now_, but I'm going to run across the same issue very soon.
Inserting the "missing" todo took care of the gap in my list of todo's
(1 through 690), but now, the last_value in the sequence for this table
is (691):

cmsdb=# select last_value from todo_todoid_seq;
last_value
------------
691
(1 row)

Meaning that the next todo I insert will have a value of 692, and once
again, I'll have a missing todo (#691).

I quickly figured out that I can't update the last_value in my sequence
table. Any suggestions out ther on how I can tackle this issue to bring
the number of records in the todo table and my last_value into sync?

Sincere Thanks in Advance,
Aurangzeb

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Harry Broomhall 2003-02-18 18:20:52 Re: continuous data from stdin
Previous Message Cristian Custodio 2003-02-18 18:15:39 pgMonitor