1

In one column I have a create_dtm saved as timestamp in postgresql. Another column is integer wait_days. When I pull a row from the database I want to retrieve create_dtm + wait_days as a timestamp.

It seems I should be able to do this...will I have to do it in my application code?

My non-working sample looks like:

select name, title, create_dtm + wait_days
1
  • Is wait_days a string? If it is, you need to convert it to integer. Commented Mar 14, 2014 at 20:20

2 Answers 2

3

You can add integers to a date but not to a timestamp.

You can only add an interval to a timestamp value, so you need to "convert" the integer value to an interval of 1 day:

select name, title, create_dtm + interval '1' day * wait_days
from the_table;

SQLFiddle example: http://sqlfiddle.com/#!15/891f5/1

(The next time, please post the error message you get)

Sign up to request clarification or add additional context in comments.

Comments

0

If wait_days is of text or char type, it will not work. You need to convert it to integer, then this query should be ok:

select name, title, create_dtm + wait_days::integer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.