DROP TABLE IF EXISTS t;
CREATE TABLE t (id int, geom geometry);
INSERT INTO t (id, geom) VALUES (1,ST_GeomFromText('MULTILINESTRING((-1 0,1 0))'));
INSERT INTO t (id, geom) VALUES (2,ST_GeomFromText('LINESTRING(-1 0,0 0)'));
INSERT INTO t (id, geom) VALUES (3,ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOINT((-1 0)),LINESTRING(0 -1,1 0))'));
They intersect each other.
SELECT ST_Intersects(a1.geom, a2.geom), ST_Intersects(a2.geom, a1.geom) FROM t As a1, t As a2 WHERE a1.id = 1 and a2.id = 2;
SELECT ST_Intersects(a1.geom, a2.geom), ST_Intersects(a2.geom, a1.geom) FROM t As a1, t As a2 WHERE a1.id = 1 and a2.id = 3;
SELECT ST_Intersects(a1.geom, a2.geom), ST_Intersects(a2.geom, a1.geom) FROM t As a1, t As a2 WHERE a1.id = 2 and a2.id = 3;
-- result{t, t; t, t; t, t}
But when I query how many geometries intersect, I get the result 5.
SELECT COUNT(*) FROM t As a1 JOIN t As a2 ON ST_Intersects(a1.geom, a2.geom) WHERE a1.id <> a2.id;
--expected{6}; actual{5}
Consider there are 3 geometries in table t.
They intersect each other.
But when I query how many geometries intersect, I get the result 5.
Version: POSTGIS="3.5.0dev 3.4.0rc1-705-g5c3ec8392" [EXTENSION] PGSQL="170" GEOS="3.11.3dev-CAPI-1.17.3" PROJ="8.2.1 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org/ USER_WRITABLE_DIRECTORY=/tmp/proj DATABASE_PATH=/usr/share/proj/proj.db" LIBXML="2.9.13"