You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: website/docs/sql/datatype/array.md
+22-15
Original file line number
Diff line number
Diff line change
@@ -26,10 +26,10 @@ Arrays can be created in two ways:
26
26
- Using the type constructor syntax
27
27
```sql
28
28
>select array[1,2,3];
29
-
{1,2,3}
29
+
[1,2,3]
30
30
31
31
>select array['one','two','three'];
32
-
{one,two,three}
32
+
["one","two","three"]
33
33
```
34
34
35
35
The constructor syntax consists of the keyword `array` followed by a comma-separated list of element SQL values surrounded by square brackets `[...]`.
@@ -39,22 +39,24 @@ Arrays can be created in two ways:
39
39
40
40
- Using a [cast](../scalar_func/conversion.md) from string data
41
41
```sql
42
-
>select'{1,2,3}'::array(integer);
43
-
{1,2,3}
42
+
>select'[1,2,3]'::array(integer);
43
+
[1,2,3]
44
44
45
-
>select'{one,two,three}'::array(text);
46
-
{one,two,three}
45
+
>select'[one,two,three]'::array(text);
46
+
["one","two","three"]
47
47
```
48
48
49
-
An array string literal consists of a comma-separated list of element literals surrounded by curly braces `{...}`.
49
+
An array string literal consists of a comma-separated list of element literals surrounded by square brackets `[...]`.
50
50
The element literal syntax is identical to that of the respective atomic type.
51
51
52
52
Note that for string array types (such as, e.g., `array(text)`), any upper- or lower-case variant of the element literal `null` will be parsed as a `null` value.
53
53
To specify the string `null`, the element literal must be escaped using double quotes, like so:
54
54
```sql
55
-
>select'{null, "null"}'::array(text)
56
-
{NULL,null}# A null element, followed by the string 'null'
55
+
>select'[null, "null"]'::array(text)
56
+
[NULL,"null"]# A null element, followed by the string 'null'
57
57
```
58
+
59
+
When outputting an array of text types, every non-null element is quoted.
58
60
59
61
## Element Types and Nullability
60
62
@@ -70,18 +72,18 @@ The following four options all represent different types in Hyper:
70
72
71
73
|Type|array nullable?|elements nullable?| possible values|
A cast from a non-nullable element type to its nullable counterpart always succeeds.
@@ -92,6 +94,11 @@ Casts across element types (e.g. from `array(integer not null)` to `array(bigint
92
94
Non-nullable element types use less memory and enable optimizations for certain array operations. Users are therefore advised to use the most "restrictive" element type possible, given the use case at hand.
93
95
:::
94
96
97
+
:::note
98
+
Hyper used curly braces `{...}` to represent arrays as string literals up to (and including) version 0.0.21200. In those versions, it also tried to avoid quoting every element of a text array when it did not contain special characters.
99
+
The new syntax uses square brackets `[...]` and always quotes text elements, which more closely resembles the JSON array syntax.
Copy file name to clipboardexpand all lines: website/docs/sql/scalar_func/arrays.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Signature|Description|Example
12
12
---|---|---
13
13
<code>array(T)**[**int**]**</code> → `T`| Returns the n-th element of the array (1-indexed). | `(array[1,2,3])[1]` → `1`
14
14
<code>array(T)**[**int**:**int**]**</code> → `T` | Returns the subarray within the given boundes (1-indexed, inclusive). |`(array[1,2,3])[2:3]` → `{2,3}` |
15
-
<code>**array_length(**array**)**</code> → `int` | Returns the length of the array. | `array_length(array[1,2,3])` → `3`
15
+
<code>**array_length(**array**)**</code> → `int` | Returns the length of the array. | `array_length(array[1,2,3])` → `3` <br/>`array_length(array[])` → `0`
16
16
<code>**array_to_string(**array, text [, text]**)**</code>| Converts the array into a textual representation, with the given element separator and (optional) null indicator. | `array_to_string(array[1,2,3], ';')` → `1;2;3`<br/>`array_to_string(array[3,2,1,null], '⏰', '🎉')` → `3⏰2⏰1⏰🎉`
17
17
<code>**array_contains(**array, value**)**</code>| Checks if a given value is contained within the array. | `array_contains(array[1,3,4], 3)` → `true`<br/>`array_contains(array[1,3,4], 2)` → `false`
18
18
<code>**array_position(**array, value**)**</code>| Returns the index of the first occurrence of `value` inside `array`. Comparisons are done using `IS NOT DISTINCT FROM` semantics, so it is possible to search for `NULL`. Returns `NULL` if the element is not found. | `array_position(array[1,3,4,3], 3)` → `2`<br/>`array_contains(array[1,3,4,3], 2)` → `NULL`
0 commit comments