swat
swat

Reputation: 21

How to add two columns of type timestamp and integer

I am new with PostgreSQL and some of the functions are different from MYSQL. I am trying to add two columns in the table of which one is timestamp without time zone type and the other is integer.

The table looks like this:

Startime: 2015-02-09 19:00:00
Duration(seconds): 10

I want the output to give:

Star time: 2015-02-09 19:00:00

Duration: 10
Endtime : 2015-02-09 19:00:10

Upvotes: 1

Views: 500

Answers (1)

Neil McGuigan
Neil McGuigan

Reputation: 48267

Convert your duration to an interval then add:

select
  start_time + ( duration_seconds * interval '1 second' )
from my_table;

You should use snake_case for Postgres identifiers, and don't use keywords as identifiers. Trust me.

Upvotes: 4

Related Questions