pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: gherzig@fmed.uba.ar
To: pgsql-sql@postgresql.org
Subject: problem using regexp_replace
Date: Sun, 10 Jan 2010 22:29:07 -0200 (ARST)
Message-ID: <6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar> (raw)

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;

<TABLE><TBODY><TR><TD>{Action_1.842}</TD></TR></TBODY></TABLE><TABLE><TBODY><TR><TD>{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;

<TD>FALSE</TD></TR></TBODY></TABLE><TABLE><TBODY><TR><TD>FALSE</TD>

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




view thread (5+ messages)  latest in thread

Message-ID: <6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar>
Permalink:  ../6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar/
Also on:    postgresql.org/message-id/6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar

 · 

reply

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: gherzig@fmed.uba.ar
  Subject: Re: problem using regexp_replace
  In-Reply-To: <6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar>

* 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