Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id A6A85633755 for ; Tue, 12 Jan 2010 08:11:11 -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 02460-07 for ; Tue, 12 Jan 2010 12:11:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ananke.wxnz.net (ananke.wxnz.net [58.28.4.122]) by mail.postgresql.org (Postfix) with ESMTP id 1919763344B for ; Tue, 12 Jan 2010 08:11:00 -0400 (AST) Received: from gonzo (ip-118-90-139-52.xdsl.xnet.co.nz [118.90.139.52]) by ananke.wxnz.net (Postfix) with ESMTP id 5D2D34009F for ; Wed, 13 Jan 2010 01:10:57 +1300 (NZDT) Received: from news by gonzo with local (Exim 4.69) (envelope-from ) id 1NUfaJ-0007cM-UU for pgsql-sql@postgresql.org; Wed, 13 Jan 2010 01:10:55 +1300 To: pgsql-sql@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.sql Subject: Re: problem using regexp_replace Date: 12 Jan 2010 12:10:50 GMT Organization: Dis (not Dat) Organisation Lines: 35 Message-ID: References: <6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar> NNTP-Posting-Host: localhost Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reversiblemaps.ath.cx 1263298250 29284 127.0.0.1 (12 Jan 2010 12:10:50 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-2 (Linux) 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/23 X-Sequence-Number: 33559 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;