如何添加两列类型的时间戳记和整数 [英] How to add two columns of type timestamp and integer

查看:87
本文介绍了如何添加两列类型的时间戳记和整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆