Numerical Functions

I l @ ve RuBoard

PostgreSQL includes many functions that assist in performing numerical calculations. The following sections discuss the included numerical functions in PostgreSQL.

ABS

Description

The ABS function returns the absolute value of a supplied number.

Input
 ABS(  num  ) 
Examples
 ABS(-7)  7  ABS(-7.234)  7.234 
Notes

The ABS function's return value is the same data type that it is passed.

ACOS

Description

The ACOS function returns an inverse cosine.

Input
 ACOS(  num  ) 

ASIN

Description

The ASIN function returns an inverse sine.

Input
 ASIN(  num  ) 

ATAN

Description

The ATAN function returns an inverse tangent.

Input
 ATAN(  num  ) 

ATAN2

Description

The ATAN2 function returns an inverse tangent of y/x.

Input
 ATAN2(  x,y  ) 

CBRT

Description

The CBRT function returns the cube root of the supplied number.

Input
 CBRT(  num  ) 
Example
 CBRT(27)  3 

CEIL

Description

The CEIL function returns the smallest integer not less than the supplied value.

Input
 CEIL(  num  ) 
Example
 CEIL(-22.2)  -22 

COS

Description

The COS function returns a cosine value.

Input
 COS(  num  ) 

COT

Description

The COT function returns a cotangent value.

Input
 COT(  num  ) 

DEGREES

Description

The DEGREES function converts from radians to degrees.

Input
 DEGREES(  num  ) 
Example
 DEGREES(1)  90 

EXP

Description

The EXP function performs an exponential calculation on the supplied value.

Input
 EXP(  num  ) 
Example
 EXP(0)  1.0 

FLOOR

Description

The FLOOR function returns the largest integer not greater than the supplied value.

Input
 FLOOR(  num  ) 
Example
 FLOOR(-22.2)  -23 

LN

Description

The LN function performs a natural logarithm on the supplied number.

Input
 LN(  num  ) 
Example
 LN(100)  4.6051701860 

LOG

Description

The LOG function performs a standard base-10 logarithm on the supplied value.

Input
 LOG(  num  ) 
Example
 LOG(100)  2.0 

PI

Description

The PI function returns the standard pi value.

Inputs

None.

Example
 PI()  3.1459265358979 

POW or POWER

Description

The POW function raises a number by the specified exponent.

Inputs
 POW(  num, exp  ) 

num ”The number on which to perform the exponentiation.

exp ”The power to which to raise the number.

Examples
 POW(2,2)  4.0  POW(2,3)  8.0 

RADIANS

Description

The RADIANS function converts the supplied degrees to radian units.

Input
 RADIANS(  num  ) 
Example
 RADIANS(90)  1 

RANDOM

Description

The RANDOM function returns a pseudorandom number between 0.0 and 1.0.

Inputs

None.

Example
 RANDOM()  .654387 

ROUND

Description

The ROUND function rounds a number to the specified decimal places.

Inputs
 ROUND(  num, dec  ) 

num ”The number to manipulate.

dec ”An integer that represents the number of decimal places.

Examples
 ROUND(1.589, 1)  1.6  ROUND(1.589, 2)  1.59 

SIN

Description

The SIN function performs a sine function on the supplied value.

Input
 SIN(num) 

SQRT

Description

The SQRT function returns the square root of the supplied value.

Input
 SQRT(  num  ) 
Example
 SQRT(9)  3 

TAN

Description

The TAN function performs a tangent calculation on the supplied number.

Input
 TAN(  num  ) 

TRUNC

Description

The TRUNC function truncates to the specified number of decimal places without rounding them out.

Inputs
 TRUNC(  num  [,  dec  ]) 

num ”The number on which to perform the truncate.

dec ”The number of decimal places to leave remaining, if supplied; otherwise , truncate all decimal places.

Examples
 TRUNC(1.589999, 2)  1.58  TRUNC(1.589999)  1 
I l @ ve RuBoard


PostgreSQL Essential Reference
PostgreSQL Essential Reference
ISBN: 0735711216
EAN: 2147483647
Year: 2001
Pages: 118
Authors: Barry Stinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net