Re: [GENERAL] Regular expression character escape

2012-02-24 Thread Tom Lane
Ronan Dunklau writes: > Unfortunately for my use case, "too much" quoting can lead to errors in > postgresql. AFAIR, the only stuff that's unsafe to insert a backslash before is ASCII letters. This is documented in the fine print discussing regular expressions, btw. rega

Re: [GENERAL] Regular expression character escape

2012-02-24 Thread Ronan Dunklau
On 24/02/2012 17:43, Heiko Wundram wrote: > Am 24.02.2012 17:40, schrieb Ronan Dunklau: >> On 24/02/2012 17:09, Heiko Wundram wrote: >>> Use the corresponding function of your programming language/framework of >>> choice. E.g. Python delivers this as re.escape(). >> >> Thank you, but as I wrote in

Re: [GENERAL] Regular expression character escape

2012-02-24 Thread Heiko Wundram
Am 24.02.2012 17:40, schrieb Ronan Dunklau: On 24/02/2012 17:09, Heiko Wundram wrote: Use the corresponding function of your programming language/framework of choice. E.g. Python delivers this as re.escape(). Thank you, but as I wrote in the original post, I don't know how postgresql and pytho

Re: [GENERAL] Regular expression character escape

2012-02-24 Thread Ronan Dunklau
On 24/02/2012 17:09, Heiko Wundram wrote: > Am 24.02.2012 17:04, schrieb Ronan Dunklau: >> On 24/02/2012 16:38, David Johnston wrote: >>> You could (should?) write the escaping routine on the server side in >>> a user-defined function: >>> >>> WHERE some_col ~ ('^' || >>> make_regexp_literal(user_s

Re: [GENERAL] Regular expression character escape

2012-02-24 Thread Heiko Wundram
Am 24.02.2012 17:04, schrieb Ronan Dunklau: On 24/02/2012 16:38, David Johnston wrote: 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 h

Re: [GENERAL] Regular expression character escape

2012-02-24 Thread Ronan Dunklau
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 inp

Re: [GENERAL] Regular expression character escape

2012-02-24 Thread David Johnston
-Original Message- From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-ow...@postgresql.org] On Behalf Of Ronan Dunklau Sent: Friday, February 24, 2012 6:34 AM To: pgsql-general@postgresql.org Subject: [GENERAL] Regular expression character escape Hello. I'd like to perf

[GENERAL] Regular expression character escape

2012-02-24 Thread Ronan Dunklau
Hello. I'd like to perform a query using user-submitted input in a regular expression. Something along the lines of: select some_col from some_table where some_col ~ ('^' || user_submitted_input || '\d*$') This query is looking for every value matching the user submitted input with optional tra