PostgreSQL area() Function

The PostgreSQL area() function to calculate the area of ​​a specified shape. It works for box, path, circle.

area() Syntax

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

area(geometric_type) -> double precision

Parameters

geometric_type

Required. A closed figure. It can be box, path, or circle. The path must be a closed path.

Return value

The PostgreSQL area() function returns the area of ​​the specified shape. It returns NULL if the argument is an open path.

area() Examples

The following statement shows how to use PostgreSQL to area() to calculate the area of ​​a box.

SELECT area(box '(2,2),(0,0)');
 area
------
    4

The following statement shows how to calculate the area of ​​a circle using PostgreSQL area().

SELECT area(circle '<(0,0),2>');
        area
--------------------
 12.566370614359172

The following statement shows how to calculate the area of ​​a closed path using PostgreSQL area().

SELECT area(path '((0,0),(1,1),(2,0))');
 area
------
    1