RowDex
Documentation

Query variables

Reuse one SQL query with different values using placeholders such as :user_id, {{date}} or ${id}. See every supported syntax and try it live.

1 min readUpdated

On this page

Put a placeholder in your SQL where a value goes. When you run the query, RowDex asks for a value for each placeholder and substitutes it. It is ideal for saved queries you re-run with a new user ID or date range.

Supported syntax#

StyleExample
Colon:order_id
Mustache{{ order_id }}
Dollar-brace${order_id}
Hash-brace#{order_id}
Percent%order_id%
Positional? or ?1

The same name can appear several times, in any style, and RowDex asks for it once. @name is deliberately not supported, because it collides with email addresses and MySQL user variables.

Try it#

Edit the query and fill in the values. This demo follows the same rules as the app.

Try query variables

RowDex asks for 3 values
What RowDex runs
SELECT * FROM orders
WHERE customer_id = 42
  AND status = 'paid'
  AND total > 100.50;

Numbers go in as they are, text is quoted and escaped, and an empty value or NULL becomes NULL.

How values are inserted#

  • Numbers are inserted as they are: 42, -3.5.
  • Text is wrapped in single quotes and escaped for you: O'Brien becomes 'O''Brien'.
  • NULL or an empty value becomes NULL.
  • A value you already wrapped in quotes is used exactly as typed.

What is not treated as a variable#

Placeholders inside string literals, quoted identifiers, comments and dollar-quoted blocks are left alone. So WHERE name LIKE '%term%' and a PostgreSQL cast like created_at::date run as written.

Was this page helpful?