]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Move partitioned tables from table list to parent table (bug #1031)
authorJakub Vrana <jakub@vrana.cz>
Sun, 13 Apr 2025 12:05:40 +0000 (14:05 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 13 Apr 2025 14:36:10 +0000 (16:36 +0200)
CHANGELOG.md
adminer/drivers/pgsql.inc.php
adminer/include/driver.inc.php
adminer/lang/cs.inc.php
adminer/lang/xx.inc.php
adminer/table.inc.php

index 0d36f5f90828189892934178f4affeb55ad241a3..da1841d3c662e0e05b1a8442399a4f9cdb64e7f6 100644 (file)
@@ -1,5 +1,5 @@
 ## Adminer dev
-- PostgreSQL: Show partitioned tables as tables, not views
+- PostgreSQL: Move partitioned tables from table list to parent table
 - Designs: adminer.css with 'prefers-color-scheme: dark' don't disable dark mode
 - Plugins: Method bodyClass() to add &lt;body class>
 
index 0fd1073bba6ff29e4d18d679c0e54b576cbdfd2b..066278f22839f541d3f160ad9cb48020cc6ba51c 100644 (file)
@@ -324,6 +324,16 @@ if (isset($_GET["pgsql"])) {
                        }
                }
 
+               function inheritedTables(string $table): array {
+                       return get_vals("SELECT c.relname
+FROM pg_class p
+JOIN pg_namespace n ON n.nspname = current_schema() AND n.oid = p.relnamespace
+JOIN pg_inherits ON inhparent = p.oid
+JOIN pg_class c ON inhrelid = c.oid
+WHERE p.relname = " . q($table) . " AND p.relkind = 'p'
+ORDER BY 1");
+               }
+
                function supportsIndex(array $table_status): bool {
                        // returns true for "materialized view"
                        return $table_status["Engine"] != "view";
@@ -415,9 +425,10 @@ ORDER BY 1";
        c.reltuples as \"Rows\",
        n.nspname
 FROM pg_class c
-JOIN pg_namespace n ON(n.nspname = current_schema() AND n.oid = c.relnamespace)
+JOIN pg_namespace n ON n.nspname = current_schema() AND n.oid = c.relnamespace
+LEFT JOIN pg_inherits ON inhrelid = c.oid
 WHERE relkind IN ('r', 'm', 'v', 'f', 'p')
-" . ($name != "" ? "AND relname = " . q($name) : "ORDER BY relname")) as $row //! Index_length, Auto_increment
+" . ($name != "" ? "AND relname = " . q($name) : "AND inhparent IS NULL ORDER BY relname")) as $row //! Auto_increment
                ) {
                        $return[$row["Name"]] = $row;
                }
index 5eea1838f0673259c4cfd2770cbac79a355b6bad..0496ddbf8c445b49df2ad40fa9c7de78a36a8b11 100644 (file)
@@ -217,6 +217,13 @@ abstract class SqlDriver {
        function tableHelp(string $name, bool $is_view = false) {
        }
 
+       /** Get inherited tables
+       * @return list<string>
+       */
+       function inheritedTables(string $table): array {
+               return array();
+       }
+
        /** Check if C-style escapes are supported */
        function hasCStyleEscapes(): bool {
                return false;
index 21c4575dab6f458665dda2ef82ca07bd3e4a5a31..fb26d01a1e2318746c32de700881104ee5297aa1 100644 (file)
@@ -194,6 +194,7 @@ Lang::$translations = array(
        'Partitions' => 'Oddíly',
        'Partition name' => 'Název oddílu',
        'Values' => 'Hodnoty',
+       'Inherited tables' => 'Zděděné tabulky',
 
        'View' => 'Pohled',
        'Materialized view' => 'Materializovaný pohled',
index 7217c8a4d7112ae04d4bed1b76e2afefaaed7314..51a8ede6dcab84c803f101158845d863ad5f8e82 100644 (file)
@@ -196,6 +196,7 @@ Lang::$translations = array(
        'Partitions' => 'Xx',
        'Partition name' => 'Xx',
        'Values' => 'Xx',
+       'Inherited tables' => 'Xx',
 
        'View' => 'Xx',
        'Materialized view' => 'Xx',
index 4388c550b00761047cd93a72ae18f217931dda00..fc3a3b0e57d180a9d53ecc2550c5916f7ce5b410 100644 (file)
@@ -95,3 +95,13 @@ if (support(is_view($table_status) ? "view_trigger" : "trigger")) {
        }
        echo '<p class="links"><a href="' . h(ME) . 'trigger=' . urlencode($TABLE) . '">' . lang('Add trigger') . "</a>\n";
 }
+
+$inherited = driver()->inheritedTables($TABLE);
+if ($inherited) {
+       echo "<h3 id='inherited'>" . lang('Inherited tables') . "</h3>\n";
+       echo "<ul>\n";
+       foreach ($inherited as $val) {
+               echo "<li><a href='" . h(ME . "table=" . urlencode($val)) . "'>" . h($val) . "</a>\n";
+       }
+       echo "</ul>\n";
+}