Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id BD991632223 for ; Fri, 3 Apr 2009 12:09:47 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 74005-09 for ; Fri, 3 Apr 2009 12:09:46 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f169.google.com (mail-bw0-f169.google.com [209.85.218.169]) by mail.postgresql.org (Postfix) with ESMTP id 0628B632219 for ; Fri, 3 Apr 2009 12:09:45 -0300 (ADT) Received: by bwz17 with SMTP id 17so1590266bwz.19 for ; Fri, 03 Apr 2009 08:09:44 -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=/ImcsNF8MvuPywkSVah2gRsXPvOPGLrwzmOR5La7sT8=; b=DvBE67Xp5SPhf3rpQHMx/8CoKzihVQY+ydhpk1F0hDVul5Z7vKT1lq//vZ+XWW0Wan 5JUnVuDyZZBj/9H02kYhcz6EjVXL1/WQSIJ8q24m7JDiszEvLT7Te9MM4mxCAvA3wRrh JZC5RPWWxBcaOuQ2DcCvvPb2UjGEyXuKRjMEg= 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=EGQAwrJkNomAdKfkER0N5Yxg0gUHWU/3fAoJVQZjYc7WYCDhLEUoGEWFkQVrRntds5 kkZnwEKZ2pnQtwwYtWSUFZ8QkLiImol5vDuej8+drJQ34kvtMT7tbMkNeDJF66cymbck ZQ95/mIHdtRns/qvT1eAuigQQXgHrzR0Jid+8= MIME-Version: 1.0 Received: by 10.102.247.4 with SMTP id u4mr622136muh.128.1238771384770; Fri, 03 Apr 2009 08:09:44 -0700 (PDT) In-Reply-To: References: Date: Fri, 3 Apr 2009 11:09:44 -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 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/72 X-Sequence-Number: 33439 On Fri, Apr 3, 2009 at 11:02 AM, Merlin Moncure wrote: > On Fri, Apr 3, 2009 at 9:32 AM, Matthew Wakeling wr= ote: >> =A0genes =3D '{}'; >> =A0next_new =3D 1; >> =A0FOR loc IN SELECT location.* FROM location, gene WHERE location.subje= ctid =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 = 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 =3D gene.id ORDER BY objectid, intermine_start, > intermine_end)) into genes; one more time: select array(SELECT location FROM location, gene WHERE location.subjectid =3D gene.id ORDER BY objectid, intermine_start, intermine_end)) into genes; this will make array of location records. when you access the records to do the merge, make sure to use () noation: if (genes[x]).field > something then ... merlin