-->

~~ Operator In Postgres

2020-08-22 06:25发布

问题:

I have a query in Postgres:

SELECT DISTINCT a.profn FROM tprof a, sap_tstc b, tgrc c 
WHERE ((c.grcid ~~ a.grcid) 
AND ((c.tcode) = (b.tcode)));

What is ~~ mean?

回答1:

From 9.7.1. LIKE of PostgreSQL documentation:

The operator ~~ is equivalent to LIKE, and ~~* corresponds to ILIKE. There are also !~~ and !~~* operators that represent NOT LIKE and NOT ILIKE, respectively. All of these operators are PostgreSQL-specific.



回答2:

It isn't listed in the index of the documentation which is frustrating.

So I had a look with psql:

regress=> \do ~~
                                     List of operators
   Schema   | Name | Left arg type | Right arg type | Result type |       Description       
------------+------+---------------+----------------+-------------+-------------------------
 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
(4 rows)

It's an operator alias for LIKE, that's all.