Query Parameters
Write a query once with placeholders and fill in the values each time you run it.
Query parameters let you keep a query generic and supply the values when you run it. Mantidb finds the placeholders in your SQL, asks for a value for each one, and then runs the query with those values filled in.
Placeholder syntax
Mantidb recognizes two kinds of placeholders:
| Placeholder | Example | Notes |
|---|---|---|
| Named | :customer_id, :status | A name after a colon. |
| Positional | $1, $2, $3 | Numbered placeholders, as in PostgreSQL. |
SELECT id, total, status
FROM orders
WHERE customer_id = :customer_id
AND status = :status
AND created_at >= $1
ORDER BY created_at DESC;
What is not a parameter
Mantidb skips anything that only looks like a placeholder, so normal SQL keeps working:
- Text inside string literals (
'10:30') and quoted identifiers. - Comments.
- Dollar-quoted bodies such as
$tag$ … $tag$. - PostgreSQL casts like
created_at::date. - Assignments with
:=. @varvariables and?markers. These are left as they are and sent to the server unchanged.
Enter the values
When you run a query that contains placeholders (⌘↩ or ⇧⌘↩), a sheet opens before anything is sent to the server.
- Type a value for each placeholder.
- Check NULL next to a placeholder to send
NULLinstead of a value. - Click Run, or Cancel to go back to the editor without running.
The values you enter are remembered for the tab, so the next run starts with the same values already filled in.
How values are sent
Each value is sent as an escaped string literal, or as NULL when the NULL box is checked. The server converts the literal to the type the query needs, so 42 works for an integer column and 2026-01-31 works for a date.
Because every value is a quoted literal, a parameter can only stand for a value. It can't replace a table name, a column name or a keyword.
Parameters and safe mode
Safe mode checks the query after the values have been substituted. If the statement is a write and the connection asks for confirmation, the confirmation sheet shows the final SQL, with your values in place, so you can review exactly what will run.
