PostgreSql Mathematical Functions and Operators

1. Operator table

operator describe example result
+ add 4+7 11
- reduce 4-7 -3
* take 4*7 11
/ divide (integer division will truncate the result) 7/3 2
% modulo (remainder) 6%4 2
^ Power (exponential operation) 3^3 27
|/ square root |/36 6
||/ cube root ||/8 2
! factorial 5! 120
!! factorial (prefix operator) !!5 120
@ absolute value @-5.0 5
& Binary AND 31&15 15
| binary OR 31|15 31
# binary XOR 31#15 16
~ Binary NOT ~1 -2
<< binary shift left 1<<8 256
>> binary right shift 16>>3 2

2. Function table

"dp" stands for double precision.

operator describe example result
abs(x) absolute value abs(-23.7) 23.7
cbrt(dp) cube root cbrt(8) 2
ceil/ceiling(dp或numeric) the smallest integer not less than the argument ceil(-38.1) ceil(38.1) ceiling(38.1) -38 39 39
degrees(dp) Convert radians to degrees degrees(1) 57.29577951308232
exp(dp or numeric) natural index exp(1) 2.7182818284590452
floor(dp或numeric) largest integer not greater than the argument floor(-42.8) floor(-42.8) -43 42
ln (dp or numeric) Natural logarithm ln(2.7182818284590452) 1.0000000000000000
log(dp or numeric) base 10 logarithm log(1000) 3
log(b numeric,x numeric) logarithm to base b log(2,32) 5.0000000000000000
mod(y,x) remainder of y/x (modulo) mod(7,3) 1
pi() π constant pi() 3.141592653589793
power(a dp or numeric, b dp or numeric) a to the power of b power(2,3) 8
radians(dp) Convert angles to radians radians(45) 0.7853981633974483
random() random number between 0 and 1 random() 随机返回一个小数
round(dp或numeric) 圆整为最接近的整数(四舍五入) round(36.5) 37
round(v numeric,s int) 圆整为s位小数(四舍五入) round(36.5252,2) 36.53
setseed(dp) 为随后的random()调用设置种子(0到1之间) setseed(0.123) 每次种子后,重现相同随机数
sign(dp或numeric) 参数的符号(-1,0,+1) sign(-8.4) -1
sprt(dp或numeric) 平方根 sqrt(9) 3
trunc(dp或numeric) 截断(向零靠近) trunc(42.8) 42
trunc(v numeric,s int) 截断为s位小数 trunc(42.4382,2) 42.43
width_bucket(op numeric,b1 numeric,b2 numeric,count int) 返回包含count等宽柱的柱状图中operand所在的柱的编号,范围从low到high,超出该范围的输入则返回0或计数+1 width_bucket(5.35,0.024,10.06,5) 3
acos(x) 反余弦 acos(1) acos(-1) 0 3.141592653589793
asin(x) 反正弦 asin(0) asin(1)*2 0 3.141592653589793
atan(x) 反正切 atan(1) 0.7853981633974483
atan2(x,y) x/y的反正切 atan2(1,1) 0.7853981633974483
cos(x) 余弦 cos(pi()) cos(0) -1 1
cot(x) 余切 cot(0) Infinity
sin(x) 正弦 sin(0) sin(pi()/2) 0 1
tan(x) 正切 tan(pi()/4) 0.9999999999999999

Guess you like

Origin blog.csdn.net/songyundong1993/article/details/131416741