Re: how to escape _ in select

From: Wes James <comptekki(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to escape _ in select
Date: 2010-07-28 18:07:34
Message-ID: AANLkTin_Zzhr+aL2skZFGtppsvnmGX8ytPd3xKY8aWKH@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jul 28, 2010 at 12:47 PM, Justin Graf <justin(at)magwerks(dot)com> wrote:
> On 7/28/2010 12:35 PM, Wes James wrote:
>> I'm trying to do this:
>>
>> select * from table where field::text ilike '%\_%';
>>
>> but it doesn't work.
>>
>> How do you escape the _ and $ chars?
>>
>> The docs say to use \, but that isn't working.
>>
>> ( http://www.postgresql.org/docs/8.3/static/functions-matching.html )
>>
>> The text between '%...%' can be longer, I'm just trying to figure out
>> how to escape some things.  I've found that ' works with '' and \
>> works with \\
>>
>
> Instead of escaping how about looking at double $ quoting.

I tried this, but it just returns a count for all the records:

select count(*) from table where field::text ilike '%' || $$_$$ || '%';

.... ilike '%$$_$$%'

returns a count of 0

So does $$a$$ and I know there is some text in the field with an "a".

-wes

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2010-07-28 18:34:20 Re: how to escape _ in select
Previous Message Wes James 2010-07-28 17:35:18 how to escape _ in select