Reference

SQL & Redis

SQLite, PostgreSQL, Snowflake and Redis syntax, queries and everyday operations.

Scope and conventions

SQL examples name their database and assume the sample schema where indicated. Redis examples are native redis-cli commands, with optional Search/JSON features labeled. Run independent examples in your own scratch database; driver binding syntax and transaction guarantees differ.

Expiration & operations

Recognize the connection and name scope

SQLite

sqlite3 opens an embedded database file. :memory: creates a connection-local in-memory database. Dot commands belong to the CLI, not SQL sent through an application driver .

Fragment

SQLite · Recognize the connection and name scope
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
sqlite3 reference.db
# Inside sqlite3:
# .tables
# .schema items

Shell command; CLI dot commands are shown in comments.

Recognize an export versus a recoverable backup

SQLite

The CLI can write CSV query output; a database backup preserves a different contract than a projected report. Inspect null/encoding/type rules for round trips, and verify a restore rather than trusting a filename.

Fragment

SQLite · Recognize an export versus a recoverable backup
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
.headers on
.mode csv
.once items.csv
SELECT item_id, name, qty FROM items ORDER BY item_id;

sqlite3 interactive dot commands; not SQL sent through a driver.

Inspect tables, columns and indexes

SQLite

The sqlite3 CLI .schema command prints schema SQL. PRAGMA table_info and index_list inspect a chosen table; they are database SQL/PRAGMA operations, not ordinary SELECT metadata tables.

Fragment

SQLite · Inspect tables, columns and indexes
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
.schema items
PRAGMA table_info(items);
PRAGMA index_list(items);

First line is a sqlite3 dot command; following lines are SQL/PRAGMA.

Create and restore a named scratch backup

SQLite

The backup API/CLI .backup produces a consistent SQLite database copy. Restore into a chosen database; an arbitrary filesystem copy during writes is not the same protocol.

Fragment

SQLite · Create and restore a named scratch backup
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
sqlite3 scratch.db '.backup backup.db'
sqlite3 restored.db '.restore backup.db'

Shell example with separate scratch and restore paths. Verify the restored schema/data before relying on a backup.