Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-06-02 Thread Reuven M. Lerner
Hi, Merlin. You wrote: select string_agg(v, '') from (select ascii(regexp_split_to_table('abc', $$\s*$$))::text as v) q; Wow. I've been programming with pl/pgsql for a good number of years, but only now do I see the amazing usefulness of regexp_split_to_table and string_agg, neither of

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-26 Thread Merlin Moncure
On Wed, May 25, 2011 at 9:20 PM, Merlin Moncure mmonc...@gmail.com wrote: On Wed, May 25, 2011 at 8:03 PM, Steve Crawford scrawf...@pinpointresearch.com wrote: On 05/25/2011 11:45 AM, Reuven M. Lerner wrote: Hi, Alex.  You wrote: Have you tried something like: SELECT  

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-26 Thread Merlin Moncure
On Thu, May 26, 2011 at 8:11 AM, Merlin Moncure mmonc...@gmail.com wrote: On Wed, May 25, 2011 at 9:20 PM, Merlin Moncure mmonc...@gmail.com wrote: On Wed, May 25, 2011 at 8:03 PM, Steve Crawford scrawf...@pinpointresearch.com wrote: On 05/25/2011 11:45 AM, Reuven M. Lerner wrote: Hi, Alex.  

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-26 Thread Reuven M. Lerner
Wow. Color me impressed and grateful. I've been working on a different project today, but I'll test these tonight. I'll never underestimate the regexp functionality in PostgreSQL again! Reuven -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-26 Thread Steve Crawford
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',

[PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Reuven M. Lerner
Hi, everyone. I'm working on a project that's using PostgreSQL 8.3, that requires me to translate strings of octal digits into strings of characters -- so '141142143' should become 'abc', although the database column containing this data (both before and after) is a bytea. While the

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Reuven M. Lerner
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

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Alex Hunsaker
On Wed, May 25, 2011 at 12:45, Reuven M. Lerner reu...@lerner.co.il wrote: Hi, Alex.  You wrote: I think select E'\XXX' is what you are looking for (per the fine manual: http://www.postgresql.org/docs/current/static/datatype-binary.html) I didn't think that I could (easily) build a string

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Pavel Stehule
Hello (1) Are there any good guidelines for what operations in pl/pgsql are optimized for which data structures?  For example, it turns out that a great deal of time is being spent in the substring() function, which surprised me.  I thought that by switching to an array, it might be faster,

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Alex Hunsaker
On Wed, May 25, 2011 at 10:59, Reuven M. Lerner reu...@lerner.co.il wrote: Hi, everyone.  I'm working on a project that's using PostgreSQL 8.3, that requires me to translate strings of octal digits into strings of characters -- so '141142143' should become 'abc', although the database column

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Merlin Moncure
On Wed, May 25, 2011 at 11:59 AM, Reuven M. Lerner reu...@lerner.co.il wrote: Hi, everyone.  I'm working on a project that's using PostgreSQL 8.3, that requires me to translate strings of octal digits into strings of characters -- so '141142143' should become 'abc', although the database column

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Reuven M. Lerner
Hi, everyone. Merlin wrote: let's see the source. I bet we can get this figured out. Here you go... it looked nicer before I started to make optimizations; I've gotten it to run about 2x as fast as the previous version, but now I'm sorta stuck, looking for further optimizations, including

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Steve Crawford
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

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Merlin Moncure
On Wed, May 25, 2011 at 8:03 PM, Steve Crawford scrawf...@pinpointresearch.com wrote: 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

Re: [PERFORM] Speeding up loops in pl/pgsql function

2011-05-25 Thread Santhakumaran
Dkloskxe Steve Crawford scrawf...@pinpointresearch.com wrote: 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