A bounding box of a geometry can be accessed in two ways. The first is to create a Box2D type from a geometry (or a set of them):
SELECT ST_Extent(
ST_GeomFromText('POLYGON((391390 5817855,391490 5817955,391590 5818055, 319590 5817855,391390 5817855))', 32633)
);
st_extent
------------------------------------
BOX(319590 5817855,391590 5818055)
Then to create one for a set of geometries:
SELECT ST_Extent(geom) FROM sometable;
ST_Extent is an aggregate function, so the usual rules of using the GROUP BY clause apply.
The second method is to access individual BBOX elements separately. For that, ST_XMin, ST_YMin, ST_XMax, and ST_YMax (and ST_ZMax for 3D geometries) are provided:
SELECT ST_XMin(
ST_GeomFromText('POLYGON((391390 5817855,391490 5817955,391590 5818055, 319590 5817855,391390 5817855))', 32633)
);
st_xmin
---------
319590
For geometries already stored in a table, we can use the following:
SELECT ST_XMin(geom), ST_YMin(geom), ST_XMax(geom), ST_YMax(geom) FROM sometable;
This function is not an aggregate, so for computing individual extreme coordinates for sets of geometries, they need to be aggregated first using the ST_Collect function that we learned about before.