Re: Updating of serial ID fields - Mailing list pgsql-novice

From Richard Broersma Jr
Subject Re: Updating of serial ID fields
Date
Msg-id 20060719213825.4320.qmail@web31804.mail.mud.yahoo.com
Whole thread Raw
In response to Updating of serial ID fields  (Lan Barnes <lan@falleagle.net>)
List pgsql-novice
> I have defined several tables with a field names "id" that is type
> serial-not null-primary index. Here is a partial dump:
>
> CREATE TABLE builds (
>     id serial NOT NULL,
> );
> Now after several iterations, I find that this is no longer happening.
> Also, even though the dumps still list these fields as serial, pgaccess
> now says they're int4.
> I figured these fields were getting updated as automatic triggers. I
> need them to stay consistent for internal integrity. How do I best do
> this?

According the the manual. Serial type is really a short hand notation for:

CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename (
    colname integer DEFAULT nextval('tablename_colname_seq') NOT NULL
);

So it insure that your id increments correctly you could specify DEFAULT as your entry for that
field in your insert command.

http://www.postgresql.org/docs/8.1/interactive/datatype.html#DATATYPE-SERIAL

Regards,

Richard Broersma Jr.


pgsql-novice by date:

Previous
From: Lan Barnes
Date:
Subject: Updating of serial ID fields
Next
From: "Patrick Ng"
Date:
Subject: Re: RE : How do I compile/test a PL/SQL in Postgresql