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

Function connectby_text_serial

contrib/tablefunc/tablefunc.c:1067–1143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1065
1066PG_FUNCTION_INFO_V1(connectby_text_serial);
1067Datum
1068connectby_text_serial(PG_FUNCTION_ARGS)
1069{
1070 char *relname = text_to_cstring(PG_GETARG_TEXT_PP(0));
1071 char *key_fld = text_to_cstring(PG_GETARG_TEXT_PP(1));
1072 char *parent_key_fld = text_to_cstring(PG_GETARG_TEXT_PP(2));
1073 char *orderby_fld = text_to_cstring(PG_GETARG_TEXT_PP(3));
1074 char *start_with = text_to_cstring(PG_GETARG_TEXT_PP(4));
1075 int max_depth = PG_GETARG_INT32(5);
1076 char *branch_delim = NULL;
1077 bool show_branch = false;
1078 bool show_serial = true;
1079 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1080 TupleDesc tupdesc;
1081 AttInMetadata *attinmeta;
1082 MemoryContext per_query_ctx;
1083 MemoryContext oldcontext;
1084
1085 /* check to see if caller supports us returning a tuplestore */
1086 if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
1087 ereport(ERROR,
1088 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1089 errmsg("set-valued function called in context that cannot accept a set")));
1090 if (!(rsinfo->allowedModes & SFRM_Materialize) ||
1091 rsinfo->expectedDesc == NULL)
1092 ereport(ERROR,
1093 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1094 errmsg("materialize mode required, but it is not allowed in this context")));
1095
1096 if (fcinfo->nargs == 7)
1097 {
1098 branch_delim = text_to_cstring(PG_GETARG_TEXT_PP(6));
1099 show_branch = true;
1100 }
1101 else
1102 /* default is no show, tilde for the delimiter */
1103 branch_delim = pstrdup("~");
1104
1105 per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
1106 oldcontext = MemoryContextSwitchTo(per_query_ctx);
1107
1108 /* get the requested return tuple description */
1109 tupdesc = CreateTupleDescCopy(rsinfo->expectedDesc);
1110
1111 /* does it meet our needs */
1112 validateConnectbyTupleDesc(tupdesc, show_branch, show_serial);
1113
1114 /* OK, use it then */
1115 attinmeta = TupleDescGetAttInMetadata(tupdesc);
1116
1117 /* OK, go to work */
1118 rsinfo->returnMode = SFRM_Materialize;
1119 rsinfo->setResult = connectby(relname,
1120 key_fld,
1121 parent_key_fld,
1122 orderby_fld,
1123 branch_delim,
1124 start_with,

Callers

nothing calls this directly

Calls 9

text_to_cstringFunction · 0.85
MemoryContextSwitchToFunction · 0.85
CreateTupleDescCopyFunction · 0.85
connectbyFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
pstrdupFunction · 0.50

Tested by

no test coverage detected