Re: PostgreSQL sequences revisited

From: Michael Gentry (blacknex..mail.com)
Date: Thu Aug 02 2007 - 08:51:03 EDT

  • Next message: Andrus Adamchik: "Re: [JIRA] Commented: (CAY-811) Meaningful identity columns: user provided PK values are ignored"

    Again, no JDBC info here, but ...

    I did (this is all done in PgAdmin):

    create table mytable
    ( name varchar(60), pk serial primary key )

    and this was reported:

    NOTICE: CREATE TABLE will create implicit sequence "mytable_pk_seq"
    for serial column "mytable.pk"
    NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
    "mytable_pkey" for table "mytable"

    So I went and looked for the sequence and found:

    CREATE SEQUENCE mytable_pk_seq
      INCREMENT 1
      MINVALUE 1
      MAXVALUE 9223372036854775807
      START 1
      CACHE 1;

    So it did create a sequence for the serial type. I could then do inserts like:

    insert into mytable (name) values ('michael')

    and it would increment the values.

    /dev/mrg

    On 8/2/07, Michael Gentry <blacknex..mail.com> wrote:
    > This doesn't really cover the JDBC driver, but tells a little more
    > about the serial type:
    >
    > http://www.postgresql.org/docs/8.1/static/datatype.html#DATATYPE-SERIAL
    >
    > It looks like declaring something to be serial sets up a sequence,
    > too? I'm always wary of the word "equivalent" in tech docs, though.
    > I've gotten burned by that before. (The old NeXTstep documentation
    > said calling "new" was the equivalent of "alloc" and then "init" --
    > but new didn't call alloc then init.)
    >
    > I can create a scratch DB later and see what it does ...
    >
    > /dev/mrg
    >



    This archive was generated by hypermail 2.0.0 : Thu Aug 02 2007 - 08:51:35 EDT