Re: Regular expression character escape

From: Ronan Dunklau <rdunklau(at)gmail(dot)com>
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Regular expression character escape
Date: 2012-02-24 16:04:29
Message-ID: 4F47B50D.8010803@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 24/02/2012 16:38, David Johnston wrote:

> How about:
>
> WHERE some_col LIKE (user_submitted_input || '%') AND some_col ~ ('^.{' || length_of_user_submitted_input || '}\d*$')
>
> I'd have some reservations regarding multi-byte characters however - but this avoids any escaping of the input string.

That's a clever trick, I might end using it.

> You could (should?) write the escaping routine on the server side in a user-defined function:
>
> WHERE some_col ~ ('^' || make_regexp_literal(user_submitted_stringliteral) || '\d*$')

I totally agree, but I hoped I could use an already existing function
without having to read the whole spec to figure what should and should
not be escaped.

> David J.
>
>

--
Ronan Dunklau

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2012-02-24 16:05:05 Re: Stability in Windows?
Previous Message Durumdara 2012-02-24 16:04:13 Re: Stability in Windows?