Re: Wierdness using SUM to add results of custom C function.
От | Tom Lane |
---|---|
Тема | Re: Wierdness using SUM to add results of custom C function. |
Дата | |
Msg-id | 24726.1014674995@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: Wierdness using SUM to add results of custom C function. (Konrad Scherer <kscherer@magma.ca>) |
Список | pgsql-general |
Konrad Scherer <kscherer@magma.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
В списке pgsql-general по дате отправления: