Opened 15 months ago

Closed 9 months ago

#5478 closed enhancement (wontfix)

ST_GeometryN should thrown an error when requesting the 0th geometry

Reported by: jgh Owned by: pramsey
Priority: low Milestone: PostGIS 3.5.0
Component: postgis Version: 3.3.x
Keywords: Cc:

Description

ST_GeometryN(geom,index) is using a 1-based index and was, in the past, using a 0-based index.

Calling it with index 0 returns null.

I suggest to throw an error (index is out of bound, or index should be > 0) in such situation, as it can never succeed.

For a bit of context, it was noticed during a column type change (multi to single) as all geometries vanished.

alter table test 
  alter column geom type geometry(linestring,4326) 
    using st_geometryN(geom,0);

Change History (3)

comment:1 by robe, 12 months ago

Milestone: PostGIS 3.3.5PostGIS 3.5.0

This can only go in 3.5.0 since it is a change in behavior.

comment:2 by pramsey, 10 months ago

In general we have found that less "exception throwy" approaches are more beloved than approaches that stop the flow of the SQL statement. The issue being that the whole SQL statement stops, and you have no idea what particular issue stopped it. So exception throwy things tend to be hostile to end users.

comment:3 by pramsey, 9 months ago

Resolution: wontfix
Status: newclosed

Having just added more of these accessors with NULL return rather than errors, I'm closing it out. It's just not the way we handle the case.

Note: See TracTickets for help on using tickets.