From: | Gregory Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | <dj1999(at)freemail(dot)hu> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: invalid memory alloc after insert with c trigger function |
Date: | 2007-06-01 12:34:47 |
Message-ID: | 87ejkvyhso.fsf@oxford.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Dudás József <dj1999(at)freemail(dot)hu> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2007-06-01 12:50:26 | Re: ERROR: domain domain1 does not allow null values |
Previous Message | Dudás József | 2007-06-01 12:03:26 | Re: invalid memory alloc after insert with c trigger function |