Skip to content

Mathematical Functions and Operators

ClapDB query SQL will fully compatibility with PostgreSQL’s SQL, and mathematical functions and operators’ current state can be checked in below chart.

according to PostgreSQL Mathematical Functions and Operators

Mathematical Operator

PostgreSQL Mathematical OperatorDescriptionFormularExampleClapDB supportedClapDB will support in future release
’+‘Additionalnumeric_type + numeric_type → numeric_type2 + 3 → 5
’+‘Unary plus (no operation)+ numeric_type → numeric_type+ 3.5 → 3.5
’-‘Subtractionnumeric_type - numeric_type → numeric_type2 - 3 → -1
’-‘Negation- numeric_type → numeric_type- 3.5 → 3.5
’*‘Multiplicationnumeric_type * numeric_type → numeric_type2 * 3 → 6
/Division (for integral types, division truncates the result towards zero)numeric_type / numeric_type → numeric_type3 / 2 → 1
%Modulo (remainder); available for smallint, integer, bigint, and numericnumeric_type % numeric_type → numeric_type5 % 4 → 1
^Exponentiationdouble precision ^ double precision → double precision2 ^ 3 → 8
|/Square root|/ double precision → double precision|/ 25 → 5
||/Cube root||/ double precision → double precision||/ 27 → 3
@Absolute value@numeric_type → numeric_type@ -4 → 4
&Bitwise ANDintegeral_type & integeral_type → integeral_type19 & 15 → 11
|Bitwise ORintegeral_type | integeral_type → integeral_type32 | 3 → 35
#Bitwise exclusive ORintegeral_type # integeral_type → integeral_type17 # 5 → 20
~Bitwise NOT~ integeral_type → integeral_type~1 → 2
<<Bitwise shift leftinteger << integer → integer8 << 2 → 32
>>Bitwise shift rightinteger >> integer → integer8 >> 2 → 2

Mathematical Function

PostgreSQL Mathematical FunctionDescriptionFormularExampleClapDB supportedClapDB will support in future release
absAbsoluteabs(numeric_type) → numeric_typeabs(-17.4) → 17.4
cbrtCube rootcbrt(double precision) → double precisioncbrt(27) → 3
ceilNearest integer greater than or equal to argumentceil(numeric_type) → numeric_typeceil(42.2) → 43
ceilcel(double precision) -> double precisionceil(-42.2) -> -42
ceilingNearest integer greater than or equal to argumentceiling(numeric_type) → numeric_typeceiling(42.2) → 43
ceilingcel(double precision) -> double precisionceiling(-42.2) -> -42
degreesConverts radians to degreesdegrees(double precision) → double precisiondegrees(0.5) → 28.6478897565412
divInteger quotient of y/x (truncates towards zero)div(numeric, numeric) → numericdiv(9, 4) → 2
erfError functionerf(double precision) → double precisionerf(0.5) → 0.520499877813047
erfcComplementary error function (1 - erf(x), without loss of precision for large inputs)erfc(double precision) → double precisionerfc(0.5) → 0.479500122186953
expExponential functionexp(numeric) → numericexp(1) → 2.71828182845905
expexp(double precision) → double precisionexp(1) → 2.71828182845905
factorialFactorialfactorial(bigint) → numericfactorial(5) → 120
floorNearest integer less than or equal to argumentfloor(numeric_type) → numeric_typefloor(42.8) → 42
floorfloor(double precision) -> double precisionfloor(-42.8) -> -43
gcdGreatest common divisorgcd(integer, integer) → integergcd(1071, 462) → 21
lcmLeast common multiple (the smallest strictly positive number that is an integral multiple of both inputs); returns 0 if either input is zero;lcm(numeric_type, numeric_type) → numeric_typelcm(1071, 462) → 23562
lnNatural logarithmln(numeric) → numericln(2.0) → 0.6931471805599453
lnln(double precision) → double precisionln(2.0) → 0.6931471805599453
logBase 10 logarithmlog(numeric) → numericlog(100.0) → 2
loglog(double precision) → double precisionlog(100.0) → 2
log10Base 10 logarithmlog10(numeric) → numericlog10(100.0) → 2
log10log10(double precision) → double precisionlog10(100.0) → 2
logLogarithm of x to base blog(numeric, numeric) → numericlog(2.0, 64.0) → 6.0
min_scaleMinimum scale (number of fractional decimal digits) needed to represent the supplied value preciselymin_scale(numeric) → integermin_scale(1.23) → 2
modRemainder of y/x; available for smallint, integer, bigint, and numericmod(numeric, numeric) → numericmod(5, 3) → 2
piApproximate value of πpi() → double precisionpi() → 3.141592653589793
powera raised to the power of bpower(numeric, numeric) → numericpower(2, 3) → 8
powerpower(double precision, double precision) → double precisionpower(2.0, 3.0) → 8.0
radiansConverts degrees to radiansradians(double precision) → double precisionradians(45.0) → 0.785398163397448
roundRounds to nearest integer. For numeric, ties are broken by rounding away from zero. For double precision, the tie-breaking behavior is platform dependent, but “round to nearest even” is the most common rule.round(numeric_type) → numeric_typeround(42.4) → 42
roundround(double precision) -> double precisionround(-42.4) -> -42
roundRounds v to s decimal places. Ties are broken by rounding away from zero.round(numeric_type, integer) → numeric_typeround(42.4382, 2) → 42.44
scaleScale of the argument (the number of decimal digits in the fractional part)scale(numeric) → integerscale(8.4100) → 4
signSign of the argument (-1, 0, or +1)sign(numeric_type) → integersign(-42.8) → -1
signsign(double precision) -> integersign(-42.8) -> -1
sqrtSquare rootsqrt(numeric) → numericsqrt(25) → 5
sqrtsqrt(double precision) → double precisionsqrt(25) → 5
trim_scaleReduces the value’s scale (number of fractional decimal digits) by removing trailing zeroestrim_scale(numeric) → numerictrim_scale(1.230) → 1.23
truncTruncates to integer (towards zero)trunc(numeric_type) → numeric_typetrunc(42.8) → 42
trunctrunc(double precision) -> double precisiontrunc(-42.8) -> -42
truncTruncates v to s decimal placestrunc(numeric_type, integer) → numeric_typetrunc(42.4382, 2) → 42.43
width_bucketReturns the number of the bucket in which operand falls in a histogram having count equal-width buckets spanning the range low to high. Returns 0 or count+1 for an input outside that range.width_bucket(operand numeric, low numeric, high numeric, count integer) → integer
width_bucketwidth_bucket(operand double precision, low double precision, high double precision, count integer) → integerwidth_bucket(5.35, 0.024, 10.06, 5) → 3
width_bucketReturns the number of the bucket in which operand falls given an array listing the lower bounds of the buckets. Returns 0 for an input less than the first lower bound. operand and the array elements can be of any type having standard comparison operators. The thresholds array must be sorted, smallest first, or unexpected results will be obtained.width_bucket(operand anycompatible, thresholds anycompatiblearray) → integerwidth_bucket(now(), array[‘yesterday’, ‘today’, ‘tomorrow’]::timestamptz[]) → 2

Randome Function

PostgreSQL Mathematical FunctionDescriptionFormularExampleClapDB supportedClapDB will support in future release
randomReturns a random value in the range 0.0 < x < 1.0random() → double precisionrandom() → 0.298594
random_normalReturns a random value from the normal distribution with the given parameters; mean defaults to 0.0 and stddev defaults to 1.0random_normal(mean double precision, ) → double precisionrandom_normal() → 0.298594
set_seedSets the seed for the random number generatorset_seed(seed double precision) → voidset_seed(0.5)

Trigonometric Functions

not supported by ClapDB by now

Hyperbolic Functions

not supported by ClapDB by now