From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Gregor Trefs <gregor(dot)trefs(at)delphit(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: C function returns null values |
Date: | 2011-07-15 14:24:24 |
Message-ID: | 29270.1310739864@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Gregor Trefs <gregor(dot)trefs(at)delphit(dot)com> writes:
> I developed a C function which returns a record. The record contains 3 scalar values and 2 arrays. Randomly some record elements are null and I wonder why. I could trace down the problem to the point where the return record is created. Until this point everything is computed correctly. Below you see an excerpt of the relevant code. I use PostGres 8.4 on Ubuntu 10.10 (x64).
You're not bothering to fill in the nulls[] array:
> // Allocate enough memory for nulls
> nulls = palloc(tuplen * sizeof (bool));
> // Create tuple
> res_tuple = heap_form_tuple(tupdesc, values, nulls);
palloc0 would work better here.
BTW, it's a good idea to develop/test C code in a backend built with
--enable-debug --enable-cassert. Had you been doing so, palloc would
have given you back intentionally-garbage-filled memory, and you'd have
noticed the mistake immediately.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Bryan Nelson | 2011-07-15 16:03:32 | Error Importing CSV File |
Previous Message | Tony Wang | 2011-07-15 13:37:53 | Re: Weird problem that enormous locks |