Re: problem with serial

From: Chris Angelico <rosuav(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: problem with serial
Date: 2012-04-19 15:01:43
Message-ID: CAPTjJmp5AOuCEme4Tw-MPCX8Yx4zeUHr4SZsNGOtehLXGo2VaA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Apr 20, 2012 at 12:19 AM, Yvon Thoraval <yvon(dot)thoraval(at)gmail(dot)com> wrote:
> even if i rearrange de sequence by :
>
> "SELECT MAX(rowid) FROM items;";
> "SELECT last_value FROM items_rowid_seq;";
> then if last_value is lower than MAX(rowid) i set it to MAX(rowid) :
> "SELECT setval('items_rowid_seq', max(rowid)) FROM items;";

As a side point, I would recommend against doing this. Once you've
"used" a rowid, it's not worth reusing it. You'll save yourself some
headaches down the track if you simply ignore those odd gaps (ditto
the gaps that result from rolled-back transactions) and just DELETE
the rows you're throwing out without bothering to setval the sequence
back.

ChrisA

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yvon Thoraval 2012-04-19 15:05:41 Re: problem with serial
Previous Message jbiskofski 2012-04-19 14:57:07 Re: spanish locale question