invalid input syntax for type bigint: “…”

SQLSTATE 22P02 condition invalid_text_representation class 22 — Data Exception severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

A string given where a bigint was expected is not a valid integer. PostgreSQL raises SQLSTATE 22P02 (invalid_text_representation).

What the server log shows

ERROR:  invalid input syntax for type bigint: "12,345"

Why PostgreSQL raises this — what the manual says

Section 8.1.1 Integer Types:

“The bigint type is designed to be used when the range of the integer type is insufficient.”

The bigint input function parses the text as a base-10 integer. Anything that isn’t a clean integer (commas, decimals, letters, blank) cannot be parsed and is rejected with 22P02.

Common causes

How to fix it

  1. Strip separators/symbols and pass a clean integer.
  2. Use NULL (not '') for missing values.
  3. Round/cast decimals appropriately before insert (e.g. round(x)::bigint).

Related & next steps

Reference: PostgreSQL 18 Section 8.1 “Numeric Types”.