4

我尝试执行以下命令(Postgresql):

ALTER TABLE authentication ADD CONSTRAINT overlapping_times EXCLUDE USING GIST
(method with =,
 authenticator with =,
 box(point(extract(epoch FROM validfrom at time zone 'UTC'),extract(epoch FROM validfrom at time zone 'UTC') ),
     point(extract(epoch FROM validuntil at time zone 'UTC'), extract(epoch FROM validuntil at time zone 'UTC'))) WITH &&
)

我收到以下错误消息:

ERROR:  data type character varying has no default operator class for access method "gist"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.

我做了相当广泛的谷歌搜索,但仍然无法将其翻译成简单的英语。我应该怎么做才能执行上面的命令?“method”的类型是字符变化,“authenticator”是文本,“validfrom”,“validuntil”是日期。

4

1 回答 1

2

For authenticator and method, use a plain unique constraint. text and varchar() are identical for indexing purposes.

This means three alter table statements instead of one, but it should save you these problems. Box should support GiST properly so you should be good there.

In plain English the error is telling you that the data type does not support the index operations expected of the index type. So text strings can't be searched via an index as to whether they overlap, for example. In other words the three cannot be put in the same constraint.

Additionally, keep in mind that UNIQUE constraints are faster than exclude constraints, so are preferred where they work.

于 2013-04-22T06:49:07.400 回答