Re: Accessing Database Data from C Function

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: jeffrey(dot)bigham(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Accessing Database Data from C Function
Date: 2006-08-09 02:33:14
Message-ID: 20060809023314.GA14667@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Aug 08, 2006 at 12:16:18PM -0700, jeffrey(dot)bigham(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Carl R. Brune 2006-08-09 02:40:47 Re: read only transaction, temporary tables
Previous Message Tom Lane 2006-08-09 02:12:45 Re: clients and libs and versions (oh my)