Nitika
Nitika

Reputation: 215

Fetch rows which are updates in last one hour

In the schema of the database I have a field which of type timestamp. (For instance, 2021-05-25 16:48:34.686402, field populated with now())

The rows have to be fetched on the basis of this field, fetching only those records have the value in last 1 hour.

I am trying this query

select * from table_name 
WHERE last_updated_time > DATE_SUB(NOW(), INTERVAL 1 HOUR);

but it is giving the following error:

ERROR: syntax error at or near "1" Position: 98`

Need help on how this usecase can be solved.

Upvotes: 0

Views: 56

Answers (2)

Nitika
Nitika

Reputation: 215

This is the answer which worked here

select * from table_name WHERE last_updated_time >= (NOW() - INTERVAL '1 hour' );

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269603

The correct syntax in Postgres is:

select * 
from table_name 
where last_updated_time > now() - interval '1 hour';

Upvotes: 1

Related Questions