Re: Wierdness using SUM to add results of custom C function.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Konrad Scherer <kscherer(at)magma(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Wierdness using SUM to add results of custom C function.
Date: 2002-02-25 22:09:55
Message-ID: 24726.1014674995@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Konrad Scherer <kscherer(at)magma(dot)ca> writes:

> //if no text, then no
> words
> if (txt->vl_len < 1)
> {
> return
> 0;

> }
> //if there is text, but no commas there must be one
> word
> count =
> 1;
> //ignore commas in first and last postion in
> list
> for (i=1;i<(txt->vl_len)-1;i++)
> {
> if (str[i]==',')
> {

> count++;

> }

You appear to be assuming that txt->vl_len is the length of the string.
It's not (it includes the size of the header). You're scanning a few
garbage bytes beyond the data, and evidently those sometimes look like
commas. The apparent difference in behavior between aggregate and
non-aggregate context likely has something to do with whether the
argument you're given has been copied or not.

> An aside: should I be freeing str after I am done with it?

You can, but it's not really necessary; the palloc'd storage will be
reclaimed soon after your function exits anyway.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-02-25 22:17:42 Re: Permissions on file created by COPY TO
Previous Message Jean-Luc Lachance 2002-02-25 21:53:29 Re: Sort problem