String Functions and Operators

str1 || str2

Returns the concatnenated string of both side strings str1 and str2.

Parameters:
  • str1 – first string
  • str2 – second string
Return type:

text

Example:
select ‘Ta’ || ‘jo’;
> 'Tajo'
char_length(string text)

Returns Number of characters in string

Parameters:string – to be counted
Return type:int4
Alias:character_length
Example:
select char_length(‘Tajo’);
> 4
trim([leading | trailing | both] [characters] from string)

Removes the characters (a space by default) from the start/end/both ends of the string

Parameters:
  • string
  • characters
Return type:

text

Example:
select trim(both ‘x’ from ‘xTajoxx’);
> Tajo
btrim(string text[, characters text])

Removes the characters (a space by default) from the both ends of the string

Parameters:
  • string
  • characters
Return type:

text

Alias:

trim

Example:
select btrim(‘xTajoxx’, ‘x’);
> Tajo
ltrim(string text[, characters text])

Removes the characters (a space by default) from the start ends of the string

Parameters:
  • string
  • characters
Return type:

text

Example:
select ltrim(‘xxTajo’, ‘x’);
> Tajo
rtrim(string text[, characters text])

Removes the characters (a space by default) from the end ends of the string

Parameters:
  • string
  • characters
Return type:

text

Example:
select rtrim('Tajoxx', 'x');
> Tajo
split_part(string text, delimiter text, field int)

Splits a string on delimiter and return the given field (counting from one)

Parameters:
  • string
  • delimiter
  • field
Return type:

text

Example:
select split_part(‘ab_bc_cd’,‘_’,2);
> bc
regexp_replace(string text, pattern text, replacement text)

Replaces substrings matched to a given regular expression pattern

Parameters:
  • string
  • pattern
  • replacement
Return type:

text

Example:
select regexp_replace(‘abcdef’, ‘(ˆab|ef$)’, ‘–’);
> –cd–
upper(string text)

makes an input text to be upper case

Parameters:string
Return type:text
Example:
select upper('tajo');
> TAJO
lower(string text)

makes an input text to be lower case

Parameters:string
Return type:text
Example:
select lower('TAJO');
> tajo