【发布时间】:2016-03-04 23:22:11
【问题描述】:
(最初是this question的一部分,但有点无关紧要,所以我决定将其作为一个问题。)
我找不到运算符~<~ 是什么。 Postgres 手册只提到了~ 和类似的运算符here,但没有提到~<~。
在 psql 控制台中摆弄时,我发现这些命令给出了相同的结果:
SELECT * FROM test ORDER BY name USING ~<~;
SELECT * FROM test ORDER BY name COLLATE "C";
这些给出了相反的顺序:
SELECT * FROM test ORDER BY name USING ~>~;
SELECT * FROM test ORDER BY name COLLATE "C" DESC;
还有一些关于波浪号运算符的信息:
\do ~*~
List of operators
Schema | Name | Left arg type | Right arg type | Result type | Description
------------+------+---------------+----------------+-------------+-------------------------
pg_catalog | ~<=~ | character | character | boolean | less than or equal
pg_catalog | ~<=~ | text | text | boolean | less than or equal
pg_catalog | ~<~ | character | character | boolean | less than
pg_catalog | ~<~ | text | text | boolean | less than
pg_catalog | ~>=~ | character | character | boolean | greater than or equal
pg_catalog | ~>=~ | text | text | boolean | greater than or equal
pg_catalog | ~>~ | character | character | boolean | greater than
pg_catalog | ~>~ | text | text | boolean | greater than
pg_catalog | ~~ | bytea | bytea | boolean | matches LIKE expression
pg_catalog | ~~ | character | text | boolean | matches LIKE expression
pg_catalog | ~~ | name | text | boolean | matches LIKE expression
pg_catalog | ~~ | text | text | boolean | matches LIKE expression
(12 rows)
第 3 行和第 4 行是我要找的运算符,但描述对我来说有点不足。
【问题讨论】:
-
如果您有一个带有 opclass 的索引,Postgres 将使用此运算符进行查找。 postgresql.org/docs/9.5/static/indexes-opclass.html
-
在
test (name text_pattern_ops)上创建索引并查看EXPLAIN的name LIKE 'abc%'输出
标签: postgresql sorting pattern-matching operators