From: Tom Lane <tgl@sss.pgh.pa.us>
To: rikard@ngs.hr
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14301: function in case expression called when it should not be
Date: Mon, 29 Aug 2016 11:28:34 -0400
Message-ID: <7178.1472484514@sss.pgh.pa.us> (raw)
In-Reply-To: <20160829151433.15676.91530@wrigleys.postgresql.org>
References: <20160829151433.15676.91530@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
rikard@ngs.hr writes:
> select case when doSlow then sum(slowFunction()) else sum(1) end as total
> from something group by doSlow
You are misunderstanding how aggregates work. The aggregates are
evaluated first, then the surrounding expressions are done once at
the end of the query (or group). The fact that the CASE might choose
the other branch at the end doesn't eliminate the necessity to run
both aggregates across all the rows.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, rikard@ngs.hr
Subject: Re: BUG #14301: function in case expression called when it should not be
In-Reply-To: <7178.1472484514@sss.pgh.pa.us>
References: <20160829151433.15676.91530@wrigleys.postgresql.org> <7178.1472484514@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox