guyforlowbro
guyforlowbro

Reputation: 361

How to get data that was createdAt or updatedAt 30 seconds from the the current time PostgreSQL

I'm trying to access data from a table that was created or updated data 30 seconds from the current time. Does anyone have any good idea of how to do this efficiently? I'm using node.js and pg package in npm. I want to grab the newly created/updated data to sync with elasticsearch.

Upvotes: 2

Views: 1543

Answers (1)

user330315
user330315

Reputation:

The rows that were created exactly 30 seconds ago:

select *
from the_table
where createdat = current_timestamp - interval '30' second

The rows that were created between 30 seconds ago and now:

select *
from the_table
where createdat >= current_timestamp - interval '30' second

Upvotes: 3

Related Questions