Hologres兼容PostgreSQL,支持使用标准的PostgreSQL语法进行开发。本文为您介绍Hologres已支持的类型转换函数列表及使用用例。
Hologres已支持的类型转换函数列表如下。当前Hologres版本支持的函数是PostgreSQL的一个子集,函数的使用方法请参见类型转换函数。
函数名 | 返回类型 | 描述 | 用例 | 结果 | 备注 |
---|---|---|---|---|---|
to_char(timestamp, text) | TEXT | 将时间戳转换为字符串,支持时间范围为1925~2282年。 | to_char(current_timestamp, 'HH12:MI:SS') | 06:26:33 | 从1.1.31版本开始,在SQL前执行set hg_experimental_functions_use_pg_implementation = ‘to_char’; 或者set hg_experimental_functions_use_pg_implementation = 'to_char,to_date,to_timestamp'; 可支持所有时间。
说明 使用该GUC参数后,查询性能约有50%的损失,升级至Hologres V1.1.42及以上版本后,约有20%的损失。
|
to_char(int, text) | TEXT | 将整数转换为字符串。 | to_char(125, '999') | 125 | 无 |
to_char(double precision, text) | TEXT | 将实数或双精度数转换为字符串。 | to_char(125.8::real, '999D9') | 125.8 | 无 |
to_date(text, text) | DATE | 将字符串转换为日期,支持时间范围为1925~2282年。 |
|
2000-12-05 | 从1.1.31版本开始,在SQL前执行set hg_experimental_functions_use_pg_implementation = 'to_date' ; 或者set hg_experimental_functions_use_pg_implementation = 'to_char,to_date,to_timestamp'; 可支持所有时间。
说明 使用该GUC参数后,查询性能约有50%的损失,升级至Hologres V1.1.42及以上版本后,约有20%的损失。
|
to_number(text, text) | NUMERIC | 将字符串转换为数字。 | to_number('12,454.8-', '99G999D9S') | -12454.8 | 无 |
to_timestamp(text, text) | TIMESTAMP | 将字符串转换为时间戳,支持时间范围为1925~2282年。 | to_timestamp('05 Dec 2000', 'DD Mon YYYY') | 2000-12-05 00:00:00 |
说明 使用该GUC参数后,查询性能约有50%的损失,升级至Hologres V1.1.42及以上版本后,约有20%的损失。
|
array_to_string(anyarray, text [, text]) | TEXT | 将数组转换为字符串。 | array_to_string(ARRAY[1, 2, 3, NULL, 5], ',', '*') | 1,2,3,*,5 | 无 |
array_agg(expression) | ARRAY | 将值串联到数组中,可作为字符串转数组、列转行使用。 |
|
|
无 |
string_agg(expression) | TEXT | 使用指定分隔符将字段的非空值串联成字符串,可作为列转行。 | string_agg(colname, '-') | a-b-c | 无 |
regexp_split_to_table(string text, pattern text ) | TEXT | 使用POSIX正则表达式分割字符串,可作为行转列。 | regexp_split_to_table('hello world', '\s+') |
hello world |
无 |
isnumeric(text) | BOOLEAN | 判断输入字符串是否是有效数字类型。 | isnumeric('95.5') | true | 从V1.1版本开始支持。 |