Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is better POW() or POWER()?

Tags:

sql

mysql

pow

I must make an exponentiation of a number and I don't know which function to use between POW() and POWER(). Which of the two functions is better?

Looking at the MySQL documentation I saw that they are synonymous, but I wanted to understand if there was a reason for two functions that do the same thing.

like image 216
Mattia Trombon Avatar asked Mar 06 '23 17:03

Mattia Trombon


2 Answers

POWER is the synonym of POW. So nothing is better, it is the same:

POWER(X,Y)
This is a synonym for POW().

Using two different names for the same function gives you the possibility to port an SQL query from one dialect to an other dialect without (big) changes.


An example:

You want to use the following TSQL query on MySQL too:

SELECT POWER(2,2) -- 4

Now you can write these query specific for the dialects:

SELECT POWER(2,2) -- 4 - TSQL (POW is not available on TSQL)
SELECT POW(2,2)   -- 4 - MySQL

But you can also use the POWER function on MySQL since this is a synonym for POW:

SELECT POWER(2,2) -- 4 - TSQL and MySQL
like image 103
Sebastian Brosch Avatar answered Mar 15 '23 15:03

Sebastian Brosch


pow and power are synonyms in MySQL.

I'd use power since it's part of the ANSI SQL standard and using it would make your code easier to port if you ever decide to use a different database.

like image 43
Mureinik Avatar answered Mar 15 '23 17:03

Mureinik