Re: Stored Procedures - Mailing list pgsql-novice

From Josh Berkus
Subject Re: Stored Procedures
Date
Msg-id web-1452641@davinci.ethosmedia.com
Whole thread Raw
In response to Stored Procedures  (Wendy Powley <wendy@cs.queensu.ca>)
List pgsql-novice
Wendy,

> Here I'm referring to a "C struct" ... a data structure containing
> several values.  For instance, I might have a struct defined as
> followed:
>
>   struct person {
>      char name[10],
>       char address[30],
>        int  age };
>
> containing the name, address & age of a particular person.

Ah.  I see what you're attempting.

I'm not sure that you want to operate through functions at all.  There
is a very hefty C library for direct Postgres interaction.  You can
look it up in the online docs, or buy a book (such as Wrox Press's
Postgres book) which covers C + Postgresql programming.

That's as much as I know ... I'm a SQL jockey, and don't do C.

> What do you mean by a record here?  Sorry, I'm new to the postgres
> terminology (although quickly learning!!!).

A RECORD is a data type that holds field data for one to several
fields, and performs ... in PL/pgSQL functions ... a lot like the
Struct you mention.  However, a RECORD must be keyed off a query, as
follows:

DECLARE
    my_rec RECORD;
BEGIN
SELECT id, type INTO my_rec
FROM table1 WHERE id = $1;
IF my_rec.type = 'press contact' THEN

etc.

See the PL/pgSQL documentation (Under "Procedural Langauges" where
you'll find information on C functions as well) for more information
about this.

-Josh Berkus




pgsql-novice by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: Stored Procedures
Next
From: "Joshua Moore-Oliva"
Date:
Subject: Functions replicating stored procedures