Regular expression on a string problem.

From: "Paul Mendoza" <mendoza(dot)paul(dot)postgres(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Regular expression on a string problem.
Date: 2007-09-07 22:53:04
Message-ID: b5baf96a0709071553u1f05d48dm738bfb7b7cc1f6c1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Here is a problem I'm having with a function I've created. It should be
returning a varchar value no matter what the input is but I'm getting a null
value back. Then it says in the error that I'm using "nonstandard use of
escape in a string literal at character 9". What do you think this should be
changed to?

Query OK (0.45 sec)
Return Value: NULL
WARNING: nonstandard use of escape in a string literal at character 9
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
QUERY: SELECT '/(\.PR\.)|(\.PR$)/'
CONTEXT: PL/pgSQL function "clean_name" line 17 at assignment

Here is the function. p_text is a varchar that might have "PR" in it.

DECLARE
var_regex_pattern varchar;

BEGIN

-- If "PR" is not in the text variable.
IF position('PR' in p_text) = 0 THEN
var_regex_pattern = '/\./';
RETURN substring(p_text from var_regex_pattern);
END IF;

IF position('PR' in p_text) > 0 THEN
-- If "PR" is in the text variable.
var_regex_pattern = '/(\.PR\.)|(\.PR$)/';
RETURN substring(p_text from var_regex_pattern);
END IF;

END;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Darek Czarkowski 2007-09-07 23:28:41 Re: Postgresql 7.3 on Red Hat Enterprise 5 (Problem with SEMMNI, SEMMNS)
Previous Message Robert Fitzpatrick 2007-09-07 22:43:26 Left joining table to setof function