Postgresql Postgres仅按日期部分查询时间戳

Postgresql Postgres仅按日期部分查询时间戳,postgresql,date,query-performance,Postgresql,Date,Query Performance,我用它来尝试获取时间戳为今天的所有事件 SELECT systemuserid,ondate from auditlog WHERE ondate::date = NOW()::date 性能似乎非常差,超过2分钟。我有一个关于ondate的索引 有没有更有效的方法 谢谢使用范围条件: select * from auditlog where ondate >= current_date and ondate < current_date + 1; 选择* 从审核日志 其中

我用它来尝试获取时间戳为今天的所有事件

SELECT systemuserid,ondate from auditlog 
WHERE ondate::date = NOW()::date
性能似乎非常差,超过2分钟。我有一个关于ondate的索引

有没有更有效的方法

谢谢

使用范围条件:

select *
from auditlog
where ondate >= current_date
  and ondate < current_date + 1;
选择*
从审核日志
其中ondate>=当前日期
和ondate<当前日期+1;
current_date
将在午夜转换为时间戳,因此
ondate=>current_date
将包括从“今天”开始的所有内容

并且条件ondate将排除时间戳为明天(午夜)或更晚的行。

使用范围条件:

select *
from auditlog
where ondate >= current_date
  and ondate < current_date + 1;
选择*
从审核日志
其中ondate>=当前日期
和ondate<当前日期+1;
current_date
将在午夜转换为时间戳,因此
ondate=>current_date
将包括从“今天”开始的所有内容


条件
ondate
将排除时间戳为明天(午夜)或更晚的行。

谢谢,不到一秒钟就完成了!谢谢,不到一秒钟就完成了!