Skip site navigation (1) Skip section navigation (2)

Automatically update sequence

From: Ognjen Blagojevic <ognjen(at)etf(dot)bg(dot)ac(dot)yu>
To: pgsql-novice(at)postgresql(dot)org
Subject: Automatically update sequence
Date: 2008-03-28 15:54:11
Message-ID: 47ED14A3.6060109@etf.bg.ac.yu (view raw or flat)
Thread:
Lists: pgsql-novice
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.

Regards,
Ognjen

Responses

pgsql-novice by date

Next:From: Sean DavisDate: 2008-03-28 16:28:58
Subject: Re: Automatically update sequence
Previous:From: Sean DavisDate: 2008-03-28 15:11:55
Subject: Re: Documentation Tool

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group