AnalyticDB for PostgreSQL is compatible with the mathematical functions and operators of PostgreSQL. This topic describes the mathematical functions and operators that are supported by AnalyticDB for PostgreSQL and provides examples on how to use the mathematical functions and operators.
For information about the mathematical functions and operators of PostgreSQL, see Mathematical Functions and Operators.
Mathematical operators
Mathematical operators are symbols or functions used in mathematics and programming languages to perform basic mathematical operations. The operators are used to perform numerical calculations, such as addition, subtraction, multiplication, division, and more complex mathematical operations.
Operator | Description | Example | Sample result |
| Performs the addition operation. |
|
|
| Performs the subtraction operation. |
|
|
| Performs the multiplication operation. |
|
|
| Performs the division operation and returns a truncated integer result. |
|
|
| Performs the modulo operation and returns the remainder of a division. |
|
|
| The left-associative operator that performs the exponentiation operation. |
|
|
| Returns the square root of a number. |
|
|
| Returns the cube root of a number. |
|
|
| Returns the factorial of a number. |
|
|
| The prefix operator that returns the factorial of a number. |
|
|
| Returns the absolute value of a number. |
|
|
| Returns the result of the bitwise AND operation between two operands. |
|
|
| Returns the result of the bitwise OR operation between two operands. |
|
|
| Returns the result of the bitwise XOR operation between two operands. |
|
|
| Returns the result of the bitwise NOT operation on an operand. |
|
|
| Shifts the bits in the left operand to the left by the number of positions specified by the right operand and fills the vacant positions with zeros. |
|
|
| Shifts the bits in the left operand to the right by the number of positions specified by the right operand and fills the vacant positions with zeros. |
|
|
Mathematical functions
Mathematical functions are a special class of mathematical expressions that map one or more independent variables to the values of the dependent variables. For example, in the linear function y = mx + b, m and b are constants, x is the independent variable, and y is the dependent variable. Other common functions include exponential functions, logarithmic functions, and trigonometric functions.
Function | Data type of the return value | Description | Example | Sample result |
| Same as the input value | Returns the absolute value of a number. |
|
|
|
| Returns the cube root of a number. |
|
|
| Same as the input value | Rounds up to the nearest integer that is greater than or equal to the specified number. |
|
|
| Same as the input value | Rounds up to the nearest integer that is greater than or equal to the specified number. This function is the same as the |
|
|
|
| Converts a value in radians into degrees. |
|
|
|
| Returns the integer quotient of |
|
|
| Same as the input value | Returns the exponential value of a number. |
|
|
| Same as the input value | Rounds down to the nearest integer that is less than or equal to the specified number. |
|
|
| Same as the input value | Returns the natural logarithm of a number. |
|
|
| Same as the input value | Returns the common logarithm (base-10 logarithm) of a number. |
|
|
| Same as the input value | Returns the common logarithm (base-10 logarithm) of a number. This function is the same as the log function. |
|
|
|
| Returns the logarithm of x to the base specified by |
|
|
| Same as the input value | Returns the remainder of |
|
|
|
| Returns the value of the pi (π) constant. |
|
|
|
| Returns the value of |
|
|
|
| Returns the value of |
|
|
|
| Converts a value in degrees into radians. |
|
|
| Same as the input value | Rounds to the nearest integer. |
|
|
|
| Rounds to |
|
|
|
| Returns the number of decimal digits in the fractional part of a number. |
|
|
| Same as the input value | Returns the sign of a number. This function returns -1, 0, and +1 if the number is negative, zero, and positive. |
|
|
| Same as the input value | Returns the square root of a number. |
|
|
| Same as the input value | Truncates toward zero. |
|
|
|
| Truncates to |
|
|
|
| Returns the number of the bucket to which the |
|
|
|
| Returns the number of the bucket to which the |
|
|
|
| Returns the number of the bucket to which the |
|
|
Random functions
A random function is a function of uncertainty whose output values can be one of the possible results instead of a specific, determined value.
Function | Data type of the return value | Description |
|
| Returns a random value in the range of |
|
| Sets a seed for subsequent calls to the |
Trigonometric functions
Trigonometric functions are a special class of functions that are related to the angles of right triangles. The most common trigonometric functions are sine (sin), cosine (cos), and tangent (tan). These functions can be used to calculate the magnitudes of angles in right triangles and solve more complex geometric problems.
Function (radians) | Function (degrees) | Description |
|
| Returns the arccosine of x. |
|
| Returns the arcsine of x. |
|
| Returns the arctangent of x. |
|
| Returns the arctangent of |
|
| Returns the cosine of x. |
|
| Returns the cotangent of x. |
|
| Returns the sine of x. |
|
| Returns the tangent of x. |
Hyperbolic functions
Hyperbolic functions are a special class of functions that are related to hyperbolas. The most common hyperbolic functions are hyperbolic sine (sinh), hyperbolic cosine (cosh), and hyperbolic tangent (tanh). These functions can be used to solve complex mathematical problems, such as differential equations.
Function | Description | Example | Sample result |
| Returns the hyperbolic sine of x. |
|
|
| Returns the hyperbolic cosine of x. |
|
|
| Returns the hyperbolic tangent of x. |
|
|
| Returns the inverse hyperbolic sine of x. |
|
|
| Returns the inverse hyperbolic cosine of x. |
|
|
| Returns the inverse hyperbolic tangent of x. |
|
|