If a value is not specified for a PK column when creating a Class::DBI
object, Class::DBI attempts to insert a row with NULL as the "value" for
this column. This works with MySQL auto-id columns, since MySQL ignores
the bogus NULL, but does not work with PostgreSQL's auto-id ("serial")
columns; the NULL overrides the default.
This appears to be an unintended result of the following test in the
_init subroutine:
if (@primary_columns == grep defined, @{$data}{@primary_columns}) {
If I'm not mistaken, this assigns undef/NULL to each missing PK column
and then checks whether each PK column has a value matching its name! I
believe this is actually meant to check that each PK column has been
given a value, which I think should be written:
if (@primary_columns == grep exists $data->{$_}, @primary_columns) {
Secondly the _auto_increment_value subroutine doesn't work with
PostgreSQL. The appropriate expression is:
$dbh->last_insert_id(undef, undef, $self->table, undef)