1 package DBIx::Class::Storage::DBI::Pg;
6 use base qw/DBIx::Class::Storage::DBI/;
8 # __PACKAGE__->load_components(qw/PK::Auto/);
11 my ($self,$source,$col) = @_;
12 my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col));
13 $self->_dbh->last_insert_id(undef,undef,undef,undef, {sequence => $seq});
17 my ($self,$source,$col) = @_;
19 my @pri = $source->primary_columns;
20 my $dbh = $self->_dbh;
21 my ($schema,$table) = $source->name =~ /^(.+)\.(.+)$/ ? ($1,$2)
22 : (undef,$source->name);
23 while (my $col = shift @pri) {
24 my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_hashref;
25 if (defined $info->{COLUMN_DEF} and $info->{COLUMN_DEF} =~
26 /^nextval\(+'([^']+)'::(?:text|regclass)\)/)
29 return $seq =~ /\./ ? $seq : $info->{TABLE_SCHEM} . "." . $seq; # may need to strip quotes -- see if this works
42 DBIx::Class::Storage::DBI::Pg - Automatic primary key class for PostgreSQL
46 # In your table classes
47 __PACKAGE__->load_components(qw/PK::Auto Core/);
48 __PACKAGE__->set_primary_key('id');
49 __PACKAGE__->sequence('mysequence');
53 This class implements autoincrements for PostgreSQL.
57 Marcus Ramberg <m.ramberg@cpan.org>
61 You may distribute this code under the same terms as Perl itself.