invalid time zone displacement value
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.
- 1Casting a timestamptz string with an invalid timezone offset (e.g., +25:00)
- 2Using a timezone name that does not exist in the pg_timezone_names catalogue
- 3Supplying an out-of-range numeric UTC offset
Parsing a timestamp string with an invalid timezone offset.
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.
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.
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.
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev