I have a query that's something like this
select days, date(date_event) + interval '10' day from tbl_user_marketing_program as programtable
Now in place of the '10', I want to add the value present in the "days" column. How can I do that?
I tried select user_id, date(date_event) + interval user_id day from tbl_user_marketing_program as programtable
then I got the below error
ERROR: syntax error at or near "day" LINE 1: ...ect user_id, date(date_event) + interval user_id day from t...
Unfortunately the "number" for an interval can't be an arbitrary expression, it has to be a string constant (which is a strange choice). You need to use a little workaround:
select days, date(date_event) + (days * interval '1' day)
from tbl_user_marketing_program as programtable
But date + integer
is also directly supported and the unit is days in that case. So you can als write:
select days, date(date_event) + days
from tbl_user_marketing_program as programtable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With