calling functions from embedded sql

From: "Tony Griffiths(RA)" <griffitt(at)cs(dot)man(dot)ac(dot)uk>
To: pgsql-novice(at)postgresql(dot)org
Subject: calling functions from embedded sql
Date: 2002-04-18 09:26:02
Message-ID: 3CBE912A.3010506@cs.man.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,
There are long and convoluted reasons why I need to do this, but
basically I'd like to call a user-defined function from within embedded
sql in C. I've successfully managed to call functions that either insert
or update tuples, as per the code below, but I'd like to be able to call
a function that returns a setof ints and then process the returned set
within my C++ code.

An example of the code that calls an insert (and that works) is:

CREATE FUNCTION
tpd_City_setrefToPerson_population_refToPerson_ass_rel_saveOp ( name,
character )
Returns int4
As '
INSERT INTO
City_setrefToPerson_population_refToPerson_ass_rel (
City_setrefToPerson_population, element_of_refToPerson_OID )
VALUES ( $1, $2);
SELECT 1;'
LANGUAGE 'sql';

and from the C++ this is called as:

EXEC SQL BEGIN DECLARE SECTION;
char insert_stmt[1000];
EXEC SQL END DECLARE SECTION;

// create the insert statement into :insert_stmt

EXEC SQL EXECUTE IMMEDIATE :insert_stmt;

What I'd not like to do is invoke the following function:

CREATE FUNCTION
tpd_City_setrefToPerson_population_refToPerson_ass_rel_loadOp ( text )
Returns SETOF int4
As '
SELECT ( current_value ) FROM
City_setrefToPerson_population_refToPerson_ass_rel WHERE
objectIdentifier = $1
'
LANGUAGE 'sql';

but how do I process the resulting setof elements? Or am I attempting
something that should only really be done through dynamic embedded sql?
Incedentally, does anyone know of a source of documentation of
postgreSQL dynamic embedded sql, as I can't seems to find any reference
to this?

Many thanks,

Tony Griffiths

Browse pgsql-novice by date

  From Date Subject
Next Message April L 2002-04-18 14:48:53 Indexes: which to use BTREE RTREE HASH GIST?
Previous Message Henshall, Stuart - WCP 2002-04-18 08:55:34 Re: Primary Key