0

If I have table with a two columns:

  • date (timestamp)
  • milliseconds (int)

How could I write a query that would return the two columns and a third column that represents a sum of the first two as a timestamp.

Like this:

            date            | milliseconds  |              sum          
----------------------------+---------------+----------------------------
 2014-12-10 17:43:47.554989 |         11882 | 2014-12-10 17:43:59.436989

Thanks!

0

3 Answers 3

1

I think you answer is as follows:

# select date, milliseconds, date+milliseconds*interval '1 milliseconds' as sum from temp;

             date            | milliseconds |            sum
 ----------------------------+--------------+----------------------------
  2014-12-10 17:43:47.554989 |        11882 | 2014-12-10 17:43:59.436989
 (1 row)

I created a temp table with your timestamp field called date, and your int field called milliseconds. Then ran the above select off the table with your values in it. Hope this helps.

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

Comments

0

Simply add it as an interval:

select stamp + (ms / 1000) * '1 second'::interval

Comments

0

The value you are looking for is

 date + milliseconds * INTERVAL '1 MILLISECOND';

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.