Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B594AB5DC4A for ; Thu, 26 May 2011 12:25:13 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 09144-03 for ; Thu, 26 May 2011 15:25:05 +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 E6FFAB5DC4B for ; Thu, 26 May 2011 12:25:01 -0300 (ADT) Received: from betelgeuse.pinpointresearch.com (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id B0CE4E00EC84; Thu, 26 May 2011 08:24:45 -0700 (PDT) Message-ID: <4DDE70BD.2060205@pinpointresearch.com> Date: Thu, 26 May 2011 08:24:45 -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: Merlin Moncure CC: "Reuven M. Lerner" , 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> <4DDD98B6.6080208@pinpointresearch.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; 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/373 X-Sequence-Number: 43882 On 05/26/2011 05:36 AM, Merlin Moncure wrote: > ... > got it: > select decode(regexp_replace('141142143', '([0-9][0-9][0-9])', > $q$\\\1$q$ , 'g'), 'escape'); > decode > -------- > abc > (1 row) > > merlin > Nice. A word of warning, in 9.0 this returns a hex string: select decode(regexp_replace('141142143', '([0-9][0-9][0-9])', $q$\\\1$q$ , 'g'), 'escape'); decode ---------- \x616263 See http://www.postgresql.org/docs/9.0/static/release-9-0.html: E.5.2.3. Data Types bytea output now appears in hex format by default (Peter Eisentraut) The server parameter bytea_output can be used to select the traditional output format if needed for compatibility. Another wrinkle, the function I wrote sort of ignored the bytea issue by using text. But text is subject to character-encoding (for both good and bad) while bytea is not so the ultimate solution will depend on whether the input string is the octal representation of an un-encoded sequence of bytes or represents a string of ASCII/UTF-8/whatever... encoded text. Cheers, Steve