Returning NULL to a set returning C type function - Mailing list pgsql-general

From Bborie Park
Subject Returning NULL to a set returning C type function
Date
Msg-id 4DCACEFD.1050401@ucdavis.edu
Whole thread Raw
Responses Re: Returning NULL to a set returning C type function  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I have a C type function that returns a set of a type.  The problem I
have is that the underlying function may return NULL.  When the
underlying function returns NULL, I get the error message:

ERROR:  function returning set of rows cannot return null value

I'm wondering what is the proper way to correct this problem?  Or is
there are correct workaround?

So, for my sample code:

CREATE TYPE histogram AS (
    min double precision,
    max double precision,
    count integer,
    proportion double precision
);

CREATE OR REPLACE FUNCTION _st_histogram(rast raster, nband int,
hasnodata boolean, sample_percent double precision, bins int, width
double precision[], right boolean)
    RETURNS SETOF histogram
    AS '$libdir/rtpostgis-2.0','RASTER_histogram'
    LANGUAGE 'C' IMMUTABLE STRICT;

PG_FUNCTION_INFO_V1(RASTER_histogram);
Datum RASTER_histogram(PG_FUNCTION_ARGS)
{
    -- if any of the args are incorrect, return NULL
    PG_RETURN_NULL();
}

Thanks,
Bborie

--
Bborie Park
Programmer
Center for Vectorborne Diseases
UC Davis
530-752-8380
bkpark@ucdavis.edu

pgsql-general by date:

Previous
From: Oleg Bartunov
Date:
Subject: Re: full text search to_tsquery performance with ispell dictionary
Next
From: Michael Nolan
Date:
Subject: Re: Query to return every 1st Sat of a month between two dates