Time 添加<;整数>;秒到a<;时间戳>;在PostgreSQL中
我有一个包含以下列的项目表:Time 添加<;整数>;秒到a<;时间戳>;在PostgreSQL中,time,casting,timedelta,Time,Casting,Timedelta,我有一个包含以下列的项目表: 开始时间列(无时区的时间戳) expiration\u time\u seconds列(integer) 例如,某些值是: SELECT start_time, expiration_time_seconds FROM whatever ORDER BY start_time; start_time | expiration_time_seconds --------------------------
列(开始时间
)无时区的时间戳
列(expiration\u time\u seconds
)integer
SELECT start_time, expiration_time_seconds
FROM whatever
ORDER BY start_time;
start_time | expiration_time_seconds
----------------------------+-------------------------
2014-08-05 08:23:32.428452 | 172800
2014-08-10 09:49:51.082456 | 3600
2014-08-13 13:03:56.980073 | 3600
2014-08-21 06:31:38.596451 | 3600
...
如何将过期时间(以秒为单位)添加到开始时间
我尝试为interval
命令格式化时间间隔字符串,但失败:
blah=> SELECT interval concat(to_char(3600, '9999'), ' seconds');
ERROR: syntax error at or near "("
LINE 1: SELECT interval concat(to_char(3600, '9999'), ' seconds');
方法是创建一个固定的间隔,并将其与列中的秒数相乘:
SELECT start_time,
expiration_time_seconds,
start_time + expiration_time_seconds * interval '1 second'
FROM whatever
ORDER BY start_time;
start_time | expiration_time_seconds | end_time
----------------------------|-------------------------|----------------------------
2014-08-05 08:23:32.428452 | 172800 | 2014-08-07 08:23:32.428452
2014-08-10 09:49:51.082456 | 3600 | 2014-08-10 10:49:51.082456
2014-08-13 13:03:56.980073 | 3600 | 2014-08-13 14:03:56.980073
2014-08-21 06:31:38.596451 | 3600 | 2014-08-21 07:31:38.596451
非常感谢你!您是否可以在
开始时间+到期时间\u秒
中添加空间,使其易于可视化?