Hi, This may be a bug, or I may be doing something wrong. Since I can do what I want with Class::DBI and with plain SQL, I think it is a bug.
I have a basic table in postgresql. I want to use it to generate unique ids for different geometric projections, so that points in different projections still have unique ids. The table has one column: CREATE TABLE geom_ids ( gid serial NOT NULL PRIMARY KEY ); I set up the following Schema: package Testbed::SpatialVDS::Model::Schema::geom_ids; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('geom_ids'); __PACKAGE__->add_columns('gid'); __PACKAGE__->set_primary_key(qw/gid/); __PACKAGE__->sequence('geom_ids_gid_seq'); I want to insert a row, using the automatically generated gid, so I write my $vdb =Testbed::SpatialVDS::Model::SpatialVDS->new(); my $new_geoid = $vdb->resultset('geom_ids')->create({}); This fails with: DBD::Pg::st execute failed: ERROR: syntax error at or near ")" at character 23 DBIx::Class::ResultSet::create(): Error executing 'INSERT INTO geom_ids () VALUES ()': ERROR: syntax error at or near ")" at character 23 If I add a dummy column to my table, or CREATE TABLE test_ids ( gid serial NOT NULL PRIMARY KEY, dummy integer default '1' ); and a corresponding entry in my schema: package Testbed::SpatialVDS::Model::Schema::test_ids; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('test_ids'); __PACKAGE__->add_columns(qw/gid dummy/); __PACKAGE__->set_primary_key(qw/gid/); __PACKAGE__->sequence('test_ids_gid_seq'); then the following code: my $vdb =Testbed::SpatialVDS::Model::SpatialVDS->new(); # my $new_geoid = $vdb->resultset('geom_ids')->create({}); my $new_geoid = $vdb->resultset('test_ids')->create({'dummy'=>1}); warn $new_geoid->id; die(); produces: 4 at create_geometries.pl line 11. Died at create_geometries.pl line 12. Class::DBI had no problems inserting into a table with no data (using the default for the one autoincrementing column. (I've been using this technique for years.) But I've run into similar problems with Jakarta's Torque, where it seems the code always wants to have something to do, other than relying on the default values (autoincrements, etc). I tried poking at the code, but the best I could do was trace the failure to the underlying DBIx::Class::Storage::DBI class, the part in package DBIC::SQL::Abstract. But I am out of my league debugging that code. For reference, my Class::DBI class looks like: package EDCU::DBI::GeomId; use 5.008005; use strict; use warnings; use base 'EDCU::DBI'; __PACKAGE__->table('geom_ids'); __PACKAGE__->columns('Primary' => qw/gid/); __PACKAGE__->sequence('geom_ids_gid_seq'); usage: sub getid { my ($self) = @_; my $uniqueid = EDCU::DBI::GeomId->create({}); $self->set('gid'=> $uniqueid->gid); } Any help would be appreciated. Thanks, James _______________________________________________ List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class Wiki: http://dbix-class.shadowcatsystems.co.uk/ IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/