PostgreSQL TAN() Function
The PostgreSQL TAN() function returns trigonometric tangent of an angle (angle should be in radians). The other variant of this function is TAND() which returns trigonometric tangent of an angle (angle should be in degrees).
Syntax
/* specify angle in radians */ TAN(x) /* specify angle in degrees */ TAND(x)
Parameters
x |
Required. Specify the angle. |
Return Value
Returns the trigonometric tangent of an angle.
Example 1:
The example below shows the usage of TAN() function.
SELECT TAN(0); Result: 0 SELECT TAN(1); Result: 1.5574077246549023 SELECT TAN(-1); Result: -1.5574077246549023 SELECT TAN(2); Result: -2.185039863261519 SELECT TAN(-2); Result: 2.185039863261519 SELECT TAN(PI()); Result: -1.2246467991473532e-16 SELECT TAND(30); Result: 0.5773502691896257 SELECT TAND(45); Result: 1 SELECT TAND(90); Result: Infinity
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | -10 |
Data 2 | -5 |
Data 3 | 0 |
Data 4 | 5 |
Data 5 | 10 |
The statement given below can be used to calculate the trigonometric tangent value of column x.
SELECT *, TAN(x) AS TAN_Value FROM Sample;
This will produce the result as shown below:
Data | x | TAN_Value |
---|---|---|
Data 1 | -10 | -0.6483608274590866 |
Data 2 | -5 | 3.380515006246586 |
Data 3 | 0 | 0 |
Data 4 | 5 | -3.380515006246586 |
Data 5 | 10 | 0.6483608274590866 |
❮ PostgreSQL Functions