Re: problem using regexp_replace

From: gherzig(at)fmed(dot)uba(dot)ar
To: "Jasen Betts" <jasen(at)xnet(dot)co(dot)nz>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: problem using regexp_replace
Date: 2010-01-12 16:17:40
Message-ID: 0862feba5dd70bb08d69d1cd4c33eb29.squirrel@www.webmail.fmed.uba.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> On 2010-01-11, gherzig(at)fmed(dot)uba(dot)ar <gherzig(at)fmed(dot)uba(dot)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(at)postgresql(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Seb 2010-01-15 03:28:23 rename primary key
Previous Message Jasen Betts 2010-01-12 12:10:50 Re: problem using regexp_replace