In PostgreSQL, asin()
is a mathematical function that returns the angle, in radians, whose sine is the specified expression.
In other words, it returns the arcsine of its argument.
The arcsine is typically used to find the measure of an angle when two sides of a right triangle are known.
The arcsine is the inverse of the sine function. To return the sine in Postgres, use sin()
to specify the angle in radians, or sind()
to specify it in degrees.
Syntax
The syntax goes like this:
asin(x)
Where x
is a double precision value.
Example
Here’s an example to demonstrate how it works.
SELECT asin(1);
Result:
1.5707963267948966
By providing a value of 1 to asin()
, we get a value that is equivalent to π/2.
I can use the pi()
function to verify this.
SELECT
asin(1),
(pi()/2) AS "pi/2";
Result:
asin | pi/2 --------------------+-------------------- 1.5707963267948966 | 1.5707963267948966
Fractions
The argument can contain a fractional component.
SELECT asin(0.1234);
Result:
0.12371534584255098
Negative Argument
The argument can also be negative.
SELECT asin(-0.1234);
Result:
-0.12371534584255098
Expressions
The argument can include expressions.
SELECT asin(.5 * 1.45);
Result:
0.8110343942875815
Out of Range Error?
Only a value ranging from -1.00 to 1.00 is valid. Values outside this range return an “out of range” error.
SELECT asin(1.01);
Result:
ERROR: input is out of range
And here it is with a negative value.
SELECT asin(-1.01);
Result:
ERROR: input is out of range
Return the Angle in Degrees
As mentioned, asin()
returns its result in radians. To get it in degrees, use the asind()
function.
The asind()
function works exactly the same as asin()
, except that its result is specified in degrees instead of radians.