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 |
|
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. |
|
Converts the first character of a string to its Unicode code point number. |
|
Returns the character for a Unicode code point. |
|
Changes how strings compare and sort, for example to ignore case or accents, or to follow the rules of a language. |
|
Concatenates one or more strings or lists, skipping |
|
Concatenates strings with a separator between them, skipping |
|
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. |
|
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. |
Builds a string by replacing |
|
Converts a number of bytes to a readable size, such as |
|
Formats a number of bytes as text in decimal units, such as |
|
formatReadableSize |
Alias of format_bytes. |
Tests whether a string matches a file-name style pattern that uses the |
|
Compares two strings of the same length character by character and returns how many positions differ. |
|
Combines a partition column name and a value into one percent-encoded Hive-style path segment, such as |
|
Returns a sort key that orders strings by the collation rules of a language. |
|
Tests whether a string matches a pattern that uses the |
|
Tests whether a string matches a |
|
Finds a search string in a string and returns the 1-based position where its first occurrence starts, or |
|
Returns the Jaccard similarity of the sets of characters in two strings, from |
|
Returns the Jaro similarity of two strings, from |
|
Returns the Jaro-Winkler similarity of two strings, from |
|
lcase |
Alias of lower. |
Returns the leftmost characters of a string. |
|
Returns the leftmost grapheme clusters of a string, where each grapheme cluster is one character as a reader sees it. |
|
Returns the number of characters in a string. It also counts the elements of a list. The list and array functions topic describes it. |
|
Returns the number of grapheme clusters in a string, where each grapheme cluster is one character as a reader sees it. |
|
Returns the Levenshtein edit distance between two strings. |
|
Tests whether a string matches a pattern that uses the |
|
Tests whether a string matches a |
|
Converts a string to lowercase. |
|
Pads a string on the left to a given length, or shortens it to that length. |
|
Removes leading spaces, or other leading characters that you choose, from a string. |
|
mismatches |
Alias of hamming. |
Converts a string to Unicode Normalization Form C (NFC). |
|
Tests whether a string does not match a |
|
Tests whether a string does not match a |
|
ord |
Alias of unicode. |
Replaces part of a string, starting at a given character position, with another string. |
|
Returns the first component of a path, such as its top-level directory. |
|
Returns the directory part of a path, without its last component. |
|
Returns the last component of a path, such as a file name, optionally without its extension. |
|
Converts a readable size, such as |
|
Splits a path into a list of its components. |
|
Joins path components into one path. |
|
position |
Alias of instr. |
Tests whether a string starts with another string. |
|
Formats values into a string with C-style |
|
Escapes the characters in a string that have special meaning in a regular expression. |
|
Returns the part of a string that matches a regular expression, or one or more of its capturing groups. |
|
Returns every non-overlapping match of a regular expression in a string, as a list. |
|
Tests whether a whole string matches a regular expression. |
|
Tests whether a string contains a match for a regular expression. |
|
Replaces the first match, or every match, of a regular expression in a string. |
|
regexp_split_to_array |
Alias of string_split_regex. |
Splits a string at each match of a regular expression and returns one row for each part. |
|
Returns a string repeated a given number of times. It also repeats blobs and lists. The blob and bitstring functions topic describes it. |
|
Replaces every occurrence of a substring with another string. |
|
Returns the characters of a string in reverse order. |
|
Returns the rightmost characters of a string. |
|
Returns the rightmost grapheme clusters of a string. |
|
Pads a string on the right to a given length, or shortens it to that length. |
|
Removes trailing spaces, or other trailing characters, from a string. |
|
split |
Alias of string_split. |
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. |
Splits a string at a separator and returns the parts as a list. |
|
Splits a string at each match of a regular expression and returns the parts as a list. |
|
string_to_array |
Alias of string_split. |
Removes accent marks from the letters in a string. |
|
Returns the number of bytes in a string. |
|
strpos |
Alias of instr. |
substr |
Alias of substring. |
Returns part of a string, starting at a given character position. |
|
Returns part of a string, counting positions in grapheme clusters instead of characters. |
|
Tests whether a string ends with another string. |
|
Converts a number to a string of digits in a given base. |
|
Replaces or removes individual characters in a string. |
|
Removes spaces, or other characters that you choose, from both ends of a string. |
|
ucase |
Alias of upper. |
Returns the Unicode code point of the first character in a string. |
|
Converts a string to uppercase. |
|
Decodes a percent-encoded string, such as part of a URL. |
|
Percent-encodes a string so that you can use it in a URL. |