postgresql - How to update a table in postgis using ST_Intersects -
i have 1 2 tables in postgis. 1 bank point , indiastate polygon. both of tables having column named state. bank state column empty , indiastate table state column having name of state. want populate state column in bank table using st_intersects. able select bank points falling under particular state
select st_intersection("indiastate".geom, tn_bank.geom) inter "bank_name", "lat" "indiastate" inner join tn_bank on st_intersects("indiastate".geom, tn_bank.geom) "indiastate".state='kerala'
the above sql returning 66 rows correct.
but update command not working properly
update tn_bank set "state"='kerala' (select st_intersection("indiastate".geom, tn_bank.geom) inter "bank_name", "lat" "indiastate" inner join tn_bank on st_intersects("indiastate".geom, tn_bank.geom) "indiastate".state='kerala')x
it updating of rows in bank table. kindly help.
- you don't have specify target table in clause, in range table
- you need link/associate target table source-table(s), moved on() clause clause
update tn_bank dst set "state" = 'kerala' "indiastate" src st_intersects(src.geom, dst.geom) , src.state = 'kerala' ;
since not using fields froum source table (and more 1 row satisfy intersects()), can move src table exists() check:
update tn_bank dst set "state" = 'kerala' exists ( select * "indiastate" src src.state = 'kerala' , st_intersects(src.geom, dst.geom) );
Comments
Post a Comment