String functions and operators provided by GaussDB(DWS) are for concatenating strings with each other, concatenating strings with non-strings, and matching the patterns of strings.
Description: Specifies the number of bits occupied by a string.
Return type: int
For example:
1 2 3 4 5 | SELECT bit_length('world'); bit_length ------------ 40 (1 row) |
Description: Removes the longest string consisting only of characters in characters (a space by default) from the start and end of string.
Return type: text
For example:
1 2 3 4 5 | SELECT btrim('sring' , 'ing'); btrim ------- sr (1 row) |
Description: Number of characters in a string
Return type: int
For example:
1 2 3 4 5 | SELECT char_length('hello'); char_length ------------- 5 (1 row) |
Description: FROM int indicates the start position of the replacement in the first string. for int indicates the number of characters replaced in the first string.
Return type: int
For example:
1 2 3 4 5 | SELECT instr( 'abcdabcdabcd', 'bcd', 2, 2 ); instr ------- 6 (1 row) |
Description: Obtains the number of bytes of a specified string.
Return type: int
For example:
1 2 3 4 5 | SELECT lengthb('hello'); lengthb --------- 5 (1 row) |
Description: Returns first n characters in the string.
Return type: text
For example:
1 2 3 4 5 | SELECT left('abcde', 2); left ------ ab (1 row) |
Description: Number of characters in string in the given encoding. The string must be valid in this encoding.
Return type: int
For example:
1 2 3 4 5 | SELECT length('jose', 'UTF8'); length -------- 4 (1 row) |
Description: Fills up the string to the specified length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated (on the right).
Return type: text
For example:
1 2 3 4 5 | SELECT lpad('hi', 5, 'xyza'); lpad ------- xyzhi (1 row) |
Description: Number of bytes in a string
Return type: int
For example:
1 2 3 4 5 | SELECT octet_length('jose'); octet_length -------------- 4 (1 row) |
Description: Replaces substring. FROM int indicates the start position of the replacement in the first string. for int indicates the number of characters replaced in the first string.
Return type: text
For example:
1 2 3 4 5 | SELECT overlay('hello' placing 'world' from 2 for 3 ); overlay --------- hworldo (1 row) |
Description: Location of specified substring
Return type: int
For example:
1 2 3 4 5 | SELECT position('ing' in 'string'); position ---------- 4 (1 row) |
Description: Current client encoding name
Return type: name
For example:
1 2 3 4 5 | SELECT pg_client_encoding(); pg_client_encoding -------------------- UTF8 (1 row) |
Description: Returns the given string suitably quoted to be used as an identifier in an SQL statement string (quotation marks are used as required). Quotes are added only if necessary (that is, if the string contains non-identifier characters or would be case-folded). Embedded quotes are properly doubled.
Return type: text
For example:
1 2 3 4 5 | SELECT quote_ident('hello world'); quote_ident -------------- "hello world" (1 row) |
Description: Returns the given string suitably quoted to be used as a string literal in an SQL statement string (quotation marks are used as required).
Return type: text
For example:
1 2 3 4 5 | SELECT quote_literal('hello'); quote_literal --------------- 'hello' (1 row) |
If command similar to the following exists, text will be escaped.
1 2 3 4 5 | SELECT quote_literal(E'O\'hello'); quote_literal --------------- 'O''hello' (1 row) |
If command similar to the following exists, backslash will be properly doubled.
1 2 3 4 5 | SELECT quote_literal('O\hello'); quote_literal --------------- E'O\\hello' (1 row) |
If the parameter is null, return NULL. If the parameter may be null, you are advised to use quote_nullable.
1 2 3 4 5 | SELECT quote_literal(NULL); quote_literal --------------- (1 row) |
Description: Coerces the given value to text and then quotes it as a literal.
Return type: text
For example:
1 2 3 4 5 | SELECT quote_literal(42.5); quote_literal --------------- '42.5' (1 row) |
If command similar to the following exists, the given value will be escaped.
1 2 3 4 5 | SELECT quote_literal(E'O\'42.5'); quote_literal --------------- '0''42.5' (1 row) |
If command similar to the following exists, backslash will be properly doubled.
1 2 3 4 5 | SELECT quote_literal('O\42.5'); quote_literal --------------- E'O\\42.5' (1 row) |
Description: Returns the given string suitably quoted to be used as a string literal in an SQL statement string (quotation marks are used as required).
Return type: text
For example:
1 2 3 4 5 | SELECT quote_nullable('hello'); quote_nullable ---------------- 'hello' (1 row) |
If command similar to the following exists, text will be escaped.
1 2 3 4 5 | SELECT quote_nullable(E'O\'hello'); quote_nullable ---------------- 'O''hello' (1 row) |
If command similar to the following exists, backslash will be properly doubled.
1 2 3 4 5 | SELECT quote_nullable('O\hello'); quote_nullable ---------------- E'O\\hello' (1 row) |
If the parameter is null, return NULL.
1 2 3 4 5 | SELECT quote_nullable(NULL); quote_nullable ---------------- NULL (1 row) |
Description: Converts the given value to text and then quotes it as a literal.
Return type: text
For example:
1 2 3 4 5 | SELECT quote_nullable(42.5); quote_nullable ---------------- '42.5' (1 row) |
If command similar to the following exists, the given value will be escaped.
1 2 3 4 5 | SELECT quote_nullable(E'O\'42.5'); quote_nullable ---------------- 'O''42.5' (1 row) |
If command similar to the following exists, backslash will be properly doubled.
1 2 3 4 5 | SELECT quote_nullable('O\42.5'); quote_nullable ---------------- E'O\\42.5' (1 row) |
If the parameter is null, return NULL.
1 2 3 4 5 | SELECT quote_nullable(NULL); quote_nullable ---------------- NULL (1 row) |
Description: Extracts a substring. from int indicates the start position of the truncation. for int indicates the number of characters truncated.
Return type: text
For example:
1 2 3 4 5 | SELECT substring('Thomas' from 2 for 3); substring ----------- hom (1 row) |
Description: Extracts substring matching POSIX regular expression. It returns the text that matches the pattern. If no match record is found, a null value is returned.
Return type: text
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | SELECT substring('Thomas' from '...$'); substring ----------- mas (1 row) SELECT substring('foobar' from 'o(.)b'); result -------- o (1 row) SELECT substring('foobar' from '(o(.)b)'); result -------- oob (1 row) |
If the POSIX pattern contains any parentheses, the portion of the text that matched the first parenthesized sub-expression (the one whose left parenthesis comes first) is returned. You can put parentheses around the whole expression if you want to use parentheses within it without triggering this exception.
Description: Extracts substring matching SQL regular expression. The specified pattern must match the entire data string, or else the function fails and returns null. To indicate the part of the pattern that should be returned on success, the pattern must contain two occurrences of the escape character followed by a double quote ("). The text matching the portion of the pattern between these markers is returned.
Return type: text
For example:
1 2 3 4 5 | SELECT substring('Thomas' from '%#"o_a#"_' for '#'); substring ----------- oma (1 row) |
Description: Indicates the string concatenation functions.
Return type: raw
For example:
1 2 3 4 5 | SELECT rawcat('ab','cd'); rawcat -------- ABCD (1 row) |
Description: Indicates the mode matching function of a regular expression.
Return type: bool
For example:
1 2 3 4 5 | SELECT regexp_like('str','[ac]'); regexp_like ------------- f (1 row) |
Description: Extracts substrings from a regular expression. Its function is similar to substr. When a regular expression contains multiple parallel brackets, it also needs to be processed.
Return type: text
For example:
1 2 3 4 5 | SELECT regexp_substr('str','[ac]'); regexp_substr --------------- (1 row) |
Description: Returns all captured substrings resulting from matching a POSIX regular expression against the string. If the pattern does not match, the function returns no rows. If the pattern contains no parenthesized sub-expressions, then each row returned is a single-element text array containing the substring matching the whole pattern. If the pattern contains parenthesized sub-expressions, the function returns a text array whose nth element is the substring matching the nth parenthesized sub-expression of the pattern.
The optional flags argument contains zero or multiple single-letter flags that change function behavior. i indicates that the matching is not related to uppercase and lowercase. g indicates that each matching substring is replaced, instead of replacing only the first one.
If the last parameter is provided but the parameter value is an empty string ('') and the SQL compatibility mode of the database is set to ORA, the returned result is an empty set. This is because the ORA compatible mode treats the empty string ('') as NULL. To resolve this problem, you can:
Return type: setof text[]
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | SELECT regexp_matches('foobarbequebaz', '(bar)(beque)'); regexp_matches ---------------- {bar,beque} (1 row) SELECT regexp_matches('foobarbequebaz', 'barbeque'); regexp_matches ---------------- {barbeque} (1 row) SELECT regexp_matches('foobarbequebazilbarfbonk', '(b[^b]+)(b[^b]+)', 'g'); result -------------- {bar,beque} {bazil,barf} (2 rows) |
Description: Splits string using a POSIX regular expression as the delimiter. The regexp_split_to_array function behaves the same as regexp_split_to_table, except that regexp_split_to_array returns its result as an array of text.
Return type: text[]
For example:
1 2 3 4 5 | SELECT regexp_split_to_array('hello world', E'\\s+'); regexp_split_to_array ----------------------- {hello,world} (1 row) |
Description: Splits string using a POSIX regular expression as the delimiter. If there is no match to the pattern, the function returns the string. If there is at least one match, for each match it returns the text from the end of the last match (or the beginning of the string) to the beginning of the match. When there are no more matches, it returns the text from the end of the last match to the end of the string.
The flags parameter is a text string containing zero or more single-letter flags that change the function's behavior. i indicates that the matching is not related to uppercase and lowercase. g indicates that each matching substring is replaced, instead of replacing only the first one.
Return type: setof text
For example:
1 2 3 4 5 6 | SELECT regexp_split_to_table('hello world', E'\\s+'); regexp_split_to_table ----------------------- hello world (2 rows) |
Return type: string repeated for number times
For example:
1 2 3 4 5 | SELECT repeat('Pg', 4); repeat ---------- PgPgPgPg (1 row) |
Description: Replaces all occurrences in string of substring from with substring to.
Return type: text
For example:
1 2 3 4 5 | SELECT replace('abcdefabcdef', 'cd', 'XXX'); replace ---------------- abXXXefabXXXef (1 row) |
Description: Returns reversed string.
Return type: text
For example:
1 2 3 4 5 | SELECT reverse('abcde'); reverse --------- edcba (1 row) |
Description: Returns the last n characters in the string.
Return type: text
For example:
1 2 3 4 5 6 7 8 9 10 11 | SELECT right('abcde', 2); right ------- de (1 row) SELECT right('abcde', -2); right ------- cde (1 row) |
Description: Fills up the string to length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated.
Return type: text
For example:
1 2 3 4 5 | SELECT rpad('hi', 5, 'xy'); rpad ------- hixyx (1 row) |
Description: Removes the longest string containing only characters from characters (a space by default) from the end of string.
Return type: text
For example:
1 2 3 4 5 | SELECT rtrim('trimxxxx', 'x'); rtrim ------- trim (1 row) |
Description: Obtains and returns the parameter values of a specified namespace.
Return type: text
For example:
1 2 3 4 5 | SELECT SYS_CONTEXT ( 'postgres' , 'archive_mode'); sys_context ------------- (1 row) |
Description: Extracts a substring. The first int indicates the start position of the subtraction. The second int indicates the number of characters subtracted.
Return type: text
For example:
1 2 3 4 5 | SELECT substrb('string',2,3); substrb --------- tri (1 row) |
Description: Extracts a substring. int indicates the start position of the subtraction.
Return type: text
For example:
1 2 3 4 5 | SELECT substrb('string',2); substrb --------- tring (1 row) |
Description: Concatenates strings.
Return type: text
For example:
1 2 3 4 5 | SELECT 'MPP'||'DB' AS RESULT; result -------- MPPDB (1 row) |
Description: Concatenates strings and non-strings.
Return type: text
For example:
1 2 3 4 5 | SELECT 'Value: '||42 AS RESULT; result ----------- Value: 42 (1 row) |
Description: Splits string on delimiter and returns the fieldth column (counting from text of the first appeared delimiter).
Return type: text
For example:
1 2 3 4 5 | SELECT split_part('abc~@~def~@~ghi', '~@~', 2); split_part ------------ def (1 row) |
Description: Specifies the position of a substring. It is the same as position(substring in string). However, the parameter sequences of them are reversed.
Return type: int
For example:
1 2 3 4 5 | SELECT strpos('source', 'rc'); strpos -------- 4 (1 row) |
Description: Converts number to a hexadecimal expression.
Return type: text
For example:
1 2 3 4 5 | SELECT to_hex(2147483647); to_hex ---------- 7fffffff (1 row) |
Description: Any character in string that matches a character in the from set is replaced by the corresponding character in the to set. If from is longer than to, extra characters occurred in from are removed.
Return type: text
For example:
1 2 3 4 5 | SELECT translate('12345', '143', 'ax'); translate ----------- a2x5 (1 row) |
Description: Obtains the number of characters in a string.
Return type: integer
For example:
1 2 3 4 5 | SELECT length('abcd'); length -------- 4 (1 row) |
Description: Obtains the number of characters in a string. The value depends on character sets (GBK and UTF8).
Return type: integer
For example:
1 2 3 4 5 | SELECT lengthb('hello'); lengthb --------- 5 (1 row) |
Extracts substrings from a string.
from indicates the start position of the extraction.
Return type: varchar
For example:
If the value of from is positive:
1 2 3 4 5 | SELECT substr('ABCDEF',2); substr -------- BCDEF (1 row) |
If the value of from is negative:
1 2 3 4 5 | SELECT substr('ABCDEF',-2); substr -------- EF (1 row) |
Extracts substrings from a string.
from indicates the start position of the extraction.
"count" indicates the length of the extracted substring.
Return type: varchar
For example:
If the value of from is positive:
1 2 3 4 5 | SELECT substr('ABCDEF',2,2); substr -------- BC (1 row) |
If the value of from is negative:
1 2 3 4 5 | SELECT substr('ABCDEF',-3,2); substr -------- DE (1 row) |
Description: The functionality of this function is the same as that of SUBSTR(string,from). However, the calculation unit is byte.
Return type: bytea
For example:
1 2 3 4 5 | SELECT substrb('ABCDEF',-2); substrb --------- EF (1 row) |
Description: The functionality of this function is the same as that of SUBSTR(string,from,count). However, the calculation unit is byte.
Return type: bytea
For example:
1 2 3 4 5 | SELECT substrb('ABCDEF',2,2); substrb --------- BC (1 row) |
Description: Removes the longest string containing only the characters (a space by default) from the start/end/both ends of the string.
Return type: varchar
For example:
1 2 3 4 5 | SELECT trim(BOTH 'x' FROM 'xTomxx'); btrim ------- Tom (1 row) |
1 2 3 4 5 | SELECT trim(LEADING 'x' FROM 'xTomxx'); ltrim ------- Tomxx (1 row) |
1 2 3 4 5 | SELECT trim(TRAILING 'x' FROM 'xTomxx'); rtrim ------- xTom (1 row) |
Description: Removes the longest string containing only characters from characters (a space by default) from the end of string.
Return type: varchar
For example:
1 2 3 4 5 | SELECT rtrim('TRIMxxxx','x'); rtrim ------- TRIM (1 row) |
Description: Removes the longest string containing only characters from characters (a space by default) from the start of string.
Return type: varchar
For example:
1 2 3 4 5 | SELECT ltrim('xxxxTRIM','x'); ltrim ------- TRIM (1 row) |
Description: Converts the string into the uppercase.
Return type: varchar
For example:
1 2 3 4 5 | SELECT upper('tom'); upper ------- TOM (1 row) |
Description: Converts the string into the lowercase.
Return type: varchar
For example:
1 2 3 4 5 | SELECT lower('TOM'); lower ------- tom (1 row) |
Description: Fills up the string to length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated.
length in GaussDB(DWS) indicates the character length. One Chinese character is counted as one character.
Return type: varchar
For example:
1 2 3 4 5 | SELECT rpad('hi',5,'xyza'); rpad ------- hixyz (1 row) |
1 2 3 4 5 | SELECT rpad('hi',5,'abcdefg'); rpad ------- hiabc (1 row) |
Description: Queries and returns the value of the substring position that occurs the occurrence (first by default) times from the position (1 by default) in the string.
In this function, the calculation unit is character. One Chinese character is one character.
Return type: integer
For example:
1 2 3 4 5 | SELECT instr('corporate floor','or', 3); instr ------- 5 (1 row) |
1 2 3 4 5 | SELECT instr('corporate floor','or',-3,2); instr ------- 2 (1 row) |
Description: The first letter of each word in the string is converted into the uppercase and the other letters are converted into the lowercase.
Return type: text
For example:
1 2 3 4 5 | SELECT initcap('hi THOMAS'); initcap ----------- Hi Thomas (1 row) |
Description: Indicates the ASCII code of the first character in the string.
Return type: integer
For example:
1 2 3 4 5 | SELECT ascii('xyz'); ascii ------- 120 (1 row) |
Description: Replaces all search-string in the string with replacement_string.
Return type: varchar
For example:
1 2 3 4 5 | SELECT replace('jack and jue','j','bl'); replace ---------------- black and blue (1 row) |
Description: Adds a series of repeat_string (a space by default) on the left of the string to generate a new string with the total length of n.
If the length of the string is longer than the specified length, the function truncates the string and returns the substrings with the specified length.
Return type: varchar
For example:
1 2 3 4 5 | SELECT lpad('PAGE 1',15,'*.'); lpad ----------------- *.*.*.*.*PAGE 1 (1 row) |
1 2 3 4 5 | SELECT lpad('hello world',5,'abcd'); lpad ------- hello (1 row) |
Description: Connects str1 and str2 and returns the string.
Return type: varchar
For example:
1 2 3 4 5 | SELECT concat('Hello', ' World!'); concat -------------- Hello World! (1 row) |
Description: Specifies the character of the ASCII code.
Return type: varchar
For example:
1 2 3 4 5 | SELECT chr(65); chr ----- A (1 row) |
Description: Extracts substrings from a regular expression.
Return type: varchar
For example:
1 2 3 4 5 | SELECT regexp_substr('500 Hello World, Redwood Shores, CA', ',[^,]+,') "REGEXPR_SUBSTR"; REGEXPR_SUBSTR ------------------- , Redwood Shores, (1 row) |
Description: Replaces substring matching POSIX regular expression. The source string is returned unchanged if there is no match to the pattern. If there is a match, the source string is returned with the replacement string substituted for the matching substring.
The replacement string can contain \n, where n is 1 through 9, to indicate that the source substring matching the nth parenthesized sub-expression of the pattern should be inserted, and it can contain \& to indicate that the substring matching the entire pattern should be inserted.
The optional flags argument contains zero or multiple single-letter flags that change function behavior. The following table lists the options of the flags argument.
Option |
Description |
---|---|
g |
Replace all the matched substrings. (By default, only the first matched substring is replaced.) |
B |
Preferentially use the boost regex regular expression library and its regular expression syntax. By default, the Henry Spencer's regular expression library and its regular expression syntax are used. In the following cases, the Henry Spencer's regular expression library and its regular expression syntax will be used even if this option is specified:
|
b |
Use POSIX Basic Regular Expressions (BREs) for matching. |
c |
Case-sensitive matching |
e |
Use POSIX Extended Regular Expressions (EREs) for matching. If neither b nor e is specified and the Henry Spencer's regular expression library is used, Advanced Regular Expressions (AREs), similar to Perl Compatible Regular Expressions (PCREs), are used for matching; if neither b nor e is specified and the boost regex regular expression library is used, PCREs are used for matching. |
i |
Case-insensitive matching |
m |
Line feed-sensitive matching, which has the same meaning as option n |
n |
Line feed-sensitive matching. When this option takes effect, the line separator affects the matching of metacharacters (., ^, $, and [^). |
p |
Partial line feed-sensitive matching. When this option takes effect, the line separator affects the matching of metacharacters (. and [^). |
q |
Reset the regular expression to a text string enclosed in double quotation marks ("") and consisting of only common characters. |
s |
Non-line feed-sensitive matching |
t |
Compact syntax (default). When this option takes effect, all characters matter. |
w |
Reverse partial line feed-sensitive matching. When this option takes effect, the line separator affects the matching of metacharacters (^ and $). |
x |
Extended syntax In contrast to the compact syntax, whitespace characters in regular expressions are ignored in the extended syntax. Whitespace characters include spaces, horizontal tabs, new lines, and any other characters in the space character table. |
Return type: varchar
For example:
1 2 3 4 5 6 7 8 9 10 | SELECT regexp_replace('Thomas', '.[mN]a.', 'M'); regexp_replace ---------------- ThM (1 row) SELECT regexp_replace('foobarbaz','b(..)', E'X\\1Y', 'g') AS RESULT; result ------------- fooXarYXazY (1 row) |
Description: The first parameter is used as the separator, which is associated with all following parameters.
Return type: text
For example:
1 2 3 4 5 | SELECT concat_ws(',', 'ABCDE', 2, NULL, 22); concat_ws ------------ ABCDE,2,22 (1 row) |
Description: Converts the bytea string to dest_encoding. src_encoding specifies the source code encoding. The string must be valid in this encoding.
Return type: bytea
For example:
1 2 3 4 5 | SELECT convert('text_in_utf8', 'UTF8', 'GBK'); convert ---------------------------- \x746578745f696e5f75746638 (1 row) |
If the rule for converting between source to target encoding (for example, GBK and LATIN1) does not exist, the string is returned without conversion. See the pg_conversion system catalog for details.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | show server_encoding; server_encoding ----------------- LATIN1 (1 row) SELECT convert_from('some text', 'GBK'); convert_from -------------- some text (1 row) db_latin1=# SELECT convert_to('some text', 'GBK'); convert_to ---------------------- \x736f6d652074657874 (1 row) db_latin1=# SELECT convert('some text', 'GBK', 'LATIN1'); convert ---------------------- \x736f6d652074657874 (1 row) |
Description: Converts the long bytea using the coding mode of the database.
src_encoding specifies the source code encoding. The string must be valid in this encoding.
Return type: text
For example:
1 2 3 4 5 6 7 8 9 10 | SELECT convert_from('text_in_utf8', 'UTF8'); convert_from -------------- text_in_utf8 (1 row) SELECT convert_from('\x6461746162617365','gbk'); convert_from -------------- database (1 row) |
Description: Converts string to dest_encoding.
Return type: bytea
For example:
1 2 3 4 5 6 7 8 9 10 | SELECT convert_to('some text', 'UTF8'); convert_to ---------------------- \x736f6d652074657874 (1 row) SELECT convert_to('database', 'gbk'); convert_to -------------------- \x6461746162617365 (1 row) |
Description: Pattern matching function
If the pattern does not include a percentage sign (%) or an underscore (_), this mode represents itself only. In this case, the behavior of LIKE is the same as the equal operator. The underscore (_) in the pattern matches any single character while one percentage sign (%) matches no or multiple characters.
To match with underscores (_) or percent signs (%), corresponding characters in pattern must lead escape characters. The default escape character is a backward slash (\) and can be specified using the ESCAPE clause. To match with escape characters, enter two escape characters.
Return type: boolean
For example:
1 2 3 4 5 | SELECT 'AA_BBCC' LIKE '%A@_B%' ESCAPE '@' AS RESULT; result -------- t (1 row) |
1 2 3 4 5 | SELECT 'AA_BBCC' LIKE '%A@_B%' AS RESULT; result -------- f (1 row) |
1 2 3 4 5 | SELECT 'AA@_BBCC' LIKE '%A@_B%' AS RESULT; result -------- t (1 row) |
Description: Indicates the mode matching function of a regular expression.
source_string indicates the source string and pattern indicates the matching pattern of the regular expression. match_parameter indicates the matching items and the values are as follows:
If match_parameter is ignored, case-sensitive is enabled by default, "." is not matched with a linefeed, and source_string is regarded as a single row.
Return type: boolean
For example:
1 2 3 4 5 | SELECT regexp_like('ABC', '[A-Z]'); regexp_like ------------- t (1 row) |
1 2 3 4 5 | SELECT regexp_like('ABC', '[D-Z]'); regexp_like ------------- f (1 row) |
1 2 3 4 5 | SELECT regexp_like('ABC', '[A-Z]','i'); regexp_like ------------- t (1 row) |
1 2 3 4 5 | SELECT regexp_like('ABC', '[A-Z]'); regexp_like ------------- t (1 row) |
Description: Formats a string.
Return type: text
For example:
1 2 3 4 5 | SELECT format('Hello %s, %1$s', 'World'); format -------------------- Hello World, World (1 row) |
Description: Encrypts a string in MD5 mode and returns a value in hexadecimal form.
MD5 is insecure and is not recommended.
Return type: text
For example:
1 2 3 4 5 | SELECT md5('ABC'); md5 ---------------------------------- 902fbdd2b1df0c4f70b4a5d23525e932 (1 row) |
Description: Decodes binary data from textual representation.
Return type: bytea
For example:
1 2 3 4 5 6 7 8 9 10 11 | SELECT decode('ZGF0YWJhc2U=', 'base64'); decode -------------- \x6461746162617365 (1 row) SELECT convert_from('\x6461746162617365','utf-8'); convert_from -------------- database (1 row) |
Description: Encodes binary data into a textual representation.
Return type: text
For example:
1 2 3 4 5 | SELECT encode('database', 'base64'); encode ---------- ZGF0YWJhc2U= (1 row) |