Matt thanks for your prompt reply.
I'm using this query because I'm not using a spatial database backend
and unfortunately I cannot move to it (this is an implementation of
haystack on
http://geonode.org/).
The query you suggested is to check whether at least one of the points
is contained into the target_bbox, however could also happen the case
where the bbox is bigger than the target and none of the points are
contained in the target_bbox even if there is full overlap. This is
the main reason (unfortunately) why I was trying to implement the more
complex query which checks the difference between the sum of the
distance of the centers and the sum of the distance of each center
from the respective edge. (I'm not sure that this is possible with a
SQL query....)
Thank you for your help!
Simone