How Tan() Works in PostgreSQL

In PostgreSQL, tan() is a mathematical function that returns the tangent of the input expression.

The input expression is provided as an argument, and it is specified in radians.

In trigonometry, in a right-angled triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side.

Syntax

The syntax goes like this:

tan(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 tan(1);

Result:

1.557407724654902

Fractions

The argument can (and usually will) contain a fractional component.

SELECT tan(1.2490);

Result:

2.9995423388618807

Negative Argument

The argument can also be negative.

SELECT tan(-1.2490);

Result:

-2.9995423388618807

Expressions

The argument can include expressions.

SELECT tan(.5 * .45);

Result:

0.22887537020775817

Pi

Here’s an example that includes the pi() function.

SELECT tan(pi()/2);

Result:

1.633123935319537e+16

Specify the Angle in Degrees

As mentioned, tan() accepts its argument in radians. To provide it in degrees, use the tand() function.

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