Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordering by arrays #7934

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 63 additions & 41 deletions v20.2/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The `ARRAY` data type is useful for ensuring compatibility with ORMs and other t
CockroachDB supports indexing array columns with [inverted indexes](inverted-indexes.html). This permits accelerating containment queries ([`@>`](functions-and-operators.html#operator-contains) and [`<@`](functions-and-operators.html#operator-is-contained-by)) on array columns by adding an index to them.

{{site.data.alerts.callout_info}}
CockroachDB does not support nested arrays or ordering by arrays.
CockroachDB does not support nested arrays.
{{site.data.alerts.end}}

{% include {{page.version.version}}/sql/vectorized-support.md %}
Expand Down Expand Up @@ -51,11 +51,9 @@ For a complete list of array functions built into CockroachDB, see the [document
~~~

~~~
+----------------------+
| b |
+----------------------+
| {"sky","road","car"} |
+----------------------+
b
------------------
{sky,road,car}
(1 row)
~~~

Expand All @@ -77,11 +75,9 @@ For a complete list of array functions built into CockroachDB, see the [document
~~~

~~~
+------------+
| d |
+------------+
| {10,20,30} |
+------------+
d
--------------
{10,20,30}
(1 row)
~~~

Expand All @@ -97,11 +93,9 @@ Arrays in CockroachDB are 1-indexed.
~~~

~~~
+------------+
| d |
+------------+
| {10,20,30} |
+------------+
d
--------------
{10,20,30}
(1 row)
~~~

Expand All @@ -111,11 +105,9 @@ Arrays in CockroachDB are 1-indexed.
~~~

~~~
+------+
| d[2] |
+------+
| 20 |
+------+
d
------
20
(1 row)
~~~

Expand All @@ -129,11 +121,9 @@ Arrays in CockroachDB are 1-indexed.
~~~

~~~
+------------+
| d |
+------------+
| {10,20,30} |
+------------+
d
--------------
{10,20,30}
(1 row)
~~~

Expand All @@ -148,11 +138,9 @@ Arrays in CockroachDB are 1-indexed.
~~~

~~~
+---------------+
| d |
+---------------+
| {10,20,30,40} |
+---------------+
d
-----------------
{10,20,30,40}
(1 row)
~~~

Expand All @@ -164,11 +152,9 @@ Arrays in CockroachDB are 1-indexed.
~~~

~~~
+---------------+
| d |
+---------------+
| {10,20,30,40} |
+---------------+
d
-----------------
{10,20,30,40}
(1 row)
~~~

Expand All @@ -183,14 +169,50 @@ Arrays in CockroachDB are 1-indexed.
~~~

~~~
+------------------+
| d |
+------------------+
| {10,20,30,40,50} |
+------------------+
d
--------------------
{10,20,30,40,50}
(1 row)
~~~

### Ordering by an array

{% include copy-clipboard.html %}
~~~ sql
> CREATE TABLE t (a INT ARRAY, b STRING);
~~~

{% include copy-clipboard.html %}
~~~ sql
> INSERT INTO t VALUES (ARRAY[3,4],'threefour'),(ARRAY[1,2],'onetwo');
~~~

{% include copy-clipboard.html %}
~~~ sql
> SELECT * FROM t;
~~~

~~~
a | b
--------+------------
{3,4} | threefour
{1,2} | onetwo
(2 rows)
~~~

{% include copy-clipboard.html %}
~~~ sql
> SELECT * FROM t ORDER BY a;
~~~

~~~
a | b
--------+------------
{1,2} | onetwo
{3,4} | threefour
(2 rows)
~~~

## Supported casting and conversion

[Casting](data-types.html#data-type-conversions-and-casts) between `ARRAY` values is supported when the data types of the arrays support casting. For example, it is possible to cast from a `BOOL` array to an `INT` array but not from a `BOOL` array to a `TIMESTAMP` array:
Expand Down