- Notifications
You must be signed in to change notification settings - Fork 36
docs: new json functions & operators #43
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits Select commit Hold shift + click to select a range
d978e4e Create json-each.md
soyeric128 1b9885b Create json-array-elements.md
soyeric128 fdf6d70 Update index.md
soyeric128 a36e623 refactored files
soyeric128 d75362d refactored files
soyeric128 dba754b Update json.md
soyeric128 e511ab2 Update subquery.md
soyeric128 fa28c0f Update dml-delete-from.md
soyeric128 0fcf235 Update index.md
soyeric128 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 0 additions & 3 deletions 3 docs/doc/14-sql-commands/30-query-operators/arithmetics/_category_.json
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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 | |
3 changes: 0 additions & 3 deletions 3 docs/doc/14-sql-commands/30-query-operators/comparisons/_category_.json
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions 23 docs/doc/14-sql-commands/30-query-operators/comparisons/index.md
This file was deleted.
Oops, something went wrong.
12 changes: 7 additions & 5 deletions 12 ...commands/30-query-operators/json/index.md → ...4-sql-commands/30-query-operators/json.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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 | |
3 changes: 0 additions & 3 deletions 3 docs/doc/14-sql-commands/30-query-operators/json/_category_.json
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions 3 docs/doc/14-sql-commands/30-query-operators/logic/_category_.json
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions 3 ...ommands/30-query-operators/logic/index.md → ...ql-commands/30-query-operators/logical.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions 66 docs/doc/15-sql-functions/110-semi-structured-functions/json-array-elements.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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 │ | ||
| └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ | ||
| ``` |
59 changes: 59 additions & 0 deletions 59 docs/doc/15-sql-functions/110-semi-structured-functions/json-each.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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 │ | ||
| └──────────────────────────────────────────────────────────────────────────────────────────────────────────┘ | ||
| ``` |
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.