Re: How to insert with a serial - Mailing list pgsql-general

From Rich Shepard
Subject Re: How to insert with a serial
Date
Msg-id Pine.LNX.4.33.0110221016040.24458-100000@salmo.appl-ecosys.com
Whole thread Raw
In response to How to insert with a serial  (elwood@agouros.de (Konstantinos Agouros))
List 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 by date:

Previous
From: Flávio Brito
Date:
Subject: Re: How to insert with a serial
Next
From: Denis Gasparin
Date:
Subject: Re: [ODBC] Writing BLOBS to pgsql via ODBC using VB