sqlite rtree:约束失败(适用于通常的 table)

sqlite rtree : constraint failed (works with usual table)

我正在尝试使用 Rtree 并遇到了这种奇怪的行为:在正常 table 中正常工作的 INSERT 语句在 rtree table:

中失败

这个例子运行良好:

DROP TABLE IF EXISTS ltssoffsets;
CREATE  TABLE ltssoffsets(id TEXT NOT NULL, 
    offset_start INT NOT NULL,
    gene_start INT NOT NULL,
    chr TEXT NOT NULL, start INT, end INT,
    PRIMARY KEY (id, offset_start) );

INSERT INTO ltssoffsets VALUES("first", -10, 45, "chr2", 30, 40);
INSERT INTO ltssoffsets VALUES("first", -5, 45, "chr2", 30, 40);

这个失败了:

DROP TABLE IF EXISTS ltssoffsets;
CREATE VIRTUAL TABLE ltssoffsets USING rtree(id TEXT NOT NULL, 
    offset_start INT NOT NULL,
    gene_start INT NOT NULL,
    chr TEXT NOT NULL, start INT, end INT,
    PRIMARY KEY (id, offset_start) );

INSERT INTO ltssoffsets VALUES("first", -10, 45, "chr2", 30, 40);
INSERT INTO ltssoffsets VALUES("first", -5, 45, "chr2", 30, 40);

->  Error: constraint failed

这里有什么问题吗?

虚拟 table 的行为与常规 table 不同。 如何处理列类型和约束取决于虚拟 table 实现。

R-tree documentation 说:

The first column of an SQLite R*Tree must always be an integer primary key. The min/max-value pair columns are stored as 32-bit floating point values [...]

您的 R 树 table 仅具有一个整数主键列 id 和四个坐标列。您的所有类型和约束都将被忽略。

R 树应该用作 索引,而不是 table。

The only information that an R*Tree index stores about an object is its integer ID and its bounding box. Additional information needs to be stored in separate tables and related to the R*Tree index using the primary key.