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

Function plpgsql_build_recfield

src/pl/plpgsql/src/pl_comp.c:2063–2096  ·  view source on GitHub ↗

* Build a RECFIELD datum for the named field of the specified record variable * * If there's already such a datum, just return it; we don't need duplicates. */

Source from the content-addressed store, hash-verified

2061 * If there's already such a datum, just return it; we don't need duplicates.
2062 */
2063PLpgSQL_recfield *
2064plpgsql_build_recfield(PLpgSQL_rec *rec, const char *fldname)
2065{
2066 PLpgSQL_recfield *recfield;
2067 int i;
2068
2069 /* search for an existing datum referencing this field */
2070 i = rec->firstfield;
2071 while (i >= 0)
2072 {
2073 PLpgSQL_recfield *fld = (PLpgSQL_recfield *) plpgsql_Datums[i];
2074
2075 Assert(fld->dtype == PLPGSQL_DTYPE_RECFIELD &&
2076 fld->recparentno == rec->dno);
2077 if (strcmp(fld->fieldname, fldname) == 0)
2078 return fld;
2079 i = fld->nextfield;
2080 }
2081
2082 /* nope, so make a new one */
2083 recfield = palloc0(sizeof(PLpgSQL_recfield));
2084 recfield->dtype = PLPGSQL_DTYPE_RECFIELD;
2085 recfield->fieldname = pstrdup(fldname);
2086 recfield->recparentno = rec->dno;
2087 recfield->rectupledescid = INVALID_TUPLEDESC_IDENTIFIER;
2088
2089 plpgsql_adddatum((PLpgSQL_datum *) recfield);
2090
2091 /* now we can link it into the parent's chain */
2092 recfield->nextfield = rec->firstfield;
2093 rec->firstfield = recfield->dno;
2094
2095 return recfield;
2096}
2097
2098/*
2099 * plpgsql_build_datatype

Callers 2

plpgsql_parse_dblwordFunction · 0.85
plpgsql_parse_tripwordFunction · 0.85

Calls 3

plpgsql_adddatumFunction · 0.85
palloc0Function · 0.50
pstrdupFunction · 0.50

Tested by

no test coverage detected