PostgreSQL slope() Function

The PostgreSQL slope() function calculates and returns the slope of a line passing through two specified points.

slope() Syntax

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

slope(point1, point2) -> double precision

Parameters

point1

Required. A point. For example: point '(0,0)'.

point2

Required. A point. For example: point '(4,4)'.

Return value

The PostgreSQL slope() function returns the slope of a line passing through two specified points.

slope() Examples

The following statement shows how to use the PostgreSQL slope() function to calculate the slope of a line passing through the two points (4,4) and (0,0).

SELECT slope(point '(4,4)', point '(0,0)');
 slope
-------
     1

The following statement shows how to use the PostgreSQL slope() function to calculate the slope of a line passing through the two points (-4,4) and (0,0).

SELECT slope(point '(-4,4)', point '(0,0)');
 slope
-------
    -1