Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redshift SUPER type: accessing camel case fields returning null result

I'm trying to access fields of a SUPER column which have camel case fields, so something like:

{"FirstName": "Mario", "LastName": "Maria"}

So let's say I store this field in Redshift as column my_json, then I'd query it with

SELECT my_json.FirstName
FROM my_table

Then I'd get only null result instead of the real value.

How to handle this use case?

like image 786
Vzzarr Avatar asked Nov 01 '25 21:11

Vzzarr


2 Answers

Second Redshift defaults to lower case for all column names so FirstName is being seen as firstname. You can enable case sensitive column names by setting the enable_case_sensitive_identifier connection variable to true and quoting all column names that require upper characters:

SET enable_case_sensitive_identifier TO true; 

and changing my_json.FirstName to my_json."FirstName".

See:

https://docs.aws.amazon.com/redshift/latest/dg/r_enable_case_sensitive_identifier.html

https://docs.aws.amazon.com/redshift/latest/dg/super-configurations.html

like image 74
Bill Weiner Avatar answered Nov 03 '25 12:11

Bill Weiner


adding to @Bill's answer above, there is a less general flag you can enable for SUPER json fields.

In your case, you can enable enable_case_sensitive_super_attribute like so:

SET enable_case_sensitive_super_attribute to TRUE;
 -- Accessing JSON attribute names with uppercase and mixedcase names

For your case, this is better than enable_case_sensitive_identifier, since that flag affects databases, tables, columns, etc.

https://docs.aws.amazon.com/redshift/latest/dg/super-configurations.html

like image 43
Gabe Avatar answered Nov 03 '25 11:11

Gabe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!