Skip to content

Commit

Permalink
Merge pull request #3692 from szarnyasg/iss3691
Browse files Browse the repository at this point in the history
Iss3691
  • Loading branch information
szarnyasg authored Sep 19, 2024
2 parents 33ff1ff + 7baffc5 commit 0660b05
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/guides/snippets/create_synthetic_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Create Synthetic Data

DuckDB allows you to quickly generate synthetic data sets. To do so, you may use:

* [range functions]({% link docs/sql/functions/nested.md %}#range-functions)
* [range functions]({% link docs/sql/functions/list.md %}#range-functions)
* hash functions, e.g.,
[`hash`]({% link docs/sql/functions/utility.md %}#hashvalue),
[`md5`]({% link docs/sql/functions/utility.md %}#md5string),
Expand Down
6 changes: 3 additions & 3 deletions docs/sql/data_types/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To store variable-length lists, use the [`LIST` type]({% link docs/sql/data_type
## Creating Arrays

Arrays can be created using the [`array_value(expr, ...)`]({% link docs/sql/functions/nested.md %}#list-functions) function.
Arrays can be created using the [`array_value(expr, ...)` function]({% link docs/sql/functions/array.md %}#array_valueindex).

Construct with the `array_value` function:

Expand Down Expand Up @@ -84,7 +84,7 @@ SELECT id, arr[1:2] AS elements FROM array_table;

## Functions

All [`LIST` functions]({% link docs/sql/functions/nested.md %}#list-functions) work with the `ARRAY` type. Additionally, several `ARRAY`-native functions are also supported.
All [`LIST` functions]({% link docs/sql/functions/list.md %}) work with the `ARRAY` type. Additionally, several `ARRAY`-native functions are also supported.
See the [`ARRAY` functions]({% link docs/sql/functions/array.md %}#array-native-functions).

## Examples
Expand Down Expand Up @@ -120,4 +120,4 @@ The ordering of `ARRAY` instances is defined using a lexicographical order. `NUL

## See Also

For more functions, see [List Functions]({% link docs/sql/functions/nested.md %}#list-functions).
For more functions, see [List Functions]({% link docs/sql/functions/list.md %}).
8 changes: 4 additions & 4 deletions docs/sql/data_types/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ title: List Type

A `LIST` column encodes lists of values. Fields in the column can have values with different lengths, but they must all have the same underlying type. `LIST`s are typically used to store arrays of numbers, but can contain any uniform data type, including other `LIST`s and `STRUCT`s.

`LIST`s are similar to PostgreSQL's `ARRAY` type. DuckDB uses the `LIST` terminology, but some [array functions]({% link docs/sql/functions/nested.md %}#list-functions) are provided for PostgreSQL compatibility.
`LIST`s are similar to PostgreSQL's `ARRAY` type. DuckDB uses the `LIST` terminology, but some [`array_` functions]({% link docs/sql/functions/list.md %}) are provided for PostgreSQL compatibility.

See the [data types overview]({% link docs/sql/data_types/overview.md %}) for a comparison between nested data types.

> For storing fixed-length lists, DuckDB uses the [`ARRAY` type]({% link docs/sql/data_types/array.md %}).
## Creating Lists

Lists can be created using the [`list_value(expr, ...)`]({% link docs/sql/functions/nested.md %}#list-functions) function or the equivalent bracket notation `[expr, ...]`. The expressions can be constants or arbitrary expressions. To create a list from a table column, use the [`list`]({% link docs/sql/functions/aggregates.md %}#general-aggregate-functions) aggregate function.
Lists can be created using the [`list_value(expr, ...)`]({% link docs/sql/functions/list.md %}#list_valueany-) function or the equivalent bracket notation `[expr, ...]`. The expressions can be constants or arbitrary expressions. To create a list from a table column, use the [`list`]({% link docs/sql/functions/aggregates.md %}#general-aggregate-functions) aggregate function.

List of integers:

Expand Down Expand Up @@ -47,7 +47,7 @@ CREATE TABLE list_table (int_list INTEGER[], varchar_list VARCHAR[]);

## Retrieving from Lists

Retrieving one or more values from a list can be accomplished using brackets and slicing notation, or through [list functions]({% link docs/sql/functions/nested.md %}#list-functions) like `list_extract`. Multiple equivalent functions are provided as aliases for compatibility with systems that refer to lists as arrays. For example, the function `array_slice`.
Retrieving one or more values from a list can be accomplished using brackets and slicing notation, or through [list functions]({% link docs/sql/functions/list.md %}) like `list_extract`. Multiple equivalent functions are provided as aliases for compatibility with systems that refer to lists as arrays. For example, the function `array_slice`.

> We wrap the list creation in parenthesis so that it happens first.
> This is only needed in our basic examples here, not when working with a list column.
Expand Down Expand Up @@ -130,4 +130,4 @@ If this is an unexpected constraint violation please double check with the known

## Functions

See [Nested Functions]({% link docs/sql/functions/nested.md %}).
See [List Functions]({% link docs/sql/functions/list.md %}).
2 changes: 1 addition & 1 deletion docs/sql/data_types/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ and a `NULL` nested value member will compare above a non-`NULL` nested value me

## Functions

See [Nested Functions]({% link docs/sql/functions/nested.md %}).
See [Map Functions]({% link docs/sql/functions/map.md %}).
8 changes: 4 additions & 4 deletions docs/sql/data_types/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Conceptually, a `STRUCT` column contains an ordered list of columns called “en

`STRUCT`s are typically used to nest multiple columns into a single column, and the nested column can be of any type, including other `STRUCT`s and `LIST`s.

`STRUCT`s are similar to PostgreSQL's `ROW` type. The key difference is that DuckDB `STRUCT`s require the same keys in each row of a `STRUCT` column. This allows DuckDB to provide significantly improved performance by fully utilizing its vectorized execution engine, and also enforces type consistency for improved correctness. DuckDB includes a `row` function as a special way to produce a `STRUCT`, but does not have a `ROW` data type. See an example below and the [nested functions docs]({% link docs/sql/functions/nested.md %}#struct-functions) for details.
`STRUCT`s are similar to PostgreSQL's `ROW` type. The key difference is that DuckDB `STRUCT`s require the same keys in each row of a `STRUCT` column. This allows DuckDB to provide significantly improved performance by fully utilizing its vectorized execution engine, and also enforces type consistency for improved correctness. DuckDB includes a `row` function as a special way to produce a `STRUCT`, but does not have a `ROW` data type. See an example below and the [`STRUCT` functions documentation]({% link docs/sql/functions/struct.md %}) for details.

`STRUCT`s have a fixed schema. It is not possible to change the schema of a `STRUCT` using `UPDATE` operations.

See the [data types overview]({% link docs/sql/data_types/overview.md %}) for a comparison between nested data types.

### Creating Structs

Structs can be created using the [`struct_pack(name := expr, ...)`]({% link docs/sql/functions/nested.md %}#struct-functions) function, the equivalent array notation `{'name': expr, ...}`, using a row variable, or using the `row` function.
Structs can be created using the [`struct_pack(name := expr, ...)`]({% link docs/sql/functions/struct.md %}) function, the equivalent array notation `{'name': expr, ...}`, using a row variable, or using the `row` function.

Create a struct using the `struct_pack` function. Note the lack of single quotes around the keys and the use of the `:=` operator:

Expand Down Expand Up @@ -73,7 +73,7 @@ SELECT struct_insert({'a': 1, 'b': 2, 'c': 3}, d := 4) AS s;

### Retrieving from Structs

Retrieving a value from a struct can be accomplished using dot notation, bracket notation, or through [struct functions]({% link docs/sql/functions/nested.md %}#struct-functions) like `struct_extract`.
Retrieving a value from a struct can be accomplished using dot notation, bracket notation, or through [struct functions]({% link docs/sql/functions/struct.md %}) like `struct_extract`.

Use dot notation to retrieve the value at a key's location. In the following query, the subquery generates a struct column `a`, which we then query with `a.x`.

Expand Down Expand Up @@ -290,4 +290,4 @@ and type STRUCT(k2 INTEGER, k1 INTEGER) - an explicit cast is required
## Functions

See [Nested Functions]({% link docs/sql/functions/nested.md %}).
See [Struct Functions]({% link docs/sql/functions/struct.md %}).
4 changes: 2 additions & 2 deletions docs/sql/data_types/union.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A `UNION` *type* (not to be confused with the SQL [`UNION` operator]({% link doc

Under the hood, `UNION` types are implemented on top of `STRUCT` types, and simply keep the “tag” as the first entry.

`UNION` values can be created with the [`union_value(tag := expr)`]({% link docs/sql/functions/nested.md %}#union-functions) function or by [casting from a member type](#casting-to-unions).
`UNION` values can be created with the [`union_value(tag := expr)`]({% link docs/sql/functions/union.md %}) function or by [casting from a member type](#casting-to-unions).

## Example

Expand Down Expand Up @@ -111,4 +111,4 @@ Since `UNION` types are implemented on top of `STRUCT` types internally, they ca

## Functions

See [Nested Functions]({% link docs/sql/functions/nested.md %}#union-functions).
See [Union Functions]({% link docs/sql/functions/union.md %}).
2 changes: 1 addition & 1 deletion docs/sql/expressions/star.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ FROM (SELECT NULL a, 42 b, true c);

The `*` expression can also be used to retrieve all keys from a struct as separate columns.
This is particularly useful when a prior operation creates a struct of unknown shape, or if a query must handle any potential struct keys.
See the [`STRUCT` data type]({% link docs/sql/data_types/struct.md %}) and [nested functions]({% link docs/sql/functions/nested.md %}) pages for more details on working with structs.
See the [`STRUCT` data type]({% link docs/sql/data_types/struct.md %}) and [`STRUCT` functions]({% link docs/sql/functions/struct.md %}) pages for more details on working with structs.

For example:

Expand Down
2 changes: 1 addition & 1 deletion docs/sql/functions/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Array Functions

<!-- markdownlint-disable MD001 -->

All [`LIST` functions]({% link docs/sql/functions/nested.md %}#list-functions) work with the [`ARRAY` data type]({% link docs/sql/data_types/array.md %}). Additionally, several `ARRAY`-native functions are also supported.
All [`LIST` functions]({% link docs/sql/functions/list.md %}) work with the [`ARRAY` data type]({% link docs/sql/data_types/array.md %}). Additionally, several `ARRAY`-native functions are also supported.

## Array-Native Functions

Expand Down
2 changes: 1 addition & 1 deletion docs/sql/query_syntax/unnest.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ SELECT unnest([[[1, 2], [3, 4]], [[5, 6], [7, 8, 9], []], [[10, 11]]], max_depth

### Keeping Track of List Entry Positions

To keep track of each entry's position within the original list, `unnest` may be combined with [`generate_subscripts`]({% link docs/sql/functions/nested.md %}#generate_subscripts):
To keep track of each entry's position within the original list, `unnest` may be combined with [`generate_subscripts`]({% link docs/sql/functions/list.md %}#generate_subscripts):

```sql
SELECT unnest(l) as x, generate_subscripts(l, 1) AS index
Expand Down

0 comments on commit 0660b05

Please sign in to comment.