A
A
Anar Latifov2020-08-14 23:12:51
PostgreSQL
Anar Latifov, 2020-08-14 23:12:51

Data in db is requested before it appears, how to make it wait?

The question is without code, there are several interconnected projects on NODE JS, one adds data to the database, the other requests from there, since everything happens asynchronously, the data does not have time to reach the DB, but they are already being requested.
The question is how to tell postgres through a SQL query to wait until the data appears?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
de1m, 2020-08-14
@de1m

I think so, that in no way, it would somehow not fit into the concept of SQL.
It is necessary to make a queue, one writes something to it, and the next step only when the previous one has completed.

N
Nikolai Savelyev, 2020-08-15
@AgentSmith

appear

I think I'm in your place to organize a queue. For example RabbitMQ.
It is allowed to make the architecture more flexible.

A
Alexander, 2020-08-14
@Alexandre888

The question is how to tell postgres through a SQL query to wait until the data appears?

through sql - no way, but why do you need it? add a query to the if-statement that will check every second if another query has reached the base, and if it is true, run another query.
Or, you can implement it this way:
client.query(`SELECT column_name FROM table_name WHERE условие`, function (err, results) {
while (строки по запросу не найдены) {
// ждать n секунд (запрос пока не дошёл)
}
// отправить запрос при нахождении строк
})

E
edo1h, 2020-08-15
@edo1h

Either fit LISTEN/NOTIFY , or use a queuing mechanism external to the database.
BTW, the article discussed LISTEN/NOTIFY, but the comments weren't particularly warm to this approach.
My opinion: if we are talking about “wait for the data to arrive in the database”, then LISTEN / NOTIFY is great (and I have used it myself more than once), but if many loaded queues are needed, it is better to take ready-made implementations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question