Last active
September 8, 2023 20:31
-
-
Save itspb/5625e223395fce674402bb500887be6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS purchases; | |
CREATE TEMP TABLE purchases ( | |
data jsonb | |
); | |
INSERT INTO purchases (data) | |
VALUES ('{ | |
"purchase_id": 83577474, | |
"customer_id": 173645, | |
"items": [ | |
{ | |
"product_id": 76, | |
"title": "beer", | |
"price": 9.99, | |
"quantity": 6 | |
}, | |
{ | |
"product_id": 90, | |
"title": "pampers", | |
"price": 545.60, | |
"quantity": 2 | |
} | |
], | |
"total_price": 1151.14 | |
} | |
') | |
; | |
SELECT data->>'customer_id' AS customer_id | |
FROM purchases | |
; | |
SELECT (jsonb_array_elements(data->'items')->>'title') AS title | |
FROM purchases | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment