Column Alias Not Allowed In Grouping Function

From: Vivek Suraiya <vivek_suraiya(at)yahoo(dot)com>
To: PostgreSQL Community <pgsql-www(at)lists(dot)postgresql(dot)org>
Subject: Column Alias Not Allowed In Grouping Function
Date: 2022-08-16 13:32:59
Message-ID: 401489932.1675199.1660656779333@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-www

Suppose we have a table SALES with the following columns:cust_namesales_person_namesale_amt
then the SQL command:
SELECT cust_name c , sales_person_name s , SUM(sale_amt) , GROUPING(c , s) grpFROM SALESGROUP BY CUBE(c,s)ORDER BY grp;
will fail. But, 
SELECT cust_name c , sales_person_name s , SUM(sale_amt) , GROUPING( cust_name , sales_person_name)  grpFROM SALESGROUP BY CUBE(c,s)ORDER BY grp;
will succeed.
Why is it illegal to use the column aliases in the GROUPING function?

Responses

Browse pgsql-www by date

  From Date Subject
Next Message Tom Lane 2022-08-16 19:32:58 Re: Column Alias Not Allowed In Grouping Function
Previous Message Jonathan S. Katz 2022-08-15 13:52:56 Re: UPSERT as a table name is confusing