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

Function plpgsql_parse_dblword

src/pl/plpgsql/src/pl_comp.c:1469–1542  ·  view source on GitHub ↗

---------- * plpgsql_parse_dblword Same lookup for two words * separated by a dot. * ---------- */

Source from the content-addressed store, hash-verified

1467 * ----------
1468 */
1469bool
1470plpgsql_parse_dblword(char *word1, char *word2,
1471 PLwdatum *wdatum, PLcword *cword)
1472{
1473 PLpgSQL_nsitem *ns;
1474 List *idents;
1475 int nnames;
1476
1477 idents = list_make2(makeString(word1),
1478 makeString(word2));
1479
1480 /*
1481 * We should do nothing in DECLARE sections. In SQL expressions, we
1482 * really only need to make sure that RECFIELD datums are created when
1483 * needed. In all the cases handled by this function, returning a T_DATUM
1484 * with a two-word idents string is the right thing.
1485 */
1486 if (plpgsql_IdentifierLookup != IDENTIFIER_LOOKUP_DECLARE)
1487 {
1488 /*
1489 * Do a lookup in the current namespace stack
1490 */
1491 ns = plpgsql_ns_lookup(plpgsql_ns_top(), false,
1492 word1, word2, NULL,
1493 &nnames);
1494 if (ns != NULL)
1495 {
1496 switch (ns->itemtype)
1497 {
1498 case PLPGSQL_NSTYPE_VAR:
1499 /* Block-qualified reference to scalar variable. */
1500 wdatum->datum = plpgsql_Datums[ns->itemno];
1501 wdatum->ident = NULL;
1502 wdatum->quoted = false; /* not used */
1503 wdatum->idents = idents;
1504 return true;
1505
1506 case PLPGSQL_NSTYPE_REC:
1507 if (nnames == 1)
1508 {
1509 /*
1510 * First word is a record name, so second word could
1511 * be a field in this record. We build a RECFIELD
1512 * datum whether it is or not --- any error will be
1513 * detected later.
1514 */
1515 PLpgSQL_rec *rec;
1516 PLpgSQL_recfield *new;
1517
1518 rec = (PLpgSQL_rec *) (plpgsql_Datums[ns->itemno]);
1519 new = plpgsql_build_recfield(rec, word2);
1520
1521 wdatum->datum = (PLpgSQL_datum *) new;
1522 }
1523 else
1524 {
1525 /* Block-qualified reference to record variable. */
1526 wdatum->datum = plpgsql_Datums[ns->itemno];

Callers 1

plpgsql_yylexFunction · 0.85

Calls 4

makeStringFunction · 0.85
plpgsql_ns_lookupFunction · 0.85
plpgsql_ns_topFunction · 0.85
plpgsql_build_recfieldFunction · 0.85

Tested by

no test coverage detected