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
值; AND 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
对解决方法有何想法?
答案 0 :(得分:4)
正确的语法是这样:
beginDate >= NOW() - INTERVAL '1 DAY' and
updated < NOW() - INTERVAL '1 DAY'
您可以在此处找到更多信息:https://www.postgresql.org/docs/current/functions-datetime.html