22009
PostgreSQLERRORNotableData ExceptionHIGH confidence

invalid time zone displacement value

What this means

SQLSTATE 22009 is raised when a time zone offset or name specified in a timestamp or time value is not a valid time zone displacement. Valid offsets are in the range -15:59 to +15:59.

Why it happens
  1. 1Casting a timestamptz string with an invalid timezone offset (e.g., +25:00)
  2. 2Using a timezone name that does not exist in the pg_timezone_names catalogue
  3. 3Supplying an out-of-range numeric UTC offset
How to reproduce

Parsing a timestamp string with an invalid timezone offset.

trigger — this will error
trigger — this will error
SELECT '2024-01-01 12:00:00+25:00'::timestamptz;

expected output

ERROR:  time zone displacement out of range: "+25:00"

Fix 1

Use a valid timezone name or offset

WHEN When parsing or constructing timestamptz values.

Use a valid timezone name or offset
SELECT '2024-01-01 12:00:00+05:30'::timestamptz; -- valid IST offset

Why this works

UTC offsets must be in [-15:59, +15:59]. Use a timezone name from pg_timezone_names for named zones.

Fix 2

Validate input timezone strings before casting

WHEN When accepting timezone data from external sources.

Validate input timezone strings before casting
SELECT name FROM pg_timezone_names WHERE name = :tz_input;

Why this works

Checking pg_timezone_names confirms the timezone exists before using it in a cast.

Sources
Official documentation ↗

Class 22 — Data Exception

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors