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_HOURSturns each 24 hours of the time part into one day.JUSTIFY_DAYSturns each 30 days into one month.JUSTIFY_INTERVALdoes 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_HOURSandJUSTIFY_DAYSalso 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_INTERVALapplies the same rule across months, days, and time, so1 mon -01:00:00becomes29 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.