]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Display partition info (bug #1031)
authorJakub Vrana <jakub@vrana.cz>
Tue, 15 Apr 2025 06:57:06 +0000 (08:57 +0200)
committerJakub Vrana <jakub@vrana.cz>
Tue, 15 Apr 2025 06:58:24 +0000 (08:58 +0200)
adminer/drivers/pgsql.inc.php
adminer/lang/cs.inc.php
adminer/lang/pl.inc.php
adminer/lang/xx.inc.php
adminer/table.inc.php

index eddd4b871c6657f607b0fb6b3f61f48fba462faa..dcdce6dfa0b6228bd168b257058af269fe848bdd 100644 (file)
@@ -338,6 +338,19 @@ if (isset($_GET["pgsql"])) {
                        return get_vals("SELECT relname FROM pg_inherits JOIN pg_class ON inhrelid = oid WHERE inhparent = " . $this->tableOid($table) . " ORDER BY 1");
                }
 
+               function partitionsInfo(string $table): array {
+                       $row = connection()->query("SELECT * FROM pg_partitioned_table WHERE partrelid = " . driver()->tableOid($table))->fetch_assoc();
+                       if ($row) {
+                               $attrs = get_vals("SELECT attname FROM pg_attribute WHERE attrelid = $row[partrelid] AND attnum IN (" . str_replace(" ", ", ", $row["partattrs"]) . ")"); //! ordering
+                               $by = array('h' => 'HASH', 'l' => 'LIST', 'r' => 'RANGE');
+                               return array(
+                                       "partition_by" => $by[$row["partstrat"]],
+                                       "partition" => implode(", ", array_map('Adminer\idf_escape', $attrs)),
+                               );
+                       }
+                       return array();
+               }
+
                function tableOid(string $table): string {
                        return "(SELECT oid FROM pg_class WHERE relnamespace = $this->nsOid AND relname = " . q($table) . " AND relkind IN ('r', 'm', 'v', 'f', 'p'))";
                }
@@ -943,12 +956,9 @@ AND typelem = 0"
                }
                $return .= implode(",\n    ", $return_parts) . "\n)";
 
-               $table_oid = driver()->tableOid($status['Name']);
-               $row = connection()->query("SELECT * FROM pg_partitioned_table WHERE partrelid = $table_oid")->fetch_assoc();
-               if ($row) {
-                       $attrs = get_vals("SELECT attname FROM pg_attribute WHERE attrelid = $row[partrelid] AND attnum IN (" . str_replace(" ", ", ", $row["partattrs"]) . ")"); //! ordering
-                       $by = array('h' => 'HASH', 'l' => 'LIST', 'r' => 'RANGE');
-                       $return .= "\nPARTITION BY $by[partstrat](" . implode(", ", array_map('Adminer\idf_escape', $attrs)) . ")";
+               $partition = driver()->partitionsInfo($status['Name']);
+               if ($partition) {
+                       $return .= "\nPARTITION BY $partition[partition_by]($partition[partition])";
                }
                //! parse pg_class.relpartbound to create PARTITION OF
 
index a950a36ea88ed8c1aeff4ef0755b5a5c115d0a14..1a96c67d6ec2756d0a4e03b4aff24c846b4aff85 100644 (file)
@@ -195,7 +195,6 @@ Lang::$translations = array(
        'Partition name' => 'Název oddílu',
        'Values' => 'Hodnoty',
        'Inherits from' => 'Zděděná z',
-       'Inherited tables' => 'Zděděné tabulky',
 
        'View' => 'Pohled',
        'Materialized view' => 'Materializovaný pohled',
index 78da24c9de5188dc1b64d19f9f4c47c3d378700d..d00f1c028b24fec7871d97b609eb1e618df9ef23 100644 (file)
@@ -196,7 +196,6 @@ Lang::$translations = array(
        'Partition name' => 'Nazwa partycji',
        'Values' => 'Wartości',
        'Inherits from' => 'Dziedziczy po',
-       'Inherited tables' => 'Tabele dziedziczone',
 
        'View' => 'Perspektywa',
        'Materialized view' => 'Zmaterializowana perspektywa',
index 34dfdbb7252a69efff6ecc0ec8514d0b998918f6..283be7e5bbfe22167350492201adb6cb9e6d4634 100644 (file)
@@ -197,7 +197,6 @@ Lang::$translations = array(
        'Partition name' => 'Xx',
        'Values' => 'Xx',
        'Inherits from' => 'Xx',
-       'Inherited tables' => 'Xx',
 
        'View' => 'Xx',
        'Materialized view' => 'Xx',
index 85067d45b89865bbd050aef0799bee53a921abed..a9846d37d8292a8f4307a9be6be0eae07eaada3d 100644 (file)
@@ -110,6 +110,10 @@ if (support(is_view($table_status) ? "view_trigger" : "trigger")) {
 
 $inherited = driver()->inheritedTables($TABLE);
 if ($inherited) {
-       echo "<h3 id='inherited'>" . lang('Inherited tables') . "</h3>\n";
+       echo "<h3 id='partitions'>" . lang('Partitions') . "</h3>\n";
+       $partition = driver()->partitionsInfo($TABLE);
+       if ($partition) {
+               echo "<p><code class='jush-" . JUSH . "'>BY " . h("$partition[partition_by]($partition[partition])") . "</code>\n";
+       }
        tables_links($inherited);
 }