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 23:25:35
Message-ID: 7f64980c0606131625h35e39502s7799d5a628aba033@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you Joachim,
it woks!

Regards,

Luis A Perez Paz

On 6/13/06, Joachim Wieland <joe(at)mcknight(dot)de> wrote:
>
> Luis,
>
> On Tue, Jun 13, 2006 at 01:19:32PM -0500, Luis Alberto Pérez Paz wrote:
> > 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).
>
> this is similar to retrieving the result of a query that returned one row
> and one column. So you just have to use PQgetvalue(res, 0, 0).
>
> Here are a few other examples:
>
> Check if there were rows at all:
>
> if (PQntuples(res) == 0) {
> /* no rows */
> PQclear(res);
> return (char*) 0;
> }
>
> Check if there was anything else than one column per row:
>
> if (PQnfields(res) != 1) {
> /* did not get only 1 column back */
> PQclear(res);
> return (char*) 0;
> }
>
> Check whether or not the first column, first row field is NULL:
>
> if (PQgetisnull(res, 0, 0)) {
> /* got NULL */
> PQclear(res);
> return (char*) 0;
> }
>
> Get the first row, first column value as char*:
>
> db_value = PQgetvalue(res, 0, 0);
>
>
> I hope this gives you an idea.
>
> Those functions are in this section of the documentation:
>
>
> http://www.postgresql.org/docs/8.1/static/libpq-exec.html#LIBPQ-EXEC-SELECT-INFO
>
> Joachim
>

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message LLC 2006-06-14 00:21:14 Compiling contrib dblink_tds and oralink
Previous Message Jim C. Nasby 2006-06-13 23:19:01 Re: postgres vs. oracle for very large tables