sqlite查询中的对数函数? [英] Logarithm function in sqlite query?

查看:27
本文介绍了sqlite查询中的对数函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要使用对数函数对超过 400,000 行执行 update.不幸的是,sqlite 中似乎不存在 SQL 对数函数.有什么方法可以导出对数函数或导入 LOG 函数?

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?

我知道如何做到这一点的唯一另一种方法是我相信通过 python 订购 O(n^2).这种方法需要的时间太长(我尝试过,在我的慢速计算机上通过 6% 需要大约 1.5 小时).

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).

我也发现为什么花了这么长时间.数据库中的主键未标记为主键.所以我使用的代码如下:

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...

难以置信的低效... O(n^2)

Incredibly inefficient... O(n^2)

推荐答案

没有内置对数函数;你必须定义你自己的函数.

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

如果您使用 Python,这可以通过 pysqliteAPSW 模块.

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

这篇关于sqlite查询中的对数函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆