Re: Auto incrementing fields. How? - Mailing list pgsql-general

From Brett W. McCoy
Subject Re: Auto incrementing fields. How?
Date
Msg-id Pine.LNX.4.30.0012191109530.18420-100000@chapelperilous.net
Whole thread Raw
In response to Auto incrementing fields. How?  (Harry Wood <harry.wood@ic.ac.uk>)
List pgsql-general
On Tue, 19 Dec 2000, Harry Wood wrote:

> Anyone know how to create auto incrementing fields?

create sequence my_seq;

create table my_table (
    my_id integer primary key default nextval('my_seq'),
    another_field varchar(10),
    ...
);

OR, you can create an implicit sequence:

create table my_table (
    my_id SERIAL primary key,
    ...
);

If you drop the table later on, though, you will need to drop the created
sequence manually.

When you insert data into the table, do not specify the autoincrement
field in the insert statement:

insert into my_table(another_field) values('some data');

Refer to the Postgres documentation for full details.

-- Brett
                                     http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Politics, as a practice, whatever its professions, has always been the
systematic organisation of hatreds.
        -- Henry Adams, "The Education of Henry Adams"


pgsql-general by date:

Previous
From: "Dan Wilson"
Date:
Subject: Re: Auto incrementing fields. How?
Next
From: Tulio Oliveira
Date:
Subject: Re: Auto incrementing fields. How?