I am trying to list elements in a nested array using JSON data type, but am not able to do that
This is my table.
INSERT INTO events(event_name, visitor ,properties, browser)
VALUES (
'pageview',
'1',
'{ "page": "/" }',
'{ "name": "UC Browser", "os": "Mac", "resolution": { "x": 1920, "y": 1080 } }'
),
('pageview',
'2',
'{ "page": "/" }',
'{ "name": "Safari", "os": "Mac", "resolution": [{ "x": 1920, "y": 1080 },{ "x": 1720, "y": 1080 } ]}'
);
This is what i tried
SELECT id, browser->>'$.name' name, browser->>'$.resolution.x' x_resolution, browser->>'$.resolution.y' y_resolution
FROM events where id=2;