Skip to main content

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.

Return Value(s)

Returns a string.


Examples

Extract elements from a string seperated by a forward slash

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';

For more information, see https://github.com/nalgeon/sqlean/blob/main/docs/text.md