SQLSTATE 22023Severity lowLab verified

Incident brief

date_trunc invalid field

date_trunc() was called with a field name it doesn't recognize. PostgreSQL rejected the call instead of guessing what precision was meant.

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
date_trunc invalid field
What triggers it
Call date_trunc() with a field name that isn't in its accepted list, e.g. 'fortnight'.
The fix
Use one of date_trunc()'s accepted field names instead: microseconds, milliseconds, second, minute, hour, day, week, month, quarter, year, decade, century, or millennium.
Proof
Reproduced on PostgreSQL 16.14 → date_trunc('fortnight', <timestamp>) was rejected with SQLSTATE 22023, because 'fortnight' is not one of date_trunc's accepted field names.

The fix

What to do right now

The immediate, application-level response to this error.

  • Use one of date_trunc()'s accepted field names instead: microseconds, milliseconds, second, minute, hour, day, week, month, quarter, year, decade, century, or millennium.
  • Don't assume a field name that works with EXTRACT() also works with date_trunc() — see the premium counterexample for 'dow'.
Fix — SQL
SELECT date_trunc('week', TIMESTAMP '2024-03-15 14:30:00');

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed