Formatting preserves identifiers and aliases. Style suggestions are not database validation. Maximum input: 100,000 characters.

INPUT 0 characters, 0 lines
OUTPUT
Ctrl + Enter

Turning history off also clears saved queries. Shared links contain your SQL; only share queries you intend others to read.

Client-Side Only

SQL formatting happens locally in your browser. Analytics records usage metadata, not SQL text. See our privacy details.

9 Dialects

PostgreSQL, MySQL, SQL Server, BigQuery, SQLite, MariaDB, Redshift, and Snowflake.

Saves Settings

Your indent size, keyword case, and dialect preferences are saved locally between sessions.

Query History

Optionally keeps your last 5 queries in this browser. Turn history off or clear it at any time.

Ctrl+Enter Format
Ctrl+Shift+C Copy
Ctrl+Shift+Backspace Clear
Ctrl+] Indent
? Shortcuts

Free Online BigQuery Formatter

This BigQuery formatter instantly beautifies your Google BigQuery SQL queries, making them easier to read, debug, and maintain. Simply paste your unformatted query and click Format.

BigQuery-Specific Formatting

Our formatter understands BigQuery-specific syntax including:

  • Data Types: STRUCT, ARRAY, GEOGRAPHY, BIGNUMERIC, JSON
  • Functions: TIMESTAMP_TRUNC, DATE_DIFF, ARRAY_AGG, UNNEST
  • Table References: Backtick-quoted project.dataset.table syntax
  • Partitioning: _PARTITIONTIME, _PARTITIONDATE pseudo-columns
  • Scripting: DECLARE, SET, IF, LOOP, WHILE statements
  • Window Functions: Advanced analytics with OVER clause

Why Format BigQuery SQL?

BigQuery queries often involve complex data transformations at scale. Clean, formatted queries help with:

  • Working with nested and repeated data structures
  • Optimizing query costs by understanding scan patterns
  • Building maintainable data pipelines
  • Collaborating on analytics queries with your team

Worked examples

UNNEST over a repeated field

BigQuery flattens arrays with UNNEST in the FROM clause. Formatting separates the flattening step from the rest of the join.

Before

select o.order_id,item.sku,item.qty from `proj.shop.orders` o, unnest(o.line_items) as item where item.qty > 1 and o.created_at >= current_date() - 30

After

SELECT
  o.order_id,
  item.sku,
  item.qty
FROM
  `proj.shop.orders` o,
  UNNEST (o.line_items) AS item
WHERE
  item.qty > 1
  AND o.created_at >= current_date() - 30

STRUCT and ARRAY literals

Nested STRUCT and ARRAY constructors get deep quickly. Each level is indented so the shape of the record is readable.

Before

select struct(id as user_id, struct(city as city, country as country) as location) as profile, array_agg(struct(event as name, ts as at) order by ts) as events from `proj.app.sessions` group by id, city, country

After

SELECT
  struct(
    id AS user_id,
    struct(city AS city, country AS country) AS location
  ) AS profile,
  array_agg(
    struct(event AS name, ts AS AT)
    ORDER BY
      ts
  ) AS events
FROM
  `proj.app.sessions`
GROUP BY
  id,
  city,
  country

QUALIFY, which filters window results

QUALIFY is a BigQuery clause that filters on a window function without a subquery. It sits at the end, after the window is defined.

Before

select user_id,event,ts,row_number() over (partition by user_id order by ts desc) as rn from `proj.app.events` where ts >= current_timestamp() - interval 1 day qualify rn = 1

After

SELECT
  user_id,
  event,
  ts,
  row_number() OVER (
    PARTITION BY
      user_id
    ORDER BY
      ts DESC
  ) AS rn
FROM
  `proj.app.events`
WHERE
  ts >= current_timestamp() - interval 1 DAY
QUALIFY
  rn = 1

Other SQL Dialects

Need to format SQL for other databases? Try our formatters for PostgreSQL, MySQL, SQL Server, or SQLite.

PostgreSQL MySQL SQL Server BigQuery SQLite MariaDB Redshift Snowflake