SPLIT_PART
Splits source string based upon a seperator and returns the given part (counting from one).
See also:
[SELECT
]
Syntax
SELECT SPLIT_PART(source, sep, part) FROM <multipartIdentifier>;
Arguments
source
A literal string or string column that you want to perform the split on.
sep
A character or characters you want to use as the separator.
If
sep
is composed of multiple characters, each character is treated as separator.
Only ASCII (1-byte) symbols are supported as separators.
part
The element (one based) of the split string to return. Negative values are used to count backwards from the last element.
Return Value(s)
Returns a string.
Examples
Extract elements from a string seperated by a forward slash
- StackQL
- Results
SELECT name,
split_part(id, '/', 3) as subscription,
split_part(id, '/', 5) as resource_group,
json_extract(properties, '$.hardwareProfile.vmSize') as vm_size
FROM azure.compute.virtual_machines
WHERE resourceGroupName = 'stackql-ops-cicd-dev-01'
AND subscriptionId = '273769f6-545f-45b2-8ab8-2f14ec5768dc';
|------|--------------------------------------|-------------------------|-----------------|
| name | subscription | resource_group | vm_size |
|------|--------------------------------------|-------------------------|-----------------|
| test | 273769f6-545f-45b2-8ab8-2f14ec5768dc | stackql-ops-cicd-dev-01 | Standard_D2s_v3 |
|------|--------------------------------------|-------------------------|-----------------|
Extract the last element from a url
- StackQL
- Results
SELECT
name,
SPLIT_PART(network, '/', -1) as network,
SPLIT_PART(region, '/', -1) as region
FROM google.compute.vpn_gateways WHERE project = 'stackql-demo';
+------------------------+-----------------------+----------------------+
| name | network | region |
+------------------------+-----------------------+----------------------+
| gcp-aws-vpn-gateway | stackql-shrd-vpc-nw | australia-southeast1 |
+------------------------+-----------------------+----------------------+
For more information, see https://github.com/nalgeon/sqlean/blob/main/docs/text.md