Обсуждение: Calling 'c' function from PostGreSQL

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

Calling 'c' function from PostGreSQL

От
"Atul"
Дата:
Is it possible to call a language 'C'  function from a PL/pgSQL function. I have the following code:
 
// file myfunc.c
#include "postgres.h"
 
text* myfunc();
 
text* myfunc()
{
 text* ch;
 *ch = '1,2';
 return ch;
}
 
// C file ends here
 
create function myfunc as
'myfunc.so' langauge 'c';
 
create function test() returns text as '
declare
    at text;
begin
    at := myfunc();
    return at;
end;
' language 'plpgsql';
 
The above when executed gives pqReadData()-- backend closed the channel unexpectedly.
 
 

Re: Calling 'c' function from PostGreSQL

От
Nabil Sayegh
Дата:
On 09 Apr 2001 16:17:08 +0530, Atul wrote:
> Is it possible to call a language 'C'  function from a PL/pgSQL function. I have the following code:
>
> // file myfunc.c
> #include "postgres.h"
>
> text* myfunc();
>
> text* myfunc()
> {
>  text* ch;
>  *ch = '1,2';
>  return ch;
> }
>
> // C file ends here



Did you compile it with -fPIC ?

--
 Nabil Sayegh



Re: Calling 'c' function from PostGreSQL

От
Tom Lane
Дата:
"Atul" <atulk@newgen.co.in> writes:
> text* myfunc()
> {
>  text* ch;
>  *ch = '1,2';
>  return ch;
> }

You can't create a text object that way.  Read some of the text-mashing
functions in the existing backend code for examples of creating a text
value correctly.  (And pay more attention to the complaints that your
C compiler undoubtedly gave you...)

            regards, tom lane