MCPcopy Create free account
hub / github.com/apache/cloudberry / print_function_sqlbody

Function print_function_sqlbody

src/backend/utils/adt/ruleutils.c:3432–3486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3430}
3431
3432static void
3433print_function_sqlbody(StringInfo buf, HeapTuple proctup)
3434{
3435 int numargs;
3436 Oid *argtypes;
3437 char **argnames;
3438 char *argmodes;
3439 deparse_namespace dpns = {0};
3440 Datum tmp;
3441 bool isnull;
3442 Node *n;
3443
3444 dpns.funcname = pstrdup(NameStr(((Form_pg_proc) GETSTRUCT(proctup))->proname));
3445 numargs = get_func_arg_info(proctup,
3446 &argtypes, &argnames, &argmodes);
3447 dpns.numargs = numargs;
3448 dpns.argnames = argnames;
3449
3450 tmp = SysCacheGetAttr(PROCOID, proctup, Anum_pg_proc_prosqlbody, &isnull);
3451 Assert(!isnull);
3452 n = stringToNode(TextDatumGetCString(tmp));
3453
3454 if (IsA(n, List))
3455 {
3456 List *stmts;
3457 ListCell *lc;
3458
3459 stmts = linitial(castNode(List, n));
3460
3461 appendStringInfoString(buf, "BEGIN ATOMIC\n");
3462
3463 foreach(lc, stmts)
3464 {
3465 Query *query = lfirst_node(Query, lc);
3466
3467 /* It seems advisable to get at least AccessShareLock on rels */
3468 AcquireRewriteLocks(query, false, false);
3469 get_query_def(query, buf, list_make1(&dpns), NULL, false,
3470 PRETTYFLAG_INDENT, WRAP_COLUMN_DEFAULT, 1);
3471 appendStringInfoChar(buf, ';');
3472 appendStringInfoChar(buf, '\n');
3473 }
3474
3475 appendStringInfoString(buf, "END");
3476 }
3477 else
3478 {
3479 Query *query = castNode(Query, n);
3480
3481 /* It seems advisable to get at least AccessShareLock on rels */
3482 AcquireRewriteLocks(query, false, false);
3483 get_query_def(query, buf, list_make1(&dpns), NULL, false,
3484 0, WRAP_COLUMN_DEFAULT, 0);
3485 }
3486}
3487
3488Datum
3489pg_get_function_sqlbody(PG_FUNCTION_ARGS)

Callers 2

pg_get_functiondefFunction · 0.85
pg_get_function_sqlbodyFunction · 0.85

Calls 9

get_func_arg_infoFunction · 0.85
SysCacheGetAttrFunction · 0.85
stringToNodeFunction · 0.85
appendStringInfoStringFunction · 0.85
AcquireRewriteLocksFunction · 0.85
get_query_defFunction · 0.85
appendStringInfoCharFunction · 0.85
pstrdupFunction · 0.50
foreachFunction · 0.50

Tested by

no test coverage detected