]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Fix export of indexes with expressions (bug #768)
authorJakub Vrana <jakub@vrana.cz>
Wed, 26 Feb 2025 18:27:19 +0000 (19:27 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 26 Feb 2025 18:27:19 +0000 (19:27 +0100)
adminer/drivers/pgsql.inc.php
changes.txt

index 69be6117e78f13b243cb24fd91243be39bb97db3..0527aa00ef529e4d20ffc2f632f3b23b8c05f584 100644 (file)
@@ -780,8 +780,6 @@ AND typelem = 0"
                        return rtrim("CREATE VIEW " . idf_escape($table) . " AS $view[select]", ";");
                }
                $fields = fields($table);
-               $indexes = indexes($table);
-               ksort($indexes);
 
                if (!$status || empty($fields)) {
                        return false;
@@ -816,31 +814,12 @@ AND typelem = 0"
                        $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) {
                        $return_parts[] = "CONSTRAINT " . idf_escape($conname) . " $consrc";
                }
 
                $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
                if ($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, ';');
        }
 
index c4338c873e3de7c14c2c66390a35b3568855efe0..b5bb54d69ff672f1e03c8fe401d267e77e420a9e 100644 (file)
@@ -1,4 +1,5 @@
 Adminer dev:
+PostgreSQL: Fix export of indexes with expressions (bug #768)
 SQLite: Support CHECK constraint
 SQLite: Add command Check tables
 SQLite: Display all rows of variable values