Skip site navigation (1) Skip section navigation (2)

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: (view raw or whole 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.


Richard Broersma Jr.

In response to

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group