Re: How can I retrieve a function result?

Поиск
Список
Период
Сортировка
От Luis Alberto Pérez Paz
Тема Re: How can I retrieve a function result?
Дата
Msg-id 7f64980c0606131119q7fec9623r5bd194b786cdb2c1@mail.gmail.com
обсуждение исходный текст
Ответ на Re: How can I retrieve a function result?  (Joachim Wieland <joe@mcknight.de>)
Ответы Re: How can I retrieve a function result?  (Joachim Wieland <joe@mcknight.de>)
Список pgsql-general
Hi,
 
Thanks a lot for your answer,
 
Let me give you a simple example with more detail:
 
In my postgres database I have a function called "myFunction".
 
/************************************************************************/
CREATE OR REPLACE FUNCTION myFunction(INT) RETURN INT AS '
DECLARE
  indice    ALIAS FOR $1;
BEGIN
 
  IF indice > 0 THEN
    return -900;
  ELSE
    //something to do....
    return 0;
  END IF;
 
END;
' LANGUAGE 'plpgsql';
/************************************************************************/
 
I have a program in C/C++ which call the FUNCTION 'myFunction'
 
/************************************************************************/
res = PQexecParams ( conn, "select myFunction($1)" , 1, NULL,
paramValues, paraLenghts, paramFormats, resultFormat);
/************************************************************************/
 
The program works fine, actually I can verify that it executes the FUNCTION 'myFunction', however I dont know how can I get the return value of the FUNCTION 'myFunction' (as you can see in the little example the return value can be 0 or -900).
 
 
Regards,
 
Thanks in advance!
 
 


 
On 6/12/06, Joachim Wieland <joe@mcknight.de> wrote:
Luis,

On Mon, Jun 12, 2006 at 06:24:24PM -0500, Luis Alberto Pérez Paz wrote:
> res = PQexecParams ( conn, "select myFunction($1,$2,$3)" , 3, NULL,
> paramValues, paraLenghts, paramFormats, resultFormat);

> It's works fine, however I dont know how can I retrieve the result that
> return the FUNCTION "myFunction". "myFunction" is a postgres FUNCTION which
> returns a INT.

libpq functions for retrieving query results are described here:

http://www.postgresql.org/docs/8.1/static/libpq-exec.html#LIBPQ-EXEC-SELECT-INFO
Have you tried them and do you have a special problem with one of those? If
so, please give more detail.

Getting the result of a function does not differ from getting the result of
a regular select of a table or view.


Joachim




--
paz, amor y comprensión
        (1967-1994)

В списке pgsql-general по дате отправления:

Предыдущее
От: "Carlos H. Reimer"
Дата:
Сообщение: RES: XID comparations
Следующее
От: "Jimmy Choi"
Дата:
Сообщение: Short circuit evaluation of expressions in query