[PostGIS] #5987: ST_GeometryN breaks for unitary geometries

PostGIS trac at osgeo.org
Mon Sep 15 07:05:01 PDT 2025


#5987: ST_GeometryN breaks for unitary geometries
---------------------+---------------------------
 Reporter:  joto     |      Owner:  pramsey
     Type:  defect   |     Status:  new
 Priority:  high     |  Milestone:  PostGIS 3.6.1
Component:  postgis  |    Version:  3.6.x
 Keywords:           |
---------------------+---------------------------
 ST_GeometryN seems to be broken for unitary geometries in PostGIS 3.6.

 Tested with Postgresql17 + Postgis 3.6 from the PostgreSQL Debian
 repository:
 (POSTGIS="3.6.0 4c1967d" [EXTENSION] PGSQL="170"
 GEOS="3.11.1-CAPI-1.17.1")

 == ST_Point

 Running ST_GeometryN against a point returns a bogus value.

 {{{
 gis=# CREATE TABLE test (geom geometry(Geometry,4326));
 CREATE TABLE
 gis=# INSERT INTO test VALUES('POINT(20 20)'::geometry);
 INSERT 0 1
 gis=# SELECT ST_AsText(geom), ST_AsText(ST_GeometryN(geom, 1)) FROM test;
   st_astext   |          st_astext
 --------------+-----------------------------
  POINT(20 20) | POINT(2.125000000242608 20)
 (1 row)
 }}}

 The same queries on Postgis 3.5 return the correct point:

 {{{
 gis=# SELECT ST_AsText(geom), ST_AsText(ST_GeometryN(geom, 1)) FROM test;
   st_astext   |  st_astext
 --------------+--------------
  POINT(20 20) | POINT(20 20)
 (1 row)
 }}}

 == ST_LineString

 Running ST_GeometryN against a linestring results in an internal error:

 {{{
 gis=# CREATE TABLE test (geom geometry(Geometry,4326));
 CREATE TABLE
 gis=# INSERT INTO test VALUES('LINESTRING(20 20,20.1 20,20.2
 19.9)'::geometry);
 INSERT 0 1
 gis=# SELECT ST_AsText(geom), ST_AsText(ST_GeometryN(geom, 1)) FROM test;
 ERROR:  Unknown geometry type: 1101004800 - Unknown
 }}}

 Again, PostGIS 3.5 returns the original geometry as expected:

 {{{
 gis=# SELECT ST_AsText(geom), ST_AsText(ST_GeometryN(geom, 1)) FROM test;
               st_astext              |              st_astext
 -------------------------------------+-------------------------------------
  LINESTRING(20 20,20.1 20,20.2 19.9) | LINESTRING(20 20,20.1 20,20.2 19.9)
 (1 row)
 }}}
-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5987>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list