FAQ
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,
dev_label character varying(25),
build_label character varying(25),
build_category character varying(15),
sw_delta_build text,
request_date date,
delivery_date date,
scm_remarks text,
requester character varying(25),
build_reason text,
build_number character varying(5),
code_line character varying(25),
unit_test_results text,
change_lists_submitted text,
lines_of_code character varying(8),
build_logs text,
special_instructions text,
build_status character varying(10),
scm_builder character varying(15)
);

The field in question is the first field.

I have written front ends in Tcl/Tk (using pgtcl) to, among other
things, insert records. Originally, I added logic to get the last value
on this field, increment it, and then insert the new value. However, I
noticed that this happened whether or not I added the logic, so I
stopped doing that.

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 have done several schema saves, db drops, and schema restores. Did I
lose something?

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?

TIA,

--
Lan Barnes
Linux Guy, SCM Specialist
Tcl/Tk Enthusiast

No matter how good you feel, if four friends tell you you're drunk,
you'd better lie down.
- Theodore Sorensen

Search Discussions

  • Richard Broersma Jr at Jul 19, 2006 at 9:38 pm

    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-novice @
categoriespostgresql
postedJul 19, '06 at 9:28p
activeJul 19, '06 at 9:38p
posts2
users2
websitepostgresql.org
irc#postgresql

2 users in discussion

Richard Broersma Jr: 1 post Lan Barnes: 1 post

People

Translate

site design / logo © 2023 Grokbase