C-language functions: SRF question

Поиск
Список
Период
Сортировка
От Jorge Arevalo
Тема C-language functions: SRF question
Дата
Msg-id p2hd321138e1004080840v3e58ba6coa0465902a9c79999@mail.gmail.com
обсуждение исходный текст
Ответы Re: C-language functions: SRF question  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
Hello,

I need to code a set-returning function, but it's my first time, and
I'm not sure if my point is the right one. I'd like to know your
opinion:

My function will return an array of structs. Then, In the first call
(SRF_IS_FIRSTCALL() is true), I get the array from another function.
For the next calls, I'll need to access a position of this array, so,
I'll need to store it, and the position needed, in any place. The
place should be the user_fctx field of the FuncCallContext.

I've created a struct that will store my array of structs and an int
value, a index. In the first call, this index is 0. In next calls, I
can recover data from FuncCallContext, get the struct indexed by the
index value, build my tuple, return it and increment the index.

Is this a good way of doing it? Is it possible? And another small
question: if the memory for my array of structs is allocated inside
the function that provides me the array, should I deallocate it in the
SRF? Using pfree? It wasn't allocated by palloc...


Thanks in advance, and best regards,
Jorge

--
http://www.gis4free.org/blog

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

Предыдущее
От: Corin
Дата:
Сообщение: fulltext search stemming/ spelling problems
Следующее
От: Merlin Moncure
Дата:
Сообщение: Re: C-language functions: SRF question