[Dbix-class] Probleme with nextval() and postgresql 7.4.17

Ludovic Legrand ludovic.legrand at jouy.inra.fr
Tue Oct 7 09:54:30 BST 2008


hi,
I want to select the nextval of the sequence 'seq_id_comparison' of the
table 'Comparison' with this line:

$dbh->resultset('Comparison')->search(undef, {
      select => "nextval('seq_id_comparison')",
      as => 'id_comp',
      })->single->get_column('id_comp');
SQL equivalent:
SELECT NEXTVAL('seq_id_comparison');

The SQL statement gives last_value + 1, that's ok, while the DBIx
request gives something like last_value + 500 ...
How to explain this increment ?

Sequence table:
   sequence_name   | last_value | increment_by |      max_value      |
min_value | cache_value | log_cnt | is_cycled | is_called
-------------------+------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
 seq_id_comparison |      10817 |            1 | 9223372036854775807
|         1 |           1 |      29 | f         | t

Schema of the table Comparison
__PACKAGE__->load_components(qw/ PK::Auto Core /);
__PACKAGE__->table('Comparison');
__PACKAGE__->add_columns(
             id_comparison =>
             {
                 data_type      => 'INTEGER',
                 is_nullable    => 0,
                 is_foreign_key => 0,
                 is_auto_increment => 1,
                 sequence       => 'seq_id_comparison',
                 default_value  => "nextval('seq_id_comparison')",
             },
             { ... },
             );
__PACKAGE__->set_primary_key( 'id_comparison' );
__PACKAGE__->sequence('seq_id_comparison');

Thanks

Ludovic Legrand




More information about the DBIx-Class mailing list