1 package DBIx::Class::Schema::Loader::DBI::Pg;
5 use base 'DBIx::Class::Schema::Loader::DBI';
6 use Carp::Clan qw/^DBIx::Class/;
9 our $VERSION = '0.04999_09';
13 DBIx::Class::Schema::Loader::DBI::Pg - DBIx::Class::Schema::Loader::DBI
14 PostgreSQL Implementation.
19 use base qw/DBIx::Class::Schema::Loader/;
21 __PACKAGE__->loader_options( debug => 1 );
27 See L<DBIx::Class::Schema::Loader::Base>.
34 $self->next::method(@_);
35 $self->{db_schema} ||= 'public';
38 sub _table_uniq_info {
39 my ($self, $table) = @_;
41 # Use the default support if available
42 return $self->next::method($table)
43 if $DBD::Pg::VERSION >= 1.50;
46 my $dbh = $self->schema->storage->dbh;
48 # Most of the SQL here is mostly based on
49 # Rose::DB::Object::Metadata::Auto::Pg, after some prodding from
50 # John Siracusa to use his superior SQL code :)
52 my $attr_sth = $self->{_cache}->{pg_attr_sth} ||= $dbh->prepare(
53 q{SELECT attname FROM pg_catalog.pg_attribute
54 WHERE attrelid = ? AND attnum = ?}
57 my $uniq_sth = $self->{_cache}->{pg_uniq_sth} ||= $dbh->prepare(
58 q{SELECT x.indrelid, i.relname, x.indkey
61 JOIN pg_catalog.pg_class c ON c.oid = x.indrelid
62 JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
63 JOIN pg_catalog.pg_constraint con ON con.conname = i.relname
64 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
66 x.indisunique = 't' AND
74 $uniq_sth->execute($self->db_schema, $table);
75 while(my $row = $uniq_sth->fetchrow_arrayref) {
76 my ($tableid, $indexname, $col_nums) = @$row;
77 $col_nums =~ s/^\s+//;
78 my @col_nums = split(/\s+/, $col_nums);
82 $attr_sth->execute($tableid, $_);
83 my $name_aref = $attr_sth->fetchrow_arrayref;
84 push(@col_names, $name_aref->[0]) if $name_aref;
88 warn "Failed to parse UNIQUE constraint $indexname on $table";
91 push(@uniqs, [ $indexname => \@col_names ]);
98 sub _extra_column_info {
99 my ($self, $info) = @_;
102 if ($info->{COLUMN_DEF} && $info->{COLUMN_DEF} =~ /\bnextval\(/i) {
103 $extra_info{is_auto_increment} = 1;
111 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
112 L<DBIx::Class::Schema::Loader::DBI>