PostgreSQL length() Function

The PostgreSQL length() function calculates the total length of the specified line segment or path and returns it.

length() Syntax

This is the syntax of the PostgreSQL length() function:

length(geometric_type) -> double precision

Parameters

geometric_type

Required. It can be lseg, path.

Return value

The PostgreSQL length() function returns the total length of the line segment or path specified by the parameter.

length() Examples

The following statement shows how to use PostgreSQL length() function to calculate the total length of path '[(2,0),(0,0)]'.

SELECT length(path '[(2,0),(0,0)]');
 length
--------
      2

The following statement shows how to use PostgreSQL length() function to calculate the total length of path '((2,0),(0,0))'.

SELECT length(path '((2,0),(0,0))');
 length
--------
      4

The following statement shows how to use PostgreSQL length() function to calculate the total length of lseg '(2,0),(0,0)'.

SELECT length(lseg '(2,0),(0,0)');
 length
--------
      2