Re: Automatically update sequence - Mailing list pgsql-novice

From Sean Davis
Subject Re: Automatically update sequence
Date
Msg-id 264855a00803280928o3267498eydd0f36b58666d07a@mail.gmail.com
Whole thread Raw
In response to Automatically update sequence  (Ognjen Blagojevic <ognjen@etf.bg.ac.yu>)
List pgsql-novice
On Fri, Mar 28, 2008 at 11:54 AM, Ognjen Blagojevic <ognjen@etf.bg.ac.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

pgsql-novice by date:

Previous
From: Ognjen Blagojevic
Date:
Subject: Automatically update sequence
Next
From: Alan Hodgson
Date:
Subject: Re: Automatically update sequence