Обсуждение: Returning NULL from SRF

Поиск
Список
Период
Сортировка

Returning NULL from SRF

От
Magnus Persson
Дата:
My function is defined as:
   CREATE OR REPLACE FUNCTION ta_f(
     IN ta_in double precision[],
     OUT ta_out double precision)
   RETURNS SETOF double precision
   AS 'pg_ta'
   LANGUAGE C STRICT;

And for those cases where I have an actual number to return I do:
   SRF_RETURN_NEXT(funcctx, ((Datum *) funcctx->user_fctx)[call_cntr]);

In those cases where I don't have a value to return, how do I express
that? As in, if I have the array [ NULL, 1.5, 2.5, NULL ]?



Re: Returning NULL from SRF

От
Magnus Persson
Дата:
RhodiumToad set me on the right track.

Apparently there is no macro defined for returning null in a SRF. The
suggestion was to copy the SRF_RETURN_NEXT macro, defining it to call
PG_RETURN_NULL() instead of PG_RETURN_DATUM(_result). Worked like a charm!