54 |
=item --pk id |
=item --pk id |
55 |
|
|
56 |
Specify name of primary key column in SQL query. If you allready have primary |
Specify name of primary key column in SQL query. If you allready have primary |
57 |
key on table, and it consists of simgle column (compaund keys are not supported) |
key on table or unique index and it consists of simgle column |
58 |
it will be picked up automatically. |
(compaund keys are not supported) it will be picked up automatically. |
59 |
|
|
60 |
If you specify value which is not unique, you will get just last occurence |
If you specify value which is not unique, you will get just last occurence |
61 |
of that item in index (which might be what you want). That's because specified |
of that item in index (which might be what you want). That's because specified |
156 |
|
|
157 |
warn "# finding primary key for $table\n" if ($c->{debug}); |
warn "# finding primary key for $table\n" if ($c->{debug}); |
158 |
|
|
159 |
$c->{pk} = $dbh->selectrow_array(qq{ |
my $index_fmt = qq{ |
160 |
SELECT |
SELECT |
161 |
a.attname, t.typname |
a.attname, t.typname |
162 |
FROM pg_type t, pg_attribute a |
FROM pg_type t, pg_attribute a |
163 |
WHERE t.oid = a.atttypid AND attrelid = ( |
WHERE t.oid = a.atttypid AND attrelid = ( |
164 |
SELECT indexrelid |
SELECT indexrelid |
165 |
FROM pg_class c, pg_index i |
FROM pg_class c, pg_index i |
166 |
WHERE c.relname = '$table' |
WHERE c.relname = '%s' |
167 |
AND c.oid = i.indrelid |
AND c.oid = i.indrelid |
168 |
AND indisprimary |
AND %s |
169 |
AND indnatts = 1 |
AND indnatts = 1 |
170 |
) |
) |
171 |
}); |
}; |
172 |
|
|
173 |
|
$c->{pk} = $dbh->selectrow_array( sprintf($index_fmt, $table, 'indisprimary') ); |
174 |
|
|
175 |
|
$c->{pk} ||= $dbh->selectrow_array( sprintf($index_fmt, $table, 'indisunique') ); |
176 |
|
|
177 |
} |
} |
178 |
|
|