Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 98FD2633A6B for ; Tue, 12 Jan 2010 13:19:10 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 50838-01 for ; Tue, 12 Jan 2010 17:19:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.fmed.uba.ar (mail.fmed.uba.ar [157.92.152.1]) by mail.postgresql.org (Postfix) with ESMTP id 03D61633816 for ; Tue, 12 Jan 2010 13:19:00 -0400 (AST) Received: from www.webmail.fmed.uba.ar (localhost [127.0.0.1]) by mail.fmed.uba.ar (Postfix) with ESMTP id 011AF39C52F; Tue, 12 Jan 2010 14:17:39 -0200 (ARST) Received: from 190.17.234.54 (SquirrelMail authenticated user gherzig) by www.webmail.fmed.uba.ar with HTTP; Tue, 12 Jan 2010 14:17:40 -0200 (ARST) Message-ID: <0862feba5dd70bb08d69d1cd4c33eb29.squirrel@www.webmail.fmed.uba.ar> In-Reply-To: References: <6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar> Date: Tue, 12 Jan 2010 14:17:40 -0200 (ARST) Subject: Re: problem using regexp_replace From: gherzig@fmed.uba.ar To: "Jasen Betts" Cc: pgsql-sql@postgresql.org User-Agent: SquirrelMail/1.4.15 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.189 tagged_above=-10 required=5 tests=BAYES_50=0.001, FH_DATE_PAST_20XX=3.188 X-Spam-Level: *** X-Archive-Number: 201001/24 X-Sequence-Number: 33560 > On 2010-01-11, 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; > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > > You hit that really hard, Jasen, thank you very much!! You save my week :) Thanks again. Gerardo