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.

What lands in your log

ERROR: unit "fortnight" not recognized for type timestamp without time zone

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

In 10 seconds

What triggers it
Call date_trunc() with a field name that isn't in its accepted list, e.g. 'fortnight'.
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.

Fix

What to do right now

Application-level steps for 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');

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

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

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops