Use when you need to run SQL queries against the PGlite database — inserting, selecting, updating, deleting data, or inspecting tables/schema. Provides the `pg` terminal command.
Run SQL queries against PGlite databases directly from the terminal. Auto-detects whether to query or exec — no subcommands needed.
pg "SELECT * FROM todos"
pg "INSERT INTO todos (title) VALUES ('Buy milk')"
pg "UPDATE todos SET completed = true WHERE id = 1"
pg "DELETE FROM todos WHERE id = 1"
The command automatically classifies SQL:
SELECT, WITH, EXPLAIN, SHOW, VALUES, TABLE, or anything with RETURNINGINSERT, UPDATE, DELETE, CREATE, ALTER, , etc.DROPpg "INSERT INTO todos (title) VALUES ('Test') RETURNING *" # → returns the inserted row
pg "CREATE TABLE users (id serial PRIMARY KEY, name text)" # → OK
--json — Output raw JSON instead of a formatted table--db <name> — Target a specific database (defaults to active)pg --json "SELECT * FROM todos"
pg --db myapp "SELECT count(*) FROM users"
pg "\dt" # List all tables
pg "\d todos" # Describe a table (columns, types, nullability)
pg "\l" # List all databases
pg "INSERT INTO todos (title) VALUES ('Buy milk')"
pg "INSERT INTO todos (title) VALUES ('Walk dog')"
pg "SELECT * FROM todos"
pg "ALTER TABLE todos ADD COLUMN priority INTEGER DEFAULT 0"
pg "\d todos"
pg "SELECT count(*) as total FROM todos"
pg --json "SELECT * FROM todos WHERE completed = false"
pg "SELECT ..." — unquoted SQL will be mangled by the shell.pg "INSERT INTO todos (title) VALUES ('Buy milk')".pg command bypasses the shell lexer, so SQL with semicolons, backslashes, and quotes works correctly.! — there is no history expansion in this environment. \! stores a literal backslash.