ziggy
ziggy

Reputation: 1538

postgresql update column from select

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

Upvotes: 11

Views: 33969

Answers (2)

Mahdi Moghimi
Mahdi Moghimi

Reputation: 568

I Use PgAdmin4 and last version of PostgreSQL and this query works for me:

update public."UserPoints"
set "AvailablePoints" = up."AvailablePoints" + tc."CLV"
from public."UserPoints" up join public."TEMPCLV" tc on up."UserId" = tc."CUSTOMER_NUMBER"

Hope help someone else!

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269445

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);

Upvotes: 13

Related Questions