SQLSTATE 22P02 ERROR Class 22: Data Exception

invalid_text_representation invalid input syntax for type bigint: “…” — 22P02

PostgreSQL error "invalid input syntax for type bigint: "…"" (SQLSTATE 22P02): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

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

  • Non-numeric text, decimals, or stray characters in an integer field.
  • Common with empty strings or thousands separators.
  • The message echoes the offending value.

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

  • Thousands separators or currency symbols in the value.
  • An empty string passed instead of NULL.
  • A decimal value where an integer is required.

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”.

Was this helpful?