pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve Crawford <scrawford@pinpointresearch.com>
To: Reuven M. Lerner <reuven@lerner.co.il>
Cc: Alex Hunsaker <badalex@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Speeding up loops in pl/pgsql function
Date: Wed, 25 May 2011 17:03:02 -0700
Message-ID: <4DDD98B6.6080208@pinpointresearch.com> (raw)
In-Reply-To: <4DDD4E57.7070800@lerner.co.il>
References: <4DDD358E.20307@lerner.co.il>
	<BANLkTinuiR=Txtn_dUeSbvvgcWZj9c2+iw@mail.gmail.com>
	<4DDD4E57.7070800@lerner.co.il>

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




view thread (18+ messages)  latest in thread

Message-ID: <4DDD98B6.6080208@pinpointresearch.com>
Permalink:  ../4DDD98B6.6080208@pinpointresearch.com/
Also on:    postgresql.org/message-id/4DDD98B6.6080208@pinpointresearch.com

 · 

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-performance@postgresql.org
  Cc: scrawford@pinpointresearch.com, reuven@lerner.co.il, badalex@gmail.com
  Subject: Re: Speeding up loops in pl/pgsql function
  In-Reply-To: <4DDD98B6.6080208@pinpointresearch.com>

* 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