tpaw Docs

Variables

Define named variables in tpaw to parameterize SQL queries with substitution syntax.

Variables let you define named key-value pairs that are substituted into your SQL queries at runtime. Use ${variable_name} in a query and tpaw replaces it with the variable's current value before executing. This is useful for queries you run repeatedly with different inputs — user IDs, date ranges, status values, and similar parameters.

Variable types

TypeBehaviorUse for
TextValue is escaped and quoted as a SQL string literalNames, statuses, string filters
RawValue is inserted as-is, without quoting or escapingNumeric values, SQL fragments, identifiers

Text variables are safe by default — tpaw properly escapes the value, so injection is not a concern. Raw variables give you full control but require you to ensure the value is safe SQL.

Using variables in queries

Reference a variable in any SQL query with ${name}:

-- Using a text variable (value will be quoted automatically)
SELECT * FROM users WHERE status = ${status};
 
-- Using a raw variable (value inserted as-is)
SELECT * FROM orders WHERE id = ${order_id};
 
-- Multiple variables
SELECT * FROM events
WHERE user_id = ${user_id}
  AND created_at > ${start_date};

Managing variables

Open the Variables panel from the sidebar navigation. The panel shows all defined variables grouped by type (Text and Raw), with a search bar and type filter.

Creating a variable

Click the + button to open the variable editor modal. Enter:

  • Name — the identifier used in ${name} syntax
  • Value — the substitution value
  • Type — Text (escaped) or Raw (literal)

Click Save to create the variable.

Editing a variable

Click any variable row in the Variables panel to open the edit modal. Update the name, value, or type and click Save.

Deleting a variable

Hover over a variable row and click the trash icon to delete it.

Variables are per-connection

Each database connection has its own variable store. Variables do not carry over between connections.

Example: parameterized reporting query

-- Define a raw variable: report_month = 2026-01
-- Define a text variable: region = us-east
 
SELECT
  date_trunc('day', created_at) AS day,
  COUNT(*) AS order_count,
  SUM(total_amount) AS revenue
FROM orders
WHERE
  region = ${region}
  AND date_trunc('month', created_at) = ${report_month}::date
GROUP BY 1
ORDER BY 1;

On this page