Postgres here; I have a Users
table that has the following fields:
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
);
I want to write a query that fetches any Users
records that:
beginDate
value within the last 24 hours (inclusively); AND updated
value that is older (exclusively) than 24 hours My best attempt thus far is:
select *
from
Users
where
beginDate >= NOW() - INTERVAL 1 DAY and
updated < NOW() - INTERVAL 1 DAY
But this gives em the following error:
ERROR: syntax error at or near "1"
Position: 59
beginDate >= NOW() - INTERVAL 1 DAY and
^
1 statement failed.
Execution time: 0.03s
Any ideas on what the fix is?
The correct syntax would be this:
beginDate >= NOW() - INTERVAL '1 DAY' and
updated < NOW() - INTERVAL '1 DAY'
You can find more information here: https://www.postgresql.org/docs/current/functions-datetime.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.