CBRT
Overview
The CBRT()
function calculates and returns the cube root of a given number. In mathematical terms, for a number x, its cube root y is determined by the equation y³ = x.
Syntax
The syntax for the CBRT()
function is as follows:
CBRT(number)
Where:
number
: This is a required value representing the number for which you want to calculate the cube root. It can be a positive or negative whole number, a decimal, or even an expression that evaluates to a number.
For example, you can use expressions like SELECT CBRT(some_column) from test_table
, assuming some_column
contains a numeric value.
- It will return
NULL
if the argument is NULL
. - It will give an error if you input a parameter that is not a numeric type.
Examples
Below are several usage examples of the CBRT()
function:
Case #1: Basic Cube Root Calculation
Consider the following example:
SELECT CBRT(125);
The result of this query will be:
cbrt
------
5
Case #2: Cube Root of a Negative Value
To calculate the cube root of a negative number, use the CBRT()
function as shown:
SELECT CBRT(-125);
The final result is as follows.
cbrt
------
-5
Case #3: Cube Root of Decimal Result
For calculations with decimal numbers, use the CBRT()
function as demonstrated below:
SELECT CBRT(32);
The result will be a decimal value, as shown below:
cbrt
-------------------
3.174802103936399
Case #4: Cube Root of Decimal Input
In this scenario, fractional seconds are incorporated into the argument:
SELECT CBRT(0.12815);
The result will be the cube root of the provided decimal value.
cbrt
------------
0.50416523
Case #5: Handling Incorrect Argument
When a non-numeric argument is provided, the CBRT()
function works as follows:
SELECT CBRT('abc');
An error will be generated, and the result will not be valid.
invalid input syntax for type double precision: "abc"
Case #6: CBRT Operator (||/(x)
)
Here’s an example using the CBRT operator (||/(x)
) to calculate the cube root of a given number:
SELECT ||/(1728) AS cbrt_operator;
In this example, we calculate the cube root of 1728 using the CBRT operator. The result of this query will be:
cbrt_operator
--------------------
12.000000000000002