[GIS] Update postgres/postgis point data attribute from another enclosed polygon shapefile in QGIS

postgispostgresqlqgisshapefile

I have

  1. a placename point table in postgis with 'district' column.

  2. a districts polygon shapefile with district name in 'Name' column.
    See the image below.

I would like to update the 'district' columns(in placename psql table) with the corresponding district name from the shapefile polygons in which each placename point feature reside.

How can I do this in QGIS?
Or Is there any other way?
enter image description here

Best Answer

Postgis way : (import polygon shape to postgis using shp2psql )

UPDATE points SET district = poly.district FROM poly WHERE ST_Within(points.geom, poly.geom)

see ST_Within

and i cant remember easy QGIS way , but its possible

Related Question