in ext/pg_query/pg_query_deparse.c [2294:2377]
static void deparseFuncCall(StringInfo str, FuncCall *func_call)
{
const ListCell *lc = NULL;
Assert(list_length(func_call->funcname) > 0);
if (list_length(func_call->funcname) == 2 &&
strcmp(strVal(linitial(func_call->funcname)), "pg_catalog") == 0 &&
strcmp(strVal(lsecond(func_call->funcname)), "overlay") == 0 &&
list_length(func_call->args) == 4)
{
/*
* Note that this is a bit odd, but "OVERLAY" is a keyword on its own merit, and only accepts the
* keyword parameter style when its called as a keyword, not as a regular function (i.e. pg_catalog.overlay)
*/
appendStringInfoString(str, "OVERLAY(");
deparseExpr(str, linitial(func_call->args));
appendStringInfoString(str, " PLACING ");
deparseExpr(str, lsecond(func_call->args));
appendStringInfoString(str, " FROM ");
deparseExpr(str, lthird(func_call->args));
appendStringInfoString(str, " FOR ");
deparseExpr(str, lfourth(func_call->args));
appendStringInfoChar(str, ')');
return;
}
deparseFuncName(str, func_call->funcname);
appendStringInfoChar(str, '(');
if (func_call->agg_distinct)
appendStringInfoString(str, "DISTINCT ");
if (func_call->agg_star)
{
appendStringInfoChar(str, '*');
}
else if (list_length(func_call->args) > 0)
{
foreach(lc, func_call->args)
{
if (func_call->func_variadic && !lnext(func_call->args, lc))
appendStringInfoString(str, "VARIADIC ");
deparseFuncArgExpr(str, lfirst(lc));
if (lnext(func_call->args, lc))
appendStringInfoString(str, ", ");
}
}
appendStringInfoChar(str, ' ');
if (func_call->agg_order != NULL && !func_call->agg_within_group)
{
deparseOptSortClause(str, func_call->agg_order);
}
removeTrailingSpace(str);
appendStringInfoString(str, ") ");
if (func_call->agg_order != NULL && func_call->agg_within_group)
{
appendStringInfoString(str, "WITHIN GROUP (");
deparseOptSortClause(str, func_call->agg_order);
removeTrailingSpace(str);
appendStringInfoString(str, ") ");
}
if (func_call->agg_filter)
{
appendStringInfoString(str, "FILTER (WHERE ");
deparseExpr(str, func_call->agg_filter);
appendStringInfoString(str, ") ");
}
if (func_call->over)
{
appendStringInfoString(str, "OVER ");
if (func_call->over->name)
appendStringInfoString(str, func_call->over->name);
else
deparseWindowDef(str, func_call->over);
}
removeTrailingSpace(str);
}