Introduction to NoSQL
Jake Roach
Data Engineer

-> operator
->> operator
$$
SELECT
parent_meta -> 'guardian' AS guardian
parent_meta ->> 'status' AS status
FROM student;

To query nested JSON objects:
-> and ->> in tandem$$
SELECT
parent_meta -> 'jobs' ->> 'P1' AS jobs_P1,
parent_meta -> 'jobs' ->> 'P2' AS jobs_P2
FROM student;

Accessing JSON array elements:
INT to ->, returns field as JSONINT to ->>, returns field as text$$
SELECT
parent_meta -> 'educations' ->> 0
parent_meta -> 'educations' ->> 1
FROM student;

json_typeof function
->->> operator$$
SELECT
json_typeof(parent_meta -> 'jobs')
FROM students;
SELECT
-- Top-level fields
<column-name> -> '<field-name>' AS <alias>,
<column-name> ->> '<field-name>' AS <alias>,
-- Nested fields
<column-name> -> '<parent-field-name>' ->> '<nested-field-name>' AS <alias>,
-- Arrays
<column-name> -> '<parent-field-name>' -> 0 AS <alias>,
<column-name> -> '<parent-field-name>' ->> 1 AS <alias>,
-- Type of
json_typeof(<column-name> -> <field-name>) AS <alias>
FROM <table-name>;
Introduction to NoSQL