Обсуждение: Returning tuple(s) from C-Functions

Поиск
Список
Период
Сортировка

Returning tuple(s) from C-Functions

От
Philip Poten
Дата:
Hi.

I'm into programming a function for pg for searching a ldap directory.
But this whole effort has absolutely no sense, if i don't find a way to
return _at least_ one whole tuple from a C-Function, e.g.

create function foobar(footable)
    returns bartable
    as '/var/lib/pgsql/data/foobar.o'
    language 'c'
;

and i return a pointer to a tuple or something?

This is what the FAQ says about it:

5.3) How do I write a C function to return a tuple?

This requires wizardry so extreme that the authors have never tried it,
though in principle it can be done?

Is this answer still correct? Is there a way to do it with 7.1?
Can i write to a temporary table in this function and insert into the
backend somehow?
I'm not expecting too much people having this done, but if anyone did
it, please reply...

tia,
Philip

--
| | Philip Poten|\ \ | | | | | | \ \/ / YL
| | Unix Operator \ \| | | | | |  \ \/   i
| |_+43/1/91 999 - 207 | | |_| |  /\ \   n
|___philip.poten@linuxteam.at_/  / /\ \  e




Re: Returning tuple(s) from C-Functions

От
Tom Lane
Дата:
Philip Poten <philip.poten@linuxteam.at> writes:
> This is what the FAQ says about it:

> 5.3) How do I write a C function to return a tuple?

> This requires wizardry so extreme that the authors have never tried it,
> though in principle it can be done?

> Is this answer still correct? Is there a way to do it with 7.1?

It's not so much that the wizardry is extreme as that once you've done
it, the resulting function is not all that useful, because there's not
very much you can *do* with a function returning tuples.  You might
care to experiment with SQL functions that return tuples to see whether
the system will support what you need to do, before you spend a lot of
effort on replicating their behavior.

In case that wasn't a clear enough hint: to do it, lift appropriate
code from SQL function execution (backend/executor/functions.c).

Be aware that this interface will likely be redesigned whenever we
get around to allowing functions as table sources, which is exactly
the step needed to make such things more conveniently usable.  Might
happen for 7.2 ...

            regards, tom lane