Re: Escape string for LIKE op - Mailing list pgsql-general

From Vik Fearing
Subject Re: Escape string for LIKE op
Date
Msg-id 520D4CEC.3070300@dalibo.com
Whole thread Raw
In response to Escape string for LIKE op  (Robert James <srobertjames@gmail.com>)
List 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


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Strange result with "SELECT ... ORDER BY random() LIMIT 1" and JOINs
Next
From: bricklen
Date:
Subject: Re: devide and summarize sql result (all)