Re: How to insert with a serial
От | Rich Shepard |
---|---|
Тема | Re: How to insert with a serial |
Дата | |
Msg-id | Pine.LNX.4.33.0110221016040.24458-100000@salmo.appl-ecosys.com обсуждение исходный текст |
Ответ на | How to insert with a serial (elwood@agouros.de (Konstantinos Agouros)) |
Список | pgsql-general |
On 21 Oct 2001, Konstantinos Agouros wrote: > I have a table defined like this: > > Attribute | Type | Modifier > -------------+-----------------------+------------------------------------------ > name | character varying(40) | > type | integer | > id | integer | not null default nextval('serial'::text) > ownerteamid | integer | > Index: devices_pkey > > How do I insert into it so that id is automatically incremented? Look at the SERIAL data type. Create a table to hold the numbers: CREATE SEQUENCE name_id_seq; CREATE TABLE person (id INT4 NOT NULL DEFAULT nextval('name_id_seq'), name VCHAR(40), ...); CREATE UNIQUE INDEX name_id_seq ON person (id); HTH, Rich Dr. Richard B. Shepard, President Applied Ecosystem Services, Inc. (TM) 2404 SW 22nd Street | Troutdale, OR 97060-1247 | U.S.A. + 1 503-667-4517 (voice) | + 1 503-667-8863 (fax) | rshepard@appl-ecosys.com http://www.appl-ecosys.com
В списке pgsql-general по дате отправления: