Convert days added to a date to an INTERVAL

Proprietary

Replaces a number of days added to or subtracted from a date, as in Oracle's SYSDATE - 7, with an INTERVAL, as PostgreSQL cannot add a number to a timestamp. Column types are unknown, so the date must recognizably be one, such as SYSDATE, TRUNC(SYSDATE) or a TO_DATE call, and the days a literal or literals multiplied and divided, as in 1/24. A fraction of a day becomes INTERVAL '1 day' * 1/24, which PostgreSQL evaluates left to right rather than first dividing the integers to zero.

org.openrewrite.sql.ConvertDateArithmetic
mod run . --recipe=org.openrewrite.sql.ConvertDateArithmetic

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.