SQLSTATE 22007 ERROR Class 22: Data Exception

invalid_datetime_format invalid input syntax for type time: “…” — 22007

PostgreSQL error "invalid input syntax for type time: "…"" (SQLSTATE 22007): 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 time was expected does not parse as a valid time of day. PostgreSQL raises SQLSTATE 22007 (invalid_datetime_format).

  • Malformed time text or out-of-range hour/minute/second.
  • Common with bad separators or extra tokens.
  • The message echoes the offending value.

What the server log shows

ERROR:  invalid input syntax for type time: "25:61"

Why PostgreSQL raises this — what the manual says

Section 8.5.1 Date/Time Input:

“Date and time input is accepted in almost any reasonable format”

The time input function parses hours/minutes/seconds and validates their ranges. Malformed or out-of-range text cannot form a valid time and is rejected with 22007.

Common causes

  • Hour > 24 or minute/second out of range.
  • Wrong separators or extra characters.
  • An empty string instead of NULL.

How to fix it

  1. Use a valid HH:MM:SS format.
  2. Validate/normalize time strings in the application.
  3. Use NULL for missing values.

Related & next steps

Reference: PostgreSQL 18 Section 8.5 “Date/Time Types”.

Was this helpful?