From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Glen W(dot) Mabey" <Glen(dot)Mabey(at)swri(dot)org> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: difficulty extracting variable-sized field on triggered row |
Date: | 2007-12-04 16:29:06 |
Message-ID: | 29312.1196785746@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Glen W. Mabey" <Glen(dot)Mabey(at)swri(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Pau Marc Munoz Torres | 2007-12-04 16:34:08 | Can i Force to postgrsql to use a certain index? |
Previous Message | Ivan Sergio Borgonovo | 2007-12-04 16:29:02 | Re: stored procedures and dynamic queries |