tags:

views:

27

answers:

1

Hey everyone,

I am currently working with some of my teacher's old Postgres SQL code and modifying it to match what I need. However, there is one piece of code that I can't seem to find an explanation of anywhere online. In the code he had a case statement with a ~~* used as what looked like a comparison. I am unfamiliar with this syntax and would greatly appreciate any help. Thanks in advance.

CASE
        WHEN sessions.status ~~* 'data%finder%'::text THEN ((sessions.minutes_in_data_ || ' ('::text) || sessions.minutes_in_idle) || ')'::text
        WHEN sessions.status ~~* 'text%edit%'::text THEN ((sessions.minutes_in_text_editor || ' ('::text) || sessions.minutes_in_idle) || ')'::text
        WHEN sessions.status ~~* 'admin%module%'::text AND sessions.minutes_in_module<> 0 THEN ((sessions.minutes_in_module|| ' ('::text) || sessions.minutes_in_idle) || ')'::text
        WHEN sessions.status ~~* 'client%module%'::text AND sessions.minutes_in_module<> 0 THEN ((sessions.minutes_in_module|| ' ('::text) || sessions.minutes_in_idle) || ')'::text
        ELSE NULL::text
    END AS "Duration (Idle)",
+2  A: 

They are equivalent to like/ilike:

From the 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.

Pablo Santa Cruz
Check this link http://www.postgresql.org/docs/9.0/interactive/functions-matching.html
StarShip3000