In PostgreSQL, the radians()
function converts from degrees to radians.
The radian is the SI (International System of Units) unit for measuring angles. One radian is just under 57.3 degrees, and a full circle has just over 6.28 radians (2π).
Syntax
The syntax goes like this:
radians(dp)
Where dp
is a double precision value that represents the degrees you want converted to radians.
Example
Here’s an example of how it works.
SELECT radians(45);
Result:
0.7853981633974483
Here, we see that 45 degrees is equal to 0.7853981633974483 radians.
Negative Values
You can also pass negative values.
SELECT radians(-45);
Result:
-0.7853981633974483
Expressions
Here’s an example that uses an expression.
SELECT radians(80 + 10);
Result:
1.5707963267948966
Large Values
You can pass values that are larger than a full circle.
SELECT radians(3000);
Result:
52.35987755982988
Full Circle
In this example I provide the number of degrees in a full circle.
SELECT radians(360);
Result:
6.283185307179586
Pass Another Function
The previous example can also be done using the degrees()
function, which converts from degrees to radians.
SELECT radians(degrees(6.283185307179586));
Result:
6.283185307179586
Pi
As mentioned, a radian is 2π. Therefore, passing a value of 180 (degrees) to the function returns pi. We can verify this by using the pi()
function to return the pi constant.
SELECT
pi(),
radians(180);
Result:
pi | radians ------------------+------------------ 3.141592653589793 | 3.141592653589793
Similarly, we can pass 360 and that will be 2π.
SELECT
pi() * 2,
radians(360);
Result:
pi | radians ------------------+------------------ 6.283185307179586 | 6.283185307179586