I have 2 tables, table #1 contains a square polygon/grid, table #2 contains the polygon of an administrative area. I updated table #1 with data from table #2 with the ST_Intersects() function. Here's an example of my query:
update table_grid
set data1 = table_administrative.data1
from table_administrative
where ST_Intersects(table_grid.geom, table_administrative.geom)
How will the query run? and what about grids that have intersections in two or more administrative regions? Will it be chosen randomly, or the largest region, or based on the centroid?
An example of the case is as shown in the picture

Randomly, due to how
update..fromworks:Even if you see some repeatability in which ones it ends up using, it's unreliable. That being said, you can correct your query to explicitly select the specific one you want, based on your own criteria, like the proximity of centroid, overlapping area, or just picking the one with lower/earlier id, alphabetically.
Add a subquery with
distinct on,order by..limit 1orrow_number()over(). The<<->>bbox centroid distance operator might be useful: demoYou might also be interested in
ST_Subdivide(). If you subdivide the administrative areas with it, all thesejoins (and yourupdatethat joins implicitly) will be way faster. It'll also be a bit safer to downgradeST_Intersects()to plain bounding box intersection&&for added performance in case you plan to stick with the "direct" update, not minding the randomly resolved ties: