problem using regexp_replace

Поиск
Список
Период
Сортировка
От gherzig@fmed.uba.ar
Тема problem using regexp_replace
Дата
Msg-id 6f55ccf2a59fe7bca287389ec92e5f91.squirrel@www.webmail.fmed.uba.ar
обсуждение исходный текст
Список pgsql-sql
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



В списке pgsql-sql по дате отправления:

Предыдущее
От: msi77
Дата:
Сообщение: Re: how to do this query
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: problem using regexp_replace