l1 POLYGON( (3 7, 5 7, 5 4, 3 4, 3 7 ) ) l2 POLYGON( (6 2, 11 2, 11 0, 6 0, 6 2) ) l3 POLYGON( (7 8 ,11 6 ,7 6 , 7 8 ) ) l4 POLYGON( (4 9, 7 9, 7 7, 4 7, 4 9 ) ) l5 POLYGON( (14 7, 15 8, 18 8, 19 7 , 19 6,18 5 , 15 5, 14 6 , 14 7 ) ) Q1 POLYGON( (2 9, 11 9 ,11 2,2 2, 2 9 ) ) Q2 POLYGON( (12 7, 14 11, 18 11, 20 7, 18 3, 14 3, 12 7 ) ) Questao 1: SELECT r2.id FROM exemplo_lotes r1, exemplo_lotes r2 WHERE touches (r1.geom, r2.geom) AND ( r1.id = 4 ) Questao 2: SELECT r2.id FROM exemplo_quadras q1, exemplo_lotes r2 WHERE within ( r2.geom , q1.geom ) AND ( q1.id = 1 ) Questao 3: insert into terceira_questao VALUES (1, 'resposta' , (SELECT (geomunion(r2.geom)) as geom FROM exemplo_quadras q1, exemplo_lotes r2 WHERE within ( r2.geom , q1.geom ) AND ( q1.id = 1 )) ) Questao 4: insert into exemplo_quadras_lotes SELECT r2.id as id , 'Lote' , r2.geom as geom FROM exemplo_lotes r2 , (select geomunion(q1.geom) as geo from exemplo_quadras q1) q2 WHERE not contains ( q2.geo , r2.geom ) insert into exemplo_quadras_lotes SELECT q.id as id , 'Quadra' , q.geom as geom FROM exemplo_quadras q