cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Gentry" <blackn...@gmail.com>
Subject Re: PostgreSQL sequences revisited
Date Thu, 02 Aug 2007 12:51:03 GMT
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 <blacknext@gmail.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
>

Mime
View raw message