Skip to main content
Normalizes an INTERVAL by moving whole days out of its time part, whole months out of its days part, or both. An interval keeps months, days, and time separately, so INTERVAL '50 hours' stays 50 hours until you justify it.
  • JUSTIFY_HOURS turns each 24 hours of the time part into one day.
  • JUSTIFY_DAYS turns each 30 days into one month.
  • JUSTIFY_INTERVAL does both, then makes all three parts carry the same sign.

Syntax

Parameters

Return type

INTERVAL. If <interval> is NULL, the result is NULL.

Remarks

  • A day is always 24 hours and a month is always 30 days, regardless of calendar or daylight saving time. Adding a justified interval to a timestamp can therefore give a different result than adding the original one.
  • JUSTIFY_HOURS and JUSTIFY_DAYS also fix the sign of the part they carry into: a positive day count with a negative time part borrows one day, and the other way around. JUSTIFY_INTERVAL applies the same rule across months, days, and time, so 1 mon -01:00:00 becomes 29 days 23:00:00.
  • If a carry does not fit the 32-bit day or month count, the function raises interval out of range.
  • The three functions are compatible with PostgreSQL’s functions of the same names.

Examples

Each function on its own
Mixed signs
JUSTIFY_HOURS leaves the month alone, because it only moves time into days. JUSTIFY_INTERVAL borrows from the month so that every part is positive.