Postgresql 博士后将“现在”(仅限时间)与“现在”(仅限时间)进行比较
我有一列是没有时区的时间(24小时时间),即11:30:10(上午11:30,10秒) 我如何将其与现在进行比较,即如果此列大于现在(如果在上午11点之后查询,则返回true) 比如:Postgresql 博士后将“现在”(仅限时间)与“现在”(仅限时间)进行比较,postgresql,time,Postgresql,Time,我有一列是没有时区的时间(24小时时间),即11:30:10(上午11:30,10秒) 我如何将其与现在进行比较,即如果此列大于现在(如果在上午11点之后查询,则返回true) 比如: select * from table where time_column < date_part(now(), 'HH:MM:SS'); 从表中选择*,其中时间列
select * from table where time_column < date_part(now(), 'HH:MM:SS');
从表中选择*,其中时间列
找到了答案
您可以使用:
select * from table where time_column < localtime
从time\u列
注意,此操作与以下操作相同:
select * from table where time_column < to_timestamp(to_char(now(),'HH:MM:SS'),'HH:MM:SS')::time;
从表中选择*,其中time_列
我认为当前的答案有问题
因为to_timestamp(to_char(now(),'HH:MM:SS'),'HH:MM:SS')::time
表示MM是月范围[0-12],而不是分钟范围。在数据库时间列中,您应该使用24小时时间格式,因此这里再次使用。
HH24
select to_timestamp(to_char(now(),'HH24:MI:SS'),'HH24:MI:SS')::time;
to_timestamp(to_char(now(),'HH:MM:SS'),'HH:MM:SS'):时间代码>是一种复杂的方法。一个简单的current\u timestamp::time
也可以实现同样的效果。但是使用current\u time
或localtime
无疑是更好的选择。