[Dbix-class] Problem with automatic primary keys

Robert Norris rob at cataclysm.cx
Wed Jun 14 03:54:09 CEST 2006


> I almost always let PostgreSQL define my sequences:
> 
> CREATE TABLE e_group (
>     groupid SERIAL PRIMARY KEY,
>     name TEXT NOT NULL
> );
> 
> This is equivalent to:
> 
> CREATE SEQUENCE e_group_pk;
> CREATE TABLE e_group (
>     groupid INTEGER PRIMARY KEY DEFAULT nextval('e_group_pk'),
>     name TEXT NOT NULL
> );

I knew about the "default nextval" method, but hadn't seen "serial"
before. I'll use that from now on.

> DBIx::Class has automatic sequence detection for some databases,
> including PostgreSQL.

Yeah, I read about the auto detection, but when it didn't work I started
trying things. I've removed it now, no use having unneeded clutter.

> > My understanding is that PK::Auto will make it setup groupid
> > automatically by getting a new value from the sequence. Is that
> > right?
> 
> Sorta.  PK::Auto assumes the database will fill groupid itself.  On
> insert it queries the storage backend for the "last insert id", then
> sets the primary key field on your result instance.

Thats were I was off. Thanks for clarifying that, its working very
nicely now.

On to the next thing .. :)

Rob.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060614/382f61a9/attachment.pgp 


More information about the Dbix-class mailing list