Re: PG_RETURN_INT64 vs PointerGetDatum & ANALYZE

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: PG_RETURN_INT64 vs PointerGetDatum & ANALYZE
Дата
Msg-id 18064.1152999572@sss.pgh.pa.us
обсуждение исходный текст
Ответ на PG_RETURN_INT64 vs PointerGetDatum & ANALYZE  ("Sergey E. Koposov" <math@sai.msu.ru>)
Список pgsql-hackers
"Sergey E. Koposov" <math@sai.msu.ru> writes:
> C function definition:

> PG_FUNCTION_INFO_V1(pgq3c_ang2ipix);
> Datum pgq3c_ang2ipix(PG_FUNCTION_ARGS)
> {
>      static q3c_ipix_t ipix_buf;
>      ipix_buf ++;
>      elog(WARNING,"%lld",ipix_buf);
>      return PointerGetDatum((&ipix_buf));
> }

This code is wrong on its face: it can't support multiple calls to the
function within a single query, because each call will damage the
previous call's result.  Try something like
select pgq3c_ang2ipix(...), pgq3c_ang2ipix(...) from ...

and you'll get bizarre behavior.

You need to return a palloc'd result, rather than returning pointers to
the same static variable on successive calls.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Re: postgresql.conf basic analysis tool
Следующее
От: Hannu Krosing
Дата:
Сообщение: Re: Forcing wal rotation