How Cosd() Works in PostgreSQL

In PostgreSQL, cosd() is a mathematical function that returns the trigonometric cosine of the specified angle, as measured in degrees.

You specify the angle by providing an argument to the function when calling it.

Syntax

The syntax goes like this:

cosd(x)

Where x is a double precision value that represents the angle (in degrees) for which you want the cosine returned.

Example

Here’s an example to demonstrate how it works.

SELECT cosd(15);

Result:

0.9659258262890683

Fractions

The angle can contain a fractional component.

SELECT cosd(12.15);

Result:

0.9775999377647907

Negative Angles

The angle can be negative.

SELECT cosd(-197);

Result:

-0.9563047559630354

Expressions

The argument can include expressions.

SELECT cosd(10 * 5);

Result:

0.6427876096865393

Specify the Angle in Radians

As mentioned, the angle you provide to cosd() is specified in degrees. To specify it in radians, use the cos() function.

The cos() function works exactly the same as cosd(), except that its argument is specified in radians instead of degrees.