1 package DBIx::DBSchema::DBD::Pg;
10 DBIx::DBSchema::DBD::Pg - PostgreSQL native driver for DBIx::DBSchema
17 $dbh = DBI->connect('dbi:Pg:dbname=database', 'user', 'pass');
18 $schema = new_native DBIx::DBSchema $dbh;
22 This module implements a PostgreSQL-native driver for DBIx::DBSchema.
27 my($proto, $dbh, $table) = @_;
28 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
29 SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull
30 FROM pg_class c, pg_attribute a, pg_type t
31 WHERE c.relname = '$table'
32 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
34 $sth->execute or die $sth->errstr;
41 ? $_->{'atttypmod'} - 4
44 } @{ $sth->fetchall_arrayref({}) };
48 my($proto, $dbh, $table) = @_;
49 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
50 SELECT a.attname, a.attnum
51 FROM pg_class c, pg_attribute a, pg_type t
52 WHERE c.relname = '${table}_pkey'
53 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
55 $sth->execute or die $sth->errstr;
56 my $row = $sth->fetchrow_hashref or return '';
61 my($proto, $dbh, $table) = @_;
62 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $_ ) ] }
63 grep { $proto->_is_unique($dbh, $_ ) }
64 $proto->_all_indices($dbh, $table)
69 my($proto, $dbh, $table) = @_;
70 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $_ ) ] }
71 grep { ! $proto->_is_unique($dbh, $_ ) }
72 $proto->_all_indices($dbh, $table)
77 my($proto, $dbh, $table) = @_;
78 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
80 FROM pg_class c, pg_class c2, pg_index i
81 WHERE c.relname = '$table' AND c.oid = i.indrelid AND i.indexrelid = c2.oid
83 $sth->execute or die $sth->errstr;
84 map { $_->{'relname'} }
85 grep { $_->{'relname'} !~ /_pkey$/ }
86 @{ $sth->fetchall_arrayref({}) };
90 my($proto, $dbh, $index) = @_;
91 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
92 SELECT a.attname, a.attnum
93 FROM pg_class c, pg_attribute a, pg_type t
94 WHERE c.relname = '$index'
95 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
97 $sth->execute or die $sth->errstr;
98 map { $_->{'attname'} } @{ $sth->fetchall_arrayref({}) };
102 my($proto, $dbh, $index) = @_;
103 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
105 FROM pg_index i, pg_class c, pg_am a
106 WHERE i.indexrelid = c.oid AND c.relname = '$index' AND c.relam = a.oid
108 $sth->execute or die $sth->errstr;
109 my $row = $sth->fetchrow_hashref or die 'guru meditation #420';
110 $row->{'indisunique'};
115 Ivan Kohler <ivan-dbix-dbschema@420.am>
119 Copyright (c) 2000 Ivan Kohler
120 Copyright (c) 2000 Mail Abuse Prevention System LLC
122 This program is free software; you can redistribute it and/or modify it under
123 the same terms as Perl itself.
131 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>, L<DBI::DBD>