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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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