How DEGREES() Works in MariaDB

In MariaDB, DEGREES() is a built-in function that returns its argument converted from radians to degrees.

The DEGREES() function is the converse of the RADIANS() function.

Syntax

The syntax goes like this:

DEGREES(X)

Where X is the value, in radians, that is to be converted to degrees.

Example

Here’s an example:

SELECT DEGREES(1);

Result:

+-------------------+
| DEGREES(1)        |
+-------------------+
| 57.29577951308232 |
+-------------------+

Fractions

The argument can contain a fractional part:

SELECT DEGREES(2.57);

Result:

+--------------------+
| DEGREES(2.57)      |
+--------------------+
| 147.25015334862155 |
+--------------------+

Negative Values

The argument can be negative:

SELECT DEGREES(-4.57);

Result:

+---------------------+
| DEGREES(-4.57)      |
+---------------------+
| -261.84171237478625 |
+---------------------+

π Radians

π (pi) radians equals 180 degrees. We can verify this by passing the PI() function to the DEGREES() function:

SELECT DEGREES(PI());

Result:

+---------------+
| DEGREES(PI()) |
+---------------+
|           180 |
+---------------+

Expressions

The argument can include expressions like this:

SELECT DEGREES(3 * 10);

Result:

+--------------------+
| DEGREES(3 * 10)    |
+--------------------+
| 1718.8733853924696 |
+--------------------+

Non-Numeric Arguments

Here’s an example of what happens when we provide a non-numeric argument:

SELECT DEGREES('Cat');

Result:

+----------------+
| DEGREES('Cat') |
+----------------+
|              0 |
+----------------+
1 row in set, 1 warning (0.043 sec)

Let’s see the warning:

SHOW WARNINGS;

Result:

+---------+------+-----------------------------------------+
| Level   | Code | Message                                 |
+---------+------+-----------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'Cat' |
+---------+------+-----------------------------------------+

Null Arguments

DEGREES() returns null if the argument is null:

SELECT DEGREES(null);

Result:

+---------------+
| DEGREES(null) |
+---------------+
|          NULL |
+---------------+

Missing Arguments

Calling DEGREES() with the wrong number of arguments, or without any arguments results in an error:

SELECT DEGREES();

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'DEGREES'

And:

SELECT DEGREES(10, 2);

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'DEGREES'