Database Reference
In-Depth Information
Datum
add_ab_null(PG_FUNCTION_ARGS)
{
int32 not_null = 0;
int32 sum = 0;
if (!PG_ARGISNULL(0)) {
sum += PG_GETARG_INT32(0);
not_null = 1;
}
if (!PG_ARGISNULL(1)) {
sum += PG_GETARG_INT32(1);
not_null = 1;
}
if (not_null) {
PG_RETURN_INT32(sum);
}
PG_RETURN_NULL();
}
This indeed does what we need: hannu=# CREATE FUNCTION add(int, int)
RETURNS int
AS '$libdir/add_func', 'add_ab_null'
LANGUAGE C;
CREATE FUNCTION
hannu=# SELECT add(NULL, NULL) as must_be_null,
add(NULL, 1) as must_be_one;
-[ RECORD 1 ]+--
must_be_null |
must_be_one | 1
Achieving the same result using standard PostgreSQL statements, functions, and
operators would be much more verbose: hannu=# SELECT (case when (a is
null) and (b is null)
Search WWH ::




Custom Search