All Products
Search
Document Center

Hologres:Mathematical functions

Last Updated:Apr 26, 2023

Hologres is compatible with PostgreSQL and allows you to use the standard PostgreSQL syntax for data development. This topic describes the mathematical functions that are supported by Hologres and provides sample statements of these functions.

The following table describes the mathematical functions that are supported by Hologres. The functions supported by Hologres are only a subset of the PostgreSQL functions. For more information about how to use these functions, see Mathematical Functions and Operators in the PostgreSQL documentation.

Function

Description

Example

Result

abs(bigint)

Returns the absolute value of a number. The number is of the BIGINT data type and can be a literal or an expression that evaluates to a number.

abs(-17)

17

abs(int)

Returns the absolute value of a number. The number is of the INT data type and can be a literal or an expression that evaluates to a number.

abs(-17)

17

abs(float8)

Returns the absolute value of a number. The number is of the FLOAT8 data type and can be a literal or an expression that evaluates to a number.

abs(-17.4)

17.4

abs(float4)

Returns the absolute value of a number. The number is of the FLOAT4 data type and can be a literal or an expression that evaluates to a number.

abs(-17.4)

17.4

abs(numeric)

Returns the absolute value of a number. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

abs(-17.4)

17.4

cbrt(dp)

Returns the cube root of a number. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

cbrt(27.0)

3.0000000000000004

ceil(dp)

Rounds a number up to the nearest integer. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

ceil(-42.8)

-42.0

ceil(numeric)

Rounds a number up to the nearest integer. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

ceil(-42.8)

-42.0

ceiling(dp)

Rounds a number up to the nearest integer. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

ceil(-42.8)

-42.0

ceiling(numeric)

Rounds a number up to the nearest integer. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

ceil(-42.8)

-42.0

degrees(dp)

Converts an angle in radians to its equivalent in degrees. The input parameter is a number, and the number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

degrees(0.5)

28.64788975654116

exp(dp)

Returns the result of constant e raised to the power of a number. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

exp(1.0)

2.718281828459045

exp(numeric)

Returns the result of constant e raised to the power of a number. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

exp(1.0)

2.718281828459045

floor(dp)

Rounds a number down to the nearest integer. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

floor(-42.8)

-43.0

floor(numeric)

Rounds a number down to the nearest integer. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

floor(-42.8)

-43.0

ln(dp)

Returns the natural logarithm of a number. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

ln(2.0)

0.6931471805599453

ln(numeric)

Returns the natural logarithm of a number. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

ln(2.0)

0.6931471805599453

log(dp)

Returns the base 10 logarithm of a number. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

log(100.0)

2.0

log(numeric)

Returns the base 10 logarithm of a number. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

log(100.0)

2.0

log(b numeric, x numeric)

Returns the base b logarithm of x. Both b and x are numbers, and the numbers are of the NUMERIC data type and can be literals or expressions that evaluate to numbers.

log(2.0, 64.0)

6.0

mod(bigint, x)

Returns the remainder of a number divided by number x. The first number is of the BIGINT data type, and the two numbers can be literals or expressions that evaluate to numbers.

mod(9,4)

1

mod(int, x)

Returns the remainder of a number divided by number x. The first number is of the INT data type, and the two numbers can be literals or expressions that evaluate to numbers.

mod(9,4)

1

pi()

Returns the value of constant π to 15 decimal places.

pi()

3.141592653589793

power(a dp, b dp)

Returns the result of a raised to the power of b. Both a and b are numbers of the DOUBLE PRECISION data type and can be literals or expressions that evaluate to numbers.

power(9.0, 3.0)

729.0

power(a numeric, b numeric)

Returns the result of a raised to the power of b. Both a and b are numbers of the NUMERIC data type and can be literals or expressions that evaluate to numbers.

power(9.0, 3.0)

729.0

radians(dp)

Converts an angle in degrees to its equivalent in radians. The input parameter is a number, and the number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

radians(45.0)

0.7853981633974483

random()

Returns a random number between 0.0 (inclusive) and 1.0 (exclusive).

random()

0.3977345246821642

round(dp)

Rounds a number to the nearest integer. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

round(42.4)

42.0

round(numeric)

Rounds a number to the nearest integer. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

round(42.4)

42.0

round(v numeric, s int)

Rounds v to the nearest number with s decimal places of precision. v is a number of the NUMERIC data type, and s is a number of the INT data type. Number v can be a literal or an expression that evaluates to a number.

round((100/400::numeric),4);

0.2500

sign(dp)

Returns the sign of a number. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number. If the specified number is greater than 0, the result of the function is 1. If the specified number is less than 0, the result of the function is -1. If the specified number is 0, the result of the function is 0.

sign(-8.4)

-1

sign(numeric)

Returns the sign of a number. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number. If the specified number is greater than 0, the result of the function is 1. If the specified number is less than 0, the result of the function is -1. If the specified number is 0, the result of the function is 0.

sign(-8.4)

-1

sqrt(dp)

Returns the square root of a number. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

sqrt(2.0)

1.414213562373095

sqrt(numeric)

Returns the square root of a number. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

sqrt(2.0)

1.414213562373095

trunc(dp)

Truncates a number to an integer. The number is of the DOUBLE PRECISION data type and can be a literal or an expression that evaluates to a number.

trunc(42.8)

42.0

trunc(numeric)

Truncates a number to an integer. The number is of the NUMERIC data type and can be a literal or an expression that evaluates to a number.

trunc(42.8)

42.0

trunc(v numeric, s int)

Truncates v to s decimal places. v is a number of the NUMERIC data type, and s is a number of the INT data type. Number v can be a literal or an expression that evaluates to a number.

trunc(42.4382, 2)

42.43

width_bucket(operand numeric, b1 numeric, ...)

Divides a data set into buckets of equal width and returns the bucket number into which an operand falls.

width_bucket(5.35, 0.024, 10.06, 5)

3