PostgreSQL ACOS() Function
The PostgreSQL ACOS() function returns arc cosine of a value. The returned value will be in the range 0 through 𝜋. The other variant of this function is ACOSD() which returns the result in degrees.
If the argument is not within the range of -1 to 1, then this function returns an error.
Note: ACOS() is the inverse of COS().
Syntax
/* returns result in radians */ ACOS(x) /* returns result in degrees */ ACOSD(x)
Parameters
x |
Required. Specify the value. |
Return Value
Returns the arc cosine of the value.
Example 1:
The example below shows the usage of ACOS() function.
SELECT ACOS(0.2); Result: 1.369438406004566 SELECT ACOS(0.8); Result: 0.6435011087932843 SELECT ACOS(1); Result: 0 SELECT ACOS(-1); Result: 3.141592653589793 SELECT ACOS(0); Result: 1.5707963267948966 SELECT ACOS(-0.2); Result: 1.7721542475852274 SELECT ACOSD(-0.2); Result: 101.53695903281549 SELECT ACOSD(-1); Result: 180
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | -1 |
Data 2 | -0.5 |
Data 3 | 0 |
Data 4 | 0.5 |
Data 5 | 1 |
The statement given below can be used to calculate the arc cosine of records of column x.
SELECT *, ACOS(x) AS ACOS_Value FROM Sample;
This will produce the result as shown below:
Data | x | ACOS_Value |
---|---|---|
Data 1 | -1 | 3.141592653589793 |
Data 2 | -0.5 | 2.0943951023931957 |
Data 3 | 0 | 1.5707963267948966 |
Data 4 | 0.5 | 1.0471975511965979 |
Data 5 | 1 | 0 |
❮ PostgreSQL Functions