9.3. 數學函式及運算子

Mathematical operators are provided for manyPostgreSQLtypes. For types without standard mathematical conventions (e.g., date/time types) we describe the actual behavior in subsequent sections.

Table 9.4shows the available mathematical operators.

Table 9.4. Mathematical Operators

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 typesbitandbit varying, as shown inTable 9.13.

Table 9.5shows the available mathematical functions. In the table,dpindicatesdouble 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 withdouble precisiondata 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.

Table 9.5. Mathematical Functions

Table 9.6shows functions for generating random numbers.

Table 9.6. Random Functions

The characteristics of the values returned byrandom()depend on the system implementation. It is not suitable for cryptographic applications; seepgcryptomodule for an alternative.

Finally,Table 9.7shows the available trigonometric functions. All trigonometric functions take arguments and return values of typedouble precision. Each of the trigonometric functions comes in two variants, one that measures angles in radians and one that measures angles in degrees.

Table 9.7. Trigonometric Functions

Note

Another way to work with angles measured in degrees is to use the unit transformation functionsradians()anddegrees()shown earlier. However, using the degree-based trigonometric functions is preferred, as that way avoids roundoff error for special cases such assind(30).

Last updated