12

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?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Iswanto San
  • 18,263
  • 13
  • 58
  • 79

2 Answers2

21

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.

Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
6

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.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778