Re: Updating of serial ID fields

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Lan Barnes <lan(at)falleagle(dot)net>, Postgres Newbie <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Updating of serial ID fields
Date: 2006-07-19 21:38:25
Message-ID: 20060719213825.4320.qmail@web31804.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Patrick Ng 2006-07-20 13:24:20 Re: RE : How do I compile/test a PL/SQL in Postgresql
Previous Message Lan Barnes 2006-07-19 20:46:13 Updating of serial ID fields