1.1.1 逻辑操作符
常用的逻辑操作符:
AND
OR
NOT
1.1.2 比较操作符
|
操作符 |
描述 |
|
< |
小于 |
|
> |
大于 |
|
<= |
小于等于 |
|
>= |
大于等于 |
|
= |
等于 |
|
<> or != |
不等于 |
1.1.3 数学函数和操作符
下表展示了所有GBase 8c可用的数学操作符:
|
操作符 |
描述 |
例子 |
结果 |
|
+ |
加 |
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 |
|
& |
按位与 |
91 & 15 |
11 |
|
| |
按位或 |
32 | 3 |
35 |
|
# |
按位异或 |
17 # 5 |
20 |
|
~ |
按位求反 |
~1 |
-2 |
|
<< |
按位左移 |
1 << 4 |
16 |
|
>> |
按位右移 |
8 >> 2 |
2 |
可用的数学函数如下表:
|
函数 |
返回类型 |
描述 |
例子 |
结果 |
|
abs(x) |
(和输入相同) |
绝对值 |
abs(-17.4) |
17.4 |
|
cbrt(dp) |
dp |
立方根 |
cbrt(27.0) |
3 |
|
ceil(dp or numeric) |
(和输入相同) |
不小于参数的最小整数 |
ceil(-42.8) |
-42 |
|
ceiling(dp or numeric) |
(和输入相同) |
不小于参数的最小整数(ceil的别名) |
ceiling(-95.3) |
-95 |
|
degrees(dp) |
dp |
把弧度转为角度 |
degrees(0.5) |
28.6478897565412 |
|
div(y numeric, x
numeric) |
numeric |
y/x的整数商 |
div(9,4) |
2 |
|
exp(dp or numeric) |
(和输入相同) |
指数 |
exp(1.0) |
2.71828182845905 |
|
floor(dp or numeric) |
(和输入相同) |
不大于参数的最大整数 |
floor(-42.8) |
-43 |
|
ln(dp or numeric) |
(和输入相同) |
自然对数 |
ln(2.0) |
0.693147180559945 |
|
log(dp or numeric) |
(和输入相同) |
以10为底的对数 |
log(100.0) |
2 |
|
log(b numeric, x
numeric) |
numeric |
以b为底的对数 |
log(2.0, 64.0) |
6.0000000000 |
|
mod(y, x) |
(和参数类型相同) |
y/x的余数 |
mod(9,4) |
1 |
|
pi() |
dp |
“π”常数 |
pi() |
3.14159265358979 |
|
power(a dp, b
dp) |
dp |
求a的b次幂 |
power(9.0, 3.0) |
729 |
|
power(a numeric, b
numeric) |
numeric |
求a的b次幂 |
power(9.0, 3.0) |
729 |
|
radians(dp) |
dp |
把角度转为弧度 |
radians(45.0) |
0.785398163397448 |
|
round(dp or numeric) |
(和输入相同) |
圆整为最接近的整数 |
round(42.4) |
42 |
|
round(v numeric, s
int) |
numeric |
圆整为s位小数数字 |
round(42.4382, 2) |
42.44 |
|
scale(numeric) |
integer |
参数的精度(小数点后的位数) |
scale(8.41) |
2 |
|
sign(dp or numeric) |
(和输入相同) |
参数的符号(-1, 0, +1) |
sign(-8.4) |
-1 |
|
sqrt(dp or numeric) |
(和输入相同) |
平方根 |
sqrt(2.0) |
1.4142135623731 |
|
trunc(dp or numeric) |
(和输入相同) |
截断(向零靠近) |
trunc(42.8) |
42 |
|
trunc(v numeric, s
int) |
numeric |
截断为s位小数位置的数字 |
trunc(42.4382, 2) |
42.43 |
|
width_bucket(operand
dp, b1 dp, b2 dp, count int) |
int |
返回一个桶,这个桶是在一个有count个桶,
上界为b1,下界为b2的柱图中operand将被赋予的那个桶。为外部范围输入返回0或者count+1 |
width_bucket(5.35, 0.024,
10.06, 5) |
3 |
|
width_bucket(operand
numeric, b1 numeric, b2 numeric, count int) |
int |
返回一个桶,这个桶是在一个有count个桶,上界为b1,下界为b2的柱图中operand将被赋予的那个桶; 为范围外的输入返回0或者count+1 |
width_bucket(5.35, 0.024,
10.06, 5) |
3 |
|
width_bucket(operand
anyelement, thresholds anyarray) |
int |
返回一个桶,它是给定数组列出桶的下限operand将被赋予的那个桶,
为了输入低于第一下界返回0;thresholds数组必须被存储,
首先最小值,或者获取意想不到的结果 |
width_bucket(now(),
array['yesterday', 'today', 'tomorrow']::timestamptz[]) |
2 |
表中dp表示double precision。除非特殊指明,任何函数都返回和它参数相同的数据类型。




