Re: plpgsql arrays

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Matthew Wakeling <matthew(at)flymine(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: plpgsql arrays
Date: 2009-04-03 15:02:13
Message-ID: b42b73150904030802q1b3685br8db7740569e31aea@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri, Apr 3, 2009 at 9:32 AM, Matthew Wakeling <matthew(at)flymine(dot)org> wrote:
>  genes = '{}';
>  next_new = 1;
>  FOR loc IN SELECT location.* FROM location, gene WHERE location.subjectid =
> gene.id ORDER BY objectid, intermine_start, intermine_end LOOP
>     genes[next_new] = loc;
>     IF (next_new % 10000 = 0) THEN
>         RAISE NOTICE 'Scanned % gene locations', next_new;
>     END IF;
>     next_new = next_new + 1;
>  END LOOP;
>  genes_size = coalesce(array_upper(genes, 1), 0);
>  RAISE NOTICE 'Scanned % gene locations', genes_size;
>
> For 200,000 rows it takes 40 minutes.
>
> So, is there a way to dump the results of a query into an array quickly in
> plpgsql, or alternatively is there a way to read two results streams
> simultaneously?

try this:
select array(SELECT location.* FROM location, gene WHERE
location.subjectid = gene.id ORDER BY objectid, intermine_start,
intermine_end)) into genes;

merlin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Merlin Moncure 2009-04-03 15:09:44 Re: plpgsql arrays
Previous Message Matthew Wakeling 2009-04-03 14:58:03 Re: plpgsql arrays