Re: how to return rows of data via function written by language C strict - Mailing list pgsql-general

From David G. Johnston
Subject Re: how to return rows of data via function written by language C strict
Date
Msg-id CAKFQuwbyLYT7ZKRUyRwfOwKzyucAEXatVkR84CAMY3=E71u+9w@mail.gmail.com
Whole thread Raw
In response to how to return rows of data via function written by language C strict  (Christoph Bilz <christoph.bilz@icloud.com>)
List 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 by date:

Previous
From: Ian Barwick
Date:
Subject: Re: how to return rows of data via function written by language Cstrict
Next
From: Julie Nishimura
Date:
Subject: Re: number of concurrent writes that are allowed for database