CREATE OR REPLACE FUNCTION ST_Intersects_(geometry, geometry) RETURNS boolean AS $$
	DECLARE
		is1collection boolean;
		is2collection boolean;
	BEGIN
	
		is1collection := GeometryType($1) = 'GEOMETRYCOLLECTION';
		is2collection := GeometryType($2) = 'GEOMETRYCOLLECTION';

		IF NOT is1collection AND NOT is2collection THEN
			return ST_Intersects($1, $2);
		END IF;
		
		
		IF NOT is1collection THEN
			FOR i IN 1..ST_NumGeometries($2) LOOP
				IF ST_Intersects($1, ST_GeometryN($2, i)) THEN
					RETURN true;
				END IF;
			END LOOP;
		ELSIF NOT is2collection THEN
			FOR i IN 1..ST_NumGeometries($1) LOOP
				IF ST_Intersects(ST_GeometryN($1, i), $2) THEN
					RETURN true;
				END IF;
			END LOOP;
		ELSE
			FOR i IN 1..ST_NumGeometries($1) LOOP
				IF ST_Intersects_($1, $2) THEN
					RETURN true;
				END IF;
			END LOOP;
		END IF;
		
		RETURN false;
		
	END;
$$ LANGUAGE 'plpgsql';