Answer the question
In order to leave comments, you need to log in
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
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.
appear
The question is how to tell postgres through a SQL query to wait until the data appears?
client.query(`SELECT column_name FROM table_name WHERE условие`, function (err, results) {
while (строки по запросу не найдены) {
// ждать n секунд (запрос пока не дошёл)
}
// отправить запрос при нахождении строк
})
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 questionAsk a Question
731 491 924 answers to any question