On Mon, Jul 05, 2010 at 10:20:30AM +0200, saitenhe...@web.de wrote:
> Datum count_person(PG_FUNCTION_ARGS) {
> SPI_connect();
> int ret = SPI_exec("SELECT count(*) FROM person", 0);
> SPI_finish();
> PG_RETURN_INT32(ret);
> }
> 
> But I guess I still did something wrong, because no matter how many
> rows exist in my table "person" the result in always 5.

5 is actually the value you want to be getting back!

The problem is that you're treating the status value of SPI_exec as the
result of the query.  You need to check the result to see if there was
an error and only if it's OK can you call something like SPI_getvalue to
actually get the count out.  You could probably steal some code from:

  http://developer.postgresql.org/pgdocs/postgres/spi-examples.html

-- 
  Sam  http://samason.me.uk/

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to