BigQuery SQL formatter
Format GoogleSQL for BigQuery in your browser. Backtick table paths, query parameters, arrays and QUALIFY are kept intact and laid out cleanly.
The formatter reads BigQuery SQL with its MySQL rules, plus the BigQuery syntax listed below.
Every layout setting of the formatter, grouped like Editor › Formatting in the SQLly app. The style above is the starting point; anything you change here is marked.
Drop a .sql file here to open it. It is read in your browser, not uploaded.
SELECT
user_id,
COUNT(*) AS sessions,
ARRAY_AGG(page ORDER BY ts LIMIT 5) AS first_pages
FROM
`my-project.analytics.events`
WHERE
event_name = @event
AND 'beta' IN UNNEST(tags)
AND ts >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 day)
GROUP BY
user_id
QUALIFY
ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) <= 100
Loading the formatter…
Shortcuts in the editor: Ctrl+Enter formats and Ctrl+Shift+Enter minifies (⌘ instead of Ctrl on a Mac). Your settings are remembered in this browser and kept in the page address, so a link shares your style – never your SQL.
What the formatter does with BigQuery SQL
- Backtick table paths.
`my-project.analytics.events`is one quoted name, hyphens and all. - Query parameters.
@eventnamed parameters are read as single tokens. - Arrays stay as written.
[1, 2, 3]literals andarr[OFFSET(0)]subscripts are kept exactly as you typed them, andUNNEST,STRUCTandARRAY_AGGcalls are laid out like any function. - QUALIFY gets its own clause, laid out like
HAVING, andINTERVALandOVER (PARTITION BY …)get your keyword casing. - Comments and strings.
#comments are kept, double-quoted text is a string, andr'…'raw andb'…'bytes literals stay attached to their prefix.
Good to know
- Keyword casing covers standard SQL and MySQL keywords, so some BigQuery-only words keep the case you typed.
Examples
BigQuery before and after
select user_id, count(*) as sessions, array_agg(page order by ts limit 5) as first_pages from `my-project.analytics.events` where event_name = @event and 'beta' in unnest(tags) and ts >= timestamp_sub(current_timestamp(), interval 7 day) group by user_id qualify row_number() over (order by count(*) desc) <= 100
SELECT
user_id,
COUNT(*) AS sessions,
ARRAY_AGG(page ORDER BY ts LIMIT 5) AS first_pages
FROM
`my-project.analytics.events`
WHERE
event_name = @event
AND 'beta' IN UNNEST(tags)
AND ts >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 day)
GROUP BY
user_id
QUALIFY
ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) <= 100
The output uses the Standard style with 4-space indents, exactly as the formatter above produces it. Switch the style to Compact for denser SQL or Expanded for leading commas and one item per line. The formatter docs cover the details.
BigQuery formatter FAQ
How does the formatter read BigQuery SQL?
With its MySQL rules, which share BigQuery's backtick quoting, # comments and double-quoted strings. On top of that it understands @parameters, [ ] arrays and QUALIFY.
Will it break my backtick project.dataset.table names?
No. A backtick-quoted path is a single name to the formatter, so it is kept exactly as written.
Is my SQL sent to a server?
No. The formatter is compiled to WebAssembly and runs inside your browser tab. Your SQL is never uploaded, logged or stored, and once the page has loaded it keeps working offline.
Can formatting break my query?
It is built not to. After formatting, SQLly checks its output token by token against your input. If anything other than whitespace and the casing you asked for would change, it gives your SQL back exactly as you wrote it and tells you why. SQL that does not parse cleanly, such as an unterminated string, is also left untouched, with the line and column of the problem.
Can I share my formatting settings with my team?
Yes. Every setting, including the advanced ones, is kept in the page address after the # sign, so copying the address or pressing Copy settings link shares your exact style. The link holds the settings only, never your SQL.
Like the formatter? Meet the rest of SQLly
A native SQL workbench for macOS, Windows and Linux with IntelliSense that knows your schema, guardrails for risky queries, and this formatter built into the editor.