Database Reference
In-Depth Information
hannu(# then null
hannu(# else coalesce(a,0) +
coalesce(b,0)
hannu(# end)
hannu-# FROM (select 1::int as a, null::int as
b)s;
-[ RECORD 1 ]
case | 1
In addition to restructuring the code, we also introduced two new macros
PG_ARGISNULL(<argnr>) for checking if argument <argnr> is NULL and
PG_RETURN_NULL() for returning NULL from a function.
Note
PG_RETURN_NULL() is different from PG_RETURN_VOID() . The latter is for us-
ing in functions which are declared to return pseudo-type void or in other words
not to return anything.
Working with any number of arguments
After the rewrite to handle NULL values it seems that with just a little more effort, we
could make it work with any number of arguments. Just move the following code in-
side the for(;;) cycle over the arguments and we are done:
if (!PG_ARGISNULL(<N>)) {
sum += PG_GETARG_INT32(<N>);
not_null = 1;
}
Actually, making the code use an array instead of simple type is not that simple
after all, and to make things more difficult there is no information or sample code
on how to work with arrays in official PostgreSQL manual for C-language extension
functions. The line between "supported" and "unsupported" when writing C-language
Search WWH ::




Custom Search