<html>
<head>
        <title></title>
        
<meta content="MSHTML 6.00.2900.5726" name="GENERATOR"></meta>
</head>

<body>
        
<div>Hi </div>
        
<div> </div>
        
<div>first, I think you get also the polygons partly within when you are using st_dwithin like that. St_within only gets the polygons comlpetly within.</div>
        
<div> </div>
        
<div>second, In your query you don't tell the database how to link the table T1 outside the subquery with the tables inside the subquery. T1 inside and outside the subquery is handled independent from eachother. I'm supriseed it works at all.</div>
        
<div>This should will work instead:</div>
        
<div>update T1 set new_column = T2.fourth_column from T2 where st_dwithin(T1.polygon, T2.multipolygon, 0.0);</div>
        
<div> </div>
        
<div>/Nicklas</div>
        
<div><br />
                2009-03-27 Jorge ArĂ©valo wrote:<br />
                <br />
                Hello everybody,<br />
                ><br />
                >I have 2 tables:<br />
                ><br />
                >T1: 8 columns. 1 geometry column of type polygon. UTM coords. Thousands<br />
                >of rows<br />
                >T2: 4 columns. 1 geometry column of type multipolygon. UTM coords. 29<br />
                >rows. Each multipolygon has thousands of polygons.<br />
                ><br />
                >I need to add a new column to T1. The new column's value will be taken<br />
                >from one of the T2's fields (the 4th one). For each row of T1, I have to<br />
                >find the multipolygon of T2 that contains the polygon of T1. When<br />
                > matchs, I have to update the new T1's column with the value of 4th<br />
                >column of the T2 matching row.<br />
                ><br />
                >I'm trying something like this:<br />
                ><br />
                >UPDATE T1 SET new_column = (SELECT T2.fourth_column from T1 JOIN T2<br />
                > ON ST_DWithin(T1.polygon, T2.multipolygon, 0.0))<br />
                ><br />
                >Yes, I know that I can use ST_Within(T1.polygon, T2.multipolygon)), but<br />
                >I would need PostGIS with GEO support, and I can't compile it again.<br />
                ><br />
                >Anyway, my big problem is that the query takes really LONG time. More<br />
                > than 1 hour. And I have to translate this test to a bigger enviroment<br />
                >(bigger tables). I' ve created index on the geometry columns in both<br />
                >tables, but doesn't seem to be enough...<br />
                ><br />
                >Any clues?<br />
                ><br />
                >Thanks in advance<br />
                > Jorge <br />
                ></div>
</body>
</html>