暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

华为openGauss 数字操作函数和操作符

华为高斯 2020-06-01
787

数字操作符

  • +

    描述:加

    示例:

    ``` postgres=# SELECT 2+3 AS RESULT; result


      5
    

    (1 row) ```

  • -

    描述:减

    示例:

    ``` postgres=# SELECT 2-3 AS RESULT; result


     -1
    

    (1 row) ```

  • *

    描述:乘

    示例:

    ``` postgres=# SELECT 2*3 AS RESULT; result


      6
    

    (1 row) ```

  • /

    描述:除(除法操作符不会取整)

    示例:

    ``` postgres=# SELECT 4/2 AS RESULT; result


      2
    

    (1 row) ```

    ``` postgres=# SELECT 4/3 AS RESULT; result


    1.33333333333333 (1 row) ```

  • +/-

    描述:正/负

    示例:

    ``` postgres=# SELECT -2 AS RESULT; result


     -2
    

    (1 row) ```

  • %

    描述:模(求余)

    示例:

    ``` postgres=# SELECT 5%4 AS RESULT; result


      1
    

    (1 row) ```

  • @

    描述:绝对值

    示例:

    ``` postgres=# SELECT @ -5.0 AS RESULT; result


    5.0
    

    (1 row) ```

  • ^

    描述:幂(指数运算)

    示例:

    ``` postgres=# SELECT 2.0^3.0 AS RESULT; result


    8.0000000000000000 (1 row) ```

  • |/

    描述:平方根

    示例:

    ``` postgres=# SELECT |/ 25.0 AS RESULT; result


      5
    

    (1 row) ```

  • ||/

    描述:立方根

    示例:

    ``` postgres=# SELECT ||/ 27.0 AS RESULT; result


      3
    

    (1 row) ```

  • !

    描述:阶乘

    示例:

    ``` postgres=# SELECT 5! AS RESULT; result


    120
    

    (1 row) ```

  • !!

    描述:阶乘(前缀操作符)

    示例:

    ``` postgres=# SELECT !!5 AS RESULT; result


    120
    

    (1 row) ```

  • &

    描述:二进制AND

    示例:

    ``` postgres=# SELECT 91&15 AS RESULT; result


     11
    

    (1 row) ```

  • |

    描述:二进制OR

    示例:

    ``` postgres=# SELECT 32|3 AS RESULT; result


     35
    

    (1 row) ```

  • #

    描述:二进制XOR

    示例:

    ``` postgres=# SELECT 17#5 AS RESULT; result


     20
    

    (1 row) ```

  • \~

    描述:二进制NOT

    示例:

    ``` postgres=# SELECT ~1 AS RESULT; result


     -2
    

    (1 row) ```

  • <<

    描述:二进制左移

    示例:

    ``` postgres=# SELECT 1<<4 AS RESULT; result


     16
    

    (1 row) ```

  • >>

    描述:二进制右移

    示例:

    ``` postgres=# SELECT 8>>2 AS RESULT; result


      2
    

    (1 row) ```

数字操作函数

  • abs(x)

    描述:绝对值。

    返回值类型:和输入相同。

    示例:

    ``` postgres=# SELECT abs(-17.4); abs


    17.4 (1 row) ```

  • acos(x)

    描述:反余弦。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT acos(-1); acos


    3.14159265358979 (1 row) ```

  • asin(x)

    描述:反正弦。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT asin(0.5); asin


    .523598775598299 (1 row) ```

  • atan(x)

    描述:反正切。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT atan(1); atan


    .785398163397448 (1 row) ```

  • atan2(y, x)

    描述:y/x的反正切。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT atan2(2, 1); atan2


    1.10714871779409 (1 row) ```

  • bitand(integer, integer)

    描述:计算两个数字与运算(&)的结果。

    返回值类型:bigint类型数字。

    示例:

    ``` postgres=# SELECT bitand(127, 63); bitand


     63
    

    (1 row) ```

  • cbrt(dp)

    描述:立方根。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT cbrt(27.0); cbrt


    3
    

    (1 row) ```

  • ceil(x)

    描述:不小于参数的最小的整数。

    返回值类型:整数。

    示例:

    ``` postgres=# SELECT ceil(-42.8); ceil


    -42 (1 row) ```

  • ceiling(dp or numeric)

    描述:不小于参数的最小整数(ceil的别名)。

    返回值类型:与输入相同。

    示例:

    ``` postgres=# SELECT ceiling(-95.3); ceiling


     -95
    

    (1 row) ```

  • cos(x)

    描述:余弦。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT cos(-3.1415927); cos


    -.999999999999999 (1 row) ```

  • cot(x)

    描述:余切。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT cot(1); cot


    .642092615934331 (1 row) ```

  • degrees(dp)

    描述:把弧度转为角度。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT degrees(0.5); degrees


    28.6478897565412 (1 row) ```

  • div(y numeric, x numeric)

    描述:y除以x的商的整数部分。

    返回值类型:numeric

    示例:

    ``` postgres=# SELECT div(9,4); div


    2 (1 row) ```

  • exp(x)

    描述:自然指数。

    返回值类型:与输入相同。

    示例:

    ``` postgres=# SELECT exp(1.0); exp


    2.7182818284590452 (1 row) ```

  • floor(x)

    描述:不大于参数的最大整数。

    返回值类型:与输入相同。

    示例:

    ``` postgres=# SELECT floor(-42.8); floor


    -43 (1 row) ```

  • radians(dp)

    描述:把角度转为弧度。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT radians(45.0); radians


    .785398163397448 (1 row) ```

  • random()

    描述:0.0到1.0之间的随机数。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT random(); random


    .824823560658842 (1 row) ```

  • ln(x)

    描述:自然对数。

    返回值类型:与输入相同。

    示例:

    ``` postgres=# SELECT ln(2.0); ln


    .6931471805599453 (1 row) ```

  • log(x)

    描述:以10为底的对数。

    返回值类型:与输入相同。

    示例:

    ``` postgres=# SELECT log(100.0); log


    2.0000000000000000 (1 row) ```

  • log(b numeric, x numeric)

    描述:以b为底的对数。

    返回值类型:numeric

    示例:

    ``` postgres=# SELECT log(2.0, 64.0); log


    6.0000000000000000 (1 row) ```

  • mod(x,y)

    描述:

    x/y的余数(模)

    如果x是0,则返回y。

    返回值类型:与参数类型相同。

    示例:

    ``` postgres=# SELECT mod(9,4); mod


    1 (1 row) ```

    ``` postgres=# SELECT mod(9,0); mod


    9 (1 row) ```

  • pi()

    描述:“π”常量。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT pi(); pi


    3.14159265358979 (1 row) ```

  • power(a double precision, b double precision)

    描述:a的b次幂。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT power(9.0, 3.0); power


    729.0000000000000000 (1 row) ```

  • round(x)

    描述:离输入参数最近的整数。

    返回值类型:与输入相同。

    示例:

    ``` postgres=# SELECT round(42.4); round


    42
    

    (1 row)

    postgres=# SELECT round(42.6); round


    43
    

    (1 row) ```

  • round(v numeric, s int)

    描述:保留小数点后s位,s后一位进行四舍五入。

    返回值类型:numeric

    示例:

    ``` postgres=# SELECT round(42.4382, 2); round


    42.44 (1 row) ```

  • setseed(dp)

    描述:为随后的random()调用设置种子(-1.0到1.0之间,包含)。

    返回值类型:void

    示例:

    ``` postgres=# SELECT setseed(0.54823); setseed


    (1 row) ```

  • sign(x)

    描述:输出此参数的符号。

    返回值类型:-1表示负数,0表示0,1表示正数。

    示例:

    ``` postgres=# SELECT sign(-8.4); sign


    -1 (1 row) ```

  • sin(x)

    描述:正弦。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT sin(1.57079); sin


    .999999999979986 (1 row) ```

  • sqrt(x)

    描述:平方根。

    返回值类型:与输入相同。

    示例:

    ``` postgres=# SELECT sqrt(2.0); sqrt


    1.414213562373095 (1 row) ```

  • tan(x)

    描述:正切。

    返回值类型:double precision

    示例:

    ``` postgres=# SELECT tan(20); tan


    2.23716094422474 (1 row) ```

  • trunc(x)

    描述:截断(取整数部分)。

    返回值类型:与输入相同。

    示例:

    ``` postgres=# SELECT trunc(42.8); trunc


    42
    

    (1 row) ```

  • trunc(v numeric, s int)

    描述:截断为s位小数。

    返回值类型:numeric

    示例:

    ``` postgres=# SELECT trunc(42.4382, 2); trunc


    42.43 (1 row) ```

  • width_bucket(op numeric, b1 numeric, b2 numeric, count int)

    描述:返回一个桶,这个桶是在一个有count个桶,上界为b1下界为b2的等深柱图中operand将被赋予的那个桶。

    返回值类型:int

    示例:

    ``` postgres=# SELECT width_bucket(5.35, 0.024, 10.06, 5); width_bucket


            3
    

    (1 row) ```

  • width_bucket(op dp, b1 dp, b2 dp, count int)

    描述:返回一个桶,这个桶是在一个有count个桶,上界为b1下界为b2的等深柱图中operand将被赋予的那个桶。

    返回值类型:int

    示例:

    ``` postgres=# SELECT width_bucket(5.35, 0.024, 10.06, 5); width_bucket


            3
    

    (1 row) ```

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

文集目录
暂无数据