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;
40 ( $_->{'attlen'} == -1
41 ? $_->{'atttypmod'} - 4
46 } @{ $sth->fetchall_arrayref({}) };
50 my($proto, $dbh, $table) = @_;
51 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
52 SELECT a.attname, a.attnum
53 FROM pg_class c, pg_attribute a, pg_type t
54 WHERE c.relname = '${table}_pkey'
55 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
57 $sth->execute or die $sth->errstr;
58 my $row = $sth->fetchrow_hashref or return '';
63 my($proto, $dbh, $table) = @_;
64 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $_ ) ] }
65 grep { $proto->_is_unique($dbh, $_ ) }
66 $proto->_all_indices($dbh, $table)
71 my($proto, $dbh, $table) = @_;
72 my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $_ ) ] }
73 grep { ! $proto->_is_unique($dbh, $_ ) }
74 $proto->_all_indices($dbh, $table)
79 my($proto, $dbh, $table) = @_;
80 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
82 FROM pg_class c, pg_class c2, pg_index i
83 WHERE c.relname = '$table' AND c.oid = i.indrelid AND i.indexrelid = c2.oid
85 $sth->execute or die $sth->errstr;
86 map { $_->{'relname'} }
87 grep { $_->{'relname'} !~ /_pkey$/ }
88 @{ $sth->fetchall_arrayref({}) };
92 my($proto, $dbh, $index) = @_;
93 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
94 SELECT a.attname, a.attnum
95 FROM pg_class c, pg_attribute a, pg_type t
96 WHERE c.relname = '$index'
97 AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
99 $sth->execute or die $sth->errstr;
100 map { $_->{'attname'} } @{ $sth->fetchall_arrayref({}) };
104 my($proto, $dbh, $index) = @_;
105 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
107 FROM pg_index i, pg_class c, pg_am a
108 WHERE i.indexrelid = c.oid AND c.relname = '$index' AND c.relam = a.oid
110 $sth->execute or die $sth->errstr;
111 my $row = $sth->fetchrow_hashref or die 'guru meditation #420';
112 $row->{'indisunique'};
117 Ivan Kohler <ivan-dbix-dbschema@420.am>
121 Copyright (c) 2000 Ivan Kohler
122 Copyright (c) 2000 Mail Abuse Prevention System LLC
124 This program is free software; you can redistribute it and/or modify it under
125 the same terms as Perl itself.
133 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>, L<DBI::DBD>