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 column or literal string to operate on.

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 column or literal string to operate on.

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 column or literal string to operate on.
  • trim_str: String column or literal string to trim from the beginning and end of the input string. 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 column or literal string to concatenate.
  • str_n: Subsequent string column or literal string to concatenate.

contcat_ws

View concat query example

concat_ws

Concatenates multiple strings together with a specified separator.

concat(separator, str[, ..., str_n])
Arguments
  • separator: Separator to insert between concatenated strings.
  • str: String column or literal string to concatenate.
  • str_n: Subsequent string column or literal string to concatenate.

concat

View concat_ws query example

chr

Returns the character with the specified ASCII code value.

chr(acsii)
Arguments
  • ascii: ASCII code value to operate on.

ascii

View chr 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 column or literal string to operate on.

lower, upper

View initcap query example

left

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

left(str, n)
Arguments
  • str: String column or literal string to operate on.
  • 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 column or literal string to operate on.
Aliases
  • char_length
  • character_length

bit_length, octet_length

View length query example

lower

Converts a string to lower-case.

lower(str)
Arguments
  • str: String column or literal string to operate on.

initcap, upper

View lower query example

lpad

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

lpad(str, n[, padding_str])
Arguments
  • str: String column or literal string to operate on.
  • n: String length to pad to.
  • padding_str: String column or literal string to pad with. Default is a space.

rpad

View lpad query example

ltrim

Removes leading spaces from a string.

ltrim(str)
Arguments
  • str: String column or literal string to operate on.

btrim, rtrim, trim

View ltrim query example

md5

Calculates and returns an MD5 128-bit checksum for a string.

md5(str)
Arguments
  • str: String column or literal string to operate on.

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 column or literal string to operate on.

bit_length, length

View octet_length query example

repeat

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

repeat(str, n)
Arguments
  • str: String column or literal string to repeat.
  • 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 column or literal string to repeat.
  • substr: Substring to replace in the input string.
  • replacement: Replacement substring.

View replace query example

reverse

Reverses the character order of a string.

reverse(str)
Arguments
  • str: String column or literal string to repeat.

View reverse query example

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

right(str, n)
Arguments
  • str: String column or literal string to operate on.
  • n: Number of characters to return.

left

View right query example

rpad

right side a string with another string to a specified string length.

rpad(str, n[, padding_str])
Arguments
  • str: String column or literal string to operate on.
  • n: String length to pad to.
  • padding_str: String column or literal string to pad with. Default is a space.

lpad

View rpad query example

rtrim

Removes trailing spaces from a string.

rtrim(str)
Arguments
  • str: String column or literal string to operate on.

btrim, ltrim, trim

View rtrim query example

split_part

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

split_part(str, delimiter, pos)
Arguments
  • str: String column or literal string to spit.
  • 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 column or literal string to test.
  • 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 column or literal string to operate on.
  • substr: Substring to search for.

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 column or literal string to operate on.
  • 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

translate

Translates characters in a string to specified translation characters.

translate(str, chars, translation)
  • str: String column or literal string to operate on.
  • 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 column or literal integer to convert.

View to_hex query example

trim

Removes leading and trailing spaces from a string.

trim(str)
Arguments
  • str: String column or literal string to operate on.

btrim, ltrim, rtrim

View trim query example

upper

Converts a string to upper-case.

upper(str)
Arguments
  • str: String column or literal string to operate on.

initcap, lower

View upper query example


Was this page helpful?

Thank you for your feedback!


Linux Package Signing Key Rotation

All signed InfluxData Linux packages have been resigned with an updated key. If using Linux, you may need to update your package configuration to continue to download and verify InfluxData software packages.

For more information, see the Linux Package Signing Key Rotation blog post.

InfluxDB Cloud backed by InfluxDB IOx

All InfluxDB Cloud organizations created on or after January 31, 2023 are backed by the new InfluxDB IOx storage engine. Check the right column of your InfluxDB Cloud organization homepage to see which InfluxDB storage engine you’re using.

If powered by IOx, this is the correct documentation.

If powered by TSM, see the TSM-based InfluxDB Cloud documentation.

InfluxDB Cloud backed by InfluxDB TSM

All InfluxDB Cloud organizations created on or after January 31, 2023 are backed by the new InfluxDB IOx storage engine which enables nearly unlimited series cardinality and SQL query support. Check the right column of your InfluxDB Cloud organization homepage to see which InfluxDB storage engine you’re using.

If powered by TSM, this is the correct documentation.

If powered by IOx, see the IOx-based InfluxDB Cloud documentation.

State of the InfluxDB Cloud (IOx) documentation

The new documentation for InfluxDB Cloud backed by InfluxDB IOx is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.