Convert super field to string/varchar in redshift

570 Views Asked by At

I have a super field that holds JSON formatted data - [{"Title":"First Last"}] I want to extract the JSON value string First Last and to do so, I tried converting this field to varchar and the result is empty. I also tried converting to JSON_serialize and then to varchar and still the results are blank. Any help on how to fix this?

Queries i tried:

SET navigate_super_null_on_error=ON;  --default lax mode for navigation

SET cast_super_null_on_error=ON;  --default lax mode for casting

SET parse_super_null_on_error=OFF;  --default strict mode for ingestion

SELECT cast(MRGBackup as varchar) FROM oc_raw.rollouts;

SET enable_case_sensitive_identifier to TRUE;
 
-- Accessing JSON attribute names with uppercase and mixedcase names
SELECT 
       json_table.data."Title"
FROM
  (SELECT json_parse(mycolumn) AS data FROM mytable);
RESET enable_case_sensitive_identifier;

mycolumn holds data like - [{"Title":"First Last"}]

This throws error as - function json_parse(super) does not exist

Any help pls?

--------UPDATE--------

For my mycol = [{"Title":"First Last"}]

I tried this query - SELECT mycolumn,mycolumn[0] from mytable

and the result is {"Title":"First Last"} still trying to extract the inner text alone.

1

There are 1 best solutions below

0
On

Alright. @lex looter's answer helped. But I had to do

ALTER USER <username> SET enable_case_sensitive_identifier to true

and then do SELECT mycolumn[0]."Title" from mytable; to make the query work correctly.