SQL COT: Calculates Cotangent of an Argument

The SQL COT function returns the cotangent of an input argument.

In math, given the ABC triangle, the cotangent of an angle (A) is defined as the ratio between the length of the adjacent side (b) to the length of the opposite side (a) as the follownig formula:

cot A = b / aCode language: SQL (Structured Query Language) (sql)
SQL_trigonometry_triangle

Syntax

The following statement shows the syntax of the COT function.

COT(numeric_expression)Code language: SQL (Structured Query Language) (sql)

Argument

The COT function accepts a numeric_expression that represents the angle in radians for which the cotangent is calculated. The numeric_expression must not evaluate to zero.

Return

The COT function returns a floating-point number.

Examples

The following example returns the cotangents of  π/6 and π/4.

SELECT COT(PI()/6) cot_one_sixth_pi, 
       COT(PI()/4) cot_one_fourth_pi;
Code language: SQL (Structured Query Language) (sql)
 cot_one_sixth_pi | cot_one_fourth_pi
------------------+-------------------
 1.73205080756888 |                 1
(1 row)Code language: SQL (Structured Query Language) (sql)

Note that we use the PI function to get the π constant.

Most database systems support the COT function with the same behavior.

Was this tutorial helpful ?