我想在 Postgres 中创建一个过期条件。我有一个变量last_sync::timestamp
和一个限制86400 * 30
秒。我试过这种方式:
NOW() - last_sync > 86400 * 30
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误:区间 > 整数没有运算符。
即使last_sunc
是,我也想让它工作-infinity
。
我怎样才能正确地进行这种比较?
使用时间间隔 ==>日期/时间函数和运算符
create table asd(
name varchar(20),
last_sync timestamp
)
;
insert into asd values( 'one', now() - interval '500' hour );
insert into asd values( 'two', now() - interval '1500' hour );
SELECT *
from asd
where NOW() - last_sync > ( 86400 * 30 ) * INTERVAL '1' second
name |last_sync |
-----|--------------------|
two |2016-10-26 00:52:16 |
Run Code Online (Sandbox Code Playgroud)
如果 last_sync 是 -infinity,如何使其工作?– 北落师门 5 分钟前
insert into asd values( 'one', now() - interval '500' hour );
insert into asd values( 'two', now() - interval '1500' hour );
insert into asd values( 'minus infinity', timestamp '-infinity' );
insert into asd values( 'plus infinity', timestamp 'infinity' );
SELECT *
from asd
where last_sync > NOW() - ( 86400 * 30 ) * INTERVAL '1' second
name |last_sync |
--------------|-------------------------|
one |2016-12-06 15:52:12 |
plus infinity |292278994-08-17 00:00:00 |
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9818 次 |
最近记录: |