SQL Parameter Formatter

Rewrite SQL placeholders between styles such as ? , $1, :name, @name, %s or {0}, numbering positional parameters in order and listing the bindings, locally in your browser.

  • Runs locally in your browser
  • No upload required

Capabilities

  • Download result

Try it

Processed entirely in your browser; never uploaded.

Each dialect has its own comment, string and identifier rules.

Parameters
2 placeholder(s)
Source style
question
Target style
dollar-numbered
select * from t where a = $1 and b = $2

Supported formats

Input
text/plain
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Converted 2 placeholder(s) from ? (positional) to $1 (numbered).

How it works

  • Tokenised the query and collected the real parameter tokens.
  • Numbered the parameters in source order.
  • Emitted each placeholder in the target style.
  • Parameters inside strings, quoted identifiers and comments are ignored.

Methodology

  1. Tokenise the query and collect only the real parameter tokens, ignoring anything inside strings or comments.
  2. Determine the source style from the first placeholder and number the parameters in source order.
  3. Emit each placeholder in the requested target style.

Usage

  1. Paste a query that contains placeholders.
  2. Choose the source dialect and the target placeholder style.
  3. Run the formatter and copy the rewritten query or the parameter list.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Positional to numbered

jsonSelect to copy
{
  "text": "select * from t where a = ? and b = ?",
  "dialect": "mysql",
  "targetStyle": "dollar-numbered"
}

Numbered to named

jsonSelect to copy
{
  "text": "select * from t where a = $1 and b = $2",
  "dialect": "postgresql",
  "targetStyle": "named-colon"
}

Named to positional

jsonSelect to copy
{
  "text": "select * from t where a = :a and b = :b",
  "dialect": "standard",
  "targetStyle": "question"
}

Limitations

One query, many drivers

The same query is written with different placeholders depending on the driver. Converting them by hand is error-prone; doing it from the token stream keeps ordering exact.

Frequently asked questions

What happens to a ? inside a string?
It is left untouched. Only placeholders outside strings, identifiers and comments are converted.
Are named parameters preserved?
When converting to a named style the names are kept; converting to a positional style replaces them with p1, p2, … in order.
Does this run my query?
No. It rewrites the text in your browser and never connects to a database.

Sources

  1. ISO/IEC 9075-1:2023: Information technology, Database languages SQL — ISO/IEC
  2. PostgreSQL Documentation: SQL Syntax, Lexical Structure — PostgreSQL Global Development Group
  3. MySQL 8.0 Reference Manual: String Literals — Oracle
  4. SQLite Documentation: SQL Syntax — SQLite Consortium
  5. Microsoft Learn: Transact-SQL Syntax Conventions — Microsoft