-- with local table: postgres=# select 2 a, avg(c1) fromt1 group by a; a | avg ---+--------------------- 2 | 15.0000000000000000 (1 row)
-- with foreign table: postgres=# select 2 a, avg(c1) from f_t1 group by a; ERROR: aggregate functions are not allowed in GROUP BY CONTEXT: Remote SQL command: EXPLAIN SELECT 2, avg(c1) FROM public.t1 GROUP BY 2
Thanks for reporting this bug in *v1.patch Prabhat.
I will have a look over this issue and will post a fix in next version.
To fix this issue, we need to make deparseConst() function aware of showtype flag exactly as that of get_const_expr(). While deparsing Const in GROUP BY clause, we need to show "::typename" so that it won't treat the constant value as a column position in the target list and rather treat it as constant value.
Fixed this in earlier attached patch and added test-case too.
--
Jeevan B Chalke Principal Software Engineer, Product Development EnterpriseDB Corporation The Enterprise PostgreSQL Company