Search Postgresql Archives

Re: invalid memory alloc after insert with c trigger function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dudás József <dj1999@xxxxxxxxxxx> writes:

> Sorry I do not understand. I did not convert float to varchar. 

Well then there's some kind of miscommunication here. Your crash is happening
trying to read a varchar column later. Someone sometime is putting data into
that varchar column. I don't understand how the snippets of code handling
floats and numerics relate to the varchar that's causing your crash.


I still don't understand what you're doing and what's going on but there are a
few strange things in this code snippet:

> 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
> }

You test attnum[0] == PointerGetDatum(NULL) but attnum contains the result of
SPI_fnumber which isn't a datum at all, it's an attribute number which is an
integer. In case of error it returns SPI_ERROR_NOATTRIBUTE which is -9.

That said if your function is a function which takes PG_FUNCTION_ARGS then the
right way to return NULL is with PG_RETURN_NULL(). Merely returning a
PointerGetDatum(NULL) isn't good enough.

-- 
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux