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 @@
verifyTextPresent | No tables. | |
+
+Partitioning |
+
+open | /adminer/?pgsql=localhost:26257&username=ODBC&db=adminer_test&ns=public&create= | |
+type | name=name | range |
+click | //input[@name='auto_increment_col' and @value='1'] | |
+click | link=Partition by | |
+select | name=partition_by | label=RANGE |
+type | name=partition | id |
+type | name=partition_names[] | old |
+type | name=partition_values[] | 10 |
+type | xpath=//table[@id='partition-table']/tr/td/input | new |
+type | xpath=//table[@id='partition-table']/tr/td[2]/input | MAXVALUE |
+click | //input[@value='Save'] | |
+verifyTextPresent | PARTITION BY RANGE(id) | |
+verifyTextPresent | PARTITION "old" VALUES FROM (MINVALUE) TO (10) | |
+click | link=Create table | |
+type | name=name | list |
+click | //input[@name='auto_increment_col' and @value='1'] | |
+click | link=Partition by | |
+select | name=partition_by | label=LIST |
+type | name=partition | id |
+type | name=partition_names[] | odd |
+type | name=partition_values[] | 1,3,5 |
+click | xpath=//input[@value='Save'] | |
+verifyTextPresent | PARTITION BY LIST(id) | |
+verifyTextPresent | PARTITION "odd" VALUES IN (1,3,5) | |
+click | link=public | |
+click | //input[@name='tables[]' and @value='list'] | |
+click | //input[@name='tables[]' and @value='range'] | |
+chooseOkOnNextConfirmation | Are you sure? | |
+click | name=drop | |
+verifyTextPresent | No tables. | |
+
+