在 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/