在Postgresql 9.2.3中我试图创建这个简化的表:
CREATE TABLE test ( user_id INTEGER,startend TSTZRANGE,EXCLUDE USING gist (user_id WITH =,startend WITH &&) );
但我得到这个错误:
06001
PostgreSQL docs use this example对我不起作用:
CREATE TABLE room_reservation ( room text,during tsrange,EXCLUDE USING gist (room WITH =,during WITH &&) );
相同的错误消息.
And this one,对我来说也不起作用:
CREATE TABLE zoo ( cage INTEGER,animal TEXT,EXCLUDE USING gist (cage WITH =,animal WITH <>) );
相同的错误消息.
我可以毫无问题地创建它:
CREATE TABLE test ( user_id INTEGER,EXCLUDE USING gist (startend WITH &&) );
还有这个:
CREATE TABLE test ( user_id INTEGER,EXCLUDE USING btree (user_id WITH =) );
我花了很多时间寻找有关如何完成这项工作的提示,或者弄清楚为什么它不起作用.有任何想法吗?
按照手册
at the location you linked to中的说明安装附加模块
原文链接:https://www.f2er.com/postgresql/192310.htmlbtree_gist
:
You can use the
btree_gist
extension to define exclusion constraints
on plain scalar data types,which can then be combined with range
exclusions for maximum flexibility. For example,afterbtree_gist
is
installed,the following constraint will reject overlapping ranges
only if the meeting room numbers are equal:
在现代的Postgresql中,您只需要运行(每个数据库一次):
CREATE EXTENSION btree_gist;
您需要先在操作系统中安装“contrib”软件包.细节取决于您的操作系统和使用的软件存储库.对于Debian家族来说,它通常是postgresql-contrib-9.2(对于Postgres 9.2).或者只是为Red Hat家族提供postgresql-contrib.在SO上考虑这个相关的答案: