SQLite 3 cheatsheet
SQLite 3: Everyday SQL
5 common SQLite 3 tasks.
Create a table
Create a table with an auto-assigned integer key and a default timestamp.
CREATE TABLE users (
id INTEGER PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
Insert or ignore duplicates
Insert a row, doing nothing if the email already exists.
INSERT INTO users (email) VALUES ('[email protected]') ON CONFLICT(email) DO NOTHING;
Read a value from JSON
Extract a field from a JSON text column.
SELECT json_extract(data, '$.name') FROM events;