"Glen W. Mabey" <Glen.Mabey@swri.org> writes:
> On Tue, Dec 04, 2007 at 09:53:37AM -0600, Tom Lane wrote:
>> 3. You're not checking for a null, and the error check you do have
>> is wrong/redundant.
> The field is constrained to be NOT NULL, so I wasn't worried about
> checking that, but I don't see how the error check is wrong,
Well, a check on the isnull state is a good idea anyway IMHO.
This code has no way of being sure that a NOT NULL constraint
exists, and dumping core if it's not there isn't my idea of being
robust.
What I didn't like about the error test was that it assumed that
SPI_ERROR_NOATTRIBUTE is and always will be the only possible
error code from SPI_getbinval. I'd test for SPI_result != 0 instead.
(The "redundant" comment came from the thought that it's probably
pointless to be making this test at all, considering that you just
got the column number from SPI_fnumber on the same tupdesc.)
>> 4. Use DatumGetTextP(), not DatumGetPointer nor PG_DETOAST_DATUM.
> Is there somewhere in the docs that I should have found this (and other
> useful) functions?
fmgr.h, perhaps, or by looking at existing code that does more or less
what you want to do. Postgres does not follow the model that you are
supposed to look only at the SGML docs to find out how to do server-side
programming. We are open source and one of the biggest benefits of that
is that you can (and should) look at the source code to learn.
regards, tom lane