PostgreSQL COS() Function
The PostgreSQL COS() function returns trigonometric cosine of an angle (angle should be in radians). The other variant of this function is COSD() which returns trigonometric cosine of an angle (angle should be in degrees).
Syntax
/* specify angle in radians */ COS(x) /* specify angle in degrees */ COSD(x)
Parameters
x |
Required. Specify the angle. |
Return Value
Returns the trigonometric cosine of an angle.
Example 1:
The example below shows the usage of COS() function.
SELECT COS(0); Result: 1 SELECT COS(1); Result: 0.5403023058681398 SELECT COS(-1); Result: 0.5403023058681398 SELECT COS(2); Result: -0.4161468365471424 SELECT COS(-2); Result: -0.4161468365471424 SELECT COS(PI()); Result: -1 SELECT COSD(30); Result: 0.8660254037844387 SELECT COSD(45); Result: 0.7071067811865475 SELECT COSD(90); Result: 0
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 cosine value of column x.
SELECT *, COS(x) AS COS_Value FROM Sample;
This will produce the result as shown below:
Data | x | COS_Value |
---|---|---|
Data 1 | -10 | -0.8390715290764524 |
Data 2 | -5 | 0.28366218546322625 |
Data 3 | 0 | 1 |
Data 4 | 5 | 0.28366218546322625 |
Data 5 | 10 | -0.8390715290764524 |
❮ PostgreSQL Functions