Re: Escape string for LIKE op

From: Vik Fearing <vik(dot)fearing(at)dalibo(dot)com>
To: Robert James <srobertjames(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Escape string for LIKE op
Date: 2013-08-15 21:49:32
Message-ID: 520D4CEC.3070300@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/15/2013 10:16 PM, Robert James wrote:
> How can I escape a string for LIKE operations?
>
> I want to do:
>
> SELECT * FROM t WHERE a LIKE b || '%'
>
> But I want be to interpreted literally. If b is 'The 7% Solution', I
> don't want that '%' to be wildcard. I can't find an appropriate
> function to escape it and any other potential wildcards for LIKE
> clauses.

In this particular case, you're better off changing the query to be

SELECT * FROM t WHERE a >= b;

but if your needs are more complex than your actual question, you'll
most likely need to process b like Jeff explained.
--
Vik

In response to

Browse pgsql-general by date

  From Date Subject
Next Message bricklen 2013-08-15 22:24:31 Re: devide and summarize sql result (all)
Previous Message Adrian Klaver 2013-08-15 21:20:11 Re: Strange result with "SELECT ... ORDER BY random() LIMIT 1" and JOINs