brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: .parameter set lets you test SQLite queries with named parameters in the shell

Sqlite
~/tips/tip-sqlite-parameter-set

sqlite> .parameter set :mail '[email protected]'

Binds values to :name placeholders so you can run an app's query exactly as written.

Queries in app code use placeholders like :email. Trying one in the shell then means replacing them by hand. The sqlite3 shell can bind them for you.

sqlite> .parameter set :mail '[email protected]'
sqlite> SELECT id FROM users WHERE email = :mail;
1
sqlite> .parameter list
:mail '[email protected]'

Names can start with :, @ or $, the same styles SQLite accepts in code, and numbered ones like ?1 work too. .parameter list shows what is set, .parameter unset :mail removes one and .parameter clear removes all of them.

I like it because you can paste a query from the code unchanged, and a value with quotes in it is passed as data, so there’s no escaping to get wrong.

The value is evaluated as SQL first, which trips people up. 42 becomes a number and a plain word becomes text, but .parameter set :d 2026-01-01 stores 2024, because that is valid arithmetic. Quote dates and strings to be safe. The parameters live in a temporary table called sqlite_parameters, so they last for the session, and any placeholder you did not set is bound as NULL. That last one is sneaky: the query runs fine and finds nothing.

Further reading: Command Line Shell For SQLite (.parameter)

More Sqlite tips SELECT unixepoch('2026-01-01 00:00:00'); SELECT name, iif(qty > 0, 'in stock', 'sold out') AS state sqlite3 -bail app.db < migrate.sql CREATE INDEX 'orders_user_id' ON 'orders'('user_id'); –> users(id) CREATE INDEX users_active_email ON users(email) WHERE active = 1; All Sqlite tips (27) All topics

Link