如何添加两列类型的时间戳记和整数 [英] How to add two columns of type timestamp and integer
问题描述
我是PostgreSQL的新手,某些功能与MYSQL不同。我想在表中添加两列,其中一列是不带时区的时间戳
类型,另一列是 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
.
表格如下:
Startime:2015-02-09 19:00:00 < br>
持续时间(秒):10
Startime: 2015-02-09 19:00:00
Duration(seconds): 10
我希望输出结果为:
星级时间:2015-02-09 19:00:00
Star time: 2015-02-09 19:00:00
持续时间:10
结束时间:2015-02-09 19:00:10
Duration: 10
Endtime : 2015-02-09 19:00:10
推荐答案
将持续时间转换为间隔,然后添加:
Convert your duration to an interval then add:
select
start_time + ( duration_seconds * interval '1 second' )
from my_table;
您应该使用snake_case作为Postgres标识符,并且不要使用关键字作为标识符。相信我。
You should use snake_case for Postgres identifiers, and don't use keywords as identifiers. Trust me.
这篇关于如何添加两列类型的时间戳记和整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!