Forked from AlessandroLorenzi/json_generated_columns.sql
Last active
August 7, 2022 08:00
-
-
Save fabrixxm/99ba47bdeea93ba60c8e87e020513d57 to your computer and use it in GitHub Desktop.
Testing json generated columns
This file contains hidden or 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 activities; | |
CREATE TABLE activities ( | |
id INTEGER NOT NULL PRIMARY KEY, | |
activity TEXT NOT NULL, | |
type TEXT GENERATED ALWAYS AS (json_extract(activity, '$.type')) STORED, | |
name text GENERATED ALWAYS AS (json_extract(activity, '$.name')) STORED | |
); | |
INSERT INTO | |
activities (activity) | |
VALUES | |
( | |
'{ | |
"type": "Foo", | |
"name": "Bar", | |
"quantity": 1 | |
}' | |
); | |
INSERT INTO | |
activities (activity) | |
VALUES | |
( | |
'{ | |
"type": "Hello", | |
"name": "World", | |
"quantity": 2 | |
}' | |
); | |
SELECT | |
type, | |
name, | |
json_extract(activity, '$.quantity') AS quantity | |
FROM | |
activities; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment