Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 3F423B5DBDD for ; Wed, 25 May 2011 21:03:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 77454-02 for ; Thu, 26 May 2011 00:03:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from polaris.pinpointresearch.com (cerberus.pinpointresearch.com [66.7.238.130]) by mail.postgresql.org (Postfix) with ESMTP id 3A1D2B5DBBF for ; Wed, 25 May 2011 21:03:04 -0300 (ADT) Received: from betelgeuse.pinpointresearch.com (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id EF24EE00EC82; Wed, 25 May 2011 17:03:02 -0700 (PDT) Message-ID: <4DDD98B6.6080208@pinpointresearch.com> Date: Wed, 25 May 2011 17:03:02 -0700 From: Steve Crawford User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: "Reuven M. Lerner" CC: Alex Hunsaker , pgsql-performance@postgresql.org Subject: Re: Speeding up loops in pl/pgsql function References: <4DDD358E.20307@lerner.co.il> <4DDD4E57.7070800@lerner.co.il> In-Reply-To: <4DDD4E57.7070800@lerner.co.il> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/355 X-Sequence-Number: 43864 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