在postgresql选择中,将timestamp列添加到another_days列 [英] In a postgresql select, add a timestamp column to an additional_days column

查看:80
本文介绍了在postgresql选择中,将timestamp列添加到another_days列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一栏中,我有一个create_dtm保存为postgresql中的时间戳。另一列是整数wait_days。当我从数据库中拉出一行时,我想检索create_dtm + wait_days作为时间戳。

In one column I have a create_dtm saved as timestamp in postgresql. Another column is integer wait_days. When I pull a row from the database I want to retrieve create_dtm + wait_days as a timestamp.

似乎我应该能够执行此操作...我是否必须在应用程序代码中执行此操作?

It seems I should be able to do this...will I have to do it in my application code?

我的非工作示例如下:

select name, title, create_dtm + wait_days


推荐答案

您可以将整数添加到日期,但没有时间戳

You can add integers to a date but not to a timestamp.

您只能将 interval 添加到时间戳值,因此需要将整数值转换为间隔1天:

You can only add an interval to a timestamp value, so you need to "convert" the integer value to an interval of 1 day:

select name, title, create_dtm + interval '1' day * wait_days
from the_table;

SQLFiddle示例: http://sqlfiddle.com/#!15/891f5/1

SQLFiddle example: http://sqlfiddle.com/#!15/891f5/1

(下次请发布您收到的错误消息)

(The next time, please post the error message you get)

这篇关于在postgresql选择中,将timestamp列添加到another_days列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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