> Date: Fri, 17 Jan 2003 15:09:32 +0900
> From: Jean-Christian Imbeault <jc@mega-bucks.co.jp>
>
> I wrote the following plpgsql function. The problem I have is that if no
> rows are found my function returns NULL whereas it should be returning 0.
>
> IF NOT FOUND THEN
> RETURN 0;
> END IF;
> RETURN total_sales;
>
I am not sure how close PL/pgSQL is to the "Persistent Stored Modules" (PSM)
of the SQL3 standard. If it is quite close it has inherited an insane feature
of PSM: "return" does *not* end the function, but only sets the return value.
Check whether the following code works:
IF NOT FOUND THEN
RETURN 0;
ELSE
RETURN total_sales;
END IF;
Christoph Dalitz