Re: difficulty extracting variable-sized field on triggered row

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: difficulty extracting variable-sized field on triggered row
Дата
Msg-id 29312.1196785746@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: difficulty extracting variable-sized field on triggered row  ("Glen W. Mabey" <Glen.Mabey@swri.org>)
Список pgsql-general
"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

В списке pgsql-general по дате отправления:

Предыдущее
От: Ivan Sergio Borgonovo
Дата:
Сообщение: Re: stored procedures and dynamic queries
Следующее
От: "Pau Marc Munoz Torres"
Дата:
Сообщение: Can i Force to postgrsql to use a certain index?