Skip to main content

String Functions

This page provides a comprehensive overview of String functions in Databend, organized by functionality for easy reference.

String Concatenation and Manipulation​

FunctionDescriptionExample
CONCATConcatenates stringsCONCAT('data', 'bend') → 'databend'
CONCAT_WSConcatenates strings with a separatorCONCAT_WS('-', 'data', 'bend') → 'data-bend'
INSERTInserts a string at a specified positionINSERT('databend', 5, 0, 'cloud') → 'databcloudbend'
REPLACEReplaces occurrences of a substringREPLACE('databend', 'bend', 'cloud') → 'datacloud'
TRANSLATEReplaces characters with their replacementsTRANSLATE('databend', 'abn', '123') → 'd1t12e3d'

String Extraction​

FunctionDescriptionExample
LEFTReturns leftmost charactersLEFT('databend', 4) → 'data'
RIGHTReturns rightmost charactersRIGHT('databend', 4) → 'bend'
SUBSTR / SUBSTRINGExtracts a substringSUBSTR('databend', 5, 4) → 'bend'
MIDExtracts a substring (alias for SUBSTRING)MID('databend', 5, 4) → 'bend'
SPLITSplits a string into an arraySPLIT('data,bend', ',') → ['data', 'bend']
SPLIT_PARTReturns a specific part after splittingSPLIT_PART('data,bend', ',', 2) → 'bend'
REGEXP_SPLIT_TO_ARRAYSplit a string into an array of segments using the specified patternregexp_split_to_array('apple,banana,orange', ','); → '['apple','banana','orange']'
REGEXP_SPLIT_TO_TABLESplit a string into a table of segments using the specified patternregexp_split_to_table('data,bend', ',', 2)

String Padding and Formatting​

FunctionDescriptionExample
LPADLeft-pads a string to a lengthLPAD('bend', 8, 'data') → 'databend'
RPADRight-pads a string to a lengthRPAD('data', 8, 'bend') → 'databend'
REPEATRepeats a string n timesREPEAT('data', 2) → 'datadata'
SPACEReturns a string of spacesSPACE(4) → ' '
REVERSEReverses a stringREVERSE('databend') → 'dnebtad'

String Trimming​

FunctionDescriptionExample
TRIMRemoves leading and trailing spacesTRIM(' databend ') → 'databend'
TRIM_BOTHRemoves specified chars from both endsTRIM_BOTH('xxdatabendxx', 'x') → 'databend'
TRIM_LEADINGRemoves specified chars from startTRIM_LEADING('xxdatabend', 'x') → 'databend'
TRIM_TRAILINGRemoves specified chars from endTRIM_TRAILING('databendxx', 'x') → 'databend'
LTRIMRemoves leading spacesLTRIM(' databend') → 'databend'
RTRIMRemoves trailing spacesRTRIM('databend ') → 'databend'

String Information​

FunctionDescriptionExample
LENGTHReturns string length in charactersLENGTH('databend') → 8
CHAR_LENGTH / CHARACTER_LENGTHReturns string length in charactersCHAR_LENGTH('databend') → 8
BIT_LENGTHReturns string length in bitsBIT_LENGTH('databend') → 64
OCTET_LENGTHReturns string length in bytesOCTET_LENGTH('databend') → 8
INSTRReturns position of first occurrenceINSTR('databend', 'bend') → 5
LOCATEReturns position of first occurrenceLOCATE('bend', 'databend') → 5
POSITIONReturns position of first occurrencePOSITION('bend' IN 'databend') → 5
STRCMPCompares two stringsSTRCMP('databend', 'datacloud') → -1
JARO_WINKLERReturns similarity between stringsJARO_WINKLER('databend', 'databand') → 0.9619047619047619

Case Conversion​

FunctionDescriptionExample
LOWER / LCASEConverts to lowercaseLOWER('DataBend') → 'databend'
UPPER / UCASEConverts to uppercaseUPPER('databend') → 'DATABEND'

Pattern Matching​

FunctionDescriptionExample
LIKEPattern matching with wildcards'databend' LIKE 'data%' → true
NOT_LIKENegated LIKE'databend' NOT LIKE 'cloud%' → true
REGEXP / RLIKEPattern matching with regex'databend' REGEXP '^data' → true
NOT_REGEXP / NOT_RLIKENegated regex matching'databend' NOT REGEXP '^cloud' → true
REGEXP_LIKEReturns boolean for regex matchREGEXP_LIKE('databend', '^data') → true
REGEXP_INSTRReturns position of regex matchREGEXP_INSTR('databend', 'bend') → 5
REGEXP_SUBSTRReturns substring matching regexREGEXP_SUBSTR('databend', 'bend') → 'bend'
REGEXP_REPLACEReplaces regex matchesREGEXP_REPLACE('databend', 'bend', 'cloud') → 'datacloud'
GLOBUnix-style pattern matching'databend' GLOB 'data*' → true

Encoding and Decoding​

FunctionDescriptionExample
ASCIIReturns ASCII value of first characterASCII('D') → 68
ORDReturns Unicode code point of first characterORD('D') → 68
CHAR / CHRReturns string of characters for given Unicode code pointsCHAR(68,97,116,97) → 'Data'
BINReturns binary representationBIN(5) → '101'
OCTReturns octal representationOCT(8) → '10'
HEXReturns hexadecimal representationHEX('ABC') → '414243'
UNHEXConverts hex to binaryUNHEX('414243') → 'ABC'
TO_BASE64Encodes to base64TO_BASE64('databend') → 'ZGF0YWJlbmQ='
FROM_BASE64Decodes from base64FROM_BASE64('ZGF0YWJlbmQ=') → 'databend'

Miscellaneous​

FunctionDescriptionExample
QUOTEEscapes string for SQLQUOTE('databend') → '"databend"'
SOUNDEXReturns soundex codeSOUNDEX('databend') → 'D315'
SOUNDSLIKECompares soundex valuesSOUNDSLIKE('databend', 'databand') → true
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today