I use Spring Data Jpa to work with the Postgres database. When accessing the database, the following query is generated:
select
user0_.user_id as user_id1_0_,
user0_.birthday as birthday2_0_,
user0_.username as username3_0_
from
users user0_
where
user0_.username=$1
limit $2
for update of user0_ skip locked
Examples on the Internet usually indicate that columns are specified after for update of, but a table is specified here in the query. What will be blocked in this case? The whole row?
While the
FROMclause only includes a single table (users AS user0_in the example), there is effectively no difference betweenFOR UPDATE OF user0_and simplyFOR UPDATE. But it makes a difference with multiple tables in theFROMclause.The manual explains in depth:
And no, you cannot list columns there in Postgres. Only tables. Postgres locks selected rows with this clause. Not columns.