Skip site navigation (1) Skip section navigation (2)

Re: Docbug, SPI_getbinval, triger example

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: mlw <markw(at)mohawksoft(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Docbug, SPI_getbinval, triger example
Date: 2001-11-30 18:03:17
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
mlw <markw(at)mohawksoft(dot)com> writes:
> The docs suggest that this:
>         /* Get number of tuples in relation */
>         ret = SPI_exec("select count(*) from ttest", 0);

Mph.  The example *used* to be right, but is not as of 7.2, because
count() now returns int8 which is pass-by-reference.  Your proposed
fix isn't quite right either (you'd have noticed the difference between
*int and *int8 on a big-endian machine ;-)).  Probably we should change
the example to read

	i = (int) DatumGetInt64(SPI_getbinval(...));

Alternatively the example query could be changed to

        ret = SPI_exec("select count(*)::int4 from ttest", 0);

so as to avoid the backend version dependency.  Comments anyone?

			regards, tom lane

In response to

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2001-11-30 18:03:23
Subject: Re: History question
Previous:From: Vince VielhaberDate: 2001-11-30 18:02:29
Subject: Re: History question

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group