# Chalk SQL Reference: String Functions
source: https://docs.chalk.ai/chalksql-docs#section-string-functions

## `boost_regexp_findall(string, pattern)`
source: https://docs.chalk.ai/chalksql-docs#boost_regexp_findall

Finds all matches of a regular expression `pattern` in a `string` and returns them as a list.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT boost_regexp_findall('[A-Z]{3}-[0-9]{4}', 'Blocked by ENG-1042; see also OPS-0077 and ENG-1190') AS ticket_refs;
```

```text
[ENG-1042, OPS-0077, ENG-1190]
```

```sql
SELECT boost_regexp_findall('[$]([0-9]+[.][0-9]{2})', 'UBER TRIP $23.40 + tip $5.00, refund $12.15') AS amounts;
```

```text
[23.40, 5.00, 12.15]
```

## `boyer_moore_search(string, substring)`
source: https://docs.chalk.ai/chalksql-docs#boyer_moore_search

Searches for the first occurrence of a pattern in a `string` using the Boyer-Moore algorithm. Returns the 0-based byte offset of the first match, or -1 if not found.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `substring`: `large_string`
  The `substring` to search for.

**Examples**

```sql
SELECT transform(ARRAY['REFUND AMAZON MKTPL', 'ACH DEBIT PAYROLL ACME CORP', 'POS REFUND TARGET #1123'], memo -> boyer_moore_search(memo, 'REFUND')) AS refund_offsets;
```

```text
[0, -1, 4]
```

```sql
SELECT substr('POS PURCHASE 04/12 WHOLEFDS MKT #10234 AUSTIN TX', boyer_moore_search('POS PURCHASE 04/12 WHOLEFDS MKT #10234 AUSTIN TX', '#') + 2, 5) AS store_number;
```

```text
10234
```

## `chr(n)`
source: https://docs.chalk.ai/chalksql-docs#chr

Converts an integer to its corresponding ASCII character.

**Parameters**

- `n`: `int64`
  The Unicode code point to convert to a character.

**Examples**

```sql
SELECT replace('WIRE' || chr(9) || 'ACME CORP' || chr(9) || 'INV-2231', chr(9), ' | ') AS cleaned_memo;
```

```text
WIRE | ACME CORP | INV-2231
```

```sql
SELECT chr(65 + CAST(floor(0.47 * 5) AS BIGINT)) AS risk_grade;
```

```text
C
```

## `codepoint(string)`
source: https://docs.chalk.ai/chalksql-docs#codepoint

Returns the Unicode code point of the only character of the `string`.

**Examples**

```sql
SELECT codepoint(substr('Émile Zola', 1, 1)) AS first_letter_codepoint;
```

```text
201
```

```sql
SELECT codepoint(substr('🛒 Grocery run', 1, 1)) > 127 AS memo_starts_non_ascii;
```

```text
true
```

**Overloads**

#### `codepoint(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `codepoint(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `concat(...)`
source: https://docs.chalk.ai/chalksql-docs#concat

Concatenates two or more `strings` or lists.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT concat('feature', '_', 'store');
```

```text
feature_store
```

**Overloads**

#### `concat(string1, string2, strings)`

Concatenates two or more `strings` together.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.
- `strings`: `large_string...`
  Additional `strings` to concatenate.

#### `concat(binary1, binary2, binaries)`

Concatenates two or more blobs together.

**Parameters**

- `binary1`: `large_binary`
  The first binary value.
- `binary2`: `large_binary`
  The second binary value.
- `binaries`: `large_binary...`
  Additional binary values to concatenate.

#### `concat(array1, array2, arrays)`

Concatenates two or more lists together.

**Parameters**

- `array1`: `list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.
- `arrays`: `list<item: $T>...`
  The input `arrays` or lists. `T` means matching inputs and outputs use the same type.

#### `concat(array1, array2, arrays)`

Concatenates two or more lists together.

**Parameters**

- `array1`: `large_list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `large_list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.
- `arrays`: `large_list<item: $T>...`
  The input `arrays` or lists. `T` means matching inputs and outputs use the same type.

## `count_matches(string, pattern)`
source: https://docs.chalk.ai/chalksql-docs#count_matches

Counts the number of non-overlapping regex matches in a `string`.

**Examples**

```sql
SELECT count_matches('Refund not received. REFUND requested twice; please refund ASAP', '(?i)\brefund') AS refund_mentions;
```

```text
3
```

```sql
SELECT count_matches('Call me at 415-555-0123 or 415-555-0199, email jo@example.com', '\d{3}-\d{3}-\d{4}') AS phone_numbers;
```

```text
2
```

**Overloads**

#### `count_matches(string, pattern)`

**Parameters**

- `string`: `string`
  The input `string`.
- `pattern`: `string`
  The `pattern` to match.

#### `count_matches(string, pattern)`

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

## `editdist3(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#editdist3

Alias for [levenshtein_distance](https://docs.chalk.ai/chalksql-docs#levenshtein_distance).

**Examples**

```sql
SELECT editdist3('Amazon Mktplace', 'Amazon Marketplace') AS memo_edit_distance;
```

```text
3
```

```sql
SELECT round(1.0 - editdist3(lower('Jon Smith'), lower('JOHN SMITH')) / CAST(greatest(length('Jon Smith'), length('JOHN SMITH')) AS DOUBLE), 2) AS name_similarity;
```

```text
0.9
```

## `ends_with(string, substring)`
source: https://docs.chalk.ai/chalksql-docs#ends_with

Checks if a `string` ends with a specified suffix.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `substring`: `large_string`
  The `substring` to search for.

**Examples**

```sql
SELECT ends_with('feature_store', 'store');
```

```text
true
```

## `hamming_distance(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#hamming_distance

Returns the Hamming distance of `string1` and `string2`, i.e. the number of positions at which the corresponding characters are different. Note that the two strings must have the same length.

**Examples**

```sql
SELECT hamming_distance('paypal.com', 'paypa1.com') AS lookalike_domain_edits;
```

```text
1
```

```sql
SELECT hamming_distance('1HGCM82633A004352', '1HGCM82633A004325') AS vin_char_mismatches;
```

```text
2
```

**Overloads**

#### `hamming_distance(string1, string2)`

**Parameters**

- `string1`: `string`
  The first input string.
- `string2`: `string`
  The second input string.

#### `hamming_distance(string1, string2)`

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.

## `ilike(string, pattern)`
source: https://docs.chalk.ai/chalksql-docs#ilike

Case-insensitive like

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT ilike('UBER *TRIP HELP.UBER.COM', '%uber%trip%') AS is_rideshare;
```

```text
true
```

```sql
SELECT ilike('Order SKU: tsh-blk-m', '%TSH-___-M') AS is_medium_tshirt;
```

```text
true
```

```sql
SELECT 'RE: Refund request for order #4521' ILIKE '%refund%' AS is_refund_ticket;
```

```text
true
```

## `instr(x, y)`
source: https://docs.chalk.ai/chalksql-docs#instr

Alias for [strpos](https://docs.chalk.ai/chalksql-docs#strpos).

**Examples**

```sql
SELECT strpos('chalk data', 'data');
```

```text
7
```

## `jaccard_similarity(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#jaccard_similarity

Calculates the Jaccard similarity coefficient between two strings based on character sets.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.

**Examples**

```sql
SELECT round(jaccard_similarity(lower('AMZN Mktp US'), lower('Amazon Marketplace')), 3) AS merchant_name_similarity;
```

```text
0.533
```

```sql
SELECT jaccard_similarity('listen', 'silent') AS anagram_similarity;
```

```text
1.0
```

## `jaro_similarity(a, b)`
source: https://docs.chalk.ai/chalksql-docs#jaro_similarity

Calculates the Jaro similarity between two strings.

**Parameters**

- `a`: `large_string`
- `b`: `large_string`

**Examples**

```sql
SELECT round(jaro_similarity(lower('Jon Smith'), lower('JOHN SMITH')), 3) AS name_match;
```

```text
0.967
```

```sql
SELECT jaro_similarity(lower(trim('  Katherine Johnson')), lower('CATHERINE JOHNSON')) >= 0.9 AS payee_matches_account_holder;
```

```text
true
```

## `jaro_winkler_distance(string1, string2, prefix_weight)`
source: https://docs.chalk.ai/chalksql-docs#jaro_winkler_distance

Calculates the Jaro-Winkler distance between two strings.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.
- `prefix_weight`: `double`
  The Jaro-Winkler prefix scaling factor.

**Examples**

```sql
SELECT round(jaro_winkler_distance(upper(trim('  Jonathon Smyth ')), 'JONATHAN SMITH', 0.1), 4) AS cardholder_name_distance;
```

```text
0.0571
```

```sql
SELECT ARRAY[round(jaro_winkler_distance('MARTHA', 'MARHTA', 0.0), 4), round(jaro_winkler_distance('MARTHA', 'MARHTA', 0.1), 4), round(jaro_winkler_distance('MARTHA', 'MARHTA', 0.25), 4)] AS distance_by_prefix_weight;
```

```text
[0.0556, 0.0389, 0.0139]
```

## `jaro_winkler_similarity(a, b, ...)`
source: https://docs.chalk.ai/chalksql-docs#jaro_winkler_similarity

Calculates the Jaro-Winkler similarity between two strings.

**Examples**

```sql
SELECT round(jaro_winkler_similarity(lower('Jonathan Smith'), lower('JONATHON SMITH')), 3) AS cardholder_name_match;
```

```text
0.971
```

```sql
SELECT round(jaro_winkler_similarity(lower('Jonathan Smith'), lower('JONATHON SMITH'), 0.0), 3) AS match_without_prefix_bonus;
```

```text
0.952
```

**Overloads**

#### `jaro_winkler_similarity(a, b)`

**Parameters**

- `a`: `large_string`
- `b`: `large_string`

#### `jaro_winkler_similarity(a, b, prefix_weight)`

**Parameters**

- `a`: `large_string`
- `b`: `large_string`
- `prefix_weight`: `double`
  The Jaro-Winkler prefix scaling factor.

## `knuth_morris_pratt_search(string, substring)`
source: https://docs.chalk.ai/chalksql-docs#knuth_morris_pratt_search

Searches for the first occurrence of a pattern in a `string` using the Knuth-Morris-Pratt algorithm. Returns the 0-based byte offset of the first match, or -1 if not found.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `substring`: `large_string`
  The `substring` to search for.

**Examples**

```sql
SELECT substr('ACH DEBIT VENMO PAYMENT REF:8841273', knuth_morris_pratt_search('ACH DEBIT VENMO PAYMENT REF:8841273', 'REF:') + 5) AS payment_ref;
```

```text
8841273
```

```sql
SELECT knuth_morris_pratt_search(lower('Where is my REFUND for order 5512?'), 'refund') >= 0 AS mentions_refund;
```

```text
true
```

## `len(...)`
source: https://docs.chalk.ai/chalksql-docs#len

Either:

- Returns the length of the binary in bytes.
- Returns the length of a string in characters.
- Returns the number of elements in a list.

**Type parameters.** `V` is the value type of the input map.

**Examples**

```sql
SELECT length('chalk');
```

```text
5
```

**Overloads**

#### `len(binary)`

Returns the length of the `binary` in bytes.

**Parameters**

- `binary`: `large_binary`
  The input `binary` value.

#### `len(string)`

Returns the length of a `string` in characters.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `len(string)`

Returns the length of a `string` in characters.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `len(array)`

Returns the number of elements in a list.

**Parameters**

- `array`: `list<item: $V>`
  The input `array` or list. `V` is the value type of the input map.

#### `len(array)`

Returns the number of elements in a list.

**Parameters**

- `array`: `large_list<item: $V>`
  The input `array` or list. `V` is the value type of the input map.

## `len_bytes(string)`
source: https://docs.chalk.ai/chalksql-docs#len_bytes

Returns the byte length of a `string`.

**Examples**

```sql
SELECT len_bytes('Café ☕ order #42') AS memo_bytes;
```

```text
19
```

```sql
SELECT len_bytes('Café ☕ order #42') > length('Café ☕ order #42') AS has_non_ascii;
```

```text
true
```

**Overloads**

#### `len_bytes(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `len_bytes(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `length(...)`
source: https://docs.chalk.ai/chalksql-docs#length

Returns the length of a `string`, `binary`, `array`, or map.

**Type parameters.** `V` is the value type of the input map.

**Examples**

```sql
SELECT length('chalk');
```

```text
5
```

```sql
SELECT length(array_constructor(1, 2, 3));
```

```text
3
```

**Overloads**

#### `length(binary)`

Returns the length of the `binary` in bytes.

**Parameters**

- `binary`: `large_binary`
  The input `binary` value.

#### `length(string)`

Returns the length of a `string` in characters.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `length(string)`

Returns the length of a `string` in characters.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `length(array)`

Returns the number of elements in a list.

**Parameters**

- `array`: `list<item: $V>`
  The input `array` or list. `V` is the value type of the input map.

#### `length(array)`

Returns the number of elements in a list.

**Parameters**

- `array`: `large_list<item: $V>`
  The input `array` or list. `V` is the value type of the input map.

## `levenshtein(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#levenshtein

Alias for [levenshtein_distance](https://docs.chalk.ai/chalksql-docs#levenshtein_distance).

**Examples**

```sql
SELECT levenshtein('paypa1-secure.com', 'paypal-secure.com') AS email_domain_edit_distance;
```

```text
1
```

```sql
SELECT round(1.0 - CAST(levenshtein(lower('AMZN Mktplace'), lower('Amazon Marketplace')) AS DOUBLE) / greatest(length('AMZN Mktplace'), length('Amazon Marketplace')), 3) AS merchant_name_similarity;
```

```text
0.722
```

## `levenshtein_distance(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#levenshtein_distance

Calculates the Levenshtein distance between two strings.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.

**Examples**

```sql
SELECT levenshtein_distance('Jonathon Smyth', 'Jonathan Smith') AS name_edit_distance;
```

```text
2
```

```sql
SELECT round(1.0 - levenshtein_distance(lower('Acme Corp.'), lower('ACME Corporation')) / greatest(length('Acme Corp.'), length('ACME Corporation')), 3) AS merchant_name_similarity;
```

```text
0.563
```

## `like(string, pattern)`
source: https://docs.chalk.ai/chalksql-docs#like

Checks if a `string` matches a `pattern` using SQL LIKE syntax with wildcards.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT like('ACH DEBIT NETFLIX.COM 866-579-7172', '%NETFLIX%') AS is_netflix_charge;
```

```text
true
```

```sql
SELECT like('SKU-48210-XL', 'SKU-____-XL') AS matches_sku_format;
```

```text
false
```

```sql
SELECT like('Save 20% on your next order', '%20#%%', '#') AS mentions_20_pct_off;
```

```text
true
```

## `longest_common_subsequence(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#longest_common_subsequence

Calculates the longest common subsequence between two strings.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.

**Examples**

```sql
SELECT longest_common_subsequence(lower('AMZN MKTP US*2K4'), lower('amazon marketplace')) AS lcs_length;
```

```text
9
```

```sql
SELECT round(CAST(longest_common_subsequence(lower('Jonathan Smith'), lower('JON SMITH')) AS DOUBLE) / greatest(length('Jonathan Smith'), length('JON SMITH')), 2) AS name_match_score;
```

```text
0.64
```

## `lower(string)`
source: https://docs.chalk.ai/chalksql-docs#lower

Converts a `string` to lowercase.

**Parameters**

- `string`: `large_string`
  The input `string`.

**Examples**

```sql
SELECT lower('Chalk');
```

```text
chalk
```

## `lpad(...)`
source: https://docs.chalk.ai/chalksql-docs#lpad

Left pads a `string` or `binary` value to a target length.

**Examples**

```sql
SELECT lpad('42', 5, '0');
```

```text
00042
```

**Overloads**

#### `lpad(binary, size, padbinary)`

Left pads `binary` to `size` bytes with `padbinary`.

**Parameters**

- `binary`: `large_binary`
  The input `binary` value.
- `size`: `int64`
- `padbinary`: `large_binary`

#### `lpad(string, size, padstring)`

Pads a `string` with a specified padding `string` on the left to reach a target length.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `size`: `int64`
- `padstring`: `large_string`

## `ltrim(string, ...)`
source: https://docs.chalk.ai/chalksql-docs#ltrim

Removes whitespace or specified characters from the left side of a `string`.

**Examples**

```sql
SELECT ltrim('  chalk');
```

```text
chalk
```

**Overloads**

#### `ltrim(string)`

Removes whitespace from the left end of a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `ltrim(string, chars)`

Removes specified characters from the left end of a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `chars`: `large_string`
  The characters to trim or match.

## `minijinja_render(template, context)`
source: https://docs.chalk.ai/chalksql-docs#minijinja_render

Render a Jinja2 `template` using the provided JSON `context` via minijinja.

**Examples**

```sql
SELECT minijinja_render('Classify this transaction memo: "{{ memo }}" (amount: ${{ amount }}, merchant: {{ merchant|upper }})', '{"memo": "UBER *TRIP 8XK2", "amount": 23.5, "merchant": "uber"}') AS llm_prompt;
```

```text
Classify this transaction memo: "UBER *TRIP 8XK2" (amount: $23.5, merchant: UBER)
```

```sql
SELECT minijinja_render('{% if score >= 0.8 %}HIGH{% elif score >= 0.5 %}MEDIUM{% else %}LOW{% endif %} risk: {{ flags|join(", ") }}', '{"score": 0.86, "flags": ["new_device", "foreign_ip"]}') AS risk_summary;
```

```text
HIGH risk: new_device, foreign_ip
```

**Overloads**

#### `minijinja_render(template, context)`

**Parameters**

- `template`: `string`
  The Jinja2 `template` string.
- `context`: `string`
  A JSON object providing the template variables.

#### `minijinja_render(template, context)`

**Parameters**

- `template`: `large_string`
  The Jinja2 `template` string.
- `context`: `large_string`
  A JSON object providing the template variables.

## `normalize(string, ...)`
source: https://docs.chalk.ai/chalksql-docs#normalize

Normalizes a `string` using a Unicode normalization `form`.

**Examples**

```sql
SELECT normalize('chalk');
```

```text
chalk
```

**Overloads**

#### `normalize(string)`

Transforms `string` with NFC normalization form.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `normalize(string, form)`

Transforms `string` with the specified Unicode normalization `form`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `form`: `large_string`

## `octet_length(...)`
source: https://docs.chalk.ai/chalksql-docs#octet_length

Returns the byte length of a `string` or `binary` value.

**Examples**

```sql
SELECT octet_length('chalk');
```

```text
5
```

**Overloads**

#### `octet_length(string)`

Returns the byte length of a `string`.

**Parameters**

- `string`: `string`
  The input `string`.

#### `octet_length(string)`

Returns the byte length of a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `octet_length(binary)`

Returns the length of the `binary` in bytes.

**Parameters**

- `binary`: `large_binary`
  The input `binary` value.

## `partial_ratio(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#partial_ratio

Calculates the partial ratio similarity between two strings using fuzzy matching.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.

**Examples**

```sql
SELECT partial_ratio('starbucks', lower('SQ *STARBUCKS STORE #1234 SEATTLE WA')) AS merchant_match_score;
```

```text
100.0
```

```sql
SELECT round(partial_ratio('starbucks', lower('SQ *STARBUKS COFFEE SEATTLE WA')), 1) AS merchant_match_score;
```

```text
88.9
```

```sql
SELECT partial_ratio('starbucks', 'SQ *STARBUCKS STORE #1234 SEATTLE WA') AS case_sensitive_score;
```

```text
0.0
```

## `prefix(x, y)`
source: https://docs.chalk.ai/chalksql-docs#prefix

Alias for [starts_with](https://docs.chalk.ai/chalksql-docs#starts_with).

**Examples**

```sql
SELECT starts_with('feature_store', 'feature');
```

```text
true
```

## `python_is_alnum(string)`
source: https://docs.chalk.ai/chalksql-docs#python_is_alnum

Returns true if all characters in the `string` are alphanumeric and there is at least one character, matching Python's str.isalnum() behavior.

**Examples**

```sql
SELECT transform(ARRAY['SAVE20', 'SAVE-20', 'save 20', ''], code -> python_is_alnum(code)) AS promo_code_is_alnum;
```

```text
[true, false, false, false]
```

```sql
SELECT transform(ARRAY['José99', '東京2024', 'x²', 'user_1'], handle -> python_is_alnum(handle)) AS handle_is_alnum;
```

```text
[true, true, true, false]
```

**Overloads**

#### `python_is_alnum(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_is_alnum(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_is_alpha(string)`
source: https://docs.chalk.ai/chalksql-docs#python_is_alpha

Returns true if all characters in the `string` are alphabetic and there is at least one character, matching Python's str.isalpha() behavior.

**Examples**

```sql
SELECT transform(ARRAY['Zoë', 'Ελλάδα', 'O''Brien', 'Mary Ann', 'R2D2', ''], n -> python_is_alpha(n)) AS valid_given_name;
```

```text
[true, true, false, false, false, false]
```

```sql
SELECT python_is_alpha(regexp_replace('Jean-Luc O''Néill', '[\s''-]', '')) AS full_name_is_letters;
```

```text
true
```

**Overloads**

#### `python_is_alpha(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_is_alpha(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_is_digit(string)`
source: https://docs.chalk.ai/chalksql-docs#python_is_digit

Returns true if all characters are digit characters and there is at least one character, matching Python's str.isdigit() behavior.

**Examples**

```sql
SELECT python_is_digit(replace('4111-1111-1111-1111', '-', '')) AS is_numeric_card;
```

```text
true
```

```sql
SELECT transform(ARRAY['94107', '9410A', '-42', '3.14', '', '²'], z -> python_is_digit(z)) AS is_digit_flags;
```

```text
[true, false, false, false, false, true]
```

**Overloads**

#### `python_is_digit(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_is_digit(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_is_lower(string)`
source: https://docs.chalk.ai/chalksql-docs#python_is_lower

Returns true if all cased characters are lowercase and there is at least one cased character, matching Python's str.islower() behavior.

**Examples**

```sql
SELECT transform(ARRAY['refund issued', 'URGENT: Call Me', 'order #48213 shipped', '12345'], s -> python_is_lower(s)) AS is_lower;
```

```text
[true, false, true, false]
```

**Overloads**

#### `python_is_lower(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_is_lower(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_is_numeric(string)`
source: https://docs.chalk.ai/chalksql-docs#python_is_numeric

Returns true if all characters are numeric characters and there is at least one character, matching Python's str.isnumeric() behavior.

**Examples**

```sql
SELECT CASE WHEN python_is_numeric(split_part('ACH PMT 4471 REF 20240115', ' ', 3)) THEN CAST(split_part('ACH PMT 4471 REF 20240115', ' ', 3) AS BIGINT) END AS payee_id;
```

```text
4471
```

```sql
SELECT transform(ARRAY['94107', '12.50', '-3', '', '½', 'Ⅻ', '٣٤'], s -> python_is_numeric(s)) AS is_numeric;
```

```text
[true, false, false, false, true, true, true]
```

**Overloads**

#### `python_is_numeric(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_is_numeric(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_is_space(string)`
source: https://docs.chalk.ai/chalksql-docs#python_is_space

Returns true if all characters are whitespace and there is at least one character, matching Python's str.isspace() behavior.

**Examples**

```sql
SELECT python_is_space(chr(9) || '   ' || chr(13) || chr(10)) AS ticket_body_is_blank;
```

```text
true
```

```sql
SELECT transform(ARRAY['  ' || chr(9) || chr(10), '', ' refund pls '], memo -> python_is_space(memo)) AS memo_is_blank;
```

```text
[true, false, false]
```

```sql
SELECT python_is_space(chr(160) || chr(8195)) AS unicode_space;
```

```text
true
```

**Overloads**

#### `python_is_space(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_is_space(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_is_title(string)`
source: https://docs.chalk.ai/chalksql-docs#python_is_title

Returns true if the `string` is titlecased and there is at least one cased character, matching Python's str.istitle() behavior.

**Examples**

```sql
SELECT transform(ARRAY['Wireless Mouse', 'wireless mouse', 'USB-C Cable', 'iPhone Case', '2024 Model', 'ACME'], t -> python_is_title(t)) AS is_title_case;
```

```text
[true, false, false, false, true, false]
```

```sql
SELECT CASE WHEN python_is_title('Mary-Jane O''Brien') THEN 'clean' ELSE 'needs_normalization' END AS name_entry_quality;
```

```text
clean
```

**Overloads**

#### `python_is_title(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_is_title(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_is_upper(string)`
source: https://docs.chalk.ai/chalksql-docs#python_is_upper

Returns true if all cased characters are uppercase and there is at least one cased character, matching Python's str.isupper() behavior.

**Examples**

```sql
SELECT python_is_upper('URGENT: REFUND ORDER #4471 NOW!!') AS is_all_caps_ticket;
```

```text
true
```

```sql
SELECT python_is_upper('4471-0092') AS is_all_caps_ticket;
```

```text
false
```

**Overloads**

#### `python_is_upper(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_is_upper(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_lstrip(string)`
source: https://docs.chalk.ai/chalksql-docs#python_lstrip

Strips leading Python whitespace (Unicode-aware), matching Python's str.lstrip() with no arguments.

**Examples**

```sql
SELECT starts_with(python_lstrip(chr(160) || chr(9) || ' REFUND: duplicate charge'), 'REFUND') AS is_refund_memo;
```

```text
true
```

```sql
SELECT '[' || python_lstrip(chr(160) || chr(12288) || '  Refund for order #8812  ') || ']' AS cleaned_memo;
```

```text
[Refund for order #8812  ]
```

**Overloads**

#### `python_lstrip(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_lstrip(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_remove_prefix(string, prefix)`
source: https://docs.chalk.ai/chalksql-docs#python_remove_prefix

Removes the `prefix` from the `string` if present, matching Python's str.removeprefix().

**Examples**

```sql
SELECT transform(ARRAY['POS DEBIT STARBUCKS #1123', 'ACH PAYROLL ACME INC'], m -> python_remove_prefix(m, 'POS DEBIT ')) AS merchants;
```

```text
[STARBUCKS #1123, ACH PAYROLL ACME INC]
```

```sql
SELECT python_remove_prefix('Re: Re: Refund request #4821', 'Re: ') AS ticket_subject;
```

```text
Re: Refund request #4821
```

**Overloads**

#### `python_remove_prefix(string, prefix)`

**Parameters**

- `string`: `string`
  The input `string`.
- `prefix`: `string`
  The `prefix` to test for or remove.

#### `python_remove_prefix(string, prefix)`

**Parameters**

- `string`: `large_string`
  The input `string`.
- `prefix`: `large_string`
  The `prefix` to test for or remove.

## `python_remove_suffix(string, suffix)`
source: https://docs.chalk.ai/chalksql-docs#python_remove_suffix

Removes the `suffix` from the `string` if present, matching Python's str.removesuffix().

**Examples**

```sql
SELECT python_remove_suffix('Acme Corp Inc.', ' Inc.') AS merchant_name;
```

```text
Acme Corp
```

```sql
SELECT transform(ARRAY['events_2024.csv', 'events_2025.parquet', 'users.csv'], f -> python_remove_suffix(f, '.csv')) AS table_names;
```

```text
[events_2024, events_2025.parquet, users]
```

**Overloads**

#### `python_remove_suffix(string, suffix)`

**Parameters**

- `string`: `string`
  The input `string`.
- `suffix`: `string`
  The `suffix` to test for or remove.

#### `python_remove_suffix(string, suffix)`

**Parameters**

- `string`: `large_string`
  The input `string`.
- `suffix`: `large_string`
  The `suffix` to test for or remove.

## `python_rstrip(string)`
source: https://docs.chalk.ai/chalksql-docs#python_rstrip

Strips trailing Python whitespace (Unicode-aware), matching Python's str.rstrip() with no arguments.

**Examples**

```sql
SELECT '[' || python_rstrip('  UBER *TRIP HELP.UBER.COM' || chr(160) || chr(12288) || chr(13) || chr(10)) || ']' AS cleaned_memo;
```

```text
[  UBER *TRIP HELP.UBER.COM]
```

```sql
SELECT python_rstrip('Wireless Earbuds' || chr(160)) = 'Wireless Earbuds' AS matches_catalog_title;
```

```text
true
```

**Overloads**

#### `python_rstrip(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_rstrip(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `python_string_slice(string, start, ...+2)`
source: https://docs.chalk.ai/chalksql-docs#python_string_slice

Slices a `string` with exact Python s[`start`:`stop`:`step`] semantics. All integer arguments are nullable (NULL = Python None / unspecified).

**Examples**

```sql
SELECT python_string_slice('4111111111111111', -4, NULL, NULL) AS card_last4;
```

```text
1111
```

```sql
SELECT python_string_slice('2024-03-15T09:30:00Z', 5, -10, NULL) AS month_day;
```

```text
03-15
```

```sql
SELECT python_string_slice('A1B2C3D4', 1, NULL, 2) AS digits;
```

```text
1234
```

**Overloads**

#### `python_string_slice(string, start, ...+2)`

**Parameters**

- `string`: `string`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.
- `stop`: `int64`
  The ending value or index, exclusive.
- `step`: `int64`
  The `step` between successive values.

#### `python_string_slice(string, start, ...+2)`

**Parameters**

- `string`: `large_string`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.
- `stop`: `int64`
  The ending value or index, exclusive.
- `step`: `int64`
  The `step` between successive values.

## `python_strip(string)`
source: https://docs.chalk.ai/chalksql-docs#python_strip

Strips leading and trailing Python whitespace (Unicode-aware), matching Python's str.strip() with no arguments.

**Examples**

```sql
SELECT python_strip(chr(160) || '  Wireless Mouse - Black' || chr(9) || chr(10)) AS product_title;
```

```text
Wireless Mouse - Black
```

```sql
SELECT python_strip(chr(160) || ' ACME COFFEE ' || chr(9) || chr(10)) = 'ACME COFFEE' AS memo_matches_merchant;
```

```text
true
```

```sql
SELECT nullif(python_strip(chr(12288) || chr(10) || chr(9) || '  '), '') IS NULL AS is_blank_note;
```

```text
true
```

**Overloads**

#### `python_strip(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `python_strip(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `regexp_extract(string, pattern, ...)`
source: https://docs.chalk.ai/chalksql-docs#regexp_extract

Returns the first substring matched by a regular expression.

**Examples**

```sql
SELECT regexp_extract('user_123', 'user_([0-9]+)', 1);
```

```text
123
```

**Overloads**

#### `regexp_extract(string, pattern)`

Returns the first substring matched by the regular expression `pattern` in `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

#### `regexp_extract(string, pattern, group)`

Returns the first substring matched by the regular expression `pattern` in `string` and returns the capturing `group` number `group`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.
- `group`: `int64`

## `regexp_extract_all(string, pattern, ...)`
source: https://docs.chalk.ai/chalksql-docs#regexp_extract_all

Returns all substrings matched by a regular expression.

**Examples**

```sql
SELECT regexp_extract_all('a1 b2 c3', '[a-z][0-9]');
```

```text
[a1, b2, c3]
```

**Overloads**

#### `regexp_extract_all(string, pattern)`

Returns the substring(s) matched by the regular expression `pattern` in `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

#### `regexp_extract_all(string, pattern)`

Returns the substring(s) matched by the regular expression `pattern` in `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

#### `regexp_extract_all(string, pattern, group)`

Returns the substring(s) matched by the regular expression `pattern` in `string` and returns the capturing `group` number `group`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.
- `group`: `int64`

#### `regexp_extract_all(string, pattern, group)`

Returns the substring(s) matched by the regular expression `pattern` in `string` and returns the capturing `group` number `group`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.
- `group`: `int64`

## `regexp_full_match(string, pattern)`
source: https://docs.chalk.ai/chalksql-docs#regexp_full_match

Checks if a `string` matches a regular expression `pattern`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT regexp_full_match('POS PURCHASE STARBUCKS #4471 SEATTLE WA', '(?i)starbucks|dunkin|peet''s') AS is_coffee_shop;
```

```text
true
```

```sql
SELECT regexp_full_match('ORD-2024-00981-RETRY', '^ORD-[0-9]{4}-[0-9]{5}$') AS is_valid_order_id;
```

```text
false
```

## `regexp_like(string, pattern)`
source: https://docs.chalk.ai/chalksql-docs#regexp_like

Checks if a `string` matches a regular expression `pattern`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT regexp_like('user_123', '^user_[0-9]+$');
```

```text
true
```

## `regexp_matches(x, y)`
source: https://docs.chalk.ai/chalksql-docs#regexp_matches

Alias for [regexp_like](https://docs.chalk.ai/chalksql-docs#regexp_like).

**Examples**

```sql
SELECT regexp_like('user_123', '^user_[0-9]+$');
```

```text
true
```

## `regexp_replace(string, pattern, ...)`
source: https://docs.chalk.ai/chalksql-docs#regexp_replace

Replaces or removes substrings matched by a regular expression.

**Examples**

```sql
SELECT regexp_replace('user_123', '[0-9]+', '456');
```

```text
user_456
```

**Overloads**

#### `regexp_replace(string, pattern, replacement)`

Replaces all matches of a regular expression `pattern` with a `replacement` `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.
- `replacement`: `large_string`
  The `replacement` value.

#### `regexp_replace(string, pattern)`

Removes all matches of a regular expression `pattern` from a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

#### `regexp_replace(string, pattern, function)`

Replaces every instance of the substring matched by the regular expression ```pattern``` in ```string``` using ```function```. The lambda expression ```function``` is invoked for each match with the capturing groups passed as an array. Capturing group numbers start at 1; there is no group for the entire match (if you need this, surround the entire expression with parenthesis).

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.
- `function`: `(large_string) => large_string`
  The callback `function` applied to the elements.

## `regexp_split(string, pattern)`
source: https://docs.chalk.ai/chalksql-docs#regexp_split

Splits ```string``` using the regular expression ```pattern``` into a list of strings.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT regexp_split('POS PURCHASE*STARBUCKS #1234  SEATTLE WA', '[\s*#]+') AS memo_tokens;
```

```text
[POS, PURCHASE, STARBUCKS, 1234, SEATTLE, WA]
```

```sql
SELECT cardinality(regexp_split('My order never arrived and support has not replied in 3 days', '\s+')) AS ticket_word_count;
```

```text
12
```

## `regexp_split_to_array(x, y)`
source: https://docs.chalk.ai/chalksql-docs#regexp_split_to_array

Alias for [regexp_split](https://docs.chalk.ai/chalksql-docs#regexp_split).

**Examples**

```sql
SELECT regexp_split_to_array('ACH DEBIT | PAYROLL;ACME CORP  |ref#88213', '\s*[|;]\s*') AS memo_parts;
```

```text
[ACH DEBIT, PAYROLL, ACME CORP, ref#88213]
```

```sql
SELECT cardinality(regexp_split_to_array('Wireless noise-cancelling over-ear headphones', '[\s-]+')) AS title_token_count;
```

```text
6
```

## `replace(string, search, ...)`
source: https://docs.chalk.ai/chalksql-docs#replace

Replaces or removes occurrences of a substring.

**Examples**

```sql
SELECT replace('hello chalk', 'hello', 'hi');
```

```text
hi chalk
```

**Overloads**

#### `replace(string, search)`

Removes all occurrences of `search` from `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `search`: `large_string`

#### `replace(string, search, replace)`

Replaces all occurrences of a substring with another `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `search`: `large_string`
- `replace`: `large_string`

## `reverse(...)`
source: https://docs.chalk.ai/chalksql-docs#reverse

Reverses a `string`, binary value, or `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT reverse('chalk');
```

```text
klahc
```

**Overloads**

#### `reverse(varbinary)`

Returns input binary with bytes in reversed order.

**Parameters**

- `varbinary`: `binary`

#### `reverse(varbinary)`

Returns input binary with bytes in reversed order.

**Parameters**

- `varbinary`: `large_binary`

#### `reverse(string)`

Reverses the characters in a `string`.

**Parameters**

- `string`: `string`
  The input `string`.

#### `reverse(string)`

Reverses the characters in a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `reverse(array)`

Returns the `array` in reversed order.

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `reverse(array)`

Returns the `array` in reversed order.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `rpad(...)`
source: https://docs.chalk.ai/chalksql-docs#rpad

Right pads a `string` or `binary` value to a target length.

**Examples**

```sql
SELECT rpad('42', 5, '0');
```

```text
42000
```

**Overloads**

#### `rpad(binary, size, padbinary)`

Right pads `binary` to `size` bytes with `padbinary`.

**Parameters**

- `binary`: `large_binary`
  The input `binary` value.
- `size`: `int64`
- `padbinary`: `large_binary`

#### `rpad(string, size, padstring)`

Pads a `string` with a specified padding `string` on the right to reach a target length.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `size`: `int64`
- `padstring`: `large_string`

## `rtrim(string, ...)`
source: https://docs.chalk.ai/chalksql-docs#rtrim

Removes whitespace or specified characters from the right side of a `string`.

**Examples**

```sql
SELECT rtrim('chalk  ');
```

```text
chalk
```

**Overloads**

#### `rtrim(string)`

Removes whitespace from the right end of a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `rtrim(string, chars)`

Removes specified characters from the right end of a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `chars`: `large_string`
  The characters to trim or match.

## `sequence_matcher_ratio(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#sequence_matcher_ratio

Computes the similarity ratio between two strings using sequence matching.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.

**Examples**

```sql
SELECT round(sequence_matcher_ratio(lower(trim('  Jonathan Smith ')), lower(trim('JONATHAN SMYTH'))), 3) AS payee_name_similarity;
```

```text
0.929
```

```sql
SELECT round(sequence_matcher_ratio('Jonathan Smith', 'JONATHAN SMITH'), 3) AS raw_ratio;
```

```text
0.214
```

## `split(string, delimiter, ...)`
source: https://docs.chalk.ai/chalksql-docs#split

Splits a `string` by a `delimiter`, optionally limiting the number of splits.

**Examples**

```sql
SELECT split('a,b,c', ',');
```

```text
[a, b, c]
```

**Overloads**

#### `split(string, delimiter)`

Splits a `string` by a `delimiter` into a list of strings.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `delimiter`: `large_string`
  The `delimiter` used to split or join the string.

#### `split(string, delimiter, limit)`

Splits a `string` by a `delimiter` with a maximum number of splits.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `delimiter`: `large_string`
  The `delimiter` used to split or join the string.
- `limit`: `int64`

## `split_part(string, delimiter, index)`
source: https://docs.chalk.ai/chalksql-docs#split_part

Splits a `string` by `delimiter` and returns the part at the specified `index` (1-based).

**Parameters**

- `string`: `large_string`
  The input `string`.
- `delimiter`: `large_string`
  The `delimiter` used to split or join the string.
- `index`: `int64`
  The `index` to read.

**Examples**

```sql
SELECT split_part('features.user.id', '.', 2);
```

```text
user
```

## `starts_with(string, substring)`
source: https://docs.chalk.ai/chalksql-docs#starts_with

Checks if a `string` starts with a specified prefix.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `substring`: `large_string`
  The `substring` to search for.

**Examples**

```sql
SELECT starts_with('feature_store', 'feature');
```

```text
true
```

## `str_split(...)`
source: https://docs.chalk.ai/chalksql-docs#str_split

Alias for [split](https://docs.chalk.ai/chalksql-docs#split).

**Examples**

```sql
SELECT element_at(str_split('electronics>computers>laptops', '>'), -1) AS leaf_category;
```

```text
laptops
```

```sql
SELECT str_split('ERROR: payment failed: card declined', ': ', 2) AS level_and_message;
```

```text
[ERROR, payment failed: card declined]
```

## `str_split_regex(x, y)`
source: https://docs.chalk.ai/chalksql-docs#str_split_regex

Alias for [regexp_split](https://docs.chalk.ai/chalksql-docs#regexp_split).

**Examples**

```sql
SELECT str_split_regex('wireless headphones, noise-cancelling;  bluetooth 5.3 |black', '\s*[,;|]\s*') AS product_tags;
```

```text
[wireless headphones, noise-cancelling, bluetooth 5.3, black]
```

```sql
SELECT str_split_regex('POS PURCHASE #4821 STARBUCKS STORE 1123', '\s*#\d+\s*')[2] AS merchant_part;
```

```text
STARBUCKS STORE 1123
```

## `string_split(...)`
source: https://docs.chalk.ai/chalksql-docs#string_split

Alias for [split](https://docs.chalk.ai/chalksql-docs#split).

**Examples**

```sql
SELECT element_at(string_split('POS PURCHASE*STARBUCKS #1042*SEATTLE WA', '*'), 2) AS merchant_name;
```

```text
STARBUCKS #1042
```

```sql
SELECT string_split('DECLINED:card_issuer:Insufficient funds: retry after 24h', ':', 3) AS decline_parts;
```

```text
[DECLINED, card_issuer, Insufficient funds: retry after 24h]
```

## `string_split_regex(x, y)`
source: https://docs.chalk.ai/chalksql-docs#string_split_regex

Alias for [regexp_split](https://docs.chalk.ai/chalksql-docs#regexp_split).

**Examples**

```sql
SELECT string_split_regex('organic, gluten-free;vegan |  non-gmo', '\s*[,;|]\s*') AS product_tags;
```

```text
[organic, gluten-free, vegan, non-gmo]
```

```sql
SELECT element_at(string_split_regex('POS PURCHASE   STARBUCKS #4821   SEATTLE WA', '\s{2,}'), 2) AS merchant_name;
```

```text
STARBUCKS #4821
```

## `string_to_array(...)`
source: https://docs.chalk.ai/chalksql-docs#string_to_array

Alias for [split](https://docs.chalk.ai/chalksql-docs#split).

**Examples**

```sql
SELECT element_at(string_to_array('Electronics > Computers > Laptops', ' > '), -1) AS leaf_category;
```

```text
Laptops
```

```sql
SELECT string_to_array('POS PURCHASE*STARBUCKS #1234*SEATTLE WA', '*', 2) AS memo_parts;
```

```text
[POS PURCHASE, STARBUCKS #1234*SEATTLE WA]
```

## `string_to_bytes_base64(x)`
source: https://docs.chalk.ai/chalksql-docs#string_to_bytes_base64

Alias for [from_base64](https://docs.chalk.ai/chalksql-docs#from_base64).

**Examples**

```sql
SELECT json_extract_scalar(from_utf8(string_to_bytes_base64('eyJldmVudCI6ImNoYXJnZS5zdWNjZWVkZWQiLCJhbW91bnQiOjQyMDB9')), '$.event') AS event_type;
```

```text
charge.succeeded
```

```sql
SELECT length(string_to_bytes_base64('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==')) AS image_num_bytes;
```

```text
70
```

## `string_to_bytes_hex(x)`
source: https://docs.chalk.ai/chalksql-docs#string_to_bytes_hex

Alias for [from_hex](https://docs.chalk.ai/chalksql-docs#from_hex).

**Examples**

```sql
SELECT string_to_bytes_hex('92ef9352c4a90c97d49718afa80788b91c407e18729a267a16b866d9bf3bc243') = sha256(to_utf8('{"order_id":1042,"amount":59.99}')) AS payload_digest_matches;
```

```text
true
```

```sql
SELECT from_utf8(string_to_bytes_hex('636172645f7465737465645f3432')) AS decoded_event;
```

```text
card_tested_42
```

## `string_to_bytes_utf8(x)`
source: https://docs.chalk.ai/chalksql-docs#string_to_bytes_utf8

Alias for [to_utf8](https://docs.chalk.ai/chalksql-docs#to_utf8).

**Examples**

```sql
SELECT length(string_to_bytes_utf8('Café ☕ München')) AS memo_byte_length;
```

```text
18
```

```sql
SELECT to_hex(sha256(string_to_bytes_utf8('user@example.com'))) AS email_sha256;
```

```text
b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514
```

## `strpos(string, substring, ...)`
source: https://docs.chalk.ai/chalksql-docs#strpos

Returns the position of a `substring` within a `string`.

**Examples**

```sql
SELECT strpos('chalk data', 'data');
```

```text
7
```

**Overloads**

#### `strpos(string, substring, instance)`

Returns the position of the N-th occurrence of a `substring` within a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `substring`: `large_string`
  The `substring` to search for.
- `instance`: `int64`
  Which occurrence to locate, 1-based.

#### `strpos(string, substring)`

Returns the position of the first occurrence of a `substring` within a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `substring`: `large_string`
  The `substring` to search for.

## `strrpos(string, substring, ...)`
source: https://docs.chalk.ai/chalksql-docs#strrpos

Returns the position of the last matching `substring` within a `string`.

**Examples**

```sql
SELECT strrpos('chalk data data', 'data');
```

```text
12
```

**Overloads**

#### `strrpos(string, substring, instance)`

Returns the position of the N-th occurrence of a `substring` from the end of a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `substring`: `large_string`
  The `substring` to search for.
- `instance`: `int64`
  Which occurrence to locate, 1-based.

#### `strrpos(string, substring)`

Returns the position of the last occurrence of a `substring` within a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `substring`: `large_string`
  The `substring` to search for.

## `substr(string, start, ...)`
source: https://docs.chalk.ai/chalksql-docs#substr

Returns a substring starting at the specified position, optionally with a specified `length`.

**Examples**

```sql
SELECT substr('feature_store', 9);
```

```text
store
```

```sql
SELECT substr('feature_store', 1, 7);
```

```text
feature
```

**Overloads**

#### `substr(string, start)`

Returns a substring starting at the specified position.

**Parameters**

- `string`: `string`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.

#### `substr(string, start)`

Returns a substring starting at the specified position.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.

#### `substr(string, start)`

Returns a substring starting at the specified position.

**Parameters**

- `string`: `binary`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.

#### `substr(string, start)`

Returns a substring starting at the specified position.

**Parameters**

- `string`: `large_binary`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.

#### `substr(string, start, length)`

Returns a substring starting at the specified position with the given `length`.

**Parameters**

- `string`: `string`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.
- `length`: `int64`

#### `substr(string, start, length)`

Returns a substring starting at the specified position with the given `length`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.
- `length`: `int64`

#### `substr(string, start, length)`

Returns a substring starting at the specified position with the given `length`.

**Parameters**

- `string`: `binary`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.
- `length`: `int64`

#### `substr(string, start, length)`

Returns a substring starting at the specified position with the given `length`.

**Parameters**

- `string`: `large_binary`
  The input `string`.
- `start`: `int64`
  The starting value or index, inclusive.
- `length`: `int64`

## `substring(...)`
source: https://docs.chalk.ai/chalksql-docs#substring

Alias for [substr](https://docs.chalk.ai/chalksql-docs#substr).

**Examples**

```sql
SELECT substr('feature_store', 9);
```

```text
store
```

```sql
SELECT substr('feature_store', 1, 7);
```

```text
feature
```

## `suffix(x, y)`
source: https://docs.chalk.ai/chalksql-docs#suffix

Alias for [ends_with](https://docs.chalk.ai/chalksql-docs#ends_with).

**Examples**

```sql
SELECT ends_with('feature_store', 'store');
```

```text
true
```

## `titlecase(string)`
source: https://docs.chalk.ai/chalksql-docs#titlecase

Converts a `string` to title case.

**Examples**

```sql
SELECT titlecase(trim('  BLUE BOTTLE coffee   ')) AS merchant_name;
```

```text
Blue Bottle Coffee
```

```sql
SELECT titlecase('mary-jane o''brien') AS customer_name;
```

```text
Mary-jane O'brien
```

**Overloads**

#### `titlecase(string)`

**Parameters**

- `string`: `string`
  The input `string`.

#### `titlecase(string)`

**Parameters**

- `string`: `large_string`
  The input `string`.

## `token_set_ratio(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#token_set_ratio

Calculates the token set ratio similarity between two strings using fuzzy matching.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.

**Examples**

```sql
SELECT token_set_ratio(lower('Starbucks Coffee Store 1234 Seattle'), lower('STARBUCKS COFFEE')) AS merchant_match_score;
```

```text
100.0
```

```sql
SELECT round(token_set_ratio(lower('Sony WH-1000XM5 Wireless Headphones Black'), lower('Sony WH-1000XM4 Wireless Headphones')), 1) AS title_similarity;
```

```text
89.5
```

```sql
SELECT token_set_ratio('Starbucks Coffee', 'STARBUCKS COFFEE') AS case_sensitive_score;
```

```text
18.75
```

## `token_sort_ratio(string1, string2)`
source: https://docs.chalk.ai/chalksql-docs#token_sort_ratio

Calculates the token sort ratio similarity between two strings using fuzzy matching.

**Parameters**

- `string1`: `large_string`
  The first input string.
- `string2`: `large_string`
  The second input string.

**Examples**

```sql
SELECT token_sort_ratio('john a smith', 'smith john a') AS name_match_score;
```

```text
100.0
```

```sql
SELECT token_sort_ratio(lower('Acme Corp Payroll Deposit'), lower('PAYROLL DEPOSIT ACME CORP')) >= 90 AS is_same_payee;
```

```text
true
```

## `trail(string, N)`
source: https://docs.chalk.ai/chalksql-docs#trail

Returns the last `N` characters of the input `string`, up to at most the length of `string`.

**Examples**

```sql
SELECT concat('**** **** **** ', trail('4111 1111 1111 4242', 4)) AS masked_card;
```

```text
**** **** **** 4242
```

```sql
SELECT trail('MX', 5) AS short_code_tail;
```

```text
MX
```

**Overloads**

#### `trail(string, N)`

**Parameters**

- `string`: `string`
  The input `string`.
- `N`: `int64`

#### `trail(string, N)`

**Parameters**

- `string`: `large_string`
  The input `string`.
- `N`: `int64`

## `trim(string, ...)`
source: https://docs.chalk.ai/chalksql-docs#trim

Removes whitespace or specified characters from both ends of a `string`.

**Examples**

```sql
SELECT trim('  chalk  ');
```

```text
chalk
```

```sql
SELECT trim('xychalkyx', 'xy');
```

```text
chalk
```

**Overloads**

#### `trim(string)`

Removes whitespace from both ends of a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.

#### `trim(string, chars)`

Removes specified characters from both ends of a `string`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `chars`: `large_string`
  The characters to trim or match.

## `unidecode_normalize(string)`
source: https://docs.chalk.ai/chalksql-docs#unidecode_normalize

Normalizes Unicode characters to their closest ASCII equivalents with whitespace normalization.

**Parameters**

- `string`: `large_string`
  The input `string`.

## `unidecode_to_ascii(string)`
source: https://docs.chalk.ai/chalksql-docs#unidecode_to_ascii

Converts Unicode characters to their closest ASCII equivalents.

**Parameters**

- `string`: `large_string`
  The input `string`.

## `upper(string)`
source: https://docs.chalk.ai/chalksql-docs#upper

Converts a `string` to uppercase.

**Parameters**

- `string`: `large_string`
  The input `string`.

**Examples**

```sql
SELECT upper('chalk');
```

```text
CHALK
```

## `uuid_string(namespace, name)`
source: https://docs.chalk.ai/chalksql-docs#uuid_string

Generates a UUID string: a random version 4 UUID with no arguments, or the deterministic version 5 UUID of a `name` within a `namespace` UUID with two arguments.

**Examples**

```sql
SELECT uuid_string();
```

```sql
SELECT uuid_string('fe971b24-9572-4005-b22f-351e9c09274d', 'chalk');
```

**Overloads**

#### `uuid_string()`

Generates a random (version 4) UUID string.

**Parameters**

None

#### `uuid_string(namespace, name)`

Generates the version 5 (SHA-1) UUID string of a `name` within a `namespace` UUID.

**Parameters**

- `namespace`: `string`
- `name`: `string`

#### `uuid_string(namespace, name)`

Generates the version 5 (SHA-1) UUID string of a `name` within a `namespace` UUID.

**Parameters**

- `namespace`: `large_string`
- `name`: `large_string`

## `word_stem(word, ...)`
source: https://docs.chalk.ai/chalksql-docs#word_stem

Returns the stem of a `word` using stemming algorithms.

**Examples**

```sql
SELECT array_join(transform(split(lower('Customer requested refunds after charges were disputed'), ' '), w -> word_stem(w)), ' ') AS stemmed_memo;
```

```text
custom request refund after charg were disput
```

```sql
SELECT word_stem('Zahlungen', 'de') AS stem_de;
```

```text
zahlung
```

**Overloads**

#### `word_stem(word)`

**Parameters**

- `word`: `large_string`

#### `word_stem(word, lang)`

**Parameters**

- `word`: `large_string`
- `lang`: `large_string`

## `zfill(string, width)`
source: https://docs.chalk.ai/chalksql-docs#zfill

Left-pads a `string` with zeros to the given `width`.

**Examples**

```sql
SELECT zfill(CAST(2134 AS VARCHAR), 5) AS zip_code;
```

```text
02134
```

```sql
SELECT zfill('-42', 6) AS signed_offset;
```

```text
-00042
```

**Overloads**

#### `zfill(string, width)`

**Parameters**

- `string`: `string`
  The input `string`.
- `width`: `int64`
  The target string `width`.

#### `zfill(string, width)`

**Parameters**

- `string`: `large_string`
  The input `string`.
- `width`: `int64`
  The target string `width`.

## `zi_split_part(string, delimiter, index)`
source: https://docs.chalk.ai/chalksql-docs#zi_split_part

Splits a `string` by `delimiter` and returns the part at the specified zero-based `index`.

**Parameters**

- `string`: `large_string`
  The input `string`.
- `delimiter`: `large_string`
  The `delimiter` used to split or join the string.
- `index`: `int64`
  The `index` to read.

**Examples**

```sql
SELECT lower(zi_split_part('Jane.Doe@Example.COM', '@', 1)) AS email_domain;
```

```text
example.com
```

```sql
SELECT zi_split_part('POS 4821 STARBUCKS #1123 SEATTLE WA', ' ', 2) AS merchant;
```

```text
STARBUCKS
```

```sql
SELECT coalesce(zi_split_part('electronics>audio', '>', 2), 'none') AS third_level_category;
```

```text
none
```

## `string !~~ pattern`
source: https://docs.chalk.ai/chalksql-docs#%21~~

operator alias for not like

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT lower('REFUND - Order #48213') !~~ 'refund%' AS is_purchase;
```

```text
false
```

```sql
SELECT 'SKU-A1-RED' !~~ 'SKU-___-%' AS bad_sku_format;
```

```text
true
```

## `string !~~* pattern`
source: https://docs.chalk.ai/chalksql-docs#%21~~%2A

operator alias for not ilike

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT 'Hi, I need a REFUND for order 88123' !~~* '%refund%' AS is_not_refund_request;
```

```text
false
```

```sql
SELECT 'promo10' !~~* 'PROMO__' AS fails_promo_code_format;
```

```text
false
```

## `x ^@ y`
source: https://docs.chalk.ai/chalksql-docs#%5E%40

Alias for [starts_with](https://docs.chalk.ai/chalksql-docs#starts_with).

**Examples**

```sql
SELECT starts_with('feature_store', 'feature');
```

```text
true
```

## `||...`
source: https://docs.chalk.ai/chalksql-docs#%7C%7C

Alias for [concat](https://docs.chalk.ai/chalksql-docs#concat).

**Examples**

```sql
SELECT 'MERCH-' || upper('acme coffee') || '-' || CAST(42 AS VARCHAR) AS merchant_key;
```

```text
MERCH-ACME COFFEE-42
```

```sql
SELECT 'Title: ' || 'Wireless Earbuds' || ' | Brand: ' || coalesce(NULL, 'unknown') AS embedding_input;
```

```text
Title: Wireless Earbuds | Brand: unknown
```

## `string ~~ pattern`
source: https://docs.chalk.ai/chalksql-docs#~~

operator alias for like

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT 'POS PURCHASE STARBUCKS #1234 SEATTLE WA' ~~ '%STARBUCKS%' AS is_coffee_purchase;
```

```text
true
```

```sql
SELECT lower('Pos Purchase STARBUCKS #1234') ~~ '%starbucks%' AS is_coffee_purchase;
```

```text
true
```

```sql
SELECT 'ORD-2024-A7' ~~ 'ORD-____-__' AS is_valid_order_id;
```

```text
true
```

## `string ~~* pattern`
source: https://docs.chalk.ai/chalksql-docs#~~%2A

Case-insensitive like

**Parameters**

- `string`: `large_string`
  The input `string`.
- `pattern`: `large_string`
  The `pattern` to match.

**Examples**

```sql
SELECT 'Payment to UBER *TRIP 8821' ~~* '%uber%trip%' AS is_rideshare;
```

```text
true
```

```sql
SELECT 'sku-ab12-RED' ~~* 'SKU-__12-%' AS is_ab12_family;
```

```text
true
```
