从 sqlite db 中删除行仍然没有删除值并且大小越来越大

Deleting the rows from sqlite db still the values are not getting deleted and size is getting bigger

我正在收集推特流并将其存储在 sqlite 中 db.Since 流即将到来并且数据库越来越大我执行了一个命令来删除早于 minute.But 的推文因为我是 sqlite

的新手,所以只有推文和数据库正在获得 bigger.Please 帮助

这是代码

class listener(StreamListener):

def on_data(self,data):
    try:
        data = json.loads(data)
        tweet = unidecode(data['text'])
        text = preprocess(tweet)
        score = predict(text)['score']
        
        created_at = data['created_at']
        

        
        

        c.execute('INSERT INTO sentiment (created_at,tweet,score) VALUES (?,?,?)',(created_at,tweet,score))
        conn.commit()

      
        
        c.execute('DELETE FROM sentiment WHERE created_at IN(SELECT created_at FROM(SELECT 
                  created_at, strftime("%s","now") - strftime("%s",created_at) AS passed_time FROM 
                sentiment WHERE passed_time >=60))')
       
        conn.commit()

    except Exception as e:
        print(str(e))

您正在测试 IN 子查询,它又具有一个子查询, 而你抱怨这种复杂的方法不起作用, 那 IN 没有找到匹配项 在您的“自 1970 年以来的秒数”时间戳中。

好的。你的规范 比那简单得多 ,你说你想要

a command to delete the tweets that are older than a minute

小菜一碟。就跟着那个英文句子变成SQL:

DELETE FROM sentiment WHERE created_at < strftime('%s', 'now') - 60;

当前时间减去六十秒是一分钟前, 并且 WHERE 子句要求的行早于该行。