Hologres兼容PostgreSQL,支持使用标准的PostgreSQL语法进行开发。
常见字符串函数
Hologres已支持的字符串函数列表如下。当前Hologres版本支持的函数是PostgreSQL的一个子集,函数的使用方法请参见字符串函数。
函数名 | 描述 | 用例 | 结果 |
---|---|---|---|
string || string | 连接两个字符串。 | 'Holo' || 'greSQL' | HologreSQL |
bit_length(string) | 获取字符串的位长度。 | bit_length('jose') | 32 |
char_length(string) | 获取字符串的字符长度。 | char_length('jose') | 4 |
lower(string) | 转换字符串为小写格式。 | lower('TOM') | tom |
octet_length(string) | 返回字符串的字节数。 | octet_length('jose') | 4 |
position(substring in string) | 查找子字符串在字符串中的位置。 | position('om' in 'Thomas') | 3 |
substring(string [from int] [for int]) | 从字符串中找出指定的子字符串。 | substring('Thomas' from 2 for 3) | hom |
substring(string from pattern) | 从字符串中找出与POSIX正则表达式匹配的子字符串。 | substring('Thomas' from '...$') | mas |
substring(string from pattern for escape) | 从字符串中找出与SQL正则表达式匹配的子字符串。 | substring('Thomas' from '%#"o_a#"_' for '#') | oma |
trim([leading | trailing | both] [characters] from string) | 从字符串String的开始、结尾或两端删除仅包含Characters中字符的最长字符串。
说明
|
trim(both 'xyz' from 'yxTomxx') | Tom |
trim([lea| tra| both] [from] string [, char] ) | 从字符串String的开始、结尾或两端删除仅包含Characters中字符的最长字符串。
说明
|
trim(both from 'yxTomxx', 'xyz') | Tom |
upper(string) | 转换字符串为大写格式。 | upper('tom') | TOM |
其他字符串函数
Hologres已支持的其他字符串函数列表如下。当前Hologres版本支持的函数是PostgreSQL的一个子集,函数的使用方法请参见其他字符串函数。
函数名 | 描述 | 用例 | 结果 |
---|---|---|---|
ascii(string) | 返回参数第一个字符的ASCII码。 | ascii('x') | 120 |
btrim(string text [, characters text]) | 从字符串String的开始和结尾删除仅包含Characters中字符的最长字符串。
说明 默认仅包含Characters中字符的最长字符串为空格。
|
btrim('xyxtrimyyx', 'xyz') | trim |
chr(int) | 返回指定编码值对应的字符。
说明 参数必须是合法的ASCII或UTF8编码值,并且参数值不能为0。
|
chr(65) | A |
concat(str "any" [, str "any" [, ...] ]) | 连接所有参数。忽略NULL参数。 | concat('abcde', 2, NULL, 22) | abcde222 |
concat_ws(sep text, str "any" [, str "any" [, ...] ]) | 使用分隔符连接除第一个参数外的所有参数。
说明 第一个参数用作分隔符字符串。忽略NULL参数。
|
concat_ws(',', 'abcde', 2, NULL, 22) | abcde,2,22 |
initcap(string) | 将每个单词的第一个字母转换为大写,其余字母转换为小写。
说明 单词是由一系列字母和数字组成的字符,使用非字母或数字分隔。
|
initcap('hi THOMAS') | Hi Thomas |
length(string) | 返回字符串中字符的个数。 | length('jose') | 4 |
lpad(string text, length int [, fill text]) | 用Fill填充在String头部,将String填充为长度是Length的字符串。
说明
|
lpad('hi', 5, 'xy') | xyxhi |
ltrim(string text [, characters text]) | 从字符串String的开始删除只包含Characters 中字符的最长的字符串。
说明 如果没有指定Characters的值,则Characters默认是空格。
|
ltrim('zzzytest', 'xyz') | test |
md5(string) | 计算String的MD5哈希值。结果表示为十六进制的形式。 | md5('abc') | 900150983cd24fb0d6963f7d28e17f72 |
parse_ident(quali_iden text [,...] ) | 解析字符串。 | parse_ident('"SomeSchema".someTable') | {SomeSchema,sometable} |
quote_ident(string text) | 使用String作为合法的SQL标识符。
说明 当字符串包含非标识符字符或者字符串会转换大小写时,需要添加引号。
|
quote_ident('Foo bar') | "Foo bar" |
quote_literal(string text) | 将String转换为合法的SQL语句字符串的常量形式。 | quote_literal(E'O\'Reilly') | 'O''Reilly' |
regexp_matches(string text, pattern text ) | 返回与POSIX正则表达式匹配的子字符串。 | regexp_match('foobarbequebaz', '(bar)(beque)') | {bar,beque} |
regexp_replace(str text, pat text, replace text ) | 使用Replacement替换与POSIX正则表达式匹配的子字符串。 | regexp_replace('Thomas', '.[mN]a.', 'M') | ThM |
regexp_split_to_array(string text, pattern text ) | 使用POSIX正则表达式分割字符串。 | regexp_split_to_array('hello world', '\s+') | {hello,world} |
regexp_split_to_table(string text, pattern text ) | 使用POSIX正则表达式分割字符串。 | regexp_split_to_table('hello world', '\s+') |
hello world (2 rows) |
repeat(string text, number int) | 将String重复指定Nnumber次。 | repeat('Pg', 4) | PgPgPgPg |
replace(string text, from text, to text) | 替换String中所有From子字符串为To。 | replace('abcdefabcdef', 'cd', 'XX') | abXXefabXXef |
rpad(string text, length int [, fill text]) | 用Fill填充在String尾部,将String填充为长度是Length的字符串。
说明
|
rpad('hi', 5, 'xy') | hixyx |
rtrim(string text [, characters text]) | 从字符串String的末尾删除只包含Characters中字符的最长的字符串。
说明 如果没有指定Characters的值,则Characters默认是空格。
|
rtrim('testxxzx', 'xyz') | test |
strpos(string, substring) | 返回Substring在String中的位置。 | strpos('high', 'ig') | 2 |
substr(string, from [, count]) | 从字符串中找出指定的子字符串。 | substr('alphabet', 3, 2) | ph |
starts_with(string, prefix) | 如果字符串以前缀开头,则返回true。 | starts_with('alphabet', 'alph') | true |
to_hex(number int or bigint) | 将数字转换为十六进制的表示形式。 | to_hex(2147483647) | 7fffffff |
translate(string text, from text, to text) | 使用字符串To中的字符替换From中的字符。 | translate('12345', '143', 'ax') | a2x5 |
在文档使用中是否遇到以下问题
更多建议
匿名提交