尝试在标准 SQL BigQuery 中使用 CAST 将十六进制时间戳转换为十进制
Trying to convert a hexadecimal timestamp into decimal with CAST in standard SQL BigQuery
所以我正在尝试从 UUID 中提取时间戳,例如 this
我在将十六进制字符串转换为十进制整数的步骤中卡住了。根据我的理解,这应该有效:
SELECT CAST("1e78c9e03144170" AS INT64) as hex_to_dec
我期待答案:136865943201620000
但我收到错误:
Error: Could not cast literal "1e78c9e03144170" to type INT64 at [1:13]
以下适用于 BigQuery 标准 SQL
SELECT hex_val, CAST(CONCAT('0x', hex_val) AS INT64) AS hex_to_dec
你可以用下面的方法测试它
#standardSQL
WITH `project.dataset.table` AS (
SELECT '1e78c9e03144170' hex_val
)
SELECT hex_val, CAST(CONCAT('0x', hex_val) AS INT64) AS hex_to_dec
FROM `project.dataset.table`
结果是
Row hex_val hex_to_dec
1 1e78c9e03144170 137232923942470000
注意:您 136865943201620000
的预期结果不正确。正确的是 137232923942470000
您可以验证它,例如 here
所以我正在尝试从 UUID 中提取时间戳,例如 this
我在将十六进制字符串转换为十进制整数的步骤中卡住了。根据我的理解,这应该有效:
SELECT CAST("1e78c9e03144170" AS INT64) as hex_to_dec
我期待答案:136865943201620000
但我收到错误:
Error: Could not cast literal "1e78c9e03144170" to type INT64 at [1:13]
以下适用于 BigQuery 标准 SQL
SELECT hex_val, CAST(CONCAT('0x', hex_val) AS INT64) AS hex_to_dec
你可以用下面的方法测试它
#standardSQL
WITH `project.dataset.table` AS (
SELECT '1e78c9e03144170' hex_val
)
SELECT hex_val, CAST(CONCAT('0x', hex_val) AS INT64) AS hex_to_dec
FROM `project.dataset.table`
结果是
Row hex_val hex_to_dec
1 1e78c9e03144170 137232923942470000
注意:您 136865943201620000
的预期结果不正确。正确的是 137232923942470000
您可以验证它,例如 here