Scalar Functions Reference¶
Complete reference for YAML scalar functions.
Extraction Functions¶
yaml_extract¶
Extracts a value at the specified path.
| Parameter | Type | Description |
|---|---|---|
yaml |
YAML | Source YAML value |
path |
VARCHAR | JSONPath-like expression |
Returns: YAML value at path, or NULL if not found.
yaml_extract_string¶
Extracts a value as a string.
| Parameter | Type | Description |
|---|---|---|
yaml |
YAML | Source YAML value |
path |
VARCHAR | JSONPath-like expression |
Returns: VARCHAR representation of value, or NULL.
yaml_exists¶
Checks if a path exists.
| Parameter | Type | Description |
|---|---|---|
yaml |
YAML | Source YAML value |
path |
VARCHAR | JSONPath-like expression |
Returns: TRUE if path exists, FALSE otherwise.
yaml_type¶
Returns the type of a YAML value.
| Parameter | Type | Description |
|---|---|---|
yaml |
YAML | Source YAML value |
path |
VARCHAR | Optional path expression |
Returns: One of: 'object', 'array', 'scalar', 'null'
yaml_keys¶
Returns keys of a YAML object.
| Parameter | Type | Description |
|---|---|---|
yaml |
YAML | Source YAML value |
path |
VARCHAR | Optional path to object |
Returns: Array of key names, or NULL if not an object.
yaml_array_length¶
Returns the length of a YAML array.
| Parameter | Type | Description |
|---|---|---|
yaml |
YAML | Source YAML value |
path |
VARCHAR | Optional path to array |
Returns: Number of elements, or NULL if not an array.
Conversion Functions¶
yaml_to_json¶
Converts YAML to JSON.
| Parameter | Type | Description |
|---|---|---|
yaml |
YAML | YAML value to convert |
Returns: JSON equivalent.
value_to_yaml¶
Converts any DuckDB value to YAML.
| Parameter | Type | Description |
|---|---|---|
value |
ANY | Value to convert |
Returns: YAML representation.
SELECT value_to_yaml({'name': 'John', 'scores': [1, 2, 3]});
-- Returns: name: John\nscores:\n - 1\n - 2\n - 3
format_yaml¶
Formats a value as YAML with configurable style.
| Parameter | Type | Description |
|---|---|---|
value |
ANY | Value to format as YAML |
style |
VARCHAR | 'flow' or 'block' (named parameter) |
multiline |
VARCHAR | 'auto', 'literal', or 'quoted' (named parameter) |
indent |
INTEGER | 1-10, indentation width (named parameter) |
Returns: Formatted YAML string.
SELECT format_yaml({'a': 1, 'b': 2}, style := 'block');
-- Returns:
-- a: 1
-- b: 2
-- Multiline strings with literal block scalars
SELECT format_yaml({'msg': E'hello\nworld'}, style := 'block', multiline := 'literal');
-- Returns:
-- msg: |
-- hello
-- world
-- Custom indentation
SELECT format_yaml({'a': {'b': 1}}, style := 'block', indent := 4);
-- Returns:
-- a:
-- b: 1
from_yaml¶
Parses YAML into a structured type.
| Parameter | Type | Description |
|---|---|---|
yaml_string |
VARCHAR | YAML string to parse |
structure |
STRUCT | Template defining output structure |
Returns: Struct matching the template.
SELECT from_yaml('name: John\nage: 30', {'name': '', 'age': 0});
-- Returns: {'name': John, 'age': 30}
Construction Functions¶
yaml_build_object¶
Builds a YAML object from key-value pairs.
| Parameter | Type | Description |
|---|---|---|
key |
VARCHAR | Object key |
value |
ANY | Value for key |
Returns: YAML object.
Utility Functions¶
yaml_valid¶
Checks if a string is valid YAML.
| Parameter | Type | Description |
|---|---|---|
yaml_string |
VARCHAR | String to validate |
Returns: TRUE if valid, FALSE otherwise.
yaml_set_default_style¶
Sets the default output style.
| Parameter | Type | Description |
|---|---|---|
style |
VARCHAR | 'flow' or 'block' |
Returns: Confirmation message.
yaml_get_default_style¶
Returns the current default style.
Returns: 'flow' or 'block'.