Assume I have a Redshift table my_schema.my_table
that contains a record as such:
id col1 my_list
-------------------
1 true [{"id": "A", "name": "foo"}, {"id": "B", "name": "bar"}]
The column my_list
is a SUPER
field. My understanding is that I would need to somehow iterate over the array, using get_array_length(my_list)
and I recognize I can extract elements as such:
select
my_list[0]."id",
my_list[0]."name"
from my_schema.my_table
Is there a simple Redshift method for doing this and ultimately achieving a table that looks as such:
id name
---------
A foo
B bar
Important to note, that this should happen dynamically. I will not know the size of the array. But the same key value pairs will always exist, i.e. id
and name
.
EDIT: Here is my best guess.
SELECT
my_list[idx]."id",
my_list[idx]."name"
FROM my_schema.my_table
CROSS JOIN (
SELECT generate_series(0, GET_ARRAY_LENGTH(my_list) - 1) AS idx
FROM my_schema.my_table
) AS idx_table
but I am getting the error:
[0A000] ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables.