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

Function column_value

gpcontrib/orafce/dbms_sql.c:1580–1696  ·  view source on GitHub ↗

* CALL statement is relatily slow in PLpgSQL - due repated parsing, planning. * So I wrote two variant of this routine. When spi_transfer is true, then * the value is copyied to SPI outer memory context. */

Source from the content-addressed store, hash-verified

1578 * the value is copyied to SPI outer memory context.
1579 */
1580static Datum
1581column_value(CursorData *c, int pos, Oid targetTypeId, bool *isnull, bool spi_transfer)
1582{
1583 Datum value;
1584 int32 columnTypeMode;
1585 Oid columnTypeId;
1586 CastCacheData *ccast;
1587
1588 Assert(c->executed);
1589
1590 if (last_row_count == 0)
1591 ereport(ERROR,
1592 (errcode(ERRCODE_NO_DATA_FOUND),
1593 errmsg("no data found")));
1594
1595 if (!c->tupdesc)
1596 ereport(ERROR,
1597 (errcode(ERRCODE_INVALID_CURSOR_STATE),
1598 errmsg("cursor is not fetched")));
1599
1600 if (!c->coltupdesc)
1601 ereport(ERROR,
1602 (errcode(ERRCODE_UNDEFINED_COLUMN),
1603 errmsg("no column is defined")));
1604
1605 if (pos < 1 && pos > c->coltupdesc->natts)
1606 ereport(ERROR,
1607 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1608 errmsg("column position is of of range [1, %d]",
1609 c->coltupdesc->natts)));
1610
1611 columnTypeId = (TupleDescAttr(c->coltupdesc, pos - 1))->atttypid;
1612 columnTypeMode = (TupleDescAttr(c->coltupdesc, pos - 1))->atttypmod;
1613
1614 Assert(c->casts);
1615 ccast = &c->casts[pos - 1];
1616
1617 if (!ccast->isvalid)
1618 {
1619 Oid basetype = getBaseType(targetTypeId);
1620
1621 init_cast_cache_entry(ccast,
1622 columnTypeId,
1623 columnTypeMode,
1624 SPI_gettypeid(c->tupdesc, pos));
1625
1626 ccast->is_array = bms_is_member(pos, c->array_columns);
1627
1628 if (ccast->is_array)
1629 {
1630 ccast->array_targettypid = basetype != targetTypeId ? targetTypeId : InvalidOid;
1631
1632 if (get_array_type(getBaseType(columnTypeId)) != basetype)
1633 ereport(ERROR,
1634 (errcode(ERRCODE_DATATYPE_MISMATCH),
1635 errmsg("unexpected target type \"%s\" (expected type \"%s\")",
1636 format_type_be(basetype),
1637 format_type_be(get_array_type(getBaseType(columnTypeId))))));

Callers 2

dbms_sql_column_valueFunction · 0.85
dbms_sql_column_value_fFunction · 0.85

Calls 15

getBaseTypeFunction · 0.85
init_cast_cache_entryFunction · 0.85
SPI_gettypeidFunction · 0.85
bms_is_memberFunction · 0.85
get_array_typeFunction · 0.85
format_type_beFunction · 0.85
get_typlenbyvalFunction · 0.85
initArrayResultFunction · 0.85
SPI_getbinvalFunction · 0.85
cast_valueFunction · 0.85
accumArrayResultFunction · 0.85
makeArrayResultFunction · 0.85

Tested by

no test coverage detected