简体   繁体   English

PostgreSQL时间戳和NULL的区别

[英]Postgresql timestamp and NULL difference

I'm novice in PostgreSQL. 我是PostgreSQL的新手。 I have a column timestamp without time zone named FailureTime . 我有一个没有时区的列时间戳,名称为FailureTime At the beginning it has NULL value. 一开始它具有NULL值。

When SELECT I need to get all entries that has current_timestamp - FailureTime > interval '7' . 当执行SELECT我需要获取所有具有current_timestamp - FailureTime > interval '7'条目。

But when FailureTime is NULL the result of operation is NULL. 但是,当FailureTime为NULL时,运算结果为NULL。 Can I cast NULL to ZERO value or somehow get just current_timestamp as result of the operation? 我可以将NULL强制转换为ZERO值还是以某种方式得到current_timestamp

current_timestamp - coalesce(FailureTime, current_timestamp) > interval '7'

You can exclude NULL elements by specifying something like: 您可以通过指定类似以下内容来排除NULL元素:

SELECT ... 
WHERE (FailureTime IS NOT NULL) 
AND (current_timestamp - FailureTime > interval '7')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM