1 package DBIx::DBSchema::DBD::Pg;
4 use vars qw($VERSION @ISA %typemap);
5 use DBIx::DBSchema::DBD;
8 @ISA = qw(DBIx::DBSchema::DBD);
12 'LONG VARBINARY' => 'BYTEA',
17 DBIx::DBSchema::DBD::Pg - PostgreSQL native driver for DBIx::DBSchema
24 $dbh = DBI->connect('dbi:Pg:dbname=database', 'user', 'pass');
25 $schema = new_native DBIx::DBSchema $dbh;
29 This module implements a PostgreSQL-native driver for DBIx::DBSchema.
34 my($proto, $dbh, $table) = @_;
35 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
36 SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull
37 FROM pg_class c, pg_attribute a, pg_type t
38 WHERE c.relname = '$table'
39 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
42 $sth->execute or die $sth->errstr;
48 ( $_->{'attlen'} == -1
49 ? $_->{'atttypmod'} - 4
55 } @{ $sth->fetchall_arrayref({}) };
59 my($proto, $dbh, $table) = @_;
60 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
61 SELECT a.attname, a.attnum
62 FROM pg_class c, pg_attribute a, pg_type t
63 WHERE c.relname = '${table}_pkey'
64 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
66 $sth->execute or die $sth->errstr;
67 my $row = $sth->fetchrow_hashref or return '';
72 my($proto, $dbh, $table) = @_;
73 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $_ ) ] }
74 grep { $proto->_is_unique($dbh, $_ ) }
75 $proto->_all_indices($dbh, $table)
80 my($proto, $dbh, $table) = @_;
81 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $_ ) ] }
82 grep { ! $proto->_is_unique($dbh, $_ ) }
83 $proto->_all_indices($dbh, $table)
88 my($proto, $dbh, $table) = @_;
89 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
91 FROM pg_class c, pg_class c2, pg_index i
92 WHERE c.relname = '$table' AND c.oid = i.indrelid AND i.indexrelid = c2.oid
94 $sth->execute or die $sth->errstr;
95 map { $_->{'relname'} }
96 grep { $_->{'relname'} !~ /_pkey$/ }
97 @{ $sth->fetchall_arrayref({}) };
101 my($proto, $dbh, $index) = @_;
102 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
103 SELECT a.attname, a.attnum
104 FROM pg_class c, pg_attribute a, pg_type t
105 WHERE c.relname = '$index'
106 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
108 $sth->execute or die $sth->errstr;
109 map { $_->{'attname'} } @{ $sth->fetchall_arrayref({}) };
113 my($proto, $dbh, $index) = @_;
114 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
116 FROM pg_index i, pg_class c, pg_am a
117 WHERE i.indexrelid = c.oid AND c.relname = '$index' AND c.relam = a.oid
119 $sth->execute or die $sth->errstr;
120 my $row = $sth->fetchrow_hashref or die 'guru meditation #420';
121 $row->{'indisunique'};
126 Ivan Kohler <ivan-dbix-dbschema@420.am>
130 Copyright (c) 2000 Ivan Kohler
131 Copyright (c) 2000 Mail Abuse Prevention System LLC
133 This program is free software; you can redistribute it and/or modify it under
134 the same terms as Perl itself.
140 columns doesn't return column default information.
144 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>, L<DBI::DBD>