Jump to: navigation, search

Postgresql String Functions

From w3cyberlearnings
# Function Return Type Description
1 string concate text string concatenation
2 bit_length int Number of bits in string
3 char_length int Number of characters in string
4 character_length int Number of characters in string (The same as char_length())
5 lower text Convert string to lower case
6 octet_length int Number of bytes in string
7 overlay text Replace substring
8 position int Location of specified substring
9 substring text Extract substring and this function is also support the POSIX and SQL regular expression.
10 trim text Remove the longest string containing only the characters (a space by default) from the start/end/both ends of the string
11 upper text Convert string to upper case
12 ascii int ASCII code of the first character of the argument. For UTF8 returns the Unicode code point of the character. For other multibyte encodings, the argument must be an ASCII character
13 btrim text Remove the longest string consisting only of characters in characters (a space by default) from the start and end of string
14 chr text Character with the given code. For UTF8 the argument is treated as a Unicode code point. For other multibyte encodings the argument must designate an ASCII character. The NULL (0) character is not allowed because text data types cannot store such bytes.
15 concat text Concatenate all arguments. NULL arguments are ignored.
16 concat_ws text Concatenate all but first arguments with separators. The first parameter is used as a separator. NULL arguments are ignored.
17 convert bytea Convert string to dest_encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding. Conversions can be defined by CREATE CONVERSION. Also there are some predefined conversions.
18 convert_from text Convert string to the database encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding.
19 convert_to bytea Convert string to dest_encoding.
20 decode bytea Decode binary data from textual representation in string. Options for format are same as in encode.
21 encode text Encode binary data into a textual representation. Supported formats are: base64, hex, escape. escape merely outputs null bytes as \000 and doubles backslashes.
22 format text Format a string. This function is similar to the C function sprintf; but only the following conversion specifications are recognized: %s interpolates the corresponding argument as a string; %I escapes its argument as an SQL identifier; %L escapes its argument as an SQL literal; %% outputs a literal %. A conversion can reference an explicit parameter position by preceding the conversion specifier with n$, where n is the argument position.
23 initcap text Convert the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters.
24 left text n| characters.
25 length int Number of characters in string
26 lpad text Fill up 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).
27 ltrim text Remove the longest string containing only characters from characters (a space by default) from the start of string
28 md5 text Calculates the MD5 hash of string, returning the result in hexadecimal
29 pg_client_encoding name Current client encoding name
30 quote_ident text Return the given string suitably quoted to be used as an identifier in an SQL statement string. Quotes are added only if necessary (i.e., if the string contains non-identifier characters or would be case-folded). Embedded quotes are properly doubled.
31 quote_literal text Return the given string suitably quoted to be used as a string literal in an SQL statement string. Embedded single-quotes and backslashes are properly doubled. Note that quote_literal returns null on null input; if the argument might be null, quote_nullable is often more suitable.
32 quote_literal text Coerce the given value to text and then quote it as a literal. Embedded single-quotes and backslashes are properly doubled.
33 quote_nullable text Return the given string suitably quoted to be used as a string literal in an SQL statement string; or, if the argument is null, return NULL. Embedded single-quotes and backslashes are properly doubled.
34 regexp_matches setof text[] Return all captured substrings resulting from matching a POSIX regular expression against the string.
35 regexp_replace text Replace substring(s) matching a POSIX regular expression. See Section 9.7.3 for more information.
36 regexp_split_to_array text[] Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information.
37 regexp_split_to_table setof text Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information.
38 repeat text Repeat string the specified number of times
39 replace text Replace all occurrences in string of substring from with substring to
40 reverse text Return reversed string.
41 right text n| characters.
42 rpad text Fill up 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.
43 rtrim text Remove the longest string containing only characters from characters (a space by default) from the end of string
44 split_part text Split string on delimiter and return the given field (counting from one)
45 strpos int Location of specified substring (same as position(substring in string), but note the reversed argument order)
46 substr text Extract substring (same as substring(string from from for count))
47 to_ascii text Convert string to ASCII from another encoding (only supports conversion from LATIN1, LATIN2, LATIN9, and WIN1250 encodings)
48 to_hex text Convert number to its equivalent hexadecimal representation
49 translate text 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, occurrences of the extra characters in from are removed.

Related Links

Navigation
Web
SQL
MISC
References