statement ok
CREATE TABLE geo_table(
  id int primary key,
  geog geography(geometry, 4326),
  geom geometry(point),
  orphan geography,
  FAMILY f (orphan)
)

statement ok
INSERT INTO geo_table VALUES
  (1, 'POINT(1.0 1.0)', 'POINT(2.0 2.0)', 'POINT(3.0 3.0)'),
  (2, 'LINESTRING(1.0 1.0, 2.0 2.0)', 'POINT(1.0 1.0)', 'POINT(3.0 3.0)')

statement error SRID 4004 does not match column SRID 4326
INSERT INTO geo_table (id, geog) VALUES
  (3, 'SRID=4004;POINT(1.0 2.0)')

statement error type LineString does not match column type Point
INSERT INTO geo_table (id, geom) VALUES
  (3, 'SRID=4004;LINESTRING(0.0 0.0, 1.0 2.0)')

statement error projection for SRID 404 does not exist
SELECT 'SRID=404;POINT(1.0 2.0)'::geometry

statement error projection for SRID 404 does not exist
SELECT 'SRID=404;POINT(1.0 2.0)'::geography

statement error pq: object type PointZ does not match column type Point
INSERT INTO geo_table (id, geom) VALUES
  (3, 'POINT Z(1 2 3)')

statement error pq: object type PointZ does not match column dimensionality Geometry
INSERT INTO geo_table (id, geog) VALUES
  (3, 'POINT Z(1 2 3)')

statement ok
CREATE INDEX geo_table_geom_idx ON geo_table USING GIST(geom)

statement ok
CREATE INDEX geo_table_geog_idx ON geo_table USING GIST(geog)

statement ok
CREATE TABLE geom_table_negative_values(
  a geometry(geometry, -1)
)

statement ok
CREATE TABLE geom_table_public_schema (
  geom public.geometry,
  geog public.geography
)

statement ok
INSERT INTO geom_table_public_schema VALUES ('POINT(1 0)', 'POINT(3 2)')

query TT
SELECT ST_AsText(geom), ST_AsText(geog) FROM geom_table_public_schema
----
POINT (1 0)  POINT (3 2)

statement error type .*geometry.* already exists
CREATE TYPE geometry AS enum('no')

statement error type .*geography.* already exists
CREATE TYPE geography AS enum('no')

statement error type .*geometry.* already exists
CREATE TABLE geometry (a geometry)

statement error type .*geography.* already exists
CREATE TABLE geography (a geography)

query T
SELECT create_statement FROM [SHOW CREATE TABLE geom_table_negative_values]
----
CREATE TABLE public.geom_table_negative_values (
  a GEOMETRY(GEOMETRY) NULL,
  rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
  CONSTRAINT geom_table_negative_values_pkey PRIMARY KEY (rowid ASC)
)

statement ok
CREATE TABLE geog_table_negative_values(
  a geography(geometry, -1)
)

query T
SELECT create_statement FROM [SHOW CREATE TABLE geog_table_negative_values]
----
CREATE TABLE public.geog_table_negative_values (
  a GEOGRAPHY(GEOMETRY) NULL,
  rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
  CONSTRAINT geog_table_negative_values_pkey PRIMARY KEY (rowid ASC)
)

statement error SRID 3857 cannot be used for geography as it is not in a lon/lat coordinate system
SELECT 'SRID=3857;POINT(1.0 2.0)'::geography

query ITTT rowsort
SELECT * FROM geo_table
----
1  0101000020E6100000000000000000F03F000000000000F03F                                          010100000000000000000000400000000000000040  0101000020E610000000000000000008400000000000000840
2  0102000020E610000002000000000000000000F03F000000000000F03F00000000000000400000000000000040  0101000000000000000000F03F000000000000F03F  0101000020E610000000000000000008400000000000000840

query T rowsort
SELECT orphan FROM geo_table
----
0101000020E610000000000000000008400000000000000840
0101000020E610000000000000000008400000000000000840

query TTBTTTB rowsort
SHOW COLUMNS FROM geo_table
----
id      INT8                      false  NULL  ·  {geo_table_geog_idx,geo_table_geom_idx,geo_table_pkey}  false
geog    GEOGRAPHY(GEOMETRY,4326)  true   NULL  ·  {geo_table_geog_idx,geo_table_pkey}                     false
geom    GEOMETRY(POINT)           true   NULL  ·  {geo_table_geom_idx,geo_table_pkey}                     false
orphan  GEOGRAPHY                 true   NULL  ·  {geo_table_pkey}                                        false

statement error column bad_pk is of type geography and thus is not indexable
CREATE TABLE bad_geog_table(bad_pk geography primary key)

statement error column bad_pk is of type geometry and thus is not indexable
CREATE TABLE bad_geom_table(bad_pk geometry primary key)

statement error column geog is of type geography and thus is not indexable
CREATE INDEX geog_idx ON geo_table(geog)

statement error column geom is of type geometry and thus is not indexable
CREATE INDEX geom_idx ON geo_table(geom)

statement ok
CREATE INVERTED INDEX geog_idx ON geo_table(geog)

statement ok
CREATE INVERTED INDEX geom_idx ON geo_table(geom)

statement ok
INSERT INTO geo_table VALUES
  (3, 'POINT(-1.25 3.375)', 'POINT(2.220 -2.445)', 'POINT(3.0 -3.710)')

query ITTT rowsort
SELECT * FROM geo_table
----
1  0101000020E6100000000000000000F03F000000000000F03F                                          010100000000000000000000400000000000000040  0101000020E610000000000000000008400000000000000840
2  0102000020E610000002000000000000000000F03F000000000000F03F00000000000000400000000000000040  0101000000000000000000F03F000000000000F03F  0101000020E610000000000000000008400000000000000840
3  0101000020E6100000000000000000F4BF0000000000000B40                                          0101000000C3F5285C8FC201408FC2F5285C8F03C0  0101000020E61000000000000000000840AE47E17A14AE0DC0

statement ok
CREATE TABLE geo_array_table(id int, geog geography array, geom geometry array)

statement ok
INSERT INTO geo_array_table VALUES (
  1,
  array['POINT(1.0 1.0)'::geography, 'LINESTRING(2.0 2.0, 3.0 3.0)'::geography],
  array['POINT(1.0 1.0)'::geometry, 'LINESTRING(2.0 2.0, 3.0 3.0)'::geometry]
)

query ITT
SELECT * FROM geo_array_table
----
1  {0101000020E6100000000000000000F03F000000000000F03F:0102000020E6100000020000000000000000000040000000000000004000000000000008400000000000000840}  {0101000000000000000000F03F000000000000F03F:0102000000020000000000000000000040000000000000004000000000000008400000000000000840}

query TT
SELECT NULL::geometry, NULL::geography
----
NULL  NULL

query T nosort
SELECT ST_AsText(p) FROM (VALUES
  (ST_Point(1, 2)),
  (ST_Point(3, 4))
) tbl(p)
----
POINT (1 2)
POINT (3 4)

query T nosort
SELECT ST_AsText(p) FROM (VALUES
  ('POINT(200 200)'::geography),
  ('POLYGON((200 200, 200 200, 200 200, 200 200))'::geography),
  ('GEOMETRYCOLLECTION(POINT (200 200), POLYGON((200 200, 200 200, 200 200, 200 200, 200 200)))'::geography),
  ('MULTIPOLYGON(((200 200,200 200, 200 200, 200 200)),((200 200,200 200,200 200,200 200)))'::geography)
) tbl(p)
----
POINT (-160 -20)
POLYGON ((-160 -20, -160 -20, -160 -20, -160 -20))
GEOMETRYCOLLECTION (POINT (-160 -20), POLYGON ((-160 -20, -160 -20, -160 -20, -160 -20, -160 -20)))
MULTIPOLYGON (((-160 -20, -160 -20, -160 -20, -160 -20)), ((-160 -20, -160 -20, -160 -20, -160 -20)))

query T nosort
SELECT ST_AsText(p) FROM (VALUES
  ('POINT(200 200)'::geometry),
  ('POLYGON((200 200, 200 200, 200 200, 200 200))'::geometry),
  ('GEOMETRYCOLLECTION(POINT (200 200), POLYGON((200 200, 200 200, 200 200, 200 200, 200 200)))'::geometry),
  ('MULTIPOLYGON(((200 200,200 200, 200 200, 200 200)),((200 200,200 200,200 200,200 200)))'::geometry)
) tbl(p)
----
POINT (200 200)
POLYGON ((200 200, 200 200, 200 200, 200 200))
GEOMETRYCOLLECTION (POINT (200 200), POLYGON ((200 200, 200 200, 200 200, 200 200, 200 200)))
MULTIPOLYGON (((200 200, 200 200, 200 200, 200 200)), ((200 200, 200 200, 200 200, 200 200)))

query T
SELECT ST_AsText(ST_Project('POINT(0 0)'::geography, 100000, radians(45.0)))
----
POINT (0.635231029125537 0.639472334729198)

statement error arguments must be POINT geometries
SELECT ST_Azimuth('POLYGON((0 0, 0 0, 0 0, 0 0))'::geometry, 'POLYGON((0 0, 0 0, 0 0, 0 0))'::geometry)

query RR
SELECT
	degrees(ST_Azimuth(ST_Point(25, 45), ST_Point(75, 100))) AS degA_B,
	degrees(ST_Azimuth(ST_Point(75, 100), ST_Point(25, 45))) AS degB_A
----
42.27368900609371  222.27368900609372

query R
SELECT ST_Azimuth(ST_Point(0, 0), ST_Point(0, 0))
----
NULL

query RRRRRRR
SELECT
	degrees(ST_Angle('POINT (0 0)', 'POINT (0 1)', 'POINT (0 0)', 'POINT (1 0)')),
	degrees(ST_Angle('POINT (0 0)', 'POINT (0 1)', 'POINT (0 0)')),
	degrees(ST_Angle('POINT (0 0)', 'POINT (0 1)', 'POINT (1 1)')),
	degrees(ST_Angle('POINT (0 0)', 'POINT (0 0)', 'POINT (0 0)', 'POINT (0 0)')),
	degrees(ST_Angle('LINESTRING (0 0, 0 1)', 'LINESTRING (0 0, 1 0)')),
	degrees(ST_Angle('LINESTRING (0 0, 0 1)', 'LINESTRING (0 0, 0 1)')),
	degrees(ST_Angle('LINESTRING (0 0, 0 0)', 'LINESTRING (0 0, 0 0)'))
----
90  0  270  NULL  90  0  NULL

subtest json_test

# All values here should be true.
query BB nosort
SELECT
  to_json(g::geometry) = st_asgeojson(g::geometry)::jsonb,
  to_json(g::geography) = st_asgeojson(g::geography)::jsonb
FROM ( VALUES
  ('POINT (30 10)'),
  ('LINESTRING (30 10, 10 30, 40 40)'),
  ('POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))'),
  ('MULTIPOINT (10 40, 40 30, 20 20, 30 10)'),
  ('MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))'),
  ('MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))'),
  ('GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40), POLYGON ((40 40, 20 45, 45 30, 40 40)))')
) tbl(g)
----
true  true
true  true
true  true
true  true
true  true
true  true
true  true

# Regression test for #124175. Allow full precision for encoding JSON instead of the old default limit of 9.
query FFT nosort
SELECT
  st_x(g), st_y(g), to_json(g)
FROM ( VALUES
  ('SRID=4326;POINT (-123.45 12.3456)'::GEOMETRY),
  ('SRID=4326;POINT (-123.45678901234 12.3456789012)'::GEOMETRY),
  ('SRID=4326;POINT (-123.4567890123456789 12.34567890123456789)'::GEOMETRY)
) tbl(g)
----
-123.45 12.3456 {"coordinates": [-123.45, 12.3456], "type": "Point"}
-123.45678901234 12.3456789012 {"coordinates": [-123.45678901234, 12.3456789012], "type": "Point"}
-123.45678901234568 12.345678901234567 {"coordinates": [-123.45678901234568, 12.345678901234567], "type": "Point"}

# st_asgeojson uses a default of 9 decimal digit precision.
query TTTT nosort
SELECT
  st_asgeojson(tbl.*)::JSONB->'geometry'->'coordinates',
  st_asgeojson(g)::JSONB->'coordinates',
  st_asgeojson(tbl.*, 'g')::JSONB->'geometry'->'coordinates',
  st_asgeojson(tbl.*, 'g', 4)::JSONB->'geometry'->'coordinates'
FROM ( VALUES
  ('SRID=4326;POINT (-123.45 12.3456)'::GEOMETRY),
  ('SRID=4326;POINT (-123.45678901234 12.3456789012)'::GEOMETRY),
  ('SRID=4326;POINT (-123.4567890123456789 12.34567890123456789)'::GEOMETRY)
) tbl(g)
----
[-123.45, 12.3456]              [-123.45, 12.3456]              [-123.45, 12.3456]              [-123.45, 12.3456]
[-123.456789012, 12.345678901]  [-123.456789012, 12.345678901]  [-123.456789012, 12.345678901]  [-123.4568, 12.3457]
[-123.456789012, 12.345678901]  [-123.456789012, 12.345678901]  [-123.456789012, 12.345678901]  [-123.4568, 12.3457]

subtest cast_test

query T nosort
SELECT ST_AsEWKT(geom) FROM (VALUES
  ('SRID=4326;POINT(1.0 2.0)'::geometry::geometry(point, 4326)),
  ('SRID=4326;POINT(1.0 2.0)'::geometry::geometry(geometry, 4326)),
  ('SRID=4326;POINT(1.0 2.0)'::geography::geometry)
) t(geom)
----
SRID=4326;POINT (1 2)
SRID=4326;POINT (1 2)
SRID=4326;POINT (1 2)

query T nosort
SELECT ST_AsEWKT(geog) FROM (VALUES
  ('POINT(1.0 2.0)'::geography::geography(point, 4326)),
  ('POINT(1.0 2.0)'::geometry::geography(point, 4326)),
  ('SRID=4004;POINT(1.0 2.0)'::geometry::geography(point, 4004)),
  ('SRID=4004;POINT(1.0 2.0)'::geometry::geography),
  ('SRID=4004;POINT(1.0 2.0)'::geography::geography(point, 4004)),
  ('SRID=4004;POINT(1.0 2.0)'::geography::geography(geometry, 4004)),
  ('POINT(1.0 2.0)'::geometry::geography),
  ('POINT(1.0 2.0)'::geometry::geography(geometry, 4326))
) t(geog)
----
SRID=4326;POINT (1 2)
SRID=4326;POINT (1 2)
SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)
SRID=4326;POINT (1 2)
SRID=4326;POINT (1 2)

statement error SRID 4004 does not match column SRID 4326
SELECT 'SRID=4004;POINT(2.0 3.0)'::geometry::geography(point, 4326)

statement error SRID 4326 does not match column SRID 4004
SELECT 'SRID=4326;POINT(2.0 3.0)'::geometry::geography(point, 4004)

statement error SRID 4326 does not match column SRID 4004
SELECT 'SRID=4326;POINT(2.0 3.0)'::geography::geography(point, 4004)

statement error SRID 4004 does not match column SRID 4326
SELECT 'SRID=4004;POINT(2.0 3.0)'::geometry::geometry(point, 4326)

statement error SRID 4004 does not match column SRID 4326
SELECT 'SRID=4004;POINT(2.0 3.0)'::geography::geometry(point, 4326)

statement error SRID 4326 does not match column SRID 4004
SELECT 'POINT(1.0 2.0)'::geometry::geography(geometry, 4004)

statement error type Point does not match column type LineString
SELECT 'SRID=4004;POINT(2.0 3.0)'::geometry::geometry(linestring)

statement error type Point does not match column type LineString
SELECT 'SRID=4004;POINT(2.0 3.0)'::geometry::geography(linestring)

statement error type Point does not match column type LineString
SELECT 'SRID=4004;POINT(2.0 3.0)'::geography::geography(linestring)

statement error type Point does not match column type LineString
SELECT 'SRID=4004;POINT(2.0 3.0)'::geography::geometry(linestring)

subtest parse_and_unparse

statement ok
CREATE TABLE parse_test (
  id SERIAL PRIMARY KEY,
  geom GEOMETRY,
  geog GEOGRAPHY
)

# These values cannot be inserted into the database due to mismatching SRIDs.
query TT nosort
SELECT
  ST_AsEWKT(geom),
  ST_AsEWKT(geog)
FROM ( VALUES
  (ST_GeometryFromText('SRID=4326;POINT(1.0 2.0)', 4004), ST_GeographyFromText('SRID=4326;POINT(1.0 2.0)', 4004)),
  (ST_GeomFromText('SRID=4326;POINT(1.0 2.0)', 4004), ST_GeogFromText('SRID=4326;POINT(1.0 2.0)', 4004)),
  (ST_GeometryFromText('SRID=4326;POINT(1.0 2.0)'), ST_GeographyFromText('POINT(1.0 2.0)', 4004)),
  (ST_GeomFromEWKT('SRID=4004;POINT(1.0 2.0)'), ST_GeogFromEWKT('SRID=4004;POINT(1.0 2.0)')),
  (ST_GeomFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'), 4004), ST_GeogFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'), 4004)),
  (ST_GeomFromWKB(decode('0101000020E6100000000000000000F03F0000000000000040', 'hex'), 4004), ST_GeogFromWKB(decode('0101000020E6100000000000000000F03F0000000000000040', 'hex'), 4004)),
  (ST_GeomFromWKB(decode('0101000020A40F0000000000000000F03F0000000000000040', 'hex')), ST_GeogFromWKB(decode('0101000020A40F0000000000000000F03F0000000000000040', 'hex')))
) t(geom, geog)
----
SRID=4004;POINT (1 2)  SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)  SRID=4004;POINT (1 2)
SRID=4326;POINT (1 2)  SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)  SRID=4004;POINT (1 2)
SRID=4004;POINT (1 1)  SRID=4004;POINT (1 1)
SRID=4004;POINT (1 2)  SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)  SRID=4004;POINT (1 2)

query T nosort
SELECT ST_AsEWKT(g) FROM ( VALUES
  (GeomFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'))),
  (GeomFromEWKT('SRID=4004;LINESTRING(-1 -1, 2 2)'))
) t(g)
----
POINT (1 1)
SRID=4004;LINESTRING (-1 -1, 2 2)

statement ok
INSERT INTO parse_test (geom, geog) VALUES
  (ST_GeomFromText('POINT(1.555 -2.0)'), ST_GeogFromText('POINT(1.555 -2.0)')),
  (ST_GeomFromText('SRID=4326;POINT(1.0 2.0)'), ST_GeogFromText('SRID=4326;POINT(1.0 2.0)')),
  (ST_GeometryFromText('SRID=4004;POINT(1.0 2.0)'), ST_GeographyFromText('POINT(1.0 2.0)')),
  (ST_GeomFromGeoJSON('{"type":"Point","coordinates":[1,2]}'), ST_GeogFromGeoJSON('{"type":"Point","coordinates":[1,2]}')),
  (ST_GeomFromGeoJSON('{"type":"Point","coordinates":[1,2]}'::jsonb), ST_GeogFromGeoJSON('{"type":"Point","coordinates":[1,2]}'::jsonb)),
  (ST_GeomFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex')), ST_GeogFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'))),
  (ST_GeomFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex')), ST_GeogFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'))),
  (ST_GeomFromText('POINT EMPTY'), ST_GeogFromText('POINT EMPTY')),
  (ST_GeomFromGeoJSON('null':::jsonb), ST_GeogFromGeoJSON('null':::jsonb))

query BB
SELECT
  st_geomfromwkb(decode('0101000000000000000000F03F000000000000F03F', 'hex')) = st_wkbtosql(decode('0101000000000000000000F03F000000000000F03F', 'hex')),
  st_geomfromtext('POINT(1.0 2.0)') = st_wkttosql('POINT(1.0 2.0)')
----
true  true

statement error invalid GeoJSON input
select st_geomfromgeojson(json_typeof('null'))

statement error invalid GeoJSON input
select st_geogfromgeojson(json_typeof('null'))

query TTTTTTT
SELECT
  ST_AsText(geom),
  ST_AsEWKT(geom),
  ST_AsBinary(geom),
  ST_AsBinary(geom, 'ndr'),
  ST_AsBinary(geom, 'xdr'),
  ST_AsEWKB(geom),
  ST_AsKML(geom)
FROM parse_test ORDER BY id ASC
----
POINT (1.555 -2)                                    POINT (1.555 -2)  [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192]  [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192]  [0 0 0 0 1 63 248 225 71 174 20 122 225 192 0 0 0 0 0 0 0]  [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1.555,-2</coordinates></Point>
POINT (1 2)                                         SRID=4326;POINT (1 2)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2)                                         SRID=4004;POINT (1 2)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0]  [1 1 0 0 32 164 15 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2)                                         SRID=4326;POINT (1 2)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2)                                         SRID=4326;POINT (1 2)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 1)                                         POINT (1 1)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  [0 0 0 0 1 63 240 0 0 0 0 0 0 63 240 0 0 0 0 0 0]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point>
POINT (1 1)                                         POINT (1 1)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  [0 0 0 0 1 63 240 0 0 0 0 0 0 63 240 0 0 0 0 0 0]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point>
POINT EMPTY                                         POINT EMPTY  [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127]  [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127]  [0 0 0 0 1 127 248 0 0 0 0 0 0 127 248 0 0 0 0 0 0]  [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates></coordinates></Point>
NULL                                                NULL  NULL  NULL  NULL  NULL  NULL

query TTT nosort
SELECT ST_AsEWKT(g), ST_GeoHash(g), ST_GeoHash(g, 8) FROM ( VALUES
  ('POINT (0 0)'::geometry),
  ('LINESTRING(0 0, 1 0)'::geometry)
) t(g)
----
POINT (0 0)            s0000000000000000000  s0000000
LINESTRING (0 0, 1 0)  ·                     s00252h0

query TTT
SELECT
  ST_AsGeoJSON(geom),
  ST_AsGeoJSON(geom, 6, 8),
  ST_AsGeoJSON(geom, 6, 5)
FROM parse_test ORDER BY id ASC
----
{"type":"Point","coordinates":[1.555,-2]}                                                     {"type":"Point","coordinates":[1.555,-2]}                                                     {"type":"Point","bbox":[1.555,-2,1.555,-2],"coordinates":[1.555,-2]}
{"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,2]}  {"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,2]}  {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4004"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,1]}                                                          {"type":"Point","coordinates":[1,1]}                                                          {"type":"Point","bbox":[1,1,1,1],"coordinates":[1,1]}
{"type":"Point","coordinates":[1,1]}                                                          {"type":"Point","coordinates":[1,1]}                                                          {"type":"Point","bbox":[1,1,1,1],"coordinates":[1,1]}
{"type":"Point","coordinates":[]}                                                             {"type":"Point","coordinates":[]}                                                             {"type":"Point","coordinates":[]}
NULL                                                                                          NULL                                                                                          NULL

# Since id in parse_test can change between tests, make a new table
# that has a consistent id over multiple logic test runs.
statement ok
CREATE TABLE parse_test_geojson AS
  SELECT
    row_number() OVER (ORDER BY id) as id,
    geom,
    geog
  FROM parse_test

query T nosort
SELECT
  ST_AsGeoJSON(t.*)
FROM ( VALUES
  (1),
  (2)
) t(row_id)
----
{"geometry": {"type": null}, "properties": {"row_id": 1}, "type": "Feature"}
{"geometry": {"type": null}, "properties": {"row_id": 2}, "type": "Feature"}

query TTT
SELECT
  ST_AsGeoJSON(parse_test_geojson.*),
  ST_AsGeoJSON(parse_test_geojson.*, 'geom'),
  ST_AsGeoJSON(parse_test_geojson.*, 'geog')
FROM parse_test_geojson ORDER BY id ASC
----
{"geometry": {"coordinates": [1.555, -2], "type": "Point"}, "properties": {"geog": {"coordinates": [1.555, -2], "type": "Point"}, "id": 1}, "type": "Feature"}  {"geometry": {"coordinates": [1.555, -2], "type": "Point"}, "properties": {"geog": {"coordinates": [1.555, -2], "type": "Point"}, "id": 1}, "type": "Feature"}  {"geometry": {"coordinates": [1.555, -2], "type": "Point"}, "properties": {"geom": {"coordinates": [1.555, -2], "type": "Point"}, "id": 1}, "type": "Feature"}
{"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 2}, "type": "Feature"}            {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 2}, "type": "Feature"}            {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 2], "type": "Point"}, "id": 2}, "type": "Feature"}
{"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 3}, "type": "Feature"}            {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 3}, "type": "Feature"}            {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 2], "type": "Point"}, "id": 3}, "type": "Feature"}
{"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 4}, "type": "Feature"}            {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 4}, "type": "Feature"}            {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 2], "type": "Point"}, "id": 4}, "type": "Feature"}
{"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 5}, "type": "Feature"}            {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 5}, "type": "Feature"}            {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 2], "type": "Point"}, "id": 5}, "type": "Feature"}
{"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 1], "type": "Point"}, "id": 6}, "type": "Feature"}            {"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 1], "type": "Point"}, "id": 6}, "type": "Feature"}            {"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 1], "type": "Point"}, "id": 6}, "type": "Feature"}
{"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 1], "type": "Point"}, "id": 7}, "type": "Feature"}            {"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 1], "type": "Point"}, "id": 7}, "type": "Feature"}            {"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 1], "type": "Point"}, "id": 7}, "type": "Feature"}
{"geometry": {"coordinates": [], "type": "Point"}, "properties": {"geog": {"coordinates": [], "type": "Point"}, "id": 8}, "type": "Feature"}                    {"geometry": {"coordinates": [], "type": "Point"}, "properties": {"geog": {"coordinates": [], "type": "Point"}, "id": 8}, "type": "Feature"}                    {"geometry": {"coordinates": [], "type": "Point"}, "properties": {"geom": {"coordinates": [], "type": "Point"}, "id": 8}, "type": "Feature"}
{"geometry": {"type": null}, "properties": {"geog": null, "geom": null, "id": 9}, "type": "Feature"}                                                            {"geometry": {"type": null}, "properties": {"geog": null, "id": 9}, "type": "Feature"}                                                                          {"geometry": {"type": null}, "properties": {"geom": null, "id": 9}, "type": "Feature"}

query T
SELECT
  ST_AsGeoJSON(parse_test_geojson.*, 'geog', 3, true)
FROM parse_test_geojson ORDER BY id ASC
----
{
   "geometry": {
     "coordinates": [
       1.555,
       -2
     ],
     "type": "Point"
   },
   "properties": {
     "geom": {
       "coordinates": [
         1.555,
         -2
       ],
       "type": "Point"
     },
     "id": 1
   },
   "type": "Feature"
}
{
   "geometry": {
     "coordinates": [
       1,
       2
     ],
     "type": "Point"
   },
   "properties": {
     "geom": {
       "coordinates": [
         1,
         2
       ],
       "type": "Point"
     },
     "id": 2
   },
   "type": "Feature"
}
{
   "geometry": {
     "coordinates": [
       1,
       2
     ],
     "type": "Point"
   },
   "properties": {
     "geom": {
       "coordinates": [
         1,
         2
       ],
       "type": "Point"
     },
     "id": 3
   },
   "type": "Feature"
}
{
   "geometry": {
     "coordinates": [
       1,
       2
     ],
     "type": "Point"
   },
   "properties": {
     "geom": {
       "coordinates": [
         1,
         2
       ],
       "type": "Point"
     },
     "id": 4
   },
   "type": "Feature"
}
{
   "geometry": {
     "coordinates": [
       1,
       2
     ],
     "type": "Point"
   },
   "properties": {
     "geom": {
       "coordinates": [
         1,
         2
       ],
       "type": "Point"
     },
     "id": 5
   },
   "type": "Feature"
}
{
   "geometry": {
     "coordinates": [
       1,
       1
     ],
     "type": "Point"
   },
   "properties": {
     "geom": {
       "coordinates": [
         1,
         1
       ],
       "type": "Point"
     },
     "id": 6
   },
   "type": "Feature"
}
{
   "geometry": {
     "coordinates": [
       1,
       1
     ],
     "type": "Point"
   },
   "properties": {
     "geom": {
       "coordinates": [
         1,
         1
       ],
       "type": "Point"
     },
     "id": 7
   },
   "type": "Feature"
}
{
   "geometry": {
     "coordinates": [],
     "type": "Point"
   },
   "properties": {
     "geom": {
       "coordinates": [],
       "type": "Point"
     },
     "id": 8
   },
   "type": "Feature"
}
{
   "geometry": {
     "type": null
   },
   "properties": {
     "geom": null,
     "id": 9
   },
   "type": "Feature"
}

statement error "geom_no_exist" column not found
SELECT
  ST_AsGeoJSON(parse_test.*, 'geom_no_exist')
FROM parse_test ORDER BY id asc

# tests casts
query TTT
SELECT
  geom::bytea,
  geom::jsonb,
  geom::string
FROM parse_test ORDER BY id ASC
----
[1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192]   {"coordinates": [1.555, -2], "type": "Point"}  0101000000E17A14AE47E1F83F00000000000000C0
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  {"coordinates": [1, 2], "type": "Point"}       0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 164 15 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  {"coordinates": [1, 2], "type": "Point"}       0101000020A40F0000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  {"coordinates": [1, 2], "type": "Point"}       0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  {"coordinates": [1, 2], "type": "Point"}       0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]            {"coordinates": [1, 1], "type": "Point"}       0101000000000000000000F03F000000000000F03F
[1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]            {"coordinates": [1, 1], "type": "Point"}       0101000000000000000000F03F000000000000F03F
[1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127]          {"coordinates": [], "type": "Point"}           0101000000000000000000F87F000000000000F87F
NULL                                                         NULL                                           NULL

query TTT
SELECT
  geom::bytea::geometry,
  geom::jsonb::geometry,
  geom::string::geometry
FROM parse_test ORDER BY id ASC
----
0101000000E17A14AE47E1F83F00000000000000C0          0101000020E6100000E17A14AE47E1F83F00000000000000C0  0101000000E17A14AE47E1F83F00000000000000C0
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040
0101000020A40F0000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020A40F0000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040
0101000000000000000000F03F000000000000F03F          0101000020E6100000000000000000F03F000000000000F03F  0101000000000000000000F03F000000000000F03F
0101000000000000000000F03F000000000000F03F          0101000020E6100000000000000000F03F000000000000F03F  0101000000000000000000F03F000000000000F03F
0101000000000000000000F87F000000000000F87F          0101000020E6100000000000000000F87F000000000000F87F  0101000000000000000000F87F000000000000F87F
NULL                                                NULL                                                NULL


# test out of bounds precisions
query TTTT
SELECT
  ST_AsText(geom, 123123123),
  ST_AsText(geom, -1),
  ST_AsGeoJSON(geom, 123123123),
  ST_AsGeoJSON(geom, -1)
FROM parse_test ORDER BY id ASC
----
POINT (1.5549999999999999378275106209912337362766265869140625 -2)  POINT (1.555 -2)  {"type":"Point","coordinates":[1.5549999999999999378275106209912337362766265869140625,-2]}    {"type":"Point","coordinates":[1.555,-2]}
POINT (1 2)                                                        POINT (1 2)       {"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","coordinates":[1,2]}
POINT (1 2)                                                        POINT (1 2)       {"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,2]}  {"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,2]}
POINT (1 2)                                                        POINT (1 2)       {"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","coordinates":[1,2]}
POINT (1 2)                                                        POINT (1 2)       {"type":"Point","coordinates":[1,2]}                                                          {"type":"Point","coordinates":[1,2]}
POINT (1 1)                                                        POINT (1 1)       {"type":"Point","coordinates":[1,1]}                                                          {"type":"Point","coordinates":[1,1]}
POINT (1 1)                                                        POINT (1 1)       {"type":"Point","coordinates":[1,1]}                                                          {"type":"Point","coordinates":[1,1]}
POINT EMPTY                                                        POINT EMPTY       {"type":"Point","coordinates":[]}                                                             {"type":"Point","coordinates":[]}
NULL                                                               NULL              NULL                                                                                          NULL

query TTT
SELECT
  ST_AsHexEWKB(geom),
  ST_AsHexEWKB(geom, 'ndr'),
  ST_AsHexEWKB(geom, 'xdr')
FROM parse_test ORDER BY id ASC
----
0101000000E17A14AE47E1F83F00000000000000C0          0101000000E17A14AE47E1F83F00000000000000C0          00000000013FF8E147AE147AE1C000000000000000
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0020000001000010E63FF00000000000004000000000000000
0101000020A40F0000000000000000F03F0000000000000040  0101000020A40F0000000000000000F03F0000000000000040  002000000100000FA43FF00000000000004000000000000000
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0020000001000010E63FF00000000000004000000000000000
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F000000000000F03F          0101000000000000000000F03F000000000000F03F          00000000013FF00000000000003FF0000000000000
0101000000000000000000F03F000000000000F03F          0101000000000000000000F03F000000000000F03F          00000000013FF00000000000003FF0000000000000
0101000000000000000000F87F000000000000F87F          0101000000000000000000F87F000000000000F87F          00000000017FF80000000000007FF8000000000000
NULL                                                NULL                                                NULL

query TTTTTTT
SELECT
  ST_AsText(geog),
  ST_AsEWKT(geog),
  ST_AsBinary(geog),
  ST_AsBinary(geog, 'ndr'),
  ST_AsBinary(geog, 'xdr'),
  ST_AsEWKB(geog),
  ST_AsKML(geog)
FROM parse_test ORDER BY id ASC
----
POINT (1.555 -2)                                    SRID=4326;POINT (1.555 -2)  [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192]  [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192]  [0 0 0 0 1 63 248 225 71 174 20 122 225 192 0 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1.555,-2</coordinates></Point>
POINT (1 2)                                         SRID=4326;POINT (1 2)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2)                                         SRID=4326;POINT (1 2)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2)                                         SRID=4326;POINT (1 2)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2)                                         SRID=4326;POINT (1 2)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 1)                                         SRID=4326;POINT (1 1)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  [0 0 0 0 1 63 240 0 0 0 0 0 0 63 240 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point>
POINT (1 1)                                         SRID=4326;POINT (1 1)  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  [0 0 0 0 1 63 240 0 0 0 0 0 0 63 240 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point>
POINT EMPTY                                         SRID=4326;POINT EMPTY  [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127]  [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127]  [0 0 0 0 1 127 248 0 0 0 0 0 0 127 248 0 0 0 0 0 0]  [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127]  <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates></coordinates></Point>
NULL                                                NULL  NULL  NULL  NULL  NULL  NULL

query TTT
SELECT
  ST_AsGeoJSON(geog),
  ST_AsGeoJSON(geog, 6, 8),
  ST_AsGeoJSON(geog, 6, 5)
FROM parse_test ORDER BY id ASC
----
{"type":"Point","coordinates":[1.555,-2]}  {"type":"Point","coordinates":[1.555,-2]}  {"type":"Point","bbox":[1.555,-2,1.555,-2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1.555,-2]}
{"type":"Point","coordinates":[1,2]}       {"type":"Point","coordinates":[1,2]}       {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]}       {"type":"Point","coordinates":[1,2]}       {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]}       {"type":"Point","coordinates":[1,2]}       {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]}       {"type":"Point","coordinates":[1,2]}       {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,1]}       {"type":"Point","coordinates":[1,1]}       {"type":"Point","bbox":[1,1,1,1],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,1]}
{"type":"Point","coordinates":[1,1]}       {"type":"Point","coordinates":[1,1]}       {"type":"Point","bbox":[1,1,1,1],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,1]}
{"type":"Point","coordinates":[]}          {"type":"Point","coordinates":[]}          {"type":"Point","crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[]}
NULL                                       NULL                                       NULL

query T
select st_asgeojson(
  ('0101000000000000000000F03F000000000000F03F':::GEOMETRY,),
  '':::STRING::STRING,
  2088580099783884006:::INT8::INT8,
  false::BOOL
)::STRING AS regression_57983
----
{"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {}, "type": "Feature"}

query TTT nosort
SELECT ST_AsEWKT(g), ST_GeoHash(g), ST_GeoHash(g, 8) FROM ( VALUES
  ('POINT (0 0)'::geography),
  ('LINESTRING(0 0, 1 0)'::geography)
) t(g)
----
SRID=4326;POINT (0 0)            s0000000000000000000  s0000000
SRID=4326;LINESTRING (0 0, 1 0)  ·                     s00252h0

# tests casts
query TTT
SELECT
  geog::bytea,
  geog::jsonb,
  geog::string
FROM parse_test ORDER BY id ASC
----
[1 1 0 0 32 230 16 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192]  {"coordinates": [1.555, -2], "type": "Point"}  0101000020E6100000E17A14AE47E1F83F00000000000000C0
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]             {"coordinates": [1, 2], "type": "Point"}       0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]             {"coordinates": [1, 2], "type": "Point"}       0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]             {"coordinates": [1, 2], "type": "Point"}       0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64]             {"coordinates": [1, 2], "type": "Point"}       0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]           {"coordinates": [1, 1], "type": "Point"}       0101000020E6100000000000000000F03F000000000000F03F
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63]           {"coordinates": [1, 1], "type": "Point"}       0101000020E6100000000000000000F03F000000000000F03F
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127]         {"coordinates": [], "type": "Point"}           0101000020E6100000000000000000F87F000000000000F87F
NULL                                                                    NULL                                           NULL

query TTT
SELECT
  geog::bytea::geography,
  geog::jsonb::geography,
  geog::string::geography
FROM parse_test ORDER BY id ASC
----
0101000020E6100000E17A14AE47E1F83F00000000000000C0  0101000020E6100000E17A14AE47E1F83F00000000000000C0  0101000020E6100000E17A14AE47E1F83F00000000000000C0
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F
0101000020E6100000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F
0101000020E6100000000000000000F87F000000000000F87F  0101000020E6100000000000000000F87F000000000000F87F  0101000020E6100000000000000000F87F000000000000F87F
NULL                                                NULL                                                NULL

query TTTT
SELECT
  ST_AsHexWKB(geog),
  ST_AsHexEWKB(geog),
  ST_AsHexEWKB(geog, 'ndr'),
  ST_AsHexEWKB(geog, 'xdr')
FROM parse_test ORDER BY id ASC
----
0101000000E17A14AE47E1F83F00000000000000C0  0101000020E6100000E17A14AE47E1F83F00000000000000C0  0101000020E6100000E17A14AE47E1F83F00000000000000C0  0020000001000010E63FF8E147AE147AE1C000000000000000
0101000000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0101000020E6100000000000000000F03F0000000000000040  0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F  0020000001000010E63FF00000000000003FF0000000000000
0101000000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F  0020000001000010E63FF00000000000003FF0000000000000
0101000000000000000000F87F000000000000F87F  0101000020E6100000000000000000F87F000000000000F87F  0101000020E6100000000000000000F87F000000000000F87F  0020000001000010E67FF80000000000007FF8000000000000
NULL                                        NULL                                                NULL                                                NULL

query T nosort
SELECT
  ST_AsText(g)
FROM ( VALUES
  (ST_PointFromGeoHash('s000000000000000')),
  (ST_PointFromGeoHash('kkqnpkue9ktbpe5')),
  (ST_PointFromGeoHash('w000000000000000')),
  (ST_PointFromGeoHash('w000000000000000',5)),
  (ST_GeomFromGeoHash('s000000000000000')),
  (ST_GeomFromGeoHash('kkqnpkue9ktbpe5')),
  (ST_GeomFromGeoHash('w000000000000000')),
  (ST_GeomFromGeoHash('w000000000000000',5))
) tbl(g)
----
POINT (0.000000000163709 0.000000000081855)
POINT (20.01234499963175 -20.01234499963175)
POINT (90.000000000163709 0.000000000081855)
POINT (90.02197265625 0.02197265625)
POLYGON ((0 0, 0 0.000000000163709, 0.000000000327418 0.000000000163709, 0.000000000327418 0, 0 0))
POLYGON ((20.012344998976914 -20.012345000286587, 20.012344998976914 -20.012344998976914, 20.012345000286587 -20.012344998976914, 20.012345000286587 -20.012345000286587, 20.012344998976914 -20.012345000286587))
POLYGON ((90 0, 90 0.000000000163709, 90.000000000327418 0.000000000163709, 90.000000000327418 0, 90 0))
POLYGON ((90 0, 90 0.0439453125, 90.0439453125 0.0439453125, 90.0439453125 0, 90 0))

statement error pq: st_pointfromgeohash\(\): invalid GeoHash: geohash decode '----': invalid character at index 0
SELECT ST_AsText(ST_PointFromGeoHash('----'))

statement error pq: st_pointfromgeohash\(\): length of GeoHash must be greater than 0
SELECT ST_AsText(ST_PointFromGeoHash(''))

query TTTTTTTT
SELECT
  ST_PointFromText('POINT(1.0 1.0)'),
  ST_PointFromText('POINT(1.0 1.0)', 4326),
  ST_PointFromText('LINESTRING(1.0 1.0, 2.0 2.0)'),
  ST_PointFromText('LINESTRING(1.0 1.0, 2.0 2.0)', 4326),
  ST_PointFromWKB(ST_AsBinary('POINT(1.0 1.0)'::geometry)),
  ST_PointFromWKB(ST_AsBinary('POINT(1.0 1.0)'::geometry), 4326),
  ST_PointFromWKB(ST_AsBinary('LINESTRING(1.0 1.0, 2.0 2.0)'::geometry)),
  ST_PointFromWKB(ST_AsBinary('LINESTRING(1.0 1.0, 2.0 2.0)'::geometry), 4326)
----
0101000000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F  NULL  NULL  0101000000000000000000F03F000000000000F03F  0101000020E6100000000000000000F03F000000000000F03F  NULL  NULL

subtest geom_operators

statement ok
CREATE TABLE geom_operators_test (
  dsc TEXT PRIMARY KEY,
  geom GEOMETRY
)

statement ok
INSERT INTO geom_operators_test VALUES
  ('NULL', NULL),
  ('Square (left)', 'POLYGON((-1.0 0.0, 0.0 0.0, 0.0 1.0, -1.0 1.0, -1.0 0.0))'),
  ('Point middle of Left Square', 'POINT(-0.5 0.5)'),
  ('Square (right)', 'POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0))'),
  ('Point middle of Right Square', 'POINT(0.5 0.5)'),
  ('Square overlapping left and right square', 'POLYGON((-0.1 0.0, 1.0 0.0, 1.0 1.0, -0.1 1.0, -0.1 0.0))'),
  ('Line going through left and right square', 'LINESTRING(-0.5 0.5, 0.5 0.5)'),
  ('Faraway point', 'POINT(5.0 5.0)'),
  ('Empty LineString', 'LINESTRING EMPTY'),
  ('Empty Point', 'POINT EMPTY'),
  ('Empty GeometryCollection', 'GEOMETRYCOLLECTION EMPTY'),
  ('Nested Geometry Collection', 'GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(0 0)))'::geometry)
  -- ('Partially Empty GeometryCollection', 'GEOMETRYCOLLECTION ( LINESTRING EMPTY, POINT (0.0 0.0) )') -- some of these cases crash GEOS.

# GROUP BY
query TR
SELECT
  a.dsc,
  ST_Area(a.geom)
FROM geom_operators_test a
GROUP BY a.dsc, a.geom
ORDER BY a.dsc
----
Empty GeometryCollection                  0
Empty LineString                          0
Empty Point                               0
Faraway point                             0
Line going through left and right square  0
NULL                                      NULL
Nested Geometry Collection                0
Point middle of Left Square               0
Point middle of Right Square              0
Square (left)                             1
Square (right)                            1
Square overlapping left and right square  1.1

# *BBox operators
query TBTTT
SELECT
  dsc,
  PostGIS_HasBBox(geom),
  ST_AsEWKT(PostGIS_AddBBox(geom)),
  PostGIS_GetBBox(geom),
  ST_AsEWKT(PostGIS_DropBBox(geom))
FROM geom_operators_test
ORDER BY dsc ASC
----
Empty GeometryCollection                  false  GEOMETRYCOLLECTION EMPTY                               NULL                    GEOMETRYCOLLECTION EMPTY
Empty LineString                          false  LINESTRING EMPTY                                       NULL                    LINESTRING EMPTY
Empty Point                               false  POINT EMPTY                                            NULL                    POINT EMPTY
Faraway point                             false  POINT (5 5)                                            BOX(5 5,5 5)            POINT (5 5)
Line going through left and right square  true   LINESTRING (-0.5 0.5, 0.5 0.5)                         BOX(-0.5 0.5,0.5 0.5)   LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                      NULL   NULL                                                   NULL                    NULL
Nested Geometry Collection                true   GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  BOX(0 0,0 0)            GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Point middle of Left Square               false  POINT (-0.5 0.5)                                       BOX(-0.5 0.5,-0.5 0.5)  POINT (-0.5 0.5)
Point middle of Right Square              false  POINT (0.5 0.5)                                        BOX(0.5 0.5,0.5 0.5)    POINT (0.5 0.5)
Square (left)                             true   POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 BOX(-1 0,0 1)           POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (right)                            true   POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    BOX(0 0,1 1)            POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square overlapping left and right square  true   POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           BOX(-0.1 0,1 1)         POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))

# Validity checking.
query TBBBTTTT nosort
SELECT
  dsc,
  ST_IsValid(geom),
  ST_IsValid(geom, 0),
  ST_IsValid(geom, 1),
  ST_IsValidReason(geom),
  ST_IsValidReason(geom, 0),
  ST_IsValidReason(geom, 1),
  ST_AsEWKT(ST_MakeValid(geom))
FROM ( VALUES
  ('valid geom', 'POINT(1.0 2.0)'::geometry),
  ('invalid polygon', 'POLYGON((1.0 1.0, 2.0 2.0, 1.5 1.5, 1.5 -1.5, 1.0 1.0))'::geometry),
  ('self-intersecting polygon', 'POLYGON ((14 20, 8 45, 20 35, 14 20, 16 30, 12 30, 14 20))'::geometry)
) t(dsc, geom)
----
valid geom                 true   true   true   Valid Geometry                   Valid Geometry          Valid Geometry     POINT (1 2)
invalid polygon            false  false  false  Ring Self-intersection[1.5 1.5]  Ring Self-intersection  Self-intersection  GEOMETRYCOLLECTION (POLYGON ((1.5 1.5, 1.5 -1.5, 1 1, 1.5 1.5)), LINESTRING (1.5 1.5, 2 2))
self-intersecting polygon  false  false  true   Ring Self-intersection[14 20]    Ring Self-intersection  Valid Geometry     POLYGON ((8 45, 20 35, 14 20, 8 45), (16 30, 12 30, 14 20, 16 30))

query TB
SELECT
  dsc,
  ST_IsValidTrajectory(geom)
FROM ( VALUES
  ('valid trajectory', 'LINESTRINGM(0 0 1,0 1 2)'::geometry)
) t(dsc, geom)
----
valid trajectory  true

# Unary operators
query TRRRRRRRT
SELECT
  a.dsc,
  ST_Area(a.geom),
  ST_Area2D(a.geom),
  ST_Length(a.geom),
  ST_Length2D(a.geom),
  ST_Perimeter(a.geom),
  ST_Perimeter2D(a.geom),
  ST_MinimumClearance(a.geom),
  ST_AsText(ST_MinimumClearanceLine(a.geom))
FROM geom_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  0     0     0     0     0     0     +Inf  LINESTRING EMPTY
Empty LineString                          0     0     0     0     0     0     +Inf  LINESTRING EMPTY
Empty Point                               0     0     0     0     0     0     +Inf  LINESTRING EMPTY
Faraway point                             0     0     0     0     0     0     +Inf  LINESTRING EMPTY
Line going through left and right square  0     0     1     1     0     0     1     LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                      NULL  NULL  NULL  NULL  NULL  NULL  NULL  NULL
Nested Geometry Collection                0     0     0     0     0     0     +Inf  LINESTRING EMPTY
Point middle of Left Square               0     0     0     0     0     0     +Inf  LINESTRING EMPTY
Point middle of Right Square              0     0     0     0     0     0     +Inf  LINESTRING EMPTY
Square (left)                             1     1     0     0     4     4     1     LINESTRING (-1 0, 0 0)
Square (right)                            1     1     0     0     4     4     1     LINESTRING (0 0, 1 0)
Square overlapping left and right square  1.1   1.1   0     0     4.2   4.2   1     LINESTRING (-0.1 0, -0.1 1)

# Unary predicates
query TBBBB
SELECT
  dsc,
  ST_IsEmpty(geom),
  ST_IsCollection(geom),
  ST_IsClosed(geom),
  ST_IsSimple(geom)
FROM geom_operators_test
ORDER BY dsc
----
Empty GeometryCollection                  true   true   false  true
Empty LineString                          true   false  false  true
Empty Point                               true   false  false  true
Faraway point                             false  false  true   true
Line going through left and right square  false  false  false  true
NULL                                      NULL   NULL   NULL   NULL
Nested Geometry Collection                false  true   true   true
Point middle of Left Square               false  false  true   true
Point middle of Right Square              false  false  true   true
Square (left)                             false  false  true   true
Square (right)                            false  false  true   true
Square overlapping left and right square  false  false  true   true

query BBB nosort
SELECT
  ST_IsRing(geom),
  ST_IsClosed(geom),
  ST_IsSimple(geom)
FROM ( VALUES
  ('LINESTRING EMPTY'::geometry),
  ('LINESTRING(0 0, 1 1)'::geometry),
  ('LINESTRING(0 0, 1 1, 0 0)'::geometry),
  ('LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)'::geometry)
) tbl(geom)
----
false  false  true
false  false  true
false  true   false
true   true   true

statement error st_isring\(\): should only be called on a linear feature: geom: unsupported type \*geom.Point
SELECT ST_IsRing('POINT(0 0)')

# Topology operators

query TTTB
SELECT
  a.dsc,
  b.dsc,
  ST_AsEWKT(ST_Intersection(a.geom, b.geom)),
  ST_Intersection(a.geom, b.geom) = ST_Intersection(a.geom::string, b.geom::string)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Empty LineString                          GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Empty Point                               GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Faraway point                             GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Line going through left and right square  GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  NULL                                      NULL                                          NULL
Empty GeometryCollection                  Nested Geometry Collection                GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Point middle of Left Square               GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Point middle of Right Square              GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Square (left)                             GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Square (right)                            GEOMETRYCOLLECTION EMPTY                      true
Empty GeometryCollection                  Square overlapping left and right square  GEOMETRYCOLLECTION EMPTY                      true
Empty LineString                          Empty GeometryCollection                  LINESTRING EMPTY                              true
Empty LineString                          Empty LineString                          LINESTRING EMPTY                              true
Empty LineString                          Empty Point                               LINESTRING EMPTY                              true
Empty LineString                          Faraway point                             LINESTRING EMPTY                              true
Empty LineString                          Line going through left and right square  LINESTRING EMPTY                              true
Empty LineString                          NULL                                      NULL                                          NULL
Empty LineString                          Nested Geometry Collection                LINESTRING EMPTY                              true
Empty LineString                          Point middle of Left Square               LINESTRING EMPTY                              true
Empty LineString                          Point middle of Right Square              LINESTRING EMPTY                              true
Empty LineString                          Square (left)                             LINESTRING EMPTY                              true
Empty LineString                          Square (right)                            LINESTRING EMPTY                              true
Empty LineString                          Square overlapping left and right square  LINESTRING EMPTY                              true
Empty Point                               Empty GeometryCollection                  POINT EMPTY                                   true
Empty Point                               Empty LineString                          POINT EMPTY                                   true
Empty Point                               Empty Point                               POINT EMPTY                                   true
Empty Point                               Faraway point                             POINT EMPTY                                   true
Empty Point                               Line going through left and right square  POINT EMPTY                                   true
Empty Point                               NULL                                      NULL                                          NULL
Empty Point                               Nested Geometry Collection                POINT EMPTY                                   true
Empty Point                               Point middle of Left Square               POINT EMPTY                                   true
Empty Point                               Point middle of Right Square              POINT EMPTY                                   true
Empty Point                               Square (left)                             POINT EMPTY                                   true
Empty Point                               Square (right)                            POINT EMPTY                                   true
Empty Point                               Square overlapping left and right square  POINT EMPTY                                   true
Faraway point                             Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Faraway point                             Empty LineString                          LINESTRING EMPTY                              true
Faraway point                             Empty Point                               POINT EMPTY                                   true
Faraway point                             Faraway point                             POINT (5 5)                                   true
Faraway point                             Line going through left and right square  POINT EMPTY                                   true
Faraway point                             NULL                                      NULL                                          NULL
Faraway point                             Nested Geometry Collection                POINT EMPTY                                   true
Faraway point                             Point middle of Left Square               POINT EMPTY                                   true
Faraway point                             Point middle of Right Square              POINT EMPTY                                   true
Faraway point                             Square (left)                             POINT EMPTY                                   true
Faraway point                             Square (right)                            POINT EMPTY                                   true
Faraway point                             Square overlapping left and right square  POINT EMPTY                                   true
Line going through left and right square  Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Line going through left and right square  Empty LineString                          LINESTRING EMPTY                              true
Line going through left and right square  Empty Point                               POINT EMPTY                                   true
Line going through left and right square  Faraway point                             POINT EMPTY                                   true
Line going through left and right square  Line going through left and right square  LINESTRING (-0.5 0.5, 0.5 0.5)                true
Line going through left and right square  NULL                                      NULL                                          NULL
Line going through left and right square  Nested Geometry Collection                POINT EMPTY                                   true
Line going through left and right square  Point middle of Left Square               POINT (-0.5 0.5)                              true
Line going through left and right square  Point middle of Right Square              POINT (0.5 0.5)                               true
Line going through left and right square  Square (left)                             LINESTRING (-0.5 0.5, 0 0.5)                  true
Line going through left and right square  Square (right)                            LINESTRING (0 0.5, 0.5 0.5)                   true
Line going through left and right square  Square overlapping left and right square  LINESTRING (-0.1 0.5, 0.5 0.5)                true
NULL                                      Empty GeometryCollection                  NULL                                          NULL
NULL                                      Empty LineString                          NULL                                          NULL
NULL                                      Empty Point                               NULL                                          NULL
NULL                                      Faraway point                             NULL                                          NULL
NULL                                      Line going through left and right square  NULL                                          NULL
NULL                                      NULL                                      NULL                                          NULL
NULL                                      Nested Geometry Collection                NULL                                          NULL
NULL                                      Point middle of Left Square               NULL                                          NULL
NULL                                      Point middle of Right Square              NULL                                          NULL
NULL                                      Square (left)                             NULL                                          NULL
NULL                                      Square (right)                            NULL                                          NULL
NULL                                      Square overlapping left and right square  NULL                                          NULL
Nested Geometry Collection                Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Nested Geometry Collection                Empty LineString                          LINESTRING EMPTY                              true
Nested Geometry Collection                Empty Point                               POINT EMPTY                                   true
Nested Geometry Collection                Faraway point                             POINT EMPTY                                   true
Nested Geometry Collection                Line going through left and right square  POINT EMPTY                                   true
Nested Geometry Collection                NULL                                      NULL                                          NULL
Nested Geometry Collection                Nested Geometry Collection                POINT (0 0)                                   true
Nested Geometry Collection                Point middle of Left Square               POINT EMPTY                                   true
Nested Geometry Collection                Point middle of Right Square              POINT EMPTY                                   true
Nested Geometry Collection                Square (left)                             POINT (0 0)                                   true
Nested Geometry Collection                Square (right)                            POINT (0 0)                                   true
Nested Geometry Collection                Square overlapping left and right square  POINT (0 0)                                   true
Point middle of Left Square               Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Point middle of Left Square               Empty LineString                          LINESTRING EMPTY                              true
Point middle of Left Square               Empty Point                               POINT EMPTY                                   true
Point middle of Left Square               Faraway point                             POINT EMPTY                                   true
Point middle of Left Square               Line going through left and right square  POINT (-0.5 0.5)                              true
Point middle of Left Square               NULL                                      NULL                                          NULL
Point middle of Left Square               Nested Geometry Collection                POINT EMPTY                                   true
Point middle of Left Square               Point middle of Left Square               POINT (-0.5 0.5)                              true
Point middle of Left Square               Point middle of Right Square              POINT EMPTY                                   true
Point middle of Left Square               Square (left)                             POINT (-0.5 0.5)                              true
Point middle of Left Square               Square (right)                            POINT EMPTY                                   true
Point middle of Left Square               Square overlapping left and right square  POINT EMPTY                                   true
Point middle of Right Square              Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Point middle of Right Square              Empty LineString                          LINESTRING EMPTY                              true
Point middle of Right Square              Empty Point                               POINT EMPTY                                   true
Point middle of Right Square              Faraway point                             POINT EMPTY                                   true
Point middle of Right Square              Line going through left and right square  POINT (0.5 0.5)                               true
Point middle of Right Square              NULL                                      NULL                                          NULL
Point middle of Right Square              Nested Geometry Collection                POINT EMPTY                                   true
Point middle of Right Square              Point middle of Left Square               POINT EMPTY                                   true
Point middle of Right Square              Point middle of Right Square              POINT (0.5 0.5)                               true
Point middle of Right Square              Square (left)                             POINT EMPTY                                   true
Point middle of Right Square              Square (right)                            POINT (0.5 0.5)                               true
Point middle of Right Square              Square overlapping left and right square  POINT (0.5 0.5)                               true
Square (left)                             Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Square (left)                             Empty LineString                          LINESTRING EMPTY                              true
Square (left)                             Empty Point                               POINT EMPTY                                   true
Square (left)                             Faraway point                             POINT EMPTY                                   true
Square (left)                             Line going through left and right square  LINESTRING (-0.5 0.5, 0 0.5)                  true
Square (left)                             NULL                                      NULL                                          NULL
Square (left)                             Nested Geometry Collection                POINT (0 0)                                   true
Square (left)                             Point middle of Left Square               POINT (-0.5 0.5)                              true
Square (left)                             Point middle of Right Square              POINT EMPTY                                   true
Square (left)                             Square (left)                             POLYGON ((-1 0, -1 1, 0 1, 0 0, -1 0))        true
Square (left)                             Square (right)                            LINESTRING (0 0, 0 1)                         true
Square (left)                             Square overlapping left and right square  POLYGON ((-0.1 0, -0.1 1, 0 1, 0 0, -0.1 0))  true
Square (right)                            Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Square (right)                            Empty LineString                          LINESTRING EMPTY                              true
Square (right)                            Empty Point                               POINT EMPTY                                   true
Square (right)                            Faraway point                             POINT EMPTY                                   true
Square (right)                            Line going through left and right square  LINESTRING (0 0.5, 0.5 0.5)                   true
Square (right)                            NULL                                      NULL                                          NULL
Square (right)                            Nested Geometry Collection                POINT (0 0)                                   true
Square (right)                            Point middle of Left Square               POINT EMPTY                                   true
Square (right)                            Point middle of Right Square              POINT (0.5 0.5)                               true
Square (right)                            Square (left)                             LINESTRING (0 1, 0 0)                         true
Square (right)                            Square (right)                            POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))           true
Square (right)                            Square overlapping left and right square  POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))           true
Square overlapping left and right square  Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      true
Square overlapping left and right square  Empty LineString                          LINESTRING EMPTY                              true
Square overlapping left and right square  Empty Point                               POINT EMPTY                                   true
Square overlapping left and right square  Faraway point                             POINT EMPTY                                   true
Square overlapping left and right square  Line going through left and right square  LINESTRING (-0.1 0.5, 0.5 0.5)                true
Square overlapping left and right square  NULL                                      NULL                                          NULL
Square overlapping left and right square  Nested Geometry Collection                POINT (0 0)                                   true
Square overlapping left and right square  Point middle of Left Square               POINT EMPTY                                   true
Square overlapping left and right square  Point middle of Right Square              POINT (0.5 0.5)                               true
Square overlapping left and right square  Square (left)                             POLYGON ((-0.1 0, -0.1 1, 0 1, 0 0, -0.1 0))  true
Square overlapping left and right square  Square (right)                            POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))           true
Square overlapping left and right square  Square overlapping left and right square  POLYGON ((-0.1 0, -0.1 1, 1 1, 1 0, -0.1 0))  true

query TTTT
SELECT
  a.dsc,
  ST_AsEWKT(ST_Centroid(a.geom)),
  ST_AsEWKT(ST_PointOnSurface(a.geom)),
  ST_AsEWKT(ST_ConvexHull(a.geom))
FROM geom_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  POINT EMPTY       POINT EMPTY       GEOMETRYCOLLECTION EMPTY
Empty LineString                          POINT EMPTY       POINT EMPTY       GEOMETRYCOLLECTION EMPTY
Empty Point                               POINT EMPTY       POINT EMPTY       GEOMETRYCOLLECTION EMPTY
Faraway point                             POINT (5 5)       POINT (5 5)       POINT (5 5)
Line going through left and right square  POINT (0 0.5)     POINT (-0.5 0.5)  LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                      NULL              NULL              NULL
Nested Geometry Collection                POINT (0 0)       POINT (0 0)       POINT (0 0)
Point middle of Left Square               POINT (-0.5 0.5)  POINT (-0.5 0.5)  POINT (-0.5 0.5)
Point middle of Right Square              POINT (0.5 0.5)   POINT (0.5 0.5)   POINT (0.5 0.5)
Square (left)                             POINT (-0.5 0.5)  POINT (-0.5 0.5)  POLYGON ((-1 0, -1 1, 0 1, 0 0, -1 0))
Square (right)                            POINT (0.5 0.5)   POINT (0.5 0.5)   POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))
Square overlapping left and right square  POINT (0.45 0.5)  POINT (0.45 0.5)  POLYGON ((-0.1 0, -0.1 1, 1 1, 1 0, -0.1 0))

query TT
SELECT
  a.dsc,
  ST_AsEWKT(ST_Boundary(a.geom))
FROM geom_operators_test a
WHERE NOT ST_IsCollection(a.geom)
ORDER BY a.dsc
----
Empty LineString                          LINESTRING EMPTY
Empty Point                               POINT EMPTY
Faraway point                             GEOMETRYCOLLECTION EMPTY
Line going through left and right square  MULTIPOINT (-0.5 0.5, 0.5 0.5)
Point middle of Left Square               GEOMETRYCOLLECTION EMPTY
Point middle of Right Square              GEOMETRYCOLLECTION EMPTY
Square (left)                             LINESTRING (-1 0, 0 0, 0 1, -1 1, -1 0)
Square (right)                            LINESTRING (0 0, 1 0, 1 1, 0 1, 0 0)
Square overlapping left and right square  LINESTRING (-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)

query TTT
SELECT
  a.dsc,
  ST_AsEWKT(ST_Simplify(a.geom, 0.2)),
  ST_AsEWKT(ST_SimplifyPreserveTopology(a.geom, 0.2))
FROM geom_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
Empty LineString                          LINESTRING EMPTY                                       LINESTRING EMPTY
Empty Point                               POINT EMPTY                                            POINT EMPTY
Faraway point                             POINT (5 5)                                            POINT (5 5)
Line going through left and right square  LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                      NULL                                                   NULL
Nested Geometry Collection                GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Point middle of Left Square               POINT (-0.5 0.5)                                       POINT (-0.5 0.5)
Point middle of Right Square              POINT (0.5 0.5)                                        POINT (0.5 0.5)
Square (left)                             POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (right)                            POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square overlapping left and right square  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))

query TTT nosort
SELECT
  ST_AsEWKT(ST_Simplify(g, 10)),
  ST_AsEWKT(ST_Simplify(g, 10, false)),
  ST_AsEWKT(ST_Simplify(g, 10, true))
FROM ( VALUES
  ('POLYGON((-1 -1, -1 1, 1 1, 1 -1, -1 -1), (0 0, 100 0, 100 100, 0 100, 0 0))'::geometry),
  ('LINESTRING(-1 -1, -1 1, 1 1, 1 -1, -1 -1)'::geometry)
) t(g)
----
POLYGON EMPTY              NULL  POLYGON ((-1 -1, -1 1, 1 1, -1 -1), (0 0, 100 0, 100 100, 0 100, 0 0))
LINESTRING (-1 -1, -1 -1)  NULL  LINESTRING (-1 -1, -1 -1)

query TT
SELECT
  a.dsc,
  ST_AsEWKT(ST_ClipByBox2D(a.geom, 'box(0 0, 0.5 0.5)'))
FROM geom_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY
Empty LineString                          LINESTRING EMPTY
Empty Point                               POINT EMPTY
Faraway point                             GEOMETRYCOLLECTION EMPTY
Line going through left and right square  GEOMETRYCOLLECTION EMPTY
NULL                                      NULL
Nested Geometry Collection                GEOMETRYCOLLECTION EMPTY
Point middle of Left Square               GEOMETRYCOLLECTION EMPTY
Point middle of Right Square              GEOMETRYCOLLECTION EMPTY
Square (left)                             GEOMETRYCOLLECTION EMPTY
Square (right)                            POLYGON ((0 0, 0 0.5, 0.5 0.5, 0.5 0, 0 0))
Square overlapping left and right square  POLYGON ((0 0, 0 0.5, 0.5 0.5, 0.5 0, 0 0))

query TT
SELECT
 ST_AsEWKT(ST_SymDifference(a.geom, b.geom)),
 ST_AsEWKT(ST_SymmetricDifference(a.geom, b.geom))
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
GEOMETRYCOLLECTION EMPTY                                                                                      GEOMETRYCOLLECTION EMPTY
LINESTRING EMPTY                                                                                              LINESTRING EMPTY
POINT EMPTY                                                                                                   POINT EMPTY
POINT (5 5)                                                                                                   POINT (5 5)
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                                                                                          NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))                                                         GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
POINT (-0.5 0.5)                                                                                              POINT (-0.5 0.5)
POINT (0.5 0.5)                                                                                               POINT (0.5 0.5)
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                                                                        POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                                                           POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))                                                                  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
LINESTRING EMPTY                                                                                              LINESTRING EMPTY
LINESTRING EMPTY                                                                                              LINESTRING EMPTY
LINESTRING EMPTY                                                                                              LINESTRING EMPTY
POINT (5 5)                                                                                                   POINT (5 5)
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                                                                                          NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))                                                         GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
POINT (-0.5 0.5)                                                                                              POINT (-0.5 0.5)
POINT (0.5 0.5)                                                                                               POINT (0.5 0.5)
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                                                                        POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                                                           POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))                                                                  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
POINT EMPTY                                                                                                   POINT EMPTY
LINESTRING EMPTY                                                                                              LINESTRING EMPTY
POINT EMPTY                                                                                                   POINT EMPTY
POINT (5 5)                                                                                                   POINT (5 5)
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                                                                                          NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))                                                         GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
POINT (-0.5 0.5)                                                                                              POINT (-0.5 0.5)
POINT (0.5 0.5)                                                                                               POINT (0.5 0.5)
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                                                                        POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                                                           POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))                                                                  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
POINT (5 5)                                                                                                   POINT (5 5)
POINT (5 5)                                                                                                   POINT (5 5)
POINT (5 5)                                                                                                   POINT (5 5)
POINT EMPTY                                                                                                   POINT EMPTY
GEOMETRYCOLLECTION (POINT (5 5), LINESTRING (-0.5 0.5, 0.5 0.5))                                              GEOMETRYCOLLECTION (POINT (5 5), LINESTRING (-0.5 0.5, 0.5 0.5))
NULL                                                                                                          NULL
GEOMETRYCOLLECTION (POINT (5 5), GEOMETRYCOLLECTION (POINT (0 0)))                                            GEOMETRYCOLLECTION (POINT (5 5), GEOMETRYCOLLECTION (POINT (0 0)))
MULTIPOINT (5 5, -0.5 0.5)                                                                                    MULTIPOINT (5 5, -0.5 0.5)
MULTIPOINT (5 5, 0.5 0.5)                                                                                     MULTIPOINT (5 5, 0.5 0.5)
GEOMETRYCOLLECTION (POINT (5 5), POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)))                                      GEOMETRYCOLLECTION (POINT (5 5), POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)))
GEOMETRYCOLLECTION (POINT (5 5), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)))                                         GEOMETRYCOLLECTION (POINT (5 5), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)))
GEOMETRYCOLLECTION (POINT (5 5), POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)))                                GEOMETRYCOLLECTION (POINT (5 5), POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)))
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
GEOMETRYCOLLECTION (LINESTRING (-0.5 0.5, 0.5 0.5), POINT (5 5))                                              GEOMETRYCOLLECTION (LINESTRING (-0.5 0.5, 0.5 0.5), POINT (5 5))
LINESTRING EMPTY                                                                                              LINESTRING EMPTY
NULL                                                                                                          NULL
GEOMETRYCOLLECTION (LINESTRING (-0.5 0.5, 0.5 0.5), GEOMETRYCOLLECTION (POINT (0 0)))                         GEOMETRYCOLLECTION (LINESTRING (-0.5 0.5, 0.5 0.5), GEOMETRYCOLLECTION (POINT (0 0)))
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
GEOMETRYCOLLECTION (POLYGON ((0 0, -1 0, -1 1, 0 1, 0 0.5, 0 0)), LINESTRING (0 0.5, 0.5 0.5))                GEOMETRYCOLLECTION (POLYGON ((0 0, -1 0, -1 1, 0 1, 0 0.5, 0 0)), LINESTRING (0 0.5, 0.5 0.5))
GEOMETRYCOLLECTION (POLYGON ((0 1, 1 1, 1 0, 0 0, 0 0.5, 0 1)), LINESTRING (-0.5 0.5, 0 0.5))                 GEOMETRYCOLLECTION (POLYGON ((0 1, 1 1, 1 0, 0 0, 0 0.5, 0 1)), LINESTRING (-0.5 0.5, 0 0.5))
GEOMETRYCOLLECTION (POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 0.5, -0.1 1)), LINESTRING (-0.5 0.5, -0.1 0.5))  GEOMETRYCOLLECTION (POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 0.5, -0.1 1)), LINESTRING (-0.5 0.5, -0.1 0.5))
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
NULL                                                                                                          NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))                                                         GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))                                                         GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))                                                         GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)), POINT (5 5))                                            GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)), POINT (5 5))
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)), LINESTRING (-0.5 0.5, 0.5 0.5))                         GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)), LINESTRING (-0.5 0.5, 0.5 0.5))
NULL                                                                                                          NULL
POINT EMPTY                                                                                                   POINT EMPTY
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)), POINT (-0.5 0.5))                                       GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)), POINT (-0.5 0.5))
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)), POINT (0.5 0.5))                                        GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)), POINT (0.5 0.5))
POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))                                                                        POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))
POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))                                                                           POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))
POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))                                                                  POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))
POINT (-0.5 0.5)                                                                                              POINT (-0.5 0.5)
POINT (-0.5 0.5)                                                                                              POINT (-0.5 0.5)
POINT (-0.5 0.5)                                                                                              POINT (-0.5 0.5)
MULTIPOINT (-0.5 0.5, 5 5)                                                                                    MULTIPOINT (-0.5 0.5, 5 5)
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                                                                                          NULL
GEOMETRYCOLLECTION (POINT (-0.5 0.5), GEOMETRYCOLLECTION (POINT (0 0)))                                       GEOMETRYCOLLECTION (POINT (-0.5 0.5), GEOMETRYCOLLECTION (POINT (0 0)))
POINT EMPTY                                                                                                   POINT EMPTY
MULTIPOINT (-0.5 0.5, 0.5 0.5)                                                                                MULTIPOINT (-0.5 0.5, 0.5 0.5)
POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))                                                                        POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))
GEOMETRYCOLLECTION (POINT (-0.5 0.5), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)))                                    GEOMETRYCOLLECTION (POINT (-0.5 0.5), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)))
GEOMETRYCOLLECTION (POINT (-0.5 0.5), POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)))                           GEOMETRYCOLLECTION (POINT (-0.5 0.5), POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)))
POINT (0.5 0.5)                                                                                               POINT (0.5 0.5)
POINT (0.5 0.5)                                                                                               POINT (0.5 0.5)
POINT (0.5 0.5)                                                                                               POINT (0.5 0.5)
MULTIPOINT (0.5 0.5, 5 5)                                                                                     MULTIPOINT (0.5 0.5, 5 5)
LINESTRING (-0.5 0.5, 0.5 0.5)                                                                                LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                                                                                          NULL
GEOMETRYCOLLECTION (POINT (0.5 0.5), GEOMETRYCOLLECTION (POINT (0 0)))                                        GEOMETRYCOLLECTION (POINT (0.5 0.5), GEOMETRYCOLLECTION (POINT (0 0)))
MULTIPOINT (0.5 0.5, -0.5 0.5)                                                                                MULTIPOINT (0.5 0.5, -0.5 0.5)
POINT EMPTY                                                                                                   POINT EMPTY
GEOMETRYCOLLECTION (POINT (0.5 0.5), POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)))                                  GEOMETRYCOLLECTION (POINT (0.5 0.5), POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)))
POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))                                                                           POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))
POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))                                                                  POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                                                                        POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                                                                        POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                                                                        POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
GEOMETRYCOLLECTION (POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)), POINT (5 5))                                      GEOMETRYCOLLECTION (POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)), POINT (5 5))
GEOMETRYCOLLECTION (POLYGON ((0 0, -1 0, -1 1, 0 1, 0 0.5, 0 0)), LINESTRING (0 0.5, 0.5 0.5))                GEOMETRYCOLLECTION (POLYGON ((0 0, -1 0, -1 1, 0 1, 0 0.5, 0 0)), LINESTRING (0 0.5, 0.5 0.5))
NULL                                                                                                          NULL
POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))                                                                        POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))
POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))                                                                        POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))
GEOMETRYCOLLECTION (POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)), POINT (0.5 0.5))                                  GEOMETRYCOLLECTION (POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)), POINT (0.5 0.5))
POLYGON EMPTY                                                                                                 POLYGON EMPTY
POLYGON ((-1 0, -1 1, 0 1, 1 1, 1 0, 0 0, -1 0))                                                              POLYGON ((-1 0, -1 1, 0 1, 1 1, 1 0, 0 0, -1 0))
MULTIPOLYGON (((-1 0, -1 1, -0.1 1, -0.1 0, -1 0)), ((0 1, 1 1, 1 0, 0 0, 0 1)))                              MULTIPOLYGON (((-1 0, -1 1, -0.1 1, -0.1 0, -1 0)), ((0 1, 1 1, 1 0, 0 0, 0 1)))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                                                           POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                                                           POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                                                           POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
GEOMETRYCOLLECTION (POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), POINT (5 5))                                         GEOMETRYCOLLECTION (POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), POINT (5 5))
GEOMETRYCOLLECTION (POLYGON ((0 1, 1 1, 1 0, 0 0, 0 0.5, 0 1)), LINESTRING (-0.5 0.5, 0 0.5))                 GEOMETRYCOLLECTION (POLYGON ((0 1, 1 1, 1 0, 0 0, 0 0.5, 0 1)), LINESTRING (-0.5 0.5, 0 0.5))
NULL                                                                                                          NULL
POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))                                                                           POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))
GEOMETRYCOLLECTION (POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), POINT (-0.5 0.5))                                    GEOMETRYCOLLECTION (POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), POINT (-0.5 0.5))
POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))                                                                           POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))
POLYGON ((1 1, 1 0, 0 0, -1 0, -1 1, 0 1, 1 1))                                                               POLYGON ((1 1, 1 0, 0 0, -1 0, -1 1, 0 1, 1 1))
POLYGON EMPTY                                                                                                 POLYGON EMPTY
POLYGON ((0 0, -0.1 0, -0.1 1, 0 1, 0 0))                                                                     POLYGON ((0 0, -0.1 0, -0.1 1, 0 1, 0 0))
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))                                                                  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))                                                                  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))                                                                  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
GEOMETRYCOLLECTION (POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)), POINT (5 5))                                GEOMETRYCOLLECTION (POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)), POINT (5 5))
GEOMETRYCOLLECTION (POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 0.5, -0.1 1)), LINESTRING (-0.5 0.5, -0.1 0.5))  GEOMETRYCOLLECTION (POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 0.5, -0.1 1)), LINESTRING (-0.5 0.5, -0.1 0.5))
NULL                                                                                                          NULL
POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))                                                                  POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))
GEOMETRYCOLLECTION (POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)), POINT (-0.5 0.5))                           GEOMETRYCOLLECTION (POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)), POINT (-0.5 0.5))
POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))                                                                  POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))
MULTIPOLYGON (((1 1, 1 0, 0 0, 0 1, 1 1)), ((-0.1 0, -1 0, -1 1, -0.1 1, -0.1 0)))                            MULTIPOLYGON (((1 1, 1 0, 0 0, 0 1, 1 1)), ((-0.1 0, -1 0, -1 1, -0.1 1, -0.1 0)))
POLYGON ((-0.1 0, -0.1 1, 0 1, 0 0, -0.1 0))                                                                  POLYGON ((-0.1 0, -0.1 1, 0 1, 0 0, -0.1 0))
POLYGON EMPTY                                                                                                 POLYGON EMPTY

# CW/CCW predicates.
query TBBTT
SELECT
  dsc,
  ST_IsPolygonCW(geom),
  ST_IsPolygonCCW(geom),
  ST_AsText(ST_ForcePolygonCW(geom)),
  ST_AsText(ST_ForcePolygonCCW(geom))
FROM geom_operators_test
ORDER BY dsc
----
Empty GeometryCollection                  true   true  GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
Empty LineString                          true   true  LINESTRING EMPTY                                       LINESTRING EMPTY
Empty Point                               true   true  POINT EMPTY                                            POINT EMPTY
Faraway point                             true   true  POINT (5 5)                                            POINT (5 5)
Line going through left and right square  true   true  LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                      NULL   NULL  NULL                                                   NULL
Nested Geometry Collection                true   true  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Point middle of Left Square               true   true  POINT (-0.5 0.5)                                       POINT (-0.5 0.5)
Point middle of Right Square              true   true  POINT (0.5 0.5)                                        POINT (0.5 0.5)
Square (left)                             false  true  POLYGON ((-1 0, -1 1, 0 1, 0 0, -1 0))                 POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (right)                            false  true  POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))                    POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square overlapping left and right square  false  true  POLYGON ((-0.1 0, -0.1 1, 1 1, 1 0, -0.1 0))           POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))

# Functions which take in strings as input as well.
query TT
SELECT
  dsc,
  ST_AsEWKT(ST_Centroid(ewkt))
FROM [SELECT dsc, ST_AsEWKT(a.geom) ewkt FROM geom_operators_test a]
ORDER BY dsc ASC
----
Empty GeometryCollection                  POINT EMPTY
Empty LineString                          POINT EMPTY
Empty Point                               POINT EMPTY
Faraway point                             POINT (5 5)
Line going through left and right square  POINT (0 0.5)
NULL                                      NULL
Nested Geometry Collection                POINT (0 0)
Point middle of Left Square               POINT (-0.5 0.5)
Point middle of Right Square              POINT (0.5 0.5)
Square (left)                             POINT (-0.5 0.5)
Square (right)                            POINT (0.5 0.5)
Square overlapping left and right square  POINT (0.45 0.5)

# Collections
query TTTT
SELECT
  dsc,
  ST_AsText(ST_Multi(geom)),
  ST_AsText(ST_CollectionHomogenize(geom)),
  ST_AsText(ST_ForceCollection(geom))
FROM geom_operators_test
ORDER BY dsc ASC
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY                      GEOMETRYCOLLECTION EMPTY
Empty LineString                          MULTILINESTRING EMPTY                                  LINESTRING EMPTY                              GEOMETRYCOLLECTION (LINESTRING EMPTY)
Empty Point                               MULTIPOINT EMPTY                                       POINT EMPTY                                   GEOMETRYCOLLECTION (POINT EMPTY)
Faraway point                             MULTIPOINT (5 5)                                       POINT (5 5)                                   GEOMETRYCOLLECTION (POINT (5 5))
Line going through left and right square  MULTILINESTRING ((-0.5 0.5, 0.5 0.5))                  LINESTRING (-0.5 0.5, 0.5 0.5)                GEOMETRYCOLLECTION (LINESTRING (-0.5 0.5, 0.5 0.5))
NULL                                      NULL                                                   NULL                                          NULL
Nested Geometry Collection                GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  POINT (0 0)                                   GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Point middle of Left Square               MULTIPOINT (-0.5 0.5)                                  POINT (-0.5 0.5)                              GEOMETRYCOLLECTION (POINT (-0.5 0.5))
Point middle of Right Square              MULTIPOINT (0.5 0.5)                                   POINT (0.5 0.5)                               GEOMETRYCOLLECTION (POINT (0.5 0.5))
Square (left)                             MULTIPOLYGON (((-1 0, 0 0, 0 1, -1 1, -1 0)))          POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))        GEOMETRYCOLLECTION (POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)))
Square (right)                            MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)))             POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))           GEOMETRYCOLLECTION (POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)))
Square overlapping left and right square  MULTIPOLYGON (((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)))    POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))  GEOMETRYCOLLECTION (POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)))

query TTTT
SELECT
  dsc,
  ST_AsEWKT(ST_CollectionExtract(geom, 1)),
  ST_AsEWKT(ST_CollectionExtract(geom, 2)),
  ST_AsEWKT(ST_CollectionExtract(geom, 3))
FROM geom_operators_test
ORDER BY dsc ASC
----
Empty GeometryCollection                  MULTIPOINT EMPTY  MULTILINESTRING EMPTY           MULTIPOLYGON EMPTY
Empty LineString                          POINT EMPTY       LINESTRING EMPTY                POLYGON EMPTY
Empty Point                               POINT EMPTY       LINESTRING EMPTY                POLYGON EMPTY
Faraway point                             POINT (5 5)       LINESTRING EMPTY                POLYGON EMPTY
Line going through left and right square  POINT EMPTY       LINESTRING (-0.5 0.5, 0.5 0.5)  POLYGON EMPTY
NULL                                      NULL              NULL                            NULL
Nested Geometry Collection                MULTIPOINT (0 0)  MULTILINESTRING EMPTY           MULTIPOLYGON EMPTY
Point middle of Left Square               POINT (-0.5 0.5)  LINESTRING EMPTY                POLYGON EMPTY
Point middle of Right Square              POINT (0.5 0.5)   LINESTRING EMPTY                POLYGON EMPTY
Square (left)                             POINT EMPTY       LINESTRING EMPTY                POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (right)                            POINT EMPTY       LINESTRING EMPTY                POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square overlapping left and right square  POINT EMPTY       LINESTRING EMPTY                POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))

statement error only point, linestring and polygon may be extracted \(got MultiPoint\)
SELECT ST_CollectionExtract(geom, 4) FROM geom_operators_test

# Binary operators
query TTRR
SELECT
  a.dsc,
  b.dsc,
  ST_Distance(a.geom, b.geom),
  ST_MaxDistance(a.geom, b.geom)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  NULL                NULL
Empty GeometryCollection                  Empty LineString                          NULL                NULL
Empty GeometryCollection                  Empty Point                               NULL                NULL
Empty GeometryCollection                  Faraway point                             NULL                NULL
Empty GeometryCollection                  Line going through left and right square  NULL                NULL
Empty GeometryCollection                  NULL                                      NULL                NULL
Empty GeometryCollection                  Nested Geometry Collection                NULL                NULL
Empty GeometryCollection                  Point middle of Left Square               NULL                NULL
Empty GeometryCollection                  Point middle of Right Square              NULL                NULL
Empty GeometryCollection                  Square (left)                             NULL                NULL
Empty GeometryCollection                  Square (right)                            NULL                NULL
Empty GeometryCollection                  Square overlapping left and right square  NULL                NULL
Empty LineString                          Empty GeometryCollection                  NULL                NULL
Empty LineString                          Empty LineString                          NULL                NULL
Empty LineString                          Empty Point                               NULL                NULL
Empty LineString                          Faraway point                             NULL                NULL
Empty LineString                          Line going through left and right square  NULL                NULL
Empty LineString                          NULL                                      NULL                NULL
Empty LineString                          Nested Geometry Collection                NULL                NULL
Empty LineString                          Point middle of Left Square               NULL                NULL
Empty LineString                          Point middle of Right Square              NULL                NULL
Empty LineString                          Square (left)                             NULL                NULL
Empty LineString                          Square (right)                            NULL                NULL
Empty LineString                          Square overlapping left and right square  NULL                NULL
Empty Point                               Empty GeometryCollection                  NULL                NULL
Empty Point                               Empty LineString                          NULL                NULL
Empty Point                               Empty Point                               NULL                NULL
Empty Point                               Faraway point                             NULL                NULL
Empty Point                               Line going through left and right square  NULL                NULL
Empty Point                               NULL                                      NULL                NULL
Empty Point                               Nested Geometry Collection                NULL                NULL
Empty Point                               Point middle of Left Square               NULL                NULL
Empty Point                               Point middle of Right Square              NULL                NULL
Empty Point                               Square (left)                             NULL                NULL
Empty Point                               Square (right)                            NULL                NULL
Empty Point                               Square overlapping left and right square  NULL                NULL
Faraway point                             Empty GeometryCollection                  NULL                NULL
Faraway point                             Empty LineString                          NULL                NULL
Faraway point                             Empty Point                               NULL                NULL
Faraway point                             Faraway point                             0                   0
Faraway point                             Line going through left and right square  6.363961030678928   7.106335201775948
Faraway point                             NULL                                      NULL                NULL
Faraway point                             Nested Geometry Collection                7.0710678118654755  7.0710678118654755
Faraway point                             Point middle of Left Square               7.106335201775948   7.106335201775948
Faraway point                             Point middle of Right Square              6.363961030678928   6.363961030678928
Faraway point                             Square (left)                             6.4031242374328485  7.810249675906654
Faraway point                             Square (right)                            5.656854249492381   7.0710678118654755
Faraway point                             Square overlapping left and right square  5.656854249492381   7.142128534267638
Line going through left and right square  Empty GeometryCollection                  NULL                NULL
Line going through left and right square  Empty LineString                          NULL                NULL
Line going through left and right square  Empty Point                               NULL                NULL
Line going through left and right square  Faraway point                             6.363961030678928   7.106335201775948
Line going through left and right square  Line going through left and right square  0                   1
Line going through left and right square  NULL                                      NULL                NULL
Line going through left and right square  Nested Geometry Collection                0.5                 0.7071067811865476
Line going through left and right square  Point middle of Left Square               0                   1
Line going through left and right square  Point middle of Right Square              0                   1
Line going through left and right square  Square (left)                             0                   1.5811388300841898
Line going through left and right square  Square (right)                            0                   1.5811388300841898
Line going through left and right square  Square overlapping left and right square  0                   1.5811388300841898
NULL                                      Empty GeometryCollection                  NULL                NULL
NULL                                      Empty LineString                          NULL                NULL
NULL                                      Empty Point                               NULL                NULL
NULL                                      Faraway point                             NULL                NULL
NULL                                      Line going through left and right square  NULL                NULL
NULL                                      NULL                                      NULL                NULL
NULL                                      Nested Geometry Collection                NULL                NULL
NULL                                      Point middle of Left Square               NULL                NULL
NULL                                      Point middle of Right Square              NULL                NULL
NULL                                      Square (left)                             NULL                NULL
NULL                                      Square (right)                            NULL                NULL
NULL                                      Square overlapping left and right square  NULL                NULL
Nested Geometry Collection                Empty GeometryCollection                  NULL                NULL
Nested Geometry Collection                Empty LineString                          NULL                NULL
Nested Geometry Collection                Empty Point                               NULL                NULL
Nested Geometry Collection                Faraway point                             7.0710678118654755  7.0710678118654755
Nested Geometry Collection                Line going through left and right square  0.5                 0.7071067811865476
Nested Geometry Collection                NULL                                      NULL                NULL
Nested Geometry Collection                Nested Geometry Collection                0                   0
Nested Geometry Collection                Point middle of Left Square               0.7071067811865476  0.7071067811865476
Nested Geometry Collection                Point middle of Right Square              0.7071067811865476  0.7071067811865476
Nested Geometry Collection                Square (left)                             0                   1.4142135623730951
Nested Geometry Collection                Square (right)                            0                   1.4142135623730951
Nested Geometry Collection                Square overlapping left and right square  0                   1.4142135623730951
Point middle of Left Square               Empty GeometryCollection                  NULL                NULL
Point middle of Left Square               Empty LineString                          NULL                NULL
Point middle of Left Square               Empty Point                               NULL                NULL
Point middle of Left Square               Faraway point                             7.106335201775948   7.106335201775948
Point middle of Left Square               Line going through left and right square  0                   1
Point middle of Left Square               NULL                                      NULL                NULL
Point middle of Left Square               Nested Geometry Collection                0.7071067811865476  0.7071067811865476
Point middle of Left Square               Point middle of Left Square               0                   0
Point middle of Left Square               Point middle of Right Square              1                   1
Point middle of Left Square               Square (left)                             0                   0.7071067811865476
Point middle of Left Square               Square (right)                            0.5                 1.5811388300841898
Point middle of Left Square               Square overlapping left and right square  0.4                 1.5811388300841898
Point middle of Right Square              Empty GeometryCollection                  NULL                NULL
Point middle of Right Square              Empty LineString                          NULL                NULL
Point middle of Right Square              Empty Point                               NULL                NULL
Point middle of Right Square              Faraway point                             6.363961030678928   6.363961030678928
Point middle of Right Square              Line going through left and right square  0                   1
Point middle of Right Square              NULL                                      NULL                NULL
Point middle of Right Square              Nested Geometry Collection                0.7071067811865476  0.7071067811865476
Point middle of Right Square              Point middle of Left Square               1                   1
Point middle of Right Square              Point middle of Right Square              0                   0
Point middle of Right Square              Square (left)                             0.5                 1.5811388300841898
Point middle of Right Square              Square (right)                            0                   0.7071067811865476
Point middle of Right Square              Square overlapping left and right square  0                   0.7810249675906654
Square (left)                             Empty GeometryCollection                  NULL                NULL
Square (left)                             Empty LineString                          NULL                NULL
Square (left)                             Empty Point                               NULL                NULL
Square (left)                             Faraway point                             6.4031242374328485  7.810249675906654
Square (left)                             Line going through left and right square  0                   1.5811388300841898
Square (left)                             NULL                                      NULL                NULL
Square (left)                             Nested Geometry Collection                0                   1.4142135623730951
Square (left)                             Point middle of Left Square               0                   0.7071067811865476
Square (left)                             Point middle of Right Square              0.5                 1.5811388300841898
Square (left)                             Square (left)                             0                   1.4142135623730951
Square (left)                             Square (right)                            0                   2.23606797749979
Square (left)                             Square overlapping left and right square  0                   2.23606797749979
Square (right)                            Empty GeometryCollection                  NULL                NULL
Square (right)                            Empty LineString                          NULL                NULL
Square (right)                            Empty Point                               NULL                NULL
Square (right)                            Faraway point                             5.656854249492381   7.0710678118654755
Square (right)                            Line going through left and right square  0                   1.5811388300841898
Square (right)                            NULL                                      NULL                NULL
Square (right)                            Nested Geometry Collection                0                   1.4142135623730951
Square (right)                            Point middle of Left Square               0.5                 1.5811388300841898
Square (right)                            Point middle of Right Square              0                   0.7071067811865476
Square (right)                            Square (left)                             0                   2.23606797749979
Square (right)                            Square (right)                            0                   1.4142135623730951
Square (right)                            Square overlapping left and right square  0                   1.4866068747318506
Square overlapping left and right square  Empty GeometryCollection                  NULL                NULL
Square overlapping left and right square  Empty LineString                          NULL                NULL
Square overlapping left and right square  Empty Point                               NULL                NULL
Square overlapping left and right square  Faraway point                             5.656854249492381   7.142128534267638
Square overlapping left and right square  Line going through left and right square  0                   1.5811388300841898
Square overlapping left and right square  NULL                                      NULL                NULL
Square overlapping left and right square  Nested Geometry Collection                0                   1.4142135623730951
Square overlapping left and right square  Point middle of Left Square               0.4                 1.5811388300841898
Square overlapping left and right square  Point middle of Right Square              0                   0.7810249675906654
Square overlapping left and right square  Square (left)                             0                   2.23606797749979
Square overlapping left and right square  Square (right)                            0                   1.4866068747318506
Square overlapping left and right square  Square overlapping left and right square  0                   1.4866068747318506

# ST_DistanceSphere, ST_DistanceSpheroid
query TTRR round-in-strings
SELECT
  a.dsc,
  b.dsc,
  ST_DistanceSphere(a.geom, b.geom),
  ST_DistanceSpheroid(a.geom, b.geom)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  NULL     NULL
Empty GeometryCollection                  Empty LineString                          NULL     NULL
Empty GeometryCollection                  Empty Point                               NULL     NULL
Empty GeometryCollection                  Faraway point                             NULL     NULL
Empty GeometryCollection                  Line going through left and right square  NULL     NULL
Empty GeometryCollection                  NULL                                      NULL     NULL
Empty GeometryCollection                  Nested Geometry Collection                NULL     NULL
Empty GeometryCollection                  Point middle of Left Square               NULL     NULL
Empty GeometryCollection                  Point middle of Right Square              NULL     NULL
Empty GeometryCollection                  Square (left)                             NULL     NULL
Empty GeometryCollection                  Square (right)                            NULL     NULL
Empty GeometryCollection                  Square overlapping left and right square  NULL     NULL
Empty LineString                          Empty GeometryCollection                  NULL     NULL
Empty LineString                          Empty LineString                          NULL     NULL
Empty LineString                          Empty Point                               NULL     NULL
Empty LineString                          Faraway point                             NULL     NULL
Empty LineString                          Line going through left and right square  NULL     NULL
Empty LineString                          NULL                                      NULL     NULL
Empty LineString                          Nested Geometry Collection                NULL     NULL
Empty LineString                          Point middle of Left Square               NULL     NULL
Empty LineString                          Point middle of Right Square              NULL     NULL
Empty LineString                          Square (left)                             NULL     NULL
Empty LineString                          Square (right)                            NULL     NULL
Empty LineString                          Square overlapping left and right square  NULL     NULL
Empty Point                               Empty GeometryCollection                  NULL     NULL
Empty Point                               Empty LineString                          NULL     NULL
Empty Point                               Empty Point                               NULL     NULL
Empty Point                               Faraway point                             NULL     NULL
Empty Point                               Line going through left and right square  NULL     NULL
Empty Point                               NULL                                      NULL     NULL
Empty Point                               Nested Geometry Collection                NULL     NULL
Empty Point                               Point middle of Left Square               NULL     NULL
Empty Point                               Point middle of Right Square              NULL     NULL
Empty Point                               Square (left)                             NULL     NULL
Empty Point                               Square (right)                            NULL     NULL
Empty Point                               Square overlapping left and right square  NULL     NULL
Faraway point                             Empty GeometryCollection                  NULL     NULL
Faraway point                             Empty LineString                          NULL     NULL
Faraway point                             Empty Point                               NULL     NULL
Faraway point                             Faraway point                             0        0
Faraway point                             Line going through left and right square  707142   705578
Faraway point                             NULL                                      NULL     NULL
Faraway point                             Nested Geometry Collection                785768   784029
Faraway point                             Point middle of Left Square               789522   788297
Faraway point                             Point middle of Right Square              707142   705578
Faraway point                             Square (left)                             711312   710261
Faraway point                             Square (right)                            628519   627130
Faraway point                             Square overlapping left and right square  628519   627130
Line going through left and right square  Empty GeometryCollection                  NULL     NULL
Line going through left and right square  Empty LineString                          NULL     NULL
Line going through left and right square  Empty Point                               NULL     NULL
Line going through left and right square  Faraway point                             707142   705578
Line going through left and right square  Line going through left and right square  0        0
Line going through left and right square  NULL                                      NULL     NULL
Line going through left and right square  Nested Geometry Collection                55599.7  55289.3
Line going through left and right square  Point middle of Left Square               0        0
Line going through left and right square  Point middle of Right Square              0        0
Line going through left and right square  Square (left)                             0        0
Line going through left and right square  Square (right)                            0        0
Line going through left and right square  Square overlapping left and right square  0        0
NULL                                      Empty GeometryCollection                  NULL     NULL
NULL                                      Empty LineString                          NULL     NULL
NULL                                      Empty Point                               NULL     NULL
NULL                                      Faraway point                             NULL     NULL
NULL                                      Line going through left and right square  NULL     NULL
NULL                                      NULL                                      NULL     NULL
NULL                                      Nested Geometry Collection                NULL     NULL
NULL                                      Point middle of Left Square               NULL     NULL
NULL                                      Point middle of Right Square              NULL     NULL
NULL                                      Square (left)                             NULL     NULL
NULL                                      Square (right)                            NULL     NULL
NULL                                      Square overlapping left and right square  NULL     NULL
Nested Geometry Collection                Empty GeometryCollection                  NULL     NULL
Nested Geometry Collection                Empty LineString                          NULL     NULL
Nested Geometry Collection                Empty Point                               NULL     NULL
Nested Geometry Collection                Faraway point                             785768   784029
Nested Geometry Collection                Line going through left and right square  55599.7  55289.3
Nested Geometry Collection                NULL                                      NULL     NULL
Nested Geometry Collection                Nested Geometry Collection                0        0
Nested Geometry Collection                Point middle of Left Square               78626.3  78451.2
Nested Geometry Collection                Point middle of Right Square              78626.3  78451.2
Nested Geometry Collection                Square (left)                             0        0
Nested Geometry Collection                Square (right)                            0        0
Nested Geometry Collection                Square overlapping left and right square  0        0
Point middle of Left Square               Empty GeometryCollection                  NULL     NULL
Point middle of Left Square               Empty LineString                          NULL     NULL
Point middle of Left Square               Empty Point                               NULL     NULL
Point middle of Left Square               Faraway point                             789522   788297
Point middle of Left Square               Line going through left and right square  0        0
Point middle of Left Square               NULL                                      NULL     NULL
Point middle of Left Square               Nested Geometry Collection                78626.3  78451.2
Point middle of Left Square               Point middle of Left Square               0        0
Point middle of Left Square               Point middle of Right Square              111191   111315
Point middle of Left Square               Square (left)                             0        0
Point middle of Left Square               Square (right)                            55595.4  55657.6
Point middle of Left Square               Square overlapping left and right square  44476.3  44526.1
Point middle of Right Square              Empty GeometryCollection                  NULL     NULL
Point middle of Right Square              Empty LineString                          NULL     NULL
Point middle of Right Square              Empty Point                               NULL     NULL
Point middle of Right Square              Faraway point                             707142   705578
Point middle of Right Square              Line going through left and right square  0        0
Point middle of Right Square              NULL                                      NULL     NULL
Point middle of Right Square              Nested Geometry Collection                78626.3  78451.2
Point middle of Right Square              Point middle of Left Square               111191   111315
Point middle of Right Square              Point middle of Right Square              0        0
Point middle of Right Square              Square (left)                             55595.4  55657.6
Point middle of Right Square              Square (right)                            0        0
Point middle of Right Square              Square overlapping left and right square  0        0
Square (left)                             Empty GeometryCollection                  NULL     NULL
Square (left)                             Empty LineString                          NULL     NULL
Square (left)                             Empty Point                               NULL     NULL
Square (left)                             Faraway point                             711312   710261
Square (left)                             Line going through left and right square  0        0
Square (left)                             NULL                                      NULL     NULL
Square (left)                             Nested Geometry Collection                0        0
Square (left)                             Point middle of Left Square               0        0
Square (left)                             Point middle of Right Square              55595.4  55657.6
Square (left)                             Square (left)                             0        0
Square (left)                             Square (right)                            0        0
Square (left)                             Square overlapping left and right square  0        0
Square (right)                            Empty GeometryCollection                  NULL     NULL
Square (right)                            Empty LineString                          NULL     NULL
Square (right)                            Empty Point                               NULL     NULL
Square (right)                            Faraway point                             628519   627130
Square (right)                            Line going through left and right square  0        0
Square (right)                            NULL                                      NULL     NULL
Square (right)                            Nested Geometry Collection                0        0
Square (right)                            Point middle of Left Square               55595.4  55657.6
Square (right)                            Point middle of Right Square              0        0
Square (right)                            Square (left)                             0        0
Square (right)                            Square (right)                            0        0
Square (right)                            Square overlapping left and right square  0        0
Square overlapping left and right square  Empty GeometryCollection                  NULL     NULL
Square overlapping left and right square  Empty LineString                          NULL     NULL
Square overlapping left and right square  Empty Point                               NULL     NULL
Square overlapping left and right square  Faraway point                             628519   627130
Square overlapping left and right square  Line going through left and right square  0        0
Square overlapping left and right square  NULL                                      NULL     NULL
Square overlapping left and right square  Nested Geometry Collection                0        0
Square overlapping left and right square  Point middle of Left Square               44476.3  44526.1
Square overlapping left and right square  Point middle of Right Square              0        0
Square overlapping left and right square  Square (left)                             0        0
Square overlapping left and right square  Square (right)                            0        0
Square overlapping left and right square  Square overlapping left and right square  0        0

# Regression test for #90118. Do not panic if a coordinate is NaN.
statement error pgcode 22023 input is out of range
SELECT ST_DistanceSpheroid(ST_SnapToGrid('01050000C00400000001020000C0040000000A2B7937D2DDF341CAEF56D6CA94FEC168909A5A5308D5C1600863B65513F9C10E9D7B3828CFF3415D754B6EE344F4C154EB8B48DC37EEC14E5053131963FA41E4B8F8F90180E941B433052AC359E2C1B0F9BD706AE0CA41E47A00106D23E6C1140CDEFC2066E541DC041E43D7E0E541D71DA60DCF5800C2C03C19D64662A94101020000C00400000078A3F3FA171BECC14906026AC73000C2BF39C72B6DC0FCC13CFE89583CADE64120EBED23DDB5C1C1C072A4065C53DCC1B04A51E92098F441A063BD5F67B2E841CCB94727FC86DCC1B8276303051FD84114B61A426749FC417483A4C01A68E341F252B7B34B6EEDC19289514C865EF14148C84B584F87F24114436730C149E04101020000C003000000F8CB40BB7D74FD41407A6D511432D741B0CD41FE895DD4418672254A1EB8014208EACF19E83CD541746AD58CB9170242C0B19FB99AFED94148AE2EF95896FE4178B997637B6BD6C164ABA2111EA8FD410CFDE813927BD7C190265FCF876A014201020000C0060000001065DCD70770F7C10F612AD0CC33F4C111FFA41FB47802C2265299CFB19A01422F77456D88D7F2C1A2EAE8CB9F09F4C150167B5B5309EA415A5DDD2C45E9F1418C125198484AE64153D5D0ED755DFAC1EA0005C2D148F1C1EC3F313A1519E241E2779FD007B7F341CB5DDDC5D00CF0C1C24CC5C279C0FDC188BB78838C7BF341F0942DF0B3FBF041906304A7FFB4D5C1982570D0B8FCDB412059D469B946BF4160C6D4DBF074E841586F81D38E05E641A14870D6117800C23C248B430E0CF9C1':::GEOMETRY::GEOMETRY, col::FLOAT8)::GEOMETRY::GEOMETRY, '010500000002000000010200000003000000000000000000244000000000000024400000000000003440000000000000344000000000000024400000000000004440010200000004000000000000000000444000000000000044400000000000003E400000000000003E40000000000000444000000000000034400000000000003E400000000000002440':::GEOMETRY::GEOMETRY)::FLOAT8
FROM (VALUES (acosh(-0.3771205263403379)), ('+Inf'::FLOAT8)) v(col)

query TTRRR
SELECT
  a.dsc,
  b.dsc,
  ST_FrechetDistance(a.geom, b.geom),
  round(ST_FrechetDistance(a.geom, b.geom, 0.2), 12),
  ST_FrechetDistance(a.geom, b.geom, -1)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  NULL                NULL            NULL
Empty GeometryCollection                  Empty LineString                          NULL                NULL            NULL
Empty GeometryCollection                  Empty Point                               NULL                NULL            NULL
Empty GeometryCollection                  Faraway point                             NULL                NULL            NULL
Empty GeometryCollection                  Line going through left and right square  NULL                NULL            NULL
Empty GeometryCollection                  NULL                                      NULL                NULL            NULL
Empty GeometryCollection                  Nested Geometry Collection                NULL                NULL            NULL
Empty GeometryCollection                  Point middle of Left Square               NULL                NULL            NULL
Empty GeometryCollection                  Point middle of Right Square              NULL                NULL            NULL
Empty GeometryCollection                  Square (left)                             NULL                NULL            NULL
Empty GeometryCollection                  Square (right)                            NULL                NULL            NULL
Empty GeometryCollection                  Square overlapping left and right square  NULL                NULL            NULL
Empty LineString                          Empty GeometryCollection                  NULL                NULL            NULL
Empty LineString                          Empty LineString                          NULL                NULL            NULL
Empty LineString                          Empty Point                               NULL                NULL            NULL
Empty LineString                          Faraway point                             NULL                NULL            NULL
Empty LineString                          Line going through left and right square  NULL                NULL            NULL
Empty LineString                          NULL                                      NULL                NULL            NULL
Empty LineString                          Nested Geometry Collection                NULL                NULL            NULL
Empty LineString                          Point middle of Left Square               NULL                NULL            NULL
Empty LineString                          Point middle of Right Square              NULL                NULL            NULL
Empty LineString                          Square (left)                             NULL                NULL            NULL
Empty LineString                          Square (right)                            NULL                NULL            NULL
Empty LineString                          Square overlapping left and right square  NULL                NULL            NULL
Empty Point                               Empty GeometryCollection                  NULL                NULL            NULL
Empty Point                               Empty LineString                          NULL                NULL            NULL
Empty Point                               Empty Point                               NULL                NULL            NULL
Empty Point                               Faraway point                             NULL                NULL            NULL
Empty Point                               Line going through left and right square  NULL                NULL            NULL
Empty Point                               NULL                                      NULL                NULL            NULL
Empty Point                               Nested Geometry Collection                NULL                NULL            NULL
Empty Point                               Point middle of Left Square               NULL                NULL            NULL
Empty Point                               Point middle of Right Square              NULL                NULL            NULL
Empty Point                               Square (left)                             NULL                NULL            NULL
Empty Point                               Square (right)                            NULL                NULL            NULL
Empty Point                               Square overlapping left and right square  NULL                NULL            NULL
Faraway point                             Empty GeometryCollection                  NULL                NULL            NULL
Faraway point                             Empty LineString                          NULL                NULL            NULL
Faraway point                             Empty Point                               NULL                NULL            NULL
Faraway point                             Faraway point                             0                   0               0
Faraway point                             Line going through left and right square  7.106335201775948   7.106335201776  7.106335201775948
Faraway point                             NULL                                      NULL                NULL            NULL
Faraway point                             Nested Geometry Collection                7.0710678118654755  7.071067811865  7.0710678118654755
Faraway point                             Point middle of Left Square               7.106335201775948   7.106335201776  7.106335201775948
Faraway point                             Point middle of Right Square              6.363961030678928   6.363961030679  6.363961030678928
Faraway point                             Square (left)                             7.810249675906654   7.810249675907  7.810249675906654
Faraway point                             Square (right)                            7.0710678118654755  7.071067811865  7.0710678118654755
Faraway point                             Square overlapping left and right square  7.142128534267638   7.142128534268  7.142128534267638
Line going through left and right square  Empty GeometryCollection                  NULL                NULL            NULL
Line going through left and right square  Empty LineString                          NULL                NULL            NULL
Line going through left and right square  Empty Point                               NULL                NULL            NULL
Line going through left and right square  Faraway point                             7.106335201775948   7.106335201776  7.106335201775948
Line going through left and right square  Line going through left and right square  0                   0               0
Line going through left and right square  NULL                                      NULL                NULL            NULL
Line going through left and right square  Nested Geometry Collection                0.7071067811865476  0.707106781187  0.7071067811865476
Line going through left and right square  Point middle of Left Square               1                   1               1
Line going through left and right square  Point middle of Right Square              1                   1               1
Line going through left and right square  Square (left)                             1.5811388300841898  1.581138830084  1.5811388300841898
Line going through left and right square  Square (right)                            0.7071067811865476  0.707106781187  0.7071067811865476
Line going through left and right square  Square overlapping left and right square  0.7810249675906654  0.781024967591  0.7810249675906654
NULL                                      Empty GeometryCollection                  NULL                NULL            NULL
NULL                                      Empty LineString                          NULL                NULL            NULL
NULL                                      Empty Point                               NULL                NULL            NULL
NULL                                      Faraway point                             NULL                NULL            NULL
NULL                                      Line going through left and right square  NULL                NULL            NULL
NULL                                      NULL                                      NULL                NULL            NULL
NULL                                      Nested Geometry Collection                NULL                NULL            NULL
NULL                                      Point middle of Left Square               NULL                NULL            NULL
NULL                                      Point middle of Right Square              NULL                NULL            NULL
NULL                                      Square (left)                             NULL                NULL            NULL
NULL                                      Square (right)                            NULL                NULL            NULL
NULL                                      Square overlapping left and right square  NULL                NULL            NULL
Nested Geometry Collection                Empty GeometryCollection                  NULL                NULL            NULL
Nested Geometry Collection                Empty LineString                          NULL                NULL            NULL
Nested Geometry Collection                Empty Point                               NULL                NULL            NULL
Nested Geometry Collection                Faraway point                             7.0710678118654755  7.071067811865  7.0710678118654755
Nested Geometry Collection                Line going through left and right square  0.7071067811865476  0.707106781187  0.7071067811865476
Nested Geometry Collection                NULL                                      NULL                NULL            NULL
Nested Geometry Collection                Nested Geometry Collection                0                   0               0
Nested Geometry Collection                Point middle of Left Square               0.7071067811865476  0.707106781187  0.7071067811865476
Nested Geometry Collection                Point middle of Right Square              0.7071067811865476  0.707106781187  0.7071067811865476
Nested Geometry Collection                Square (left)                             1.4142135623730951  1.414213562373  1.4142135623730951
Nested Geometry Collection                Square (right)                            1.4142135623730951  1.414213562373  1.4142135623730951
Nested Geometry Collection                Square overlapping left and right square  1.4142135623730951  1.414213562373  1.4142135623730951
Point middle of Left Square               Empty GeometryCollection                  NULL                NULL            NULL
Point middle of Left Square               Empty LineString                          NULL                NULL            NULL
Point middle of Left Square               Empty Point                               NULL                NULL            NULL
Point middle of Left Square               Faraway point                             7.106335201775948   7.106335201776  7.106335201775948
Point middle of Left Square               Line going through left and right square  1                   1               1
Point middle of Left Square               NULL                                      NULL                NULL            NULL
Point middle of Left Square               Nested Geometry Collection                0.7071067811865476  0.707106781187  0.7071067811865476
Point middle of Left Square               Point middle of Left Square               0                   0               0
Point middle of Left Square               Point middle of Right Square              1                   1               1
Point middle of Left Square               Square (left)                             0.7071067811865476  0.707106781187  0.7071067811865476
Point middle of Left Square               Square (right)                            1.5811388300841898  1.581138830084  1.5811388300841898
Point middle of Left Square               Square overlapping left and right square  1.5811388300841898  1.581138830084  1.5811388300841898
Point middle of Right Square              Empty GeometryCollection                  NULL                NULL            NULL
Point middle of Right Square              Empty LineString                          NULL                NULL            NULL
Point middle of Right Square              Empty Point                               NULL                NULL            NULL
Point middle of Right Square              Faraway point                             6.363961030678928   6.363961030679  6.363961030678928
Point middle of Right Square              Line going through left and right square  1                   1               1
Point middle of Right Square              NULL                                      NULL                NULL            NULL
Point middle of Right Square              Nested Geometry Collection                0.7071067811865476  0.707106781187  0.7071067811865476
Point middle of Right Square              Point middle of Left Square               1                   1               1
Point middle of Right Square              Point middle of Right Square              0                   0               0
Point middle of Right Square              Square (left)                             1.5811388300841898  1.581138830084  1.5811388300841898
Point middle of Right Square              Square (right)                            0.7071067811865476  0.707106781187  0.7071067811865476
Point middle of Right Square              Square overlapping left and right square  0.7810249675906654  0.781024967591  0.7810249675906654
Square (left)                             Empty GeometryCollection                  NULL                NULL            NULL
Square (left)                             Empty LineString                          NULL                NULL            NULL
Square (left)                             Empty Point                               NULL                NULL            NULL
Square (left)                             Faraway point                             7.810249675906654   7.810249675907  7.810249675906654
Square (left)                             Line going through left and right square  1.5811388300841898  1.581138830084  1.5811388300841898
Square (left)                             NULL                                      NULL                NULL            NULL
Square (left)                             Nested Geometry Collection                1.4142135623730951  1.414213562373  1.4142135623730951
Square (left)                             Point middle of Left Square               0.7071067811865476  0.707106781187  0.7071067811865476
Square (left)                             Point middle of Right Square              1.5811388300841898  1.581138830084  1.5811388300841898
Square (left)                             Square (left)                             0                   0               0
Square (left)                             Square (right)                            1                   1               1
Square (left)                             Square overlapping left and right square  1                   1               1
Square (right)                            Empty GeometryCollection                  NULL                NULL            NULL
Square (right)                            Empty LineString                          NULL                NULL            NULL
Square (right)                            Empty Point                               NULL                NULL            NULL
Square (right)                            Faraway point                             7.0710678118654755  7.071067811865  7.0710678118654755
Square (right)                            Line going through left and right square  0.7071067811865476  0.707106781187  0.7071067811865476
Square (right)                            NULL                                      NULL                NULL            NULL
Square (right)                            Nested Geometry Collection                1.4142135623730951  1.414213562373  1.4142135623730951
Square (right)                            Point middle of Left Square               1.5811388300841898  1.581138830084  1.5811388300841898
Square (right)                            Point middle of Right Square              0.7071067811865476  0.707106781187  0.7071067811865476
Square (right)                            Square (left)                             1                   1               1
Square (right)                            Square (right)                            0                   0               0
Square (right)                            Square overlapping left and right square  0.1                 0.1             0.1
Square overlapping left and right square  Empty GeometryCollection                  NULL                NULL            NULL
Square overlapping left and right square  Empty LineString                          NULL                NULL            NULL
Square overlapping left and right square  Empty Point                               NULL                NULL            NULL
Square overlapping left and right square  Faraway point                             7.142128534267638   7.142128534268  7.142128534267638
Square overlapping left and right square  Line going through left and right square  0.7810249675906654  0.781024967591  0.7810249675906654
Square overlapping left and right square  NULL                                      NULL                NULL            NULL
Square overlapping left and right square  Nested Geometry Collection                1.4142135623730951  1.414213562373  1.4142135623730951
Square overlapping left and right square  Point middle of Left Square               1.5811388300841898  1.581138830084  1.5811388300841898
Square overlapping left and right square  Point middle of Right Square              0.7810249675906654  0.781024967591  0.7810249675906654
Square overlapping left and right square  Square (left)                             1                   1               1
Square overlapping left and right square  Square (right)                            0.1                 0.1             0.1
Square overlapping left and right square  Square overlapping left and right square  0                   0               0

query TTRR
SELECT
  a.dsc,
  b.dsc,
  ST_HausdorffDistance(a.geom, b.geom),
  round(ST_HausdorffDistance(a.geom, b.geom, 0.4), 5)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  NULL                NULL
Empty GeometryCollection                  Empty LineString                          NULL                NULL
Empty GeometryCollection                  Empty Point                               NULL                NULL
Empty GeometryCollection                  Faraway point                             NULL                NULL
Empty GeometryCollection                  Line going through left and right square  NULL                NULL
Empty GeometryCollection                  NULL                                      NULL                NULL
Empty GeometryCollection                  Nested Geometry Collection                NULL                NULL
Empty GeometryCollection                  Point middle of Left Square               NULL                NULL
Empty GeometryCollection                  Point middle of Right Square              NULL                NULL
Empty GeometryCollection                  Square (left)                             NULL                NULL
Empty GeometryCollection                  Square (right)                            NULL                NULL
Empty GeometryCollection                  Square overlapping left and right square  NULL                NULL
Empty LineString                          Empty GeometryCollection                  NULL                NULL
Empty LineString                          Empty LineString                          NULL                NULL
Empty LineString                          Empty Point                               NULL                NULL
Empty LineString                          Faraway point                             NULL                NULL
Empty LineString                          Line going through left and right square  NULL                NULL
Empty LineString                          NULL                                      NULL                NULL
Empty LineString                          Nested Geometry Collection                NULL                NULL
Empty LineString                          Point middle of Left Square               NULL                NULL
Empty LineString                          Point middle of Right Square              NULL                NULL
Empty LineString                          Square (left)                             NULL                NULL
Empty LineString                          Square (right)                            NULL                NULL
Empty LineString                          Square overlapping left and right square  NULL                NULL
Empty Point                               Empty GeometryCollection                  NULL                NULL
Empty Point                               Empty LineString                          NULL                NULL
Empty Point                               Empty Point                               NULL                NULL
Empty Point                               Faraway point                             NULL                NULL
Empty Point                               Line going through left and right square  NULL                NULL
Empty Point                               NULL                                      NULL                NULL
Empty Point                               Nested Geometry Collection                NULL                NULL
Empty Point                               Point middle of Left Square               NULL                NULL
Empty Point                               Point middle of Right Square              NULL                NULL
Empty Point                               Square (left)                             NULL                NULL
Empty Point                               Square (right)                            NULL                NULL
Empty Point                               Square overlapping left and right square  NULL                NULL
Faraway point                             Empty GeometryCollection                  NULL                NULL
Faraway point                             Empty LineString                          NULL                NULL
Faraway point                             Empty Point                               NULL                NULL
Faraway point                             Faraway point                             0                   0
Faraway point                             Line going through left and right square  7.106335201775948   7.10634
Faraway point                             NULL                                      NULL                NULL
Faraway point                             Nested Geometry Collection                7.0710678118654755  7.07107
Faraway point                             Point middle of Left Square               7.106335201775948   7.10634
Faraway point                             Point middle of Right Square              6.363961030678928   6.36396
Faraway point                             Square (left)                             7.810249675906654   7.81025
Faraway point                             Square (right)                            7.0710678118654755  7.07107
Faraway point                             Square overlapping left and right square  7.142128534267638   7.14213
Line going through left and right square  Empty GeometryCollection                  NULL                NULL
Line going through left and right square  Empty LineString                          NULL                NULL
Line going through left and right square  Empty Point                               NULL                NULL
Line going through left and right square  Faraway point                             7.106335201775948   7.10634
Line going through left and right square  Line going through left and right square  0                   0
Line going through left and right square  NULL                                      NULL                NULL
Line going through left and right square  Nested Geometry Collection                0.7071067811865476  0.70711
Line going through left and right square  Point middle of Left Square               1                   1
Line going through left and right square  Point middle of Right Square              1                   1
Line going through left and right square  Square (left)                             0.7071067811865476  0.70711
Line going through left and right square  Square (right)                            0.7071067811865476  0.70711
Line going through left and right square  Square overlapping left and right square  0.7071067811865476  0.70711
NULL                                      Empty GeometryCollection                  NULL                NULL
NULL                                      Empty LineString                          NULL                NULL
NULL                                      Empty Point                               NULL                NULL
NULL                                      Faraway point                             NULL                NULL
NULL                                      Line going through left and right square  NULL                NULL
NULL                                      NULL                                      NULL                NULL
NULL                                      Nested Geometry Collection                NULL                NULL
NULL                                      Point middle of Left Square               NULL                NULL
NULL                                      Point middle of Right Square              NULL                NULL
NULL                                      Square (left)                             NULL                NULL
NULL                                      Square (right)                            NULL                NULL
NULL                                      Square overlapping left and right square  NULL                NULL
Nested Geometry Collection                Empty GeometryCollection                  NULL                NULL
Nested Geometry Collection                Empty LineString                          NULL                NULL
Nested Geometry Collection                Empty Point                               NULL                NULL
Nested Geometry Collection                Faraway point                             7.0710678118654755  7.07107
Nested Geometry Collection                Line going through left and right square  0.7071067811865476  0.70711
Nested Geometry Collection                NULL                                      NULL                NULL
Nested Geometry Collection                Nested Geometry Collection                0                   0
Nested Geometry Collection                Point middle of Left Square               0.7071067811865476  0.70711
Nested Geometry Collection                Point middle of Right Square              0.7071067811865476  0.70711
Nested Geometry Collection                Square (left)                             1.4142135623730951  1.41421
Nested Geometry Collection                Square (right)                            1.4142135623730951  1.41421
Nested Geometry Collection                Square overlapping left and right square  1.4142135623730951  1.41421
Point middle of Left Square               Empty GeometryCollection                  NULL                NULL
Point middle of Left Square               Empty LineString                          NULL                NULL
Point middle of Left Square               Empty Point                               NULL                NULL
Point middle of Left Square               Faraway point                             7.106335201775948   7.10634
Point middle of Left Square               Line going through left and right square  1                   1
Point middle of Left Square               NULL                                      NULL                NULL
Point middle of Left Square               Nested Geometry Collection                0.7071067811865476  0.70711
Point middle of Left Square               Point middle of Left Square               0                   0
Point middle of Left Square               Point middle of Right Square              1                   1
Point middle of Left Square               Square (left)                             0.7071067811865476  0.70711
Point middle of Left Square               Square (right)                            1.5811388300841898  1.58114
Point middle of Left Square               Square overlapping left and right square  1.5811388300841898  1.58114
Point middle of Right Square              Empty GeometryCollection                  NULL                NULL
Point middle of Right Square              Empty LineString                          NULL                NULL
Point middle of Right Square              Empty Point                               NULL                NULL
Point middle of Right Square              Faraway point                             6.363961030678928   6.36396
Point middle of Right Square              Line going through left and right square  1                   1
Point middle of Right Square              NULL                                      NULL                NULL
Point middle of Right Square              Nested Geometry Collection                0.7071067811865476  0.70711
Point middle of Right Square              Point middle of Left Square               1                   1
Point middle of Right Square              Point middle of Right Square              0                   0
Point middle of Right Square              Square (left)                             1.5811388300841898  1.58114
Point middle of Right Square              Square (right)                            0.7071067811865476  0.70711
Point middle of Right Square              Square overlapping left and right square  0.7810249675906654  0.78102
Square (left)                             Empty GeometryCollection                  NULL                NULL
Square (left)                             Empty LineString                          NULL                NULL
Square (left)                             Empty Point                               NULL                NULL
Square (left)                             Faraway point                             7.810249675906654   7.81025
Square (left)                             Line going through left and right square  0.7071067811865476  0.70711
Square (left)                             NULL                                      NULL                NULL
Square (left)                             Nested Geometry Collection                1.4142135623730951  1.41421
Square (left)                             Point middle of Left Square               0.7071067811865476  0.70711
Square (left)                             Point middle of Right Square              1.5811388300841898  1.58114
Square (left)                             Square (left)                             0                   0
Square (left)                             Square (right)                            1                   1
Square (left)                             Square overlapping left and right square  1                   1
Square (right)                            Empty GeometryCollection                  NULL                NULL
Square (right)                            Empty LineString                          NULL                NULL
Square (right)                            Empty Point                               NULL                NULL
Square (right)                            Faraway point                             7.0710678118654755  7.07107
Square (right)                            Line going through left and right square  0.7071067811865476  0.70711
Square (right)                            NULL                                      NULL                NULL
Square (right)                            Nested Geometry Collection                1.4142135623730951  1.41421
Square (right)                            Point middle of Left Square               1.5811388300841898  1.58114
Square (right)                            Point middle of Right Square              0.7071067811865476  0.70711
Square (right)                            Square (left)                             1                   1
Square (right)                            Square (right)                            0                   0
Square (right)                            Square overlapping left and right square  0.1                 0.1
Square overlapping left and right square  Empty GeometryCollection                  NULL                NULL
Square overlapping left and right square  Empty LineString                          NULL                NULL
Square overlapping left and right square  Empty Point                               NULL                NULL
Square overlapping left and right square  Faraway point                             7.142128534267638   7.14213
Square overlapping left and right square  Line going through left and right square  0.7071067811865476  0.70711
Square overlapping left and right square  NULL                                      NULL                NULL
Square overlapping left and right square  Nested Geometry Collection                1.4142135623730951  1.41421
Square overlapping left and right square  Point middle of Left Square               1.5811388300841898  1.58114
Square overlapping left and right square  Point middle of Right Square              0.7810249675906654  0.78102
Square overlapping left and right square  Square (left)                             1                   1
Square overlapping left and right square  Square (right)                            0.1                 0.1
Square overlapping left and right square  Square overlapping left and right square  0                   0

# ST_LongestLine, ST_ShortestLine
query TTTTT
SELECT
  a.dsc,
  b.dsc,
  ST_AsText(ST_LongestLine(a.geom, b.geom)),
  ST_AsText(ST_ShortestLine(a.geom, b.geom)),
  ST_AsText(ST_ClosestPoint(a.geom, b.geom))
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  NULL                             NULL                             NULL
Empty GeometryCollection                  Empty LineString                          NULL                             NULL                             NULL
Empty GeometryCollection                  Empty Point                               NULL                             NULL                             NULL
Empty GeometryCollection                  Faraway point                             NULL                             NULL                             NULL
Empty GeometryCollection                  Line going through left and right square  NULL                             NULL                             NULL
Empty GeometryCollection                  NULL                                      NULL                             NULL                             NULL
Empty GeometryCollection                  Nested Geometry Collection                NULL                             NULL                             NULL
Empty GeometryCollection                  Point middle of Left Square               NULL                             NULL                             NULL
Empty GeometryCollection                  Point middle of Right Square              NULL                             NULL                             NULL
Empty GeometryCollection                  Square (left)                             NULL                             NULL                             NULL
Empty GeometryCollection                  Square (right)                            NULL                             NULL                             NULL
Empty GeometryCollection                  Square overlapping left and right square  NULL                             NULL                             NULL
Empty LineString                          Empty GeometryCollection                  NULL                             NULL                             NULL
Empty LineString                          Empty LineString                          NULL                             NULL                             NULL
Empty LineString                          Empty Point                               NULL                             NULL                             NULL
Empty LineString                          Faraway point                             NULL                             NULL                             NULL
Empty LineString                          Line going through left and right square  NULL                             NULL                             NULL
Empty LineString                          NULL                                      NULL                             NULL                             NULL
Empty LineString                          Nested Geometry Collection                NULL                             NULL                             NULL
Empty LineString                          Point middle of Left Square               NULL                             NULL                             NULL
Empty LineString                          Point middle of Right Square              NULL                             NULL                             NULL
Empty LineString                          Square (left)                             NULL                             NULL                             NULL
Empty LineString                          Square (right)                            NULL                             NULL                             NULL
Empty LineString                          Square overlapping left and right square  NULL                             NULL                             NULL
Empty Point                               Empty GeometryCollection                  NULL                             NULL                             NULL
Empty Point                               Empty LineString                          NULL                             NULL                             NULL
Empty Point                               Empty Point                               NULL                             NULL                             NULL
Empty Point                               Faraway point                             NULL                             NULL                             NULL
Empty Point                               Line going through left and right square  NULL                             NULL                             NULL
Empty Point                               NULL                                      NULL                             NULL                             NULL
Empty Point                               Nested Geometry Collection                NULL                             NULL                             NULL
Empty Point                               Point middle of Left Square               NULL                             NULL                             NULL
Empty Point                               Point middle of Right Square              NULL                             NULL                             NULL
Empty Point                               Square (left)                             NULL                             NULL                             NULL
Empty Point                               Square (right)                            NULL                             NULL                             NULL
Empty Point                               Square overlapping left and right square  NULL                             NULL                             NULL
Faraway point                             Empty GeometryCollection                  NULL                             NULL                             NULL
Faraway point                             Empty LineString                          NULL                             NULL                             NULL
Faraway point                             Empty Point                               NULL                             NULL                             NULL
Faraway point                             Faraway point                             LINESTRING (5 5, 5 5)            LINESTRING (5 5, 5 5)            POINT (5 5)
Faraway point                             Line going through left and right square  LINESTRING (5 5, -0.5 0.5)       LINESTRING (5 5, 0.5 0.5)        POINT (5 5)
Faraway point                             NULL                                      NULL                             NULL                             NULL
Faraway point                             Nested Geometry Collection                LINESTRING (5 5, 0 0)            LINESTRING (5 5, 0 0)            POINT (5 5)
Faraway point                             Point middle of Left Square               LINESTRING (5 5, -0.5 0.5)       LINESTRING (5 5, -0.5 0.5)       POINT (5 5)
Faraway point                             Point middle of Right Square              LINESTRING (5 5, 0.5 0.5)        LINESTRING (5 5, 0.5 0.5)        POINT (5 5)
Faraway point                             Square (left)                             LINESTRING (5 5, -1 0)           LINESTRING (5 5, 0 1)            POINT (5 5)
Faraway point                             Square (right)                            LINESTRING (5 5, 0 0)            LINESTRING (5 5, 1 1)            POINT (5 5)
Faraway point                             Square overlapping left and right square  LINESTRING (5 5, -0.1 0)         LINESTRING (5 5, 1 1)            POINT (5 5)
Line going through left and right square  Empty GeometryCollection                  NULL                             NULL                             NULL
Line going through left and right square  Empty LineString                          NULL                             NULL                             NULL
Line going through left and right square  Empty Point                               NULL                             NULL                             NULL
Line going through left and right square  Faraway point                             LINESTRING (-0.5 0.5, 5 5)       LINESTRING (0.5 0.5, 5 5)        POINT (0.5 0.5)
Line going through left and right square  Line going through left and right square  LINESTRING (-0.5 0.5, 0.5 0.5)   LINESTRING (-0.5 0.5, -0.5 0.5)  POINT (-0.5 0.5)
Line going through left and right square  NULL                                      NULL                             NULL                             NULL
Line going through left and right square  Nested Geometry Collection                LINESTRING (-0.5 0.5, 0 0)       LINESTRING (0 0.5, 0 0)          POINT (0 0.5)
Line going through left and right square  Point middle of Left Square               LINESTRING (0.5 0.5, -0.5 0.5)   LINESTRING (-0.5 0.5, -0.5 0.5)  POINT (-0.5 0.5)
Line going through left and right square  Point middle of Right Square              LINESTRING (-0.5 0.5, 0.5 0.5)   LINESTRING (0.5 0.5, 0.5 0.5)    POINT (0.5 0.5)
Line going through left and right square  Square (left)                             LINESTRING (0.5 0.5, -1 0)       LINESTRING (-0.5 0.5, -0.5 0.5)  POINT (-0.5 0.5)
Line going through left and right square  Square (right)                            LINESTRING (-0.5 0.5, 1 0)       LINESTRING (0 0.5, 0 0.5)        POINT (0 0.5)
Line going through left and right square  Square overlapping left and right square  LINESTRING (-0.5 0.5, 1 0)       LINESTRING (-0.1 0.5, -0.1 0.5)  POINT (-0.1 0.5)
NULL                                      Empty GeometryCollection                  NULL                             NULL                             NULL
NULL                                      Empty LineString                          NULL                             NULL                             NULL
NULL                                      Empty Point                               NULL                             NULL                             NULL
NULL                                      Faraway point                             NULL                             NULL                             NULL
NULL                                      Line going through left and right square  NULL                             NULL                             NULL
NULL                                      NULL                                      NULL                             NULL                             NULL
NULL                                      Nested Geometry Collection                NULL                             NULL                             NULL
NULL                                      Point middle of Left Square               NULL                             NULL                             NULL
NULL                                      Point middle of Right Square              NULL                             NULL                             NULL
NULL                                      Square (left)                             NULL                             NULL                             NULL
NULL                                      Square (right)                            NULL                             NULL                             NULL
NULL                                      Square overlapping left and right square  NULL                             NULL                             NULL
Nested Geometry Collection                Empty GeometryCollection                  NULL                             NULL                             NULL
Nested Geometry Collection                Empty LineString                          NULL                             NULL                             NULL
Nested Geometry Collection                Empty Point                               NULL                             NULL                             NULL
Nested Geometry Collection                Faraway point                             LINESTRING (0 0, 5 5)            LINESTRING (0 0, 5 5)            POINT (0 0)
Nested Geometry Collection                Line going through left and right square  LINESTRING (0 0, -0.5 0.5)       LINESTRING (0 0, 0 0.5)          POINT (0 0)
Nested Geometry Collection                NULL                                      NULL                             NULL                             NULL
Nested Geometry Collection                Nested Geometry Collection                LINESTRING (0 0, 0 0)            LINESTRING (0 0, 0 0)            POINT (0 0)
Nested Geometry Collection                Point middle of Left Square               LINESTRING (0 0, -0.5 0.5)       LINESTRING (0 0, -0.5 0.5)       POINT (0 0)
Nested Geometry Collection                Point middle of Right Square              LINESTRING (0 0, 0.5 0.5)        LINESTRING (0 0, 0.5 0.5)        POINT (0 0)
Nested Geometry Collection                Square (left)                             LINESTRING (0 0, -1 1)           LINESTRING (0 0, 0 0)            POINT (0 0)
Nested Geometry Collection                Square (right)                            LINESTRING (0 0, 1 1)            LINESTRING (0 0, 0 0)            POINT (0 0)
Nested Geometry Collection                Square overlapping left and right square  LINESTRING (0 0, 1 1)            LINESTRING (0 0, 0 0)            POINT (0 0)
Point middle of Left Square               Empty GeometryCollection                  NULL                             NULL                             NULL
Point middle of Left Square               Empty LineString                          NULL                             NULL                             NULL
Point middle of Left Square               Empty Point                               NULL                             NULL                             NULL
Point middle of Left Square               Faraway point                             LINESTRING (-0.5 0.5, 5 5)       LINESTRING (-0.5 0.5, 5 5)       POINT (-0.5 0.5)
Point middle of Left Square               Line going through left and right square  LINESTRING (-0.5 0.5, 0.5 0.5)   LINESTRING (-0.5 0.5, -0.5 0.5)  POINT (-0.5 0.5)
Point middle of Left Square               NULL                                      NULL                             NULL                             NULL
Point middle of Left Square               Nested Geometry Collection                LINESTRING (-0.5 0.5, 0 0)       LINESTRING (-0.5 0.5, 0 0)       POINT (-0.5 0.5)
Point middle of Left Square               Point middle of Left Square               LINESTRING (-0.5 0.5, -0.5 0.5)  LINESTRING (-0.5 0.5, -0.5 0.5)  POINT (-0.5 0.5)
Point middle of Left Square               Point middle of Right Square              LINESTRING (-0.5 0.5, 0.5 0.5)   LINESTRING (-0.5 0.5, 0.5 0.5)   POINT (-0.5 0.5)
Point middle of Left Square               Square (left)                             LINESTRING (-0.5 0.5, 0 0)       LINESTRING (-0.5 0.5, -0.5 0.5)  POINT (-0.5 0.5)
Point middle of Left Square               Square (right)                            LINESTRING (-0.5 0.5, 1 0)       LINESTRING (-0.5 0.5, 0 0.5)     POINT (-0.5 0.5)
Point middle of Left Square               Square overlapping left and right square  LINESTRING (-0.5 0.5, 1 0)       LINESTRING (-0.5 0.5, -0.1 0.5)  POINT (-0.5 0.5)
Point middle of Right Square              Empty GeometryCollection                  NULL                             NULL                             NULL
Point middle of Right Square              Empty LineString                          NULL                             NULL                             NULL
Point middle of Right Square              Empty Point                               NULL                             NULL                             NULL
Point middle of Right Square              Faraway point                             LINESTRING (0.5 0.5, 5 5)        LINESTRING (0.5 0.5, 5 5)        POINT (0.5 0.5)
Point middle of Right Square              Line going through left and right square  LINESTRING (0.5 0.5, -0.5 0.5)   LINESTRING (0.5 0.5, 0.5 0.5)    POINT (0.5 0.5)
Point middle of Right Square              NULL                                      NULL                             NULL                             NULL
Point middle of Right Square              Nested Geometry Collection                LINESTRING (0.5 0.5, 0 0)        LINESTRING (0.5 0.5, 0 0)        POINT (0.5 0.5)
Point middle of Right Square              Point middle of Left Square               LINESTRING (0.5 0.5, -0.5 0.5)   LINESTRING (0.5 0.5, -0.5 0.5)   POINT (0.5 0.5)
Point middle of Right Square              Point middle of Right Square              LINESTRING (0.5 0.5, 0.5 0.5)    LINESTRING (0.5 0.5, 0.5 0.5)    POINT (0.5 0.5)
Point middle of Right Square              Square (left)                             LINESTRING (0.5 0.5, -1 1)       LINESTRING (0.5 0.5, 0 0.5)      POINT (0.5 0.5)
Point middle of Right Square              Square (right)                            LINESTRING (0.5 0.5, 1 0)        LINESTRING (0.5 0.5, 0.5 0.5)    POINT (0.5 0.5)
Point middle of Right Square              Square overlapping left and right square  LINESTRING (0.5 0.5, -0.1 1)     LINESTRING (0.5 0.5, 0.5 0.5)    POINT (0.5 0.5)
Square (left)                             Empty GeometryCollection                  NULL                             NULL                             NULL
Square (left)                             Empty LineString                          NULL                             NULL                             NULL
Square (left)                             Empty Point                               NULL                             NULL                             NULL
Square (left)                             Faraway point                             LINESTRING (-1 0, 5 5)           LINESTRING (0 1, 5 5)            POINT (0 1)
Square (left)                             Line going through left and right square  LINESTRING (-1 0, 0.5 0.5)       LINESTRING (-0.5 0.5, -0.5 0.5)  POINT (-0.5 0.5)
Square (left)                             NULL                                      NULL                             NULL                             NULL
Square (left)                             Nested Geometry Collection                LINESTRING (-1 1, 0 0)           LINESTRING (0 0, 0 0)            POINT (0 0)
Square (left)                             Point middle of Left Square               LINESTRING (0 0, -0.5 0.5)       LINESTRING (-0.5 0.5, -0.5 0.5)  POINT (-0.5 0.5)
Square (left)                             Point middle of Right Square              LINESTRING (-1 1, 0.5 0.5)       LINESTRING (0 0.5, 0.5 0.5)      POINT (0 0.5)
Square (left)                             Square (left)                             LINESTRING (-1 0, 0 1)           LINESTRING (-1 0, -1 0)          POINT (-1 0)
Square (left)                             Square (right)                            LINESTRING (-1 0, 1 1)           LINESTRING (0 0, 0 0)            POINT (0 0)
Square (left)                             Square overlapping left and right square  LINESTRING (-1 0, 1 1)           LINESTRING (-0.1 0, -0.1 0)      POINT (-0.1 0)
Square (right)                            Empty GeometryCollection                  NULL                             NULL                             NULL
Square (right)                            Empty LineString                          NULL                             NULL                             NULL
Square (right)                            Empty Point                               NULL                             NULL                             NULL
Square (right)                            Faraway point                             LINESTRING (0 0, 5 5)            LINESTRING (1 1, 5 5)            POINT (1 1)
Square (right)                            Line going through left and right square  LINESTRING (1 0, -0.5 0.5)       LINESTRING (0 0.5, 0 0.5)        POINT (0 0.5)
Square (right)                            NULL                                      NULL                             NULL                             NULL
Square (right)                            Nested Geometry Collection                LINESTRING (1 1, 0 0)            LINESTRING (0 0, 0 0)            POINT (0 0)
Square (right)                            Point middle of Left Square               LINESTRING (1 0, -0.5 0.5)       LINESTRING (0 0.5, -0.5 0.5)     POINT (0 0.5)
Square (right)                            Point middle of Right Square              LINESTRING (1 0, 0.5 0.5)        LINESTRING (0.5 0.5, 0.5 0.5)    POINT (0.5 0.5)
Square (right)                            Square (left)                             LINESTRING (1 0, -1 1)           LINESTRING (0 0, 0 0)            POINT (0 0)
Square (right)                            Square (right)                            LINESTRING (0 0, 1 1)            LINESTRING (0 0, 0 0)            POINT (0 0)
Square (right)                            Square overlapping left and right square  LINESTRING (1 0, -0.1 1)         LINESTRING (0 0, 0 0)            POINT (0 0)
Square overlapping left and right square  Empty GeometryCollection                  NULL                             NULL                             NULL
Square overlapping left and right square  Empty LineString                          NULL                             NULL                             NULL
Square overlapping left and right square  Empty Point                               NULL                             NULL                             NULL
Square overlapping left and right square  Faraway point                             LINESTRING (-0.1 0, 5 5)         LINESTRING (1 1, 5 5)            POINT (1 1)
Square overlapping left and right square  Line going through left and right square  LINESTRING (1 0, -0.5 0.5)       LINESTRING (-0.1 0.5, -0.1 0.5)  POINT (-0.1 0.5)
Square overlapping left and right square  NULL                                      NULL                             NULL                             NULL
Square overlapping left and right square  Nested Geometry Collection                LINESTRING (1 1, 0 0)            LINESTRING (0 0, 0 0)            POINT (0 0)
Square overlapping left and right square  Point middle of Left Square               LINESTRING (1 0, -0.5 0.5)       LINESTRING (-0.1 0.5, -0.5 0.5)  POINT (-0.1 0.5)
Square overlapping left and right square  Point middle of Right Square              LINESTRING (-0.1 1, 0.5 0.5)     LINESTRING (0.5 0.5, 0.5 0.5)    POINT (0.5 0.5)
Square overlapping left and right square  Square (left)                             LINESTRING (1 0, -1 1)           LINESTRING (-0.1 0, -0.1 0)      POINT (-0.1 0)
Square overlapping left and right square  Square (right)                            LINESTRING (-0.1 0, 1 1)         LINESTRING (0 0, 0 0)            POINT (0 0)
Square overlapping left and right square  Square overlapping left and right square  LINESTRING (-0.1 0, 1 1)         LINESTRING (-0.1 0, -0.1 0)      POINT (-0.1 0)

# ST_Difference
query TTT
SELECT
  a.dsc,
  b.dsc,
  ST_AsText(ST_Difference(a.geom, b.geom))
FROM geom_operators_test a, geom_operators_test b
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Empty LineString                          GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Empty Point                               GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Faraway point                             GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Line going through left and right square  GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  NULL                                      NULL
Empty GeometryCollection                  Nested Geometry Collection                GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Point middle of Left Square               GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Point middle of Right Square              GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Square (left)                             GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Square (right)                            GEOMETRYCOLLECTION EMPTY
Empty GeometryCollection                  Square overlapping left and right square  GEOMETRYCOLLECTION EMPTY
Empty LineString                          Empty GeometryCollection                  LINESTRING EMPTY
Empty LineString                          Empty LineString                          LINESTRING EMPTY
Empty LineString                          Empty Point                               LINESTRING EMPTY
Empty LineString                          Faraway point                             LINESTRING EMPTY
Empty LineString                          Line going through left and right square  LINESTRING EMPTY
Empty LineString                          NULL                                      NULL
Empty LineString                          Nested Geometry Collection                LINESTRING EMPTY
Empty LineString                          Point middle of Left Square               LINESTRING EMPTY
Empty LineString                          Point middle of Right Square              LINESTRING EMPTY
Empty LineString                          Square (left)                             LINESTRING EMPTY
Empty LineString                          Square (right)                            LINESTRING EMPTY
Empty LineString                          Square overlapping left and right square  LINESTRING EMPTY
Empty Point                               Empty GeometryCollection                  POINT EMPTY
Empty Point                               Empty LineString                          POINT EMPTY
Empty Point                               Empty Point                               POINT EMPTY
Empty Point                               Faraway point                             POINT EMPTY
Empty Point                               Line going through left and right square  POINT EMPTY
Empty Point                               NULL                                      NULL
Empty Point                               Nested Geometry Collection                POINT EMPTY
Empty Point                               Point middle of Left Square               POINT EMPTY
Empty Point                               Point middle of Right Square              POINT EMPTY
Empty Point                               Square (left)                             POINT EMPTY
Empty Point                               Square (right)                            POINT EMPTY
Empty Point                               Square overlapping left and right square  POINT EMPTY
Faraway point                             Empty GeometryCollection                  POINT (5 5)
Faraway point                             Empty LineString                          POINT (5 5)
Faraway point                             Empty Point                               POINT (5 5)
Faraway point                             Faraway point                             POINT EMPTY
Faraway point                             Line going through left and right square  POINT (5 5)
Faraway point                             NULL                                      NULL
Faraway point                             Nested Geometry Collection                POINT (5 5)
Faraway point                             Point middle of Left Square               POINT (5 5)
Faraway point                             Point middle of Right Square              POINT (5 5)
Faraway point                             Square (left)                             POINT (5 5)
Faraway point                             Square (right)                            POINT (5 5)
Faraway point                             Square overlapping left and right square  POINT (5 5)
Line going through left and right square  Empty GeometryCollection                  LINESTRING (-0.5 0.5, 0.5 0.5)
Line going through left and right square  Empty LineString                          LINESTRING (-0.5 0.5, 0.5 0.5)
Line going through left and right square  Empty Point                               LINESTRING (-0.5 0.5, 0.5 0.5)
Line going through left and right square  Faraway point                             LINESTRING (-0.5 0.5, 0.5 0.5)
Line going through left and right square  Line going through left and right square  LINESTRING EMPTY
Line going through left and right square  NULL                                      NULL
Line going through left and right square  Nested Geometry Collection                LINESTRING (-0.5 0.5, 0.5 0.5)
Line going through left and right square  Point middle of Left Square               LINESTRING (-0.5 0.5, 0.5 0.5)
Line going through left and right square  Point middle of Right Square              LINESTRING (-0.5 0.5, 0.5 0.5)
Line going through left and right square  Square (left)                             LINESTRING (0 0.5, 0.5 0.5)
Line going through left and right square  Square (right)                            LINESTRING (-0.5 0.5, 0 0.5)
Line going through left and right square  Square overlapping left and right square  LINESTRING (-0.5 0.5, -0.1 0.5)
NULL                                      Empty GeometryCollection                  NULL
NULL                                      Empty LineString                          NULL
NULL                                      Empty Point                               NULL
NULL                                      Faraway point                             NULL
NULL                                      Line going through left and right square  NULL
NULL                                      NULL                                      NULL
NULL                                      Nested Geometry Collection                NULL
NULL                                      Point middle of Left Square               NULL
NULL                                      Point middle of Right Square              NULL
NULL                                      Square (left)                             NULL
NULL                                      Square (right)                            NULL
NULL                                      Square overlapping left and right square  NULL
Nested Geometry Collection                Empty GeometryCollection                  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Nested Geometry Collection                Empty LineString                          GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Nested Geometry Collection                Empty Point                               GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Nested Geometry Collection                Faraway point                             POINT (0 0)
Nested Geometry Collection                Line going through left and right square  POINT (0 0)
Nested Geometry Collection                NULL                                      NULL
Nested Geometry Collection                Nested Geometry Collection                POINT EMPTY
Nested Geometry Collection                Point middle of Left Square               POINT (0 0)
Nested Geometry Collection                Point middle of Right Square              POINT (0 0)
Nested Geometry Collection                Square (left)                             POINT EMPTY
Nested Geometry Collection                Square (right)                            POINT EMPTY
Nested Geometry Collection                Square overlapping left and right square  POINT EMPTY
Point middle of Left Square               Empty GeometryCollection                  POINT (-0.5 0.5)
Point middle of Left Square               Empty LineString                          POINT (-0.5 0.5)
Point middle of Left Square               Empty Point                               POINT (-0.5 0.5)
Point middle of Left Square               Faraway point                             POINT (-0.5 0.5)
Point middle of Left Square               Line going through left and right square  POINT EMPTY
Point middle of Left Square               NULL                                      NULL
Point middle of Left Square               Nested Geometry Collection                POINT (-0.5 0.5)
Point middle of Left Square               Point middle of Left Square               POINT EMPTY
Point middle of Left Square               Point middle of Right Square              POINT (-0.5 0.5)
Point middle of Left Square               Square (left)                             POINT EMPTY
Point middle of Left Square               Square (right)                            POINT (-0.5 0.5)
Point middle of Left Square               Square overlapping left and right square  POINT (-0.5 0.5)
Point middle of Right Square              Empty GeometryCollection                  POINT (0.5 0.5)
Point middle of Right Square              Empty LineString                          POINT (0.5 0.5)
Point middle of Right Square              Empty Point                               POINT (0.5 0.5)
Point middle of Right Square              Faraway point                             POINT (0.5 0.5)
Point middle of Right Square              Line going through left and right square  POINT EMPTY
Point middle of Right Square              NULL                                      NULL
Point middle of Right Square              Nested Geometry Collection                POINT (0.5 0.5)
Point middle of Right Square              Point middle of Left Square               POINT (0.5 0.5)
Point middle of Right Square              Point middle of Right Square              POINT EMPTY
Point middle of Right Square              Square (left)                             POINT (0.5 0.5)
Point middle of Right Square              Square (right)                            POINT EMPTY
Point middle of Right Square              Square overlapping left and right square  POINT EMPTY
Square (left)                             Empty GeometryCollection                  POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (left)                             Empty LineString                          POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (left)                             Empty Point                               POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (left)                             Faraway point                             POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))
Square (left)                             Line going through left and right square  POLYGON ((0 0, -1 0, -1 1, 0 1, 0 0.5, 0 0))
Square (left)                             NULL                                      NULL
Square (left)                             Nested Geometry Collection                POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))
Square (left)                             Point middle of Left Square               POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))
Square (left)                             Point middle of Right Square              POLYGON ((-1 1, 0 1, 0 0, -1 0, -1 1))
Square (left)                             Square (left)                             POLYGON EMPTY
Square (left)                             Square (right)                            POLYGON ((-1 0, -1 1, 0 1, 0 0, -1 0))
Square (left)                             Square overlapping left and right square  POLYGON ((-1 0, -1 1, -0.1 1, -0.1 0, -1 0))
Square (right)                            Empty GeometryCollection                  POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square (right)                            Empty LineString                          POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square (right)                            Empty Point                               POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square (right)                            Faraway point                             POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))
Square (right)                            Line going through left and right square  POLYGON ((0 1, 1 1, 1 0, 0 0, 0 0.5, 0 1))
Square (right)                            NULL                                      NULL
Square (right)                            Nested Geometry Collection                POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))
Square (right)                            Point middle of Left Square               POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))
Square (right)                            Point middle of Right Square              POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))
Square (right)                            Square (left)                             POLYGON ((1 1, 1 0, 0 0, 0 1, 1 1))
Square (right)                            Square (right)                            POLYGON EMPTY
Square (right)                            Square overlapping left and right square  POLYGON EMPTY
Square overlapping left and right square  Empty GeometryCollection                  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
Square overlapping left and right square  Empty LineString                          POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
Square overlapping left and right square  Empty Point                               POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
Square overlapping left and right square  Faraway point                             POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))
Square overlapping left and right square  Line going through left and right square  POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 0.5, -0.1 1))
Square overlapping left and right square  NULL                                      NULL
Square overlapping left and right square  Nested Geometry Collection                POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))
Square overlapping left and right square  Point middle of Left Square               POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))
Square overlapping left and right square  Point middle of Right Square              POLYGON ((-0.1 1, 1 1, 1 0, -0.1 0, -0.1 1))
Square overlapping left and right square  Square (left)                             POLYGON ((1 1, 1 0, 0 0, 0 1, 1 1))
Square overlapping left and right square  Square (right)                            POLYGON ((-0.1 0, -0.1 1, 0 1, 0 0, -0.1 0))
Square overlapping left and right square  Square overlapping left and right square  POLYGON EMPTY

query TT
SELECT
  st_astext(st_shortestline(a, b)),
  st_astext(st_longestline(a, b))
FROM ( VALUES
  (st_scale('multipoint (0 0, 1 1)', 0, 'NaN'::float)::geometry, 'linestring (0 0, 1 1)'::geometry)
) regression_t65422(a, b)
----
LINESTRING (0 NaN, 0 0)  LINESTRING (0 NaN, 0 0)

# Binary predicates
query TTBBBBBBBBBBBB
SELECT
  a.dsc,
  b.dsc,
  ST_Covers(a.geom, b.geom),
  ST_CoveredBy(a.geom, b.geom),
  ST_Contains(a.geom, b.geom),
  ST_ContainsProperly(a.geom, b.geom),
  ST_Crosses(a.geom, b.geom),
  ST_Disjoint(a.geom, b.geom),
  ST_Equals(a.geom, b.geom),
  ST_OrderingEquals(a.geom, b.geom),
  ST_Intersects(a.geom, b.geom),
  ST_Overlaps(a.geom, b.geom),
  ST_Touches(a.geom, b.geom),
  ST_Within(a.geom, b.geom)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  false  false  false  false  false  true   true   true   false  false  false  false
Empty GeometryCollection                  Empty LineString                          false  false  false  false  false  true   true   false  false  false  false  false
Empty GeometryCollection                  Empty Point                               false  false  false  false  false  true   true   false  false  false  false  false
Empty GeometryCollection                  Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Empty GeometryCollection                  Line going through left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Empty GeometryCollection                  NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Empty GeometryCollection                  Nested Geometry Collection                false  false  false  false  false  true   false  false  false  false  false  false
Empty GeometryCollection                  Point middle of Left Square               false  false  false  false  false  true   false  false  false  false  false  false
Empty GeometryCollection                  Point middle of Right Square              false  false  false  false  false  true   false  false  false  false  false  false
Empty GeometryCollection                  Square (left)                             false  false  false  false  false  true   false  false  false  false  false  false
Empty GeometryCollection                  Square (right)                            false  false  false  false  false  true   false  false  false  false  false  false
Empty GeometryCollection                  Square overlapping left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Empty LineString                          Empty GeometryCollection                  false  false  false  false  false  true   true   false  false  false  false  false
Empty LineString                          Empty LineString                          false  false  false  false  false  true   true   true   false  false  false  false
Empty LineString                          Empty Point                               false  false  false  false  false  true   true   false  false  false  false  false
Empty LineString                          Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Empty LineString                          Line going through left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Empty LineString                          NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Empty LineString                          Nested Geometry Collection                false  false  false  false  false  true   false  false  false  false  false  false
Empty LineString                          Point middle of Left Square               false  false  false  false  false  true   false  false  false  false  false  false
Empty LineString                          Point middle of Right Square              false  false  false  false  false  true   false  false  false  false  false  false
Empty LineString                          Square (left)                             false  false  false  false  false  true   false  false  false  false  false  false
Empty LineString                          Square (right)                            false  false  false  false  false  true   false  false  false  false  false  false
Empty LineString                          Square overlapping left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Empty Point                               Empty GeometryCollection                  false  false  false  false  false  true   true   false  false  false  false  false
Empty Point                               Empty LineString                          false  false  false  false  false  true   true   false  false  false  false  false
Empty Point                               Empty Point                               false  false  false  false  false  true   true   true   false  false  false  false
Empty Point                               Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Empty Point                               Line going through left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Empty Point                               NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Empty Point                               Nested Geometry Collection                false  false  false  false  false  true   false  false  false  false  false  false
Empty Point                               Point middle of Left Square               false  false  false  false  false  true   false  false  false  false  false  false
Empty Point                               Point middle of Right Square              false  false  false  false  false  true   false  false  false  false  false  false
Empty Point                               Square (left)                             false  false  false  false  false  true   false  false  false  false  false  false
Empty Point                               Square (right)                            false  false  false  false  false  true   false  false  false  false  false  false
Empty Point                               Square overlapping left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Empty LineString                          false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Empty Point                               false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Faraway point                             true   true   true   true   false  false  true   true   true   false  false  true
Faraway point                             Line going through left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Faraway point                             Nested Geometry Collection                false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Point middle of Left Square               false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Point middle of Right Square              false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Square (left)                             false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Square (right)                            false  false  false  false  false  true   false  false  false  false  false  false
Faraway point                             Square overlapping left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Line going through left and right square  Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false  false  false
Line going through left and right square  Empty LineString                          false  false  false  false  false  true   false  false  false  false  false  false
Line going through left and right square  Empty Point                               false  false  false  false  false  true   false  false  false  false  false  false
Line going through left and right square  Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Line going through left and right square  Line going through left and right square  true   true   true   false  false  false  true   true   true   false  false  true
Line going through left and right square  NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Line going through left and right square  Nested Geometry Collection                false  false  false  false  false  true   false  false  false  false  false  false
Line going through left and right square  Point middle of Left Square               true   false  false  false  false  false  false  false  true   false  true   false
Line going through left and right square  Point middle of Right Square              true   false  false  false  false  false  false  false  true   false  true   false
Line going through left and right square  Square (left)                             false  false  false  false  true   false  false  false  true   false  false  false
Line going through left and right square  Square (right)                            false  false  false  false  true   false  false  false  true   false  false  false
Line going through left and right square  Square overlapping left and right square  false  false  false  false  true   false  false  false  true   false  false  false
NULL                                      Empty GeometryCollection                  NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Empty LineString                          NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Empty Point                               NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Faraway point                             NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Line going through left and right square  NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Nested Geometry Collection                NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Point middle of Left Square               NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Point middle of Right Square              NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Square (left)                             NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Square (right)                            NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Square overlapping left and right square  NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Nested Geometry Collection                Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false  false  false
Nested Geometry Collection                Empty LineString                          false  false  false  false  false  true   false  false  false  false  false  false
Nested Geometry Collection                Empty Point                               false  false  false  false  false  true   false  false  false  false  false  false
Nested Geometry Collection                Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Nested Geometry Collection                Line going through left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Nested Geometry Collection                NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Nested Geometry Collection                Nested Geometry Collection                true   true   true   true   false  false  true   true   true   false  false  true
Nested Geometry Collection                Point middle of Left Square               false  false  false  false  false  true   false  false  false  false  false  false
Nested Geometry Collection                Point middle of Right Square              false  false  false  false  false  true   false  false  false  false  false  false
Nested Geometry Collection                Square (left)                             false  true   false  false  false  false  false  false  true   false  true   false
Nested Geometry Collection                Square (right)                            false  true   false  false  false  false  false  false  true   false  true   false
Nested Geometry Collection                Square overlapping left and right square  false  true   false  false  false  false  false  false  true   false  true   false
Point middle of Left Square               Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Left Square               Empty LineString                          false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Left Square               Empty Point                               false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Left Square               Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Left Square               Line going through left and right square  false  true   false  false  false  false  false  false  true   false  true   false
Point middle of Left Square               NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Point middle of Left Square               Nested Geometry Collection                false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Left Square               Point middle of Left Square               true   true   true   true   false  false  true   true   true   false  false  true
Point middle of Left Square               Point middle of Right Square              false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Left Square               Square (left)                             false  true   false  false  false  false  false  false  true   false  false  true
Point middle of Left Square               Square (right)                            false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Left Square               Square overlapping left and right square  false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Right Square              Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Right Square              Empty LineString                          false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Right Square              Empty Point                               false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Right Square              Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Right Square              Line going through left and right square  false  true   false  false  false  false  false  false  true   false  true   false
Point middle of Right Square              NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Point middle of Right Square              Nested Geometry Collection                false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Right Square              Point middle of Left Square               false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Right Square              Point middle of Right Square              true   true   true   true   false  false  true   true   true   false  false  true
Point middle of Right Square              Square (left)                             false  false  false  false  false  true   false  false  false  false  false  false
Point middle of Right Square              Square (right)                            false  true   false  false  false  false  false  false  true   false  false  true
Point middle of Right Square              Square overlapping left and right square  false  true   false  false  false  false  false  false  true   false  false  true
Square (left)                             Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false  false  false
Square (left)                             Empty LineString                          false  false  false  false  false  true   false  false  false  false  false  false
Square (left)                             Empty Point                               false  false  false  false  false  true   false  false  false  false  false  false
Square (left)                             Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Square (left)                             Line going through left and right square  false  false  false  false  true   false  false  false  true   false  false  false
Square (left)                             NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Square (left)                             Nested Geometry Collection                true   false  false  false  false  false  false  false  true   false  true   false
Square (left)                             Point middle of Left Square               true   false  true   true   false  false  false  false  true   false  false  false
Square (left)                             Point middle of Right Square              false  false  false  false  false  true   false  false  false  false  false  false
Square (left)                             Square (left)                             true   true   true   false  false  false  true   true   true   false  false  true
Square (left)                             Square (right)                            false  false  false  false  false  false  false  false  true   false  true   false
Square (left)                             Square overlapping left and right square  false  false  false  false  false  false  false  false  true   true   false  false
Square (right)                            Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false  false  false
Square (right)                            Empty LineString                          false  false  false  false  false  true   false  false  false  false  false  false
Square (right)                            Empty Point                               false  false  false  false  false  true   false  false  false  false  false  false
Square (right)                            Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Square (right)                            Line going through left and right square  false  false  false  false  true   false  false  false  true   false  false  false
Square (right)                            NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Square (right)                            Nested Geometry Collection                true   false  false  false  false  false  false  false  true   false  true   false
Square (right)                            Point middle of Left Square               false  false  false  false  false  true   false  false  false  false  false  false
Square (right)                            Point middle of Right Square              true   false  true   true   false  false  false  false  true   false  false  false
Square (right)                            Square (left)                             false  false  false  false  false  false  false  false  true   false  true   false
Square (right)                            Square (right)                            true   true   true   false  false  false  true   true   true   false  false  true
Square (right)                            Square overlapping left and right square  false  true   false  false  false  false  false  false  true   false  false  true
Square overlapping left and right square  Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false  false  false
Square overlapping left and right square  Empty LineString                          false  false  false  false  false  true   false  false  false  false  false  false
Square overlapping left and right square  Empty Point                               false  false  false  false  false  true   false  false  false  false  false  false
Square overlapping left and right square  Faraway point                             false  false  false  false  false  true   false  false  false  false  false  false
Square overlapping left and right square  Line going through left and right square  false  false  false  false  true   false  false  false  true   false  false  false
Square overlapping left and right square  NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Square overlapping left and right square  Nested Geometry Collection                true   false  false  false  false  false  false  false  true   false  true   false
Square overlapping left and right square  Point middle of Left Square               false  false  false  false  false  true   false  false  false  false  false  false
Square overlapping left and right square  Point middle of Right Square              true   false  true   true   false  false  false  false  true   false  false  false
Square overlapping left and right square  Square (left)                             false  false  false  false  false  false  false  false  true   true   false  false
Square overlapping left and right square  Square (right)                            true   false  true   false  false  false  false  false  true   false  false  false
Square overlapping left and right square  Square overlapping left and right square  true   true   true   false  false  false  true   true   true   false  false  true

query TTBBBBBBBBBB
SELECT
  a.dsc,
  b.dsc,
  _ST_Covers(a.geom, b.geom),
  _ST_CoveredBy(a.geom, b.geom),
  _ST_Contains(a.geom, b.geom),
  _ST_ContainsProperly(a.geom, b.geom),
  _ST_Crosses(a.geom, b.geom),
  _ST_Equals(a.geom, b.geom),
  _ST_Intersects(a.geom, b.geom),
  _ST_Overlaps(a.geom, b.geom),
  _ST_Touches(a.geom, b.geom),
  _ST_Within(a.geom, b.geom)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false
Empty GeometryCollection                  Empty LineString                          false  false  false  false  false  true   false  false  false  false
Empty GeometryCollection                  Empty Point                               false  false  false  false  false  true   false  false  false  false
Empty GeometryCollection                  Faraway point                             false  false  false  false  false  false  false  false  false  false
Empty GeometryCollection                  Line going through left and right square  false  false  false  false  false  false  false  false  false  false
Empty GeometryCollection                  NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Empty GeometryCollection                  Nested Geometry Collection                false  false  false  false  false  false  false  false  false  false
Empty GeometryCollection                  Point middle of Left Square               false  false  false  false  false  false  false  false  false  false
Empty GeometryCollection                  Point middle of Right Square              false  false  false  false  false  false  false  false  false  false
Empty GeometryCollection                  Square (left)                             false  false  false  false  false  false  false  false  false  false
Empty GeometryCollection                  Square (right)                            false  false  false  false  false  false  false  false  false  false
Empty GeometryCollection                  Square overlapping left and right square  false  false  false  false  false  false  false  false  false  false
Empty LineString                          Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false
Empty LineString                          Empty LineString                          false  false  false  false  false  true   false  false  false  false
Empty LineString                          Empty Point                               false  false  false  false  false  true   false  false  false  false
Empty LineString                          Faraway point                             false  false  false  false  false  false  false  false  false  false
Empty LineString                          Line going through left and right square  false  false  false  false  false  false  false  false  false  false
Empty LineString                          NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Empty LineString                          Nested Geometry Collection                false  false  false  false  false  false  false  false  false  false
Empty LineString                          Point middle of Left Square               false  false  false  false  false  false  false  false  false  false
Empty LineString                          Point middle of Right Square              false  false  false  false  false  false  false  false  false  false
Empty LineString                          Square (left)                             false  false  false  false  false  false  false  false  false  false
Empty LineString                          Square (right)                            false  false  false  false  false  false  false  false  false  false
Empty LineString                          Square overlapping left and right square  false  false  false  false  false  false  false  false  false  false
Empty Point                               Empty GeometryCollection                  false  false  false  false  false  true   false  false  false  false
Empty Point                               Empty LineString                          false  false  false  false  false  true   false  false  false  false
Empty Point                               Empty Point                               false  false  false  false  false  true   false  false  false  false
Empty Point                               Faraway point                             false  false  false  false  false  false  false  false  false  false
Empty Point                               Line going through left and right square  false  false  false  false  false  false  false  false  false  false
Empty Point                               NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Empty Point                               Nested Geometry Collection                false  false  false  false  false  false  false  false  false  false
Empty Point                               Point middle of Left Square               false  false  false  false  false  false  false  false  false  false
Empty Point                               Point middle of Right Square              false  false  false  false  false  false  false  false  false  false
Empty Point                               Square (left)                             false  false  false  false  false  false  false  false  false  false
Empty Point                               Square (right)                            false  false  false  false  false  false  false  false  false  false
Empty Point                               Square overlapping left and right square  false  false  false  false  false  false  false  false  false  false
Faraway point                             Empty GeometryCollection                  false  false  false  false  false  false  false  false  false  false
Faraway point                             Empty LineString                          false  false  false  false  false  false  false  false  false  false
Faraway point                             Empty Point                               false  false  false  false  false  false  false  false  false  false
Faraway point                             Faraway point                             true   true   true   true   false  true   true   false  false  true
Faraway point                             Line going through left and right square  false  false  false  false  false  false  false  false  false  false
Faraway point                             NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Faraway point                             Nested Geometry Collection                false  false  false  false  false  false  false  false  false  false
Faraway point                             Point middle of Left Square               false  false  false  false  false  false  false  false  false  false
Faraway point                             Point middle of Right Square              false  false  false  false  false  false  false  false  false  false
Faraway point                             Square (left)                             false  false  false  false  false  false  false  false  false  false
Faraway point                             Square (right)                            false  false  false  false  false  false  false  false  false  false
Faraway point                             Square overlapping left and right square  false  false  false  false  false  false  false  false  false  false
Line going through left and right square  Empty GeometryCollection                  false  false  false  false  false  false  false  false  false  false
Line going through left and right square  Empty LineString                          false  false  false  false  false  false  false  false  false  false
Line going through left and right square  Empty Point                               false  false  false  false  false  false  false  false  false  false
Line going through left and right square  Faraway point                             false  false  false  false  false  false  false  false  false  false
Line going through left and right square  Line going through left and right square  true   true   true   false  false  true   true   false  false  true
Line going through left and right square  NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Line going through left and right square  Nested Geometry Collection                false  false  false  false  false  false  false  false  false  false
Line going through left and right square  Point middle of Left Square               true   false  false  false  false  false  true   false  true   false
Line going through left and right square  Point middle of Right Square              true   false  false  false  false  false  true   false  true   false
Line going through left and right square  Square (left)                             false  false  false  false  true   false  true   false  false  false
Line going through left and right square  Square (right)                            false  false  false  false  true   false  true   false  false  false
Line going through left and right square  Square overlapping left and right square  false  false  false  false  true   false  true   false  false  false
NULL                                      Empty GeometryCollection                  NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Empty LineString                          NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Empty Point                               NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Faraway point                             NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Line going through left and right square  NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Nested Geometry Collection                NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Point middle of Left Square               NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Point middle of Right Square              NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Square (left)                             NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Square (right)                            NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
NULL                                      Square overlapping left and right square  NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Nested Geometry Collection                Empty GeometryCollection                  false  false  false  false  false  false  false  false  false  false
Nested Geometry Collection                Empty LineString                          false  false  false  false  false  false  false  false  false  false
Nested Geometry Collection                Empty Point                               false  false  false  false  false  false  false  false  false  false
Nested Geometry Collection                Faraway point                             false  false  false  false  false  false  false  false  false  false
Nested Geometry Collection                Line going through left and right square  false  false  false  false  false  false  false  false  false  false
Nested Geometry Collection                NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Nested Geometry Collection                Nested Geometry Collection                true   true   true   true   false  true   true   false  false  true
Nested Geometry Collection                Point middle of Left Square               false  false  false  false  false  false  false  false  false  false
Nested Geometry Collection                Point middle of Right Square              false  false  false  false  false  false  false  false  false  false
Nested Geometry Collection                Square (left)                             false  true   false  false  false  false  true   false  true   false
Nested Geometry Collection                Square (right)                            false  true   false  false  false  false  true   false  true   false
Nested Geometry Collection                Square overlapping left and right square  false  true   false  false  false  false  true   false  true   false
Point middle of Left Square               Empty GeometryCollection                  false  false  false  false  false  false  false  false  false  false
Point middle of Left Square               Empty LineString                          false  false  false  false  false  false  false  false  false  false
Point middle of Left Square               Empty Point                               false  false  false  false  false  false  false  false  false  false
Point middle of Left Square               Faraway point                             false  false  false  false  false  false  false  false  false  false
Point middle of Left Square               Line going through left and right square  false  true   false  false  false  false  true   false  true   false
Point middle of Left Square               NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Point middle of Left Square               Nested Geometry Collection                false  false  false  false  false  false  false  false  false  false
Point middle of Left Square               Point middle of Left Square               true   true   true   true   false  true   true   false  false  true
Point middle of Left Square               Point middle of Right Square              false  false  false  false  false  false  false  false  false  false
Point middle of Left Square               Square (left)                             false  true   false  false  false  false  true   false  false  true
Point middle of Left Square               Square (right)                            false  false  false  false  false  false  false  false  false  false
Point middle of Left Square               Square overlapping left and right square  false  false  false  false  false  false  false  false  false  false
Point middle of Right Square              Empty GeometryCollection                  false  false  false  false  false  false  false  false  false  false
Point middle of Right Square              Empty LineString                          false  false  false  false  false  false  false  false  false  false
Point middle of Right Square              Empty Point                               false  false  false  false  false  false  false  false  false  false
Point middle of Right Square              Faraway point                             false  false  false  false  false  false  false  false  false  false
Point middle of Right Square              Line going through left and right square  false  true   false  false  false  false  true   false  true   false
Point middle of Right Square              NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Point middle of Right Square              Nested Geometry Collection                false  false  false  false  false  false  false  false  false  false
Point middle of Right Square              Point middle of Left Square               false  false  false  false  false  false  false  false  false  false
Point middle of Right Square              Point middle of Right Square              true   true   true   true   false  true   true   false  false  true
Point middle of Right Square              Square (left)                             false  false  false  false  false  false  false  false  false  false
Point middle of Right Square              Square (right)                            false  true   false  false  false  false  true   false  false  true
Point middle of Right Square              Square overlapping left and right square  false  true   false  false  false  false  true   false  false  true
Square (left)                             Empty GeometryCollection                  false  false  false  false  false  false  false  false  false  false
Square (left)                             Empty LineString                          false  false  false  false  false  false  false  false  false  false
Square (left)                             Empty Point                               false  false  false  false  false  false  false  false  false  false
Square (left)                             Faraway point                             false  false  false  false  false  false  false  false  false  false
Square (left)                             Line going through left and right square  false  false  false  false  true   false  true   false  false  false
Square (left)                             NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Square (left)                             Nested Geometry Collection                true   false  false  false  false  false  true   false  true   false
Square (left)                             Point middle of Left Square               true   false  true   true   false  false  true   false  false  false
Square (left)                             Point middle of Right Square              false  false  false  false  false  false  false  false  false  false
Square (left)                             Square (left)                             true   true   true   false  false  true   true   false  false  true
Square (left)                             Square (right)                            false  false  false  false  false  false  true   false  true   false
Square (left)                             Square overlapping left and right square  false  false  false  false  false  false  true   true   false  false
Square (right)                            Empty GeometryCollection                  false  false  false  false  false  false  false  false  false  false
Square (right)                            Empty LineString                          false  false  false  false  false  false  false  false  false  false
Square (right)                            Empty Point                               false  false  false  false  false  false  false  false  false  false
Square (right)                            Faraway point                             false  false  false  false  false  false  false  false  false  false
Square (right)                            Line going through left and right square  false  false  false  false  true   false  true   false  false  false
Square (right)                            NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Square (right)                            Nested Geometry Collection                true   false  false  false  false  false  true   false  true   false
Square (right)                            Point middle of Left Square               false  false  false  false  false  false  false  false  false  false
Square (right)                            Point middle of Right Square              true   false  true   true   false  false  true   false  false  false
Square (right)                            Square (left)                             false  false  false  false  false  false  true   false  true   false
Square (right)                            Square (right)                            true   true   true   false  false  true   true   false  false  true
Square (right)                            Square overlapping left and right square  false  true   false  false  false  false  true   false  false  true
Square overlapping left and right square  Empty GeometryCollection                  false  false  false  false  false  false  false  false  false  false
Square overlapping left and right square  Empty LineString                          false  false  false  false  false  false  false  false  false  false
Square overlapping left and right square  Empty Point                               false  false  false  false  false  false  false  false  false  false
Square overlapping left and right square  Faraway point                             false  false  false  false  false  false  false  false  false  false
Square overlapping left and right square  Line going through left and right square  false  false  false  false  true   false  true   false  false  false
Square overlapping left and right square  NULL                                      NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
Square overlapping left and right square  Nested Geometry Collection                true   false  false  false  false  false  true   false  true   false
Square overlapping left and right square  Point middle of Left Square               false  false  false  false  false  false  false  false  false  false
Square overlapping left and right square  Point middle of Right Square              true   false  true   true   false  false  true   false  false  false
Square overlapping left and right square  Square (left)                             false  false  false  false  false  false  true   true   false  false
Square overlapping left and right square  Square (right)                            true   false  true   false  false  false  true   false  false  false
Square overlapping left and right square  Square overlapping left and right square  true   true   true   false  false  true   true   false  false  true

# DWithin
query TTBB
SELECT
  a.dsc,
  b.dsc,
  ST_DWithin(a.geom, b.geom, 1),
  ST_DFullyWithin(a.geom, b.geom, 1)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  false  false
Empty GeometryCollection                  Empty LineString                          false  false
Empty GeometryCollection                  Empty Point                               false  false
Empty GeometryCollection                  Faraway point                             false  false
Empty GeometryCollection                  Line going through left and right square  false  false
Empty GeometryCollection                  NULL                                      NULL   NULL
Empty GeometryCollection                  Nested Geometry Collection                false  false
Empty GeometryCollection                  Point middle of Left Square               false  false
Empty GeometryCollection                  Point middle of Right Square              false  false
Empty GeometryCollection                  Square (left)                             false  false
Empty GeometryCollection                  Square (right)                            false  false
Empty GeometryCollection                  Square overlapping left and right square  false  false
Empty LineString                          Empty GeometryCollection                  false  false
Empty LineString                          Empty LineString                          false  false
Empty LineString                          Empty Point                               false  false
Empty LineString                          Faraway point                             false  false
Empty LineString                          Line going through left and right square  false  false
Empty LineString                          NULL                                      NULL   NULL
Empty LineString                          Nested Geometry Collection                false  false
Empty LineString                          Point middle of Left Square               false  false
Empty LineString                          Point middle of Right Square              false  false
Empty LineString                          Square (left)                             false  false
Empty LineString                          Square (right)                            false  false
Empty LineString                          Square overlapping left and right square  false  false
Empty Point                               Empty GeometryCollection                  false  false
Empty Point                               Empty LineString                          false  false
Empty Point                               Empty Point                               false  false
Empty Point                               Faraway point                             false  false
Empty Point                               Line going through left and right square  false  false
Empty Point                               NULL                                      NULL   NULL
Empty Point                               Nested Geometry Collection                false  false
Empty Point                               Point middle of Left Square               false  false
Empty Point                               Point middle of Right Square              false  false
Empty Point                               Square (left)                             false  false
Empty Point                               Square (right)                            false  false
Empty Point                               Square overlapping left and right square  false  false
Faraway point                             Empty GeometryCollection                  false  false
Faraway point                             Empty LineString                          false  false
Faraway point                             Empty Point                               false  false
Faraway point                             Faraway point                             true   true
Faraway point                             Line going through left and right square  false  false
Faraway point                             NULL                                      NULL   NULL
Faraway point                             Nested Geometry Collection                false  false
Faraway point                             Point middle of Left Square               false  false
Faraway point                             Point middle of Right Square              false  false
Faraway point                             Square (left)                             false  false
Faraway point                             Square (right)                            false  false
Faraway point                             Square overlapping left and right square  false  false
Line going through left and right square  Empty GeometryCollection                  false  false
Line going through left and right square  Empty LineString                          false  false
Line going through left and right square  Empty Point                               false  false
Line going through left and right square  Faraway point                             false  false
Line going through left and right square  Line going through left and right square  true   true
Line going through left and right square  NULL                                      NULL   NULL
Line going through left and right square  Nested Geometry Collection                true   true
Line going through left and right square  Point middle of Left Square               true   true
Line going through left and right square  Point middle of Right Square              true   true
Line going through left and right square  Square (left)                             true   false
Line going through left and right square  Square (right)                            true   false
Line going through left and right square  Square overlapping left and right square  true   false
NULL                                      Empty GeometryCollection                  NULL   NULL
NULL                                      Empty LineString                          NULL   NULL
NULL                                      Empty Point                               NULL   NULL
NULL                                      Faraway point                             NULL   NULL
NULL                                      Line going through left and right square  NULL   NULL
NULL                                      NULL                                      NULL   NULL
NULL                                      Nested Geometry Collection                NULL   NULL
NULL                                      Point middle of Left Square               NULL   NULL
NULL                                      Point middle of Right Square              NULL   NULL
NULL                                      Square (left)                             NULL   NULL
NULL                                      Square (right)                            NULL   NULL
NULL                                      Square overlapping left and right square  NULL   NULL
Nested Geometry Collection                Empty GeometryCollection                  false  false
Nested Geometry Collection                Empty LineString                          false  false
Nested Geometry Collection                Empty Point                               false  false
Nested Geometry Collection                Faraway point                             false  false
Nested Geometry Collection                Line going through left and right square  true   true
Nested Geometry Collection                NULL                                      NULL   NULL
Nested Geometry Collection                Nested Geometry Collection                true   true
Nested Geometry Collection                Point middle of Left Square               true   true
Nested Geometry Collection                Point middle of Right Square              true   true
Nested Geometry Collection                Square (left)                             true   false
Nested Geometry Collection                Square (right)                            true   false
Nested Geometry Collection                Square overlapping left and right square  true   false
Point middle of Left Square               Empty GeometryCollection                  false  false
Point middle of Left Square               Empty LineString                          false  false
Point middle of Left Square               Empty Point                               false  false
Point middle of Left Square               Faraway point                             false  false
Point middle of Left Square               Line going through left and right square  true   true
Point middle of Left Square               NULL                                      NULL   NULL
Point middle of Left Square               Nested Geometry Collection                true   true
Point middle of Left Square               Point middle of Left Square               true   true
Point middle of Left Square               Point middle of Right Square              true   true
Point middle of Left Square               Square (left)                             true   true
Point middle of Left Square               Square (right)                            true   false
Point middle of Left Square               Square overlapping left and right square  true   false
Point middle of Right Square              Empty GeometryCollection                  false  false
Point middle of Right Square              Empty LineString                          false  false
Point middle of Right Square              Empty Point                               false  false
Point middle of Right Square              Faraway point                             false  false
Point middle of Right Square              Line going through left and right square  true   true
Point middle of Right Square              NULL                                      NULL   NULL
Point middle of Right Square              Nested Geometry Collection                true   true
Point middle of Right Square              Point middle of Left Square               true   true
Point middle of Right Square              Point middle of Right Square              true   true
Point middle of Right Square              Square (left)                             true   false
Point middle of Right Square              Square (right)                            true   true
Point middle of Right Square              Square overlapping left and right square  true   true
Square (left)                             Empty GeometryCollection                  false  false
Square (left)                             Empty LineString                          false  false
Square (left)                             Empty Point                               false  false
Square (left)                             Faraway point                             false  false
Square (left)                             Line going through left and right square  true   false
Square (left)                             NULL                                      NULL   NULL
Square (left)                             Nested Geometry Collection                true   false
Square (left)                             Point middle of Left Square               true   true
Square (left)                             Point middle of Right Square              true   false
Square (left)                             Square (left)                             true   false
Square (left)                             Square (right)                            true   false
Square (left)                             Square overlapping left and right square  true   false
Square (right)                            Empty GeometryCollection                  false  false
Square (right)                            Empty LineString                          false  false
Square (right)                            Empty Point                               false  false
Square (right)                            Faraway point                             false  false
Square (right)                            Line going through left and right square  true   false
Square (right)                            NULL                                      NULL   NULL
Square (right)                            Nested Geometry Collection                true   false
Square (right)                            Point middle of Left Square               true   false
Square (right)                            Point middle of Right Square              true   true
Square (right)                            Square (left)                             true   false
Square (right)                            Square (right)                            true   false
Square (right)                            Square overlapping left and right square  true   false
Square overlapping left and right square  Empty GeometryCollection                  false  false
Square overlapping left and right square  Empty LineString                          false  false
Square overlapping left and right square  Empty Point                               false  false
Square overlapping left and right square  Faraway point                             false  false
Square overlapping left and right square  Line going through left and right square  true   false
Square overlapping left and right square  NULL                                      NULL   NULL
Square overlapping left and right square  Nested Geometry Collection                true   false
Square overlapping left and right square  Point middle of Left Square               true   false
Square overlapping left and right square  Point middle of Right Square              true   true
Square overlapping left and right square  Square (left)                             true   false
Square overlapping left and right square  Square (right)                            true   false
Square overlapping left and right square  Square overlapping left and right square  true   false

query TTBB
SELECT
  a.dsc,
  b.dsc,
  _ST_DWithin(a.geom, b.geom, 1),
  _ST_DFullyWithin(a.geom, b.geom, 1)
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  false  false
Empty GeometryCollection                  Empty LineString                          false  false
Empty GeometryCollection                  Empty Point                               false  false
Empty GeometryCollection                  Faraway point                             false  false
Empty GeometryCollection                  Line going through left and right square  false  false
Empty GeometryCollection                  NULL                                      NULL   NULL
Empty GeometryCollection                  Nested Geometry Collection                false  false
Empty GeometryCollection                  Point middle of Left Square               false  false
Empty GeometryCollection                  Point middle of Right Square              false  false
Empty GeometryCollection                  Square (left)                             false  false
Empty GeometryCollection                  Square (right)                            false  false
Empty GeometryCollection                  Square overlapping left and right square  false  false
Empty LineString                          Empty GeometryCollection                  false  false
Empty LineString                          Empty LineString                          false  false
Empty LineString                          Empty Point                               false  false
Empty LineString                          Faraway point                             false  false
Empty LineString                          Line going through left and right square  false  false
Empty LineString                          NULL                                      NULL   NULL
Empty LineString                          Nested Geometry Collection                false  false
Empty LineString                          Point middle of Left Square               false  false
Empty LineString                          Point middle of Right Square              false  false
Empty LineString                          Square (left)                             false  false
Empty LineString                          Square (right)                            false  false
Empty LineString                          Square overlapping left and right square  false  false
Empty Point                               Empty GeometryCollection                  false  false
Empty Point                               Empty LineString                          false  false
Empty Point                               Empty Point                               false  false
Empty Point                               Faraway point                             false  false
Empty Point                               Line going through left and right square  false  false
Empty Point                               NULL                                      NULL   NULL
Empty Point                               Nested Geometry Collection                false  false
Empty Point                               Point middle of Left Square               false  false
Empty Point                               Point middle of Right Square              false  false
Empty Point                               Square (left)                             false  false
Empty Point                               Square (right)                            false  false
Empty Point                               Square overlapping left and right square  false  false
Faraway point                             Empty GeometryCollection                  false  false
Faraway point                             Empty LineString                          false  false
Faraway point                             Empty Point                               false  false
Faraway point                             Faraway point                             true   true
Faraway point                             Line going through left and right square  false  false
Faraway point                             NULL                                      NULL   NULL
Faraway point                             Nested Geometry Collection                false  false
Faraway point                             Point middle of Left Square               false  false
Faraway point                             Point middle of Right Square              false  false
Faraway point                             Square (left)                             false  false
Faraway point                             Square (right)                            false  false
Faraway point                             Square overlapping left and right square  false  false
Line going through left and right square  Empty GeometryCollection                  false  false
Line going through left and right square  Empty LineString                          false  false
Line going through left and right square  Empty Point                               false  false
Line going through left and right square  Faraway point                             false  false
Line going through left and right square  Line going through left and right square  true   true
Line going through left and right square  NULL                                      NULL   NULL
Line going through left and right square  Nested Geometry Collection                true   true
Line going through left and right square  Point middle of Left Square               true   true
Line going through left and right square  Point middle of Right Square              true   true
Line going through left and right square  Square (left)                             true   false
Line going through left and right square  Square (right)                            true   false
Line going through left and right square  Square overlapping left and right square  true   false
NULL                                      Empty GeometryCollection                  NULL   NULL
NULL                                      Empty LineString                          NULL   NULL
NULL                                      Empty Point                               NULL   NULL
NULL                                      Faraway point                             NULL   NULL
NULL                                      Line going through left and right square  NULL   NULL
NULL                                      NULL                                      NULL   NULL
NULL                                      Nested Geometry Collection                NULL   NULL
NULL                                      Point middle of Left Square               NULL   NULL
NULL                                      Point middle of Right Square              NULL   NULL
NULL                                      Square (left)                             NULL   NULL
NULL                                      Square (right)                            NULL   NULL
NULL                                      Square overlapping left and right square  NULL   NULL
Nested Geometry Collection                Empty GeometryCollection                  false  false
Nested Geometry Collection                Empty LineString                          false  false
Nested Geometry Collection                Empty Point                               false  false
Nested Geometry Collection                Faraway point                             false  false
Nested Geometry Collection                Line going through left and right square  true   true
Nested Geometry Collection                NULL                                      NULL   NULL
Nested Geometry Collection                Nested Geometry Collection                true   true
Nested Geometry Collection                Point middle of Left Square               true   true
Nested Geometry Collection                Point middle of Right Square              true   true
Nested Geometry Collection                Square (left)                             true   false
Nested Geometry Collection                Square (right)                            true   false
Nested Geometry Collection                Square overlapping left and right square  true   false
Point middle of Left Square               Empty GeometryCollection                  false  false
Point middle of Left Square               Empty LineString                          false  false
Point middle of Left Square               Empty Point                               false  false
Point middle of Left Square               Faraway point                             false  false
Point middle of Left Square               Line going through left and right square  true   true
Point middle of Left Square               NULL                                      NULL   NULL
Point middle of Left Square               Nested Geometry Collection                true   true
Point middle of Left Square               Point middle of Left Square               true   true
Point middle of Left Square               Point middle of Right Square              true   true
Point middle of Left Square               Square (left)                             true   true
Point middle of Left Square               Square (right)                            true   false
Point middle of Left Square               Square overlapping left and right square  true   false
Point middle of Right Square              Empty GeometryCollection                  false  false
Point middle of Right Square              Empty LineString                          false  false
Point middle of Right Square              Empty Point                               false  false
Point middle of Right Square              Faraway point                             false  false
Point middle of Right Square              Line going through left and right square  true   true
Point middle of Right Square              NULL                                      NULL   NULL
Point middle of Right Square              Nested Geometry Collection                true   true
Point middle of Right Square              Point middle of Left Square               true   true
Point middle of Right Square              Point middle of Right Square              true   true
Point middle of Right Square              Square (left)                             true   false
Point middle of Right Square              Square (right)                            true   true
Point middle of Right Square              Square overlapping left and right square  true   true
Square (left)                             Empty GeometryCollection                  false  false
Square (left)                             Empty LineString                          false  false
Square (left)                             Empty Point                               false  false
Square (left)                             Faraway point                             false  false
Square (left)                             Line going through left and right square  true   false
Square (left)                             NULL                                      NULL   NULL
Square (left)                             Nested Geometry Collection                true   false
Square (left)                             Point middle of Left Square               true   true
Square (left)                             Point middle of Right Square              true   false
Square (left)                             Square (left)                             true   false
Square (left)                             Square (right)                            true   false
Square (left)                             Square overlapping left and right square  true   false
Square (right)                            Empty GeometryCollection                  false  false
Square (right)                            Empty LineString                          false  false
Square (right)                            Empty Point                               false  false
Square (right)                            Faraway point                             false  false
Square (right)                            Line going through left and right square  true   false
Square (right)                            NULL                                      NULL   NULL
Square (right)                            Nested Geometry Collection                true   false
Square (right)                            Point middle of Left Square               true   false
Square (right)                            Point middle of Right Square              true   true
Square (right)                            Square (left)                             true   false
Square (right)                            Square (right)                            true   false
Square (right)                            Square overlapping left and right square  true   false
Square overlapping left and right square  Empty GeometryCollection                  false  false
Square overlapping left and right square  Empty LineString                          false  false
Square overlapping left and right square  Empty Point                               false  false
Square overlapping left and right square  Faraway point                             false  false
Square overlapping left and right square  Line going through left and right square  true   false
Square overlapping left and right square  NULL                                      NULL   NULL
Square overlapping left and right square  Nested Geometry Collection                true   false
Square overlapping left and right square  Point middle of Left Square               true   false
Square overlapping left and right square  Point middle of Right Square              true   true
Square overlapping left and right square  Square (left)                             true   false
Square overlapping left and right square  Square (right)                            true   false
Square overlapping left and right square  Square overlapping left and right square  true   false

# ST_Buffer
query TTTT
SELECT
  a.dsc,
  ST_AsEWKT(ST_Buffer(a.geom, 10), 5),
  ST_AsEWKT(ST_Buffer(a.geom, 10, 2), 5),
  ST_AsEWKT(ST_Buffer(a.geom, 10, 'quad_segs=4 endcap=flat'), 5)
FROM geom_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  POLYGON EMPTY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      POLYGON EMPTY                                                                                                                                                POLYGON EMPTY
Empty LineString                          POLYGON EMPTY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      POLYGON EMPTY                                                                                                                                                POLYGON EMPTY
Empty Point                               POLYGON EMPTY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      POLYGON EMPTY                                                                                                                                                POLYGON EMPTY
Faraway point                             POLYGON ((15 5, 14.80785 3.0491, 14.2388 1.17317, 13.3147 -0.5557, 12.07107 -2.07107, 10.5557 -3.3147, 8.82683 -4.2388, 6.9509 -4.80785, 5 -5, 3.0491 -4.80785, 1.17317 -4.2388, -0.5557 -3.3147, -2.07107 -2.07107, -3.3147 -0.5557, -4.2388 1.17317, -4.80785 3.0491, -5 5, -4.80785 6.9509, -4.2388 8.82683, -3.3147 10.5557, -2.07107 12.07107, -0.5557 13.3147, 1.17317 14.2388, 3.0491 14.80785, 5 15, 6.9509 14.80785, 8.82683 14.2388, 10.5557 13.3147, 12.07107 12.07107, 13.3147 10.5557, 14.2388 8.82683, 14.80785 6.9509, 15 5))                                       POLYGON ((15 5, 12.07107 -2.07107, 5 -5, -2.07107 -2.07107, -5 5, -2.07107 12.07107, 5 15, 12.07107 12.07107, 15 5))                                         POLYGON EMPTY
Line going through left and right square  POLYGON ((0.5 10.5, 2.4509 10.30785, 4.32683 9.7388, 6.0557 8.8147, 7.57107 7.57107, 8.8147 6.0557, 9.7388 4.32683, 10.30785 2.4509, 10.5 0.5, 10.30785 -1.4509, 9.7388 -3.32683, 8.8147 -5.0557, 7.57107 -6.57107, 6.0557 -7.8147, 4.32683 -8.7388, 2.4509 -9.30785, 0.5 -9.5, -0.5 -9.5, -2.4509 -9.30785, -4.32683 -8.7388, -6.0557 -7.8147, -7.57107 -6.57107, -8.8147 -5.0557, -9.7388 -3.32683, -10.30785 -1.4509, -10.5 0.5, -10.30785 2.4509, -9.7388 4.32683, -8.8147 6.0557, -7.57107 7.57107, -6.0557 8.8147, -4.32683 9.7388, -2.4509 10.30785, -0.5 10.5, 0.5 10.5))  POLYGON ((0.5 10.5, 7.57107 7.57107, 10.5 0.5, 7.57107 -6.57107, 0.5 -9.5, -0.5 -9.5, -7.57107 -6.57107, -10.5 0.5, -7.57107 7.57107, -0.5 10.5, 0.5 10.5))  POLYGON ((0.5 10.5, 0.5 -9.5, -0.5 -9.5, -0.5 10.5, 0.5 10.5))
NULL                                      NULL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               NULL                                                                                                                                                         NULL
Nested Geometry Collection                POLYGON ((10 0, 9.80785 -1.9509, 9.2388 -3.82683, 8.3147 -5.5557, 7.07107 -7.07107, 5.5557 -8.3147, 3.82683 -9.2388, 1.9509 -9.80785, 0 -10, -1.9509 -9.80785, -3.82683 -9.2388, -5.5557 -8.3147, -7.07107 -7.07107, -8.3147 -5.5557, -9.2388 -3.82683, -9.80785 -1.9509, -10 -0, -9.80785 1.9509, -9.2388 3.82683, -8.3147 5.5557, -7.07107 7.07107, -5.5557 8.3147, -3.82683 9.2388, -1.9509 9.80785, -0 10, 1.9509 9.80785, 3.82683 9.2388, 5.5557 8.3147, 7.07107 7.07107, 8.3147 5.5557, 9.2388 3.82683, 9.80785 1.9509, 10 0))                                               POLYGON ((10 0, 7.07107 -7.07107, 0 -10, -7.07107 -7.07107, -10 -0, -7.07107 7.07107, -0 10, 7.07107 7.07107, 10 0))                                         POLYGON EMPTY
Point middle of Left Square               POLYGON ((9.5 0.5, 9.30785 -1.4509, 8.7388 -3.32683, 7.8147 -5.0557, 6.57107 -6.57107, 5.0557 -7.8147, 3.32683 -8.7388, 1.4509 -9.30785, -0.5 -9.5, -2.4509 -9.30785, -4.32683 -8.7388, -6.0557 -7.8147, -7.57107 -6.57107, -8.8147 -5.0557, -9.7388 -3.32683, -10.30785 -1.4509, -10.5 0.5, -10.30785 2.4509, -9.7388 4.32683, -8.8147 6.0557, -7.57107 7.57107, -6.0557 8.8147, -4.32683 9.7388, -2.4509 10.30785, -0.5 10.5, 1.4509 10.30785, 3.32683 9.7388, 5.0557 8.8147, 6.57107 7.57107, 7.8147 6.0557, 8.7388 4.32683, 9.30785 2.4509, 9.5 0.5))                          POLYGON ((9.5 0.5, 6.57107 -6.57107, -0.5 -9.5, -7.57107 -6.57107, -10.5 0.5, -7.57107 7.57107, -0.5 10.5, 6.57107 7.57107, 9.5 0.5))                        POLYGON EMPTY
Point middle of Right Square              POLYGON ((10.5 0.5, 10.30785 -1.4509, 9.7388 -3.32683, 8.8147 -5.0557, 7.57107 -6.57107, 6.0557 -7.8147, 4.32683 -8.7388, 2.4509 -9.30785, 0.5 -9.5, -1.4509 -9.30785, -3.32683 -8.7388, -5.0557 -7.8147, -6.57107 -6.57107, -7.8147 -5.0557, -8.7388 -3.32683, -9.30785 -1.4509, -9.5 0.5, -9.30785 2.4509, -8.7388 4.32683, -7.8147 6.0557, -6.57107 7.57107, -5.0557 8.8147, -3.32683 9.7388, -1.4509 10.30785, 0.5 10.5, 2.4509 10.30785, 4.32683 9.7388, 6.0557 8.8147, 7.57107 7.57107, 8.8147 6.0557, 9.7388 4.32683, 10.30785 2.4509, 10.5 0.5))                           POLYGON ((10.5 0.5, 7.57107 -6.57107, 0.5 -9.5, -6.57107 -6.57107, -9.5 0.5, -6.57107 7.57107, 0.5 10.5, 7.57107 7.57107, 10.5 0.5))                         POLYGON EMPTY
Square (left)                             POLYGON ((-11 0, -11 1, -10.80785 2.9509, -10.2388 4.82683, -9.3147 6.5557, -8.07107 8.07107, -6.5557 9.3147, -4.82683 10.2388, -2.9509 10.80785, -1 11, 0 11, 1.9509 10.80785, 3.82683 10.2388, 5.5557 9.3147, 7.07107 8.07107, 8.3147 6.5557, 9.2388 4.82683, 9.80785 2.9509, 10 1, 10 0, 9.80785 -1.9509, 9.2388 -3.82683, 8.3147 -5.5557, 7.07107 -7.07107, 5.5557 -8.3147, 3.82683 -9.2388, 1.9509 -9.80785, 0 -10, -1 -10, -2.9509 -9.80785, -4.82683 -9.2388, -6.5557 -8.3147, -8.07107 -7.07107, -9.3147 -5.5557, -10.2388 -3.82683, -10.80785 -1.9509, -11 0))            POLYGON ((-11 0, -11 1, -8.07107 8.07107, -1 11, 0 11, 7.07107 8.07107, 10 1, 10 0, 7.07107 -7.07107, 0 -10, -1 -10, -8.07107 -7.07107, -11 0))              POLYGON ((-11 0, -11 1, -10.2388 4.82683, -8.07107 8.07107, -4.82683 10.2388, -1 11, 0 11, 3.82683 10.2388, 7.07107 8.07107, 9.2388 4.82683, 10 1, 10 0, 9.2388 -3.82683, 7.07107 -7.07107, 3.82683 -9.2388, 0 -10, -1 -10, -4.82683 -9.2388, -8.07107 -7.07107, -10.2388 -3.82683, -11 0))
Square (right)                            POLYGON ((-10 0, -10 1, -9.80785 2.9509, -9.2388 4.82683, -8.3147 6.5557, -7.07107 8.07107, -5.5557 9.3147, -3.82683 10.2388, -1.9509 10.80785, 0 11, 1 11, 2.9509 10.80785, 4.82683 10.2388, 6.5557 9.3147, 8.07107 8.07107, 9.3147 6.5557, 10.2388 4.82683, 10.80785 2.9509, 11 1, 11 0, 10.80785 -1.9509, 10.2388 -3.82683, 9.3147 -5.5557, 8.07107 -7.07107, 6.5557 -8.3147, 4.82683 -9.2388, 2.9509 -9.80785, 1 -10, 0 -10, -1.9509 -9.80785, -3.82683 -9.2388, -5.5557 -8.3147, -7.07107 -7.07107, -8.3147 -5.5557, -9.2388 -3.82683, -9.80785 -1.9509, -10 0))              POLYGON ((-10 0, -10 1, -7.07107 8.07107, 0 11, 1 11, 8.07107 8.07107, 11 1, 11 0, 8.07107 -7.07107, 1 -10, 0 -10, -7.07107 -7.07107, -10 0))                POLYGON ((-10 0, -10 1, -9.2388 4.82683, -7.07107 8.07107, -3.82683 10.2388, 0 11, 1 11, 4.82683 10.2388, 8.07107 8.07107, 10.2388 4.82683, 11 1, 11 0, 10.2388 -3.82683, 8.07107 -7.07107, 4.82683 -9.2388, 1 -10, 0 -10, -3.82683 -9.2388, -7.07107 -7.07107, -9.2388 -3.82683, -10 0))
Square overlapping left and right square  POLYGON ((-10.1 0, -10.1 1, -9.90785 2.9509, -9.3388 4.82683, -8.4147 6.5557, -7.17107 8.07107, -5.6557 9.3147, -3.92683 10.2388, -2.0509 10.80785, -0.1 11, 1 11, 2.9509 10.80785, 4.82683 10.2388, 6.5557 9.3147, 8.07107 8.07107, 9.3147 6.5557, 10.2388 4.82683, 10.80785 2.9509, 11 1, 11 0, 10.80785 -1.9509, 10.2388 -3.82683, 9.3147 -5.5557, 8.07107 -7.07107, 6.5557 -8.3147, 4.82683 -9.2388, 2.9509 -9.80785, 1 -10, -0.1 -10, -2.0509 -9.80785, -3.92683 -9.2388, -5.6557 -8.3147, -7.17107 -7.07107, -8.4147 -5.5557, -9.3388 -3.82683, -9.90785 -1.9509, -10.1 0))  POLYGON ((-10.1 0, -10.1 1, -7.17107 8.07107, -0.1 11, 1 11, 8.07107 8.07107, 11 1, 11 0, 8.07107 -7.07107, 1 -10, -0.1 -10, -7.17107 -7.07107, -10.1 0))    POLYGON ((-10.1 0, -10.1 1, -9.3388 4.82683, -7.17107 8.07107, -3.92683 10.2388, -0.1 11, 1 11, 4.82683 10.2388, 8.07107 8.07107, 10.2388 4.82683, 11 1, 11 0, 10.2388 -3.82683, 8.07107 -7.07107, 4.82683 -9.2388, 1 -10, -0.1 -10, -3.92683 -9.2388, -7.17107 -7.07107, -9.3388 -3.82683, -10.1 0))

# Test raw string with ST_Buffer
query I
SELECT ST_NPoints(ST_Buffer('SRID=4326;POINT(0 0)', 10.0))
----
33

# DE-9IM relations
query B nosort
SELECT
  ST_RelateMatch(m, pattern)
FROM ( VALUES
  ('101202FFF', 'TTTTTTFFF'),
  ('101202FTF', 'TTTTTTFFF')
) tbl(m, pattern)
----
true
false

query TTTTB
SELECT
  a.dsc,
  b.dsc,
  ST_Relate(a.geom, b.geom),
  ST_Relate(a.geom, b.geom, 3),
  ST_Relate(a.geom, b.geom, 'T**FF*FF*')
FROM geom_operators_test a
JOIN geom_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  FFFFFFFF2  FFFFFFFF2  false
Empty GeometryCollection                  Empty LineString                          FFFFFFFF2  FFFFFFFF2  false
Empty GeometryCollection                  Empty Point                               FFFFFFFF2  FFFFFFFF2  false
Empty GeometryCollection                  Faraway point                             FFFFFF0F2  FFFFFF0F2  false
Empty GeometryCollection                  Line going through left and right square  FFFFFF102  FFFFFF102  false
Empty GeometryCollection                  NULL                                      NULL       NULL       NULL
Empty GeometryCollection                  Nested Geometry Collection                FFFFFF0F2  FFFFFF0F2  false
Empty GeometryCollection                  Point middle of Left Square               FFFFFF0F2  FFFFFF0F2  false
Empty GeometryCollection                  Point middle of Right Square              FFFFFF0F2  FFFFFF0F2  false
Empty GeometryCollection                  Square (left)                             FFFFFF212  FFFFFF212  false
Empty GeometryCollection                  Square (right)                            FFFFFF212  FFFFFF212  false
Empty GeometryCollection                  Square overlapping left and right square  FFFFFF212  FFFFFF212  false
Empty LineString                          Empty GeometryCollection                  FFFFFFFF2  FFFFFFFF2  false
Empty LineString                          Empty LineString                          FFFFFFFF2  FFFFFFFF2  false
Empty LineString                          Empty Point                               FFFFFFFF2  FFFFFFFF2  false
Empty LineString                          Faraway point                             FFFFFF0F2  FFFFFF0F2  false
Empty LineString                          Line going through left and right square  FFFFFF102  FFFFFF102  false
Empty LineString                          NULL                                      NULL       NULL       NULL
Empty LineString                          Nested Geometry Collection                FFFFFF0F2  FFFFFF0F2  false
Empty LineString                          Point middle of Left Square               FFFFFF0F2  FFFFFF0F2  false
Empty LineString                          Point middle of Right Square              FFFFFF0F2  FFFFFF0F2  false
Empty LineString                          Square (left)                             FFFFFF212  FFFFFF212  false
Empty LineString                          Square (right)                            FFFFFF212  FFFFFF212  false
Empty LineString                          Square overlapping left and right square  FFFFFF212  FFFFFF212  false
Empty Point                               Empty GeometryCollection                  FFFFFFFF2  FFFFFFFF2  false
Empty Point                               Empty LineString                          FFFFFFFF2  FFFFFFFF2  false
Empty Point                               Empty Point                               FFFFFFFF2  FFFFFFFF2  false
Empty Point                               Faraway point                             FFFFFF0F2  FFFFFF0F2  false
Empty Point                               Line going through left and right square  FFFFFF102  FFFFFF102  false
Empty Point                               NULL                                      NULL       NULL       NULL
Empty Point                               Nested Geometry Collection                FFFFFF0F2  FFFFFF0F2  false
Empty Point                               Point middle of Left Square               FFFFFF0F2  FFFFFF0F2  false
Empty Point                               Point middle of Right Square              FFFFFF0F2  FFFFFF0F2  false
Empty Point                               Square (left)                             FFFFFF212  FFFFFF212  false
Empty Point                               Square (right)                            FFFFFF212  FFFFFF212  false
Empty Point                               Square overlapping left and right square  FFFFFF212  FFFFFF212  false
Faraway point                             Empty GeometryCollection                  FF0FFFFF2  FF0FFFFF2  false
Faraway point                             Empty LineString                          FF0FFFFF2  FF0FFFFF2  false
Faraway point                             Empty Point                               FF0FFFFF2  FF0FFFFF2  false
Faraway point                             Faraway point                             0FFFFFFF2  0FFFFFFF2  true
Faraway point                             Line going through left and right square  FF0FFF102  FF0FFF102  false
Faraway point                             NULL                                      NULL       NULL       NULL
Faraway point                             Nested Geometry Collection                FF0FFF0F2  FF0FFF0F2  false
Faraway point                             Point middle of Left Square               FF0FFF0F2  FF0FFF0F2  false
Faraway point                             Point middle of Right Square              FF0FFF0F2  FF0FFF0F2  false
Faraway point                             Square (left)                             FF0FFF212  FF0FFF212  false
Faraway point                             Square (right)                            FF0FFF212  FF0FFF212  false
Faraway point                             Square overlapping left and right square  FF0FFF212  FF0FFF212  false
Line going through left and right square  Empty GeometryCollection                  FF1FF0FF2  FF1FF0FF2  false
Line going through left and right square  Empty LineString                          FF1FF0FF2  FF1FF0FF2  false
Line going through left and right square  Empty Point                               FF1FF0FF2  FF1FF0FF2  false
Line going through left and right square  Faraway point                             FF1FF00F2  FF1FF00F2  false
Line going through left and right square  Line going through left and right square  1FFF0FFF2  1FFFFFFF2  false
Line going through left and right square  NULL                                      NULL       NULL       NULL
Line going through left and right square  Nested Geometry Collection                FF1FF00F2  FF1FF00F2  false
Line going through left and right square  Point middle of Left Square               FF10F0FF2  0F1FFFFF2  false
Line going through left and right square  Point middle of Right Square              FF10F0FF2  0F1FFFFF2  false
Line going through left and right square  Square (left)                             1010F0212  101FFF202  false
Line going through left and right square  Square (right)                            1010F0212  101FFF202  false
Line going through left and right square  Square overlapping left and right square  1010F0212  101FFF202  false
NULL                                      Empty GeometryCollection                  NULL       NULL       NULL
NULL                                      Empty LineString                          NULL       NULL       NULL
NULL                                      Empty Point                               NULL       NULL       NULL
NULL                                      Faraway point                             NULL       NULL       NULL
NULL                                      Line going through left and right square  NULL       NULL       NULL
NULL                                      NULL                                      NULL       NULL       NULL
NULL                                      Nested Geometry Collection                NULL       NULL       NULL
NULL                                      Point middle of Left Square               NULL       NULL       NULL
NULL                                      Point middle of Right Square              NULL       NULL       NULL
NULL                                      Square (left)                             NULL       NULL       NULL
NULL                                      Square (right)                            NULL       NULL       NULL
NULL                                      Square overlapping left and right square  NULL       NULL       NULL
Nested Geometry Collection                Empty GeometryCollection                  FF0FFFFF2  FF0FFFFF2  false
Nested Geometry Collection                Empty LineString                          FF0FFFFF2  FF0FFFFF2  false
Nested Geometry Collection                Empty Point                               FF0FFFFF2  FF0FFFFF2  false
Nested Geometry Collection                Faraway point                             FF0FFF0F2  FF0FFF0F2  false
Nested Geometry Collection                Line going through left and right square  FF0FFF102  FF0FFF102  false
Nested Geometry Collection                NULL                                      NULL       NULL       NULL
Nested Geometry Collection                Nested Geometry Collection                0FFFFFFF2  0FFFFFFF2  true
Nested Geometry Collection                Point middle of Left Square               FF0FFF0F2  FF0FFF0F2  false
Nested Geometry Collection                Point middle of Right Square              FF0FFF0F2  FF0FFF0F2  false
Nested Geometry Collection                Square (left)                             F0FFFF212  F0FFFF212  false
Nested Geometry Collection                Square (right)                            F0FFFF212  F0FFFF212  false
Nested Geometry Collection                Square overlapping left and right square  F0FFFF212  F0FFFF212  false
Point middle of Left Square               Empty GeometryCollection                  FF0FFFFF2  FF0FFFFF2  false
Point middle of Left Square               Empty LineString                          FF0FFFFF2  FF0FFFFF2  false
Point middle of Left Square               Empty Point                               FF0FFFFF2  FF0FFFFF2  false
Point middle of Left Square               Faraway point                             FF0FFF0F2  FF0FFF0F2  false
Point middle of Left Square               Line going through left and right square  F0FFFF102  0FFFFF1F2  false
Point middle of Left Square               NULL                                      NULL       NULL       NULL
Point middle of Left Square               Nested Geometry Collection                FF0FFF0F2  FF0FFF0F2  false
Point middle of Left Square               Point middle of Left Square               0FFFFFFF2  0FFFFFFF2  true
Point middle of Left Square               Point middle of Right Square              FF0FFF0F2  FF0FFF0F2  false
Point middle of Left Square               Square (left)                             0FFFFF212  0FFFFF212  false
Point middle of Left Square               Square (right)                            FF0FFF212  FF0FFF212  false
Point middle of Left Square               Square overlapping left and right square  FF0FFF212  FF0FFF212  false
Point middle of Right Square              Empty GeometryCollection                  FF0FFFFF2  FF0FFFFF2  false
Point middle of Right Square              Empty LineString                          FF0FFFFF2  FF0FFFFF2  false
Point middle of Right Square              Empty Point                               FF0FFFFF2  FF0FFFFF2  false
Point middle of Right Square              Faraway point                             FF0FFF0F2  FF0FFF0F2  false
Point middle of Right Square              Line going through left and right square  F0FFFF102  0FFFFF1F2  false
Point middle of Right Square              NULL                                      NULL       NULL       NULL
Point middle of Right Square              Nested Geometry Collection                FF0FFF0F2  FF0FFF0F2  false
Point middle of Right Square              Point middle of Left Square               FF0FFF0F2  FF0FFF0F2  false
Point middle of Right Square              Point middle of Right Square              0FFFFFFF2  0FFFFFFF2  true
Point middle of Right Square              Square (left)                             FF0FFF212  FF0FFF212  false
Point middle of Right Square              Square (right)                            0FFFFF212  0FFFFF212  false
Point middle of Right Square              Square overlapping left and right square  0FFFFF212  0FFFFF212  false
Square (left)                             Empty GeometryCollection                  FF2FF1FF2  FF2FF1FF2  false
Square (left)                             Empty LineString                          FF2FF1FF2  FF2FF1FF2  false
Square (left)                             Empty Point                               FF2FF1FF2  FF2FF1FF2  false
Square (left)                             Faraway point                             FF2FF10F2  FF2FF10F2  false
Square (left)                             Line going through left and right square  1020F1102  1F20F01F2  false
Square (left)                             NULL                                      NULL       NULL       NULL
Square (left)                             Nested Geometry Collection                FF20F1FF2  FF20F1FF2  false
Square (left)                             Point middle of Left Square               0F2FF1FF2  0F2FF1FF2  true
Square (left)                             Point middle of Right Square              FF2FF10F2  FF2FF10F2  false
Square (left)                             Square (left)                             2FFF1FFF2  2FFF0FFF2  false
Square (left)                             Square (right)                            FF2F11212  1F2F002F2  false
Square (left)                             Square overlapping left and right square  212111212  2F2F002F2  false
Square (right)                            Empty GeometryCollection                  FF2FF1FF2  FF2FF1FF2  false
Square (right)                            Empty LineString                          FF2FF1FF2  FF2FF1FF2  false
Square (right)                            Empty Point                               FF2FF1FF2  FF2FF1FF2  false
Square (right)                            Faraway point                             FF2FF10F2  FF2FF10F2  false
Square (right)                            Line going through left and right square  1020F1102  1F20F01F2  false
Square (right)                            NULL                                      NULL       NULL       NULL
Square (right)                            Nested Geometry Collection                FF20F1FF2  FF20F1FF2  false
Square (right)                            Point middle of Left Square               FF2FF10F2  FF2FF10F2  false
Square (right)                            Point middle of Right Square              0F2FF1FF2  0F2FF1FF2  true
Square (right)                            Square (left)                             FF2F11212  1F2F0F202  false
Square (right)                            Square (right)                            2FFF1FFF2  2FFF0FFF2  false
Square (right)                            Square overlapping left and right square  2FF11F212  2FFF0F202  false
Square overlapping left and right square  Empty GeometryCollection                  FF2FF1FF2  FF2FF1FF2  false
Square overlapping left and right square  Empty LineString                          FF2FF1FF2  FF2FF1FF2  false
Square overlapping left and right square  Empty Point                               FF2FF1FF2  FF2FF1FF2  false
Square overlapping left and right square  Faraway point                             FF2FF10F2  FF2FF10F2  false
Square overlapping left and right square  Line going through left and right square  1020F1102  1F20F01F2  false
Square overlapping left and right square  NULL                                      NULL       NULL       NULL
Square overlapping left and right square  Nested Geometry Collection                FF20F1FF2  FF20F1FF2  false
Square overlapping left and right square  Point middle of Left Square               FF2FF10F2  FF2FF10F2  false
Square overlapping left and right square  Point middle of Right Square              0F2FF1FF2  0F2FF1FF2  true
Square overlapping left and right square  Square (left)                             212111212  2F2F0F202  false
Square overlapping left and right square  Square (right)                            212F11FF2  2F2F00FF2  false
Square overlapping left and right square  Square overlapping left and right square  2FFF1FFF2  2FFF0FFF2  false

# ST_Envelope
query TTT
SELECT
  a.dsc,
  ST_AsEWKT(ST_Envelope(a.geom)),
  ST_AsEWKT(ST_Envelope(a.geom::box2d))
FROM geom_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                      NULL
Empty LineString                          LINESTRING EMPTY                              NULL
Empty Point                               POINT EMPTY                                   NULL
Faraway point                             POINT (5 5)                                   POINT (5 5)
Line going through left and right square  LINESTRING (-0.5 0.5, 0.5 0.5)                LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                      NULL                                          NULL
Nested Geometry Collection                POINT (0 0)                                   POINT (0 0)
Point middle of Left Square               POINT (-0.5 0.5)                              POINT (-0.5 0.5)
Point middle of Right Square              POINT (0.5 0.5)                               POINT (0.5 0.5)
Square (left)                             POLYGON ((-1 0, -1 1, 0 1, 0 0, -1 0))        POLYGON ((-1 0, -1 1, 0 1, 0 0, -1 0))
Square (right)                            POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))           POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))
Square overlapping left and right square  POLYGON ((-0.1 0, -0.1 1, 1 1, 1 0, -0.1 0))  POLYGON ((-0.1 0, -0.1 1, 1 1, 1 0, -0.1 0))

# basic metadata
query TTTIIIIIB colnames
SELECT
  a.dsc,
  GeometryType(a.geom),
  ST_GeometryType(a.geom),
  ST_NDims(a.geom),
  ST_CoordDim(a.geom),
  ST_Dimension(a.geom),
  ST_NPoints(a.geom),
  ST_NumGeometries(a.geom),
  ST_HasArc(a.geom)
FROM geom_operators_test a
ORDER BY a.dsc
----
dsc                                       geometrytype        st_geometrytype        st_ndims  st_coorddim  st_dimension  st_npoints  st_numgeometries  st_hasarc
Empty GeometryCollection                  GeometryCollection  ST_GeometryCollection  2         2            0             0           0                 false
Empty LineString                          LineString          ST_LineString          2         2            1             0           0                 false
Empty Point                               Point               ST_Point               2         2            0             0           0                 false
Faraway point                             Point               ST_Point               2         2            0             1           1                 false
Line going through left and right square  LineString          ST_LineString          2         2            1             2           1                 false
NULL                                      NULL                NULL                   NULL      NULL         NULL          NULL        NULL              NULL
Nested Geometry Collection                GeometryCollection  ST_GeometryCollection  2         2            0             1           1                 false
Point middle of Left Square               Point               ST_Point               2         2            0             1           1                 false
Point middle of Right Square              Point               ST_Point               2         2            0             1           1                 false
Square (left)                             Polygon             ST_Polygon             2         2            2             5           1                 false
Square (right)                            Polygon             ST_Polygon             2         2            2             5           1                 false
Square overlapping left and right square  Polygon             ST_Polygon             2         2            2             5           1                 false

query TT
SELECT
  dsc,
  ST_AsEWKT(ST_Points(geom))
FROM geom_operators_test
ORDER BY dsc
----
Empty GeometryCollection                  MULTIPOINT EMPTY
Empty LineString                          MULTIPOINT EMPTY
Empty Point                               MULTIPOINT EMPTY
Faraway point                             MULTIPOINT (5 5)
Line going through left and right square  MULTIPOINT (-0.5 0.5, 0.5 0.5)
NULL                                      NULL
Nested Geometry Collection                MULTIPOINT (0 0)
Point middle of Left Square               MULTIPOINT (-0.5 0.5)
Point middle of Right Square              MULTIPOINT (0.5 0.5)
Square (left)                             MULTIPOINT (-1 0, 0 0, 0 1, -1 1, -1 0)
Square (right)                            MULTIPOINT (0 0, 1 0, 1 1, 0 1, 0 0)
Square overlapping left and right square  MULTIPOINT (-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)

query TTTT
SELECT
  a.dsc,
  ST_AsEWKT(ST_GeometryN(a.geom, 0)),
  ST_AsEWKT(ST_GeometryN(a.geom, 1)),
  ST_AsEWKT(ST_GeometryN(a.geom, 2))
FROM geom_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  NULL  NULL                                          NULL
Empty LineString                          NULL  LINESTRING EMPTY                              NULL
Empty Point                               NULL  POINT EMPTY                                   NULL
Faraway point                             NULL  POINT (5 5)                                   NULL
Line going through left and right square  NULL  LINESTRING (-0.5 0.5, 0.5 0.5)                NULL
NULL                                      NULL  NULL                                          NULL
Nested Geometry Collection                NULL  GEOMETRYCOLLECTION (POINT (0 0))              NULL
Point middle of Left Square               NULL  POINT (-0.5 0.5)                              NULL
Point middle of Right Square              NULL  POINT (0.5 0.5)                               NULL
Square (left)                             NULL  POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))        NULL
Square (right)                            NULL  POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))           NULL
Square overlapping left and right square  NULL  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))  NULL

# Point specific operations
query RR nosort
SELECT
  st_x(a.geom),
  st_y(a.geom)
FROM (VALUES
  ('POINT(1.0 2.0)'::geometry),
  ('POINT(33.0 66.0)'::geometry),
  ('POINT EMPTY'::geometry)
) a(geom)
----
1     2
33    66
NULL  NULL

# ST_XMin, ST_XMax, ST_YMin, ST_YMax on point geometries
query RR nosort
SELECT
  st_xmin(a.geom),
  st_ymin(a.geom)
FROM (VALUES
  ('POINT(1.0 2.0)'::geometry),
  ('POINT(33.0 66.0)'::geometry),
  ('POINT EMPTY'::geometry)
) a(geom)
----
1     2
33    66
NULL  NULL

query RR nosort
SELECT
  st_xmax(a.geom),
  st_ymax(a.geom)
FROM (VALUES
  ('POINT(1.0 2.0)'::geometry),
  ('POINT(33.0 66.0)'::geometry),
  ('POINT EMPTY'::geometry)
) a(geom)
----
1     2
33    66
NULL  NULL

statement error argument to st_x\(\) must have shape POINT
SELECT st_x('LINESTRING(0.0 0.0, 1.0 1.0)')

statement error argument to st_y\(\) must have shape POINT
SELECT st_y('LINESTRING(0.0 0.0, 1.0 1.0)')

# LineString specific operations
query TTITTTTT nosort
SELECT
  ST_AsEWKT(ST_StartPoint(a.geom)),
  ST_AsEWKT(ST_EndPoint(a.geom)),
  ST_NumPoints(a.geom),
  ST_AsEWKT(ST_PointN(a.geom, 0)),
  ST_AsEWKT(ST_PointN(a.geom, 1)),
  ST_AsEWKT(ST_PointN(a.geom, 2)),
  ST_AsEWKT(ST_PointN(a.geom, 3)),
  ST_AsEWKT(ST_PointN(a.geom, 4))
FROM (VALUES
  ('LINESTRING EMPTY'::geometry),
  ('LINESTRING (0.0 0.0, 1.0 1.0, 2.0 2.0)'::geometry),
  ('SRID=4326;LINESTRING (0.0 0.0, 1.0 1.0, 2.0 2.0)'::geometry),
  ('MULTILINESTRING ((0.0 0.0, 1.0 1.0, 2.0 2.0), (3.0 3.0, 4.0 4.0))'::geometry)
) a(geom)
----
NULL                   NULL                   0     NULL  NULL                   NULL                   NULL                   NULL
POINT (0 0)            POINT (2 2)            3     NULL  POINT (0 0)            POINT (1 1)            POINT (2 2)            NULL
SRID=4326;POINT (0 0)  SRID=4326;POINT (2 2)  3     NULL  SRID=4326;POINT (0 0)  SRID=4326;POINT (1 1)  SRID=4326;POINT (2 2)  NULL
NULL                   NULL                   NULL  NULL  NULL                   NULL                   NULL                   NULL

# Polygon specific operations
query IIITTTT nosort
SELECT
  ST_NRings(a.geom),
  ST_NumInteriorRing(a.geom),
  ST_NumInteriorRings(a.geom),
  ST_AsEWKT(ST_ExteriorRing(a.geom)),
  ST_AsEWKT(ST_InteriorRingN(a.geom, 0)),
  ST_AsEWKT(ST_InteriorRingN(a.geom, 1)),
  ST_AsEWKT(ST_InteriorRingN(a.geom, 2))
FROM (VALUES
  ('POLYGON EMPTY'::geometry),
  ('POLYGON((0 0,1 0, 1 1, 0 0))'::geometry),
  ('POLYGON((0 0,1 0, 1 1, 0 0),(0.1 0.1,0.9 0.1, 0.9 0.9, 0.1 0.1))'::geometry),
  ('SRID=4326;POLYGON((0 0,1 0, 1 1, 0 0),(0.1 0.1,0.9 0.1, 0.9 0.9, 0.1 0.1))'::geometry),
  ('LINESTRING EMPTY'::geometry)
) a(geom)
----
0  0     0     LINESTRING EMPTY                           NULL  NULL                                                       NULL
1  0     0     LINESTRING (0 0, 1 0, 1 1, 0 0)            NULL  NULL                                                       NULL
2  1     1     LINESTRING (0 0, 1 0, 1 1, 0 0)            NULL  LINESTRING (0.1 0.1, 0.9 0.1, 0.9 0.9, 0.1 0.1)            NULL
2  1     1     SRID=4326;LINESTRING (0 0, 1 0, 1 1, 0 0)  NULL  SRID=4326;LINESTRING (0.1 0.1, 0.9 0.1, 0.9 0.9, 0.1 0.1)  NULL
0  NULL  NULL  NULL                                       NULL  NULL                                                       NULL

# ST_XMin, ST_XMax, ST_YMin, ST_YMax on polygon and linestring geometries
query RRRR nosort
SELECT
  ST_xmin(a.geom),
  ST_xmax(a.geom),
  ST_ymin(a.geom),
  ST_ymax(a.geom)
FROM (VALUES
  ('POLYGON EMPTY'::geometry),
  ('POLYGON((0 0,1 0, 1 1, 0 0))'::geometry),
  ('POLYGON((0 0,2 0, 2 2, 0 0),(0.1 0.1,0.9 0.1, 0.9 0.9, 0.1 0.1))'::geometry),
  ('SRID=4326;POLYGON((0 0,1 0, 1 1, 0 0),(0.1 0.1,0.9 0.1, 0.9 0.9, 0.1 0.1))'::geometry),
  ('LINESTRING EMPTY'::geometry)
) a(geom)
----
NULL  NULL  NULL  NULL
0     1     0     1
0     2     0     2
0     1     0     1
NULL  NULL  NULL  NULL

statement error argument must be LINESTRING geometries
SELECT ST_MakePolygon('MULTIPOINT(0 0, 1 1)')

statement error unknown signature: st_makepolygon\(string\)
SELECT ST_MakePolygon('abc')

statement error polygon shell must not be empty
SELECT ST_MakePolygon('LINESTRING EMPTY'::geometry)

statement error Polygon LinearRing must have at least 4 points, found 0 at position 2
SELECT ST_MakePolygon('LINESTRING (0 0, 1 0, 1 1, 0 0)'::geometry, ARRAY['LINESTRING EMPTY'::geometry])

statement error mixed dimension rings
SELECT ST_AsEWKT(ST_MakePolygon(
      ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)', 4326),
      ARRAY[
        ST_GeomFromText('LINESTRING(50 70 40, 70 70 40, 70 50 40, 50 50 40, 50 70 40)', 4326)
      ]))

statement error argument must be LINESTRING geometries
SELECT ST_MakePolygon(
    ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)'),
    ARRAY[
      ST_GeomFromText('MULTIPOINT(50 70, 70 70, 70 50, 50 50, 50 70)')
    ])

statement error argument must be LINESTRING geometries
SELECT ST_MakePolygon(
    ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)'),
    ARRAY[
      'MULTIPOINT(50 70, 70 70, 70 50, 50 50, 50 70)'
    ])

statement error argument must be LINESTRING geometries
SELECT ST_MakePolygon(
    ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)'),
    ARRAY['abc'])

# SRID set on shell but not interior rings
statement error mixed SRIDs are not allowed
SELECT ST_MakePolygon(
    ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)', 4326),
    ARRAY[
      ST_GeomFromText('LINESTRING(50 70, 70 70, 70 50, 50 50, 50 70)')
    ])

# SRIDs on shell and interior ring are unmatched
statement error mixed SRIDs are not allowed
SELECT ST_MakePolygon(
    ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)', 4326),
    ARRAY[
      ST_GeomFromText('LINESTRING(50 70, 70 70, 70 50, 50 50, 50 70)', 3857)
    ])

# SRIDs on interior rings are unmatched
statement error mixed SRIDs are not allowed
SELECT ST_MakePolygon(
    ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)', 4326),
    ARRAY[
      ST_GeomFromText('LINESTRING(50 70, 70 70, 70 50, 50 50, 50 70)', 4326),
      ST_GeomFromText('LINESTRING(60 60, 75 60, 75 45, 60 45, 60 60)', 3857)
    ])

statement error Polygon LinearRing at position 1 is not closed
SELECT ST_MakePolygon(ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 70)'))

statement error Polygon LinearRing must have at least 4 points, found 3 at position 1
SELECT ST_MakePolygon(ST_GeomFromText('LINESTRING(40 80, 80 80, 40 80)'))

statement error Polygon LinearRing at position 2 is not closed
SELECT ST_MakePolygon(
    ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)'),
    ARRAY[
      ST_GeomFromText('LINESTRING(50 70, 70 70, 70 50, 50 50, 50 60)')
    ])

statement error Polygon LinearRing must have at least 4 points, found 3 at position 2
SELECT ST_MakePolygon(
    ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)'),
    ARRAY[
      ST_GeomFromText('LINESTRING(50 70, 70 70, 50 70)')
    ])

query T
SELECT ST_AsEWKT(ST_MakePolygon( ST_GeomFromText('LINESTRING(75 29,77 29,77 29, 75 29)')))
----
POLYGON ((75 29, 77 29, 77 29, 75 29))

query T
SELECT ST_AsEWKT(ST_MakePolygon( ST_GeomFromText('LINESTRING(75 29,77 29,77 29, 75 29)', 4326)))
----
SRID=4326;POLYGON ((75 29, 77 29, 77 29, 75 29))

query T
SELECT ST_AsEWKT(ST_MakePolygon(
      ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)'),
      ARRAY[
        ST_GeomFromText('LINESTRING(50 70, 70 70, 70 50, 50 50, 50 70)')
      ]))
----
POLYGON ((40 80, 80 80, 80 40, 40 40, 40 80), (50 70, 70 70, 70 50, 50 50, 50 70))

query T
SELECT ST_AsEWKT(ST_MakePolygon(
      ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)'),
      ARRAY[
        ST_GeomFromText('LINESTRING(50 70, 70 70, 70 50, 50 50, 50 70)'),
        ST_GeomFromText('LINESTRING(60 60, 75 60, 75 45, 60 45, 60 60)')
      ]))
----
POLYGON ((40 80, 80 80, 80 40, 40 40, 40 80), (50 70, 70 70, 70 50, 50 50, 50 70), (60 60, 75 60, 75 45, 60 45, 60 60))

query T
SELECT ST_AsEWKT(ST_MakePolygon(
      ST_GeomFromText('LINESTRING(40 80, 80 80, 80 40, 40 40, 40 80)', 4326),
      ARRAY[
        ST_GeomFromText('LINESTRING(50 70, 70 70, 70 50, 50 50, 50 70)', 4326)
      ]))
----
SRID=4326;POLYGON ((40 80, 80 80, 80 40, 40 40, 40 80), (50 70, 70 70, 70 50, 50 50, 50 70))

query T
SELECT ST_AsEWKT(ST_Polygon( ST_GeomFromText('LINESTRING(75 29,77 29,77 29, 75 29)'), 4326))
----
SRID=4326;POLYGON ((75 29, 77 29, 77 29, 75 29))

# Multi-Geometry related operations.
query ITTT nosort
SELECT
  ST_NumGeometries(a.geom),
  ST_AsEWKT(ST_GeometryN(a.geom, 0)),
  ST_AsEWKT(ST_GeometryN(a.geom, 1)),
  ST_AsEWKT(ST_GeometryN(a.geom, 2))
FROM (VALUES
  ('MULTIPOINT EMPTY'::geometry),
  ('MULTILINESTRING EMPTY'::geometry),
  ('MULTIPOLYGON EMPTY'::geometry),
  ('MULTIPOINT((0 0), (1 1), (2 2))'::geometry),
  ('SRID=4326;MULTIPOINT((0 0), (1 1), (2 2))'::geometry),
  ('MULTILINESTRING((0 0, 1 1), (2 2, 3 3))'::geometry),
  ('SRID=4326;MULTILINESTRING((0 0, 1 1), (2 2, 3 3))'::geometry),
  ('MULTIPOLYGON(((0 0,1 0, 1 1, 0 0)),((0.1 0.1,0.9 0.1, 0.9 0.9, 0.1 0.1)))'::geometry),
  ('SRID=4326;MULTIPOLYGON(((0 0,1 0, 1 1, 0 0)),((0.1 0.1,0.9 0.1, 0.9 0.9, 0.1 0.1)))'::geometry),
  ('GEOMETRYCOLLECTION (POINT (40 10),LINESTRING (10 10, 20 20, 10 40),POLYGON ((40 40, 20 45, 45 30, 40 40)))'::geometry),
  ('SRID=4326;GEOMETRYCOLLECTION (POINT (40 10),LINESTRING (10 10, 20 20, 10 40),POLYGON ((40 40, 20 45, 45 30, 40 40)))'::geometry)
) a(geom)
----
0  NULL  NULL                                      NULL
0  NULL  NULL                                      NULL
0  NULL  NULL                                      NULL
3  NULL  POINT (0 0)                               POINT (1 1)
3  NULL  SRID=4326;POINT (0 0)                     SRID=4326;POINT (1 1)
2  NULL  LINESTRING (0 0, 1 1)                     LINESTRING (2 2, 3 3)
2  NULL  SRID=4326;LINESTRING (0 0, 1 1)           SRID=4326;LINESTRING (2 2, 3 3)
2  NULL  POLYGON ((0 0, 1 0, 1 1, 0 0))            POLYGON ((0.1 0.1, 0.9 0.1, 0.9 0.9, 0.1 0.1))
2  NULL  SRID=4326;POLYGON ((0 0, 1 0, 1 1, 0 0))  SRID=4326;POLYGON ((0.1 0.1, 0.9 0.1, 0.9 0.9, 0.1 0.1))
3  NULL  POINT (40 10)                             LINESTRING (10 10, 20 20, 10 40)
3  NULL  SRID=4326;POINT (40 10)                   SRID=4326;LINESTRING (10 10, 20 20, 10 40)

statement ok
CREATE TABLE geom_linear (
  dsc  TEXT PRIMARY KEY,
  geom GEOMETRY
)

statement ok
INSERT INTO geom_linear VALUES
  ('Empty LineString', 'LINESTRING EMPTY'),
  ('LineString anticlockwise covering all the quadrants', 'LINESTRING(1 -1, 2 2, -2 2, -1 -1)'),
  ('LineString clockwise covering all the quadrants with SRID 4004', 'SRID=4004;LINESTRING(1 -1, -1 -1, -2 2, 2 2)')

# ST_LineInterpolatePoint, ST_LineInterpolatePoints
query TRBTTT
SELECT
  a.dsc,
  b.fraction,
  c.repeat,
  ST_AsEWKT(ST_LineInterpolatePoint(a.geom, b.fraction::float)),
  ST_AsEWKT(ST_LineInterpolatePoints(a.geom, b.fraction::float)),
  ST_AsEWKT(ST_LineInterPolatePoints(a.geom, b.fraction::float, c.repeat))
FROM geom_linear a
JOIN (VALUES (0.0), (0.2), (0.5), (0.51), (1.0)) b(fraction) ON (1=1)
JOIN (VALUES (true), (false)) c(repeat) ON (1=1)
ORDER BY a.dsc, b.fraction, c.repeat
----
Empty LineString                                                0.0   false  POINT EMPTY                                             POINT EMPTY                                                                                                                             POINT EMPTY
Empty LineString                                                0.0   true   POINT EMPTY                                             POINT EMPTY                                                                                                                             POINT EMPTY
Empty LineString                                                0.2   false  POINT EMPTY                                             MULTIPOINT (EMPTY, EMPTY, EMPTY, EMPTY, EMPTY)                                                                                          POINT EMPTY
Empty LineString                                                0.2   true   POINT EMPTY                                             MULTIPOINT (EMPTY, EMPTY, EMPTY, EMPTY, EMPTY)                                                                                          MULTIPOINT (EMPTY, EMPTY, EMPTY, EMPTY, EMPTY)
Empty LineString                                                0.5   false  POINT EMPTY                                             MULTIPOINT (EMPTY, EMPTY)                                                                                                               POINT EMPTY
Empty LineString                                                0.5   true   POINT EMPTY                                             MULTIPOINT (EMPTY, EMPTY)                                                                                                               MULTIPOINT (EMPTY, EMPTY)
Empty LineString                                                0.51  false  POINT EMPTY                                             POINT EMPTY                                                                                                                             POINT EMPTY
Empty LineString                                                0.51  true   POINT EMPTY                                             POINT EMPTY                                                                                                                             POINT EMPTY
Empty LineString                                                1.0   false  POINT EMPTY                                             POINT EMPTY                                                                                                                             POINT EMPTY
Empty LineString                                                1.0   true   POINT EMPTY                                             POINT EMPTY                                                                                                                             POINT EMPTY
LineString anticlockwise covering all the quadrants             0.0   false  POINT (1 -1)                                            POINT (1 -1)                                                                                                                            POINT (1 -1)
LineString anticlockwise covering all the quadrants             0.0   true   POINT (1 -1)                                            POINT (1 -1)                                                                                                                            POINT (1 -1)
LineString anticlockwise covering all the quadrants             0.2   false  POINT (1.652982212813471 0.958946638440411)             MULTIPOINT (1.652982212813471 0.958946638440411, 1.032455532033675 2, -1.032455532033678 2, -1.65298221281347 0.95894663844041, -1 -1)  POINT (1.652982212813471 0.958946638440411)
LineString anticlockwise covering all the quadrants             0.2   true   POINT (1.652982212813471 0.958946638440411)             MULTIPOINT (1.652982212813471 0.958946638440411, 1.032455532033675 2, -1.032455532033678 2, -1.65298221281347 0.95894663844041, -1 -1)  MULTIPOINT (1.652982212813471 0.958946638440411, 1.032455532033675 2, -1.032455532033678 2, -1.65298221281347 0.95894663844041, -1 -1)
LineString anticlockwise covering all the quadrants             0.5   false  POINT (-0 2)                                            MULTIPOINT (-0 2, -1 -1)                                                                                                                POINT (-0 2)
LineString anticlockwise covering all the quadrants             0.5   true   POINT (-0 2)                                            MULTIPOINT (-0 2, -1 -1)                                                                                                                MULTIPOINT (-0 2, -1 -1)
LineString anticlockwise covering all the quadrants             0.51  false  POINT (-0.103245553203368 2)                            POINT (-0.103245553203368 2)                                                                                                            POINT (-0.103245553203368 2)
LineString anticlockwise covering all the quadrants             0.51  true   POINT (-0.103245553203368 2)                            POINT (-0.103245553203368 2)                                                                                                            POINT (-0.103245553203368 2)
LineString anticlockwise covering all the quadrants             1.0   false  POINT (-1 -1)                                           POINT (-1 -1)                                                                                                                           POINT (-1 -1)
LineString anticlockwise covering all the quadrants             1.0   true   POINT (-1 -1)                                           POINT (-1 -1)                                                                                                                           POINT (-1 -1)
LineString clockwise covering all the quadrants with SRID 4004  0.0   false  SRID=4004;POINT (1 -1)                                  SRID=4004;POINT (1 -1)                                                                                                                  SRID=4004;POINT (1 -1)
LineString clockwise covering all the quadrants with SRID 4004  0.0   true   SRID=4004;POINT (1 -1)                                  SRID=4004;POINT (1 -1)                                                                                                                  SRID=4004;POINT (1 -1)
LineString clockwise covering all the quadrants with SRID 4004  0.2   false  SRID=4004;POINT (-0.832455532033676 -1)                 SRID=4004;MULTIPOINT (-0.832455532033676 -1, -1.526491106406735 0.579473319220206, -1.664911064067351 2, 0.167544467966325 2, 2 2)      SRID=4004;POINT (-0.832455532033676 -1)
LineString clockwise covering all the quadrants with SRID 4004  0.2   true   SRID=4004;POINT (-0.832455532033676 -1)                 SRID=4004;MULTIPOINT (-0.832455532033676 -1, -1.526491106406735 0.579473319220206, -1.664911064067351 2, 0.167544467966325 2, 2 2)      SRID=4004;MULTIPOINT (-0.832455532033676 -1, -1.526491106406735 0.579473319220206, -1.664911064067351 2, 0.167544467966325 2, 2 2)
LineString clockwise covering all the quadrants with SRID 4004  0.5   false  SRID=4004;POINT (-1.816227766016838 1.448683298050514)  SRID=4004;MULTIPOINT (-1.816227766016838 1.448683298050514, 2 2)                                                                        SRID=4004;POINT (-1.816227766016838 1.448683298050514)
LineString clockwise covering all the quadrants with SRID 4004  0.5   true   SRID=4004;POINT (-1.816227766016838 1.448683298050514)  SRID=4004;MULTIPOINT (-1.816227766016838 1.448683298050514, 2 2)                                                                        SRID=4004;MULTIPOINT (-1.816227766016838 1.448683298050514, 2 2)
LineString clockwise covering all the quadrants with SRID 4004  0.51  false  SRID=4004;POINT (-1.845201431977848 1.535604295933545)  SRID=4004;POINT (-1.845201431977848 1.535604295933545)                                                                                  SRID=4004;POINT (-1.845201431977848 1.535604295933545)
LineString clockwise covering all the quadrants with SRID 4004  0.51  true   SRID=4004;POINT (-1.845201431977848 1.535604295933545)  SRID=4004;POINT (-1.845201431977848 1.535604295933545)                                                                                  SRID=4004;POINT (-1.845201431977848 1.535604295933545)
LineString clockwise covering all the quadrants with SRID 4004  1.0   false  SRID=4004;POINT (2 2)                                   SRID=4004;POINT (2 2)                                                                                                                   SRID=4004;POINT (2 2)
LineString clockwise covering all the quadrants with SRID 4004  1.0   true   SRID=4004;POINT (2 2)                                   SRID=4004;POINT (2 2)                                                                                                                   SRID=4004;POINT (2 2)

statement error st_lineinterpolatepoint\(\): fraction -1.000000 should be within \[0 1\] range
SELECT ST_LineInterpolatePoint('LINESTRING (0 0, 1 1)'::geometry, -1)

statement error st_lineinterpolatepoints\(\): fraction -1.000000 should be within \[0 1\] range
SELECT ST_LineInterpolatePoints('LINESTRING (0 0, 1 1)'::geometry, -1, false)

statement error st_lineinterpolatepoint\(\): geometry MultiLineString should be LineString
SELECT ST_LineInterpolatePoint('MULTILINESTRING ((0 0, 1 1), (1 1, 0 0))'::geometry, 0.2)

statement error st_lineinterpolatepoints\(\): geometry MultiLineString should be LineString
SELECT ST_LineInterpolatePoints('MULTILINESTRING ((0 0, 1 1), (1 1, 0 0))'::geometry, 0.2, false)

statement error st_lineinterpolatepoint\(\): geometry Point should be LineString
SELECT ST_LineInterpolatePoint('POINT (0 0)'::geometry, 0.2)

statement error st_lineinterpolatepoints\(\): geometry Point should be LineString
SELECT ST_LineInterpolatePoints('POINT (0 0)'::geometry, 0.2, false)

statement error st_lineinterpolatepoint\(\): geometry Polygon should be LineString
SELECT ST_LineInterpolatePoint('POLYGON((-1.0 0.0, 0.0 0.0, 0.0 1.0, -1.0 1.0, -1.0 0.0))'::geometry, 0.2)

statement error st_lineinterpolatepoints\(\): geometry Polygon should be LineString
SELECT ST_LineInterpolatePoints('POLYGON((-1.0 0.0, 0.0 0.0, 0.0 1.0, -1.0 1.0, -1.0 0.0))'::geometry, 0.2, false)

subtest geog_operators

statement ok
CREATE TABLE geog_operators_test AS SELECT dsc, geom::geography AS geog FROM geom_operators_test

# GROUP BY
query TR
SELECT
  a.dsc,
  round(ST_Area(a.geog), 2)
FROM geog_operators_test a
GROUP BY a.dsc, a.geog
ORDER BY a.dsc
----
Empty GeometryCollection                  0
Empty LineString                          0
Empty Point                               0
Faraway point                             0
Line going through left and right square  0
NULL                                      NULL
Nested Geometry Collection                0
Point middle of Left Square               0
Point middle of Right Square              0
Square (left)                             1.230877836147e+10
Square (right)                            1.230877836147e+10
Square overlapping left and right square  1.35397288423e+10

# Unary operators
query TRRRRRRRRR
SELECT
  a.dsc,
  round(ST_Area(a.geog), 4), round(ST_Area(a.geog, false), 4), round(ST_Area(a.geog, true), 4),
  round(ST_Length(a.geog), 4), round(ST_Length(a.geog, false), 4), round(ST_Length(a.geog, true), 4),
  round(ST_Perimeter(a.geog), 4), round(ST_Perimeter(a.geog, false), 4), round(ST_Perimeter(a.geog, true), 4)
FROM geog_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  0                     0                     0                     0            0            0            0            0            0
Empty LineString                          0                     0                     0                     0            0            0            0            0            0
Empty Point                               0                     0                     0                     0            0            0            0            0            0
Faraway point                             0                     0                     0                     0            0            0            0            0            0
Line going through left and right square  0                     0                     0                     111315.2804  111190.8457  111315.2804  0            0            0
NULL                                      NULL                  NULL                  NULL                  NULL         NULL         NULL         NULL         NULL         NULL
Nested Geometry Collection                0                     0                     0                     0            0            0            0            0            0
Point middle of Left Square               0                     0                     0                     0            0            0            0            0            0
Point middle of Right Square              0                     0                     0                     0            0            0            0            0            0
Square (left)                             1.23087783614695e+10  1.23640317985177e+10  1.23087783614695e+10  0            0            0            443770.9172  444763.383   443770.9172
Square (right)                            1.23087783614695e+10  1.23640317985177e+10  1.23087783614695e+10  0            0            0            443770.9172  444763.383   443770.9172
Square overlapping left and right square  1.35397288423019e+10  1.36005074605892e+10  1.35397288423019e+10  0            0            0            466033.1312  467000.7052  466033.1312

query TTTB
SELECT
  a.dsc,
  ST_AsEWKT(a.geom),
  ST_AsEWKT(ST_Normalize(a.geom)),
  ST_AsEWKT(a.geom) = ST_AsEWKT(ST_Normalize(a.geom))
FROM geom_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY                               true
Empty LineString                          LINESTRING EMPTY                                       LINESTRING EMPTY                                       true
Empty Point                               POINT EMPTY                                            POINT EMPTY                                            true
Faraway point                             POINT (5 5)                                            POINT (5 5)                                            true
Line going through left and right square  LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (-0.5 0.5, 0.5 0.5)                         true
NULL                                      NULL                                                   NULL                                                   NULL
Nested Geometry Collection                GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  true
Point middle of Left Square               POINT (-0.5 0.5)                                       POINT (-0.5 0.5)                                       true
Point middle of Right Square              POINT (0.5 0.5)                                        POINT (0.5 0.5)                                        true
Square (left)                             POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((-1 0, -1 1, 0 1, 0 0, -1 0))                 false
Square (right)                            POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))                    false
Square overlapping left and right square  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((-0.1 0, -0.1 1, 1 1, 1 0, -0.1 0))           false

# Binary operators
query TTRRR round-in-strings
SELECT
  a.dsc,
  b.dsc,
  ST_Distance(a.geog, b.geog), ST_Distance(a.geog, b.geog, false), ST_Distance(a.geog, b.geog, true)
FROM geog_operators_test a
JOIN geog_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  NULL     NULL     NULL
Empty GeometryCollection                  Empty LineString                          NULL     NULL     NULL
Empty GeometryCollection                  Empty Point                               NULL     NULL     NULL
Empty GeometryCollection                  Faraway point                             NULL     NULL     NULL
Empty GeometryCollection                  Line going through left and right square  NULL     NULL     NULL
Empty GeometryCollection                  NULL                                      NULL     NULL     NULL
Empty GeometryCollection                  Nested Geometry Collection                NULL     NULL     NULL
Empty GeometryCollection                  Point middle of Left Square               NULL     NULL     NULL
Empty GeometryCollection                  Point middle of Right Square              NULL     NULL     NULL
Empty GeometryCollection                  Square (left)                             NULL     NULL     NULL
Empty GeometryCollection                  Square (right)                            NULL     NULL     NULL
Empty GeometryCollection                  Square overlapping left and right square  NULL     NULL     NULL
Empty LineString                          Empty GeometryCollection                  NULL     NULL     NULL
Empty LineString                          Empty LineString                          NULL     NULL     NULL
Empty LineString                          Empty Point                               NULL     NULL     NULL
Empty LineString                          Faraway point                             NULL     NULL     NULL
Empty LineString                          Line going through left and right square  NULL     NULL     NULL
Empty LineString                          NULL                                      NULL     NULL     NULL
Empty LineString                          Nested Geometry Collection                NULL     NULL     NULL
Empty LineString                          Point middle of Left Square               NULL     NULL     NULL
Empty LineString                          Point middle of Right Square              NULL     NULL     NULL
Empty LineString                          Square (left)                             NULL     NULL     NULL
Empty LineString                          Square (right)                            NULL     NULL     NULL
Empty LineString                          Square overlapping left and right square  NULL     NULL     NULL
Empty Point                               Empty GeometryCollection                  NULL     NULL     NULL
Empty Point                               Empty LineString                          NULL     NULL     NULL
Empty Point                               Empty Point                               NULL     NULL     NULL
Empty Point                               Faraway point                             NULL     NULL     NULL
Empty Point                               Line going through left and right square  NULL     NULL     NULL
Empty Point                               NULL                                      NULL     NULL     NULL
Empty Point                               Nested Geometry Collection                NULL     NULL     NULL
Empty Point                               Point middle of Left Square               NULL     NULL     NULL
Empty Point                               Point middle of Right Square              NULL     NULL     NULL
Empty Point                               Square (left)                             NULL     NULL     NULL
Empty Point                               Square (right)                            NULL     NULL     NULL
Empty Point                               Square overlapping left and right square  NULL     NULL     NULL
Faraway point                             Empty GeometryCollection                  NULL     NULL     NULL
Faraway point                             Empty LineString                          NULL     NULL     NULL
Faraway point                             Empty Point                               NULL     NULL     NULL
Faraway point                             Faraway point                             0        0        0
Faraway point                             Line going through left and right square  705578   707142   705578
Faraway point                             NULL                                      NULL     NULL     NULL
Faraway point                             Nested Geometry Collection                784029   785768   784029
Faraway point                             Point middle of Left Square               788297   789522   788297
Faraway point                             Point middle of Right Square              705578   707142   705578
Faraway point                             Square (left)                             710261   711312   710261
Faraway point                             Square (right)                            627130   628519   627130
Faraway point                             Square overlapping left and right square  627130   628519   627130
Line going through left and right square  Empty GeometryCollection                  NULL     NULL     NULL
Line going through left and right square  Empty LineString                          NULL     NULL     NULL
Line going through left and right square  Empty Point                               NULL     NULL     NULL
Line going through left and right square  Faraway point                             705578   707142   705578
Line going through left and right square  Line going through left and right square  0        0        0
Line going through left and right square  NULL                                      NULL     NULL     NULL
Line going through left and right square  Nested Geometry Collection                55289.3  55599.7  55289.3
Line going through left and right square  Point middle of Left Square               0        0        0
Line going through left and right square  Point middle of Right Square              0        0        0
Line going through left and right square  Square (left)                             0        0        0
Line going through left and right square  Square (right)                            0        0        0
Line going through left and right square  Square overlapping left and right square  0        0        0
NULL                                      Empty GeometryCollection                  NULL     NULL     NULL
NULL                                      Empty LineString                          NULL     NULL     NULL
NULL                                      Empty Point                               NULL     NULL     NULL
NULL                                      Faraway point                             NULL     NULL     NULL
NULL                                      Line going through left and right square  NULL     NULL     NULL
NULL                                      NULL                                      NULL     NULL     NULL
NULL                                      Nested Geometry Collection                NULL     NULL     NULL
NULL                                      Point middle of Left Square               NULL     NULL     NULL
NULL                                      Point middle of Right Square              NULL     NULL     NULL
NULL                                      Square (left)                             NULL     NULL     NULL
NULL                                      Square (right)                            NULL     NULL     NULL
NULL                                      Square overlapping left and right square  NULL     NULL     NULL
Nested Geometry Collection                Empty GeometryCollection                  NULL     NULL     NULL
Nested Geometry Collection                Empty LineString                          NULL     NULL     NULL
Nested Geometry Collection                Empty Point                               NULL     NULL     NULL
Nested Geometry Collection                Faraway point                             784029   785768   784029
Nested Geometry Collection                Line going through left and right square  55289.3  55599.7  55289.3
Nested Geometry Collection                NULL                                      NULL     NULL     NULL
Nested Geometry Collection                Nested Geometry Collection                0        0        0
Nested Geometry Collection                Point middle of Left Square               78451.2  78626.3  78451.2
Nested Geometry Collection                Point middle of Right Square              78451.2  78626.3  78451.2
Nested Geometry Collection                Square (left)                             0        0        0
Nested Geometry Collection                Square (right)                            0        0        0
Nested Geometry Collection                Square overlapping left and right square  0        0        0
Point middle of Left Square               Empty GeometryCollection                  NULL     NULL     NULL
Point middle of Left Square               Empty LineString                          NULL     NULL     NULL
Point middle of Left Square               Empty Point                               NULL     NULL     NULL
Point middle of Left Square               Faraway point                             788297   789522   788297
Point middle of Left Square               Line going through left and right square  0        0        0
Point middle of Left Square               NULL                                      NULL     NULL     NULL
Point middle of Left Square               Nested Geometry Collection                78451.2  78626.3  78451.2
Point middle of Left Square               Point middle of Left Square               0        0        0
Point middle of Left Square               Point middle of Right Square              111315   111191   111315
Point middle of Left Square               Square (left)                             0        0        0
Point middle of Left Square               Square (right)                            55657.6  55595.4  55657.6
Point middle of Left Square               Square overlapping left and right square  44526.1  44476.3  44526.1
Point middle of Right Square              Empty GeometryCollection                  NULL     NULL     NULL
Point middle of Right Square              Empty LineString                          NULL     NULL     NULL
Point middle of Right Square              Empty Point                               NULL     NULL     NULL
Point middle of Right Square              Faraway point                             705578   707142   705578
Point middle of Right Square              Line going through left and right square  0        0        0
Point middle of Right Square              NULL                                      NULL     NULL     NULL
Point middle of Right Square              Nested Geometry Collection                78451.2  78626.3  78451.2
Point middle of Right Square              Point middle of Left Square               111315   111191   111315
Point middle of Right Square              Point middle of Right Square              0        0        0
Point middle of Right Square              Square (left)                             55657.6  55595.4  55657.6
Point middle of Right Square              Square (right)                            0        0        0
Point middle of Right Square              Square overlapping left and right square  0        0        0
Square (left)                             Empty GeometryCollection                  NULL     NULL     NULL
Square (left)                             Empty LineString                          NULL     NULL     NULL
Square (left)                             Empty Point                               NULL     NULL     NULL
Square (left)                             Faraway point                             710261   711312   710261
Square (left)                             Line going through left and right square  0        0        0
Square (left)                             NULL                                      NULL     NULL     NULL
Square (left)                             Nested Geometry Collection                0        0        0
Square (left)                             Point middle of Left Square               0        0        0
Square (left)                             Point middle of Right Square              55657.6  55595.4  55657.6
Square (left)                             Square (left)                             0        0        0
Square (left)                             Square (right)                            0        0        0
Square (left)                             Square overlapping left and right square  0        0        0
Square (right)                            Empty GeometryCollection                  NULL     NULL     NULL
Square (right)                            Empty LineString                          NULL     NULL     NULL
Square (right)                            Empty Point                               NULL     NULL     NULL
Square (right)                            Faraway point                             627130   628519   627130
Square (right)                            Line going through left and right square  0        0        0
Square (right)                            NULL                                      NULL     NULL     NULL
Square (right)                            Nested Geometry Collection                0        0        0
Square (right)                            Point middle of Left Square               55657.6  55595.4  55657.6
Square (right)                            Point middle of Right Square              0        0        0
Square (right)                            Square (left)                             0        0        0
Square (right)                            Square (right)                            0        0        0
Square (right)                            Square overlapping left and right square  0        0        0
Square overlapping left and right square  Empty GeometryCollection                  NULL     NULL     NULL
Square overlapping left and right square  Empty LineString                          NULL     NULL     NULL
Square overlapping left and right square  Empty Point                               NULL     NULL     NULL
Square overlapping left and right square  Faraway point                             627130   628519   627130
Square overlapping left and right square  Line going through left and right square  0        0        0
Square overlapping left and right square  NULL                                      NULL     NULL     NULL
Square overlapping left and right square  Nested Geometry Collection                0        0        0
Square overlapping left and right square  Point middle of Left Square               44526.1  44476.3  44526.1
Square overlapping left and right square  Point middle of Right Square              0        0        0
Square overlapping left and right square  Square (left)                             0        0        0
Square overlapping left and right square  Square (right)                            0        0        0
Square overlapping left and right square  Square overlapping left and right square  0        0        0

# Binary predicates
query TTBBB
SELECT
  a.dsc,
  b.dsc,
  ST_Covers(a.geog, b.geog),
  ST_CoveredBy(a.geog, b.geog),
  ST_Intersects(a.geog, b.geog)
FROM geog_operators_test a
JOIN geog_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  false  false  false
Empty GeometryCollection                  Empty LineString                          false  false  false
Empty GeometryCollection                  Empty Point                               false  false  false
Empty GeometryCollection                  Faraway point                             false  false  false
Empty GeometryCollection                  Line going through left and right square  false  false  false
Empty GeometryCollection                  NULL                                      NULL   NULL   NULL
Empty GeometryCollection                  Nested Geometry Collection                false  false  false
Empty GeometryCollection                  Point middle of Left Square               false  false  false
Empty GeometryCollection                  Point middle of Right Square              false  false  false
Empty GeometryCollection                  Square (left)                             false  false  false
Empty GeometryCollection                  Square (right)                            false  false  false
Empty GeometryCollection                  Square overlapping left and right square  false  false  false
Empty LineString                          Empty GeometryCollection                  false  false  false
Empty LineString                          Empty LineString                          false  false  false
Empty LineString                          Empty Point                               false  false  false
Empty LineString                          Faraway point                             false  false  false
Empty LineString                          Line going through left and right square  false  false  false
Empty LineString                          NULL                                      NULL   NULL   NULL
Empty LineString                          Nested Geometry Collection                false  false  false
Empty LineString                          Point middle of Left Square               false  false  false
Empty LineString                          Point middle of Right Square              false  false  false
Empty LineString                          Square (left)                             false  false  false
Empty LineString                          Square (right)                            false  false  false
Empty LineString                          Square overlapping left and right square  false  false  false
Empty Point                               Empty GeometryCollection                  false  false  false
Empty Point                               Empty LineString                          false  false  false
Empty Point                               Empty Point                               false  false  false
Empty Point                               Faraway point                             false  false  false
Empty Point                               Line going through left and right square  false  false  false
Empty Point                               NULL                                      NULL   NULL   NULL
Empty Point                               Nested Geometry Collection                false  false  false
Empty Point                               Point middle of Left Square               false  false  false
Empty Point                               Point middle of Right Square              false  false  false
Empty Point                               Square (left)                             false  false  false
Empty Point                               Square (right)                            false  false  false
Empty Point                               Square overlapping left and right square  false  false  false
Faraway point                             Empty GeometryCollection                  false  false  false
Faraway point                             Empty LineString                          false  false  false
Faraway point                             Empty Point                               false  false  false
Faraway point                             Faraway point                             true   true   true
Faraway point                             Line going through left and right square  false  false  false
Faraway point                             NULL                                      NULL   NULL   NULL
Faraway point                             Nested Geometry Collection                false  false  false
Faraway point                             Point middle of Left Square               false  false  false
Faraway point                             Point middle of Right Square              false  false  false
Faraway point                             Square (left)                             false  false  false
Faraway point                             Square (right)                            false  false  false
Faraway point                             Square overlapping left and right square  false  false  false
Line going through left and right square  Empty GeometryCollection                  false  false  false
Line going through left and right square  Empty LineString                          false  false  false
Line going through left and right square  Empty Point                               false  false  false
Line going through left and right square  Faraway point                             false  false  false
Line going through left and right square  Line going through left and right square  true   true   true
Line going through left and right square  NULL                                      NULL   NULL   NULL
Line going through left and right square  Nested Geometry Collection                false  false  false
Line going through left and right square  Point middle of Left Square               true   false  true
Line going through left and right square  Point middle of Right Square              true   false  true
Line going through left and right square  Square (left)                             false  false  true
Line going through left and right square  Square (right)                            false  false  true
Line going through left and right square  Square overlapping left and right square  false  false  true
NULL                                      Empty GeometryCollection                  NULL   NULL   NULL
NULL                                      Empty LineString                          NULL   NULL   NULL
NULL                                      Empty Point                               NULL   NULL   NULL
NULL                                      Faraway point                             NULL   NULL   NULL
NULL                                      Line going through left and right square  NULL   NULL   NULL
NULL                                      NULL                                      NULL   NULL   NULL
NULL                                      Nested Geometry Collection                NULL   NULL   NULL
NULL                                      Point middle of Left Square               NULL   NULL   NULL
NULL                                      Point middle of Right Square              NULL   NULL   NULL
NULL                                      Square (left)                             NULL   NULL   NULL
NULL                                      Square (right)                            NULL   NULL   NULL
NULL                                      Square overlapping left and right square  NULL   NULL   NULL
Nested Geometry Collection                Empty GeometryCollection                  false  false  false
Nested Geometry Collection                Empty LineString                          false  false  false
Nested Geometry Collection                Empty Point                               false  false  false
Nested Geometry Collection                Faraway point                             false  false  false
Nested Geometry Collection                Line going through left and right square  false  false  false
Nested Geometry Collection                NULL                                      NULL   NULL   NULL
Nested Geometry Collection                Nested Geometry Collection                true   true   true
Nested Geometry Collection                Point middle of Left Square               false  false  false
Nested Geometry Collection                Point middle of Right Square              false  false  false
Nested Geometry Collection                Square (left)                             false  true   true
Nested Geometry Collection                Square (right)                            false  true   true
Nested Geometry Collection                Square overlapping left and right square  false  true   true
Point middle of Left Square               Empty GeometryCollection                  false  false  false
Point middle of Left Square               Empty LineString                          false  false  false
Point middle of Left Square               Empty Point                               false  false  false
Point middle of Left Square               Faraway point                             false  false  false
Point middle of Left Square               Line going through left and right square  false  true   true
Point middle of Left Square               NULL                                      NULL   NULL   NULL
Point middle of Left Square               Nested Geometry Collection                false  false  false
Point middle of Left Square               Point middle of Left Square               true   true   true
Point middle of Left Square               Point middle of Right Square              false  false  false
Point middle of Left Square               Square (left)                             false  true   true
Point middle of Left Square               Square (right)                            false  false  false
Point middle of Left Square               Square overlapping left and right square  false  false  false
Point middle of Right Square              Empty GeometryCollection                  false  false  false
Point middle of Right Square              Empty LineString                          false  false  false
Point middle of Right Square              Empty Point                               false  false  false
Point middle of Right Square              Faraway point                             false  false  false
Point middle of Right Square              Line going through left and right square  false  true   true
Point middle of Right Square              NULL                                      NULL   NULL   NULL
Point middle of Right Square              Nested Geometry Collection                false  false  false
Point middle of Right Square              Point middle of Left Square               false  false  false
Point middle of Right Square              Point middle of Right Square              true   true   true
Point middle of Right Square              Square (left)                             false  false  false
Point middle of Right Square              Square (right)                            false  true   true
Point middle of Right Square              Square overlapping left and right square  false  true   true
Square (left)                             Empty GeometryCollection                  false  false  false
Square (left)                             Empty LineString                          false  false  false
Square (left)                             Empty Point                               false  false  false
Square (left)                             Faraway point                             false  false  false
Square (left)                             Line going through left and right square  false  false  true
Square (left)                             NULL                                      NULL   NULL   NULL
Square (left)                             Nested Geometry Collection                true   false  true
Square (left)                             Point middle of Left Square               true   false  true
Square (left)                             Point middle of Right Square              false  false  false
Square (left)                             Square (left)                             true   true   true
Square (left)                             Square (right)                            false  false  true
Square (left)                             Square overlapping left and right square  false  false  true
Square (right)                            Empty GeometryCollection                  false  false  false
Square (right)                            Empty LineString                          false  false  false
Square (right)                            Empty Point                               false  false  false
Square (right)                            Faraway point                             false  false  false
Square (right)                            Line going through left and right square  false  false  true
Square (right)                            NULL                                      NULL   NULL   NULL
Square (right)                            Nested Geometry Collection                true   false  true
Square (right)                            Point middle of Left Square               false  false  false
Square (right)                            Point middle of Right Square              true   false  true
Square (right)                            Square (left)                             false  false  true
Square (right)                            Square (right)                            true   true   true
Square (right)                            Square overlapping left and right square  false  false  true
Square overlapping left and right square  Empty GeometryCollection                  false  false  false
Square overlapping left and right square  Empty LineString                          false  false  false
Square overlapping left and right square  Empty Point                               false  false  false
Square overlapping left and right square  Faraway point                             false  false  false
Square overlapping left and right square  Line going through left and right square  false  false  true
Square overlapping left and right square  NULL                                      NULL   NULL   NULL
Square overlapping left and right square  Nested Geometry Collection                true   false  true
Square overlapping left and right square  Point middle of Left Square               false  false  false
Square overlapping left and right square  Point middle of Right Square              true   false  true
Square overlapping left and right square  Square (left)                             false  false  true
Square overlapping left and right square  Square (right)                            false  false  true
Square overlapping left and right square  Square overlapping left and right square  true   true   true

query TTBBB
SELECT
  a.dsc,
  b.dsc,
  _ST_Covers(a.geog, b.geog),
  _ST_CoveredBy(a.geog, b.geog),
  _ST_Intersects(a.geog, b.geog)
FROM geog_operators_test a
JOIN geog_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  false  false  false
Empty GeometryCollection                  Empty LineString                          false  false  false
Empty GeometryCollection                  Empty Point                               false  false  false
Empty GeometryCollection                  Faraway point                             false  false  false
Empty GeometryCollection                  Line going through left and right square  false  false  false
Empty GeometryCollection                  NULL                                      NULL   NULL   NULL
Empty GeometryCollection                  Nested Geometry Collection                false  false  false
Empty GeometryCollection                  Point middle of Left Square               false  false  false
Empty GeometryCollection                  Point middle of Right Square              false  false  false
Empty GeometryCollection                  Square (left)                             false  false  false
Empty GeometryCollection                  Square (right)                            false  false  false
Empty GeometryCollection                  Square overlapping left and right square  false  false  false
Empty LineString                          Empty GeometryCollection                  false  false  false
Empty LineString                          Empty LineString                          false  false  false
Empty LineString                          Empty Point                               false  false  false
Empty LineString                          Faraway point                             false  false  false
Empty LineString                          Line going through left and right square  false  false  false
Empty LineString                          NULL                                      NULL   NULL   NULL
Empty LineString                          Nested Geometry Collection                false  false  false
Empty LineString                          Point middle of Left Square               false  false  false
Empty LineString                          Point middle of Right Square              false  false  false
Empty LineString                          Square (left)                             false  false  false
Empty LineString                          Square (right)                            false  false  false
Empty LineString                          Square overlapping left and right square  false  false  false
Empty Point                               Empty GeometryCollection                  false  false  false
Empty Point                               Empty LineString                          false  false  false
Empty Point                               Empty Point                               false  false  false
Empty Point                               Faraway point                             false  false  false
Empty Point                               Line going through left and right square  false  false  false
Empty Point                               NULL                                      NULL   NULL   NULL
Empty Point                               Nested Geometry Collection                false  false  false
Empty Point                               Point middle of Left Square               false  false  false
Empty Point                               Point middle of Right Square              false  false  false
Empty Point                               Square (left)                             false  false  false
Empty Point                               Square (right)                            false  false  false
Empty Point                               Square overlapping left and right square  false  false  false
Faraway point                             Empty GeometryCollection                  false  false  false
Faraway point                             Empty LineString                          false  false  false
Faraway point                             Empty Point                               false  false  false
Faraway point                             Faraway point                             true   true   true
Faraway point                             Line going through left and right square  false  false  false
Faraway point                             NULL                                      NULL   NULL   NULL
Faraway point                             Nested Geometry Collection                false  false  false
Faraway point                             Point middle of Left Square               false  false  false
Faraway point                             Point middle of Right Square              false  false  false
Faraway point                             Square (left)                             false  false  false
Faraway point                             Square (right)                            false  false  false
Faraway point                             Square overlapping left and right square  false  false  false
Line going through left and right square  Empty GeometryCollection                  false  false  false
Line going through left and right square  Empty LineString                          false  false  false
Line going through left and right square  Empty Point                               false  false  false
Line going through left and right square  Faraway point                             false  false  false
Line going through left and right square  Line going through left and right square  true   true   true
Line going through left and right square  NULL                                      NULL   NULL   NULL
Line going through left and right square  Nested Geometry Collection                false  false  false
Line going through left and right square  Point middle of Left Square               true   false  true
Line going through left and right square  Point middle of Right Square              true   false  true
Line going through left and right square  Square (left)                             false  false  true
Line going through left and right square  Square (right)                            false  false  true
Line going through left and right square  Square overlapping left and right square  false  false  true
NULL                                      Empty GeometryCollection                  NULL   NULL   NULL
NULL                                      Empty LineString                          NULL   NULL   NULL
NULL                                      Empty Point                               NULL   NULL   NULL
NULL                                      Faraway point                             NULL   NULL   NULL
NULL                                      Line going through left and right square  NULL   NULL   NULL
NULL                                      NULL                                      NULL   NULL   NULL
NULL                                      Nested Geometry Collection                NULL   NULL   NULL
NULL                                      Point middle of Left Square               NULL   NULL   NULL
NULL                                      Point middle of Right Square              NULL   NULL   NULL
NULL                                      Square (left)                             NULL   NULL   NULL
NULL                                      Square (right)                            NULL   NULL   NULL
NULL                                      Square overlapping left and right square  NULL   NULL   NULL
Nested Geometry Collection                Empty GeometryCollection                  false  false  false
Nested Geometry Collection                Empty LineString                          false  false  false
Nested Geometry Collection                Empty Point                               false  false  false
Nested Geometry Collection                Faraway point                             false  false  false
Nested Geometry Collection                Line going through left and right square  false  false  false
Nested Geometry Collection                NULL                                      NULL   NULL   NULL
Nested Geometry Collection                Nested Geometry Collection                true   true   true
Nested Geometry Collection                Point middle of Left Square               false  false  false
Nested Geometry Collection                Point middle of Right Square              false  false  false
Nested Geometry Collection                Square (left)                             false  true   true
Nested Geometry Collection                Square (right)                            false  true   true
Nested Geometry Collection                Square overlapping left and right square  false  true   true
Point middle of Left Square               Empty GeometryCollection                  false  false  false
Point middle of Left Square               Empty LineString                          false  false  false
Point middle of Left Square               Empty Point                               false  false  false
Point middle of Left Square               Faraway point                             false  false  false
Point middle of Left Square               Line going through left and right square  false  true   true
Point middle of Left Square               NULL                                      NULL   NULL   NULL
Point middle of Left Square               Nested Geometry Collection                false  false  false
Point middle of Left Square               Point middle of Left Square               true   true   true
Point middle of Left Square               Point middle of Right Square              false  false  false
Point middle of Left Square               Square (left)                             false  true   true
Point middle of Left Square               Square (right)                            false  false  false
Point middle of Left Square               Square overlapping left and right square  false  false  false
Point middle of Right Square              Empty GeometryCollection                  false  false  false
Point middle of Right Square              Empty LineString                          false  false  false
Point middle of Right Square              Empty Point                               false  false  false
Point middle of Right Square              Faraway point                             false  false  false
Point middle of Right Square              Line going through left and right square  false  true   true
Point middle of Right Square              NULL                                      NULL   NULL   NULL
Point middle of Right Square              Nested Geometry Collection                false  false  false
Point middle of Right Square              Point middle of Left Square               false  false  false
Point middle of Right Square              Point middle of Right Square              true   true   true
Point middle of Right Square              Square (left)                             false  false  false
Point middle of Right Square              Square (right)                            false  true   true
Point middle of Right Square              Square overlapping left and right square  false  true   true
Square (left)                             Empty GeometryCollection                  false  false  false
Square (left)                             Empty LineString                          false  false  false
Square (left)                             Empty Point                               false  false  false
Square (left)                             Faraway point                             false  false  false
Square (left)                             Line going through left and right square  false  false  true
Square (left)                             NULL                                      NULL   NULL   NULL
Square (left)                             Nested Geometry Collection                true   false  true
Square (left)                             Point middle of Left Square               true   false  true
Square (left)                             Point middle of Right Square              false  false  false
Square (left)                             Square (left)                             true   true   true
Square (left)                             Square (right)                            false  false  true
Square (left)                             Square overlapping left and right square  false  false  true
Square (right)                            Empty GeometryCollection                  false  false  false
Square (right)                            Empty LineString                          false  false  false
Square (right)                            Empty Point                               false  false  false
Square (right)                            Faraway point                             false  false  false
Square (right)                            Line going through left and right square  false  false  true
Square (right)                            NULL                                      NULL   NULL   NULL
Square (right)                            Nested Geometry Collection                true   false  true
Square (right)                            Point middle of Left Square               false  false  false
Square (right)                            Point middle of Right Square              true   false  true
Square (right)                            Square (left)                             false  false  true
Square (right)                            Square (right)                            true   true   true
Square (right)                            Square overlapping left and right square  false  false  true
Square overlapping left and right square  Empty GeometryCollection                  false  false  false
Square overlapping left and right square  Empty LineString                          false  false  false
Square overlapping left and right square  Empty Point                               false  false  false
Square overlapping left and right square  Faraway point                             false  false  false
Square overlapping left and right square  Line going through left and right square  false  false  true
Square overlapping left and right square  NULL                                      NULL   NULL   NULL
Square overlapping left and right square  Nested Geometry Collection                true   false  true
Square overlapping left and right square  Point middle of Left Square               false  false  false
Square overlapping left and right square  Point middle of Right Square              true   false  true
Square overlapping left and right square  Square (left)                             false  false  true
Square overlapping left and right square  Square (right)                            false  false  true
Square overlapping left and right square  Square overlapping left and right square  true   true   true

# DWithin
query TTBBB
SELECT
  a.dsc,
  b.dsc,
  ST_DWithin(a.geog, b.geog, 70558),
  ST_DWithin(a.geog, b.geog, 70558, false),
  ST_DWithin(a.geog, b.geog, 70558, true)
FROM geog_operators_test a
JOIN geog_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  false  false  false
Empty GeometryCollection                  Empty LineString                          false  false  false
Empty GeometryCollection                  Empty Point                               false  false  false
Empty GeometryCollection                  Faraway point                             false  false  false
Empty GeometryCollection                  Line going through left and right square  false  false  false
Empty GeometryCollection                  NULL                                      NULL   NULL   NULL
Empty GeometryCollection                  Nested Geometry Collection                false  false  false
Empty GeometryCollection                  Point middle of Left Square               false  false  false
Empty GeometryCollection                  Point middle of Right Square              false  false  false
Empty GeometryCollection                  Square (left)                             false  false  false
Empty GeometryCollection                  Square (right)                            false  false  false
Empty GeometryCollection                  Square overlapping left and right square  false  false  false
Empty LineString                          Empty GeometryCollection                  false  false  false
Empty LineString                          Empty LineString                          false  false  false
Empty LineString                          Empty Point                               false  false  false
Empty LineString                          Faraway point                             false  false  false
Empty LineString                          Line going through left and right square  false  false  false
Empty LineString                          NULL                                      NULL   NULL   NULL
Empty LineString                          Nested Geometry Collection                false  false  false
Empty LineString                          Point middle of Left Square               false  false  false
Empty LineString                          Point middle of Right Square              false  false  false
Empty LineString                          Square (left)                             false  false  false
Empty LineString                          Square (right)                            false  false  false
Empty LineString                          Square overlapping left and right square  false  false  false
Empty Point                               Empty GeometryCollection                  false  false  false
Empty Point                               Empty LineString                          false  false  false
Empty Point                               Empty Point                               false  false  false
Empty Point                               Faraway point                             false  false  false
Empty Point                               Line going through left and right square  false  false  false
Empty Point                               NULL                                      NULL   NULL   NULL
Empty Point                               Nested Geometry Collection                false  false  false
Empty Point                               Point middle of Left Square               false  false  false
Empty Point                               Point middle of Right Square              false  false  false
Empty Point                               Square (left)                             false  false  false
Empty Point                               Square (right)                            false  false  false
Empty Point                               Square overlapping left and right square  false  false  false
Faraway point                             Empty GeometryCollection                  false  false  false
Faraway point                             Empty LineString                          false  false  false
Faraway point                             Empty Point                               false  false  false
Faraway point                             Faraway point                             true   true   true
Faraway point                             Line going through left and right square  false  false  false
Faraway point                             NULL                                      NULL   NULL   NULL
Faraway point                             Nested Geometry Collection                false  false  false
Faraway point                             Point middle of Left Square               false  false  false
Faraway point                             Point middle of Right Square              false  false  false
Faraway point                             Square (left)                             false  false  false
Faraway point                             Square (right)                            false  false  false
Faraway point                             Square overlapping left and right square  false  false  false
Line going through left and right square  Empty GeometryCollection                  false  false  false
Line going through left and right square  Empty LineString                          false  false  false
Line going through left and right square  Empty Point                               false  false  false
Line going through left and right square  Faraway point                             false  false  false
Line going through left and right square  Line going through left and right square  true   true   true
Line going through left and right square  NULL                                      NULL   NULL   NULL
Line going through left and right square  Nested Geometry Collection                true   true   true
Line going through left and right square  Point middle of Left Square               true   true   true
Line going through left and right square  Point middle of Right Square              true   true   true
Line going through left and right square  Square (left)                             true   true   true
Line going through left and right square  Square (right)                            true   true   true
Line going through left and right square  Square overlapping left and right square  true   true   true
NULL                                      Empty GeometryCollection                  NULL   NULL   NULL
NULL                                      Empty LineString                          NULL   NULL   NULL
NULL                                      Empty Point                               NULL   NULL   NULL
NULL                                      Faraway point                             NULL   NULL   NULL
NULL                                      Line going through left and right square  NULL   NULL   NULL
NULL                                      NULL                                      NULL   NULL   NULL
NULL                                      Nested Geometry Collection                NULL   NULL   NULL
NULL                                      Point middle of Left Square               NULL   NULL   NULL
NULL                                      Point middle of Right Square              NULL   NULL   NULL
NULL                                      Square (left)                             NULL   NULL   NULL
NULL                                      Square (right)                            NULL   NULL   NULL
NULL                                      Square overlapping left and right square  NULL   NULL   NULL
Nested Geometry Collection                Empty GeometryCollection                  false  false  false
Nested Geometry Collection                Empty LineString                          false  false  false
Nested Geometry Collection                Empty Point                               false  false  false
Nested Geometry Collection                Faraway point                             false  false  false
Nested Geometry Collection                Line going through left and right square  true   true   true
Nested Geometry Collection                NULL                                      NULL   NULL   NULL
Nested Geometry Collection                Nested Geometry Collection                true   true   true
Nested Geometry Collection                Point middle of Left Square               false  false  false
Nested Geometry Collection                Point middle of Right Square              false  false  false
Nested Geometry Collection                Square (left)                             true   true   true
Nested Geometry Collection                Square (right)                            true   true   true
Nested Geometry Collection                Square overlapping left and right square  true   true   true
Point middle of Left Square               Empty GeometryCollection                  false  false  false
Point middle of Left Square               Empty LineString                          false  false  false
Point middle of Left Square               Empty Point                               false  false  false
Point middle of Left Square               Faraway point                             false  false  false
Point middle of Left Square               Line going through left and right square  true   true   true
Point middle of Left Square               NULL                                      NULL   NULL   NULL
Point middle of Left Square               Nested Geometry Collection                false  false  false
Point middle of Left Square               Point middle of Left Square               true   true   true
Point middle of Left Square               Point middle of Right Square              false  false  false
Point middle of Left Square               Square (left)                             true   true   true
Point middle of Left Square               Square (right)                            true   true   true
Point middle of Left Square               Square overlapping left and right square  true   true   true
Point middle of Right Square              Empty GeometryCollection                  false  false  false
Point middle of Right Square              Empty LineString                          false  false  false
Point middle of Right Square              Empty Point                               false  false  false
Point middle of Right Square              Faraway point                             false  false  false
Point middle of Right Square              Line going through left and right square  true   true   true
Point middle of Right Square              NULL                                      NULL   NULL   NULL
Point middle of Right Square              Nested Geometry Collection                false  false  false
Point middle of Right Square              Point middle of Left Square               false  false  false
Point middle of Right Square              Point middle of Right Square              true   true   true
Point middle of Right Square              Square (left)                             true   true   true
Point middle of Right Square              Square (right)                            true   true   true
Point middle of Right Square              Square overlapping left and right square  true   true   true
Square (left)                             Empty GeometryCollection                  false  false  false
Square (left)                             Empty LineString                          false  false  false
Square (left)                             Empty Point                               false  false  false
Square (left)                             Faraway point                             false  false  false
Square (left)                             Line going through left and right square  true   true   true
Square (left)                             NULL                                      NULL   NULL   NULL
Square (left)                             Nested Geometry Collection                true   true   true
Square (left)                             Point middle of Left Square               true   true   true
Square (left)                             Point middle of Right Square              true   true   true
Square (left)                             Square (left)                             true   true   true
Square (left)                             Square (right)                            true   true   true
Square (left)                             Square overlapping left and right square  true   true   true
Square (right)                            Empty GeometryCollection                  false  false  false
Square (right)                            Empty LineString                          false  false  false
Square (right)                            Empty Point                               false  false  false
Square (right)                            Faraway point                             false  false  false
Square (right)                            Line going through left and right square  true   true   true
Square (right)                            NULL                                      NULL   NULL   NULL
Square (right)                            Nested Geometry Collection                true   true   true
Square (right)                            Point middle of Left Square               true   true   true
Square (right)                            Point middle of Right Square              true   true   true
Square (right)                            Square (left)                             true   true   true
Square (right)                            Square (right)                            true   true   true
Square (right)                            Square overlapping left and right square  true   true   true
Square overlapping left and right square  Empty GeometryCollection                  false  false  false
Square overlapping left and right square  Empty LineString                          false  false  false
Square overlapping left and right square  Empty Point                               false  false  false
Square overlapping left and right square  Faraway point                             false  false  false
Square overlapping left and right square  Line going through left and right square  true   true   true
Square overlapping left and right square  NULL                                      NULL   NULL   NULL
Square overlapping left and right square  Nested Geometry Collection                true   true   true
Square overlapping left and right square  Point middle of Left Square               true   true   true
Square overlapping left and right square  Point middle of Right Square              true   true   true
Square overlapping left and right square  Square (left)                             true   true   true
Square overlapping left and right square  Square (right)                            true   true   true
Square overlapping left and right square  Square overlapping left and right square  true   true   true

query TTBBB
SELECT
  a.dsc,
  b.dsc,
  _ST_DWithin(a.geog, b.geog, 70558),
  _ST_DWithin(a.geog, b.geog, 70558, false),
  _ST_DWithin(a.geog, b.geog, 70558, true)
FROM geog_operators_test a
JOIN geog_operators_test b ON (1=1)
ORDER BY a.dsc, b.dsc
----
Empty GeometryCollection                  Empty GeometryCollection                  false  false  false
Empty GeometryCollection                  Empty LineString                          false  false  false
Empty GeometryCollection                  Empty Point                               false  false  false
Empty GeometryCollection                  Faraway point                             false  false  false
Empty GeometryCollection                  Line going through left and right square  false  false  false
Empty GeometryCollection                  NULL                                      NULL   NULL   NULL
Empty GeometryCollection                  Nested Geometry Collection                false  false  false
Empty GeometryCollection                  Point middle of Left Square               false  false  false
Empty GeometryCollection                  Point middle of Right Square              false  false  false
Empty GeometryCollection                  Square (left)                             false  false  false
Empty GeometryCollection                  Square (right)                            false  false  false
Empty GeometryCollection                  Square overlapping left and right square  false  false  false
Empty LineString                          Empty GeometryCollection                  false  false  false
Empty LineString                          Empty LineString                          false  false  false
Empty LineString                          Empty Point                               false  false  false
Empty LineString                          Faraway point                             false  false  false
Empty LineString                          Line going through left and right square  false  false  false
Empty LineString                          NULL                                      NULL   NULL   NULL
Empty LineString                          Nested Geometry Collection                false  false  false
Empty LineString                          Point middle of Left Square               false  false  false
Empty LineString                          Point middle of Right Square              false  false  false
Empty LineString                          Square (left)                             false  false  false
Empty LineString                          Square (right)                            false  false  false
Empty LineString                          Square overlapping left and right square  false  false  false
Empty Point                               Empty GeometryCollection                  false  false  false
Empty Point                               Empty LineString                          false  false  false
Empty Point                               Empty Point                               false  false  false
Empty Point                               Faraway point                             false  false  false
Empty Point                               Line going through left and right square  false  false  false
Empty Point                               NULL                                      NULL   NULL   NULL
Empty Point                               Nested Geometry Collection                false  false  false
Empty Point                               Point middle of Left Square               false  false  false
Empty Point                               Point middle of Right Square              false  false  false
Empty Point                               Square (left)                             false  false  false
Empty Point                               Square (right)                            false  false  false
Empty Point                               Square overlapping left and right square  false  false  false
Faraway point                             Empty GeometryCollection                  false  false  false
Faraway point                             Empty LineString                          false  false  false
Faraway point                             Empty Point                               false  false  false
Faraway point                             Faraway point                             true   true   true
Faraway point                             Line going through left and right square  false  false  false
Faraway point                             NULL                                      NULL   NULL   NULL
Faraway point                             Nested Geometry Collection                false  false  false
Faraway point                             Point middle of Left Square               false  false  false
Faraway point                             Point middle of Right Square              false  false  false
Faraway point                             Square (left)                             false  false  false
Faraway point                             Square (right)                            false  false  false
Faraway point                             Square overlapping left and right square  false  false  false
Line going through left and right square  Empty GeometryCollection                  false  false  false
Line going through left and right square  Empty LineString                          false  false  false
Line going through left and right square  Empty Point                               false  false  false
Line going through left and right square  Faraway point                             false  false  false
Line going through left and right square  Line going through left and right square  true   true   true
Line going through left and right square  NULL                                      NULL   NULL   NULL
Line going through left and right square  Nested Geometry Collection                true   true   true
Line going through left and right square  Point middle of Left Square               true   true   true
Line going through left and right square  Point middle of Right Square              true   true   true
Line going through left and right square  Square (left)                             true   true   true
Line going through left and right square  Square (right)                            true   true   true
Line going through left and right square  Square overlapping left and right square  true   true   true
NULL                                      Empty GeometryCollection                  NULL   NULL   NULL
NULL                                      Empty LineString                          NULL   NULL   NULL
NULL                                      Empty Point                               NULL   NULL   NULL
NULL                                      Faraway point                             NULL   NULL   NULL
NULL                                      Line going through left and right square  NULL   NULL   NULL
NULL                                      NULL                                      NULL   NULL   NULL
NULL                                      Nested Geometry Collection                NULL   NULL   NULL
NULL                                      Point middle of Left Square               NULL   NULL   NULL
NULL                                      Point middle of Right Square              NULL   NULL   NULL
NULL                                      Square (left)                             NULL   NULL   NULL
NULL                                      Square (right)                            NULL   NULL   NULL
NULL                                      Square overlapping left and right square  NULL   NULL   NULL
Nested Geometry Collection                Empty GeometryCollection                  false  false  false
Nested Geometry Collection                Empty LineString                          false  false  false
Nested Geometry Collection                Empty Point                               false  false  false
Nested Geometry Collection                Faraway point                             false  false  false
Nested Geometry Collection                Line going through left and right square  true   true   true
Nested Geometry Collection                NULL                                      NULL   NULL   NULL
Nested Geometry Collection                Nested Geometry Collection                true   true   true
Nested Geometry Collection                Point middle of Left Square               false  false  false
Nested Geometry Collection                Point middle of Right Square              false  false  false
Nested Geometry Collection                Square (left)                             true   true   true
Nested Geometry Collection                Square (right)                            true   true   true
Nested Geometry Collection                Square overlapping left and right square  true   true   true
Point middle of Left Square               Empty GeometryCollection                  false  false  false
Point middle of Left Square               Empty LineString                          false  false  false
Point middle of Left Square               Empty Point                               false  false  false
Point middle of Left Square               Faraway point                             false  false  false
Point middle of Left Square               Line going through left and right square  true   true   true
Point middle of Left Square               NULL                                      NULL   NULL   NULL
Point middle of Left Square               Nested Geometry Collection                false  false  false
Point middle of Left Square               Point middle of Left Square               true   true   true
Point middle of Left Square               Point middle of Right Square              false  false  false
Point middle of Left Square               Square (left)                             true   true   true
Point middle of Left Square               Square (right)                            true   true   true
Point middle of Left Square               Square overlapping left and right square  true   true   true
Point middle of Right Square              Empty GeometryCollection                  false  false  false
Point middle of Right Square              Empty LineString                          false  false  false
Point middle of Right Square              Empty Point                               false  false  false
Point middle of Right Square              Faraway point                             false  false  false
Point middle of Right Square              Line going through left and right square  true   true   true
Point middle of Right Square              NULL                                      NULL   NULL   NULL
Point middle of Right Square              Nested Geometry Collection                false  false  false
Point middle of Right Square              Point middle of Left Square               false  false  false
Point middle of Right Square              Point middle of Right Square              true   true   true
Point middle of Right Square              Square (left)                             true   true   true
Point middle of Right Square              Square (right)                            true   true   true
Point middle of Right Square              Square overlapping left and right square  true   true   true
Square (left)                             Empty GeometryCollection                  false  false  false
Square (left)                             Empty LineString                          false  false  false
Square (left)                             Empty Point                               false  false  false
Square (left)                             Faraway point                             false  false  false
Square (left)                             Line going through left and right square  true   true   true
Square (left)                             NULL                                      NULL   NULL   NULL
Square (left)                             Nested Geometry Collection                true   true   true
Square (left)                             Point middle of Left Square               true   true   true
Square (left)                             Point middle of Right Square              true   true   true
Square (left)                             Square (left)                             true   true   true
Square (left)                             Square (right)                            true   true   true
Square (left)                             Square overlapping left and right square  true   true   true
Square (right)                            Empty GeometryCollection                  false  false  false
Square (right)                            Empty LineString                          false  false  false
Square (right)                            Empty Point                               false  false  false
Square (right)                            Faraway point                             false  false  false
Square (right)                            Line going through left and right square  true   true   true
Square (right)                            NULL                                      NULL   NULL   NULL
Square (right)                            Nested Geometry Collection                true   true   true
Square (right)                            Point middle of Left Square               true   true   true
Square (right)                            Point middle of Right Square              true   true   true
Square (right)                            Square (left)                             true   true   true
Square (right)                            Square (right)                            true   true   true
Square (right)                            Square overlapping left and right square  true   true   true
Square overlapping left and right square  Empty GeometryCollection                  false  false  false
Square overlapping left and right square  Empty LineString                          false  false  false
Square overlapping left and right square  Empty Point                               false  false  false
Square overlapping left and right square  Faraway point                             false  false  false
Square overlapping left and right square  Line going through left and right square  true   true   true
Square overlapping left and right square  NULL                                      NULL   NULL   NULL
Square overlapping left and right square  Nested Geometry Collection                true   true   true
Square overlapping left and right square  Point middle of Left Square               true   true   true
Square overlapping left and right square  Point middle of Right Square              true   true   true
Square overlapping left and right square  Square (left)                             true   true   true
Square overlapping left and right square  Square (right)                            true   true   true
Square overlapping left and right square  Square overlapping left and right square  true   true   true

# ST_Segmentize
query TTT
SELECT
  dsc,
  ST_AsText(ST_Segmentize(geog, 100000)),
  ST_AsText(ST_Segmentize(geog, 50000))
FROM geog_operators_test
ORDER BY dsc
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                                                                       GEOMETRYCOLLECTION EMPTY
Empty LineString                          LINESTRING EMPTY                                                                               LINESTRING EMPTY
Empty Point                               POINT EMPTY                                                                                    POINT EMPTY
Faraway point                             POINT (5 5)                                                                                    POINT (5 5)
Line going through left and right square  LINESTRING (-0.5 0.5, -0 0.500019038226216, 0.5 0.5)                                           LINESTRING (-0.5 0.5, -0.250000000362479 0.500014278647005, -0 0.500019038226216, 0.250000000362479 0.500014278647005, 0.5 0.5)
NULL                                      NULL                                                                                           NULL
Nested Geometry Collection                GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))                                          GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Point middle of Left Square               POINT (-0.5 0.5)                                                                               POINT (-0.5 0.5)
Point middle of Right Square              POINT (0.5 0.5)                                                                                POINT (0.5 0.5)
Square (left)                             POLYGON ((-1 0, -0.5 0, 0 0, 0 0.5, 0 1, -0.5 1.000038070652873, -1 1, -1 0.5, -1 0))          POLYGON ((-1 0, -0.75 0, -0.5 0, -0.25 0, 0 0, 0 0.25, 0 0.5, 0 0.75, 0 1, -0.249999998550193 1.000028552944327, -0.5 1.000038070652873, -0.750000001449807 1.000028552944326, -1 1, -1 0.75, -1 0.5, -1 0.25, -1 0))
Square (right)                            POLYGON ((0 0, 0.5 0, 1 0, 1 0.5, 1 1, 0.5 1.000038070652873, 0 1, 0 0.5, 0 0))                POLYGON ((0 0, 0.25 0, 0.5 0, 0.75 0, 1 0, 1 0.25, 1 0.5, 1 0.75, 1 1, 0.750000001449807 1.000028552944327, 0.5 1.000038070652873, 0.249999998550193 1.000028552944327, 0 1, 0 0.75, 0 0.5, 0 0.25, 0 0))
Square overlapping left and right square  POLYGON ((-0.1 0, 0.45 0, 1 0, 1 0.5, 1 1, 0.45 1.000046065796834, -0.1 1, -0.1 0.5, -0.1 0))  POLYGON ((-0.1 0, 0.175 0, 0.45 0, 0.725 0, 1 0, 1 0.25, 1 0.5, 1 0.75, 1 1, 0.725000001929716 1.000034549281259, 0.45 1.000046065796834, 0.174999998070284 1.000034549281259, -0.1 1, -0.1 0.75, -0.1 0.5, -0.1 0.25, -0.1 0))

# ST_Buffer
query TTTT
SELECT
  a.dsc,
  ST_AsEWKT(ST_Buffer(a.geog, 10), 5),
  ST_AsEWKT(ST_Buffer(a.geog, 10, 2), 5),
  ST_AsEWKT(ST_Buffer(a.geog, 10, 'quad_segs=4 endcap=flat'), 5)
FROM geog_operators_test a
ORDER BY a.dsc
----
Empty GeometryCollection                  SRID=4326;POLYGON EMPTY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      SRID=4326;POLYGON EMPTY                                                                                                                                                                                      SRID=4326;POLYGON EMPTY
Empty LineString                          SRID=4326;POLYGON EMPTY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      SRID=4326;POLYGON EMPTY                                                                                                                                                                                      SRID=4326;POLYGON EMPTY
Empty Point                               SRID=4326;POLYGON EMPTY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      SRID=4326;POLYGON EMPTY                                                                                                                                                                                      SRID=4326;POLYGON EMPTY
Faraway point                             SRID=4326;POLYGON ((5.00009 5, 5.00009 4.99998, 5.00008 4.99997, 5.00007 4.99995, 5.00006 4.99994, 5.00005 4.99992, 5.00003 4.99992, 5.00002 4.99991, 5 4.99991, 4.99998 4.99991, 4.99997 4.99992, 4.99995 4.99992, 4.99994 4.99994, 4.99992 4.99995, 4.99992 4.99997, 4.99991 4.99998, 4.99991 5, 4.99991 5.00002, 4.99992 5.00003, 4.99993 5.00005, 4.99994 5.00006, 4.99995 5.00008, 4.99997 5.00008, 4.99998 5.00009, 5 5.00009, 5.00002 5.00009, 5.00003 5.00008, 5.00005 5.00008, 5.00006 5.00006, 5.00008 5.00005, 5.00008 5.00003, 5.00009 5.00002, 5.00009 5))                                                                                      SRID=4326;POLYGON ((5.00009 5, 5.00006 4.99994, 5 4.99991, 4.99994 4.99994, 4.99991 5, 4.99994 5.00006, 5 5.00009, 5.00006 5.00006, 5.00009 5))                                                              SRID=4326;POLYGON EMPTY
Line going through left and right square  SRID=4326;POLYGON ((0.5 0.50009, 0.50002 0.50009, 0.50003 0.50008, 0.50005 0.50008, 0.50006 0.50006, 0.50007 0.50005, 0.50008 0.50003, 0.50009 0.50002, 0.50009 0.5, 0.50009 0.49998, 0.50008 0.49997, 0.50007 0.49995, 0.50006 0.49994, 0.50005 0.49992, 0.50003 0.49992, 0.50002 0.49991, 0.5 0.49991, -0.5 0.49991, -0.50002 0.49991, -0.50003 0.49992, -0.50005 0.49992, -0.50006 0.49994, -0.50007 0.49995, -0.50008 0.49997, -0.50009 0.49998, -0.50009 0.5, -0.50009 0.50002, -0.50008 0.50003, -0.50007 0.50005, -0.50006 0.50006, -0.50005 0.50008, -0.50003 0.50008, -0.50002 0.50009, -0.5 0.50009, 0.5 0.50009))                                 SRID=4326;POLYGON ((0.5 0.50009, 0.50006 0.50006, 0.50009 0.5, 0.50006 0.49994, 0.5 0.49991, -0.5 0.49991, -0.50006 0.49994, -0.50009 0.5, -0.50006 0.50006, -0.5 0.50009, 0.5 0.50009))                     SRID=4326;POLYGON ((0.5 0.50009, 0.5 0.49991, -0.5 0.49991, -0.5 0.50009, 0.5 0.50009))
NULL                                      NULL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         NULL                                                                                                                                                                                                         NULL
Nested Geometry Collection                SRID=4326;POLYGON ((0.00009 0, 0.00009 -0.00002, 0.00008 -0.00003, 0.00007 -0.00005, 0.00006 -0.00006, 0.00005 -0.00008, 0.00003 -0.00008, 0.00002 -0.00009, -0 -0.00009, -0.00002 -0.00009, -0.00003 -0.00008, -0.00005 -0.00008, -0.00006 -0.00006, -0.00007 -0.00005, -0.00008 -0.00003, -0.00009 -0.00002, -0.00009 -0, -0.00009 0.00002, -0.00008 0.00003, -0.00007 0.00005, -0.00006 0.00006, -0.00005 0.00008, -0.00003 0.00008, -0.00002 0.00009, -0 0.00009, 0.00002 0.00009, 0.00003 0.00008, 0.00005 0.00008, 0.00006 0.00006, 0.00007 0.00005, 0.00008 0.00003, 0.00009 0.00002, 0.00009 0))                                                     SRID=4326;POLYGON ((0.00009 0, 0.00006 -0.00006, -0 -0.00009, -0.00006 -0.00006, -0.00009 -0, -0.00006 0.00006, -0 0.00009, 0.00006 0.00006, 0.00009 0))                                                     SRID=4326;POLYGON EMPTY
Point middle of Left Square               SRID=4326;POLYGON ((-0.49991 0.5, -0.49991 0.49998, -0.49992 0.49997, -0.49993 0.49995, -0.49994 0.49994, -0.49995 0.49992, -0.49997 0.49992, -0.49998 0.49991, -0.5 0.49991, -0.50002 0.49991, -0.50003 0.49992, -0.50005 0.49992, -0.50006 0.49994, -0.50007 0.49995, -0.50008 0.49997, -0.50009 0.49998, -0.50009 0.5, -0.50009 0.50002, -0.50008 0.50003, -0.50007 0.50005, -0.50006 0.50006, -0.50005 0.50008, -0.50003 0.50008, -0.50002 0.50009, -0.5 0.50009, -0.49998 0.50009, -0.49997 0.50008, -0.49995 0.50008, -0.49994 0.50006, -0.49993 0.50005, -0.49992 0.50003, -0.49991 0.50002, -0.49991 0.5))                                           SRID=4326;POLYGON ((-0.49991 0.5, -0.49994 0.49994, -0.5 0.49991, -0.50006 0.49994, -0.50009 0.5, -0.50006 0.50006, -0.5 0.50009, -0.49994 0.50006, -0.49991 0.5))                                           SRID=4326;POLYGON EMPTY
Point middle of Right Square              SRID=4326;POLYGON ((0.50009 0.5, 0.50009 0.49998, 0.50008 0.49997, 0.50007 0.49995, 0.50006 0.49994, 0.50005 0.49992, 0.50003 0.49992, 0.50002 0.49991, 0.5 0.49991, 0.49998 0.49991, 0.49997 0.49992, 0.49995 0.49992, 0.49994 0.49994, 0.49993 0.49995, 0.49992 0.49997, 0.49991 0.49998, 0.49991 0.5, 0.49991 0.50002, 0.49992 0.50003, 0.49993 0.50005, 0.49994 0.50006, 0.49995 0.50008, 0.49997 0.50008, 0.49998 0.50009, 0.5 0.50009, 0.50002 0.50009, 0.50003 0.50008, 0.50005 0.50008, 0.50006 0.50006, 0.50007 0.50005, 0.50008 0.50003, 0.50009 0.50002, 0.50009 0.5))                                                                            SRID=4326;POLYGON ((0.50009 0.5, 0.50006 0.49994, 0.5 0.49991, 0.49994 0.49994, 0.49991 0.5, 0.49994 0.50006, 0.5 0.50009, 0.50006 0.50006, 0.50009 0.5))                                                    SRID=4326;POLYGON EMPTY
Square (left)                             SRID=4326;POLYGON ((-1.00009 -0, -1.00009 1, -1.00009 1.00002, -1.00008 1.00003, -1.00007 1.00005, -1.00006 1.00006, -1.00005 1.00008, -1.00003 1.00008, -1.00002 1.00009, -1 1.00009, 0 1.00009, 0.00002 1.00009, 0.00003 1.00008, 0.00005 1.00008, 0.00006 1.00006, 0.00007 1.00005, 0.00008 1.00003, 0.00009 1.00002, 0.00009 1, 0.00009 0, 0.00009 -0.00002, 0.00008 -0.00003, 0.00007 -0.00005, 0.00006 -0.00006, 0.00005 -0.00008, 0.00003 -0.00008, 0.00002 -0.00009, 0 -0.00009, -1 -0.00009, -1.00002 -0.00009, -1.00003 -0.00008, -1.00005 -0.00008, -1.00006 -0.00006, -1.00007 -0.00005, -1.00008 -0.00003, -1.00009 -0.00002, -1.00009 -0))     SRID=4326;POLYGON ((-1.00009 -0, -1.00009 1, -1.00006 1.00006, -1 1.00009, 0 1.00009, 0.00006 1.00006, 0.00009 1, 0.00009 0, 0.00006 -0.00006, 0 -0.00009, -1 -0.00009, -1.00006 -0.00006, -1.00009 -0))     SRID=4326;POLYGON ((-1.00009 -0, -1.00009 1, -1.00008 1.00003, -1.00006 1.00006, -1.00003 1.00008, -1 1.00009, 0 1.00009, 0.00003 1.00008, 0.00006 1.00006, 0.00008 1.00003, 0.00009 1, 0.00009 0, 0.00008 -0.00003, 0.00006 -0.00006, 0.00003 -0.00008, 0 -0.00009, -1 -0.00009, -1.00003 -0.00008, -1.00006 -0.00006, -1.00008 -0.00003, -1.00009 -0))
Square (right)                            SRID=4326;POLYGON ((-0.00009 0, -0.00009 1, -0.00009 1.00002, -0.00008 1.00003, -0.00007 1.00005, -0.00006 1.00006, -0.00005 1.00008, -0.00003 1.00008, -0.00002 1.00009, -0 1.00009, 1 1.00009, 1.00002 1.00009, 1.00003 1.00008, 1.00005 1.00008, 1.00006 1.00006, 1.00007 1.00005, 1.00008 1.00003, 1.00009 1.00002, 1.00009 1, 1.00009 -0, 1.00009 -0.00002, 1.00008 -0.00003, 1.00007 -0.00005, 1.00006 -0.00006, 1.00005 -0.00008, 1.00003 -0.00008, 1.00002 -0.00009, 1 -0.00009, -0 -0.00009, -0.00002 -0.00009, -0.00003 -0.00008, -0.00005 -0.00008, -0.00006 -0.00006, -0.00007 -0.00005, -0.00008 -0.00003, -0.00009 -0.00002, -0.00009 0))      SRID=4326;POLYGON ((-0.00009 0, -0.00009 1, -0.00006 1.00006, -0 1.00009, 1 1.00009, 1.00006 1.00006, 1.00009 1, 1.00009 -0, 1.00006 -0.00006, 1 -0.00009, -0 -0.00009, -0.00006 -0.00006, -0.00009 0))      SRID=4326;POLYGON ((-0.00009 0, -0.00009 1, -0.00008 1.00003, -0.00006 1.00006, -0.00003 1.00008, -0 1.00009, 1 1.00009, 1.00003 1.00008, 1.00006 1.00006, 1.00008 1.00003, 1.00009 1, 1.00009 -0, 1.00008 -0.00003, 1.00006 -0.00006, 1.00003 -0.00008, 1 -0.00009, -0 -0.00009, -0.00003 -0.00008, -0.00006 -0.00006, -0.00008 -0.00003, -0.00009 0))
Square overlapping left and right square  SRID=4326;POLYGON ((-0.10009 0, -0.10009 1, -0.10009 1.00002, -0.10008 1.00003, -0.10007 1.00005, -0.10006 1.00006, -0.10005 1.00008, -0.10003 1.00008, -0.10002 1.00009, -0.1 1.00009, 1 1.00009, 1.00002 1.00009, 1.00003 1.00008, 1.00005 1.00008, 1.00006 1.00006, 1.00007 1.00005, 1.00008 1.00003, 1.00009 1.00002, 1.00009 1, 1.00009 -0, 1.00009 -0.00002, 1.00008 -0.00003, 1.00007 -0.00005, 1.00006 -0.00006, 1.00005 -0.00008, 1.00003 -0.00008, 1.00002 -0.00009, 1 -0.00009, -0.1 -0.00009, -0.10002 -0.00009, -0.10003 -0.00008, -0.10005 -0.00008, -0.10006 -0.00006, -0.10007 -0.00005, -0.10008 -0.00003, -0.10009 -0.00002, -0.10009 0))  SRID=4326;POLYGON ((-0.10009 0, -0.10009 1, -0.10006 1.00006, -0.1 1.00009, 1 1.00009, 1.00006 1.00006, 1.00009 1, 1.00009 -0, 1.00006 -0.00006, 1 -0.00009, -0.1 -0.00009, -0.10006 -0.00006, -0.10009 0))  SRID=4326;POLYGON ((-0.10009 0, -0.10009 1, -0.10008 1.00003, -0.10006 1.00006, -0.10003 1.00008, -0.1 1.00009, 1 1.00009, 1.00003 1.00008, 1.00006 1.00006, 1.00008 1.00003, 1.00009 1, 1.00009 -0, 1.00008 -0.00003, 1.00006 -0.00006, 1.00003 -0.00008, 1 -0.00009, -0.1 -0.00009, -0.10003 -0.00008, -0.10006 -0.00006, -0.10008 -0.00003, -0.10009 0))

# ST_Intersection for geography
query TT nosort
SELECT
  dsc,
  st_asewkt(st_intersection(a, b), 5)
FROM ( VALUES
  ('empty', 'POINT EMPTY'::geography, 'POINT EMPTY'::geography),
  ('non intersecting', 'POINT (1.5 1.5)'::geography, 'POINT (1.6 1.6)'::geography),
  ('intersecting', 'LINESTRING (0 0, 1 1)'::geography, 'LINESTRING (0 1, 1 0)'::geography)
) t(dsc, a, b)
----
empty             SRID=4326;POINT EMPTY
non intersecting  SRID=4326;POINT EMPTY
intersecting      SRID=4326;POINT (0.50019 0.50006)

# ST_Centroid for Geography
query TTT round-in-strings
SELECT
  a.dsc,
  ST_AsEWKT(ST_Centroid(a.geog, false)),
  ST_AsEWKT(ST_Centroid(a.geog, true))
FROM geog_operators_test a
WHERE a.dsc != 'Nested Geometry Collection' -- unhandled in ST_Centroid, like in PostGIS.
ORDER BY a.dsc
----
Empty GeometryCollection                  SRID=4326;GEOMETRYCOLLECTION EMPTY  SRID=4326;GEOMETRYCOLLECTION EMPTY
Empty LineString                          SRID=4326;GEOMETRYCOLLECTION EMPTY  SRID=4326;GEOMETRYCOLLECTION EMPTY
Empty Point                               SRID=4326;GEOMETRYCOLLECTION EMPTY  SRID=4326;GEOMETRYCOLLECTION EMPTY
Faraway point                             SRID=4326;POINT (5 5)               SRID=4326;POINT (5 5)
Line going through left and right square  SRID=4326;POINT (0 0.500019)        SRID=4326;POINT (0 0.500019)
NULL                                      NULL                                NULL
Point middle of Left Square               SRID=4326;POINT (-0.5 0.5)          SRID=4326;POINT (-0.5 0.5)
Point middle of Right Square              SRID=4326;POINT (0.5 0.5)           SRID=4326;POINT (0.5 0.5)
Square (left)                             SRID=4326;POINT (-0.5 0.500006)     SRID=4326;POINT (-0.5 0.500006)
Square (right)                            SRID=4326;POINT (0.5 0.500006)      SRID=4326;POINT (0.5 0.500006)
Square overlapping left and right square  SRID=4326;POINT (0.45 0.50001)      SRID=4326;POINT (0.45 0.50001)

statement error st_centroid\(\): unhandled geography type GeometryCollection
SELECT ST_Centroid('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING EMPTY)'::geography, true)

query T
SELECT ST_AsText(ST_Segmentize('MULTIPOINT (0 0, 1 1)'::geography, -1))
----
MULTIPOINT (0 0, 1 1)

statement error st_segmentize\(\): maximum segment length must be positive
SELECT ST_Segmentize('POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0))'::geography, 0)

query TTT
SELECT
  dsc,
  ST_AsText(ST_Segmentize(geom, 1)),
  ST_AsText(ST_Segmentize(geom, 0.3))
FROM geom_operators_test
ORDER BY dsc
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                                      GEOMETRYCOLLECTION EMPTY
Empty LineString                          LINESTRING EMPTY                                              LINESTRING EMPTY
Empty Point                               POINT EMPTY                                                   POINT EMPTY
Faraway point                             POINT (5 5)                                                   POINT (5 5)
Line going through left and right square  LINESTRING (-0.5 0.5, 0.5 0.5)                                LINESTRING (-0.5 0.5, -0.25 0.5, 0 0.5, 0.25 0.5, 0.5 0.5)
NULL                                      NULL                                                          NULL
Nested Geometry Collection                GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))         GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Point middle of Left Square               POINT (-0.5 0.5)                                              POINT (-0.5 0.5)
Point middle of Right Square              POINT (0.5 0.5)                                               POINT (0.5 0.5)
Square (left)                             POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                        POLYGON ((-1 0, -0.75 0, -0.5 0, -0.25 0, 0 0, 0 0.25, 0 0.5, 0 0.75, 0 1, -0.25 1, -0.5 1, -0.75 1, -1 1, -1 0.75, -1 0.5, -1 0.25, -1 0))
Square (right)                            POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                           POLYGON ((0 0, 0.25 0, 0.5 0, 0.75 0, 1 0, 1 0.25, 1 0.5, 1 0.75, 1 1, 0.75 1, 0.5 1, 0.25 1, 0 1, 0 0.75, 0 0.5, 0 0.25, 0 0))
Square overlapping left and right square  POLYGON ((-0.1 0, 0.45 0, 1 0, 1 1, 0.45 1, -0.1 1, -0.1 0))  POLYGON ((-0.1 0, 0.175 0, 0.45 0, 0.725 0, 1 0, 1 0.25, 1 0.5, 1 0.75, 1 1, 0.725 1, 0.45 1, 0.175 1, -0.1 1, -0.1 0.75, -0.1 0.5, -0.1 0.25, -0.1 0))

query T
SELECT ST_AsText(ST_Segmentize('MULTIPOINT (0 0, 1 1)'::geometry, -1))
----
MULTIPOINT (0 0, 1 1)

statement error st_segmentize\(\): maximum segment length must be positive
SELECT ST_Segmentize('POLYGON ((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0))'::geometry, -1)

# ST_Force*
query TT
SELECT
  dsc,
  ST_AsEWKT(ST_Force2D(geom))
FROM geom_operators_test
ORDER BY dsc
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY
Empty LineString                          LINESTRING EMPTY
Empty Point                               POINT EMPTY
Faraway point                             POINT (5 5)
Line going through left and right square  LINESTRING (-0.5 0.5, 0.5 0.5)
NULL                                      NULL
Nested Geometry Collection                GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Point middle of Left Square               POINT (-0.5 0.5)
Point middle of Right Square              POINT (0.5 0.5)
Square (left)                             POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (right)                            POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square overlapping left and right square  POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))

# ST_Expand
query TTT
SELECT
  dsc,
  ST_AsEWKT(ST_Expand(geom, 10)),
  ST_AsEWKT(ST_Expand(geom, 15, 20))
FROM geom_operators_test
ORDER BY dsc
----
Empty GeometryCollection                  GEOMETRYCOLLECTION EMPTY                                              GEOMETRYCOLLECTION EMPTY
Empty LineString                          LINESTRING EMPTY                                                      LINESTRING EMPTY
Empty Point                               POINT EMPTY                                                           POINT EMPTY
Faraway point                             POLYGON ((-5 -5, -5 15, 15 15, 15 -5, -5 -5))                         POLYGON ((-10 -15, -10 25, 20 25, 20 -15, -10 -15))
Line going through left and right square  POLYGON ((-10.5 -9.5, -10.5 10.5, 10.5 10.5, 10.5 -9.5, -10.5 -9.5))  POLYGON ((-15.5 -19.5, -15.5 20.5, 15.5 20.5, 15.5 -19.5, -15.5 -19.5))
NULL                                      NULL                                                                  NULL
Nested Geometry Collection                POLYGON ((-10 -10, -10 10, 10 10, 10 -10, -10 -10))                   POLYGON ((-15 -20, -15 20, 15 20, 15 -20, -15 -20))
Point middle of Left Square               POLYGON ((-10.5 -9.5, -10.5 10.5, 9.5 10.5, 9.5 -9.5, -10.5 -9.5))    POLYGON ((-15.5 -19.5, -15.5 20.5, 14.5 20.5, 14.5 -19.5, -15.5 -19.5))
Point middle of Right Square              POLYGON ((-9.5 -9.5, -9.5 10.5, 10.5 10.5, 10.5 -9.5, -9.5 -9.5))     POLYGON ((-14.5 -19.5, -14.5 20.5, 15.5 20.5, 15.5 -19.5, -14.5 -19.5))
Square (left)                             POLYGON ((-11 -10, -11 11, 10 11, 10 -10, -11 -10))                   POLYGON ((-16 -20, -16 21, 15 21, 15 -20, -16 -20))
Square (right)                            POLYGON ((-10 -10, -10 11, 11 11, 11 -10, -10 -10))                   POLYGON ((-15 -20, -15 21, 16 21, 16 -20, -15 -20))
Square overlapping left and right square  POLYGON ((-10.1 -10, -10.1 11, 11 11, 11 -10, -10.1 -10))             POLYGON ((-15.1 -20, -15.1 21, 16 21, 16 -20, -15.1 -20))

subtest st_srid

statement ok
CREATE TABLE geo_st_srid(
  id int primary key,
  geog geography(geometry),
  geom geometry(point)
)

statement ok
INSERT INTO geo_st_srid VALUES
  (1, ST_GeogFromText('SRID=4004;POINT(1.0 2.0)'), ST_GeomFromText('POINT(5.0 5.0)', 0)),
  (2, ST_GeogFromText('SRID=4326;POINT(1.0 2.0)'), ST_GeomFromText('POINT(5.0 5.0)', 4326)),
  (3, ST_SetSRID(ST_GeogFromText('SRID=4326;POINT(1.0 2.0)'), 4004), ST_SetSRID(ST_GeomFromText('POINT(5.0 5.0)', 4326), 3857))

query III
SELECT
  id,
  st_srid(geog),
  st_srid(geom)
FROM geo_st_srid
ORDER BY id
----
1  4004  0
2  4326  4326
3  4004  3857

subtest transform_test

statement ok
CREATE TABLE transform_test(geom geometry); INSERT INTO transform_test VALUES
  ('SRID=4326;POINT(1.0 1.0)'::geometry),
  ('SRID=3857;POINT(1.0 1.0)'::geometry),
  ('SRID=4326;LINESTRING(1.0 1.0, 2.0 2.0)'::geometry),
  ('SRID=3857;LINESTRING(1.0 1.0, 2.0 2.0)'::geometry),
  ('SRID=4326;POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0))'::geometry),
  ('SRID=3857;POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0))'::geometry),
  ('SRID=4326;MULTIPOINT((1.0 1.0), (2.0 2.0))'::geometry),
  ('SRID=3857;MULTIPOINT((1.0 1.0), (2.0 2.0))'::geometry),
  ('SRID=4326;MULTILINESTRING((1.0 1.0, 2.0 2.0), (3.0 3.0, 4.0 4.0))'::geometry),
  ('SRID=3857;MULTILINESTRING((1.0 1.0, 2.0 2.0), (3.0 3.0, 4.0 4.0))'::geometry),
  ('SRID=4326;MULTIPOLYGON(((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0)))'::geometry),
  ('SRID=3857;MULTIPOLYGON(((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0)))'::geometry),
  ('SRID=4326;GEOMETRYCOLLECTION (POINT (40 10),LINESTRING (10 10, 20 20, 10 40))'::geometry),
  ('SRID=3857;GEOMETRYCOLLECTION (POINT (40 10),LINESTRING (10 10, 20 20, 10 40))'::geometry)

# Temporarily do not display full numbers for now, as they can be inaccurate.
# This can be displayed when ST_AsText can have rounding.
query TBB
SELECT
  ST_AsEWKT(a.geom) d,
  ST_Transform(a.geom, 4326) = a.geom,
  ST_Transform(a.geom, 3857) = a.geom
FROM transform_test a
ORDER BY d ASC
----
SRID=3857;GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40))  false  true
SRID=3857;LINESTRING (1 1, 2 2)                                                 false  true
SRID=3857;MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))                              false  true
SRID=3857;MULTIPOINT (1 1, 2 2)                                                 false  true
SRID=3857;MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)))                            false  true
SRID=3857;POINT (1 1)                                                           false  true
SRID=3857;POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                   false  true
SRID=4326;GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40))  true   false
SRID=4326;LINESTRING (1 1, 2 2)                                                 true   false
SRID=4326;MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))                              true   false
SRID=4326;MULTIPOINT (1 1, 2 2)                                                 true   false
SRID=4326;MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)))                            true   false
SRID=4326;POINT (1 1)                                                           true   false
SRID=4326;POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                   true   false

query TBB
SELECT
  ST_AsEWKT(a.geom) d,
  ST_Transform(a.geom, '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', '+proj=longlat +datum=WGS84 +no_defs') = a.geom,
  ST_Transform(a.geom, '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', 3857) = a.geom
FROM transform_test a
ORDER BY d ASC
----
SRID=3857;GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40))  false  true
SRID=3857;LINESTRING (1 1, 2 2)                                                 false  true
SRID=3857;MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))                              false  true
SRID=3857;MULTIPOINT (1 1, 2 2)                                                 false  true
SRID=3857;MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)))                            false  true
SRID=3857;POINT (1 1)                                                           false  true
SRID=3857;POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                   false  true
SRID=4326;GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40))  false  false
SRID=4326;LINESTRING (1 1, 2 2)                                                 false  false
SRID=4326;MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))                              false  false
SRID=4326;MULTIPOINT (1 1, 2 2)                                                 false  false
SRID=4326;MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)))                            false  false
SRID=4326;POINT (1 1)                                                           false  false
SRID=4326;POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                                   false  false

query TT
SELECT
  ST_AsText(a.geom) d,
  ST_AsText(ST_Translate(a.geom, 1, 1))
FROM geom_operators_test a
ORDER BY d ASC
----
NULL                                                   NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (1 1)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (0.5 1.5, 1.5 1.5)
LINESTRING EMPTY                                       LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (0.5 1.5)
POINT (0.5 0.5)                                        POINT (1.5 1.5)
POINT (5 5)                                            POINT (6 6)
POINT EMPTY                                            POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((0.9 1, 2 1, 2 2, 0.9 2, 0.9 1))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((0 1, 1 1, 1 2, 0 2, 0 1))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((1 1, 2 1, 2 2, 1 2, 1 1))

query TTTTT
SELECT
  ST_AsText(a.geom) d,
  ST_AsText(ST_Scale(a.geom, .5 , 2)),
  ST_AsText(ST_Scale(a.geom, 'Point(.25 3)')),
  ST_AsText(ST_Scale(a.geom, 'Point(2 2)', 'Point(1 1)')),
  ST_AsText(ST_Scale(a.geom, 'POINT EMPTY'))
FROM geom_operators_test a
ORDER BY d ASC
----
NULL                                                   NULL                                                   NULL                                                      NULL                                                     NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))     GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (-1 -1)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY                                  GEOMETRYCOLLECTION EMPTY                                 GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (-0.25 1, 0.25 1)                           LINESTRING (-0.125 1.5, 0.125 1.5)                        LINESTRING (-2 0, 0 0)                                   LINESTRING (0 0, 0 0)
LINESTRING EMPTY                                       LINESTRING EMPTY                                       LINESTRING EMPTY                                          LINESTRING EMPTY                                         LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (-0.25 1)                                        POINT (-0.125 1.5)                                        POINT (-2 0)                                             POINT (0 0)
POINT (0.5 0.5)                                        POINT (0.25 1)                                         POINT (0.125 1.5)                                         POINT (0 0)                                              POINT (0 0)
POINT (5 5)                                            POINT (2.5 10)                                         POINT (1.25 15)                                           POINT (9 9)                                              POINT (0 0)
POINT EMPTY                                            POINT EMPTY                                            POINT EMPTY                                               POINT EMPTY                                              POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((-0.05 0, 0.5 0, 0.5 2, -0.05 2, -0.05 0))    POLYGON ((-0.025 0, 0.25 0, 0.25 3, -0.025 3, -0.025 0))  POLYGON ((-1.2 -1, 1 -1, 1 1, -1.2 1, -1.2 -1))          POLYGON ((0 0, 0 0, 0 0, 0 0, 0 0))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((-0.5 0, 0 0, 0 2, -0.5 2, -0.5 0))           POLYGON ((-0.25 0, 0 0, 0 3, -0.25 3, -0.25 0))           POLYGON ((-3 -1, -1 -1, -1 1, -3 1, -3 -1))              POLYGON ((0 0, 0 0, 0 0, 0 0, 0 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, 0.5 0, 0.5 2, 0 2, 0 0))                POLYGON ((0 0, 0.25 0, 0.25 3, 0 3, 0 0))                 POLYGON ((-1 -1, 1 -1, 1 1, -1 1, -1 -1))                POLYGON ((0 0, 0 0, 0 0, 0 0, 0 0))

query TT
SELECT
  ST_AsText(a.geom) d,
  ST_AsText(ST_Affine(a.geom, 1, 2, 3, 4, 5, 6), 3)
FROM geom_operators_test a
ORDER BY d ASC
----
NULL                                                   NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (5 6)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (5.5 6.5, 6.5 9.5)
LINESTRING EMPTY                                       LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (5.5 6.5)
POINT (0.5 0.5)                                        POINT (6.5 9.5)
POINT (5 5)                                            POINT (20 41)
POINT EMPTY                                            POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((4.9 5.7, 6 9, 8 13, 6.9 9.7, 4.9 5.7))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((4 3, 5 6, 7 10, 6 7, 4 3))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((5 6, 6 9, 8 13, 7 10, 5 6))

query T
SELECT ST_Summary('POINT(0 0)'::geometry)
----
Point[B]

subtest st_summary

query T
SELECT ST_Summary('POINT(0 0)'::geometry)
----
Point[B]

query T
SELECT ST_Summary('SRID=4326;POINT(0 0)'::geometry)
----
Point[BS]

query T
SELECT ST_Summary('MULTIPOINT(0 0)'::geometry)
----
MultiPoint[B] with 1 element
  Point[]

query T
SELECT ST_Summary('SRID=4326;MULTIPOINT(0 0)'::geometry)
----
MultiPoint[BS] with 1 element
  Point[S]

query T
SELECT ST_Summary('GEOMETRYCOLLECTION(MULTILINESTRING((0 0, 1 0),(2 0, 4 4)),MULTIPOINT(0 0))'::geometry)
----
GeometryCollection[B] with 2 elements
  MultiLineString[] with 2 elements
    LineString[] with 2 points
    LineString[] with 2 points
  MultiPoint[] with 1 element
    Point[]


query T
SELECT ST_Summary('SRID=4326;GEOMETRYCOLLECTION(MULTILINESTRING((0 0, 1 0),(2 0, 4 4)),MULTIPOINT(0 0))'::geometry)
----
GeometryCollection[BS] with 2 elements
  MultiLineString[S] with 2 elements
    LineString[S] with 2 points
    LineString[S] with 2 points
  MultiPoint[S] with 1 element
    Point[S]

query T
SELECT ST_Summary('POINT(0 0)'::geography)
----
Point[BGS]

query T
SELECT ST_Summary('SRID=4326;POINT(0 0)'::geography)
----
Point[BGS]

query T
SELECT ST_Summary('MULTIPOINT(0 0)'::geography)
----
MultiPoint[BGS] with 1 element
  Point[GS]

query T
SELECT ST_Summary('SRID=4326;MULTIPOINT(0 0)'::geography)
----
MultiPoint[BGS] with 1 element
  Point[GS]

query T
SELECT ST_Summary('GEOMETRYCOLLECTION(MULTILINESTRING((0 0, 1 0),(2 0, 4 4)),MULTIPOINT(0 0))'::geography)
----
GeometryCollection[BGS] with 2 elements
  MultiLineString[GS] with 2 elements
    LineString[GS] with 2 points
    LineString[GS] with 2 points
  MultiPoint[GS] with 1 element
    Point[GS]


query T
SELECT ST_Summary('SRID=4326;GEOMETRYCOLLECTION(MULTILINESTRING((0 0, 1 0),(2 0, 4 4)),MULTIPOINT(0 0))'::geography)
----
GeometryCollection[BGS] with 2 elements
  MultiLineString[GS] with 2 elements
    LineString[GS] with 2 points
    LineString[GS] with 2 points
  MultiPoint[GS] with 1 element
    Point[GS]

query RR
SELECT
	degrees(ST_Azimuth(ST_Point(25, 45)::geography, ST_Point(75, 90)::geography)) AS degA_B,
	degrees(ST_Azimuth(ST_Point(75, 90)::geography, ST_Point(25, 45)::geography)) AS degB_A
----
0  -130

query R
SELECT ST_Azimuth(ST_Point(0, 0)::geography, ST_Point(0, 0)::geography)
----
NULL

statement error POINT EMPTY
SELECT st_azimuth('0101000020E6100000000000000000F87F000000000000F87F':::GEOGRAPHY::GEOGRAPHY, '0101000020E6100000000000000000F03F000000000000F03F':::GEOGRAPHY::GEOGRAPHY)::FLOAT8

# Test for string arguments being cast to GEOMETRY.
query RTTTR nosort
SELECT
  ST_Area(geom_str),
  ST_AsEWKT(geom_str),
  ST_AsGeoJSON(geom_str),
  ST_AsText(geom_str),
  ST_Length(geom_str)
FROM (VALUES
  ('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0 ))'),
  ('LINESTRING(0 0, 1 1, 2 2)')
) t(geom_str)
----
1  POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))  {"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]}  POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))  0
0  LINESTRING (0 0, 1 1, 2 2)           {"type":"LineString","coordinates":[[0,0],[1,1],[2,2]]}             LINESTRING (0 0, 1 1, 2 2)           2.8284271247461903

# Test for 2+ arguments string arguments which resolve and get cast to GEOMETRY.
query BBRBB nosort
SELECT
  ST_CoveredBy(a, b),
  ST_Covers(a, b),
  ST_Distance(a, b),
  ST_DWithin(a, b, 10),
  ST_Intersects(a, b)
FROM ( VALUES
  ('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', 'POINT(1.0 1.0)'),
  ('POINT(3 0)', 'POINT(10 0)'),
  ('POINT(3 0)', 'POINT(100 0)')
) t(a, b)
----
false  true   0   true   true
false  false  7   true   false
false  false  97  false  false

# Test for 2+ string arguments for Geometry where one side of the arguments
# raises an error.
statement error pq: st_intersects\(\): error parsing EWKT: syntax error: invalid keyword at line 1, pos 0
SELECT ST_Intersects('abc'::string, 'POINT(1 0)'::string)

statement error pq: st_intersects\(\): error parsing EWKT: syntax error: invalid keyword at line 1, pos 0
SELECT ST_Intersects('POINT(1 0)'::string, 'abc'::string)

query T
SELECT ST_AsEWKT(ST_MakeLine(g::geometry)) FROM ( VALUES
  (NULL),
  ('POINT (30 10)'), -- value is used
  ('POINT EMPTY'),
  ('LINESTRING (30 10, 10 30, 40 40)'), -- value is used
  ('LINESTRING EMPTY'),
  ('POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))'),
  ('MULTIPOINT ((10 40), (40 30), (20 20), (30 10))'), -- value is used
  ('MULTIPOINT EMPTY'),
  ('MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))'),
  ('MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))'),
  ('GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40), POLYGON ((40 40, 20 45, 45 30, 40 40)))')
) t(g)
----
LINESTRING (30 10, 30 10, 10 30, 40 40, 10 40, 40 30, 20 20, 30 10)

query T
SELECT ST_AsEWKT(ST_MakeLine(g::geometry)) FROM ( VALUES
  (NULL)
) t(g)
----
NULL

query T
SELECT ST_AsText(ST_MakeLine(geom ORDER BY geom)) FROM geo_table
----
LINESTRING (1 1, 2 2, 2.22 -2.445)

query T
SELECT ST_Extent(g::geometry) FROM ( VALUES
  (NULL),
  ('POINT(-10.5 10.5)'),
  ('LINESTRING(0 0, 15 15)'),
  ('POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))'),
  ('POINT EMPTY')
) t(g)
----
BOX(-10.5 0,45 45)

query T
SELECT ST_Extent(g::geometry) FROM ( VALUES (NULL), ('POINT EMPTY') ) t(g)
----
NULL

query T
SELECT ST_AsEWKT(ST_Union(g::geometry)) FROM ( VALUES (NULL) ) tbl(g)
----
NULL

query T
SELECT ST_AsEWKT(ST_Union(g::geometry)) FROM ( VALUES (NULL), ('POINT(1 0)') ) tbl(g)
----
POINT (1 0)

statement error operation on mixed SRIDs forbidden
SELECT ST_AsEWKT(ST_Union(g::geometry)) FROM ( VALUES ('POINT(1 0)'), ('SRID=3857;POINT(1 0)') ) tbl(g)

query T
SELECT ST_AsEWKT(ST_Union(g::geometry)) FROM ( VALUES (NULL), ('POINT(1 0)'), ('LINESTRING(0 0, 5 0)')) tbl(g)
----
LINESTRING (0 0, 5 0)

query T
SELECT ST_AsEWKT(ST_MemUnion(g::geometry)) FROM ( VALUES (NULL), ('POINT(1 0)'), ('LINESTRING(0 0, 5 0)')) tbl(g)
----
LINESTRING (0 0, 5 0)

query T
SELECT ST_AsEWKT(ST_Collect(g::geometry)) FROM ( VALUES (NULL) ) tbl(g)
----
NULL

query T
SELECT ST_AsEWKT(ST_Collect(g::geometry)) FROM ( VALUES (NULL), ('POINT(1 0)') ) tbl(g)
----
MULTIPOINT (1 0)

statement error operation on mixed SRIDs forbidden
SELECT ST_AsEWKT(ST_Collect(g::geometry)) FROM ( VALUES ('POINT(1 0)'), ('SRID=3857;POINT(1 0)') ) tbl(g)

query T
SELECT ST_AsEWKT(ST_Collect(g::geometry)) FROM ( VALUES (NULL), ('POINT(1 0)'), ('LINESTRING(0 0, 5 0)')) tbl(g)
----
GEOMETRYCOLLECTION (POINT (1 0), LINESTRING (0 0, 5 0))

query T
SELECT ST_AsEWKT(ST_Collect(g::geometry)) FROM ( VALUES (NULL), ('POINT (1 1)'), ('POINT EMPTY'), ('POINT (2 2)')) tbl(g)
----
MULTIPOINT (1 1, EMPTY, 2 2)

query T
SELECT ST_AsEWKT(ST_Collect(g::geometry)) FROM ( VALUES ('MULTIPOINT (1 1, 2 2)'), ('POINT (3 3)')) tbl(g)
----
GEOMETRYCOLLECTION (MULTIPOINT (1 1, 2 2), POINT (3 3))

query T
SELECT ST_AsEWKT(ST_Collect(g::geometry)) FROM ( VALUES ('MULTIPOINT (1 1, 2 2)'), ('MULTIPOINT (3 3, 4 4)')) tbl(g)
----
GEOMETRYCOLLECTION (MULTIPOINT (1 1, 2 2), MULTIPOINT (3 3, 4 4))

query T
SELECT ST_AsEWKT(ST_Collect(g::geometry)) FROM ( VALUES ('GEOMETRYCOLLECTION (POINT (1 1))'), ('GEOMETRYCOLLECTION (POINT (2 2))')) tbl(g)
----
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (1 1)), GEOMETRYCOLLECTION (POINT (2 2)))

query T
SELECT ST_AsText(ST_Collect(geom ORDER BY geom)) FROM geo_table
----
MULTIPOINT (1 1, 2 2, 2.22 -2.445)

query T
SELECT ST_AsText(ST_MemCollect(geom ORDER BY geom)) FROM geo_table
----
MULTIPOINT (1 1, 2 2, 2.22 -2.445)

query T
SELECT ST_AsEWKT(ST_MemCollect(g::geometry)) FROM ( VALUES (NULL), ('POINT (1 1)'), ('POINT EMPTY'), ('POINT (2 2)')) tbl(g)
----
MULTIPOINT (1 1, EMPTY, 2 2)

query T
SELECT ST_AsEWKT(
  ST_SharedPaths(
    ST_GeomFromText('MULTILINESTRING((26 125,26 200,126 200,126 125,26 125),
	   (51 150,101 150,76 175,51 150))'),
	ST_GeomFromText('LINESTRING(151 100,126 156.25,126 125,90 161, 76 175)')))
----
GEOMETRYCOLLECTION (MULTILINESTRING ((126 156.25, 126 125), (101 150, 90 161), (90 161, 76 175)), MULTILINESTRING EMPTY)

subtest add_point_test

query T nosort
SELECT
  ST_AsText(ST_AddPoint(ls::geometry, p::geometry, i))
FROM ( VALUES
  ('LINESTRING(0 0, 1 1, 2 2)', 'POINT(5 5)', 0),
  ('LINESTRING(0 0, 1 1, 2 2)', 'POINT(5 5)', 2),
  ('LINESTRING(0 0, 1 1, 2 2)', 'POINT(5 5)', 3),
  ('LINESTRING(0 0, 1 1, 2 2)', 'POINT(5 5)', -1)
  )
 t(ls, p, i)
----
LINESTRING (5 5, 0 0, 1 1, 2 2)
LINESTRING (0 0, 1 1, 5 5, 2 2)
LINESTRING (0 0, 1 1, 2 2, 5 5)
LINESTRING (0 0, 1 1, 2 2, 5 5)

query T
SELECT
  ST_AsText(ST_AddPoint(ls::geometry, p::geometry))
FROM ( VALUES
  ('LINESTRING(0 0, 1 1, 2 2)', 'POINT(5 5)')
  )
 t(ls, p)
----
LINESTRING (0 0, 1 1, 2 2, 5 5)


subtest set_point_test

query T nosort
SELECT
  ST_AsText(ST_SetPoint(ls::geometry, i, p::geometry))
FROM ( VALUES
  ('LINESTRING(-1 2,-1 3)', 0, 'POINT(10 10)'),
  ('LINESTRING(0 0, 1 1, 2 2)', 2, 'POINT(10 10)'),
  ('LINESTRING(0 0, 1 1, 2 2, 3 3)', -1, 'POINT(10 10)'),
  ('LINESTRING(0 0, 1 1, 2 2, 3 3)', -4, 'POINT(10 10)')
  )
 t(ls, i, p)
----
LINESTRING (10 10, -1 3)
LINESTRING (0 0, 1 1, 10 10)
LINESTRING (0 0, 1 1, 2 2, 10 10)
LINESTRING (10 10, 1 1, 2 2, 3 3)

subtest remove_point_test

query T nosort
SELECT
  ST_AsText(ST_RemovePoint(ls::geometry, i))
FROM ( VALUES
  ('LINESTRING(0 0, 1 1, 2 2)', 2),
  ('LINESTRING(0 0, 1 1, 2 2, 3 3)', 0),
  ('LINESTRING(0 0, 1 1, 2 2, 3 3)', 1)
  )
 t(ls, i)
----
LINESTRING (0 0, 1 1)
LINESTRING (1 1, 2 2, 3 3)
LINESTRING (0 0, 2 2, 3 3)

subtest remove_repeated_points_test

query T nosort
SELECT
  ST_AsText(ST_RemoveRepeatedPoints(ls::geometry, i::float))
FROM ( VALUES
  ('LINESTRING(0 0, 0 0, 1 1, 2 2, 3 3, 4 4)', 0.0),
  ('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4, 5 5)', 1.4),
  ('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4, 5 5)', 1.5),
  ('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4, 5 5)', 3.0)
  )
 t(ls, i)
----
LINESTRING (0 0, 1 1, 2 2, 3 3, 4 4)
LINESTRING (0 0, 1 1, 2 2, 3 3, 4 4, 5 5)
LINESTRING (0 0, 2 2, 4 4)
LINESTRING (0 0, 3 3)

subtest reverse_test

query TT
SELECT
  ST_AsText(a.geom) d,
  ST_AsText(ST_Reverse(a.geom))
FROM geom_operators_test a
ORDER BY d ASC
----
NULL                                                   NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (0.5 0.5, -0.5 0.5)
LINESTRING EMPTY                                       LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (-0.5 0.5)
POINT (0.5 0.5)                                        POINT (0.5 0.5)
POINT (5 5)                                            POINT (5 5)
POINT EMPTY                                            POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((-0.1 0, -0.1 1, 1 1, 1 0, -0.1 0))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((-1 0, -1 1, 0 1, 0 0, -1 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))

subtest linefrommultipoint_test

query T nosort
SELECT
  ST_AsText(ST_LineFromMultiPoint(mp::geometry))
FROM ( VALUES
  ('MULTIPOINT EMPTY'),
  ('MULTIPOINT (1 1, 2 2, 3 3)')
  )
 t(mp)
----
LINESTRING EMPTY
LINESTRING (1 1, 2 2, 3 3)

subtest linemerge

query T nosort
SELECT
  ST_AsText(ST_LineMerge(g::geometry))
FROM ( VALUES
  ('MULTILINESTRING ((1 2, 3 4), (3 4, 5 6))'),
  ('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))'),
  ('POINT (1 2)')
  )
 t(g)
----
LINESTRING (1 2, 3 4, 5 6)
MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))
GEOMETRYCOLLECTION EMPTY

statement error st_linemerge\(\): value out of range: overflow
select st_linemerge('01020000C003000000000000000000F0FF000000000000F8FF60DB272315DEBAC13CDE36003499DEC1000000000000F0FF000000000000F8FF9CDB5D9AA401E1C1D0C80253A5F1C4C1000000000000F0FF000000000000F8FF003E39CD6CDDD2C1A6909F31D737F4C1'::geometry);

subtest public_schema_resolution

query T
SELECT public.ST_AsText('POINT(10.5 20.25)'::geometry)
----
POINT (10.5 20.25)

statement error pq: unknown function: public.log\(\)
SELECT public.log(10)

query TT
SELECT
  ST_AsText(a.geom) d,
  ST_AsText(ST_FlipCoordinates(a.geom))
FROM geom_operators_test a
ORDER BY d ASC
----
NULL                                                   NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (0.5 -0.5, 0.5 0.5)
LINESTRING EMPTY                                       LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (0.5 -0.5)
POINT (0.5 0.5)                                        POINT (0.5 0.5)
POINT (5 5)                                            POINT (5 5)
POINT EMPTY                                            POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((0 -0.1, 0 1, 1 1, 1 -0.1, 0 -0.1))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((0 -1, 0 0, 1 0, 1 -1, 0 -1))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))

query TTT
SELECT
  ST_AsText(a.geom) d,
  ST_AsText(ST_Rotate(a.geom, pi())),
  ST_AsText(ST_Rotate(a.geom, pi()/4))
FROM geom_operators_test a
ORDER BY d ASC
----
NULL                                                   NULL                                                   NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (0.5 -0.5, -0.5 -0.5)                       LINESTRING (-0.707106781186547 0, 0 0.707106781186547)
LINESTRING EMPTY                                       LINESTRING EMPTY                                       LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (0.5 -0.5)                                       POINT (-0.707106781186547 0)
POINT (0.5 0.5)                                        POINT (-0.5 -0.5)                                      POINT (0 0.707106781186547)
POINT (5 5)                                            POINT (-5.000000000000001 -4.999999999999999)          POINT (0 7.071067811865476)
POINT EMPTY                                            POINT EMPTY                                            POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((0.1 -0, -1 0, -1 -1, 0.1 -1, 0.1 -0))        POLYGON ((-0.070710678118655 -0.070710678118655, 0.707106781186548 0.707106781186547, 0 1.414213562373095, -0.777817459305202 0.636396103067893, -0.070710678118655 -0.070710678118655))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((1 -0, 0 0, -0 -1, 1 -1, 1 -0))               POLYGON ((-0.707106781186548 -0.707106781186547, 0 0, -0.707106781186547 0.707106781186548, -1.414213562373095 0, -0.707106781186548 -0.707106781186547))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, -1 0, -1 -1, -0 -1, 0 0))               POLYGON ((0 0, 0.707106781186548 0.707106781186547, 0 1.414213562373095, -0.707106781186547 0.707106781186548, 0 0))

query TT
SELECT
    ST_AsText(a.geom) d,
    ST_AsText(ST_Rotate(a.geom, pi(),4,7))
FROM geom_operators_test a
ORDER BY d;
----
NULL                                                   NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (8 14)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (8.5 13.5, 7.5 13.5)
LINESTRING EMPTY                                       LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (8.5 13.5)
POINT (0.5 0.5)                                        POINT (7.5 13.5)
POINT (5 5)                                            POINT (2.999999999999999 9)
POINT EMPTY                                            POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((8.1 14, 7 14, 7 13, 8.1 13, 8.1 14))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((9 14, 8 14, 8 13, 9 13, 9 14))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((8 14, 7 14, 7 13, 8 13, 8 14))


query T
SELECT
    ST_AsText(ST_Rotate(a.geom, pi(), 'POINT (6 3)'::geometry)) as t
FROM geom_operators_test a
ORDER BY t;
----
NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (12 5.999999999999999)))
GEOMETRYCOLLECTION EMPTY
LINESTRING (12.5 5.499999999999999, 11.5 5.499999999999999)
LINESTRING EMPTY
POINT (11.5 5.499999999999999)
POINT (12.5 5.499999999999999)
POINT (6.999999999999999 1)
POINT EMPTY
POLYGON ((12 5.999999999999999, 11 5.999999999999999, 11 4.999999999999999, 12 4.999999999999999, 12 5.999999999999999))
POLYGON ((12.1 5.999999999999999, 11 5.999999999999999, 11 4.999999999999999, 12.1 4.999999999999999, 12.1 5.999999999999999))
POLYGON ((13 5.999999999999999, 12 5.999999999999999, 12 4.999999999999999, 13 4.999999999999999, 13 5.999999999999999))

query T
SELECT st_asewkt(st_rotate('LINESTRING (1 5, 5 1)'::geometry,pi()/4,'POINT EMPTY'::geometry))
----
NULL

query TTTT round-in-strings
SELECT
  ST_AsText(a.geom) d,
  ST_AsEWKT(ST_SnapToGrid(a.geom, 0.1)),
  ST_AsEWKT(ST_SnapToGrid(a.geom, 0.1, 0.01)),
  ST_AsEWKT(ST_SnapToGrid(a.geom, 0.05, 0.05, 0.1, 0.01))
FROM geom_operators_test a
ORDER BY d ASC
----
NULL                                                   NULL                                                   NULL                                                   NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0.05 0)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (-0.55 0.5, 0.45 0.5)
LINESTRING EMPTY                                       LINESTRING EMPTY                                       LINESTRING EMPTY                                       LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (-0.5 0.5)                                       POINT (-0.5 0.5)                                       POINT (-0.55 0.5)
POINT (0.5 0.5)                                        POINT (0.5 0.5)                                        POINT (0.5 0.5)                                        POINT (0.45 0.5)
POINT (5 5)                                            POINT (5 5)                                            POINT (5 5)                                            POINT (5.05 5)
POINT EMPTY                                            POINT EMPTY                                            POINT EMPTY                                            POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((-0.15 0, 0.95 0, 0.95 1, -0.15 1, -0.15 0))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((-0.95 0, 0.05 0, 0.05 1, -0.95 1, -0.95 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0.05 0, 0.95 0, 0.95 1, 0.05 1, 0.05 0))

query TT
SELECT
  ST_AsText(a.geom) d,
  ST_AsText(ST_SwapOrdinates(a.geom,'Xy'))
FROM geom_operators_test a
ORDER BY d
----
NULL                                                   NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))  GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
GEOMETRYCOLLECTION EMPTY                               GEOMETRYCOLLECTION EMPTY
LINESTRING (-0.5 0.5, 0.5 0.5)                         LINESTRING (0.5 -0.5, 0.5 0.5)
LINESTRING EMPTY                                       LINESTRING EMPTY
POINT (-0.5 0.5)                                       POINT (0.5 -0.5)
POINT (0.5 0.5)                                        POINT (0.5 0.5)
POINT (5 5)                                            POINT (5 5)
POINT EMPTY                                            POINT EMPTY
POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))           POLYGON ((0 -0.1, 0 1, 1 1, 1 -0.1, 0 -0.1))
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))                 POLYGON ((0 -1, 0 0, 1 0, 1 -1, 0 -1))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))                    POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))

query TTT round-in-strings,nosort
SELECT
  ST_AsEWKT(geom::geometry),
  ST_AsEWKT(ST_S2Covering(geom::geometry)),
  ST_AsEWKT(ST_S2Covering(geom::geometry, 's2_max_cells=2'))
FROM ( VALUES
  ('POLYGON EMPTY'),
  ('LINESTRING(-30000 -40000, 15 15)'),
  ('LINESTRING(-15 -15, 15 15)'),
  ('SRID=3854;LINESTRING(56000 9000, 58000 9323)'),
  ('SRID=3857;LINESTRING(-30000 -40000, 15 15)'),
  ('SRID=3857;LINESTRING(-3004343200 -4002312300, 15 15)')
) tbl(geom)
----
POLYGON EMPTY                                          MULTIPOLYGON EMPTY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         MULTIPOLYGON EMPTY
LINESTRING (-30000 -40000, 15 15)                      MULTIPOLYGON (((-32768.5 -49152.5, -16384.5 -49152.5, -16384.5 -32768.5, -32768.5 -32768.5, -32768.5 -49152.5)), ((-32768.5 -32768.5, -0.5 -32768.5, -0.5 -0.5, -32768.5 -0.5, -32768.5 -32768.5)), ((-0.5 -0.5, 15.5 -0.5, 15.5 15.5, -0.5 15.5, -0.5 -0.5)), ((-0.5 -8.5, 7.5 -8.5, 7.5 -0.5, -0.5 -0.5, -0.5 -8.5)))                                                                                                                                                                                                                    MULTIPOLYGON (((-2147483648 -2147483648, 2147483647 -2147483648, 2147483647 2147483647, -2147483648 2147483647, -2147483648 -2147483648)))
LINESTRING (-15 -15, 15 15)                            MULTIPOLYGON (((-16.5 -16.5, -0.5 -16.5, -0.5 -0.5, -16.5 -0.5, -16.5 -16.5)), ((-4.5 -0.5, -0.5 -0.5, -0.5 3.5, -4.5 3.5, -4.5 -0.5)), ((-0.5 -0.5, 15.5 -0.5, 15.5 15.5, -0.5 15.5, -0.5 -0.5)))                                                                                                                                                                                                                                                                                                                                         MULTIPOLYGON (((-2147483648 -2147483648, 2147483647 -2147483648, 2147483647 2147483647, -2147483648 2147483647, -2147483648 -2147483648)))
SRID=3854;LINESTRING (56000 9000, 58000 9323)          SRID=3854;MULTIPOLYGON (((57138.4 8540.6, 58574.5 8540.6, 58574.5 9976.66, 57138.4 9976.66, 57138.4 8540.6)), ((55702.4 8540.6, 56420.4 8540.6, 56420.4 9258.63, 55702.4 9258.63, 55702.4 8540.6)), ((56779.4 8899.62, 57138.4 8899.62, 57138.4 9258.63, 56779.4 9258.63, 56779.4 8899.62)), ((56420.4 8899.62, 56779.4 8899.62, 56779.4 9258.63, 56420.4 9258.63, 56420.4 8899.62)))                                                                                                                                                      SRID=3854;MULTIPOLYGON (((57138.4 8540.6, 58574.5 8540.6, 58574.5 9976.66, 57138.4 9976.66, 57138.4 8540.6)), ((55702.4 8540.6, 57138.4 8540.6, 57138.4 9976.66, 55702.4 9976.66, 55702.4 8540.6)))
SRID=3857;LINESTRING (-30000 -40000, 15 15)            SRID=3857;MULTIPOLYGON (((-40724.5 -40724.5, 0 -40724.5, 0 -3.72529e-09, -40724.5 -3.72529e-09, -40724.5 -40724.5)), ((0 -3.72529e-09, 19.885 -3.72529e-09, 19.885 19.885, 0 19.885, 0 -3.72529e-09)), ((0 -4.97125, 4.97125 -4.97125, 4.97125 -3.72529e-09, 0 -3.72529e-09, 0 -4.97125)), ((0 -5.01009, 0.0388379 -5.01009, 0.0388379 -4.97125, 0 -4.97125, 0 -5.01009)))                                                                                                                                                                 SRID=3857;MULTIPOLYGON (((-2.08509e+07 -2.08509e+07, 2.08509e+07 -2.08509e+07, 2.08509e+07 2.08509e+07, -2.08509e+07 2.08509e+07, -2.08509e+07 -2.08509e+07)))
SRID=3857;LINESTRING (-3004343200 -4002312300, 15 15)  SRID=3857;MULTIPOLYGON (((-2.08509e+07 -2.08509e+07, 0 -2.08509e+07, 0 -3.72529e-09, -2.08509e+07 -3.72529e-09, -2.08509e+07 -2.08509e+07)), ((0 -3.72529e-09, 19.885 -3.72529e-09, 19.885 19.885, 0 19.885, 0 -3.72529e-09)), ((0 -4.97125, 4.97125 -4.97125, 4.97125 -3.72529e-09, 0 -3.72529e-09, 0 -4.97125)), ((0 -7.45687, 2.48562 -7.45687, 2.48562 -4.97125, 0 -4.97125, 0 -7.45687)), ((-2.08509e+07 -2.08509e+07, -2.08509e+07 -2.08509e+07, -2.08509e+07 -2.08509e+07, -2.08509e+07 -2.08509e+07, -2.08509e+07 -2.08509e+07)))  SRID=3857;MULTIPOLYGON (((-2.08509e+07 -2.08509e+07, 2.08509e+07 -2.08509e+07, 2.08509e+07 2.08509e+07, -2.08509e+07 2.08509e+07, -2.08509e+07 -2.08509e+07)), ((-2.08509e+07 -2.08509e+07, -2.08509e+07 -2.08509e+07, -2.08509e+07 -2.08509e+07, -2.08509e+07 -2.08509e+07, -2.08509e+07 -2.08509e+07)))

query TTT round-in-strings,nosort
SELECT
  ST_AsEWKT(geog::geography),
  ST_AsEWKT(ST_S2Covering(geog::geography)),
  ST_AsEWKT(ST_S2Covering(geog::geography, 's2_max_cells=2'))
FROM ( VALUES
  ('POLYGON EMPTY'),
  ('LINESTRING(15 15, 30 30)'),
  ('SRID=4004;LINESTRING(15 15, 30 30)'),
  ('SRID=4004;LINESTRING(-180 -90, 180 90)')
) tbl(geog)
----
SRID=4326;POLYGON EMPTY                  SRID=4326;MULTIPOLYGON EMPTY                                                                                                                                                                                                                                                                   SRID=4326;MULTIPOLYGON EMPTY
SRID=4326;LINESTRING (15 15, 30 30)      SRID=4326;MULTIPOLYGON (((10.6197 10.4418, 22.6199 9.8193, 22.6199 21.0375, 10.6197 22.2706, 10.6197 10.4418)), ((19.5687 21.435, 22.6199 21.0375, 22.6199 23.9177, 19.5687 24.3571, 19.5687 21.435)), ((22.6199 21.0375, 34.5085 18.95, 34.5085 29.5328, 22.6199 32.3998, 22.6199 21.0375)))  SRID=4326;MULTIPOLYGON (((0 0, 45 0, 45 35.2644, 0 45, 0 0)))
SRID=4004;LINESTRING (15 15, 30 30)      SRID=4004;MULTIPOLYGON (((10.6197 10.4418, 22.6199 9.8193, 22.6199 21.0375, 10.6197 22.2706, 10.6197 10.4418)), ((19.5687 21.435, 22.6199 21.0375, 22.6199 23.9177, 19.5687 24.3571, 19.5687 21.435)), ((22.6199 21.0375, 34.5085 18.95, 34.5085 29.5328, 22.6199 32.3998, 22.6199 21.0375)))  SRID=4004;MULTIPOLYGON (((0 0, 45 0, 45 35.2644, 0 45, 0 0)))
SRID=4004;LINESTRING (-180 -90, 180 90)  SRID=4004;MULTIPOLYGON (((45 35.2644, 135 35.2644, -135 35.2644, -45 35.2644, 45 35.2644)), ((135 35.2644, 135 -35.2644, -135 -35.2644, -135 35.2644, 135 35.2644)), ((-135 -35.2644, 135 -35.2644, 45 -35.2644, -45 -35.2644, -135 -35.2644)))                                                SRID=4004;MULTIPOLYGON (((45 35.2644, 135 35.2644, -135 35.2644, -45 35.2644, 45 35.2644)), ((135 35.2644, 135 -35.2644, -135 -35.2644, -135 35.2644, 135 35.2644)), ((-135 -35.2644, 135 -35.2644, 45 -35.2644, -45 -35.2644, -135 -35.2644)))

subtest st_memsize

query I nosort
SELECT ST_MemSize(g) FROM ( VALUES
   (ST_GeomFromText('POINT EMPTY')),
   (ST_GeomFromText('POINT (0 0)')),
   (ST_GeomFromText('POLYGON EMPTY')),
   (ST_GeomFromText('LINESTRING EMPTY')),
   (ST_GeomFromText('POLYGON ((-1 0, 1 0, 1 1, -1 1, -1 0))')),
   (ST_GeomFromText('LINESTRING (-0.5 0.5, 0.5 0.5)')),
   (ST_GeomFromText('GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))'))
) mem_size_test(g)
----
69
101
57
57
173
121
119

subtest st_pointinsidecircle

query B nosort
SELECT ST_PointInsideCircle(point, x, y, radius) FROM ( VALUES
   ((ST_Point(1,2)),    (0.5::float), (2.0::float), (3.0::float)),
   ((ST_Point(0,0)),    (3.0::float), (3.0::float), (2.0::float)),
   ((ST_Point(1,-1)),    (1.5::float), (-2.0::float), (5.0::float)),
   ((ST_Point(0,0)),    (1.0::float), (1.0::float), (1.0::float)),
   ((ST_Point(0,0)),    (1.0::float), (1.0::float), (2.0::float)),
   ((ST_Point(-1,-1)),  (1.0::float), (1.0::float), (1.0::float)),
   ((ST_Point(-1,-1)),  (1.0::float), (1.0::float), (2.0::float)),
   ((ST_Point(2.5,-2)), (2.5::float), (-1.5::float), (1.0::float)),
   ((ST_Point(2.5,-2)), (2.5::float), (-1.0::float), (0.5::float)),
   ((ST_Point(2.5,-2)), (2.5::float), (-1.5::float), (2.0::float))
) points_inside_circle(point, x, y, radius)
----
true
false
true
false
true
false
false
true
false
true

statement error pq: st_pointinsidecircle\(\): radius of the circle has to be positive
SELECT ST_PointInsideCircle(ST_Point(1,2), 0.5, 2, -3);

statement error pq: st_pointinsidecircle\(\): first parameter has to be of type Point
SELECT ST_PointInsideCircle(ST_GeomFromText('LINESTRING (-0.5 0.5, 0.5 0.5)'), 0.5, 2, -3);

subtest st_linelocatepoint

query R nosort
SELECT round(ST_LineLocatePoint(line, point)::float, 2) FROM ( VALUES
  ((ST_GeomFromText('LINESTRING (0 2, 2 0)')), (ST_Point(0, 0))),
  ((ST_GeomFromText('LINESTRING (0 0, 0 2)')), (ST_Point(1, 1))),
  ((ST_GeomFromText('LINESTRING (-1 -1, 3 3)')), (ST_Point(1, 0))),
  ((ST_GeomFromText('LINESTRING (0 1, 2 0)')), (ST_Point(0, 0))),
  ((ST_GeomFromText('LINESTRING (-1 0, 0 1)')), (ST_Point(1, 0))),
  ((ST_GeomFromText('LINESTRING (0 0, 0 1)')), (ST_Point(1, 0))),
  ((ST_GeomFromText('LINESTRING (-3 5, 4 -2)')), (ST_Point(-1, -1))),
  ((ST_GeomFromText('LINESTRING (0 0, 10 10)')), (ST_Point(0, 3))),
  ((ST_GeomFromText('LINESTRING (-5 7, 1 4)')), (ST_Point(-3, 3)))
) line_locate_point(line, point)
----
0.5
0.5
0.37
0.2
1
0
0.57
0.15
0.53

statement error pq: st_linelocatepoint\(\): first parameter has to be of type LineString
SELECT ST_LineLocatePoint(ST_GeomFromText('GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))'), ST_Point(0, 0));


query TT
SELECT
  ST_AsEWKT(ST_LineFromEncodedPolyline('ud}|Hi_juBa~kk@m}t_@'), 5),
  ST_AsEWKT(ST_LineFromEncodedPolyline('|_cw}Daosrst@udew}D`osrst@', 8), 8)
----
SRID=4326;LINESTRING (19.38949 52.09179, 24.74476 59.36716)
SRID=4326;LINESTRING (9.00000001 -1.00009999, 0 0.000011)

statement error parsing geography error
SELECT ST_AsEWKT(ST_LineFromEncodedPolyline('NO'), 5)

query TT
SELECT
  ST_AsEncodedPolyline(GeomFromEWKT('SRID=4326;LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)')),
  ST_AsEncodedPolyline(GeomFromEWKT('SRID=4326;LINESTRING(9.00000001 -1.00009999, 0.00000007 0.00000091)'), 8);
----
_p~iF~ps|U_ulLnnqC_mqNvxq`@
|_cw}Daosrst@secw}Drnsrst@

statement error only SRID 4326 is supported
SELECT ST_AsEncodedPolyline(GeomFromEWKT('SRID=4004;LINESTRING(9.00000001 -1.00009999, 0.00000007 0.00000091)'), 8);

subtest st_minimumboundingradius

query TR
SELECT ST_AsText(center), round(radius, 2) FROM ST_MinimumBoundingRadius('POLYGON((26426 65078,26531 65242,26075 65136,26096 65427,26426 65078))')
----
POINT (26284.841802713268407 65267.114509082544828)  247.44

query TR
SELECT ST_AsText(center), round(radius, 2) FROM ST_MinimumBoundingRadius('GEOMETRYCOLLECTION (LINESTRING(0 0, 4 0), POINT(0 4))')
----
POINT (2 2)  2.83

query TR
SELECT ST_AsText(center), round(radius, 2) FROM ST_MinimumBoundingRadius('LINESTRING EMPTY')
----
POINT EMPTY  0

query TR
SELECT ST_AsText(center), round(radius, 2) FROM ST_MinimumBoundingRadius('POLYGON((0 2,-2 0,0 -2,2 0,0 2))')
----
POINT (0 0)  2


subtest st_minimumboundincircle

query T
SELECT ST_AsText(ST_SnapToGrid(ST_MinimumBoundingCircle(ST_GeomFromText('GEOMETRYCOLLECTION (LINESTRING(55 75,125 150), POINT(20 80))')), 0.001));
----
POLYGON ((135.597000000000008 115, 134.384999999999991 102.689999999999998, 130.794000000000011 90.853999999999999, 124.963000000000008 79.945000000000007, 117.116 70.384, 107.555000000000007 62.536999999999999, 96.646000000000001 56.706000000000003, 84.810000000000002 53.115000000000002, 72.5 51.902999999999999, 60.189999999999998 53.115000000000002, 48.353999999999999 56.706000000000003, 37.445 62.536999999999999, 27.884 70.384, 20.036999999999999 79.945000000000007, 14.206 90.853999999999999, 10.615 102.689999999999998, 9.403 115, 10.615 127.310000000000002, 14.206 139.146000000000015, 20.036999999999999 150.055000000000007, 27.884 159.616000000000014, 37.445 167.462999999999994, 48.353999999999999 173.294000000000011, 60.189999999999998 176.884999999999991, 72.5 178.097000000000008, 84.810000000000002 176.884999999999991, 96.646000000000001 173.294000000000011, 107.555000000000007 167.462999999999994, 117.116 159.616000000000014, 124.963000000000008 150.055000000000007, 130.794000000000011 139.146000000000015, 134.384999999999991 127.310000000000002, 135.597000000000008 115))

query T
SELECT ST_AsText(ST_SnapToGrid(ST_MinimumBoundingCircle(ST_GeomFromText('GEOMETRYCOLLECTION (LINESTRING(0 0, 4 0), POINT(0 4))')), 0.001));
----
POLYGON ((4.828 2, 4.774 1.448, 4.613 0.918, 4.352 0.429, 4 0, 3.571 -0.352, 3.082 -0.613, 2.552 -0.774, 2 -0.828, 1.448 -0.774, 0.918 -0.613, 0.429 -0.352, 0 0, -0.352 0.429, -0.613 0.918, -0.774 1.448, -0.828 2, -0.774 2.552, -0.613 3.082, -0.352 3.571, 0 4, 0.429 4.352, 0.918 4.613, 1.448 4.774, 2 4.828, 2.552 4.774, 3.082 4.613, 3.571 4.352, 4 4, 4.352 3.571, 4.613 3.082, 4.774 2.552, 4.828 2))

query T
SELECT ST_AsText(ST_SnapToGrid(ST_MinimumBoundingCircle(ST_GeomFromText('POINT EMPTY')), 0.001));
----
POLYGON EMPTY

query T
SELECT ST_AsText(ST_SnapToGrid(ST_MinimumBoundingCircle(ST_GeomFromText('POINT(0 0)')), 0.001));
----
POINT (0 0)

statement error st_minimumboundingcircle\(\): value out of range: overflow
SELECT st_astext(st_minimumboundingcircle(
  st_makepoint(
    (-0.23349138300862382)::FLOAT8,
    (-1.0):::FLOAT8::FLOAT8 ^ (0.7478831141483115:::FLOAT8 - (0))::FLOAT8
  )
)) AS regression_81277

query T
SELECT ST_AsText(ST_SnapToGrid(ST_MinimumBoundingCircle(ST_GeomFromText('GEOMETRYCOLLECTION (LINESTRING(55 75,125 150), POINT(20 80))'), 4), 0.001));
----
POLYGON ((135.597000000000008 115, 130.794000000000011 90.853999999999999, 117.116 70.384, 96.646000000000001 56.706000000000003, 72.5 51.902999999999999, 48.353999999999999 56.706000000000003, 27.884 70.384, 14.206 90.853999999999999, 9.403 115, 14.206 139.146000000000015, 27.884 159.616000000000014, 48.353999999999999 173.294000000000011, 72.5 178.097000000000008, 96.646000000000001 173.294000000000011, 117.116 159.616000000000014, 130.794000000000011 139.146000000000015, 135.597000000000008 115))

query B
SELECT ST_MinimumBoundingCircle(NULL::geometry) IS NULL;
----
true

statement error st_minimumboundingcircle\(\): value out of range: overflow
select st_minimumboundingcircle(st_makepoint(((-0.27013513189303495):::FLOAT8::FLOAT8 // 5e-324:::FLOAT8::FLOAT8)::FLOAT8::FLOAT8, (-0.4968052087960828):::FLOAT8::FLOAT8)::GEOMETRY::GEOMETRY)::GEOMETRY

statement error st_minimumboundingcircle\(\): value out of range: overflow
select st_minimumboundingcircle(st_makepoint(((-0.27013513189303495):::FLOAT8::FLOAT8 // 5e-324:::FLOAT8::FLOAT8)::FLOAT8::FLOAT8, (-0.4968052087960828):::FLOAT8::FLOAT8)::GEOMETRY::GEOMETRY, 10)::GEOMETRY

subtest st_unaryunion

query T
SELECT ST_AsText(ST_UnaryUnion(ST_GeomFromText('MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))')));
----
MULTIPOLYGON (((-1 -2, -2 -2, -2 -1, -1 -1, -1 -2)), ((0 4, 4 4, 4 0, 0 0, 0 4), (2 1, 2 2, 1 2, 1 1, 2 1)))


query T
SELECT
   st_astext(st_transscale(geom,10,4,8,9)) as a
FROM geom_operators_test ORDER BY a;
----
NULL
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (80 36)))
GEOMETRYCOLLECTION EMPTY
LINESTRING (76 40.5, 84 40.5)
LINESTRING EMPTY
POINT (120 81)
POINT (76 40.5)
POINT (84 40.5)
POINT EMPTY
POLYGON ((72 36, 80 36, 80 45, 72 45, 72 36))
POLYGON ((79.200000000000003 36, 88 36, 88 45, 79.200000000000003 45, 79.200000000000003 36))
POLYGON ((80 36, 88 36, 88 45, 80 45, 80 36))


subtest st_node

query TT
SELECT
  ST_AsText(ST_Node(ST_GeomFromText('LINESTRING(1 1, 4 4, 1 4, 4 1)'))),
  ST_AsText(ST_Node(ST_GeomFromText('MULTILINESTRING((0 0, 10 10, 0 10, 10 0), (1 1, 4 4), (1 3, 4 2), (0 0, 10 10, 0 10, 10 0))')));
----
MULTILINESTRING ((1 1, 2.5 2.5), (2.5 2.5, 4 4, 1 4, 2.5 2.5), (2.5 2.5, 4 1))
MULTILINESTRING ((0 0, 1 1), (1 1, 2.5 2.5), (1 3, 2.5 2.5), (2.5 2.5, 4 4), (4 4, 5 5), (2.5 2.5, 4 2), (5 5, 10 10, 0 10, 5 5), (5 5, 10 0))

statement error geometry type is unsupported. Please pass a LineString or a MultiLineString
SELECT ST_AsText(ST_Node(ST_GeomFromText('POLYGON((1 1, 1 3, 3 3, 3 1, 1 1))')));

query T nosort
SELECT
ST_AsEWKT(
  ST_SubDivide('SRID=4326;POLYGON((132 10,119 23,85 35,68 29,66 28,49 42,32 56,22 64,32 110,40 119,36 150,
                          57 158,75 171,92 182,114 184,132 186,146 178,176 184,179 162,184 141,190 122,
                          190 100,185 79,186 56,186 52,178 34,168 18,147 13,132 10))'::geometry,10)
)
----
SRID=4326;POLYGON ((85 35, 68 29, 66 28, 32 56, 22 64, 29.826086956521738 100, 119 100, 119 23, 85 35))
SRID=4326;POLYGON ((186 52, 178 34, 168 18, 147 13, 132 10, 119 23, 119 56, 186 56, 186 52))
SRID=4326;POLYGON ((185 79, 186 56, 119 56, 119 100, 190 100, 185 79))
SRID=4326;POLYGON ((40 119, 36 150, 57 158, 75 171, 92 182, 114 184, 114 100, 29.826086956521738 100, 32 110, 40 119))
SRID=4326;POLYGON ((132 186, 146 178, 176 184, 179 162, 184 141, 190 122, 190 100, 114 100, 114 184, 132 186))

query T
SELECT ST_AsText(ST_Subdivide('POLYGON((-1 -1,-1 -0.5, -1 0, 1 0.5, 1 -1,-1 -1))'::geometry))
----
POLYGON ((-1 -1, -1 -0.5, -1 0, 1 0.5, 1 -1, -1 -1))

query T nosort
SELECT ST_AsText(ST_Subdivide('SRID=4269;LINESTRING(0 0, 10 15, 0 0, 10 15, 10 0, 10 15)'::geometry, 5))
----
LINESTRING (0 0, 5 7.5)
LINESTRING (10 7.5, 10 0)
LINESTRING (5 7.5, 10 15)
LINESTRING (10 15, 10 7.5)

statement error pq: max_vertices number cannot be less than 5
SELECT ST_AsText(ST_SubDivide(ST_GeomFromText('POLYGON((1 1, 1 3, 3 3, 3 1, 1 1))'), 4))

query T
SELECT ST_AsText(ST_VoronoiPolygons(ST_GeomFromText('MULTIPOINT(50 30, 60 30, 100 100,10 150, 110 120)'))::geometry, 1)
----
GEOMETRYCOLLECTION (POLYGON ((-110 270, 100.5 270, 59.3 132.8, 36.8 92.3, -110 43.3, -110 270)), POLYGON ((-110 -90, -110 43.3, 36.8 92.3, 55 79.3, 55 -90, -110 -90)), POLYGON ((230 -20.7, 55 79.3, 36.8 92.3, 59.3 132.8, 230 47.5, 230 -20.7)), POLYGON ((230 -90, 55 -90, 55 79.3, 230 -20.7, 230 -90)), POLYGON ((230 270, 230 47.5, 59.3 132.8, 100.5 270, 230 270)))

subtest st_voronoilines

query T
SELECT ST_AsText(ST_VoronoiLines(ST_GeomFromText('MULTIPOINT(50 30, 60 30, 100 100,10 150, 110 120)'))::geometry, 5)
----
MULTILINESTRING ((100.5 270, 59.34783 132.82609), (59.34783 132.82609, 36.81818 92.27273), (36.81818 92.27273, -110 43.33333), (36.81818 92.27273, 55 79.28571), (55 79.28571, 55 -90), (59.34783 132.82609, 230 47.5), (230 -20.71429, 55 79.28571))

query T
SELECT ST_AsText(ST_GeneratePoints('POLYGON((0 0,2 5,2.5 4,3 5,3 1,0 0))'::geometry, 5, 1996)::geometry, 5)
----
MULTIPOINT (0.69466 0.92001, 2.44176 3.71642, 2.79788 3.8425, 1.05776 1.77173, 1.79696 2.42853)

statement error pq: st_generatepoints\(\): zero area input Polygon
SELECT ST_AsText(ST_GeneratePoints('POLYGON((0 0, 1 1, 1 1, 0 0))'::geometry, 4, 1))

statement error pq: st_generatepoints\(\): seed must be greater than zero
SELECT ST_AsText(ST_GeneratePoints('POLYGON((0 0,2 5,2.5 4,3 5,3 1,0 0))'::geometry, 5, 0))

query T nosort
SELECT t AS should_be_null FROM ( VALUES
  (ST_GeneratePoints('POLYGON ((0 0, 1 0, 1 1, 0 0))', -1)),
  (ST_GeneratePoints('POLYGON ((0 0, 1 0, 1 1, 0 0))', -2, 3)),
  (ST_GeneratePoints('POLYGON EMPTY', 2)),
  (ST_GeneratePoints('POLYGON EMPTY', 2))
) t(t)
----
NULL
NULL
NULL
NULL

subtest st_orientedenvelope

query T
SELECT ST_AsText(ST_OrientedEnvelope(ST_GeomFromText('MULTIPOINT ((0 0), (-1 -1), (3 2))')));
----
POLYGON ((3 2, 2.88 2.16, -1.12 -0.84, -1 -1, 3 2))


statement error pq: st_linesubstring\(\): end must be greater or equal to the start
select st_astext(st_linesubstring('LINESTRING(0 0, 0 5, 5 5,10 3)'::geometry,0.5,0.4))

statement error pq: st_linesubstring\(\): start and and must be within 0 and 1
select st_astext(st_linesubstring('LINESTRING(0 0, 0 5, 5 5,10 3)'::geometry,0,1.4));

statement error pq: st_linesubstring\(\): end must be greater or equal to the start
select st_astext(st_linesubstring('POINT(0 0)'::geometry,0.5,0.4));

query T nosort
select st_astext(st_linesubstring(g,star,"end")::geometry, 1)from (VALUES
       ('LINESTRING(0 0, 0 5, 4 5, 4 2)'::geometry, 0.0, 0.3),
       ('LINESTRING(-25 -50, 100 125, 150 190, 40 60)'::geometry, 0.8, 0.9),
       ('LINESTRING(70 10, 10 125.6, 15.40 1.9, 4 6)'::geometry, 0.1, 0.8),
       ('LINESTRING(70 10, 10 125)'::geometry, 0.1, 0.8),
       ('LINESTRING(70 10, 10 125)'::geometry, 0.8, 0.8),
       ('LINESTRING(0 0, 0 0)'::geometry, 0.8, 0.8),
       ('LINESTRING EMPTY'::geometry, 0.1, 0.2)
    ) t(g,star, "end");
----
LINESTRING (0 0, 0 3.6)
LINESTRING (100.4 131.4, 70.2 95.7)
LINESTRING (57.7 33.6, 10 125.6, 13.6 43)
LINESTRING (64 21.5, 22 102)
POINT (22 102)
POINT (0 0)
NULL

query T nosort
SELECT ST_AsEWKT(ST_ShiftLongitude(geom)) FROM ( VALUES
  ('POINT(0 0)'::geometry),
  ('POINT(-1 90)'::geometry),
  ('POINT(181 -23)'::geometry),
  ('LINESTRING(2 2, 5 -60, 200 0)'::geometry),
  ('POLYGON((-6 -10, 6 -10, 0 20, -6 -10), (3 2, -1 -1, 1 -5, 3 2))'::geometry)
) t(geom);
----
POINT (0 0)
POINT (359 90)
POINT (-179 -23)
LINESTRING (2 2, 5 -60, -160 0)
POLYGON ((354 -10, 6 -10, 0 20, 354 -10), (3 2, 359 -1, 1 -5, 3 2))

query T nosort
SELECT ST_AsEWKT(ST_ShiftLongitude(geom)) FROM ( VALUES
  ('SRID=4326;POINT(0 0)'::geometry),
  ('SRID=4326;POINT(-1 90)'::geometry),
  ('SRID=4326;POINT(181 -23)'::geometry),
  ('SRID=4326;LINESTRING(2 2, 5 -60, 200 0)'::geometry),
  ('SRID=4326;POLYGON((-6 -10, 6 -10, 0 20, -6 -10), (3 2, -1 -1, 1 -5, 3 2))'::geometry)
) t(geom);
----
SRID=4326;POINT (0 0)
SRID=4326;POINT (359 90)
SRID=4326;POINT (-179 -23)
SRID=4326;LINESTRING (2 2, 5 -60, -160 0)
SRID=4326;POLYGON ((354 -10, 6 -10, 0 20, 354 -10), (3 2, 359 -1, 1 -5, 3 2))

query T
SELECT ST_AsText(
    ST_Snap(poly,line, ST_Distance(poly, line)*1.25)
) AS polysnapped
FROM (SELECT
    ST_GeomFromText('MULTIPOLYGON(
      (( 26 125, 26 200, 126 200, 126 125, 26 125 ),
      ( 51 150, 101 150, 76 175, 51 150 )),
      (( 151 100, 151 200, 176 175, 151 100 )))') As poly,
    ST_GeomFromText('LINESTRING (5 107, 54 84, 101 100)') As line
	) tbl(poly, line);
----
MULTIPOLYGON (((5 107, 26 200, 126 200, 126 125, 101 100, 54 84, 5 107), (51 150, 101 150, 76 175, 51 150)), ((151 100, 151 200, 176 175, 151 100)))

query TTT
SELECT
  ST_EstimatedExtent('a', 'b', 'c', false),
  ST_EstimatedExtent('a', 'b', 'c'),
  ST_EstimatedExtent('a', 'b')
----
NULL  NULL  NULL

query II nosort
SELECT ST_LineCrossingDirection(line1, line2), ST_LineCrossingDirection(line2, line1) FROM ( VALUES
    ((ST_GeomFromText('LINESTRING(0 -20, 0 20)')), (ST_GeomFromText('LINESTRING(5 5, 5 10)'))),
    ((ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)')), (ST_GeomFromText('LINESTRING(171 154,20 140,71 74,161 53)'))),
    ((ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)')), (ST_GeomFromText('LINESTRING (20 140, 71 74, 161 53)'))),
    ((ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)')), (ST_GeomFromText('LINESTRING (171 154, 20 140, 71 74, 2.99 90.16)'))),
    ((ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)')), (ST_GeomFromText('LINESTRING(2.99 90.16,71 74,20 140,171 154)')))
) line_crossing_direction_test(line1, line2);
----
0   0
3   -3
-1  1
2   -2
-2  2

# NaN coordinates do not work with PIP.
query BBB nosort
SELECT ST_Intersects(point, polygon), ST_Within(point, polygon), ST_Contains(polygon, point)
FROM ( VALUES
  (ST_MakePoint('NaN', 1), 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry),
  (ST_MakePoint(0, 1), ST_MakePolygon(ST_AddPoint(ST_AddPoint('LINESTRING(0 0, 1 0)', ST_MakePoint(0, 'NaN')), ST_MakePoint(0, 0))))
) t(point, polygon)
----
false  false  false
false  false  false

# ST_MakeEnvelope
query T
SELECT ST_AsEWKT(ST_MakeEnvelope(30.01,50.01,72.01,52.01,4326))
----
SRID=4326;POLYGON ((30.010000000000002 50.009999999999998, 30.010000000000002 52.009999999999998, 72.010000000000005 52.009999999999998, 72.010000000000005 50.009999999999998, 30.010000000000002 50.009999999999998))

query T
SELECT ST_AsEWKT(ST_MakeEnvelope(30.01,50.01,72.01,52.01))
----
POLYGON ((30.010000000000002 50.009999999999998, 30.010000000000002 52.009999999999998, 72.010000000000005 52.009999999999998, 72.010000000000005 50.009999999999998, 30.010000000000002 50.009999999999998))

subtest st_bdpolyfromtext

query TTT
SELECT
  ST_AsText(ST_BdPolyFromText('MULTILINESTRING((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))', 4326)),
  ST_AsText(ST_BdPolyFromText('MULTILINESTRING((0 0, 1 0, 1 1, 0 1, 0 0))', 4326)),
  ST_AsEWKT(ST_BdPolyFromText('MULTILINESTRING((0 0, 1 0, 1 1, 0 1, 0 0))', 4326))
----
POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)) POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) SRID=4326;POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))

query TT
SELECT
  ST_AsEWKT(ST_BdPolyFromText(NULL, 4326)),
  ST_AsEWKT(ST_BdPolyFromText('MULTILINESTRING((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))', NULL))
----
NULL NULL

statement error pq: st_bdpolyfromtext\(\): argument must be MULTILINESTRING geometry
SELECT ST_AsText(ST_BdPolyFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 4326))

statement error pq: st_bdpolyfromtext\(\): argument must be MULTILINESTRING geometry
SELECT ST_AsText(ST_BdPolyFromText('LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)', 4326))

statement error pq: st_bdpolyfromtext\(\): argument must be MULTILINESTRING geometry
SELECT ST_AsText(ST_BdPolyFromText('POINT(0 0)', 4326))

subtest st_asmvtgeom

query T
SELECT ST_AsText(ST_AsMVTGeom(
    ST_GeomFromText('LINESTRING (0 0, 10.6 0.4, 10.6 5.4, 0 -5, 0 0)'),
    ST_MakeBox2D(ST_Point(0, 0), ST_Point(20, 20)),
    20, 0, false))
----
LINESTRING (0 20, 11 20, 11 15, 0 25, 0 20)

statement error buffer value cannot be negative
SELECT ST_AsText(ST_AsMVTGeom(
    ST_GeomFromText('LINESTRING (0 0, 10.6 0.4, 10.6 5.4, 0 -5, 0 0)'),
    ST_MakeBox2D(ST_Point(0, 0), ST_Point(20, 20)),
    20, -1, false))

query T
SELECT st_asmvtgeom(
  '0103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000'::GEOMETRY,
  'BOX(-0.7283491852530968 -1.8211168776573217,0.5639272771291987 1.4483176236186077)'::BOX2D,
  1,
  34268045,
  true
) AS regression_109113
----
NULL

subtest end

subtest regression_103616

# Regression test for #103616
statement ok
CREATE TABLE t103616 (
  tag string,
  geog GEOGRAPHY,
  geom GEOMETRY,
  INVERTED INDEX geog_idx (geog),
  INVERTED INDEX geom_idx (geom)
);

statement ok
insert into t103616 values ('null', null, null);

statement ok
insert into t103616 values ('point (0 0)', 'POINT(0 0)'::GEOGRAPHY, 'POINT(0 0)'::GEOMETRY);

statement ok
insert into t103616 values ('point (10 10)', 'POINT(10 10)'::GEOGRAPHY, 'POINT(10 10)'::GEOMETRY);

statement ok
insert into t103616 values ('empty 1', ST_GeogFromText('POLYGON EMPTY'), ST_GeomFromText('POLYGON EMPTY'));

statement ok
insert into t103616 values ('empty 2', ST_GeogFromText('GEOMETRYCOLLECTION EMPTY'), ST_GeomFromText('GEOMETRYCOLLECTION EMPTY'));

# Null and empty geog values should not appear in the output.
query T rowsort
SELECT tag FROM t103616@geog_idx
WHERE
    st_distance(geog, 'POINT(0 0)'::GEOGRAPHY, false) = 0;
----
point (0 0)

# Null and empty geog values should not appear in the output.
query T rowsort
SELECT tag FROM t103616@geog_idx
WHERE
    st_distance(geog, 'POINT(0 0)'::GEOGRAPHY, false) = 0;
----
point (0 0)

# Null and empty geog values should not appear in the output.
query T rowsort
SELECT tag FROM t103616@geog_idx
WHERE
    NOT 1.2345678901234566e-43 < st_distance(geog, 'POINT(0 0)'::GEOGRAPHY);
----
point (0 0)

# Null and empty geog values should not appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    NOT 1.2345678901234566e-43 > st_distance(geog, 'POINT(0 0)'::GEOGRAPHY);
----
point (10 10)

# Null and empty geog values should not appear in the output.
query T rowsort
SELECT tag FROM t103616@geog_idx
WHERE
    1.2345678901234566e-43 > st_distance(geog, 'POINT(0 0)'::GEOGRAPHY);
----
point (0 0)

# Null and empty geog values should not appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    1.2345678901234566e-43 < st_distance(geog, 'POINT(0 0)'::GEOGRAPHY);
----
point (10 10)

# Null and empty geog values should not appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    0 <= st_distance(geog, 'POINT(0 0)'::GEOGRAPHY);
----
point (0 0)
point (10 10)

# Only null and empty geog values should appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    (st_distance(geog, 'POINT(0 0)'::GEOGRAPHY, false) = 0) IS NULL;
----
null
empty 1
empty 2

# Only null and empty geog values should appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    (0 <= st_distance(geog, 'POINT(0 0)'::GEOGRAPHY)) IS NULL;
----
null
empty 1
empty 2

# Null and empty geom values should appear in the output.
query T rowsort
SELECT tag FROM t103616@geom_idx
WHERE
    NOT 1.2345678901234566e-43 < st_maxdistance(geom, 'POINT(0 0)'::GEOMETRY);
----
point (0 0)

# Null and empty geom values should not appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    NOT 1.2345678901234566e-43 > st_maxdistance(geom, 'POINT(0 0)'::GEOMETRY);
----
point (10 10)

# Null and empty geom values should not appear in the output.
query T rowsort
SELECT tag FROM t103616@geom_idx
WHERE
    1.2345678901234566e-43 > st_maxdistance(geom, 'POINT(0 0)'::GEOMETRY);
----
point (0 0)

# Null and empty geom values should not appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    1.2345678901234566e-43 < st_maxdistance(geom, 'POINT(0 0)'::GEOMETRY);
----
point (10 10)

# Null and empty geom values should not appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    0 <= st_maxdistance(geom, 'POINT(0 0)'::GEOMETRY);
----
point (0 0)
point (10 10)

# Only null and empty geog values should appear in the output.
query T rowsort
SELECT tag FROM t103616
WHERE
    (0 <= st_maxdistance(geom, 'POINT(0 0)'::GEOMETRY)) IS NULL;
----
null
empty 1
empty 2

# Regression test for #111556. st_union produces different results depending on
# the number of duplicate values, so it should not ignore duplicate values. This
# test ensures that the optimizer does not eliminate joins and change the number
# of input values to an st_union aggregate.
subtest regression_111556

# Create a table for input and a table for results of the st_union aggregate.
statement ok
CREATE TABLE t111556_in (g GEOMETRY NOT NULL);
CREATE TABLE t111556_res (g GEOMETRY);

# Insert two identical values in the input table
statement ok
INSERT INTO t111556_in(g)
SELECT '0103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000'
FROM generate_series(1, 2)

# Perform an st_union aggregate and insert the results into the table.
statement ok
INSERT INTO t111556_res
SELECT st_union(t2.g) FROM t111556_in t1 JOIN t111556_in t2 ON t1.g = t2.g

# Turn off all optimizations.
statement ok
SET testing_optimizer_disable_rule_probability = 1.0

# Perform the same st_union aggregate and insert the results into the table.
statement ok
INSERT INTO t111556_res
SELECT st_union(t2.g) FROM t111556_in t1 JOIN t111556_in t2 ON t1.g = t2.g

# Count the number of distinct values in the results table. It should be 1
# because the INSERTS above should insert the same value.
query I
SELECT count(DISTINCT g) FROM t111556_res
----
1

statement ok
SET testing_optimizer_disable_rule_probability = 0

subtest end


subtest regressions

# Regression test for #111157
query T
SELECT ST_Extent(ST_GeomFromGeoHash('C'::TEXT, NULL::INT4)::GEOMETRY);
----
BOX(-135 45,-90 90)

query T
SELECT ST_Extent(ST_GeomFromGeoHash(NULL::TEXT, 1::INT4)::GEOMETRY);
----
NULL

query T
SELECT ST_Extent(ST_PointFromGeoHash('C'::TEXT, NULL::INT4)::GEOMETRY);
----
BOX(-112.5 67.5,-112.5 67.5)

query T
SELECT ST_Extent(ST_PointFromGeoHash(NULL::TEXT, 1::INT4)::GEOMETRY);
----
NULL

# X min > X max
query T
SELECT ST_AsEWKT(ST_MakeEnvelope(8.0::FLOAT8, 2.0::FLOAT8, 5.0::FLOAT8, 4.0::FLOAT8)::GEOMETRY);
----
POLYGON ((8 2, 8 4, 5 4, 5 2, 8 2))

# Y min > Y max
query T
SELECT ST_AsEWKT(ST_MakeEnvelope(5.0::FLOAT8, 4.0::FLOAT8, 8.0::FLOAT8, 2.0::FLOAT8)::GEOMETRY);
----
POLYGON ((5 4, 5 2, 8 2, 8 4, 5 4))

subtest end

subtest st_tileenvelope

query T
SELECT ST_TileEnvelope(NULL, NULL, NULL);
----
NULL

query T
SELECT ST_AsText(ST_TileEnvelope(8, 1, 2));
----
POLYGON ((-19880965.308861203491688 19567879.241005122661591, -19880965.308861203491688 19724422.274933163076639, -19724422.274933163076639 19724422.274933163076639, -19724422.274933163076639 19567879.241005122661591, -19880965.308861203491688 19567879.241005122661591))

query T
SELECT ST_TileEnvelope(8, 1, 2, NULL);
----
NULL

query T
SELECT ST_AsText(ST_TileEnvelope(3, 1, 1, ST_MakeEnvelope(-180, -90, 180, 90, 4326)) );
----
POLYGON ((-135 45, -135 67.5, -90 67.5, -90 45, -135 45))

query T
SELECT ST_TileEnvelope(3, 1, 1, ST_MakeEnvelope(-180, -90, 180, 90, 4326), NULL);
----
NULL

query T
SELECT ST_AsText(ST_TileEnvelope(3, 1, 1, ST_MakeEnvelope(-180, -90, 180, 90, 4326), 0.125));
----
POLYGON ((-140.625 42.1875, -140.625 70.3125, -84.375 70.3125, -84.375 42.1875, -140.625 42.1875))

statement error pgcode 22023 pq: st_tileenvelope\(\): Unable to compute bbox
SELECT st_tileenvelope(0, 0, 0, '010500000000000000');

subtest end

# Regression test for not respecting max_decimal_digits argument of the
# st_geojson builtin function (#124368).
query T
SELECT st_asgeojson(tbl.*, 'g', 4)::JSONB->'geometry'->'coordinates'
  FROM (VALUES ('SRID=4326;POINT (-123.45678901234 12.3456789012)'::GEOMETRY)) tbl(g);
----
[-123.4568, 12.3457]
