From: | Rich Shepard <rshepard(at)appl-ecosys(dot)com> |
---|---|
To: | |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to insert with a serial |
Date: | 2001-10-22 17:21:48 |
Message-ID: | Pine.LNX.4.33.0110221016040.24458-100000@salmo.appl-ecosys.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)appl-ecosys(dot)com
http://www.appl-ecosys.com
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2001-10-22 17:22:27 | Re: [GENERAL] To Postgres Devs : Wouldn't changing the select limit |
Previous Message | Bruce Momjian | 2001-10-22 17:00:15 | Re: [GENERAL] To Postgres Devs : Wouldn't changing the select limit |