User-defined functions with NULL values and sets as parameter and/or return type - Mailing list pgsql-hackers

From Jeroen van Vianen
Subject User-defined functions with NULL values and sets as parameter and/or return type
Date
Msg-id 34D8E347.5DC47278@design.nl
Whole thread Raw
Responses Re: [HACKERS] User-defined functions with NULL values and sets as parameter and/or return type  (jwieck@debis.com (Jan Wieck))
List pgsql-hackers
Hi,

I have some questions about implementing additional features to the fmgr
code:

1. How do I return a NULL value from a function. In fmgr.c I found out
that only the C-function with 1 parameter has an additional parameter
&isNull which might be used to set the return value to a SQL NULL value.
Why not for functions with more paramaters?

2. How do I use sets as a parameter to my code. E.g. in Illustra's API,
with which I'm fairly familiar, I wrote a function to send an email to
certain people in the following fashion:

return sendmail((select email from table where condition), 'from email',
'subject', 'body of email');

Of course it would be possible to do something like this:

select
  sendmail(email, 'from email', 'subject', 'body of email')
from
  table
where
  condition;

But this would have a detrimental impact on the server, if it has to
open say 400 pipes to /usr/lib/sendmail before this query returns
(probably my machine dies on this).

The function definition in Illustra would be something like:

create function sendmail(setof(text), text, text, text) returns integer
as external name '/path/to/sendmail.so';

3. Can I return sets from a function, e.g. select * from range(1,6)
would give me six rows?

(Again, in Illustra: create function range(integer, integer) returns
setof(integer) as external '/path/to/range.so').

Can this be done using PostgreSQL's API and if not where do I have to
start to try implementing this?

4. And finally: I hardly dare to ask this one: setof(user defined type)?

Please let me know if you have any information that I can use.
If you want me to elaborate some more on Illustra's API (which is quite
good on implementing sets except for naming conventions) please let me
know.

Cheers,

Jeroen van Vianen

pgsql-hackers by date:

Previous
From: Julia Anne Case
Date:
Subject: Compile error ...
Next
From: Keith Parks
Date:
Subject: Snapshot 030298 on SPARC Linux.