Is this a bug? - Mailing list pgsql-bugs

From Prateek Sanyal
Subject Is this a bug?
Date
Msg-id CALByby-KCYFK32r9TR8ZheXLtF0x8pn4FrWn9ESJYFh64uUtaQ@mail.gmail.com
Whole thread Raw
Responses Re: Is this a bug?
List pgsql-bugs
I discovered a difference between sqlite3 and psql and I am not sure if it
is intentional but it is definitely inconvenient.

If you use an alias for an aggregate function and then do a GROUP BY with
HAVING, you can't use that alias in the HAVING and you have to type in the
entire function again.

This is not the case with sqlite3 where you can just use the alias. Why
doesn't psql allow this? It seems more efficient.

Take a look at the following example:

-- Schema for sample table named "invoices":

-- id => int

-- customer_id => int

-- total_sale => decimal
Here is the query:
********************

SELECT SUM(total_sale) AS sum_sales FROM invoices GROUP BY customer_id
HAVING sum_sales > 20 ORDER BY sum_sales DESC;

********************

This code above works in sqlite3 but not psql. For psql I have to do the
following:

********************

SELECT SUM(total_sale) AS sum_sales FROM invoices GROUP BY customer_id
HAVING SUM(total_sale) > 20 ORDER BY sum_sales DESC;

********************

Regards,
Prateek.

pgsql-bugs by date:

Previous
From: Dmitriy Sarafannikov
Date:
Subject: Re[2]: [BUGS] Wal sender segfault
Next
From: Tom Lane
Date:
Subject: Re: Is this a bug?