* 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. */
| 1578 | * the value is copyied to SPI outer memory context. |
| 1579 | */ |
| 1580 | static Datum |
| 1581 | column_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)))))); |
no test coverage detected