Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logarithm function in sqlite query?

Tags:

python

sqlite

I really need to perform an update on over 400,000 rows using the logarithm function. Unfortunately, the SQL logarithm function does not seem to exist in sqlite. Is there any way I can derive the logarithm function or import the LOG function?

The only other way I know how to do this is I believe order O(n^2) through python. This approach will take too long (I tried, it took about and 1.5 hours to go through 6% on my slow computer).

EDIT:

I also found out why it took so long. The primary key in the database was not marked as a primary key. So the code that I was using followed:

for row in database:
    ...calculations for the row...
    ...sql update for the specific row which follows:...
    for search_row in database:
        if search_row[id] = row[id]:
            ...update values here...

Incredibly inefficient... O(n^2)

like image 644
jakebird451 Avatar asked Jan 27 '13 20:01

jakebird451


1 Answers

There is no built-in logarithm function; you have to define your own function.

If you're using Python, this is possible with both the pysqlite and APSW modules.

like image 151
CL. Avatar answered Oct 23 '22 10:10

CL.