Re: Help requd in writing functions in C and using in Postgres

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Jasbinder Bali <jsbali(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Help requd in writing functions in C and using in Postgres
Date: 2006-06-20 22:32:20
Message-ID: 20060620223220.GA69870@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 20, 2006 at 02:03:06PM -0400, Jasbinder Bali wrote:
> Does that mean I can't make a function in C that will have all the database
> transactions and then would just be included in the Stored Procedure in
> postgres (though i know there is no concept of stored procs in postgres, its
> all functions that you have in it).

Functions are executed in the context of an outer transaction, so
if you need multiple transactions then you'll have to initiate them
from the client side. However, as I mentioned, a server-side
function could connect to the database and act as a client, so that
would be one way to execute multiple transactions via a server-side
function. A possible drawback of doing so is that if the function
is called from a transaction that's later rolled back, the statements
that the function executed over its client connection would have
already been committed and thus wouldn't be rolled back.

> Also when i say include <postgres.h>, my function would not find it coz its
> in some different path altogether. Where exactly is this postgres.h and
> other postgres header files??

The "C-Language Functions" documentation I previously sent explains
how to find include files, but if you use the PGXS build infrastructure
then you don't need to worry about it.

http://www.postgresql.org/docs/8.1/interactive/xfunc-c.html#AEN32313
http://www.postgresql.org/docs/8.1/interactive/xfunc-c.html#DFUNC
http://www.postgresql.org/docs/8.1/interactive/xfunc-c.html#XFUNC-C-PGXS

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Florian G. Pflug 2006-06-21 01:17:23 Re: Adding foreign key constraints without integrity check?
Previous Message simon 2006-06-20 22:09:48 Re: merge result sets