extracting multiple results from a set of tuples - Mailing list pgsql-general

From merlino
Subject extracting multiple results from a set of tuples
Date
Msg-id 1192188408.140955.68950@y27g2000pre.googlegroups.com
Whole thread Raw
List pgsql-general
Hi all, I am writing a few pg/plsql and have no great experience, so
i'm asking here.

I need to obtain <X1>,<X2>,.. from N queryes like these:

SELECT <X1> FROM tab GROUP BY <Y1>
SELECT <X2> FROM tab GROUP  BY <Y2>
SELECT <X3> FROM tab WHERE C3 GROUP BY <Y3> [eventually ORDER BY Z3];

example:
SELECT count(*),name FROM tab GROUP BY name;
SELECT sum(seconds), job FROM tab WHERE status = 1 GROUP BY job;
etc;

Doing this way the table tab would be scanned once per SELECT (tab is
a quite large table).

Since it hurts to me the idea of repeating many queryes on the
identical set of tuples
I would like to write a stored procedure who produceses these results
putting them
into a few "temporary" tables, so i ask you:

is there a way to obtain <X1>, <X2>, <X3> with a single tables scan?

May you point me to an example?
I hope i was clear enough explaining the problem.
Thank you
Stefano


pgsql-general by date:

Previous
From: Robert Treat
Date:
Subject: Re: SLEEP in posgresql
Next
From: Joao Miguel Ferreira
Date:
Subject: replicating to a stopped server