我正在尝试创建一个排除约束,以防止重叠的有效时间戳范围,但只比较具有相同文本值的记录的范围。我希望文本值比较不区分大小写。我可以将=
运算符与文本字段一起使用,但不能与citext
字段一起使用,~~*
运算符不可交换。
这是PostgreSQL 9.5,并且在数据库上创建了citext
和btree_gist
扩展。
CREATE TABLE customer_product_categories (
id serial PRIMARY KEY,
name text NOT NULL,
effective tstzrange DEFAULT '[-infinity,infinity]',
EXCLUDE USING gist (name WITH ~~*, effective WITH &&)
)
ERROR: operator ~~*(text,text) is not commutative
CREATE TABLE customer_product_categories (
id serial PRIMARY KEY,
name citext NOT NULL,
effective tstzrange DEFAULT '[-infinity,infinity]',
EXCLUDE USING gist (name WITH =, effective WITH &&)
)
ERROR: operator =(citext,citext) is not a member of operator family "gist_text_ops"
ILIKE
如何不可交换?答案 0 :(得分:2)
A-公顷!我想到了。我不得不去上学:
CREATE TABLE "customer_product_categories" (
"id" serial PRIMARY KEY,
"name" text NOT NULL,
"effective" tstzrange DEFAULT '[-infinity,infinity]',
EXCLUDE USING gist (LOWER("name") WITH =, "effective" WITH &&)
)