Re: Updating of serial ID fields
| От | Richard Broersma Jr |
|---|---|
| Тема | Re: Updating of serial ID fields |
| Дата | |
| Msg-id | 20060719213825.4320.qmail@web31804.mail.mud.yahoo.com обсуждение исходный текст |
| Ответ на | Updating of serial ID fields (Lan Barnes <lan@falleagle.net>) |
| Список | 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 по дате отправления: