Re: Question with combining ANY with ilike

From: Rusty Conover <rconover(at)infogears(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Question with combining ANY with ilike
Date: 2008-12-12 17:56:09
Message-ID: 5975FBBC-2852-46B9-93DA-F438B5D9AB69@infogears.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Dec 12, 2008, at 6:12 AM, Tom Lane wrote:

> Rusty Conover <rconover(at)infogears(dot)com> writes:
>> I'd like to specify a pattern then apply that pattern to match each
>> element of an array:
>
>> rconover=# select 'foobar%' ~~ ANY (ARRAY['bar', 'cat',
>> 'foobar:asdf']);
>> ?column?
>> ----------
>> f
>> (1 row)
>
>> I'd like the the pattern would be evaluated against all of the array
>> elements, but the order of parameters for the ~~ operator when
>> combined with the ANY command is backwards to what I need.
>
> Create a reverse-LIKE operator and underlying one-line SQL function.
>
> regards, tom lane

Thanks Tom.

For the benefit of future searches I used:

create function reverse_ilike(text, text) RETURNS boolean AS 'select
$2 ilike $1;' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT;

create operator ~~*^ (PROCEDURE = reverse_ilike, LEFTARG = text,
RIGHTARG = text);

Best,

Rusty
--
Rusty Conover
rconover(at)infogears(dot)com
InfoGears Inc / GearBuyer.com / FootwearBuyer.com
http://www.infogears.com
http://www.gearbuyer.com
http://www.footwearbuyer.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Emanuel Calvo Franco 2008-12-12 18:16:22 Re: Schemas and Privileges
Previous Message Joshua D. Drake 2008-12-12 17:49:01 Re: Data Replication