hotmeatballsoup
hotmeatballsoup

Reputation: 635

Postgres syntax error on timestamp interval

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:

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?

Upvotes: 0

Views: 3576

Answers (1)

Matias Fuentes
Matias Fuentes

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

Related Questions