INSERT或REPLACE到FTS表中

时间:2016-06-02 12:44:25

标签: android sqlite full-text-search

这是我的数据库结构

CREATE VIRTUAL TABLE Products_fts USING fts4(PrdID, ConcatSearchField)
CREATE UNIQUE INDEX CategoryProduct_MM_CatID_PrdID_idx ON CategoryProduct_MM(CategoryID,PrdID)
CREATE INDEX CategoryProduct_MM_CatID_idx ON CategoryProduct_MM(CategoryID)
CREATE INDEX CategoryProduct_MM_PrdID_idx ON CategoryProduct_MM(PrdID)

我需要从具有相同结构的另一个表更新它。

Insert or Replace into Products_fts select * from mydb.Products_fts

插入了数据,但它是重复的。怎么做INSERT或REPLACE?

1 个答案:

答案 0 :(得分:1)

FTS表包含隐藏的rowid字段,可用于执行替换

INSERT OR REPLACE 
INTO Products_fts (rowid, PrdID, ConcatSearchField) 
SELECT PrdID AS rowid, PrdID, ConcatSearchField FROM mydb.Products_fts