Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fabrixxm/99ba47bdeea93ba60c8e87e020513d57 to your computer and use it in GitHub Desktop.
Save fabrixxm/99ba47bdeea93ba60c8e87e020513d57 to your computer and use it in GitHub Desktop.
Testing json generated columns
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