Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CBF1C6333CA for ; Sun, 10 Jan 2010 21:55:46 -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 58497-02 for ; Mon, 11 Jan 2010 01:55:35 +0000 (UTC) X-Greylist: delayed 00:25:10.063306 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 413FE633453 for ; Sun, 10 Jan 2010 21:55:36 -0400 (AST) Received: from www.webmail.fmed.uba.ar (localhost [127.0.0.1]) by mail.fmed.uba.ar (Postfix) with ESMTP id C518F39C332 for ; Sun, 10 Jan 2010 22:29:07 -0200 (ARST) Received: from 190.55.96.62 (SquirrelMail authenticated user gherzig) by www.webmail.fmed.uba.ar with HTTP; Sun, 10 Jan 2010 22:29:07 -0200 (ARST) Message-ID: <6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar> Date: Sun, 10 Jan 2010 22:29:07 -0200 (ARST) Subject: problem using regexp_replace From: gherzig@fmed.uba.ar To: 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/15 X-Sequence-Number: 33551 Hi all. Im having a hard time here. Really have no idea what is wrong here. Facing a special case of text substitution, i have to parse a column like this one: SELECT formato from table where id=1;
{Action_1.842}
{Action_2.921}[truncated] The numbers at the rigth of the period identifies an argument to the function identified to "Action_x" Every {Action_x....} is asociated to a diff function , so i have a helper function to identify the "Action" part: CREATE FUNCTION valores_sustitucion(valor_ingresado varchar[]) returns varchar as $$ select case $1[1] when 'Action_1' then (select descripcion from load_by_cod($1[2])) when 'Action_2' then (select descripcion from pay_by_view($1[2]) else 'FALSE' end; $$ language sql; So, the idea is, to call associated function with every "Action_x", with the number as the argument to that associated function. 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; FALSE
The valores_sustitucion() functions is called, but the case construction is failing. I have tested the regular expression, and its fine. It looks like is something with the grouping and using that groups as the argument of the valores_sustiticion() funcion. Anybody has a hint? Thanks! Gerardo
FALSE