Skip site navigation (1) Skip section navigation (2)

Re: 8.0.3 regexp_replace()...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "rlee0001" <robeddielee(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: 8.0.3 regexp_replace()...
Date: 2006-01-31 15:22:11
Message-ID: 4033.1138720931@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-general
"rlee0001" <robeddielee(at)hotmail(dot)com> writes:
> CREATE OR REPLACE FUNCTION "regexp_replacex" (source varchar, pattern
> varchar, replacement varchar) RETURNS varchar AS
> $body$
> DECLARE
>  retvalue VARCHAR;
> BEGIN
>  retvalue = "source";
>  LOOP
>   retvalue = REPLACE(retvalue, SUBSTRING(retvalue FROM "pattern"),
> "replacement");
>   EXIT WHEN retvalue = REPLACE(retvalue, SUBSTRING(retvalue FROM
> "pattern"), "replacement");
>  END LOOP;
>  RETURN retvalue;
> END;
> $body$
> LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

You probably don't want to be double-quoting the variable names.  Also,
I think this should be marked STRICT IMMUTABLE rather than the options
you have chosen.

> if you test it and do expect to have to kill the server when it enters
> the infinate loop.

Control-C cancels the query just fine for me ...

			regards, tom lane

In response to

pgsql-general by date

Next:From: jaoDate: 2006-01-31 15:28:04
Subject: Re: Insert rate drops as table grows
Previous:From: P. Scott DeVosDate: 2006-01-31 15:21:46
Subject: plpython error logs

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group