Skip to content

String Functions

String Operator and Function will work with text / enum type.

String Operator / Function

By now, ClapDB just support a few operators and functions.

  • length
  • substr
  • lower
  • position
  • upper
  • startswith
  • ltrim
  • rtrim
  • btrim
  • concat
  • like
  • not like
  • regexp_like

ClapDB query SQL will fully compatibility with PostgreSQL’s SQL, and string functions and operators’ current state can be checked in below chart.

Compatible with PostgreSQL

According to PostgreSQL String Functions and Operators

PostgreSQL String Operator / FunctionDescriptionFormulaExampleClapDB supportedClapDB will support in future release
||Concatenates the two strings.text || text → text’hello’ || ‘world’ → ‘helloworld’
||Converts the non-string input to text, then concatenates the two strings. (The non-string input cannot be of an array type, because that would create ambiguity with the array || operators. If you want to concatenate an array’s text equivalent, cast it to text explicitly.)text || anynonarray → text’hello’ || 2 → ‘hello2’
||anynonarray || text → text’hello’ || 2 → ‘hello2’
btrimRemoves the longest string consisting only of characters in characters (a space by default) from the start and end of string.btrim(string text [, characters text]) → textbtrim(‘xyxtrimyyx’, ‘xyz’) → ‘trim’
text IS [NOT][form] NORMALIZEDChecks whether the string is in the specified Unicode normalization form. The optional form key word specifies the form: NFC (the default), NFD, NFKC, or NFKD. This expression can only be used when the server encoding is UTF8. Note that checking for normalization using this expression is often faster than normalizing possibly already normalized strings.text IS [NOT] NORMALIZED [form] → boolean’Mnchen’ IS NORMALIZED → true
bit_lengthReturns number of bits in the string (8 times the octet_length).bit_length(string text) → integerbit_length(‘jose’) → 32
char_lengthReturns the number of characters in string.char_length(string text) → integerchar_length(‘jose’) → 4
character_lengthcharacter_length(string text) → integercharacter_length(‘jose’) → 4
lowerConverts the string to all lower case, according to the rules of the database’s locale.lower(string text) → textlower(‘TOM’) → ‘tom’
lpadExtends the string to length length by prepending the characters fill (a space by default). If the string is already longer than length then it is truncated (on the right).lpad(string text, length integer [, fill text]) → textlpad(‘hi’, 5, ‘xy’) → ‘xyxhi’
ltrimRemoves the longest string containing only characters in characters (a space by default) from the start of string.ltrim(string text [, characters text]) → textltrim(‘zzzytest’, ‘xyz’) → ‘test’
normalizeConverts the string to the specified Unicode normalization form. The optional form key word specifies the form: NFC (the default), NFD, NFKC, or NFKD. This function can only be used when the server encoding is UTF8.normalize(string text [, form text]) → textnormalize(U&‘\0061\0308bc’, NFC) → U&‘\00E4bc’
octet_lengthReturns the number of bytes in string.octet_length(string text) → integeroctet_length(‘josé’) → 5
octet_lengthoctet_length(character) → integeroctet_length(‘abc ‘::character(4)) → 4
overlayReplaces the substring of string that starts at the start’th character and extends for count characters with newsubstring. If count is omitted, it defaults to the length of newsubstring.overlay ( string text PLACING newsubstring text FROM start integer [ FOR count integer ] ) → textoverlay(‘Txxxxas’ placing ‘hom’ from 2 for 4) → Thomas
positionReturns first starting index of the specified substring within string, or zero if it’s not present.position ( substring text IN string text ) → integerposition(‘om’ in ‘Thomas’) → 3
rpadExtends the string to length length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated.rpad ( string text, length integer [, fill text ] ) → textrpad(‘hi’, 5, ‘xy’) → hixyx
rtrimRemoves the longest string containing only characters in characters (a space by default) from the end of string.rtrim(string text [, characters text]) → textrtrim(‘testxxzx’, ‘xyz’) → ‘test’
substringExtracts the substring of string starting at the start’th character if that is specified, and stopping after count characters if that is specified. Provide at least one of start and count.substring ( string text [ FROM start integer ] [ FOR count integer ] ) → textsubstring(‘Thomas’ from 2 for 3) → hom
substringExtracts the first substring matching POSIX regular expressionsubstring ( string text FROM pattern text ) → textsubstring(‘Thomas’ from ‘…$’) → mas
substringExtracts the first substring matching SQL regular expression; The first form has been specified since SQL:2003; the second form was only in SQL:1999 and should be considered obsolete.substring ( string text SIMILAR pattern text ESCAPE escape text ) → textsubstring(‘Thomas’ similar ‘…$’) → mas
substringsubstring ( string text FROM pattern text FOR escape text ) → textsubstring(‘Thomas’ similar ‘…$’) → mas
trimRemoves the longest string containing only characters in characters (a space by default) from the start, end, or both ends (BOTH is the default) of string.trim ( [ LEADING | TRAILING | BOTH ] [ characters text ] FROM string text ) → texttrim(both ‘xyz’ from ‘yxTomxx’) → Tom
upperConverts the string to all upper case, according to the rules of the database’s locale.upper ( text ) → textupper(‘tom’) → TOM

Pattern Matching

LIKE & ILIKE

LIKE operator is supported by ClapDB, and the syntax is the same as PostgreSQL. it support the following wildcards:

  • _ : matches any single character
  • % : matches any sequence of characters

ILIKE is similar to LIKE but is case insensitive.

examples:

SELECT * FROM table WHERE column LIKE 'a%';
SELECT * FROM table WHERE column LIKE 'hello_';
SELECT * FROM table WHERE column LIKE 'a%b';

regex

Operators

PostgreSQL OperatorDescriptionExampleClapDB supportedClapDB will support in future release
~String matches regular expression, case sensitively’thomas’ ~ ‘t.*ma’
~*String matches regular expression, case insensitively’thomas’ ~* ‘T.*MA’
!~String does not match regular expression, case sensitively’thomas’ !~ ‘t.*ma’
!~*String does not match regular expression, case insensitively’thomas’ !~* ‘T.*MA’

pattern matching support PCRE (Perl Compatible Regular Expressions) syntax.

Functions

PostgreSQL FunctionDescriptionFormulaExampleClapDB supportedClapDB will support in future release
regexp_countThe regexp_count function counts the number of places where a regular expression pattern matches a string.regexp_count(string, pattern [, start [, flags ]]) -> integerregexp_count(‘ABCABCAXYaxy’, ‘A.‘) → 3
regexp_instrThe regexp_instr function returns the starting or ending position of the N’th match of a regular expression pattern to a string, or zero if there is no such match.regexp_instr(string, pattern [, start [, N [, endoption [, flags [, subexpr ]]]]]) -> integerregexp_instr(‘ABCABCAXYaxy’, ‘A.’, 1, 2) → 4
regexp_likeThe regexp_like function checks whether a match of a regular expression pattern occurs within a string, returning boolean true or false.regexp_like(string, pattern [, flags ]) → booleanregexp_like(‘ABCABCAXYaxy’, ‘A.‘) → true
regexp_matchesThe regexp_match function returns a text array of matching substring(s) within the first match of a regular expression pattern to a string.regexp_matches(string, pattern [, flags ]) → text[]regexp_matches(‘foobarbequebaz’, ‘bar.*que’) → {barbeque}
regexp_replaceThe regexp_replace function provides substitution of new text for substrings that match regular expression patterns.regexp_replace(string, pattern, replacement [, flags ]) → textregexp_replace(‘foobarbequebaz’, ‘bar.*que’, ‘123’) → foo123baz
regexp_substrThe regexp_substr function returns the substring that matches a regular expression pattern, or NULL if there is no match.regexp_substr(string, pattern [, start [, nth [, flags ]]]) → textregexp_substr(‘number of your street, town zip, FR’, ’[^,]+’, 1, 2) -> town zip

SIMILAR TO

not supported by ClapDB.