热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

PostgreSQL数据库中数字相关函数

PostgreSQL的数字函数主要用于数字操纵和/或数学计算。下表详列的数字函数:名称描述ABS()Returnstheabsolutevalueofnumericexpression.ACOS()Returnsthearccosineofnumericexpression.ReturnsNULLifthevaluei

PostgreSQL的数字函数主要用于数字操纵和/或数学计算。下表详列的数字函数:

名称 描述
ABS() Returns the absolute value of numeric expression.
ACOS() Returns the arccosine of numeric expression. Returns NULL if the value is not in the range -1 to 1.
ASIN() Returns the arcsine of numeric expression. Returns NULL if value is not in the range -1 to 1
ATAN() Returns the arctangent of numeric expression.
ATAN2() Returns the arctangent of the two variables passed to it.
CEIL() Returns the smallest integer value that is not less than passed numeric expression
CEILING() Returns the smallest integer value that is not less than passed numeric expression
COS() Returns the cosine of passed numeric expression. The numeric expression should be expressed in radians.
COT() Returns the cotangent of passed numeric expression.
DEGREES() Returns numeric expression converted from radians to degrees.
EXP() Returns the base of the natural logarithm (e) raised to the power of passed numeric expression.
FLOOR() Returns the largest integer value that is not greater than passed numeric expression.
GREATEST() Returns the largest value of the input expressions.
LEAST() Returns the minimum-valued input when given two or more.
LOG() Returns the natural logarithm of the passed numeric expression.
MOD() Returns the remainder of one expression by diving by another expression.
PI() Returns the value of pi
POW() Returns the value of one expression raised to the power of another expression
POWER() Returns the value of one expression raised to the power of another expression
RADIANS() Returns the value of passed expression converted from degrees to radians.
ROUND() Returns numeric expression rounded to an integer. Can be used to round an expression to a number of decimal points
SIN() Returns the sine of numeric expression given in radians.
SQRT() Returns the non-negative square root of numeric expression.
TAN() Returns the tangent of numeric expression expressed in radians.
ABS(X)

The ABS() function returns the absolute value of X. Consider the following example:

testdb "pun">=# SELECT ABS "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> ABS() "pln">                                                  |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
testdb=# "pln"> SELECT ABS(-);
"pun">+---------------------------------------------------------+
| "pln"> ABS() "pln">                                                  |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
ACOS(X)

This function returns the arccosine of X. The value of X must range between .1 and 1 or NULL will be returned. Consider the following example:

testdb "pun">=# SELECT ACOS "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> ACOS() "pln">                                                 |
"pun">+---------------------------------------------------------+
| "pln"> 0.000000 "pln">                                                |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
ASIN(X)

The ASIN() function returns the arcsine of X. The value of X must be in the range of .1 to 1 or NULL is returned.

testdb "pun">=# SELECT ASIN "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> ASIN() "pln">                                                 |
"pun">+---------------------------------------------------------+
| "pln"> 1.5707963267949 "pln">                                          "pun">|
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
ATAN(X)

This function returns the arctangent of X.

testdb "pun">=# SELECT ATAN "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> ATAN() "pln">                                                 |
"pun">+---------------------------------------------------------+
| "pln"> 0.78539816339745 "pln">                                         "pun">|
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
ATAN2(Y,X)

This function returns the arctangent of the two arguments: X and Y. It is similar to the arctangent of Y/X, except that the signs of both are used to find the quadrant of the result.

testdb "pun">=# SELECT ATAN2 "pun">( "pun">, "pun">);
"pun">+---------------------------------------------------------+
| "pln"> ATAN2(,) "pln">                                              |
"pun">+---------------------------------------------------------+
| "pln"> 0.46364760900081 "pln">                                         "pun">|
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
CEIL(X) CEILING(X)

These function return the smallest integer value that is not smaller than X. Consider the following example:

testdb "pun">=# SELECT CEILING "pun">(3.46 "pun">);
"pun">+---------------------------------------------------------+
| "pln"> CEILING( "lit">3.46) "pln">                                           |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
testdb=# "pln"> SELECT CEIL(- "lit">6.43);
"pun">+---------------------------------------------------------+
| "pln"> CEIL(- "lit">6.43) "pln">                                             |
"pun">+---------------------------------------------------------+
| "pln"> - "pln">                                                      |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
COS(X)

This function returns the cosine of X. The value of X is given in radians.

testdb "pun">=#SELECT COS "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> COS() "pln">                                                 |
"pun">+---------------------------------------------------------+
| "pln"> - "lit">0.44807361612917 "pln">                                        "pun">|
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
COT(X)

This function returns the cotangent of X. Consider the following example:

testdb "pun">=#SELECT COT "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> COT() "pln">                                                  |
"pun">+---------------------------------------------------------+
| "pln"> 0.64209261593433 "pln">                                         "pun">|
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
DEGREES(X)

This function returns the value of X converted from radians to degrees.

testdb "pun">=#SELECT DEGREES "pun">(PI "pun">());
"pun">+---------------------------------------------------------+
| "pln"> DEGREES( "pln">PI()) "pln">                                           |
"pun">+---------------------------------------------------------+
| "pln"> 180.000000 "pln">                                              |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
EXP(X)

This function returns the value of e (the base of the natural logarithm) raised to the power of X.

testdb "pun">=#SELECT EXP "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> EXP() "pln">                                                  |
"pun">+---------------------------------------------------------+
| "pln"> 20.085537 "pln">                                               |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
FLOOR(X)

This function returns the largest integer value that is not greater than X.

testdb "pun">=#SELECT FLOOR "pun">(7.55 "pun">);
"pun">+---------------------------------------------------------+
| "pln"> FLOOR( "lit">7.55) "pln">                                             |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
GREATEST(n1,n2,n3,..........)

The GREATEST() function returns the greatest value in the set of input parameters (n1, n2, n3, and so on). The following example uses the GREATEST() function to return the largest number from a set of numeric values:

testdb "pun">=#SELECT GREATEST "pun">( "pun">, "pun">, "pun">, "pun">, "pun">, "pun">, "pun">, "pun">, "pun">, "pun">);
"pun">+---------------------------------------------------------+
| "pln"> GREATEST(,,,,,,,,,) "pln">                      "pun">|
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                      |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
LEAST(N1,N2,N3,N4,......)

The LEAST() function is the opposite of the GREATEST() function. Its purpose is to return the least-valued item from the value list (N1, N2, N3, and so on). The following example shows the proper usage and output for the LEAST() function:

testdb "pun">=#SELECT LEAST "pun">( "pun">, "pun">, "pun">, "pun">, "pun">, "pun">, "pun">, "pun">, "pun">, "pun">);
"pun">+---------------------------------------------------------+
| "pln"> LEAST(,,,,,,,,,) "pln">                         "pun">|
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
LOG(X) LOG(B,X)

The single argument version of the function will return the natural logarithm of X. If it is called with two arguments, it returns the logarithm of X for an arbitrary base B. Consider the following example:

testdb "pun">=#SELECT LOG "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> LOG() "pln">                                                 |
"pun">+---------------------------------------------------------+
| "pln"> 1.65321251377534 "pln">                                               |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
testdb=# "pln">SELECT LOG(,);
"pun">+---------------------------------------------------------+
| "pln"> LOG(,) "pln">                                            |
"pun">+---------------------------------------------------------+
| "pln"> 16.000000 "pln">                                               |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
MOD(N,M)

This function returns the remainder of N divided by M. Consider the following example:

testdb "pun">=#SELECT MOD "pun">( "pun">, "pun">);
"pun">+---------------------------------------------------------+
| "pln"> MOD(,) "pln">                                               |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
PI()

This function simply returns the value of pi. SQL internally stores the full double-precision value of pi.

testdb "pun">=#SELECT PI "pun">();
"pun">+---------------------------------------------------------+
| "pln"> PI() "pln">                                                    |
"pun">+---------------------------------------------------------+
| "pln"> 3.141593 "pln">                                                |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
POW(X,Y) POWER(X,Y)

These two functions return the value of X raised to the power of Y.

testdb "pun">=# SELECT POWER "pun">( "pun">, "pun">);
"pun">+---------------------------------------------------------+
| "pln"> POWER(,) "pln">                                              |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                      |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
RADIANS(X)

This function returns the value of X, converted from degrees to radians.

testdb "pun">=#SELECT RADIANS "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> RADIANS() "pln">                                             |
"pun">+---------------------------------------------------------+
| "lit">1.570796 "pln">                                                 |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
ROUND(X) ROUND(X,D)

This function returns X rounded to the nearest integer. If a second argument, D, is supplied, then the function returns X rounded to D decimal places. D must be positive or all digits to the right of the decimal point will be removed. Consider the following example:

testdb "pun">=#SELECT ROUND "pun">(5.693893 "pun">);
"pun">+---------------------------------------------------------+
| "pln"> ROUND( "lit">5.693893) "pln">                                          "pun">|
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
testdb=# "pln">SELECT ROUND( "lit">5.693893,);
"pun">+---------------------------------------------------------+
| "pln"> ROUND( "lit">5.693893,) "pln">                                        "pun">|
"pun">+---------------------------------------------------------+
| "pln"> 5.69 "pln">                                                    |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
SIGN(X)

This function returns the sign of X (negative, zero, or positive) as .1, 0, or 1.

testdb "pun">=#SELECT SIGN "pun">(-4.65 "pun">);
"pun">+---------------------------------------------------------+
| "pln"> SIGN(- "lit">4.65) "pln">                                             |
"pun">+---------------------------------------------------------+
| "pln"> - "pln">                                                      |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
testdb=# "pln">SELECT SIGN();
"pun">+---------------------------------------------------------+
| "pln"> SIGN() "pln">                                                 |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
testdb=# "pln">SELECT SIGN( "lit">4.65);
"pun">+---------------------------------------------------------+
| "pln"> SIGN( "lit">4.65) "pln">                                              |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
SIN(X)

This function returns the sine of X. Consider the following example:

testdb "pun">=#SELECT SIN "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> SIN() "pln">                                                 |
"pun">+---------------------------------------------------------+
| "pln"> 0.893997 "pln">                                                |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
SQRT(X)

This function returns the non-negative square root of X. Consider the following example:

testdb "pun">=#SELECT SQRT "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> SQRT() "pln">                                                |
"pun">+---------------------------------------------------------+
| "pln">  "pln">                                                       |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)
TAN(X)

This function returns the tangent of the argument X, which is expressed in radians.

testdb "pun">=#SELECT TAN "pun">( "pun">);
"pun">+---------------------------------------------------------+
| "pln"> TAN() "pln">                                                 |
"pun">+---------------------------------------------------------+
| "pln"> 1.619775 "pln">                                                |
"pun">+---------------------------------------------------------+
"pln"> row in "pln"> set "pln"> ( "lit">0.00 sec "pun">)

推荐阅读
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • 学习笔记(34):第三阶段4.2.6:SpringCloud Config配置中心的应用与原理第三阶段4.2.6SpringCloud Config配置中心的应用与原理
    立即学习:https:edu.csdn.netcourseplay29983432482?utm_sourceblogtoedu配置中心得核心逻辑springcloudconfi ... [详细]
  • Android中高级面试必知必会,积累总结
    本文介绍了Android中高级面试的必知必会内容,并总结了相关经验。文章指出,如今的Android市场对开发人员的要求更高,需要更专业的人才。同时,文章还给出了针对Android岗位的职责和要求,并提供了简历突出的建议。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • [译]技术公司十年经验的职场生涯回顾
    本文是一位在技术公司工作十年的职场人士对自己职业生涯的总结回顾。她的职业规划与众不同,令人深思又有趣。其中涉及到的内容有机器学习、创新创业以及引用了女性主义者在TED演讲中的部分讲义。文章表达了对职业生涯的愿望和希望,认为人类有能力不断改善自己。 ... [详细]
  • baresip android编译、运行教程1语音通话
    本文介绍了如何在安卓平台上编译和运行baresip android,包括下载相关的sdk和ndk,修改ndk路径和输出目录,以及创建一个c++的安卓工程并将目录考到cpp下。详细步骤可参考给出的链接和文档。 ... [详细]
  • 20211101CleverTap参与度和分析工具功能平台学习/实践
    1.应用场景主要用于学习CleverTap的使用,该平台主要用于客户保留与参与平台.为客户提供价值.这里接触到的原因,是目前公司用到该平台的服务~2.学习操作 ... [详细]
  • 如何用UE4制作2D游戏文档——计算篇
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何用UE4制作2D游戏文档——计算篇相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 安卓select模态框样式改变_微软Office风格的多端(Web、安卓、iOS)组件库——Fabric UI...
    介绍FabricUI是微软开源的一套Office风格的多端组件库,共有三套针对性的组件,分别适用于web、android以及iOS,Fab ... [详细]
  • 使用在线工具jsonschema2pojo根据json生成java对象
    本文介绍了使用在线工具jsonschema2pojo根据json生成java对象的方法。通过该工具,用户只需将json字符串复制到输入框中,即可自动将其转换成java对象。该工具还能解析列表式的json数据,并将嵌套在内层的对象也解析出来。本文以请求github的api为例,展示了使用该工具的步骤和效果。 ... [详细]
  • 关于我们EMQ是一家全球领先的开源物联网基础设施软件供应商,服务新产业周期的IoT&5G、边缘计算与云计算市场,交付全球领先的开源物联网消息服务器和流处理数据 ... [详细]
  • 推荐系统遇上深度学习(十七)详解推荐系统中的常用评测指标
    原创:石晓文小小挖掘机2018-06-18笔者是一个痴迷于挖掘数据中的价值的学习人,希望在平日的工作学习中,挖掘数据的价值, ... [详细]
  • 解决Cydia数据库错误:could not open file /var/lib/dpkg/status 的方法
    本文介绍了解决iOS系统中Cydia数据库错误的方法。通过使用苹果电脑上的Impactor工具和NewTerm软件,以及ifunbox工具和终端命令,可以解决该问题。具体步骤包括下载所需工具、连接手机到电脑、安装NewTerm、下载ifunbox并注册Dropbox账号、下载并解压lib.zip文件、将lib文件夹拖入Books文件夹中,并将lib文件夹拷贝到/var/目录下。以上方法适用于已经越狱且出现Cydia数据库错误的iPhone手机。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
author-avatar
川崎步
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有