postgresql 数字函数相关

数字类型

Name

Storage Size

Description

Range

int2

2 bytes

small-range integer

-32768 to +32767

int4

4 bytes

typical choice for integer

-2147483648 to +2147483647

int8

8 bytes

large-range integer

-9223372036854775808 to 9223372036854775807

decimal

variable

user-specified precision,exact

up to 131072 digits before the decimal point; up to 16383 digits after the decimal point

float4

4 bytes

variable-precision,inexact

6 decimal digits precision

float8

8 bytes

variable-precision,inexact

15 decimal digits precision

serial2

2 bytes

small autoincrementing integer

1 to 32767

serial4

4 bytes

autoincrementing integer

1 to 2147483647

serial8

8 bytes

large autoincrementing integer

1 to 9223372036854775807

常用数字操作符

操作符

描述

例子

结果

+

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

@

绝对值

@ -5.0

5

&

按位AND

91 & 15

11

|

按位OR

32 | 3

35

#

按位XOR

17 # 5

20

~

按位NOT

~1

-2

<<

按位左移

1 << 4

16

>>

按位右移

8 >> 2

2

三角函数

函数

描述

acos(x)

反余弦

asin(x)

反正弦

atan(x)

反正切

atan2(x, y)

正切 y/x 的反函数

cos(x)

余弦

cot(x)

余切

sin(x)

正弦

tan(x)

正切

数值运算函数

函数

返回类型 

描述

例子 

结果

abs(x)

 

绝对值

abs(-17.4)

17.4

cbrt(double)

 

立方根

cbrt(27.0)

3

ceil(double/numeric)

 

不小于参数的最小的整数

ceil(-42.8)

-42

degrees(double) 

 

把弧度转为角度

degrees(0.5)

28.6478897565412

exp(double/numeric)

 

自然指数

exp(1.0)

2.71828182845905

floor(double/numeric)

 

不大于参数的最大整数

floor(-42.8)

-43

ln(double/numeric)

 

自然对数

ln(2.0)

0.693147180559945

log(double/numeric)

 

10为底的对数

log(100.0)

2

log(b numeric,x numeric)

 

numeric指定底数的对数

log(2.0, 64.0)

6.0000000000

mod(y, x)

 

取余数

mod(9,4)

1

pi() 

double

"π"常量

pi() 

3.14159265358979

power(a double, b double)

double

求a的b次幂

power(9.0, 3.0)

729

power(a numeric, b numeric)

numeric

求a的b次幂

power(9.0, 3.0)

729

radians(double)

double

把角度转为弧度

radians(45.0)

0.785398163397448

random()

double

0.0到1.0之间的随机数值

random()

 

round(double/numeric)

 

圆整为最接近的整数

round(42.4)

42

round(v numeric, s int)

numeric

圆整为s位小数数字

round(42.438,2)

42.44

sign(double/numeric)

 

参数的符号(-1,0,+1) 

sign(-8.4)

-1

sqrt(double/numeric)

 

平方根

sqrt(2.0)

1.4142135623731

trunc(double/numeric)

 

截断(向零靠近)

trunc(42.8)

42

trunc(v numeric, s int)

numeric

截断为s小数位置的数字

trunc(42.438,2)

coalesce(null ,0)

将空转换为0

coalesce(null,0)

0

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值