postgresql interval 字段拼接

无拼接时:

SELECT scan_time + '5 day' FROM tbl_temp_record

SELECT scan_time + '-5 day' FROM tbl_temp_record

拼接字段时:

SELECT scan_time + 5 || ' day' FROM tbl_temp_record 报错
ERROR: operator does not exist: timestamp without time zone + integer
SQL 状态: 42883
SELECT scan_time + '5' || ' day' FROM tbl_temp_record 不是想要的结果

正确写法:

SELECT scan_time + (5 || ' day')::interval FROM tbl_temp_record

SELECT scan_time + ('-' || 5 || ' day')::interval FROM tbl_temp_record

SELECT scan_time + 5*interval '1 day' FROM tbl_temp_record

SELECT scan_time + 5*interval '-1 day' FROM tbl_temp_record
————————————————
版权声明:本文为CSDN博主「宫辰雅轩」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/r_rcgz/article/details/53171256

posted @ 2021-07-11 10:46  疯子110  阅读(321)  评论(0编辑  收藏  举报