Postgres function, postgres date function
1. Data restoration is first considered to be performed in the database, but it is not feasible. External applications are considered to be repaired through jdbc.
For example, profile_image_url and enlarge_image_url are fields returned by Weibo users. the former is Hangzhou // tp2.sinaimg.cn/1928431341/180/5621497369/1. If the latter's data is repaired, replace/50/with/180/and use the postgres character.FunctionSolution.
2. CommonFunction
2.1 common stringsFunctionList
Note: In the example on the next page, strings can all be replaced by fields in the Table. TestFunctionIt can be similar to select "char_length" ('string'); * The identifier is not commonly used.FunctionMost of them are substring, position, length, and replace, which are similar to CRUD of db.
Function: String | string
Note: String concatenation String connection operation
Example: 'post' | 'gresql' = PostgreSQL
Function: String | non-string or non-string | string
Description: String concatenation with one non-string input String and non-string type.
Example: 'value: '| 42 = Value: 42
Function: Bit_length (string)
Description: Number of bits in string calculates the Number of digits of a string.
Example: bit_length ('job') = 32
Function: Char_length (string) or character_length (string)
Description: Number of characters in string calculates the Number of characters in a string.
Example: char_length ('job') = 4
Same as length
Select "char_length" ('string'), "length" ('string'); res: 6 6
Function: Lower (string)
Description: Convert string to lower case converts the string to lowercase.
Example: select "lower" ('abc') = ABC
Function: Octet_length (string)
Description: Number of bytes in string calculates the Number of bytes of a string.
Example: octet_length ('job') = 4
Function: Overlay (string placing string from int [for int])
Note: Replace substring replaces the substring of any length in the string with the new string.
Example: overlay ('txxxxas 'placing' from 2 for 4) = 4
For example:
1.
Update t_sns_member set enlarge_image_url = overlay (profile_image_url placing '/180/' from position ('/50/' in profile_image_url) for 4) where enlarge_image_url =''
2. Do not use replacement. substring + position + | concatenate a new string.
Update t_sns_member set enlarge_image_url = substring (profile_image_url, 0, position ('/50/' in profile_image_url) | '/180/' | substring (profile_image_url, position ('/50/' in profile_image_url) + 4, char_length (profile_image_url) where enlarge_image_url = '';
Function: Position (substring in string)
Note: Location of specified position of the substring in a string
Example: position ('om 'in 'Thomas') = 3
Function: Substring (string [from int] [for int])
Description: Extract substring intercepts substrings of any length.
Example: substring ('Thomas 'from 2 for 3) = hom
Function: Substring (string from pattern)
Note: Extract substring matching POSIX regular expression. See Section 9.7 for more information on pattern matching. use regular expressions to intercept strings of any length.
Example: substring ('Thomas 'from'... $ ') = mas
Function: Substring (string from pattern for escape)
Note: Extract substring matching SQL regular expression. See Section 9.7 for more information on pattern matching. regular expressions are used to delete certain types of characters to obtain substrings.
Example: trim (both 'X' from 'xtomxx') = Tom
Function: Trim ([leading | trailing | both] [characters] from string)
Note: Remove the longest string containing only the characters (a space by default) from the start/end/both ends of the string to Remove as long as possible the start, end, or two types of characters, by default, spaces are removed. Of course, you can specify multiple strings to be deleted at the same time.
Example: trim (both 'X' from 'xtomxx') = Tom
Function: Upper (string)
Description: Convert string to uppercase converts a string to uppercase.
Example: upper ('Tom ') = tom
Function: Ascii (string)
Note: 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 a strictly ASCII character. obtains the asⅱ value of a character.
Example: ascii ('x') = 120
Function: Btrim (string text [, characters text])
Note: Remove the longest string consisting only of characters in characters (a space by default) from the start and end of string removes all specified characters on both sides of the string. Multiple characters can be specified at the same time.
Example: btrim ('xyxtrimyyx ', 'xy') = trim
Update property set memorial_no = btrim (memorial_no, '') where memorial_no like '%'
Or update property set memorial_no = trim (both ''from memorial_no) where memorial_no like '%'
Function: Chr (int)
Note: Character with the given code. for UTF8 the argument is treated as a Unicode code point. for other multibyte encodings the argument must designate a strictly ASCII character. the NULL (0) character is not allowed because text data types cannot store such bytes. obtains the character corresponding to an acⅱ value.
Example: chr (65) =
Function: Convert (string bytea, src_encoding name, dest_encoding name)
Note: 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. see Table 9-7 for available conversions. converts string encoding to specify the source and target encoding.
Example: convert ('text _ in_utf8', 'utf8', 'latin1') = text_in_utf8 represented in ISO 8859-1 encoding
Function: Convert_from (string bytea, src_encoding name)
Note: Convert string to the database encoding. the original encoding is specified by src_encoding. the string must be valid in this encoding. to convert the string encoding, you must specify the source encoding. The target encoding is the database encoding by default,
Example: convert_from ('text _ in_utf8', 'utf8') = text_in_utf8 represented in the current database encoding
Function: Convert_to (string text, dest_encoding name)
Note: Convert string to dest_encoding. Convert the string encoding. The source encoding specifies the encoding by default for the database. You must specify the target encoding,
Example: convert_to ('some text', 'utf8') = some text represented in the UTF8 encoding
Function: Decode (string text, type text)
Description: Decode binary data from string previusly encoded with encode. Parameter type is same as in encode. decodes strings of the specified type.
Example: decode ('tizaae = ', 'base64') = 123 \ 000 \ 001
Function: Encode (data bytea, type text)
Note: Encode binary data to different representation. supported types are: base64, hex, escape. escape merely outputs null bytes as \ 000 and doubles backslashes. in contrast to decode, the string is encoded according to the specified type.
Example: encode (E '2014 \ 000 \ 001', 'base64') = MTIzAAE =
Function: Initcap (string)
Note: Convert the first letter of each word to uppercase and the rest to lowercase. words are sequences of alphanumeric characters separated by non-alphanumeric characters. format all the words in the string. The first letter is in upper case, and the others are in lower case.
Example: initcap ('Hi THOMAS ') = hi Thomas
Function: Length (string)
Description: Number of characters in string indicates the length of a string.
Example: length ('job') = 4
Function: Length (stringbytea, encoding name)
Note: Number of characters in string in the given encoding. The string must be valid in this encoding. calculates the string length and specifies The encoding of the string.
Example: length ('job', 'utf8') = 4
*Function: Lpad (string text, length int [, fill text])
Note: Fill up the string to 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 ). to the left side of a string, you can automatically fill in the specified string to the left until it reaches the specified length. Multiple automatically filled characters can be specified at the same time.
Example: lpad ('hi', 5, 'xy') = xyxhi
Function: Ltrim (string text [, characters text])
Remove: Remove the longest string containing only characters from characters (a space by default) from the start of string to delete some characters on the left of the string. You can specify multiple characters to be deleted.
Example: trim
Function: Md5 (string)
Note: Calculates the MD5 hash of string, returning the result in hexadecimal encodes the string using md5.
Example: md5 ('abc') = 900150983cd24fb0 d6963f7d28e17f72
*Function: Pg_client_encoding ()
Note: The Current client encoding name is encoded by the pg client.
Example: pg_client_encoding () = SQL _ASCII
*Function: Quote_ident (string 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 wocould be case-folded ). embedded quotes are properly doubled. enclose a string with two quotation marks.
Example: quote_ident ('foo bar') = "Foo bar"
*Function: Quote_literal (string 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. single quotation marks are added to both sides of the string. If a single SQL-encoded single quotation mark is displayed in the string, two single quotation marks will be obtained by the table.
Example: quote_literal ('o \ 'Reilly ') = 'O' Reilly'
*Function: Quote_literal (value anyelement)
Note: Coerce the given value to text and then quote it as a literal. embedded single-quotes and backslashes are properly doubled. converts a value to a string with single quotation marks on both sides. If a single quotation mark appears in the middle of the value, it is expressed as two single quotation marks.
Example: quote_literal (42.5) = '42. 5'
Function: Regexp_matches (string text, pattern text [, flags text])
: Return all captured substrings resulting from matching a POSIX regular expression against the string. see Section 9.7.3 for more information. matches strings by regular expressions. If yes, the strings are displayed in the result array.
Example: regexp_matches ('foobarbequebaz', '(bar) (beque)') = {bar, beque}
Function: Regexp_replace (string text, pattern text, replacement text [, flags text])
Note: Replace substring (s) matching a POSIX regular expression. See Section 9.7.3 for more information. use regular expressions to Replace strings.
Example: regexp_replace ('Thomas ','. [mN] a. ', 'M') = ThM
*Function: Regexp_split_to_array (string text, pattern text [, flags text])
Description: Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. Use a regular expression to Split the string into arrays.
Example: regexp_split_to_array ('Hello world', e' \ s + ') = {hello, world}
*Function: Regexp_split_to_table (string text, pattern text [, flags text])
Note: Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. use regular expressions to Split strings into tables.
Example: regexp_split_to_table ('Hello world', e' \ s + ') =
Hello
World
(2 rows)
*Function: Repeat (string text, number int)
Note: Repeat string the specified number of times repeats a specified number of times of a string.
Example: repeat ('pg ', 4) = PgPgPgPg
Function: Replace (string text, from text, to text)
Note: Replace all occurrences in string of substring from with substring to Replace a substring of a character with another substring.
Example: ('abcdefabcdef ', 'cd', 'xx') = abXXefabXXef
Like overlay,
Select overlay ('HTTP: // tp2.sinaimg.cn/1928431341/50/5621497369/1'placing'/180/'from position ('/50/'in' http: // fill) for 4), replace ('HTTP: // tp2.sinaimg.cn/1928431341/50/5621497112/1', '/50/', '/180 /');
*Function: Rpad (string text, length int [, fill text])
Note: Fill 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. pads The string with the specified string.
Example: rpad ('hi', 5, 'xy') = hixyx
Function: Rtrim (string text [, characters text])
Remove: Remove the longest string containing only characters from characters (a space by default) from the end of string
Removes the specified character on the right of the string.
Example: rtrim ('trimxxxx', 'x') = trim
*Function: Split_part (string text, delimiter text, field int)
Description: Split string on delimiter and return the given field (counting from one) splits the string by the specified sub-string and returns the value at the specified position.
Example: split_part ('abc ~ @~ Def ~ @~ Ghi ','~ @~ ', 2) = def
Function: Strpos (string, substring)
Location: Location of specified substring (same as position (substring in string), but note the reversed argument order) specifies the position of the string in the target string
Example: strpos ('high', 'ig ') = 2
Similar to position
Select strpos ('HTTP: // tp2.sinaimg.cn/1928431341/50/5621497131/1', '/50/'), position ('/50/' in 'HTTP: // region ');
Function: Substr (string, from [, count])
Note: Extract substring (same as substring (string from for count) Intercepts substrings.
Example: substr ('alphabet ', 3, 2) = ph
*Function: To_ascii (string text [, encoding text])
Note: Convert string to ASCII from another encoding (only supports conversion from LATIN1, LATIN2, LATIN9, and WIN1250 encodings) converts a string to an ascii encoded string.
Example: to_ascii ('karel ') = Karel
*Function: To_hex (number int or bigint)
Note: Convert number to its equivalent hexadecimal representation encodes the value in hexadecimal notation.
Example: to_hex (2147483647) = 7 fffffff
*Function: Translate (string text, from text, to text)
Note: Any character in string that matches a character in the from set is replaced by the corresponding character in the to set replaces some matching characters in the string with the specified string, you can specify multiple target and source characters at the same time.
Example: translate ('20140901', '14', 'ax ') = a23x5