For a project I have to show the relationship between 2 or more objects. For this I use the code below in QGIS in step 1 I determine the relation in step 2 the items are counted. In the test set I use 5128 objects here QGIS takes quite a long time, the original data set is more than 1 million objects. I wonder would this also be possible in PostgreSQL / PostGIS to make the whole faster and reproducible?
Code for QGIS 3 Step 1
aggregate( layer:= ‘Test', aggregate:='concatenate', expression:=Label, concatenator:=', ', filter:=touches($geometry, geometry(@parent)) )
aggregate( layer:= ‘Test’, aggregate:='count', expression:=Label, filter:=touches($geometry, geometry(@parent)) )
In the result you can see that an (label) object has a relation with an other object 1 to N=(Count)