Request a demo

BigQuery error · Query and syntax errors

Syntax error: Expected end of input but got

The parser read a complete statement and then found more text it can't attach to it: a second statement without a semicolon, LIMIT before ORDER BY, ORDER BY before UNION ALL, or syntax from another dialect such as SELECT TOP. The token named in the message is where the extra text starts.

Error reason invalidQuery · HTTP 400 · Checked against the Google Cloud docs in November 2026

The error message

Syntax error: Expected end of input but got <token> at [<line>:<column>]

Causes

Two statements without a semicolon

SELECT 1 AS a followed by SELECT 2 AS b on the next line fails with Expected end of input but got keyword SELECT at [2:1]. Statements in a multi-statement query must end with ;.

Clauses after the end of the query

ORDER BY must come before LIMIT: SELECT 1 AS order_id LIMIT 1 ORDER BY 1 fails with Expected end of input but got keyword ORDER at [1:30]. In the same way, a UNION ALL after a branch that already has ORDER BY or LIMIT fails with got keyword UNION, unless that branch is in parentheses.

Syntax from another dialect

SELECT TOP 10 order_id FROM ... (SQL Server) reads TOP as a column and fails at the number: Expected end of input but got integer literal "10". Similar errors come from MySQL LIMIT 10, 20 or a - in an unquoted dataset or table name. PostgreSQL :: casts give a different message, CAST operators are not supported.

Text pasted after the query

Stray characters, an unfinished comment or notes left at the end of a scheduled query make the parser find a token after a complete statement.

How to fix it

1. End every statement with a semicolon

Separate statements with ; so BigQuery runs them as a multi-statement query.

CREATE TEMP TABLE recent_orders AS
SELECT order_id, customer_id, amount
FROM `project.dataset.orders`
WHERE order_date >= '2026-11-01';

SELECT customer_id, SUM(amount) AS revenue
FROM recent_orders
GROUP BY customer_id;

2. Use GoogleSQL clause order

Write ORDER BY before LIMIT and OFFSET, and put ORDER BY and LIMIT that apply to a whole UNION ALL after the last branch.

SELECT order_id, amount FROM `project.dataset.orders_2025`
UNION ALL
SELECT order_id, amount FROM `project.dataset.orders_2026`
ORDER BY amount DESC
LIMIT 10;

3. Translate dialect-specific syntax

Use LIMIT n instead of TOP n, LIMIT n OFFSET m instead of LIMIT m, n, CAST(x AS DATE) instead of x::date, and backticks around names with hyphens.

SELECT order_id, amount
FROM `my-project.sales.orders`
ORDER BY amount DESC
LIMIT 10 OFFSET 20;

How to prevent it

  • Validate scheduled queries and dbt models with a free dry run in CI before deploying them.
  • When migrating SQL from another warehouse, search for TOP, :: and LIMIT x, y before the first run.
  • Keep ORDER BY only where a person or a LIMIT needs it; a sort in a table-building query costs time and adds nothing.

FAQ

Is a query with this syntax error billed?

No. It fails while parsing, before BigQuery reads any data, so nothing is billed on-demand and no slots are used under editions.

Why does BigQuery say Expected end of input when my query looks complete?

Because it is complete at the point the parser stopped. Everything after that position, starting with the token in the message, is extra: usually a second statement, a misplaced clause or a token from another dialect.

Can I run several statements in one BigQuery query?

Yes, as a multi-statement query: separate the statements with semicolons. Each statement runs as a child job and the parent job shows the result of the last one.

SQL reference

More query and syntax errors

All BigQuery error messages · What 50M daily events say about BigQuery failures

Stop finding BigQuery failures in Slack threads

Masthead watches every BigQuery job, dbt model, Dataform action and Airflow task from audit logs, groups failures into incidents and shows which tables and dashboards are affected. No access to your data and no added BigQuery cost.