Skip to content

Commit dd17ff7

Browse files
committed
Revert "Update ARRAY literal syntax (#144)"
This reverts commit 6f365e7.
1 parent 6f365e7 commit dd17ff7

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

website/docs/releases.md

-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ In case you are wondering why all our releases start with `0.0`, read [this FAQ
2424

2525
:::
2626

27-
### Upcoming
28-
29-
* Update syntax for [`ARRAY` literals](./sql/datatype/array.md) and fixed bugs with quoting and escaping of text arrays.
30-
3127
### 0.0.21200 [Jan 17 2025]
3228

3329
* Support for Microsoft Azure Blob Storage using [`azure_location`](./sql/external/location.md#microsoft-azure-blob-storage) was added.

website/docs/sql/datatype/array.md

+15-22
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ Arrays can be created in two ways:
2626
- Using the type constructor syntax
2727
```sql
2828
> select array[1,2,3];
29-
[1,2,3]
29+
{1,2,3}
3030

3131
> select array['one','two','three'];
32-
["one","two","three"]
32+
{one,two,three}
3333
```
3434

3535
The constructor syntax consists of the keyword `array` followed by a comma-separated list of element SQL values surrounded by square brackets `[...]`.
@@ -39,24 +39,22 @@ Arrays can be created in two ways:
3939

4040
- Using a [cast](../scalar_func/conversion.md) from string data
4141
```sql
42-
> select '[1,2,3]'::array(integer);
43-
[1,2,3]
42+
> select '{1,2,3}'::array(integer);
43+
{1,2,3}
4444

45-
> select '[one,two,three]'::array(text);
46-
["one","two","three"]
45+
> select '{one,two,three}'::array(text);
46+
{one,two,three}
4747
```
4848

49-
An array string literal consists of a comma-separated list of element literals surrounded by square brackets `[...]`.
49+
An array string literal consists of a comma-separated list of element literals surrounded by curly braces `{...}`.
5050
The element literal syntax is identical to that of the respective atomic type.
5151

5252
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.
5353
To specify the string `null`, the element literal must be escaped using double quotes, like so:
5454
```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'
5757
```
58-
59-
When outputting an array of text types, every non-null element is quoted.
6058

6159
## Element Types and Nullability
6260

@@ -72,18 +70,18 @@ The following four options all represent different types in Hyper:
7270

7371
|Type|array nullable?|elements nullable?| possible values|
7472
|---|---|---|---|
75-
|`array(integer)`|||`[]`,`[1,2,3]`,`[1,2,null]`, `null`|
76-
|`array(integer not null)`|||`[]`,`[1,2,3]`,`null`|
77-
|`array(integer) not null`|||`[]`,`[1,2,3]`,`[1,2,null]`|
78-
|`array(integer not null) not null`|||`[]`,`[1,2,3]`|
73+
|`array(integer)`|||`{}`,`{1,2,3}`,`{1,2,null}`, `null`|
74+
|`array(integer not null)`|||`{}`,`{1,2,3}`,`null`|
75+
|`array(integer) not null`|||`{}`,`{1,2,3}`,`{1,2,null}`|
76+
|`array(integer not null) not null`|||`{}`,`{1,2,3}`|
7977

8078
The inner nullability of an array type can be changed by casting, using the conventional [cast syntax](../scalar_func/conversion.md):
8179

8280
```sql
8381
# nullable to non-nullable
84-
> select ('[1,2,3]'::array(integer))::array(integer not null)
82+
> select ('{1,2,3}'::array(integer))::array(integer not null)
8583
# non-nullable to nullable
86-
> select ('[1,2,3]'::array(integer not null))::array(integer)
84+
> select ('{1,2,3}'::array(integer not null))::array(integer)
8785
```
8886

8987
A cast from a non-nullable element type to its nullable counterpart always succeeds.
@@ -94,11 +92,6 @@ Casts across element types (e.g. from `array(integer not null)` to `array(bigint
9492
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.
9593
:::
9694

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.
100-
:::
101-
10295
## Limitations
10396

10497
Arrays are subject to the following limitations:

website/docs/sql/scalar_func/arrays.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Signature|Description|Example
1212
---|---|---
1313
<code>array(T)**[**int**]**</code> → `T`| Returns the n-th element of the array (1-indexed). | `(array[1,2,3])[1]``1`
1414
<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` <br/>`array_length(array[])``0`
15+
<code>**array_length(**array**)**</code> → `int` | Returns the length of the array. | `array_length(array[1,2,3])``3`
1616
<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⏰🎉`
1717
<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`
1818
<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

Comments
 (0)