<div dir="ltr"><div><div>Hi,</div><div><br></div><div>What about a simple left join on the table searching for polygons contained inside other polygon ?</div><div>Polygons
that are contained inside other polygons will have false for the
outer_pg column and true if they are not contained (ie are outer
polygons).</div><div>You can then create the tables you want based on the outer_pg values<br></div><font size="2"><span style="color:rgb(204,120,50)"></span></font><br><div><font size="2"><span style="color:rgb(204,120,50)"></span></font><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"Consolas",monospace"><font size="2"><span style="color:rgb(204,120,50)"><span style="color:rgb(204,120,50)">select distinct </span>p1.<span style="color:rgb(152,118,170)">id</span><span style="color:rgb(204,120,50)">, </span>p2.<span style="color:rgb(152,118,170)">id </span><span style="color:rgb(204,120,50)">is null as </span>outer_pg<br><span style="color:rgb(204,120,50)">from </span>polygon p1<br> <span style="color:rgb(204,120,50)">left join </span>polygon p2 <span style="color:rgb(204,120,50)">on </span>p1.<span style="color:rgb(152,118,170)">id </span><> p2.<span style="color:rgb(152,118,170)">id </span><span style="color:rgb(204,120,50)">and </span><span style="color:rgb(255,198,109);font-style:italic">st_within</span>(p1.<span style="color:rgb(152,118,170)">geom</span><span style="color:rgb(204,120,50)">, </span>p2.<span style="color:rgb(152,118,170)">geom</span>)<br><span style="color:rgb(204,120,50)">order by </span>p1.<span style="color:rgb(152,118,170)">id</span><span style="color:rgb(204,120,50)">;<br><br>id outer_pg<br>1 true<br>2 true<br>3 true<br>4 true<br>5 false<br>6 false<br>7 false<br>8 true<br>9 true<br>10 true<br>11 false<br><br><br></span></span></font></pre></div></div></div><div>Nicolas</div></div>