* CREATE FUNCTION dbms_sql.column_value(c int, pos int, value anyelement) RETURNS anyelement; * Note - CALL statement is slow from PLpgSQL block (against function execution). * This is reason why this routine is in function form too. */
| 1771 | * This is reason why this routine is in function form too. |
| 1772 | */ |
| 1773 | Datum |
| 1774 | dbms_sql_column_value_f(PG_FUNCTION_ARGS) |
| 1775 | { |
| 1776 | CursorData *c; |
| 1777 | Datum value; |
| 1778 | int pos; |
| 1779 | bool isnull; |
| 1780 | Oid targetTypeId; |
| 1781 | MemoryContext oldcxt; |
| 1782 | |
| 1783 | if (SPI_connect() != SPI_OK_CONNECT) |
| 1784 | elog(ERROR, "SPI_connact failed"); |
| 1785 | |
| 1786 | c = get_cursor(fcinfo, true); |
| 1787 | |
| 1788 | if (PG_ARGISNULL(1)) |
| 1789 | ereport(ERROR, |
| 1790 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 1791 | errmsg("column position (number) is NULL"))); |
| 1792 | |
| 1793 | pos = PG_GETARG_INT32(1); |
| 1794 | |
| 1795 | if (!c->executed) |
| 1796 | ereport(ERROR, |
| 1797 | (errcode(ERRCODE_INVALID_CURSOR_STATE), |
| 1798 | errmsg("cursor is not executed"))); |
| 1799 | |
| 1800 | oldcxt = MemoryContextSwitchTo(c->result_cxt); |
| 1801 | |
| 1802 | targetTypeId = get_fn_expr_argtype(fcinfo->flinfo, 2); |
| 1803 | |
| 1804 | value = column_value(c, pos, targetTypeId, &isnull, true); |
| 1805 | |
| 1806 | SPI_finish(); |
| 1807 | |
| 1808 | MemoryContextSwitchTo(oldcxt); |
| 1809 | |
| 1810 | PG_RETURN_DATUM(value); |
| 1811 | } |
| 1812 | |
| 1813 | /****************************************************************** |
| 1814 | * Simple parser - just for replacement of bind variables by |
nothing calls this directly
no test coverage detected