From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | "Tomasz Myrta" <jasiek(at)klaster(dot)net>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: can i make this sql query more efficiant? |
Date: | 2003-04-04 16:16:01 |
Message-ID: | 200304040816.01369.josh@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance pgsql-sql |
Tomasz,
> What about this:
> select
> event,
> sum(case when level=1 then 1 else 0 end) as ones,
> sum(case when level=2 then 1 else 0 end) as twos,
> sum(case when level=3 then 1 else 0 end) as threes
> from baz
> group by event;
That version is only more efficient for small data sets. I've generally
found that case statements are slower than subselects for large data sets.
YMMV.
BTW, while it won't be faster, Joe Conway's crosstab function in /tablefunc
does this kind of transformation.
--
Josh Berkus
Aglio Database Solutions
San Francisco
From | Date | Subject | |
---|---|---|---|
Next Message | Jeffrey D. Brower | 2003-04-04 16:42:33 | Re: OSS database needed for testing |
Previous Message | Josh Berkus | 2003-04-04 16:09:22 | Re: [PERFORM] OSS database needed for testing |
From | Date | Subject | |
---|---|---|---|
Next Message | Manfred Koizar | 2003-04-04 19:03:08 | Re: [SQL] can i make this sql query more efficiant? |
Previous Message | Tom Lane | 2003-04-04 14:58:24 | Re: Finding if a temp table exists in the current connection |