[code notes] check_agg_arguments

The SQL

select sum(sum(a)) from myt1 group by a;

This note focuses only on sum(sum(a)) and it's about how postgres rejects the sql above.

Notes

sum(sum(a))
^   ^   ^__ inner most argument, Var node
|   | 
|   \_	 function call
\_ function call	 

Function call is handled by function transformFuncCall. Here's overview how tranformFuncCall works:

  • transform arguments first
  • if it's an aggregate function, transform aggregate call.
  • check_agg_arguments

For sum(sum(a)), the recursive way is like this:

FuncCall
    FuncCall
    AggCall
    check_agg_arguments
AggCall
check_agg_arguments

Here's the detail,

  • sum(sum(a)) is a FuncCall, handle its arguements sum(a).
  • sum(a) is a FuncCall, handle its arguments a.
  • check the arguments a, is's a simple Var node, that's fine.
  • sum(a) is an AggCall, check_agg_arguments of sum(a). A Var node, that's fine.
  • sum(sum(a)) is an AggCall, check_agg_arguments of sum(sum(a)), which is sum(a). Since sum(a)
    is an AggCall, postgres rejects this sql.

posted on 2024-05-11 20:25  winter-loo  阅读(4)  评论(0编辑  收藏  举报

导航