<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} tt {mso-style-unhide:no; mso-ansi-font-size:12.0pt; mso-bidi-font-size:12.0pt; font-family:宋体; mso-ascii-font-family:宋体; mso-fareast-font-family:宋体; mso-hansi-font-family:宋体; mso-bidi-font-family:宋体;} span.optional {mso-style-name:optional; mso-style-unhide:no;} span.acronym {mso-style-name:acronym; mso-style-unhide:no;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->
函数 | 返回类型 | 描述 | 例子 | 结果 |
string || string | text | 字串连接 | 'Post' || 'greSQL' | PostgreSQL |
bit_length( string ) | integer | 字串里二进制位的个数 | bit_length('jose') | 32 |
char_length( string ) 或 character_length( string ) | integer | 字串中的字符个数 | char_length('jose') | 4 |
convert( string using conversion_name ) | text | 使用指定的转换名字改变编码。转换可以通过 CREATE CONVERSION 定义。当然系统里有一些预定义的转换名字。参阅 Table 9-8 获取可用的转换名。 | convert('PostgreSQL' | Unicode (UTF-8) 编码的 'PostgreSQL' |
lower( string ) | text | 把字串转化为小写 | lower('TOM') | tom |
octet_length( string ) | integer | 字串中的字节数 | octet_length('jose') | 4 |
position( substring in string ) | integer | 声明的子字串的位置 | position('om' in 'Thomas') | 3 |
overlay( string placing string from integer [ for integer ]) | text | 替换子字串 | overlay('Txxxxas' placing 'hom' from 2 for 4) | Thomas |
position( substring in string ) | integer | 指定的子字串的位置 | position('om' in 'Thomas') | 3 |
substring ( string [from integer ] [for integer ]) | text | 抽取子字串 | substring('Thomas' from 2 for 3) | hom |
substring( string from pattern ) | text | 抽取匹配 POSIX 正则表达式的子字串 | substring('Thomas' from '...$') | mas |
substring ( string from pattern for escape ) | text | 抽取匹配 SQL 正则表达式的子字串 | substring('Thomas' from '%#"o_a#"_' for '#') | oma |
trim([ leading | trailing | both ] [ characters ] from string ) | text | 从字串 string 的 开头 / 结尾 / 两边 / 删除只包含 characters (缺省是一个空白)的最长的字串。 | trim(both 'x' from 'xTomxx') | Tom |
upper( string ) | text | 把字串转化为大写。 | upper('tom') | TOM |
|
|
|
|
|
ascii(text) | integer | 参数第一 | ascii('x') | 120 |
btrim | text | 从 string | btrim | trim |
chr(integer) | text | 给出 ASCII 码的字符 | chr(65) | A |
convert(string text, [src_encoding name,] dest_encoding name) | text | 把字串转换为 dest_encoding . 原来的编码是用 src_encoding 声明的 . 如果省略了 src_encoding , 则假设为数据库编码 . | convert( | 以 ISO |
decode(string text, type text) | bytea | 把早先用 encode 编码的,存放在 string 里面的二进制数据解码。 参数类型和 encode 一样。 | decode('MTIzAAE=', | 123/000/001 |
encode(data bytea, type text) | text | 把二进制数据编码为只包含 ASCII 形式的数据。 支持的类型有 base64 , hex , escape 。 | encode('123//000 | MTIzAAE= |
initcap(text) | text | 把每个单词(空白分隔)的第一个子母转为大写 | initcap('hi | Hi Thomas |
length(string ) | integer | length('jose') | 4 | |
lpad(string text, length integer [, fill text]) | text | 通过填充字符 fill (缺省时为空白), 把 string 填充为长度 length 。 如果 string 已经比 length 长则将其截断(在右边)。 | lpad('hi', 5, 'xy') | xyxhi |
ltrim(string text, characters text) | text | 从字串 string 的 开头 删除只包含 characters 的最长的字串。 | ltrim | trim |
md5(string text) | text | 计算给出字串的 MD5 散列,以十六进制返回结果。 | md5('abc') | 90015098 |
pg_client_encoding() | name | 当前客户端编码名称。 | pg_client_ | SQL_ASCII |
quote_ident(string text) | text | 返回给出字串的一个适用于在 SQL 语句字串里当作标识符引起使用的形式。 只有在必要的时候才会添加引号(也就是说,如果字串包含非标识符字符或者会 转换大小写的字符)。 嵌入的引号被恰当地写了双份。 | quote_ident('Foo') | "Foo" |
quote_literal(string text) | text | 返回给出字串的一个适用于在 SQL 语句字串里当作文本使用的形式。 嵌入的引号和反斜杠被恰当地写了双份。 | quote_literal | 'O''Reilly' |
repeat(text, integer) | text | 重复 text 一定次数。 | repeat('Pg', 4) | PgPgPgPg |
replace(string text, from text, to text) | text | 把字串 string 里出现地所有子字串 from 替换成子字串 to 。 | replace | abXXef |
rpad(string text, length integer [, fill text]) | text | 通过填充字符 fill (缺省时为空白), 把 string 填充为长度 length 。 如果 string 已经比 length 长则将其截断。 | rpad('hi', 5, 'xy') | hixyx |
rtrim(string | text | 从字串 string 的 结尾 | rtrim | trim |
split_part | text | 根据 delimiter 分隔 string 返回生成的第 field 个子字串(一为基)。 | split_part | def |
strpos(string , substring ) | text | 声明的子字串的位置。(和 position(substring in string 一样) ,不过要注意参数顺序 是相反的) | strpos | 2 |
substr(string , from [, count ]) | text | 抽取子字串。(和 substring(string from from for count ) 一样) | substr('alphabet', | ph |
to_ascii | text | 把文本从其它编码转换为 ASCII 。 [a] | to_ascii('Karel') | Karel |
to_hex(number integer 或者 bigint) | text | 把 number 转换成其对应地十六进制表现形式。 | to_hex(922337203 | 7fffffff |
translate(string text, from text, to text) | text | 把在 string 中包含的任何匹配 from 中的字符的字符转化为对应的 在 to 中的字符。 | translate('12345', |
|