我的表已经填充了推文。我正在使用json阅读推文中的一些词典。我在Python中使用SQLite3。
TwTbl = """Create table TwTbl
(created_at text, id text, geo_count integer, user_id integer, text text, geo_id integer, source text,in_reply_to_user_id integer, retweet_count integer,
constraint fk_UserEntry
foreign key (user_id) references UserEntry(id)
constraint fk_Geo
foreign key (geo_count) references Geo(Id)
);"""
c.execute(TwTbl)
现在我必须在这个表“LenTweet”中添加一列,它应该包含coloumn“Text”的长度。我可以使用
添加coloumnc.execute("ALTER TABLE TwTbl ADD LenTweet text").fetchall()
但是,我不知道如何使用“Text”列的长度填充这个新创建的coloumn。我能想到的只是在阅读推文的同时重新创建表并在那里插入长度。必须根据当前表中的值填充coloumn。任何插入都不会触发此操作。有人可以告诉我一个方法,所以我可以用我已经在其中的数据填充表格吗? 提前谢谢。
答案 0 :(得分:1)
UPDATE TwTbl
SET LenTweet = length(text)
其中text是您想知道其长度的列的名称。有关长度函数的详细信息,请参阅this page。
此外,LenTweet应该是数字而不是文本字段。