diff --git a/CHANGELOG.md b/CHANGELOG.md index 63fb9edc..e0c0cb5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Adminer dev - MySQL: Avoid warning on selecting tables with fulltext indexes (bug #1036) -- PostgreSQL: Creating partitioned tables (bug #1031) +- PostgreSQL, CockroachDB: Creating partitioned tables (bug #1031) - 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 <body class> diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 9512b8cf..eddd4b87 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -206,7 +206,6 @@ if (isset($_GET["pgsql"])) { public $operators = array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "ILIKE", "ILIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"); // no "SQL" to avoid CSRF public $functions = array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper"); public $grouping = array("avg", "count", "count distinct", "max", "min", "sum"); - public $partitionBy = array("RANGE", "LIST", "HASH"); public string $nsOid = "(SELECT oid FROM pg_namespace WHERE nspname = current_schema())"; @@ -255,6 +254,10 @@ if (isset($_GET["pgsql"])) { if (min_version(12, 0, $connection)) { $this->generated = array("STORED"); } + $this->partitionBy = array("RANGE", "LIST"); + if (!$connection->flavor) { + $this->partitionBy[] = "HASH"; + } } function enumLength(array $field) { @@ -638,6 +641,7 @@ ORDER BY conkey, conname") as $row if ($table == "") { $status = ""; if ($partitioning) { + $cockroach = (connection()->flavor == 'cockroach'); $status = " PARTITION BY $partitioning[partition_by]($partitioning[partition])"; if ($partitioning["partition_by"] == 'HASH') { $partitions = +$partitioning["partitions"]; @@ -648,11 +652,15 @@ ORDER BY conkey, conname") as $row $prev = "MINVALUE"; foreach ($partitioning["partition_names"] as $i => $val) { $value = $partitioning["partition_values"][$i]; - $queries[] = "CREATE TABLE " . idf_escape($name . "_$val") . " PARTITION OF " . idf_escape($name) . " FOR VALUES " - . ($partitioning["partition_by"] == 'LIST' ? "IN ($value)" : "FROM ($prev) TO ($value)") - ; + $partition = " VALUES " . ($partitioning["partition_by"] == 'LIST' ? "IN ($value)" : "FROM ($prev) TO ($value)"); + if ($cockroach) { + $status .= ($i ? "," : " (") . "\n PARTITION " . (preg_match('~^DEFAULT$~i', $val) ? $val : idf_escape($val)) . "$partition"; + } else { + $queries[] = "CREATE TABLE " . idf_escape($name . "_$val") . " PARTITION OF " . idf_escape($name) . " FOR$partition"; + } $prev = $value; } + $status .= ($cockroach ? "\n)" : ""); } } array_unshift($queries, "CREATE TABLE " . table($name) . " (\n" . implode(",\n", $alter) . "\n)$status"); diff --git a/tests/cockroachdb.html b/tests/cockroachdb.html index f42944a7..bfcfee44 100644 --- a/tests/cockroachdb.html +++ b/tests/cockroachdb.html @@ -375,6 +375,41 @@ verifyTextPresentNo tables. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Partitioning
open/adminer/?pgsql=localhost:26257&username=ODBC&db=adminer_test&ns=public&create=
typename=namerange
click//input[@name='auto_increment_col' and @value='1']
clicklink=Partition by
selectname=partition_bylabel=RANGE
typename=partitionid
typename=partition_names[]old
typename=partition_values[]10
typexpath=//table[@id='partition-table']/tr/td/inputnew
typexpath=//table[@id='partition-table']/tr/td[2]/inputMAXVALUE
click//input[@value='Save']
verifyTextPresentPARTITION BY RANGE(id)
verifyTextPresentPARTITION "old" VALUES FROM (MINVALUE) TO (10)
clicklink=Create table
typename=namelist
click//input[@name='auto_increment_col' and @value='1']
clicklink=Partition by
selectname=partition_bylabel=LIST
typename=partitionid
typename=partition_names[]odd
typename=partition_values[]1,3,5
clickxpath=//input[@value='Save']
verifyTextPresentPARTITION BY LIST(id)
verifyTextPresentPARTITION "odd" VALUES IN (1,3,5)
clicklink=public
click//input[@name='tables[]' and @value='list']
click//input[@name='tables[]' and @value='range']
chooseOkOnNextConfirmationAre you sure?
clickname=drop
verifyTextPresentNo tables.
+
Variables