1 package DBIx::Class::Schema::Loader::DBI::Pg;
5 use base 'DBIx::Class::Schema::Loader::DBI';
10 DBIx::Class::Schema::Loader::DBI::Pg - DBIx::Class::Schema::Loader::DBI
11 PostgreSQL Implementation.
16 use base qw/DBIx::Class::Schema::Loader/;
18 __PACKAGE__->loader_options(
26 See L<DBIx::Class::Schema::Loader::Base>.
33 $self->next::method(@_);
34 $self->{db_schema} ||= 'public';
37 sub _table_uniq_info {
38 my ($self, $table) = @_;
41 my $dbh = $self->schema->storage->dbh;
43 # Most of the SQL here is mostly based on
44 # Rose::DB::Object::Metadata::Auto::Pg, after some prodding from
45 # John Siracusa to use his superior SQL code :)
47 my $attr_sth = $self->{_cache}->{pg_attr_sth} ||= $dbh->prepare(
48 q{SELECT attname FROM pg_catalog.pg_attribute
49 WHERE attrelid = ? AND attnum = ?}
52 my $uniq_sth = $self->{_cache}->{pg_uniq_sth} ||= $dbh->prepare(
53 q{SELECT x.indrelid, i.relname, x.indkey
56 JOIN pg_catalog.pg_class c ON c.oid = x.indrelid
57 JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
58 JOIN pg_catalog.pg_constraint con ON con.conname = i.relname
59 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
61 x.indisunique = 't' AND
69 $uniq_sth->execute($self->db_schema, $table);
70 while(my $row = $uniq_sth->fetchrow_arrayref) {
71 my ($tableid, $indexname, $col_nums) = @$row;
72 $col_nums =~ s/^\s+//;
73 my @col_nums = split(/\s+/, $col_nums);
77 $attr_sth->execute($tableid, $_);
78 my $name_aref = $attr_sth->fetchrow_arrayref;
79 push(@col_names, $name_aref->[0]) if $name_aref;
83 warn "Failed to parse UNIQUE constraint $indexname on $table";
86 push(@uniqs, [ $indexname => \@col_names ]);
95 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
96 L<DBIx::Class::Schema::Loader::DBI>