When you SELECT a column FROM a table, the column value(s) are made available to functions, either per row, or as aggregates. Function results can be passed consecutively into enclosing functions.
In this case you would simply
SELECT ST_AsText(ST_Segmentize(geom::GEOGRAPHY, 50)) AS geom
FROM public.segments
;
Note that I use a cast (::) to GEOGRAPHY; since you intent to use meter as distance threshold, you either need your geometries projected in a suitable CRS (with meter as unit), or the GEOGRAPHY type, which implicitly uses meter as unit; this only works on geographic reference systems, and the cast assumes EPSG:4326 (WGS84) as the default.
However:
ST_Segmentize only inserts vertices to ensure no two vertices are further apart than the given threshold (the definition of a segment is a geometry part between two vertices)!
To obtain individual geometries representing parts of your 'segments' with a max. length, you'd need to get more involved; there is no simple command as of yet.
There are multiple possibilities, e.g.:
- create line 'segments' from the densified lines (following the usage of
ST_Segmentize above); you'd get 'segments' with arbitrary lines not longer than the threshold given to ST_Segmentize.
- create line 'segments' of fixed length, using
ST_LineSubstring; well defined line length, e.g. you could find a length that divides a line equally
For your case (initial two-vertice 'segments' will have segments with exactly 50m length, except the last one with up to 50m length), the first approach should work just fine:
WITH
densified AS (
SELECT <id>, -- ROW_NUMBER() OVER() AS id
ST_AsText(ST_Segmentize(geom, 50)) AS geom
FROM public.segments
)
SELECT id AS line_id,
path[1] AS segment_id,
geom
FROM (
SELECT d.id,
dmp.path,
ST_MakeLine(dmp.geom, LEAD(dmp.geom) OVER(PARTITION BY d.id ORDER BY dmp.path)) AS geom
FROM densified AS d,
LATERAL ST_DumpPoints(d.geom) AS dmp
) q
WHERE geom IS NOT NULL
;
Don't forget to replace <id> with the actual id column of your table, or use the commented out ROW_NUMBER
Note that I do not use a cast to GEOGRAPHY, since your mentioned CRS is a metric projection already.