pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Trying to make functions in 'C'
5+ messages / 5 participants
[nested] [flat]

* Trying to make functions in 'C'
@ 1999-05-16 11:23  fabian baena <fabbaena@hotmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: fabian baena @ 1999-05-16 11:23 UTC (permalink / raw)
  To: pgsql-general

I'm tying to learn how to make function in 'C'.
I'm trying to compile a program I made in 'C'.
The command I gave were:

% gcc -fPIC -c addone.c -I/usr/local/pgsql/include
% ld -G -Bdynamic -o addone.so addone.o

and created the function in postgres like this:

         CREATE FUNCTION add_one(int4) RETURNS int4
              AS './addone.so' LANGUAGE 'c';


The function I made looks like this:

#include "postgres.h"

int
add_one(int arg)
{
     return arg + 1;
}

But when I try to test the function in postgres I recieve this error:

ERROR:  stat failed on file ./addone.so
ERROR:  stat failed on file ./addone.so
Can anyone tell where did I make a mistake?
I have a linux on a PC.

Thank you.


Fabian.


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [GENERAL] Trying to make functions in 'C'
@ 1999-05-16 19:24  selkovjr@mcs.anl.gov
  parent: fabian baena <fabbaena@hotmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: selkovjr@mcs.anl.gov @ 1999-05-16 19:24 UTC (permalink / raw)
  To: fabian baena <fabbaena@hotmail.com>; pgsql-general

> I'm tying to learn how to make function in 'C'.
> I'm trying to compile a program I made in 'C'.
> The command I gave were:
> 
> % gcc -fPIC -c addone.c -I/usr/local/pgsql/include
> % ld -G -Bdynamic -o addone.so addone.o
> 
> and created the function in postgres like this:
> 
>          CREATE FUNCTION add_one(int4) RETURNS int4
>               AS './addone.so' LANGUAGE 'c';
                   ^^^^^^^^^^^^^
one must provide an absolute path here

--Gene



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [GENERAL] Trying to make functions in 'C'
@ 1999-05-17 06:46  Anatoly K. Lasareff <tolik@icomm.ru>
  parent: fabian baena <fabbaena@hotmail.com>
  1 sibling, 2 replies; 5+ messages in thread

From: tolik@icomm.ru @ 1999-05-17 06:46 UTC (permalink / raw)
  To: fabian baena <fabbaena@hotmail.com>; +Cc: pgsql-general

>>>>> "fb" == fabian baena <fabbaena@hotmail.com> writes:

 fb> I'm tying to learn how to make function in 'C'.
 fb> I'm trying to compile a program I made in 'C'.
 fb> The command I gave were:

 fb> % gcc -fPIC -c addone.c -I/usr/local/pgsql/include
 fb> % ld -G -Bdynamic -o addone.so addone.o

 fb> and created the function in postgres like this:

 fb> CREATE FUNCTION add_one(int4) RETURNS int4
 fb> AS './addone.so' LANGUAGE 'c';


 fb> The function I made looks like this:

 fb> #include "postgres.h"

 fb> int
 fb> add_one(int arg)
 fb> {
 fb> return arg + 1;
 fb> }

 fb> But when I try to test the function in postgres I recieve this error:

 fb> ERROR:  stat failed on file ./addone.so
 fb> ERROR:  stat failed on file ./addone.so
 fb> Can anyone tell where did I make a mistake?
 fb> I have a linux on a PC.

Pehaps not 'int', but 'int4' in argument and return type? Except this
I think your example is right.

-- 
Anatoly K. Lasareff              Email:       tolik@icomm.ru 
Senior programmer



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [GENERAL] Trying to make functions in 'C'
@ 1999-05-17 16:00  selkovjr.mcs.anl.gov@mcs.anl.gov
  parent: Anatoly K. Lasareff <tolik@icomm.ru>
  1 sibling, 0 replies; 5+ messages in thread

From: selkovjr.mcs.anl.gov@mcs.anl.gov @ 1999-05-17 16:00 UTC (permalink / raw)
  To: tolik@icomm.ru; pgsql-general

> >>>>> "fb" == fabian baena <fabbaena@hotmail.com> writes:
> 
>  fb> I'm tying to learn how to make function in 'C'.
>  fb> I'm trying to compile a program I made in 'C'.
>  fb> The function I made looks like this:
> 
>  fb> #include "postgres.h"
> 
>  fb> int
>  fb> add_one(int arg)
>  fb> {
>  fb> return arg + 1;
>  fb> }
> 
> Pehaps not 'int', but 'int4' in argument and return type? Except this
> I think your example is right.

As far as return types, make sure you get what you want by
checking how types are typedef'ed in postgres.h

The safest way to add your own code would be what Fabian is trying to
accomplish -- by using the prototypes from tutorial.


--Gene



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [GENERAL] Trying to make functions in 'C'
@ 1999-06-08 19:25  Jonathan Davis <haj@idianet.net>
  parent: Anatoly K. Lasareff <tolik@icomm.ru>
  1 sibling, 0 replies; 5+ messages in thread

From: Jonathan Davis @ 1999-06-08 19:25 UTC (permalink / raw)
  To: pgsql-general

hello


CREATE SEQUENCE seq

        INCREMENT       1
        MINVALUE        1
        START           1
;

CREATE TABLE T (
 index  int  primary key UNIQUE DEFAULT nextval('seq'),
 f1    char(5),
 f2    char(5)

);

CREATE TABLE T1 (
 f3    char(5),
 f4    char(5),
 f5    char(5)

) INHERITS (T);

CREATE TABLE  T2(
 cp1      char(5),
 cp2  char(5)
) INHERITS (T);


INSERT INTO T1 VALUES ( nextval('seq'), 'joe', 'joe', 'joe', 'joe', 'joe');
INSERT INTO T1 VALUES ( nextval('seq'), 'davis', 'davis', 'davis', 'davis',
'davis');
INSERT INTO T1 VALUES ( nextval('seq'), 'ba', 'ba', 'ba', 'ba', 'ba');

INSERT INTO T2 VALUES  ( nextval('seq'), 'aw', 'aw', 'aw', 'aw');
INSERT INTO T2 VALUES  ( nextval('seq'), 'es', 'es', 'es', 'es');

SELECT * FROM T*;

this request give me only the fields in table T but I want to give me all
fiels in T1 and T2
how ?

thanks





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~1999-06-08 19:25 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-05-16 11:23 Trying to make functions in 'C' fabian baena <fabbaena@hotmail.com>
1999-05-16 19:24 ` selkovjr@mcs.anl.gov
1999-05-17 06:46 ` Anatoly K. Lasareff <tolik@icomm.ru>
1999-05-17 16:00   ` selkovjr.mcs.anl.gov@mcs.anl.gov
1999-06-08 19:25   ` Jonathan Davis <haj@idianet.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox