Postgresql - Functions and Operators 函数和运算 - Mathematical

数学函数,运算。

Operator

Description

Example

Result

+

加法

2 + 3

5

-

减法

2 - 3

-1

*

乘法

2 * 3

6

/

除法(只取整除结果)

4 / 2

2

%

取模

5 % 4

1

^

指数

2.0 ^ 3.0

8

|/

平方根

|/ 25.0

5

||/

立方根

||/ 27.0

3

!

阶乘

5 !

120

!!

阶乘(符号放在前边)

!! 5

120

@

absolute value 绝对值

@ -5.0

5

&

bitwise AND 按二进制位取且

91 & 15

11

|

bitwise OR 按二进制位取或

32 | 3

35

#

bitwise XOR 按二进制位取反,再取或

17 # 5

20

~

bitwise NOT 按二进制取非

~1

-2

<<

bitwise shift left 按二进制向左移位

1 << 4

16

>>

bitwise shift right 按二进制向右移位

8 >> 2

2

数学函数。

Function

Return Type

Description

Example

Result

abs(x)

(same as input)

absolute value 绝对值

abs(-17.4)

17.4

cbrt(dp)

dp

cube root 立方根

cbrt(27.0)

3

ceil(dp or numeric)

(same as input)

取浮点参数大的最近的整数

ceil(-42.8)

-42

ceiling(dp ornumeric)

(same as input)

取浮点参数大的最近的整数 (same as ceil)

ceiling(-95.3)

-95

degrees(dp)

dp

弧度

degrees(0.5)

28.6478897565412

div(y numeric, xnumeric)

numeric

整数商

div(9,4)

2

exp(dp or numeric)

(same as input)

指数

exp(1.0)

2.71828182845905

floor(dp or numeric)

(same as input)

取浮点数小的最近的整数

floor(-42.8)

-43

ln(dp or numeric)

(same as input)

自然对数,以e为底的对数

ln(2.0)

0.693147180559945

log(dp or numeric)

(same as input)

取底为10的对数

log(100.0)

2

log(b numeric, xnumeric)

numeric

取B为底的对数

log(2.0, 64.0)

6.0000000000

mod(y, x)

(same as argument types)

取模(余数)

mod(9,4)

1

pi()

dp

常数“π”

pi()

3.14159265358979

power(a dp, b dp)

dp

幂运算

power(9.0, 3.0)

729

power(a numeric, bnumeric)

numeric

幂运算

power(9.0, 3.0)

729

radians(dp)

dp

弧度

radians(45.0)

0.785398163397448

round(dp or numeric)

(same as input)

四舍五入取整

round(42.4)

42

round(v numeric, sint)

numeric

四舍五入取小数点后的位数

round(42.4382, 2)

42.44

scale(numeric)

integer

小数点之后的个数

scale(8.41)

2

sign(dp or numeric)

(same as input)

给的参数的正1,零0,负-1

sign(-8.4)

-1

sqrt(dp or numeric)

(same as input)

square root 平方根

sqrt(2.0)

1.4142135623731

trunc(dp or numeric)

(same as input)

只取整数

trunc(42.8)

42

trunc(v numeric, sint)

numeric

截断小数点后的多少位

trunc(42.4382, 2)

42.43

width_bucket(operanddp, b1 dp, b2 dp,count int)

int

返回一个在一个直方图中分配操作数的桶数,它有一个计数等于等宽度的桶,它跨越范围B1到B2;在范围之外的输入中返回0个或1个数。

width_bucket(5.35, 0.024, 10.06, 5)

3

width_bucket(operandnumeric, b1 numeric,b2 numeric, countint)

int

返回一个在一个直方图中分配操作数的桶数,它有一个计数等于等宽度的桶,它跨越范围B1到B2;在范围之外的输入中返回0个或1个数。

width_bucket(5.35, 0.024, 10.06, 5)

3

width_bucket(operandanyelement,thresholds anyarray)

int

返回一个给操作数分配的桶数,给定一个数组,列出桶的下界;返回小于第一下限的输入0;阈值数组必须先排序,最小,否则将得到意想不到的结果。

width_bucket(now(), array['yesterday', 'today', 'tomorrow']::timestamptz[])

2

随机函数。

Function

Return Type

Description

random()

dp

返回0到1之间的随机数(包括0,1)

setseed(dp)

void

为后续调用random()设置种子 (value between -1.0 and 1.0, inclusive)

三角函数

Function (弧度)

Function (角度)

Description

acos(x)

acosd(x)

inverse cosine

asin(x)

asind(x)

inverse sine

atan(x)

atand(x)

inverse tangent

atan2(y, x)

atan2d(y, x)

inverse tangent of y/x

cos(x)

cosd(x)

cosine

cot(x)

cotd(x)

cotangent

sin(x)

sind(x)

sine

tan(x)

tand(x)

tangent

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值