Skip site navigation (1) Skip section navigation (2)

C Stored Function with ECPG

From: Bob Henkel <bob(dot)henkel(at)gmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: C Stored Function with ECPG
Date: 2009-02-24 01:04:04
Message-ID: (view raw or flat)
Lists: pgsql-interfaces
Sorry if this double posts. My first attempt was stalled because I was
not a member of the list. So now I am.

I'm starting to experiment with writing some stored functions in C and
find it really handy.  I have a simple C function that takes two
integers and returns the sum.  This works fine. Now I want to create a
function that makes us of some embedded ECPG. So far I have failed at
my first attempt. Below are the steps and outputs of what I did.  I
assume it's feasible to embedd ECPG in a Postgres Stored function
written in C?

My foo1.pcg file looks like this.
#include "postgres.h"
#include  <string.h>
#include "fmgr.h"



   EXEC SQL CREATE TABLE foo1 (c1 integer NOT NULL, c2 varchar(50) NOT NULL);


1. I run ecpg foo1.pcg and this generates my foo1.c file. I get no
warnings or errors.
[postgres(at)PortJackson ~]$ ecpg foo1.pgc
[postgres(at)PortJackson ~]$

2. I compile foo1.c and get some warnings.  Are these warnings ok?
[postgres(at)PortJackson ~]$  gcc -g -fpic -c foo1.c
foo1.pgc: In function 'foo1':
foo1.pgc:14: warning: passing argument 5 of 'ECPGdo' makes integer
from pointer without a cast
foo1.pgc:14: warning: passing argument 7 of 'ECPGdo' makes pointer
from integer without a cast
[postgres(at)PortJackson ~]$

3.I link foo1. With now warnings or errors.
[postgres(at)PortJackson ~]$ gcc -shared -o foo1.o
-L/usr/local/pgsql/lib -lecpg
[postgres(at)PortJackson ~]$

4. I create a function in psql to call my new library. And get a could
not load library error for file  How do I fix this
dev=# CREATE OR REPLACE FUNCTION foo1(integer)
 RETURNS integer AS
'/usr/home/postgres/foo1', 'foo1'
 COST 1;
ERROR:  could not load library "/usr/home/postgres/": dlopen
(/usr/home/postgres/ failed: Shared object "" not
found, required by ""

I'm new to C functions and to ECPG. So mixing the two at this point
for me is probably asking for trouble.  Any help would be much



pgsql-interfaces by date

Next:From: Tom LaneDate: 2009-02-24 01:47:28
Subject: Re: C Stored Function with ECPG
Previous:From: Tom LaneDate: 2009-02-03 00:43:46
Subject: Re: char columns, space padding, and the "like" operator

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group