如何从 Postgresql 中的 CURRENT_TIMESTAMP 中提取时间

How to extract time from CURRENT_TIMESTAMP in Postgresql

正如我们能够使用 date(CURRENT_TIMESTAMP) 从 Postgresql 中的时间戳中提取日期一样,我想知道是否存在提取时间的等效函数。 (格式为 hh:mm:ss)

我希望能够使用 SQL 查询将存储在具有时间数据类型的列中的时间值(参见 https://www.postgresql.org/docs/current/datatype-datetime.html)与当前时间进行比较。

欢迎提出任何建议!

您可以使用 current_time 或将时间戳转换为时间:current_timestamp::time

例如

where the_time_column >= current_time - interval '6' hour

有关详细信息,请参阅 Postgres 手册中的Current Date/Time