# 62: SYNTAX_ERROR (code 62)

> The parser could not turn the statement text into a query tree; the message names the position and token.

Source: https://sqlly.app/errors/clickhouse/syntax-error
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error code: `62`
- Name: `SYNTAX_ERROR`
- Category: Syntax and parsing

Error message:

```text
Syntax error: failed at position {position}: {token}
```

## What it means

`SYNTAX_ERROR` (62) means the statement text is not valid ClickHouse SQL. The message gives the byte position and shows a fragment starting where parsing failed, so read that fragment first. Dialect differences from MySQL or Postgres are the most common cause.

## Common causes

- Dialect SQL sent unmodified: `ON DUPLICATE KEY` or `ON CONFLICT` clauses ClickHouse does not have. With `INSERT ... VALUES` these fail with code 27 CANNOT_PARSE_INPUT_ASSERTION_FAILED; with `INSERT ... SELECT` they fail with 62.
- A missing comma, quote or parenthesis before the fragment shown.
- A clause keyword with nothing valid before it, for example `SELECT * FROM WHERE id = 1;`, which fails at the `=` with code 62.

## How to fix it

1. Fix the fragment at the reported position; here the unfinished IN list just needs its list or subquery.

   ```sql
   SELECT * FROM my_table WHERE id IN (1, 2);
   ```
2. Identifiers can keep their backticks or use double quotes; strings take single quotes, so only the dialect clauses need rewriting.

   ```sql
   SELECT `id`, "name" FROM my_table LIMIT 10;
   ```
3. Quote identifiers that collide with keywords.

   ```sql
   SELECT "partition", "key" FROM my_table;
   ```

## Reproduce it safely

```sql
SELECT * FROM scratch_d WHERE id IN; in clickhouse-client returns Code: 62 SYNTAX_ERROR at position 36 (end of query): ;, the semicolon just after IN.
```

## How SQLly helps

When the server names the failing position, SQLly highlights that token in the editor, which is where MySQL-only dialect usually trips.

## Questions

### Why does my MySQL query fail?

ClickHouse is its own dialect. Rewrites are usually small: no ON DUPLICATE KEY, use a ReplacingMergeTree table and read with FINAL for upsert-like behavior; duplicate keys can stay visible until a background merge runs.

### The position points at the wrong token?

The position is where the parser gave up, which can trail the actual typo by a few tokens.

## Related errors

- [`47`](https://sqlly.app/errors/clickhouse/unknown-identifier): UNKNOWN_IDENTIFIER (code 47)
- [`53`](https://sqlly.app/errors/clickhouse/type-mismatch): TYPE_MISMATCH (code 53)

The code and message text are from the [ClickHouse documentation (system.errors)](https://clickhouse.com/docs/en/operations/system-tables/errors).
