Summary: in this tutorial, you will learn how to use the SQLite radians()
function to convert a value in degrees to radians.
Introduction to the SQLite radians() function
The radians()
function converts a value in degrees to radians.
Here’s the syntax of the radians()
function:
radians(x)
Code language: SQL (Structured Query Language) (sql)
In this syntax,
s
is a value in degrees that you want to convert to radians.
The radians()
function returns the x
converted to radians. If x
is NULL, the radians() returns NULL
. If x
is not a number, the function attempts to convert it to a number before calculating the radians.
If the conversion fails, the radians() function returns NULL.
The radians()
function is a counterpart of the degrees()
function.
SQLite radians() function examples
Let’s take some examples of using the radians()
function.
1) Basic SQLite radians() function example
The following example uses the radians()
function to convert 180 from degrees to radians:
SELECT radians(180.00) radians;
Code language: SQL (Structured Query Language) (sql)
Output:
radians
-----------------
3.141592653589793
Code language: SQL (Structured Query Language) (sql)
2) Using the radians() function with table data
First, create a new table called angles
to store angle data in radians:
CREATE TABLE angles(
id INTEGER PRIMARY KEY,
angle REAL
);
Code language: SQL (Structured Query Language) (sql)
Second, insert rows into the
table:angles
INSERT INTO angles(angle)
VALUES
(45),
(60),
(90),
(NULL),
('180'),
('36O');
Code language: SQL (Structured Query Language) (sql)
Third, query data from the angles
table:
SELECT * FROM angles;
Output:
id | angle
---+------
1 | 45.0
2 | 60.0
3 | 90.0
4 | NULL
5 | 180.0
6 | 36O
(6 rows)
Code language: SQL (Structured Query Language) (sql)
Third, use the radians() function to convert the values in the angle
column to radians:
SELECT
id,
angle,
radians(angle) AS angle_radians
FROM
angles;
Code language: SQL (Structured Query Language) (sql)
Output:
id | angle | angle_radians
---+-------+-------------------
1 | 45.0 | 0.7853981633974483
2 | 60.0 | 1.0471975511965976
3 | 90.0 | 1.5707963267948966
4 | NULL | NULL
5 | 180.0 | 3.141592653589793
6 | 36O | NULL
(6 rows)
Code language: SQL (Structured Query Language) (sql)
The radians()
converts the value 36O
to NULL because it cannot implicitly convert the string '36O'
to a number.
Summary
- Use the
radians()
function to convert a value in degrees to radians.