PostgreSQL:从列值将时间间隔添加到时间戳记

编程入门 行业动态 更新时间:2024-10-24 13:25:54
本文介绍了PostgreSQL:从列值将时间间隔添加到时间戳记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要添加带有时间戳的整数列的分钟数才能与另一列进行比较。

I need to add minutes coming from an integer column with a timestamp to compare to another column.

这里是一个示例:

Here's an example:

SELECT t1.id_liame, t1.id_table, t1.periodicidade , t3.data_extracao, CASE WHEN(NOW() < (e.data_extracao + INTERVAL t1.periodicidade || ' MINUTES')) THEN 'yes' ELSE 'no' END FROM table1 as t1 LEFT JOIN liame_has_extracao as t2 USING(id_liame) LEFT JOIN extracao as t3 USING(id_extracao)

l.periodicidade 是整数(分钟) 我需要验证 data_extracao(timestamp)是否大于 NOW()+ l.periodicidade(整数-分钟)。

l.periodicidade is integer (minutes) I need to verify if data_extracao(timestamp) is greater then NOW() + l.periodicidade(integer - minutes).

我该怎么做?

推荐答案

您可以这样编写查询:

SELECT t1.id_liame, t1.id_table, t1.periodicidade, t3.data_extracao, CASE WHEN(NOW() < (t3.data_extracao + (INTERVAL '1 min' * t1.periodicidade))) THEN 'yes' ELSE 'no' END FROM table1 AS t1 LEFT JOIN liame_has_extracao AS t2 USING(id_liame) LEFT JOIN extracao AS t3 USING(id_extracao)

可以看到,您可以将间隔与整数相乘,因此使用 INTERVAL'1分钟'定义基本单位并乘以实际时间间隔。

As you can see, you can multiply intervals with integers so with INTERVAL '1 minute' you define your base unit and multiply your actual time interval.

希望有帮助

更多推荐

PostgreSQL:从列值将时间间隔添加到时间戳记

本文发布于:2023-10-13 09:49:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:戳记   时间   间隔   PostgreSQL   列值将

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!