Re: Auto incrementing fields. How?

Поиск
Список
Период
Сортировка
От Brett W. McCoy
Тема Re: Auto incrementing fields. How?
Дата
Msg-id Pine.LNX.4.30.0012191109530.18420-100000@chapelperilous.net
обсуждение исходный текст
Ответ на Auto incrementing fields. How?  (Harry Wood <harry.wood@ic.ac.uk>)
Список 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 по дате отправления:

Предыдущее
От: "Dan Wilson"
Дата:
Сообщение: Re: Auto incrementing fields. How?
Следующее
От: Tulio Oliveira
Дата:
Сообщение: Re: Auto incrementing fields. How?