Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 8BC579FB7EB for ; Wed, 17 Oct 2007 09:37:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 21266-03 for ; Wed, 17 Oct 2007 09:37:10 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.247]) by postgresql.org (Postfix) with ESMTP id 9FF5B9FB7DD for ; Wed, 17 Oct 2007 09:37:15 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id b33so161888ana for ; Wed, 17 Oct 2007 05:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; bh=+tDlk55EyiKF0FLKb2cwww2yCnngUq1OO9VY+CAAQ48=; b=ARh2MaKU9w9XVT8QDEoERAflpVoqGMTMb6GtNsBr1sYyOcg3LgCSXVL36e1jPd4G8Mqb/fdkaO+cY0YT2eDQ5uGnCRQyTpKTCHkf4BMD/zdX8C/FYNIUMT4IeAj7QoedsEkTWXtIPVz+KG10FpK1YUcTIdbOWl2fUk4hIX/imrs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; b=Hvjn6ZB2U+oO1VdJTNJGUiF7UKgXxOIE8yeEiRBhN82YafoA5+mwS0rjFW4JxX5v8EFCvmke+0EM6mDwpY00N//XIRc12eTjW9OwAkH1pZ0aAL/Dm3o/q58MFgAg6Nb5Jzh9aHWAPsaAvj9qJ9MpqgdHQie/8xt6WmR0osOADuo= Received: by 10.142.191.2 with SMTP id o2mr2425141wff.1192624252799; Wed, 17 Oct 2007 05:30:52 -0700 (PDT) Received: by 10.35.27.16 with HTTP; Wed, 17 Oct 2007 05:30:52 -0700 (PDT) Message-ID: <290a5abc0710170530v215cb2b0q4fa000ad43096a28@mail.gmail.com> Date: Wed, 17 Oct 2007 14:30:52 +0200 From: "Stefano Dal Pra" To: pgsql-sql@postgresql.org Subject: two queryes in a single tablescan Cc: pgsql-performance@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/197 X-Sequence-Number: 27219 Hi everybody, suppose you have a large table tab and two (or more) queryes like this: SELECT count(*),A FROM tab WHERE C GROUP BY A; SELECT count(*),B FROM tab WHERE C GROUP BY B; is there any way to get both results in a single query, eventually through stored procedure? The retrieved [count(*),A] ; [count(*),B)] data couldnt fit on a single table, of course. The main goal would be to get multiple results while scanning the table[s] once only thus getting results in a faster way. This seems to me quite a common situation but i have no clue whether a neat solution can be implemented through stored procedure. Any hint? Thank you Stefano