View a markdown version of this page

String functions and operators in DuckDB - Amazon Athena

String functions and operators in DuckDB

Use string functions and operators to build, search, compare, and reformat text values.

Text comparisons and the LIKE and GLOB pattern matches are case-sensitive, and ILIKE ignores case. Positions in a string start at 1, and most functions return NULL when an argument is NULL, though some, such as concat, skip NULL arguments.

The following table lists the string functions and operators, with a link to the description of each one.

Function or operator Description

^@

Tests whether a string begins with a given prefix.

||

Joins two strings, two lists, or two BLOB values into one value.

array_extract

Returns the character at a position in a string. It also returns an element of a list or a field of a struct. The list and array functions topic describes it.

ascii

Converts the first character of a string to its Unicode code point number.

chr

Returns the character for a Unicode code point.

Collations

Changes how strings compare and sort, for example to ignore case or accents, or to follow the rules of a language.

concat

Concatenates one or more strings or lists, skipping NULL arguments.

concat_ws

Concatenates strings with a separator between them, skipping NULL arguments.

contains

Tests whether a string contains a substring, a list contains an element, a map contains a key, or an unnamed struct contains a field value.

damerau_levenshtein

Returns the edit distance between two strings, counting a swap of two adjacent characters as one edit.

editdist3

Alias of levenshtein.

ends_with

Alias of suffix.

format

Builds a string by replacing {} placeholders with argument values.

format_bytes

Converts a number of bytes to a readable size, such as 15.6 KiB, in binary units.

formatReadableDecimalSize

Formats a number of bytes as text in decimal units, such as 16.0 kB or 1.5 MB.

formatReadableSize

Alias of format_bytes.

GLOB

Tests whether a string matches a file-name style pattern that uses the *, ?, and [] wildcards.

hamming

Compares two strings of the same length character by character and returns how many positions differ.

hive_partition_component

Combines a partition column name and a value into one percent-encoded Hive-style path segment, such as year=2024.

icu_sort_key

Returns a sort key that orders strings by the collation rules of a language.

ILIKE

Tests whether a string matches a pattern that uses the % and _ wildcards, ignoring case.

ilike_escape

Tests whether a string matches a LIKE pattern, ignoring case, with an escape character that you choose.

instr

Finds a search string in a string and returns the 1-based position where its first occurrence starts, or 0 if the string does not contain it.

jaccard

Returns the Jaccard similarity of the sets of characters in two strings, from 0 to 1.

jaro_similarity

Returns the Jaro similarity of two strings, from 0 to 1.

jaro_winkler_similarity

Returns the Jaro-Winkler similarity of two strings, from 0 to 1, which can give a higher score when the strings share a prefix.

lcase

Alias of lower.

left

Returns the leftmost characters of a string.

left_grapheme

Returns the leftmost grapheme clusters of a string, where each grapheme cluster is one character as a reader sees it.

length

Returns the number of characters in a string. It also counts the elements of a list. The list and array functions topic describes it.

length_grapheme

Returns the number of grapheme clusters in a string, where each grapheme cluster is one character as a reader sees it.

levenshtein

Returns the Levenshtein edit distance between two strings.

LIKE

Tests whether a string matches a pattern that uses the % and _ wildcards, with case-sensitive matching.

like_escape

Tests whether a string matches a LIKE pattern, with an escape character that you choose.

lower

Converts a string to lowercase.

lpad

Pads a string on the left to a given length, or shortens it to that length.

ltrim

Removes leading spaces, or other leading characters that you choose, from a string.

mismatches

Alias of hamming.

nfc_normalize

Converts a string to Unicode Normalization Form C (NFC).

not_ilike_escape

Tests whether a string does not match a LIKE pattern, ignoring case, with an escape character that you choose.

not_like_escape

Tests whether a string does not match a LIKE pattern, with an escape character that you choose.

ord

Alias of unicode.

overlay

Replaces part of a string, starting at a given character position, with another string.

parse_dirname

Returns the first component of a path, such as its top-level directory.

parse_dirpath

Returns the directory part of a path, without its last component.

parse_filename

Returns the last component of a path, such as a file name, optionally without its extension.

parse_formatted_bytes

Converts a readable size, such as 16 KiB, to a number of bytes.

parse_path

Splits a path into a list of its components.

path_join

Joins path components into one path.

position

Alias of instr.

prefix

Tests whether a string starts with another string.

printf

Formats values into a string with C-style % format specifiers.

regexp_escape

Escapes the characters in a string that have special meaning in a regular expression.

regexp_extract

Returns the part of a string that matches a regular expression, or one or more of its capturing groups.

regexp_extract_all

Returns every non-overlapping match of a regular expression in a string, as a list.

regexp_full_match

Tests whether a whole string matches a regular expression.

regexp_matches

Tests whether a string contains a match for a regular expression.

regexp_replace

Replaces the first match, or every match, of a regular expression in a string.

regexp_split_to_array

Alias of string_split_regex.

regexp_split_to_table

Splits a string at each match of a regular expression and returns one row for each part.

repeat

Returns a string repeated a given number of times. It also repeats blobs and lists. The blob and bitstring functions topic describes it.

replace

Replaces every occurrence of a substring with another string.

reverse

Returns the characters of a string in reverse order.

right

Returns the rightmost characters of a string.

right_grapheme

Returns the rightmost grapheme clusters of a string.

rpad

Pads a string on the right to a given length, or shortens it to that length.

rtrim

Removes trailing spaces, or other trailing characters, from a string.

split

Alias of string_split.

split_part

Splits a string at a delimiter and returns the part at a given position.

starts_with

Alias of ^@.

str_split

Alias of string_split.

str_split_regex

Alias of string_split_regex.

string_split

Splits a string at a separator and returns the parts as a list.

string_split_regex

Splits a string at each match of a regular expression and returns the parts as a list.

string_to_array

Alias of string_split.

strip_accents

Removes accent marks from the letters in a string.

strlen

Returns the number of bytes in a string.

strpos

Alias of instr.

substr

Alias of substring.

substring

Returns part of a string, starting at a given character position.

substring_grapheme

Returns part of a string, counting positions in grapheme clusters instead of characters.

suffix

Tests whether a string ends with another string.

to_base

Converts a number to a string of digits in a given base.

translate

Replaces or removes individual characters in a string.

trim

Removes spaces, or other characters that you choose, from both ends of a string.

ucase

Alias of upper.

unicode

Returns the Unicode code point of the first character in a string.

upper

Converts a string to uppercase.

url_decode

Decodes a percent-encoded string, such as part of a URL.

url_encode

Percent-encodes a string so that you can use it in a URL.