In a Redshift database, given a field containing the following 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:
SELECT
json_extract_path_text(my_field, '0')::boolean
FROM my_table
I then get the following error:
cannot cast type text to 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
SELECT BOOLIN(TEXTOUT(json_extract_path_text('{"0":true}', '0')));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.