无法创建唯一的部分索引 - Sqlite3

时间:2022-06-01 18:30:14

Consider the following table.

请考虑下表。

CREATE TABLE IF NOT EXISTS wsfiles
(
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  website_id integer NOT NULL,
  parent_id integer,
  archive_id integer,
  path character varying,
  path_sha character varying NOT NULL,
  target character varying,
  name character varying NOT NULL,
  is_directory boolean
  CONSTRAINT uniq_file_website_backup UNIQUE (archive_id, path_sha) ON CONFLICT REPLACE
);

And I need to create the following unique partial index.

我需要创建以下唯一的部分索引。

CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_directory ON wsfiles(path_sha) WHERE is_directory = 1;

But when executing the above schema I am getting a syntax error near the WHERE clause in CREATE UNIQUE INDEX query. This is working well in my local machine and the problem occurs when I am executing on the production machine.

但是在执行上述模式时,我在CREATE UNIQUE INDEX查询中的WHERE子句附近遇到语法错误。这在我的本地机器上运行良好,当我在生产机器上执行时会出现问题。

Error: near line 98: near "WHERE": syntax error

Production machine sqlite3 version is 3.7.17

生产机器sqlite3版本是3.7.17

Local machine sqlite3 version is 3.8.5

本地机器sqlite3版本是3.8.5

1 个解决方案

#1


1  

The documentation says:

文件说:

Partial indexes have been supported in SQLite since version 3.8.0.

自3.8.0版以来,SQLite一直支持部分索引。

#1


1  

The documentation says:

文件说:

Partial indexes have been supported in SQLite since version 3.8.0.

自3.8.0版以来,SQLite一直支持部分索引。