Re: How can I retrieve a function result?

From: Luis Alberto Pérez Paz <midriasis(at)gmail(dot)com>
To: "Joachim Wieland" <joe(at)mcknight(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How can I retrieve a function result?
Date: 2006-06-13 18:19:32
Message-ID: 7f64980c0606131119q7fec9623r5bd194b786cdb2c1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)mcknight(dot)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)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jimmy Choi 2006-06-13 18:34:36 Short circuit evaluation of expressions in query
Previous Message Carlos H. Reimer 2006-06-13 18:13:39 RES: XID comparations