I am trying to extract the 'Name' and 'Value' from the nested column 'Fields' which is a nested array containing nested columns. I have a SOURCE schema with a similar structure as shown in the discussion thread. How can I achieve this in a view or table creation?
Jim
Asked on Oct 18, 2023
To extract nested data from columns and arrays in a view or table creation, you can use JSONB data type for the nested array.
Update the source schema to use JSONB for the 'Fields' column:
CREATE SOURCE user_profile (
data STRUCT <
integration VARCHAR,
crm STRUCT < EntityName VARCHAR, Fields JSONB[] >
>
) WITH (
connector = 'kafka',
..........
CREATE TABLE user_contact AS
SELECT
(data).crm.Fields[3]->>'Name' AS field_name,
(data).crm.Fields[3]->>'Value' AS field_value
FROM user_profile
WHERE (data).crm.EntityName = 'contact';