Reputation: 635
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); ANDupdated
value that is older (exclusively) than 24 hoursMy 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?
Upvotes: 0
Views: 3576
Reputation: 461
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
Upvotes: 5