日期比较Postgresql [英] Date compare in Postgresql

查看:407
本文介绍了日期比较Postgresql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SELECT * FROM mytable WHERE date_1 = date_2 ; 

我正在寻找最简单的做法作为更新语句的一部分。

解决方案

是的,你可以这样做。



看看 date / time PostgreSQL中的数据类型



如果您的日期实际上是时间戳,则可能需要特别注意。默认情况下保存最多6个小数位数。而分数可能会与等式运算符相当棘手。



如果您不需要精确度超过秒数,建议使用在这种情况下,timestamp(0)。精确度修正符(0)确定使用多少个小数位数,不带(0)的小数位数。对 = 进行平等检查更容易。


Is there a way to compare two dates in the same table like this:

SELECT * FROM mytable WHERE date_1 = date_2;

I am looking for the simplest approach to do this as part of an update statement.

解决方案

Yes, you can do that. Simple as that.

Have a look at the date / time data types in PostgreSQL.

You may have to pay special attention if your "date", in fact, is a timestamp. By default up to 6 fractional digits are saved. And fractional numbers can turn out to be tricky with the equality operator.

If you don't need precision beyond seconds, I would suggest to use timestamp(0) in such a case. The precision modifier (0) determines how many fractional digits are used, no fractional digits with (0). Makes equality checks with = easier.

这篇关于日期比较Postgresql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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