Sorry I do not understand. I did not convert float to varchar. The first
3 data are char* these conver to Datum:
attnum[0] = SPI_fnumber( tupdesc, "deviza_kod" );
datums[0] = DirectFunctionCall1(textin, CStringGetDatum(
_selectFunction( "SELECT ertek FROM foo WHERE parameter='currency'" ) ) );
if ( attnum[0] == PointerGetDatum( NULL ) ) {
elog( ERROR, "Hianyzo deviza" );
SPI_finish(); // zárunk
return PointerGetDatum(NULL); // vissza
}
The 1 and 2 are same as this. But these are OK.
I have problem with NUMERIC type. Convert with this function char* to
double to Datum:
PG_FUNCTION_INFO_V1(_selectFunctionB);
Datum
_selectFunctionB( char *sql )
{
double b;
int ret, proc;
ret = SPI_exec( sql, 0 );
proc = SPI_processed;
if (ret == SPI_OK_SELECT && proc > 0) {
SPITupleTable* tuptable = SPI_tuptable;
TupleDesc tupdesc = SPI_tuptable->tupdesc;
HeapTuple tuple = tuptable->vals[ 0 ];
if ( tuple ) {
b = atof( SPI_getvalue( tuple, tupdesc, 1 ) );
}
}
PG_RETURN_FLOAT8( b );
}
I call these to put Datum value to datums[3] array element:
datums[3] = _selectFunctionB( "SELECT ertek FROM foo WHERE
parameter='rate'" );
Dudás József <dj1999@xxxxxxxxxxx> writes:
elog( INFO, "2.5.1 Datums[3] = %f", DatumGetFloat8( datums[3] ) );
rettuple = SPI_modifytuple( trigdata->tg_relation, tmptuple, 4, &attnum[0],
...
The datums[0 - 2] are char* / VARCHAR type. If I set /SPI_modifytuple(
trigdata->tg_relation, tmptuple, 3, &attnum[0], &datums[0], &isNull[0] ); /than
everything is OK after insert.
At what point does the float get converted to a varchar?