Created
January 7, 2023 03:24
-
-
Save reddec/70cbde11fbf048a2df8d5b63a18fa6cd to your computer and use it in GitHub Desktop.
SQLite document
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
-- https://www.sqlite.org/json1.html | |
CREATE TABLE stat | |
( | |
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | |
started_at TIMESTAMP NOT NULL DEFAULT current_timestamp, | |
finished_at TIMESTAMP NOT NULL DEFAULT current_timestamp, | |
meta JSON NOT NULL DEFAULT '{}' -- JSON! | |
); | |
CREATE INDEX stat_meta_project ON stat (meta ->> 'project'); | |
INSERT INTO stat(meta) | |
VALUES ('{ | |
"project": "hello", | |
"workspace": "default", | |
"method": "POST" | |
}'), | |
('{ | |
"project": "help", | |
"workspace": "default", | |
"method": "POST" | |
}'); | |
SELECT * | |
FROM stat; | |
SELECT * | |
FROM stat | |
WHERE meta ->> 'project' = 'hello'; | |
EXPLAIN QUERY PLAN | |
SELECT * | |
FROM stat | |
WHERE meta ->> 'project' = 'hello'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment