Postgres在这里;我有一个Users
表,其中包含以下字段:
create table Users (
id bigserial primary key,
isAdmin boolean not null default false,
beginDate timestamp with time zone not null,
updated timestamp with time zone
);
我想写一个查询来获取任何Users
记录:
beginDate
值;和updated
值比24小时更长(独家)到目前为止,我最好的尝试是:
select *
from
Users
where
beginDate >= NOW() - INTERVAL 1 DAY and
updated < NOW() - INTERVAL 1 DAY
但这会给em带来以下错误:
ERROR: syntax error at or near "1"
Position: 59
beginDate >= NOW() - INTERVAL 1 DAY and
^
1 statement failed.
Execution time: 0.03s
关于解决方案的任何想法?
正确的语法是这样的:
beginDate >= NOW() - INTERVAL '1 DAY' and
updated < NOW() - INTERVAL '1 DAY'
您可以在这里找到更多信息:https://www.postgresql.org/docs/current/functions-datetime.html