Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 2E7A11337B68 for ; Wed, 13 Apr 2011 12:15:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 83061-02-3 for ; Wed, 13 Apr 2011 15:14:35 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 923E81337C14 for ; Wed, 13 Apr 2011 12:09:24 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p3DF9NcE005080; Wed, 13 Apr 2011 11:09:23 -0400 (EDT) To: Anish Kejariwal cc: pgsql-sql@postgresql.org Subject: Re: pass in array to function for use by where clause? how optimize? In-reply-to: References: Comments: In-reply-to Anish Kejariwal message dated "Tue, 12 Apr 2011 10:08:25 -0700" Date: Wed, 13 Apr 2011 11:09:23 -0400 Message-ID: <5079.1302707363@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/11 X-Sequence-Number: 35258 Anish Kejariwal writes: > (select store_id, avg(sales) sales > from store > where group_id in(select $1[i] from generate_subscripts($1, 1) g(i)) Seems like a pretty brute-force way to deal with the array. Try where group_id = any($1) Not sure if it'll be a great deal faster, but it's at least easier to write. regards, tom lane