Re: Speeding up loops in pl/pgsql function - Mailing list pgsql-performance

From Steve Crawford
Subject Re: Speeding up loops in pl/pgsql function
Date
Msg-id 4DDD98B6.6080208@pinpointresearch.com
Whole thread Raw
In response to Re: Speeding up loops in pl/pgsql function  ("Reuven M. Lerner" <reuven@lerner.co.il>)
Responses Re: Speeding up loops in pl/pgsql function
List pgsql-performance
On 05/25/2011 11:45 AM, Reuven M. Lerner wrote:
> Hi, Alex.  You wrote:
>> Have you tried something like:
>> SELECT  encode(regexp_replace('141142143', '(\d{3})', '\\\1',
>> 'g')::bytea, 'escape');
> Hmm, forgot about regexp_replace.  It might do the trick, but without
> a full-blown eval that I can run on the replacement side, it'll be a
> bit more challenging.  But that's a good direction to consider, for sure.

The function given didn't work exactly as written for me but it is on
the right track. See if this works for you (input validation is left as
an exercise for the reader...:)):

create or replace function octal_string_to_text(someoctal text) returns
text as $$
declare
     binstring text;
begin
     execute 'select E''' || regexp_replace($1, E'(\\d{3})', E'\\\\\\1',
'g') || '''' into binstring;
return binstring;
end
$$ language plpgsql;

Cheers,
Steve


pgsql-performance by date:

Previous
From: Stefan Keller
Date:
Subject: Re: FW: KVP table vs. hstore - hstore performance (Was: Postgres NoSQL emulation)
Next
From: Merlin Moncure
Date:
Subject: Re: Speeding up loops in pl/pgsql function