Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select * math operations

is it possible to select colums and do complex operations on them for example select factorial(column1) from table1 or select integral_of(something) from table2

perhaps there are libraries that support such operations?

like image 224
Alex Gordon Avatar asked Jun 28 '10 15:06

Alex Gordon


2 Answers

Yes, you can call all pre-defined functions of your DB on the select columns and you can use CREATE FUNCTION to define your own.

But DBs are meant to wade through huge amounts of data, not to do complex calculations on them. If you try this, you'll find that many operations are awfully slow (especially the user defined ones).

Which is why most people fetch the data from the database and then do the complex math on the application side. This also makes it more simple to test and optimize the code or replace it with a new version.

like image 169
Aaron Digulla Avatar answered Oct 25 '22 04:10

Aaron Digulla


Yes, it is. If the function you want is not built into your RDBMS, you can write your own User Defined Functions.

You'll find an example here: http://www.15seconds.com/Issue/000817.htm.

like image 45
D'Arcy Rittich Avatar answered Oct 25 '22 04:10

D'Arcy Rittich