INTERVAL is really not a function. It is a datatype and an operator. In earlier version of PostgreSQL, you were allowed to 'sort of' use it as a function, but that no longer exists. Instead, try to either:
1.
cast your value to an interval datatype:
Code:
SELECT order_id FROM order
WHERE order_date + ((term ||'year')::interval)
< current_timestamp;
(see
2. Or, you can use the "interval" keyword as an operator to a timestamp representation, if you remove any ambiguity about the parentheses. (Meaning: if you need parentheses for your expression, then put "interval" in quotes:
Code:
SELECT order_id FROM order
WHERE order_date + ("interval" (term ||'year'))
< current_timestamp;
(see
and
I can't vouch for whether your query is correctly formed, though, since I don't know the table structure. But, I suggest you use more parentheses to remove ambiguity from your queries:
Code:
SELECT order_id FROM order
WHERE (order_date + ("interval" (term ||'year')))
< current_timestamp;
By the way, the reason for the changed behavior about parentheses affects
all date/time-related expressions: they all have an optional argument (p), which can be any number from 0 to 13 specifying the
precision you want from that value. (
So, your above query could be written:
Code:
SELECT order_id FROM order
WHERE (order_date + (interval (9) (term ||'year')))
< current_timestamp;
Thus, another thing to watch for now is that all timestamp, timestamptz, and interval expressions will default to full precision, which could mean you will see values like
Code:
2001-06-21 08:43:36.391869+02
instead of
. -------------------------------------------
Big Brother: "War is Peace" -- Big Business: "Trust is Suspicion"
(