Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 博士后将“现在”(仅限时间)与“现在”(仅限时间)进行比较_Postgresql_Time - Fatal编程技术网

Postgresql 博士后将“现在”(仅限时间)与“现在”(仅限时间)进行比较

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'); 从表中选择*,其中时间列

我有一列是没有时区的时间(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 < 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
无疑是更好的选择。