why content_rowid must be integer in FTS?

Viewed 131

Why content_rowid must be integer in FTS?

And what if content_rowid be a not primary integer key?

I create a VIRTUAL TABLE and TRIGGER width content_rowid equal to a not primary integer key, it works, has there any hidden risk?

CREATE TABLE tbl (a, createTime INTEGER NOT NULL);
CREATE VIRTUAL TABLE fts USING fts5(a, content=tbl, content_rowid=createTime);

CREATE TRIGGER IF NOT EXISTS tbl_ai AFTER INSERT ON tbl
BEGIN
  INSERT INTO fts (rowid, a)
  VALUES (new.createTime, new.a);
 END;

Is there anywayt to set content_rowid to a text column?I have tried,throw error dataType mismatch

CREATE TABLE tbl (a, guid text NOT NULL PRIMARY KEY);
CREATE VIRTUAL TABLE fts USING fts5(a, content=tbl, content_rowid=guid);

CREATE TRIGGER IF NOT EXISTS tbl_ai AFTER INSERT ON tbl
BEGIN
  INSERT INTO fts (rowid, a)
  VALUES (new.guid, new.a);
 END;
1 Answers

Your virtual table explicitly references tbl.createTime, which is an integer. The resulting virtual column is of the same type, necessarily.

Related