Re: how to return rows of data via function written by language C strict

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: how to return rows of data via function written by language C strict
Дата
Msg-id CAKFQuwbyLYT7ZKRUyRwfOwKzyucAEXatVkR84CAMY3=E71u+9w@mail.gmail.com
обсуждение исходный текст
Ответ на how to return rows of data via function written by language C strict  (Christoph Bilz <christoph.bilz@icloud.com>)
Список pgsql-general
On Tue, Jul 9, 2019 at 1:00 PM Christoph Bilz <christoph.bilz@icloud.com> wrote:
Hello,

i want write functions like this:

CREATE FUNCTION foo(text) returns real as '<path>/foo.dll', 'foo'  LANGUAGE C STRICT;"
CREATE FUNCTION foo2(text) returns table(c1 text, c2 int) as '<path>/foo2.dll', 'foo'  LANGUAGE C STRICT;
So far, so clear. I don't want to return one scalar value or SETOF smth, I want to start the function like this:
select * from foo; … and the rows will be returned.
Maybe SQL or pl/pgSQL would be a better choice then?

Also, if you plan to return more than one row you are, by definition, creating a SETOF (TABLE is just shorthand) function.

Also, for what its worth I have no idea with "smth" means here - but I also don't program C.
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_RECORD)   ereport(ERROR,   (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),       errmsg("function returning record called in context "           "that cannot accept type record")));
The inequality check above seems wrong - you want to error if you are presented with a record, not when you aren't.

But it doesn’t work. Either the get_call_result_type fails because the function definition doesn’t match or the the client process crashes because smth. happens and I don’t know how this stuff should work.
So, due to the lack of examples in general and the sparse documentation about it, any help will be appreciate.

As Ian noted, contrib is usually the recommended source for up-to-date coding examples.

David J.

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

Предыдущее
От: Ian Barwick
Дата:
Сообщение: Re: how to return rows of data via function written by language Cstrict
Следующее
От: Julie Nishimura
Дата:
Сообщение: Re: number of concurrent writes that are allowed for database