Re: Automatically update sequence

From: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>
To: "Ognjen Blagojevic" <ognjen(at)etf(dot)bg(dot)ac(dot)yu>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Automatically update sequence
Date: 2008-03-28 16:28:58
Message-ID: 264855a00803280928o3267498eydd0f36b58666d07a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Mar 28, 2008 at 11:54 AM, Ognjen Blagojevic <ognjen(at)etf(dot)bg(dot)ac(dot)yu> wrote:
> Hi all,
>
> Is it possible to automatically update the sequence after the literal
> value was used in INSERT statement?
>
> For instance,
>
> CREATE SEQUENCE test_table_id; -- test_table_id = 1
> CREATE TABLE test_table (
> id INTEGER NOT NULL DEFAULT nextval('test_table_id') CHECK (id >= 0),
> column1 VARCHAR(255),
> PRIMARY KEY (id)
> )
>
> INSERT INTO test_table (id, column1) VALUES (1000, 'something');
>
> Here, I used literal value for ID (1000), and I want my sequence to be
> updated to 1000 automatically (i.e. without calling setval).
>
> I'm trying to achieve something similar to MySQL's auto_increment feature.

You'll probably want to look at currval and nextval.

Sean

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Alan Hodgson 2008-03-28 16:35:56 Re: Automatically update sequence
Previous Message Ognjen Blagojevic 2008-03-28 15:54:11 Automatically update sequence