Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D66DB6322C7 for ; Fri, 3 Apr 2009 12:02:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 41466-05 for ; Fri, 3 Apr 2009 12:02:14 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f222.google.com (mail-fx0-f222.google.com [209.85.220.222]) by mail.postgresql.org (Postfix) with ESMTP id AEEE7632219 for ; Fri, 3 Apr 2009 12:02:14 -0300 (ADT) Received: by fxm22 with SMTP id 22so1675424fxm.19 for ; Fri, 03 Apr 2009 08:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=ZZq1Hcvk9VgllYeoLRa6QY+GDgRboUd5I3M0wWLhWhw=; b=Bzf6OdYyXRWk9GczRco3aEA3uMI43ytFdIDhEC9F1Ppb+4ZyXYDo8DjotcmWyi3ogF CeWpsME65V//bAkskKidvRu/UQ+78iSVChc9cNWhvhJ+PWpoRNlGSusWqcA/5TNisbm4 pygDOEXAWrazjiQBazJ6POC4G0Mn7AooZtQZc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Ba3RK7z46M4eAncnt5kK/BeVdcXpQP76ZDFjz7wMKdG47ZUnhR7h2ERm6I+qMTujjL ytKWYC8QQLidgwhjk8VPGJdqvzbn8vaWnkliXSBtHUHR03gzFeJqgJmoEyHFVmSbcms8 Z8qiNek57oc9G26YMVHc/RUn1dH3OVehHItFs= MIME-Version: 1.0 Received: by 10.103.248.17 with SMTP id a17mr626552mus.83.1238770933220; Fri, 03 Apr 2009 08:02:13 -0700 (PDT) In-Reply-To: References: Date: Fri, 3 Apr 2009 11:02:13 -0400 Message-ID: Subject: Re: plpgsql arrays From: Merlin Moncure To: Matthew Wakeling Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.078 tagged_above=0 required=5 tests=AWL=0.078 X-Spam-Level: X-Archive-Number: 200904/71 X-Sequence-Number: 33438 On Fri, Apr 3, 2009 at 9:32 AM, Matthew Wakeling wrot= e: > =A0genes =3D '{}'; > =A0next_new =3D 1; > =A0FOR loc IN SELECT location.* FROM location, gene WHERE location.subjec= tid =3D > gene.id ORDER BY objectid, intermine_start, intermine_end LOOP > =A0 =A0 genes[next_new] =3D loc; > =A0 =A0 IF (next_new % 10000 =3D 0) THEN > =A0 =A0 =A0 =A0 RAISE NOTICE 'Scanned % gene locations', next_new; > =A0 =A0 END IF; > =A0 =A0 next_new =3D next_new + 1; > =A0END LOOP; > =A0genes_size =3D coalesce(array_upper(genes, 1), 0); > =A0RAISE 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 i= n > 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 =3D gene.id ORDER BY objectid, intermine_start, intermine_end)) into genes; merlin