sql - Amazon Redshift 中的十六进制字符串到整数转换

标签 sql postgresql amazon-web-services hex amazon-redshift

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/

相关文章:

amazon-web-services - AWS s3 "public access"

django-storges 支持 CloudFront 签名 URL

Python将参数传递给查询错误

ruby-on-rails - 如何为 Rails 服务器使用多个数据库?

sql - 在 SQL Server 2005 中使用 SSIS 从平面文件导入时如何保留 NULL 值

php - 将值放入 sql 枚举的最佳实践

sql - postgresql 查询以确定用户未看到的推荐记录

csv - 敏感文件的 Amazon S3 存储

sql - R 连接到本地 SQL Server

mysql - 条件 SQL 选择 : when select has a value select all but the smallest date