PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References
PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References

PostgreSQL POWER() Function



The PostgreSQL POWER() function returns the base raise to the power of exponent. In special cases it returns the following:

  • If the exponent is zero, then 1 is returned.

The POWER() function is a synonym for the POW() function.

Syntax

POWER(base, exponent)

Parameters

base Required. Specify the base.
exponent Required. Specify the exponent.

Return Value

Returns the base raise to the power of exponent.

Example 1:

The example below shows the usage of POWER() function.

SELECT POWER(5, 2);
Result: 25

SELECT POWER(3, 5);
Result: 243

SELECT POWER(5.5, 2);
Result: 30.2500000000000000

SELECT POWER(5.5, 2.1);
Result: 35.872500303490979

SELECT POWER(5, -1);
Result: 0.2

SELECT POWER(5, 0);
Result: 1

SELECT POWER(0, 5);
Result: 0

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 10.5
Data 21
Data 35
Data 410
Data 550

The statement given below can be used to calculate the square root of column x.

SELECT *, POWER(x, 0.5) AS POWER_Value FROM Sample;

This will produce the result as shown below:

DataxPOWER_Value
Data 10.50.7071067811865475
Data 211.0000000000000000
Data 352.2360679774997897
Data 4103.1622776601683793
Data 5507.0710678118654752

Example 3:

Consider a database table called Sample with the following records:

Dataxy
Data 10.52
Data 213
Data 354
Data 4103
Data 5503

To calculate the records of column x raised to the power of records of column y, the following query can be used:

SELECT *, POWER(x, y) AS POWER_Value FROM Sample;

This will produce the result as shown below:

DataxyPOWER_Value
Data 10.520.2500000000000000
Data 2131
Data 354625
Data 41031000
Data 5503125000

❮ PostgreSQL Functions