1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-12 01:24:17 +02:00

PostgreSQL: Fix export of indexes with expressions (bug #768)

This commit is contained in:
Jakub Vrana
2025-02-26 19:27:19 +01:00
parent ba70be12a4
commit 9aaa429528
2 changed files with 5 additions and 21 deletions

View File

@@ -780,8 +780,6 @@ AND typelem = 0"
return rtrim("CREATE VIEW " . idf_escape($table) . " AS $view[select]", ";"); return rtrim("CREATE VIEW " . idf_escape($table) . " AS $view[select]", ";");
} }
$fields = fields($table); $fields = fields($table);
$indexes = indexes($table);
ksort($indexes);
if (!$status || empty($fields)) { if (!$status || empty($fields)) {
return false; return false;
@@ -816,31 +814,12 @@ AND typelem = 0"
$return = implode("\n\n", $sequences) . "\n\n$return"; $return = implode("\n\n", $sequences) . "\n\n$return";
} }
// primary + unique keys
foreach ($indexes as $index_name => $index) {
switch($index['type']) {
case 'UNIQUE': $return_parts[] = "CONSTRAINT " . idf_escape($index_name) . " UNIQUE (" . implode(', ', array_map('idf_escape', $index['columns'])) . ")"; break;
case 'PRIMARY': $return_parts[] = "CONSTRAINT " . idf_escape($index_name) . " PRIMARY KEY (" . implode(', ', array_map('idf_escape', $index['columns'])) . ")"; break;
}
}
foreach ($driver->checkConstraints($table) as $conname => $consrc) { foreach ($driver->checkConstraints($table) as $conname => $consrc) {
$return_parts[] = "CONSTRAINT " . idf_escape($conname) . " $consrc"; $return_parts[] = "CONSTRAINT " . idf_escape($conname) . " $consrc";
} }
$return .= implode(",\n ", $return_parts) . "\n) WITH (oids = " . ($status['Oid'] ? 'true' : 'false') . ");"; $return .= implode(",\n ", $return_parts) . "\n) WITH (oids = " . ($status['Oid'] ? 'true' : 'false') . ");";
// "basic" indexes after table definition
foreach ($indexes as $index_name => $index) {
if ($index['type'] == 'INDEX') {
$columns = array();
foreach ($index['columns'] as $key => $val) {
$columns[] = idf_escape($val) . ($index['descs'][$key] ? " DESC" : "");
}
$return .= "\n\nCREATE INDEX " . idf_escape($index_name) . " ON " . idf_escape($status['nspname']) . "." . idf_escape($status['Name']) . " USING btree (" . implode(', ', $columns) . ");";
}
}
// comments for table & fields // comments for table & fields
if ($status['Comment']) { if ($status['Comment']) {
$return .= "\n\nCOMMENT ON TABLE " . idf_escape($status['nspname']) . "." . idf_escape($status['Name']) . " IS " . q($status['Comment']) . ";"; $return .= "\n\nCOMMENT ON TABLE " . idf_escape($status['nspname']) . "." . idf_escape($status['Name']) . " IS " . q($status['Comment']) . ";";
@@ -852,6 +831,10 @@ AND typelem = 0"
} }
} }
foreach (get_rows("SELECT indexdef FROM pg_catalog.pg_indexes WHERE schemaname = current_schema() AND tablename = " . q($table)) as $row) {
$return .= "\n\n$row[indexdef];";
}
return rtrim($return, ';'); return rtrim($return, ';');
} }

View File

@@ -1,4 +1,5 @@
Adminer dev: Adminer dev:
PostgreSQL: Fix export of indexes with expressions (bug #768)
SQLite: Support CHECK constraint SQLite: Support CHECK constraint
SQLite: Add command Check tables SQLite: Add command Check tables
SQLite: Display all rows of variable values SQLite: Display all rows of variable values