[英]Redshift can't cast text to boolean from json field
In a Redshift database, given a field containing the following json:在 Redshift 数据库中,给定一个包含以下 json 的字段:
{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true}
Although I can extract true
using json_extract_path_text(my_field, '0')
, when I'm trying to extract an element and cast it to a boolean as follow:虽然我可以使用json_extract_path_text(my_field, '0')
提取true
,但当我尝试提取元素并将其转换为 boolean 时,如下所示:
SELECT
json_extract_path_text(my_field, '0')::boolean
FROM my_table
I then get the following error:然后我收到以下错误:
cannot cast type text to boolean无法将类型文本转换为 boolean
I do not understand as the following is working without any issue:我不明白,因为以下工作没有任何问题:
SELECT 'true'::boolean, 'false'::boolean;
This post seems to answer the problem: https://stackoverflow.com/a/45799072这篇文章似乎回答了这个问题: https://stackoverflow.com/a/45799072
SELECT BOOLIN(TEXTOUT(json_extract_path_text('{"0":true}', '0')));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.