1 package DBIx::DBSchema::DBD::Pg;
4 use vars qw($VERSION @ISA %typemap);
5 use DBIx::DBSchema::DBD;
8 @ISA = qw(DBIx::DBSchema::DBD);
16 DBIx::DBSchema::DBD::Pg - PostgreSQL native driver for DBIx::DBSchema
23 $dbh = DBI->connect('dbi:Pg:dbname=database', 'user', 'pass');
24 $schema = new_native DBIx::DBSchema $dbh;
28 This module implements a PostgreSQL-native driver for DBIx::DBSchema.
33 my($proto, $dbh, $table) = @_;
34 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
35 SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull
36 FROM pg_class c, pg_attribute a, pg_type t
37 WHERE c.relname = '$table'
38 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
40 $sth->execute or die $sth->errstr;
46 ( $_->{'attlen'} == -1
47 ? $_->{'atttypmod'} - 4
53 } @{ $sth->fetchall_arrayref({}) };
57 my($proto, $dbh, $table) = @_;
58 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
59 SELECT a.attname, a.attnum
60 FROM pg_class c, pg_attribute a, pg_type t
61 WHERE c.relname = '${table}_pkey'
62 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
64 $sth->execute or die $sth->errstr;
65 my $row = $sth->fetchrow_hashref or return '';
70 my($proto, $dbh, $table) = @_;
71 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $_ ) ] }
72 grep { $proto->_is_unique($dbh, $_ ) }
73 $proto->_all_indices($dbh, $table)
78 my($proto, $dbh, $table) = @_;
79 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $_ ) ] }
80 grep { ! $proto->_is_unique($dbh, $_ ) }
81 $proto->_all_indices($dbh, $table)
86 my($proto, $dbh, $table) = @_;
87 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
89 FROM pg_class c, pg_class c2, pg_index i
90 WHERE c.relname = '$table' AND c.oid = i.indrelid AND i.indexrelid = c2.oid
92 $sth->execute or die $sth->errstr;
93 map { $_->{'relname'} }
94 grep { $_->{'relname'} !~ /_pkey$/ }
95 @{ $sth->fetchall_arrayref({}) };
99 my($proto, $dbh, $index) = @_;
100 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
101 SELECT a.attname, a.attnum
102 FROM pg_class c, pg_attribute a, pg_type t
103 WHERE c.relname = '$index'
104 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
106 $sth->execute or die $sth->errstr;
107 map { $_->{'attname'} } @{ $sth->fetchall_arrayref({}) };
111 my($proto, $dbh, $index) = @_;
112 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
114 FROM pg_index i, pg_class c, pg_am a
115 WHERE i.indexrelid = c.oid AND c.relname = '$index' AND c.relam = a.oid
117 $sth->execute or die $sth->errstr;
118 my $row = $sth->fetchrow_hashref or die 'guru meditation #420';
119 $row->{'indisunique'};
124 Ivan Kohler <ivan-dbix-dbschema@420.am>
128 Copyright (c) 2000 Ivan Kohler
129 Copyright (c) 2000 Mail Abuse Prevention System LLC
131 This program is free software; you can redistribute it and/or modify it under
132 the same terms as Perl itself.
138 columns doesn't return column default information.
142 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>, L<DBI::DBD>