0% found this document useful (0 votes)
14 views2 pages

Semi Structured Query

The document discusses parsing and analyzing raw JSON data stored in a database table. It shows how to select attributes, format data types, handle nested data and arrays, and extract specific elements from the JSON documents.

Uploaded by

clouditlab9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Semi Structured Query

The document discusses parsing and analyzing raw JSON data stored in a database table. It shows how to select attributes, format data types, handle nested data and arrays, and extract specific elements from the JSON documents.

Uploaded by

clouditlab9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//// Step 2: Parse & Analyse Raw JSON

// Selecting attribute/column

SELECT RAW_FILE:city FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

SELECT $1:first_name FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

// Selecting attribute/column - formattted

SELECT RAW_FILE:first_name::string as first_name FROM


OUR_FIRST_DB.PUBLIC.JSON_RAW;

SELECT RAW_FILE:id::int as id FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

-- Put everything together


SELECT
RAW_FILE:id::int as id,
RAW_FILE:first_name::STRING as first_name,
RAW_FILE:last_name::STRING as last_name,
RAW_FILE:gender::STRING as gender
FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

// Handling nested data

SELECT RAW_FILE:job as job FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

SELECT
RAW_FILE:job.salary::INT as salary
FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

SELECT
RAW_FILE:first_name::STRING as first_name,
RAW_FILE:job.salary::INT as salary,
RAW_FILE:job.title::STRING as title
FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

// Handling arrays

SELECT
RAW_FILE:prev_company as prev_company
FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

SELECT
RAW_FILE:prev_company[1]::STRING as prev_company
FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

SELECT
RAW_FILE:id::int as id,
RAW_FILE:first_name::STRING as first_name,
RAW_FILE:prev_company[0]::STRING as first_prev_company,
RAW_FILE:prev_company[1]::STRING as second_prev_company
FROM OUR_FIRST_DB.PUBLIC.JSON_RAW;

SELECT
RAW_FILE:id::int as id,
RAW_FILE:first_name::STRING as first_name,
RAW_FILE:prev_company[0]::STRING as first_prev_company
FROM OUR_FIRST_DB.PUBLIC.JSON_RAW
UNION ALL
SELECT
RAW_FILE:id::int as id,
RAW_FILE:first_name::STRING as first_name,
RAW_FILE:prev_company[1]::STRING as second_prev_company
FROM OUR_FIRST_DB.PUBLIC.JSON_RAW
ORDER BY id;

You might also like