Automatically update sequence - Mailing list pgsql-novice

From Ognjen Blagojevic
Subject Automatically update sequence
Date
Msg-id 47ED14A3.6060109@etf.bg.ac.yu
Whole thread Raw
Responses Re: Automatically update sequence  ("Sean Davis" <sdavis2@mail.nih.gov>)
Re: Automatically update sequence  (Alan Hodgson <ahodgson@simkin.ca>)
List 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

pgsql-novice by date:

Previous
From: "Sean Davis"
Date:
Subject: Re: Documentation Tool
Next
From: "Sean Davis"
Date:
Subject: Re: Automatically update sequence