0

In PostgreSQL:

Let say:

SELECT DATE(NOW())+interval '1 day';

It will show date tomorrow.

Problem:
While I having a column duration in table tbl, following SQL does not work :

 SELECT DATE(NOW())+interval duration || ' day' from tbl;

I just wondering how to make the '1 day' become a variable instead of a constant.

arne
  • 4,514
  • 1
  • 28
  • 47
Rakesh K
  • 692
  • 4
  • 13
  • 26
  • very similar question and good answer here: http://stackoverflow.com/questions/7796657/using-a-variable-period-in-an-interval-in-postgres – mechanical_meat Nov 22 '13 at 06:05

1 Answers1

2

Do not try to make '1day' a variable, just multiply it by duration variable:

SELECT DATE(NOW()+duration * INTERVAL '1day') FROM tbl;
Jerzy Pawlikowski
  • 1,751
  • 19
  • 21