-
Hi, let mut result_stream = sqlx::query!("SELECT * FROM t1 FOR UPDATE") // FOR UPDATE locks the row
.fetch(&mut conn)
.await?;
while let Some(x) = result_stream.try_next().await? {
// ...
} Will this lock all the rows in the table when the stream is returned from the query, or will it lock each row when I call Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The query itself will be executed on the first call to It is at that point that the rows should be locked, although the exact details depend on the database. Note that for the lock to be effective, the query needs to be executed in a transaction. |
Beta Was this translation helpful? Give feedback.
The query itself will be executed on the first call to
.try_next().await
as there is no.await?
for.fetch()
.It is at that point that the rows should be locked, although the exact details depend on the database.
Note that for the lock to be effective, the query needs to be executed in a transaction.