amazon-redshift - Redshift 无法将 json 字段中的文本转换为 bool 值

标签 amazon-redshift

在 Redshift 数据库中,给定一个包含以下 json 的字段:

{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true}

尽管我可以使用 json_extract_path_text(my_field, '0') 提取 true,但当我尝试提取元素并将其转换为 bool 值时,如下所示:

SELECT 
    json_extract_path_text(my_field, '0')::boolean
FROM my_table

然后我收到以下错误:

cannot cast type text to boolean

我不明白,因为以下内容运行没有任何问题:

SELECT 'true'::boolean, 'false'::boolean;

最佳答案

这篇文章似乎回答了这个问题: https://stackoverflow.com/a/45799072

    SELECT BOOLIN(TEXTOUT(json_extract_path_text('{"0":true}', '0')));

关于amazon-redshift - Redshift 无法将 json 字段中的文本转换为 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74521836/

相关文章:

amazon-redshift - 有多个 sortkey 列是什么意思?

amazon-redshift - 在大型数据集上使用 ADD COLUMN 的含义

amazon-s3 - 亚马逊 Redshift : Acces Denied RestoreClusterSnapshotRequest

postgresql - 亚马逊 Redshift : Is it possible to return multiple result set?

sql - 在 FULL OUTER JOIN 中计算 DISTINCT

jdbc - AWS Redshift JDBC 插入性能

sql - 获取不带 NULL 值的 SQL 不同行

amazon-web-services - Glue爬虫如何加载Redshift表中的数据?

sql - 如果可用,请在该月加入,否则请在最近一个月加入

sql - 我怎样才能做一个不同的总和?