函數名稱 | 傳回型別 | 函數說明 | 用法樣本 | 樣本結果 |
ascii()
| int
| 擷取指定字串中第一段字元的 ASCII 碼值。 | ascii('x')
| 120
|
btrim([,])
| text
| 從字串的兩端移除指定的一組字元。如果未指定字元集合,則預設移除空白字元(如空格、定位字元等)。 | btrim('xyxtrimyyx', 'xyz')
| trim
|
chr(
| text
| 將指定的整數(假設該整數代表一段ASCII或擴充ASCII字元的編碼值)轉換成對應的字元。 | chr(65)
| A
|
concat([,[, ...] ])
| text
| 將兩個或更多個字串串連成一段字串。 | concat('abcde', 2, NULL, 22)
| abcde222
|
concat_ws(,[,[, ...] ])
| text
| 將多個字串使用指定的分隔字元 sep 串連成一段字串,並且允許在串連的字串之間插入一段自訂的分隔字元。 | concat_ws(',', 'abcde', 2, NULL, 22)
| abcde,2,22
|
convert(,,)
| bytea
| 將字串轉換為dest_encoding,原始編碼由src_encoding指定。 | convert('text_in_utf8', 'UTF8', 'LATIN1')
| 用Latin-1 encoding (ISO 8859-1) 表示的text_in_utf8 |
convert_from(,)
| text
| 將位元據(bytea 類型)轉換為文本字串,轉換時會使用指定的源字元編碼(src_encoding_name)。 | convert_from('text_in_utf8', 'UTF8')
| 用當前資料庫編碼錶示的text_in_utf8 |
convert_to(,)
| bytea
| 將文本字串轉換為位元據(bytea 類型),轉換時採用指定的目標字元編碼(dest_encoding_name)。 | convert_to('some text', 'UTF8')
| 用UTF8編碼錶達的some text |
decode(,)
| bytea
| 將十六進位字串(表示為文本)解碼為其二進位表示形式(bytea 類型)。 | decode('MTIzAAE=', 'base64')
| \x3132330001
|
encode(,)
| text
| 將位元據(bytea 類型)編碼為特定格式的文本字串。 | encode('123\000\001', 'base64')
| MTIzAAE=
|
format([,[, ...] ])
| text
| 格式化字串輸出。 | format('Hello %s, %1$s', 'World')
| Hello World, World
|
initcap()
| text
| 將字串中每個單詞的首字母轉換為大寫,而其餘字母轉換為小寫。 | initcap('hi THOMAS')
| Hi Thomas
|
left(,)
| text
| 從一段指定的字串(str)的開始位置提取指定數量(n)的字元。 | left('abcde', 2)
| ab
|
length()
| int
| 計算指定字串中字元的數量,包括空格和特殊字元。 | length('jose')
| 4
|
length(,)
| int
| 計算string在指定編碼中的字元數。 | length('jose', 'UTF8')
| 4
|
lpad(,[,])
| text
| 在字串的左側填充指定的字元直到達到指定的長度 | lpad('hi', 5, 'xy')
| xyxhi
|
ltrim([,])
| text
| 從字串的左側移除指定的字元。如果不指定字元集,則預設移除空白字元(如空格、定位字元、分行符號等)。 | ltrim('zzzytest', 'xyz')
| test
|
md5()
| text
| 計算輸入字串的MD5散列值。 | md5('abc')
| 900150983cd24fb0 d6963f7d28e17f72
|
parse_ident([,DEFAULT true ] )
| text[]
| 解析一段符合SQL標識符規則的字串,並將其分解成一個模式和一個對象名。 | parse_ident('"SomeSchema".someTable')
| {SomeSchema,sometable}
|
pg_client_encoding()
| name
| 擷取當前會話的用戶端字元編碼設定。 | pg_client_encoding()
| SQL_ASCII
|
quote_ident()
| text
| 將指定的字串轉換為一段可以在SQL語句中安全使用的標識符。 | quote_ident('Foo bar')
| "Foo bar"
|
quote_literal()
| text
| 強制轉換指定值為文本類型,並且用引號包圍。 | quote_literal(E'O\'Reilly')
| 'O''Reilly'
|
quote_literal(valueanyelement) | text
| 強制轉換指定值為文本類型,並且用引號包圍。 | quote_literal(42.5)
| '42.5'
|
quote_nullable()
| text
| 強制轉換指定值為文本類型,並且用引號包圍。如果參數為空白,則返回NULL。 | quote_nullable(NULL)
| NULL
|
quote_nullable()
| text
| 指定值可以為任何類型,並且用引號包圍。 | quote_nullable(42.5)
| '42.5'
|
regexp_match(,[,])
| text[]
| 執行Regex匹配。此函數在指定的字串中搜尋與指定模式比對的子串,並返回匹配的結果數組。如果有多個匹配項,每個匹配都會作為一個元素返回。如果沒有匹配項,則返回 NULL。 | regexp_match('foobarbequebaz', '(bar)(beque)')
| {bar,beque}
|
regexp_matches(,[,])
| setof text[]
| 執行Regex匹配。此函數在指定的字串中搜尋與指定模式比對的子串,並返回所有匹配的結果。 | regexp_matches('foobarbequebaz', 'ba.', 'g')
| {bar}
{baz}
(2 rows) |
regexp_replace(,,[,])
| text
| 替換匹配POSIXRegex的子串。 | regexp_replace('Thomas', '.[mN]a.', 'M')
| ThM
|
regexp_split_to_array(,[,])
| text[]
| 使用POSIXRegex作為分隔字元劃分字串。 | regexp_split_to_array('hello world', '\s+')
| {hello,world}
|
regexp_split_to_table(,[,])
| setof text
| 使用POSIXRegex作為分隔字元劃分字串。 | regexp_split_to_table('hello world', '\s+')
| hello
world
(2 rows) |
repeat(,))
| text
| 重複指定的字串指定的次數。 | repeat('Pg', 4)
| PgPgPgPg
|
replace(,,)
| text
| 在指定的字串中尋找指定的子串並替換為另一段指定的子串。 | replace('abcdefabcdef', 'cd', 'XX')
| abXXefabXXef
|
reverse()
| text
| 反轉指定字串中的字元順序。 | reverse('abcde')
| edcba
|
right(,)
| text
| 從指定的字串(str)中提取最右邊的n個字元。 | right('abcde', 2)
| de
|
rpad(,[,])
| text
| 在字串的右側填充指定的字元,直到達到指定的總長度。 | rpad('hi', 5, 'xy')
| hixyx
|
rtrim([,])
| text
| 刪除字串末尾的指定字元或空白字元。 | rtrim('testxxzx', 'xyz')
| test
|
split_part(,,)
| text
| 將字串按照指定的分隔字元分割。 | split_part('abc~@~def~@~ghi', '~@~', 2)
| def
|
strpos(,)
| int
| 尋找子字串 substring 在字串 string 中第一次出現的位置。 | strpos('high', 'ig')
| 2
|
substr(,[,])
| text
| 從原始字串中提取子串。 | substr('alphabet', 3, 2)
| ph
|
starts_with(,)
| bool
| 如果string以prefix開始則返回真。 | starts_with('alphabet', 'alph')
| t
|
to_ascii([,])
| text
| 將string從另一段編碼轉換到ASCII(只支援LATIN1、LATIN2、LATIN9和WIN1250編碼的轉換)。 | to_ascii('Karel')
| Karel
|
to_hex(or)
| text
| 將整數(integer)或大整數(bigint)類型的數值轉換為其對應的十六進位字串表示。 | to_hex(2147483647)
| 7fffffff
|
translate(,,)
| text
| 將字串中的某些字元替換為另一些字元。 | translate('12345', '143', 'ax')
| a2x5
|