Skip to content
2 changes: 1 addition & 1 deletion docs/doc/14-sql-commands/10-dml/dml-delete-from.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ SELECT * FROM bookstore;

### Example 2: Subquery-Based Deletions

When using a subquery to identify the rows to be deleted, [Subquery Operators](../30-query-operators/subquery.md) and [Comparison Operators](../30-query-operators/comparisons/index.md) can be utilized to achieve the desired deletion.
When using a subquery to identify the rows to be deleted, [Subquery Operators](../30-query-operators/subquery.md) and [Comparison Operators](../30-query-operators/comparison.md) can be utilized to achieve the desired deletion.

The examples in this section are based on the following two tables:

Expand Down

This file was deleted.

15 changes: 15 additions & 0 deletions docs/doc/14-sql-commands/30-query-operators/comparison.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Comparison Operators
---

| Operator | Description | Example | Result |
|----------------------------|---------------------------------------------|----------------------------|--------|
| **=** | a is equal to b | **2 = 2** | TRUE |
| **!=** | a is not equal to b | **2 != 3** | TRUE |
| **<\>** | a is not equal to b | **2 <\> 2** | FALSE |
| **>** | a is greater than b | **2 > 3** | FALSE |
| **>=** | a is greater than or equal to b | **4 >= NULL** | NULL |
| **<** | a is less than b | **2 < 3** | TRUE |
| **<=** | a is less than or equal to b | **2 <= 3** | TRUE |
| **IS NULL** | TRUE if expression is NULL, FALSE otherwise | **(4 >= NULL) IS NULL** | TRUE |
| **IS NOT NULL** | FALSE if expression is NULL, TRUE otherwise | **(4 >= NULL) IS NOT NULL**| FALSE |

This file was deleted.

23 changes: 0 additions & 23 deletions docs/doc/14-sql-commands/30-query-operators/comparisons/index.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
---
title: 'JSON Operators'
title: JSON Operators
---
import FunctionDescription from '@site/src/components/FunctionDescription';

<FunctionDescription description="Introduced or updated: v1.2.190"/>
<FunctionDescription description="Introduced or updated: v1.2.209"/>

| Operator | Description | Example | Result |
|----------|-------------|---------|--------|
| -> | Retrieves a JSON array or object using an index or key, returning a JSON object. | - **Using a key**:<br/>`PARSE_JSON('{"Databend": "Cloud Native Warehouse"}')->'Databend'`<br/>- **Using an index**:<br/>`PARSE_JSON('["Databend", "Cloud Native Warehouse"]')->1` | Cloud Native Warehouse |
| ->> | Retrieves a JSON array or object using an index or key, returning a string. | - **Using a key**:<br/>`PARSE_JSON('{"Databend": "Cloud Native Warehouse"}')->>'Databend'`<br/>- **Using an index**:<br/>`PARSE_JSON('["Databend", "Cloud Native Warehouse"]')->>1` | Cloud Native Warehouse |
| #> | Retrieves a JSON array or object by specifying a key path, returning a JSON object. | `PARSE_JSON('{"example": {"Databend": "Cloud Native Warehouse"}}')#>'{example, Databend}'` | Cloud Native Warehouse |
| #>> | Retrieves a JSON array or object by specifying a key path, returning a string. | `PARSE_JSON('{"example": {"Databend": "Cloud Native Warehouse"}}')#>>'{example, Databend}'` | Cloud Native Warehouse |
| ? | Checks if the given string exists in a JSON object as a key or array and returns a boolean result (1 for true, 0 for false). | `PARSE_JSON('{"a":1,"b":2,"c":3}') ? 'b'`| 1 |
| ?\| | Checks if any string in the given array exists as a key or array element and returns a boolean result (1 for true, 0 for false). | PARSE_JSON('{"a":1,"b":2,"c":3}') ?\| ['b','e'] | 1 |
| ?& | Checks if each string in the given array exists as a key or array element and returns a boolean result (1 for true, 0 for false). | `PARSE_JSON('{"a":1,"b":2,"c":3}') ?& ['b','e']` | 0 |
| ? | Checks if the given string exists in a JSON object as a key or array, returning 1 for true and 0 for false. | `PARSE_JSON('{"a":1,"b":2,"c":3}') ? 'b'`| 1 |
| ?\| | Checks if any string in the given array exists as a key or array element, returning 1 for true and 0 for false. | PARSE_JSON('{"a":1,"b":2,"c":3}') ?\| ['b','e'] | 1 |
| ?& | Checks if each string in the given array exists as a key or array element, returning 1 for true and 0 for false. | `PARSE_JSON('{"a":1,"b":2,"c":3}') ?& ['b','e']` | 0 |
| @> | Checks if the left JSON expression contains all key-value pairs of the right JSON expression, returning 1 for true and 0 for false. | `PARSE_JSON('{"name":"Alice","age":30}') @> PARSE_JSON('{"name":"Alice"}')` | 1 |
| <@ | Checks if the left JSON expression is a subset of the right JSON expression, returning 1 for true and 0 for false. | `PARSE_JSON('{"name":"Alice"}') <@ PARSE_JSON('{"name":"Bob"}')` | 0 |

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
title: 'Logical/Boolean Operators'
title: Logical Operators
---


| Operator | Description | Example | Result |
|----------|----------------------------------------|---------------|--------|
| **AND** | Matches both expressions (`a` and `b`) | **1 AND 1** | TRUE |
Expand Down
6 changes: 2 additions & 4 deletions docs/doc/14-sql-commands/30-query-operators/subquery.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
title: Subquery Operators
description:
A subquery is a query nested within another query.
---

A subquery is a query nested within another one. Databend supports the following subquery types:
Expand Down Expand Up @@ -156,7 +154,7 @@ WHERE t1.a NOT IN (SELECT *

You can use ANY (or SOME) to check whether a comparison is true for any of the values returned by a subquery.

- The keyword ANY (or SOME) must follow one of the [Comparison Operators](comparisons/index.md).
- The keyword ANY (or SOME) must follow one of the [Comparison Operators](comparison.md).
- If the subquery doesn't return any values, the comparison evaluates to false.
- SOME work the same way as ANY.

Expand Down Expand Up @@ -203,7 +201,7 @@ WHERE t1.a < ANY (SELECT *

You can use ALL to check whether a comparison is true for all of the values returned by a subquery.

- The keyword ALL must follow one of the [Comparison Operators](comparisons/index.md).
- The keyword ALL must follow one of the [Comparison Operators](comparison.md).
- If the subquery doesn't return any values, the comparison evaluates to true.

### Syntax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This section provides reference information for the semi-structured data functio
- [FLATTEN](flatten.md)

## JSON Query and Extraction:
- [JSON_ARRAY_ELEMENTS](json-array-elements.md)
- [JSON_EACH](json-each.md)
- [JSON_EXTRACT_PATH_TEXT](json-extract-path-text.md)
- [JSON_PATH_EXISTS](json-path-exists.md)
- [JSON_PATH_QUERY](json-path-query.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: JSON_ARRAY_ELEMENTS
---
import FunctionDescription from '@site/src/components/FunctionDescription';

<FunctionDescription description="Introduced or updated: v1.2.152"/>

Extracts the elements from a JSON array, returning them as individual rows in the result set. JSON_ARRAY_ELEMENTS does not recursively expand nested arrays; it treats them as single elements.



## Syntax

```sql
JSON_ARRAY_ELEMENTS(<json_string>)
```

## Return Type

JSON_ARRAY_ELEMENTS returns a set of VARIANT values, each representing an element extracted from the input JSON array.

## Examples

```sql
-- Extract individual elements from a JSON array containing product information
SELECT
JSON_ARRAY_ELEMENTS(
PARSE_JSON (
'[
{"product": "Laptop", "brand": "Apple", "price": 1500},
{"product": "Smartphone", "brand": "Samsung", "price": 800},
{"product": "Headphones", "brand": "Sony", "price": 150}
]'
)
);

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ json_array_elements(parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]')) │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ {"brand":"Apple","price":1500,"product":"Laptop"} │
│ {"brand":"Samsung","price":800,"product":"Smartphone"} │
│ {"brand":"Sony","price":150,"product":"Headphones"} │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

-- Display data types of the extracted elements
SELECT
TYPEOF (
JSON_ARRAY_ELEMENTS(
PARSE_JSON (
'[
{"product": "Laptop", "brand": "Apple", "price": 1500},
{"product": "Smartphone", "brand": "Samsung", "price": 800},
{"product": "Headphones", "brand": "Sony", "price": 150}
]'
)
)
);

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ typeof(json_array_elements(parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]'))) │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ VARIANT NULL │
│ VARIANT NULL │
│ VARIANT NULL │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: JSON_EACH
---
import FunctionDescription from '@site/src/components/FunctionDescription';

<FunctionDescription description="Introduced or updated: v1.2.152"/>

Extracts key-value pairs from a JSON object, breaking down the structure into individual rows in the result set. Each row represents a distinct key-value pair derived from the input JSON expression.

## Syntax

```sql
JSON_EACH(<json_string>)
```

## Return Type

JSON_EACH returns a set of tuples, each consisting of a STRING key and a corresponding VARIANT value.

## Examples

```sql
-- Extract key-value pairs from a JSON object representing information about a person
SELECT
JSON_EACH(
PARSE_JSON (
'{"name": "John", "age": 25, "isStudent": false, "grades": [90, 85, 92]}'
)
);


┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
│ json_each(parse_json('{"name": "john", "age": 25, "isstudent": false, "grades": [90, 85, 92]}')) │
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ('age','25') │
│ ('grades','[90,85,92]') │
│ ('isStudent','false') │
│ ('name','"John"') │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘

-- Display data types of the extracted values
SELECT
TYPEOF (
JSON_EACH(
PARSE_JSON (
'{"name": "John", "age": 25, "isStudent": false, "grades": [90, 85, 92]}'
)
)
);

┌──────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ typeof(json_each(parse_json('{"name": "john", "age": 25, "isstudent": false, "grades": [90, 85, 92]}'))) │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ TUPLE(STRING, VARIANT) NULL │
│ TUPLE(STRING, VARIANT) NULL │
│ TUPLE(STRING, VARIANT) NULL │
│ TUPLE(STRING, VARIANT) NULL │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```