From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Christoph Bilz <christoph(dot)bilz(at)icloud(dot)com> |
Cc: | "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: how to return rows of data via function written by language C strict |
Date: | 2019-07-10 01:16:24 |
Message-ID: | CAKFQuwbyLYT7ZKRUyRwfOwKzyucAEXatVkR84CAMY3=E71u+9w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, Jul 9, 2019 at 1:00 PM Christoph Bilz <christoph(dot)bilz(at)icloud(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Julie Nishimura | 2019-07-10 02:10:56 | Re: number of concurrent writes that are allowed for database |
Previous Message | Ian Barwick | 2019-07-10 00:58:00 | Re: how to return rows of data via function written by language C strict |