Re: invalid memory alloc after insert with c trigger function

From: Dudás József <dj1999(at)freemail(dot)hu>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: invalid memory alloc after insert with c trigger function
Date: 2007-06-01 12:03:26
Message-ID: 46600B0E.8010107@freemail.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(at)freemail(dot)hu> 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?
>
>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Stark 2007-06-01 12:34:47 Re: invalid memory alloc after insert with c trigger function
Previous Message Simon Riggs 2007-06-01 11:44:31 Re: warm standby server stops doing checkpoints afterawhile