2016-03-04 67 views
5

(本this question一部分,但它是有点文不对题,所以我决定把它自身的问题。)符〜<〜Postgres里

我找不到什么操作~<~是。 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行是我正在查找的操作员,但是desc ription对我来说有点不足。

+0

该运营商正在使用的Postgres的查询,如果你有一个的opclass指数。 http://www.postgresql.org/docs/9.5/static/indexes-opclass.html –

+0

在'test(name text_pattern_ops)'上创建一个索引并查看'name LIKE'的'EXPLAIN'输出abc%'' –

回答

4

~>=~~<=~~>~~<~text图案(或varchar,基本上是相同的)的运营商,它们各自的兄弟姐妹>=<=><的对应物。他们严格按字节值对字符数据进行排序,忽略任何排序规则设置(与其兄弟相对)。这使得它们更快,但对大多数语言/国家也无效。

“C”语言环境实际上与没有语言环境相同,表示没有整理规则。这就解释了为什么ORDER BY name USING ~<~ORDER BY name COLLATE "C"最终会这样做。

在这个相关答案对dba.SE的最后一章详细解释:


注意~~是用来实现SQL LIKE expression Postgres的运营商和与几乎没有关系以上。同样,~~*执行ILIKE。更多:

+0

感谢您的回答,尤其是指出与“COLLATE”C“'的关系。 我甚至在问我的问题之前,在dba.SE上读到了你的答案,但不知何故,我错过了用〜〜〜〜操作符的部分。 –