Amazon Redshift 基于 ParAccel,后者基于 Postgres。根据我的研究,在 Postgres 中执行十六进制字符串到整数转换的首选方法似乎是通过位字段,如 answer 中所述。
对于 bigint,这将是:
select ('x'||lpad('123456789abcdef',16,'0'))::bit(64)::bigint
不幸的是,这在 Redshift 上失败了:
ERROR: cannot cast type text to bit [SQL State=42846]
在 Postgres 8.1ish(接近 Redshift 兼容性级别)中还有哪些其他方法可以执行此转换? Redshift 不支持 UDF,数组、正则表达式函数或集合生成函数也不支持...
最佳答案
看起来他们在某个时候为此添加了一个功能:STRTOL
Syntax
STRTOL(num_string, base)
Return type
BIGINT. If num_string is null, returns NULL.
例如
SELECT strtol('deadbeef', 16);
返回:3735928559
关于sql - Amazon Redshift 中的十六进制字符串到整数转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20888593/