From: | "Mitch Vincent" <mvincent(at)cablespeed(dot)com> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to insert with a serial |
Date: | 2001-10-22 18:01:31 |
Message-ID: | 004801c15b23$94f85450$1e51000a@mitch |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
insert 'ing a NULL in place of the serial will work too, yes?
INSERT INTO DEVICES (my_serial_id, name, type, ownerteamid) VALUES
(NULL,'scoobydoo', 1, 43);
-Mitch
----- Original Message -----
From: "Ian Harding" <ianh(at)tpchd(dot)org>
To: <elwood(at)agouros(dot)de>; <pgsql-general(at)postgresql(dot)org>
Sent: Monday, October 22, 2001 12:43 PM
Subject: Re: [GENERAL] How to insert with a serial
> 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(at)tpchd(dot)org
>
> >>> Konstantinos Agouros <elwood(at)agouros(dot)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(at)agouros(dot)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(at)postgresql(dot)org
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2001-10-22 18:58:59 | Re: Sequence problems during restart |
Previous Message | Flávio Brito | 2001-10-22 17:49:41 | Re: How to insert with a serial |