calling functions from embedded sql

Поиск
Список
Период
Сортировка
Искать

calling functions from embedded sql

От:
"Tony Griffiths(RA)" <griffitt@cs.man.ac.uk>
Дата:
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




FAQ