Can you store JSON fields on Redshift?
Asked Answered
S

3

15

Does Redshift support JSON fields, like Postgresql's json data type? If so what do I do to use it?

Somewise answered 22/9, 2015 at 17:0 Comment(0)
I
13

You can store JSON in Amazon Redshift, within a normal text field.

There are functions available to extract data from JSON fields, but it is not an effective way to store data since it doesn't leverage the full capabilities of Redshift's column-based architecture.

See: Amazon Redshift documentation - JSON Functions

Isooctane answered 23/9, 2015 at 5:6 Comment(0)
Z
2

You can use the SUPER type to store JSON data within Redshift, using JSON_PARSE(...) to convert text to JSON as required.

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

For example:

CREATE TABLE t
(
   id   INT,
   item SUPER
);

INSERT INTO t VALUES(1, JSON_PARSE('{"name":"Beethoven", "born":1770}'));

SELECT id, item.born FROM t WHERE item.name = 'Beethoven';

You can query attributes within your JSON field content using the dot notation, as shown above. You can also join on JSON attributes.

Note that Redshift's SUPER type currently has a limit of 16MB.

Zolnay answered 24/2, 2023 at 9:54 Comment(0)
I
0

UPDATE: Redshift now supports Data column of type "super" which allows saving JSONs and also querying over it. Added a link to video that further explains the new option: https://www.youtube.com/watch?v=PR15TVZDgy4

Iranian answered 3/11, 2022 at 10:44 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Squires

© 2022 - 2024 — McMap. All rights reserved.