SQLite degrees() Function

Summary: in this tutorial, you will learn how to use the SQLite degrees() function to convert a value in radians to degrees.

Introduction to the SQLite degrees() function

In SQLite, the degrees() function allows you to convert a value in radians to degrees.

Here’s the syntax of the degrees() function:

degrees(x)Code language: SQL (Structured Query Language) (sql)

In this syntax

  • x is a value in radians that you want to convert to degrees. It can be an expression or a table column.

The degrees() function returns x converted to degrees. If x is NULL, the degrees() returns NULL.

The degrees() function is a counterpart of the radians() function.

SQLite degrees() function examples

Let’s take some examples of using the degrees() function.

1) Basic SQLite degrees() function examples

The following example uses the degrees() function to convert 3 radians to degrees:

SELECT degrees(3) degrees;Code language: SQL (Structured Query Language) (sql)

Output:

degrees
------------------
171.88733853924697Code language: SQL (Structured Query Language) (sql)

The following example uses the degrees() function to convert the value of π (pi) radians to degrees:

SELECT degrees(pi()) degrees;Code language: SQL (Structured Query Language) (sql)

Output:

degrees
-------
180.0Code language: SQL (Structured Query Language) (sql)

2) Using the degrees() function with table data

First, create a new table called angles to store angles in radians:

CREATE TABLE angles (
    id INTEGER PRIMARY KEY,
    angle REAL
);Code language: SQL (Structured Query Language) (sql)

Second, insert rows into the angles table:

INSERT INTO angles (angle) 
VALUES
    (2*PI()),
    (PI()),
    (PI()/2),
    (NULL);Code language: SQL (Structured Query Language) (sql)

Third, use the degrees() function to convert radians stored in the angles table to degrees:

SELECT
  id,
  angle,
  degrees(angle) AS angle_degrees
FROM
  angles;Code language: SQL (Structured Query Language) (sql)

Output:

id | angle              | angle_degrees
---+--------------------+--------------
1  | 6.283185307179586  | 360.0
2  | 3.141592653589793  | 180.0
3  | 1.5707963267948966 | 90.0
4  | NULL               | NULL

(4 rows)Code language: SQL (Structured Query Language) (sql)

Summary

  • Use the degrees() function to convert a value in radians to degrees.
Was this tutorial helpful ?