Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

~~ Operator In Postgres

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?

like image 731
Iswanto San Avatar asked Feb 21 '14 05:02

Iswanto San


2 Answers

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.

like image 109
Lee Duhem Avatar answered Oct 26 '22 03:10

Lee Duhem


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.

like image 21
Craig Ringer Avatar answered Oct 26 '22 04:10

Craig Ringer