9.3. Mathematical Functions and Operators
9.3.数学函数和运算符
Mathematical operators are provided for many PostgreSQL types. For types without standard mathematical
conventions (e.g., date/time types) we describe the actual behavior in subsequent sections.
PostgreSQL提供了许多类型的数学运算符。对于没有标准数学约定的类型(例如,日期/时间类型),我们将在后续部分中描述其实际行为。
Table 9.4 shows the available mathematical operators.
表9.4列出了可用的数学运算符。
The bitwise operators work only on integral data types, whereas the others are available for all numeric
data types. The bitwise operators are also available for the bit string types
bit
and
bit varying
,
as shown in Table 9.13.
按位运算符仅适用于整数数据类型,而其他运算符可用于所有数字数据类型。 如表9.13所示,按位运算符还可用于位串类型bit和bit variant。
Table 9.5 shows the available mathematical functions. In the table,
dp
indicates
double precision
.
Many of these functions are provided in multiple forms with different argument types. Except
where noted, any given form of a function returns the same data type as its argument. The functions
working with
double precision
data are mostly implemented on top of the host system's C
library; accuracy and behavior in boundary cases can therefore vary depending on the host system.
表9.5列出了可用的数学函数。 在表中,dp表示双精度。 这些函数中的许多函数都以不同的参数类型的多种形式提供。 除非另有说明,任何给定形式的函数都将返回与其参数相同的数据类型。 使用双精度数据的函数主要在主机系统的C库实现; 因此,边界情况下的准确性和行为可能会因主机系统而异。
The characteristics of the values returned by
random()
depend on the system implementation. It is
not suitable for cryptographic applications; see pgcrypto module for an alternative.
random()返回的值的特征取决于系统实现。 它不适用于密码应用程序;密码应用程序可参见pgcrypto模块。
Finally, Table 9.7 shows the available trigonometric functions. All trigonometric functions take arguments
and return values of type
double precision
. Each of the trigonometric functions comes
in two variants, one that measures angles in radians and one that measures angles in degrees.
最后,表9.7显示了可用的三角函数。 所有三角函数均接受参数并返回双精度类型的值。 每个三角函数都有两种变体,一种以弧度为单位,另一种以度为单位。
Note
注
Another way to work with angles measured in degrees is to use the unit transformation
functions
radians()
and
degrees()
shown earlier. However, using the degree-
based trigonometric functions is preferred, as that way avoids round-off error for
special cases such as
sind(30)
.
处理以度为单位的角度的另一种方法是使用前面提到的单位转换函数radians()和degree()。 但是,最好使用基于度的三角函数,因为这样可以避免在诸如sind(30)之类的特殊情况下产生舍入误差。