I am attempting to update a column from one table with a select query.
It runs and updates the entire type_
column as religious
(text field).
I am trying to only update the rows where the religious geometry intersects the parcel geometry.
update wash_parcels_final
set type_ = t.religious
from (select wash_worship.religious
from wash_parcels_final
join wash_worship
on st_intersects(wash_worship.geom, wash_parcels_final.geom)) t
The select ... for update acquires a ROW SHARE LOCK on a table. This lock conflicts with the EXCLUSIVE lock needed for an update statement, and prevents any changes that could happen concurrently. All the locks will be released when the transaction ends.
The SELECT FOR UPDATE statement is used to order transactions by controlling concurrent access to one or more rows of a table. It works by locking the rows returned by a selection query, such that other transactions trying to access those rows are forced to wait for the transaction that locked the rows to finish.
PostgreSQL implements multiversioning by keeping the old version of the table row in the table – an UPDATE adds a new row version (“tuple”) of the row and marks the old version as invalid. In many respects, an UPDATE in PostgreSQL is not much different from a DELETE followed by an INSERT .
I think this is what you want:
update wash_parcels_final
set type_ = ww.religious
from wash_worship ww
where st_intersects(ww.geom, wash_parcels_final.geom);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With