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
值在过去 24 小时内(含); 和- 有一个
更新的
值早(绝对)超过 24 小时
到目前为止我最好的尝试是:
select *
from
Users
where
beginDate >= NOW() - INTERVAL 1 DAY and
updated < NOW() - INTERVAL 1 DAY
但这给他们带来了以下错误:
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
关于sql - 时间戳间隔的 Postgres 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55620281/