diff --git a/adminer/db.inc.php b/adminer/db.inc.php
index 14fb27c6..dc3fc3ec 100644
--- a/adminer/db.inc.php
+++ b/adminer/db.inc.php
@@ -82,7 +82,7 @@ if ($adminer->homepage()) {
echo '
' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
echo ' | ' . (support("table") || support("indexes") ? '' . h($name) . '' : h($name));
if ($view) {
- echo ' | ' . lang('View') . '';
+ echo ' | ' . (preg_match('~materialized~i', $type) ? lang('Materialized View') : lang('View')) . '';
echo ' | ?';
} else {
foreach (array(
@@ -144,6 +144,7 @@ if ($adminer->homepage()) {
echo ' ' . lang('Create table') . "\n";
echo (support("view") ? '' . lang('Create view') . "\n" : "");
+ echo (support("materializedview") ? '' . lang('Create materialized view') . "\n" : "");
if (support("routine")) {
echo " " . lang('Routines') . "\n";
diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php
index abd0c578..6e77fe3c 100644
--- a/adminer/drivers/pgsql.inc.php
+++ b/adminer/drivers/pgsql.inc.php
@@ -225,7 +225,12 @@ if (isset($_GET["pgsql"])) {
}
function tables_list() {
- return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema() ORDER BY table_name");
+ return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema()
+UNION ALL
+SELECT matviewname, 'MATERIALIZED VIEW'
+FROM pg_matviews
+WHERE schemaname = current_schema()
+ORDER BY table_name");
}
function count_tables($databases) {
@@ -234,9 +239,9 @@ if (isset($_GET["pgsql"])) {
function table_status($name = "") {
$return = array();
- foreach (get_rows("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN 'table' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_total_relation_size(oid) - pg_relation_size(oid) AS \"Index_length\", obj_description(oid, 'pg_class') AS \"Comment\", relhasoids::int AS \"Oid\", reltuples as \"Rows\"
+ foreach (get_rows("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN 'table' WHEN 'mv' THEN 'materialized view' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_total_relation_size(oid) - pg_relation_size(oid) AS \"Index_length\", obj_description(oid, 'pg_class') AS \"Comment\", relhasoids::int AS \"Oid\", reltuples as \"Rows\"
FROM pg_class
-WHERE relkind IN ('r','v')
+WHERE relkind IN ('r','v','mv')
AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
" . ($name != "" ? "AND relname = " . q($name) : "ORDER BY relname")
) as $row) { //! Index_length, Auto_increment
@@ -246,7 +251,7 @@ AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema(
}
function is_view($table_status) {
- return $table_status["Engine"] == "view";
+ return in_array($table_status["Engine"], array("view", "materialized view"));
}
function fk_support($table_status) {
@@ -467,21 +472,23 @@ ORDER BY conkey, conname") as $row) {
}
function drop_views($views) {
- return queries("DROP VIEW " . implode(", ", array_map('table', $views)));
+ return drop_tables($views);
}
function drop_tables($tables) {
- return queries("DROP TABLE " . implode(", ", array_map('table', $tables)));
+ foreach ($tables as $table) {
+ $status = table_status($table);
+ if (!queries("DROP " . strtoupper($status["Engine"]) . " " . table($table))) {
+ return false;
+ }
+ }
+ return true;
}
function move_tables($tables, $views, $target) {
- foreach ($tables as $table) {
- if (!queries("ALTER TABLE " . table($table) . " SET SCHEMA " . idf_escape($target))) {
- return false;
- }
- }
- foreach ($views as $table) {
- if (!queries("ALTER VIEW " . table($table) . " SET SCHEMA " . idf_escape($target))) {
+ foreach (array_merge($tables, $views) as $table) {
+ $status = table_status($table);
+ if (!queries("ALTER " . strtoupper($status["Engine"]) . " " . table($table) . " SET SCHEMA " . idf_escape($target))) {
return false;
}
}
@@ -612,7 +619,7 @@ AND typelem = 0"
}
function support($feature) {
- return preg_match('~^(database|table|columns|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
+ return preg_match('~^(database|table|columns|sql|indexes|comment|view|materializedview|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
}
$jush = "pgsql";
diff --git a/adminer/lang/cs.inc.php b/adminer/lang/cs.inc.php
index 20d15622..f45c4815 100644
--- a/adminer/lang/cs.inc.php
+++ b/adminer/lang/cs.inc.php
@@ -180,11 +180,13 @@ $translations = array(
'Values' => 'Hodnoty',
'View' => 'Pohled',
+ 'Materialized View' => 'Materializovaný pohled',
'View has been dropped.' => 'Pohled byl odstraněn.',
'View has been altered.' => 'Pohled byl změněn.',
'View has been created.' => 'Pohled byl vytvořen.',
'Alter view' => 'Pozměnit pohled',
'Create view' => 'Vytvořit pohled',
+ 'Create materialized view' => 'Vytvořit materializovaný pohled',
'Indexes' => 'Indexy',
'Indexes have been altered.' => 'Indexy byly změněny.',
diff --git a/adminer/lang/xx.inc.php b/adminer/lang/xx.inc.php
index 8e4b4615..04b09049 100644
--- a/adminer/lang/xx.inc.php
+++ b/adminer/lang/xx.inc.php
@@ -180,11 +180,13 @@ $translations = array(
'Values' => 'xx',
'View' => 'xx',
+ 'Materialized View' => 'xx',
'View has been dropped.' => 'xx',
'View has been altered.' => 'xx',
'View has been created.' => 'xx',
'Alter view' => 'xx',
'Create view' => 'xx',
+ 'Create materialized view' => 'xx',
'Indexes' => 'xx',
'Indexes have been altered.' => 'xx',
diff --git a/adminer/view.inc.php b/adminer/view.inc.php
index 32578b58..f8804850 100644
--- a/adminer/view.inc.php
+++ b/adminer/view.inc.php
@@ -7,17 +7,27 @@ if ($_POST && !$error) {
$as = " AS\n$row[select]";
$location = ME . "table=" . urlencode($name);
$message = lang('View has been altered.');
-
- if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite") {
+
+ if ($_GET["materialized"]) {
+ $type = "MATERIALIZED VIEW";
+ } else {
+ $type = "VIEW";
+ if ($jush == "pgsql") {
+ $status = table_status($name);
+ $type = ($status ? strtoupper($status["Engine"]) : $type);
+ }
+ }
+
+ if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite" && $type != "MATERIALIZED VIEW") {
query_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . table($name) . $as, $location, $message);
} else {
$temp_name = $name . "_adminer_" . uniqid();
drop_create(
- "DROP VIEW " . table($TABLE),
- "CREATE VIEW " . table($name) . $as,
- "DROP VIEW " . table($name),
- "CREATE VIEW " . table($temp_name) . $as,
- "DROP VIEW " . table($temp_name),
+ "DROP $type " . table($TABLE),
+ "CREATE $type " . table($name) . $as,
+ "DROP $type " . table($name),
+ "CREATE $type " . table($temp_name) . $as,
+ "DROP $type " . table($temp_name),
($_POST["drop"] ? substr(ME, 0, -1) : $location),
lang('View has been dropped.'),
$message,
|
---|