In PostgreSQL, cot()
is a trigonometric function that returns the cotangent of the specified angle.
The angle is provided as an argument, specified in radians.
In trigonometry, in a right triangle, the cotangent of an angle is the length of the adjacent side divided by the length of the opposite side.
Syntax
The syntax goes like this:
cot(x)
Where x
is a double precision value that is interpreted as number of radians.
Example
Here’s an example to demonstrate how it works.
SELECT cot(1);
Result:
0.6420926159343308
Fractions
The argument can contain a fractional component.
SELECT cot(1.2490);
Result:
0.33338419232963085
Negative Argument
The argument can also be negative.
SELECT cot(-1.2490);
Result:
-0.33338419232963085
Expressions
The argument can include expressions.
SELECT cot(.5 * .45);
Result:
4.369190092810183
Pi
Here’s an example that includes the pi()
function.
SELECT cot(pi()/3);
Result:
0.577350269189626
Zero Argument
The argument provided to cot()
must be non-zero, as the cotangent of zero doesn’t exist.
Here’s the result I get when I pass zero as an argument.
SELECT cot(0);
Result:
Infinity
Specify the Angle in Degrees
As mentioned, cot()
accepts its argument in radians. To provide it in degrees, use the cotd()
function.
The cotd()
function works exactly the same as cot()
, except that its argument is specified in degrees instead of radians.