Re: how to escape _ in select

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to escape _ in select
Date: 2010-07-29 07:16:44
Message-ID: i2r9ss$gt0$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Wes James, 28.07.2010 19:35:
> 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 \\
>

To get around the somewhat quirky usage of backslashes, you can simply define a different esacpe character:

select *
from table
where field::text ilike '%(at)_%' escape '@';

Thomas

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rainer Stengele 2010-07-29 09:41:57 Re: grouping subsets
Previous Message Dmitriy Igrishin 2010-07-28 20:44:59 Re: how to escape _ in select