Re: Accessing Database Data from C Function - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Accessing Database Data from C Function
Date
Msg-id 20060809023314.GA14667@winnie.fuhr.org
Whole thread Raw
In response to Accessing Database Data from C Function  (jeffrey.bigham@gmail.com)
Responses Re: Accessing Database Data from C Function
List pgsql-general
On Tue, Aug 08, 2006 at 12:16:18PM -0700, jeffrey.bigham@gmail.com wrote:
> I'd like to write a C Function for Postgresql that can access data in
> the database, use that to conduct additional queries to find more
> information in the database and eventually return a result.  I
> currently have the functionality I want implemented as php/C programs
> that first connect to the database, do the processing and then
> disconnect, but I want to make it what I think is called a "stored
> procedure" in other databases.  It seems odd that I would write a C
> program to be included in the database that connects to  the localhost
> - is that what I should do?  Is that somehow more efficient than
> running it as a separate process?

Server-side functions written in C can use the Server Programming
Interface (SPI) to query the database.

http://www.postgresql.org/docs/8.1/interactive/spi.html

Do you have a reason to use C instead of a higher-level language?
Functions that are mostly queries are probably best done in SQL or
PL/pgSQL, while text processing and some OS-level access (e.g.,
reading and writing files) can be done with PL/Perl, PL/Tcl,
PL/Python, PL/Ruby, PL/R, etc.  There's even a third-party PL/php
if that's your preferred language:

http://projects.commandprompt.com/public/plphp

--
Michael Fuhr

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: clients and libs and versions (oh my)
Next
From: Michael Fuhr
Date:
Subject: Re: DROP TABLESPACE fails