How Cos() Works in PostgreSQL

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

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

Syntax

The syntax goes like this:

cos(x)

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

Example

Here’s an example to demonstrate how it works.

SELECT cos(15);

Result:

-0.7596879128588212

Fractions

The angle can contain a fractional component.

SELECT cos(12.15);

Result:

0.9145628431984176

Negative Angles

The angle can be negative.

SELECT cos(-197);

Result:

-0.6055518643146514

Expressions

The argument can include expressions.

SELECT cos(10 * 5);

Result:

0.9649660284921133

Specify the Angle in Degrees

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

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