This works:
SELECT "date", "value"::Int, "date" interval '1' day AS "computed"
FROM "tab1"
but what if I want to add a variable from the table to a timestamp?
SELECT "date", "value"::Int, "date" interval "value" day AS "computed"
FROM "tab1"
This fails.
CodePudding user response:
An interval is like a number, and can be multiplied
SELECT "date", "value"::Int, "date" interval '1' day * "value" AS "computed"
FROM "tab1"
Not sure if your cast to int was indicative of it being e.g. some decimal like 1.5, but if it is then 1.5 days would be added. If you want just the integral part of value
to matter, then consider something like "date" interval '1' day * "value"::int