From: Jasen Betts <jasen@xnet.co.nz>
To: pgsql-sql@postgresql.org
Subject: Re: problem using regexp_replace
Date: 12 Jan 2010 12:10:50 GMT
Message-ID: <hihosa$sj4$1@reversiblemaps.ath.cx> (raw)
References: <6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar>
On 2010-01-11, gherzig@fmed.uba.ar <gherzig@fmed.uba.ar> wrote:
> So, i come with this:
> SELECT regexp_replace(
> formato, E'{([^.]*)\.([a-zA-Z0-9]*)},
> valores_sustitucion(ARRAY[E'\\1'::varchar,E'\\2'::varchar]),
> 'g')
> from table where id =1;
select valores_sustitucion(ARRAY[E'\\1'::varchar,E'\\2'::varchar]);
valores_sustitucion
---------------------
FALSE
that's the problem you are getting, the valores_sustitucion works on
the values given and that result is given to regexp_replace.
try this:
create OR REPLACE function magic( inp text ) returns text as $F$
DECLARE
tmp text;
res text;
BEGIN
tmp= 'SELECT ' || regexp_replace(quote_literal(inp),E'{([^.]*)\.([a-zA-Z0-9]*)}',
$s$'|| valores_sustitucion(ARRAY[E'\1',E'\2']) ||'$s$,'g');
-- raise notice 'tmp=%',(tmp);
EXECUTE tmp INTO res;
RETURN res;
END;
$F$ language plpgsql;
SELECT magic( formato ) FROM from table where id =1;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jasen@xnet.co.nz
Subject: Re: problem using regexp_replace
In-Reply-To: <hihosa$sj4$1@reversiblemaps.ath.cx>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox