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

From Ian Harding
Subject Re: How to insert with a serial
Date
Msg-id sbd3eaac.055@mail.tpchd.org
Whole thread Raw
In response to How to insert with a serial  (elwood@agouros.de (Konstantinos Agouros))
List pgsql-general
Specify all fields except the serial field in your insert so it will use the default (sequence number) value.

INSERT INTO DEVICES (name, type, ownerteamid) VALUES ('scoobydoo', 1, 43)

One funny thing about serial fields is that you CAN insert a value into them, but the sequence has no idea what you
did,so it will merrily assign the next value it knows about when you don't provide a value, potentially causing a
conflict. Therefore, don't do that.  Always let the value be assigned as above. 

PS Check out Bruce's book!

Ian A. Harding
Programmer/Analyst II
Tacoma-Pierce County Health Department
(253) 798-3549
mailto: ianh@tpchd.org

>>> Konstantinos Agouros <elwood@agouros.de> 10/21/01 06:16AM >>>
Hi,

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?

Konstantin
--
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not survive the forming of the cosmos." B'Elana Torres

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


pgsql-general by date:

Previous
From: Markus Wagner
Date:
Subject: where are the memory leaks?
Next
From: "Ian Harding"
Date:
Subject: Dump Error...