Re: Automatically update sequence

From: Alan Hodgson <ahodgson(at)simkin(dot)ca>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Automatically update sequence
Date: 2008-03-28 16:35:56
Message-ID: 200803280935.56295@hal.medialogik.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Friday 28 March 2008, Ognjen Blagojevic <ognjen(at)etf(dot)bg(dot)ac(dot)yu> wrote:
> Here, I used literal value for ID (1000), and I want my sequence to be
> updated to 1000 automatically (i.e. without calling setval).

You could probably use a trigger to do it, but it's not a great idea.

What you should do is fetch the next value from the sequence yourself and
then use it in the insert. Or, if you're pre-loading existing data, load it
and then set the sequence value afterwards.

--
Alan

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Ognjen Blagojevic 2008-03-28 16:39:43 Re: Automatically update sequence
Previous Message Sean Davis 2008-03-28 16:28:58 Re: Automatically update sequence