Adds SQL-standard function body support to ruleutils_14.c

Relevant PG commit:
e717a9a18b2e34c9c40e5259ad4d31cd7e420750
talha_pg14_support
Halil Ozan Akgul 2021-08-16 17:10:29 +03:00 committed by Sait Talha Nisanci
parent f8d656d87a
commit 76fc13d50c
1 changed files with 52 additions and 1 deletions

View File

@ -182,6 +182,10 @@ typedef struct
List *outer_tlist; /* referent for OUTER_VAR Vars */ List *outer_tlist; /* referent for OUTER_VAR Vars */
List *inner_tlist; /* referent for INNER_VAR Vars */ List *inner_tlist; /* referent for INNER_VAR Vars */
List *index_tlist; /* referent for INDEX_VAR Vars */ List *index_tlist; /* referent for INDEX_VAR Vars */
/* Special namespace representing a function signature: */
char *funcname;
int numargs;
char **argnames;
} deparse_namespace; } deparse_namespace;
/* Callback signature for resolve_special_varno() */ /* Callback signature for resolve_special_varno() */
@ -2358,6 +2362,9 @@ get_basic_select_query(Query *query, deparse_context *context,
/* /*
* Build up the query string - first we say SELECT * Build up the query string - first we say SELECT
*/ */
if (query->isReturn)
appendStringInfoString(buf, "RETURN");
else
appendStringInfoString(buf, "SELECT"); appendStringInfoString(buf, "SELECT");
/* Add the DISTINCT clause if given */ /* Add the DISTINCT clause if given */
@ -4594,6 +4601,50 @@ get_parameter(Param *param, deparse_context *context)
return; return;
} }
/*
* If it's an external parameter, see if the outermost namespace provides
* function argument names.
*/
if (param->paramkind == PARAM_EXTERN)
{
dpns = lfirst(list_tail(context->namespaces));
if (dpns->argnames)
{
char *argname = dpns->argnames[param->paramid - 1];
if (argname)
{
bool should_qualify = false;
ListCell *lc;
/*
* Qualify the parameter name if there are any other deparse
* namespaces with range tables. This avoids qualifying in
* trivial cases like "RETURN a + b", but makes it safe in all
* other cases.
*/
foreach(lc, context->namespaces)
{
deparse_namespace *dpns = lfirst(lc);
if (list_length(dpns->rtable_names) > 0)
{
should_qualify = true;
break;
}
}
if (should_qualify)
{
appendStringInfoString(context->buf, quote_identifier(dpns->funcname));
appendStringInfoChar(context->buf, '.');
}
appendStringInfoString(context->buf, quote_identifier(argname));
return;
}
}
}
/* /*
* Not PARAM_EXEC, or couldn't find referent: for base types just print $N. * Not PARAM_EXEC, or couldn't find referent: for base types just print $N.
* For composite types, add cast to the parameter to ease remote node detect * For composite types, add cast to the parameter to ease remote node detect