I need to know which points from Table 1 are contained in Table 2.

In Table 1 I have longitude and latitude and I made points with ST_SetSRID(ST_MakePoint(d.longitude, d.latitude),4326) as geom

Table 2 has a collection of multipolygons: geom geometry(MultiPolygon,4326)

I know it is a collection because when I run select ST_IsCollection(geom)from table2 it is TRUE, but when I want to know how many collections with SELECT ST_NumGeometries(geom)from table 2, it returns 1.

I know that since I have a collection I have to use st_INTERSECTS.

select TABLE1.*, TABLE2.*
where ST_Intersects(TABLE2.geom, TABLE1.geom)

But it is empty. And I know from plotting the data that they intersect.

Do you know what might be wrong?

  • 3
    you are missing aliases, e.g. TABLE1 AS T1, TABLE2 AS T2
    – Taras
    Apr 11, 2019 at 13:24
  • Yes @BERA is postgis Apr 11, 2019 at 13:29
  • 2
    you're title is misleading -- its a multipolygon collection. If I were you I would dump the collection into an actual geometry. I think postgis recently allowed collections to be used in spatial functions such as st_intersects but that depends on what version of postgis you have
    – ziggy
    Apr 11, 2019 at 14:12

1 Answer 1


Have a look at St_Dump: https://postgis.net/docs/ST_Dump.html and Using multipolygon or polygon features for large intersect operations?

Assuming that Table2 are the polygons, this would be:

select T1.*, T2.*
from TABLE1 as T1, TABLE2 as T2
where ST_Intersects(St_Dump(T2.geom), T1.geom)
  • No Pieter, thanks, but that is not the problem. I edited the question, I wrote T1 T2 for convenience. Apr 11, 2019 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.