[postgresql] How to add number of days in postgresql datetime

I have a following table projects.

id title        created_at                     claim_window
1  Project One  2012-05-08 13:50:09.924437     5
2  Project Two  2012-06-01 13:50:09.924437     10

A) I want to find the deadline with calculation deadline = created_at + claim_window(No. of days).

Something like following.

id title        created_at                     claim_window deadline
1  Project One  2012-05-08 13:50:09.924437     5            2012-05-13 13:50:09.924437
2  Project Two  2012-06-01 13:50:09.924437     10           2012-06-11 13:50:09.924437

B] I also want to find the projects whose deadline is gone

id title        created_at                     claim_window deadline
1  Project One  2012-05-08 13:50:09.924437     5            2012-05-13 13:50:09.924437

I try something like following.

SELECT * FROM "projects" WHERE (DATE_PART('day', now()- created_at) >= (claim_window+1))

But for some reason it is not working.

This question is related to postgresql datetime

The answer is


For me I had to put the whole interval in single quotes not just the value of the interval.

select id,  
   title,
   created_at + interval '1 day' * claim_window as deadline from projects   

Instead of

select id,  
   title,
   created_at + interval '1' day * claim_window as deadline from projects   

Postgres Date/Time Functions