Re: Condition in a calculated field - Mailing list pgsql-novice

From David Johnston
Subject Re: Condition in a calculated field
Date
Msg-id CAKFQuwbNdxYVZQysNtkft2cRC7RdSnbNDpeET5KyqNgHPFiwig@mail.gmail.com
Whole thread Raw
In response to Re: Condition in a calculated field  (JORGE MALDONADO <jorgemal1960@gmail.com>)
List pgsql-novice
On Tue, Sep 9, 2014 at 3:00 PM, JORGE MALDONADO <jorgemal1960@gmail.com> wrote:
I just watched the documentation and did what you suggested but I am still getting the same error message. I did the following test, what is wrong?

HAVING 
  facturas.fce_valor_comercial > total

​It cannot see "total" because that alias is defined in the final select-list.  

As I said you have to repeat the expression.

HAVING
  facturas.fce_valor_comercial > sum(facsub.fce_valor_comercial)

 
WHERE clause is pre-grouping.

What you want is the HAVING clause - though you have to repeat the
expression (e.g., col > sum(...) ) as opposed to referring to it by name
(e.g., col > total).

http://www.postgresql.org/docs/devel/static/sql-select.html

David J.

pgsql-novice by date:

Previous
From: JORGE MALDONADO
Date:
Subject: Re: Condition in a calculated field
Next
From: "Jake O'brien Fagan"
Date:
Subject: Postgresql replication not starting after running pg_basebackup