Only this week, get the SQL Complete Track of 9 courses in a special prize of $330 $89!
Functions returning geometries
11. ST_GeometryN


Nicely done! There are a couple of small functions that can be used to work with collections. We will discuss a few that may prove useful.

The first function is ST_GeometryN(geometry, n). It returns the nth geometry in the collection, for instance:

FROM sf_chains;

The query above will return the first element of each collection in sf_chains.

Note that elements in the collection are numbered starting from 1.


Mark has taken a particular liking to one of the Aquamarine Prairie Hotel & Spa (id = 2). For the row with id = 2 in the sf_chains table, return the third item in the internal PostGIS format, its text representation and the description column.

Stuck? Here's a hint!

Use ST_GeometryN(geo_data,3). Then, surround this call with ST_AsText.