BigQuery error · Query and syntax errors
Syntax error: Unexpected keyword
The parser reached a reserved keyword where it can't be used: most often a reserved word used as a column, alias or table name (END, ORDER, GROUP, RANGE, ROWS, HASH...), or a clause written in the wrong place. Go to the line and column in the message and quote the name with backticks or move the clause.
The error message
Syntax error: Unexpected keyword <KEYWORD> at [<line>:<column>]
Causes
A reserved keyword used as a name
GoogleSQL reserves words such as END, ORDER, GROUP, FROM, RANGE, ROWS, HASH, PROTO, ALL and LIMIT. SELECT 1 AS order_id, 'paid' AS end fails with Unexpected keyword END at [1:33]. Columns called order, group or range coming from another database are a common source.
A clause in the wrong order
GoogleSQL clauses have a fixed order: SELECT, FROM, WHERE, GROUP BY, HAVING, QUALIFY, WINDOW, ORDER BY, LIMIT. When several continuations would be valid at the point of the mistake, the parser doesn't list them and reports the keyword it got instead.
Syntax from another SQL dialect
Keywords placed the way PostgreSQL, MySQL or SQL Server allow but GoogleSQL doesn't, such as a join type written in the wrong position (JOIN LEFT instead of LEFT JOIN), end up as unexpected keywords.
A missing comma or parenthesis just before
The reported position is where the parser gave up, which is often one token after the real mistake. Look at the previous token as well: an unclosed parenthesis or a missing comma before a keyword produces the same error.
How to fix it
1. Quote reserved words with backticks
Backticks turn any keyword into an identifier, for columns, aliases and table names.
SELECT
order_id,
`end` AS ended_at,
`range` AS price_range
FROM `project.dataset.orders`;2. Rename the alias
For aliases you control, pick a non-reserved name: ended_at instead of end, sort_order instead of order.
SELECT 1 AS order_id, 'paid' AS order_status;3. Put clauses in GoogleSQL order
Filters on aggregates go in HAVING after GROUP BY, filters on window functions go in QUALIFY, and ORDER BY and LIMIT come last.
SELECT customer_id, SUM(amount) AS revenue
FROM `project.dataset.orders`
WHERE order_date >= '2026-11-01'
GROUP BY customer_id
HAVING SUM(amount) > 1000
ORDER BY revenue DESC
LIMIT 50;How to prevent it
- Use the console's query validator or a free dry run (
bq query --dry_run) in CI for scheduled queries and dbt models, so syntax errors never reach production runs. - Rename reserved-word columns when you migrate tables from other databases instead of quoting them in every query.
- Keep one formatter for SQL in the repository; consistent line breaks make the
[line:column]position easy to find.
FAQ
Am I charged for a query with a syntax error?
No. Syntax errors are caught while parsing, before any data is read, so nothing is billed on-demand and no slot time is used under editions.
What does at [3:14] mean in a BigQuery error?
Line 3, column 14 of the query text, counting from 1. In the console, the editor highlights the position; the real mistake is often the token just before it.
What is the difference between Unexpected keyword and Expected end of input?
Both come from the parser. If only a few tokens could follow at that point, BigQuery names them (for example Expected end of input but got); if many could, it only reports the unexpected token.
Related
SQL reference
More query and syntax errors
All BigQuery error messages · What 50M daily events say about BigQuery failures
