# SPLIT_PART

> SPLIT_PART function in StackQL: split a string on a separator and return the part at a one-based position, handy for picking apart resource IDs and ARNs.

Source: https://stackql.io/language-spec/functions/string/split_part

Splits source string based upon a seperator and returns the given part (counting from one).  

See also:  
[[` SELECT `]](/language-spec/select) 

* * * 

## Syntax

```sql
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**

```sql
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 resource_group_name = 'stackql-ops-cicd-dev-01' 
 AND subscription_id = '273769f6-545f-45b2-8ab8-2f14ec5768dc';
```

**Results**

```
|------|--------------------------------------|-------------------------|-----------------|
| 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**

```sql
SELECT
name,
SPLIT_PART(network, '/', -1) as network,
SPLIT_PART(region, '/', -1) as region
FROM google.compute.vpn_gateways WHERE project = 'stackql-demo';
```

**Results**

```
+------------------------+-----------------------+----------------------+
| 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](https://github.com/nalgeon/sqlean/blob/main/docs/text.md)
