Documentation

SQL string functions

The InfluxDB SQL implementation supports the following string functions for operating on string values:

ascii

Returns the ASCII value of the first character in a string.

ascii returns a 32-bit integer. To use with InfluxDB, cast the return value to 64-bit integer.

ascii(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

chr

View ascii query example

bit_length

Returns the bit length of a string.

bit_length returns a 32-bit integer. To use with InfluxDB, cast the return value to 64-bit integer.

bit_length(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

length, octet_length

View bit_length query example

btrim

Trims the specified trim string from the start and end of a string. If no trim string is provided, all whitespace is removed from the start and end of the input string.

btrim(str[, trim_str])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • trim_str: String expression to trim from the beginning and end of the input string. Can be a constant, column, or function, and any combination of arithmetic operators. Default is whitespace characters.

ltrim, rtrim, trim

View btrim query example

char_length

Alias of length.

character_length

Alias of length.

concat

Concatenates multiple strings together.

concat(str[, ..., str_n])
Arguments
  • str: String expression to concatenate. Can be a constant, column, or function, and any combination of string operators.
  • str_n: Subsequent string expression to concatenate.

contcat_ws

View concat query example

concat_ws

Concatenates multiple strings together with a specified separator.

concat_ws(separator, str[, ..., str_n])
Arguments
  • separator: Separator to insert between concatenated strings.
  • str: String expression to concatenate. Can be a constant, column, or function, and any combination of string operators.
  • str_n: Subsequent string expression to concatenate. Can be a constant, column, or function, and any combination of string operators.

concat

View concat_ws query example

chr

Returns the character with the specified ASCII or Unicode code value.

chr(expression)

Arguments

  • expression: Expression containing the ASCII or Unicode code value to operate on. Can be a constant, column, or function, and any combination of arithmetic or string operators.

ascii

View chr query example

ends_with

Tests if a string ends with a substring.

ends_with(str, substr)
Arguments
  • str: String expression to test. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring to test for.

View ends_with query example

find_in_set

Returns the position of a string in a comma-delimited list of substrings. Returns 0 if the string is not in the list of substrings.

find_in_set(str, strlist)
Arguments
  • str: String expression to find in strlist.
  • strlist: A string containing a comma-delimited list of substrings.

View find_in_set query example

initcap

Capitalizes the first character in each word in the input string. Words are delimited by non-alphanumeric characters.

initcap(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

lower, upper

View initcap query example

instr

Returns the location where a substring first appears in a string (starting at 1). If the substring is not in the string, the function returns 0.

instr(str, substr)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring expression to search for. Can be a constant, column, or function, and any combination of string operators.

View instr query example

left

Returns a specified number of characters from the left side of a string.

left(str, n)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • n: Number of characters to return.

right

View left query example

length

Returns the number of characters in a string.

char_length returns a 32-bit integer. To use with InfluxDB, cast the return value to 64-bit integer.

length(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
Aliases
  • char_length
  • character_length

bit_length, octet_length

View length query example

levenshtein

Returns the Levenshtein distance between two strings.

levenshtein(str1, str2)
Arguments
  • str1: First string expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • str2: Second string expression to operate on. Can be a constant, column, or function, and any combination of string operators.

View levenshtein query example

lower

Converts a string to lower-case.

lower(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

initcap, upper

View lower query example

lpad

Pads the left side of a string with another string to a specified string length.

lpad(str, n[, padding_str])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • n: String length to pad to.
  • padding_str: String expression to pad with. Can be a constant, column, or function, and any combination of string operators. Default is a space.

rpad

View lpad query example

ltrim

Removes leading spaces from a string.

ltrim(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

btrim, rtrim, trim

View ltrim query example

md5

Computes an MD5 128-bit checksum for a string expression.

md5(str)
Arguments
  • expression: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

View md5 query example

octet_length

Returns the length of a string in bytes.

length returns a 32-bit integer. To use with InfluxDB, cast the return value to 64-bit integer.

octet_length(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

bit_length, length

View octet_length query example

overlay

Replaces part of a string with another substring using a specified starting position and number of characters to replace.

overlay(str PLACING substr FROM pos [FOR count])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring to use to replace part of the specified string (str). Can be a constant, column, or function, and any combination of string operators.
  • pos: Start position of the substring replacement (substr).
  • count: Number of characters in the string (str) to replace with the substring (substr) beginning from the start position (pos). If not specified, the function uses the length of the substring.

View overlay query example

position

Returns the position of a substring in a string.

position(substr IN str)
Arguments
  • substr: Substring expression to search for. Can be a constant, column, or function, and any combination of string operators.
  • str: String expression to search. Can be a constant, column, or function, and any combination of string operators.

View position query example

repeat

Returns a string with an input string repeated a specified number of times.

repeat(str, n)
Arguments
  • str: String expression to repeat. Can be a constant, column, or function, and any combination of string operators.
  • n: Number of times to repeat the input string.

View repeat query example

replace

Replaces all occurrences of a specified substring in a string with a new substring.

replace(str, substr, replacement)
Arguments
  • str: String expression to repeat. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring expression to replace in the input string. Can be a constant, column, or function, and any combination of string operators.
  • replacement: Replacement substring expression. Can be a constant, column, or function, and any combination of string operators.

View replace query example

reverse

Reverses the character order of a string.

reverse(str)
Arguments
  • str: String expression to repeat. Can be a constant, column, or function, and any combination of string operators.

View reverse query example

Returns a specified number of characters from the right side of a string.

right(str, n)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • n: Number of characters to return.

left

View right query example

rpad

Pads the right side of a string with another string to a specified string length.

rpad(str, n[, padding_str])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • n: String length to pad to.
  • padding_str: String expression to pad with. Can be a constant, column, or function, and any combination of string operators. Default is a space.

lpad

View rpad query example

rtrim

Removes trailing spaces from a string.

rtrim(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

btrim, ltrim, trim

View rtrim query example

split_part

Splits a string based on a specified delimiter and returns the substring in the specified position.

split_part(str, delimiter, pos)
Arguments
  • str: String expression to spit. Can be a constant, column, or function, and any combination of string operators.
  • delimiter: String or character to split on.
  • pos: Position of the part to return.

View split_part query example

starts_with

Tests if a string starts with a substring.

starts_with(str, substr)
Arguments
  • str: String expression to test. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring to test for.

View starts_with query example

strpos

Returns the starting position of a specified substring in a string. Positions begin at 1. If the substring does not exist in the string, the function returns 0.

strpos returns a 32-bit integer. To use with InfluxDB, cast the return value to 64-bit integer.

strpos(str, substr)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring expression to search for. Can be a constant, column, or function, and any combination of string operators.

View strpos query example

substr

Extracts a substring of a specified number of characters from a specific starting position in a string.

substr(str, start_pos[, length])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • start_pos: Character position to start the substring at. The first character in the string has a position of 1.
  • length: Number of characters to extract. If not specified, returns the rest of the string after the start position.

View substr query example

substr_index

Returns the substring that occurs before or after the specified number (count) of delimiter (delimiter) occurrences in a string (str). If the count is positive, the function returns everything to the left of the final delimiter (counting from the left). If the count is negative, the function returns everything to the right of the final delimiter (counting from the right).

substr_index(str, delimiter, count)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • delimiter: String expression to use to delimit substrings in the string (str). Can be a constant, column, or function, and any combination of string operators.
  • count: The Nth occurrence of the delimiter (delimiter) to split on. Can be a constant, column, or function, and any combination of arithmetic operators. Supports positive and negative numbers.

View substr_index query example

translate

Translates characters in a string to specified translation characters.

translate(str, chars, translation)
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • chars: Characters to translate.
  • translation: Translation characters. Translation characters replace only characters at the same position in the chars string.

View translate query example

to_hex

Converts an integer to a hexadecimal string.

to_hex(int)
Arguments
  • int: Integer expression to convert. Can be a constant, column, or function, and any combination of arithmetic operators.

View to_hex query example

trim

Removes leading and trailing spaces from a string.

trim(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

btrim, ltrim, rtrim

View trim query example

upper

Converts a string to upper-case.

upper(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

initcap, lower

View upper query example

uuid

Returns a UUID v4 string value that is unique per row.

uuid()

View uuid query example


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

InfluxDB Cloud Serverless