Re: can i make this sql query more efficiant? - Mailing list pgsql-sql

From Josh Berkus
Subject Re: can i make this sql query more efficiant?
Date
Msg-id 200304040816.01369.josh@agliodbs.com
Whole thread Raw
In response to Re: can i make this sql query more efficiant?  ("Tomasz Myrta" <jasiek@klaster.net>)
Responses Re: can i make this sql query more efficiant?  (Manfred Koizar <mkoi-pg@aon.at>)
List 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



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Finding if a temp table exists in the current connection
Next
From: Manfred Koizar
Date:
Subject: Re: can i make this sql query more efficiant?