pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: logik@centrum.cz
To: pgsql-bugs@postgresql.org
Subject: BUG #6440: Window function in WHERE evaluated after agregate
Date: Wed, 08 Feb 2012 13:50:40 +0000
Message-ID: <E1Rv7uy-0002pB-Vf@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      6440
Logged by:          Matyas Novak
Email address:      logik@centrum.cz
PostgreSQL version: 9.1.1
Operating system:   Linux
Description:        

Window function in WHERE clause - as all other functions used in where -
should be evaluated before agregating takes place. But it seems that
postgresql try evaluate its after agregating, as it'd be in HAVING clause.

E.g. in folowing example I'l try to sum the best results of given persons
from all dispciplines - so I agregate over persons and best result in each
discipline wann get using window function.

(I'm aware that it can be done by various subselects, or that there may be
better to use different window function or nested agregates, but it's
simplified example from a bit complex example.)

Test example:

create table results
(
 id serial not null primary key,
 person integer,
 discipline integer,
 result integer
);

select person, sum(result) from
  results 
where
  row_number() over (partition by person, discipline order by result desc) =
1
group by
  person

Error:
ERROR:  column "results.result" must appear in the GROUP BY clause or be
used in an aggregate function
LINE 19: ...() over (partition by person, discipline order by result des...




view thread (2+ messages)  latest in thread

Message-ID: <E1Rv7uy-0002pB-Vf@wrigleys.postgresql.org>
Permalink:  ../E1Rv7uy-0002pB-Vf@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1Rv7uy-0002pB-Vf@wrigleys.postgresql.org

 · 

reply

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: logik@centrum.cz
  Subject: Re: BUG #6440: Window function in WHERE evaluated after agregate
  In-Reply-To: <E1Rv7uy-0002pB-Vf@wrigleys.postgresql.org>
  References: <E1Rv7uy-0002pB-Vf@wrigleys.postgresql.org>

* 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