PL/PGSQL beginning is hard....
От | Bruno Boettcher |
---|---|
Тема | PL/PGSQL beginning is hard.... |
Дата | |
Msg-id | 20001103005823.G14044@erm1.u-strasbg.fr обсуждение исходный текст |
Ответы |
Re: PL/PGSQL beginning is hard....
|
Список | pgsql-sql |
hello, i am a beginner at SQL and PL/pgsql.... and thus have some surely already known problems... i have set up some tables, and wanted to play around with inbuild functions, and set up the following function: CREATE FUNCTION balance (int4) RETURNS int4 AS ' DECLARE compte ALIAS FOR $1; actplus accounts.num%TYPE; actminus accounts.num%TYPE; actres accounts.num%TYPE; BEGIN SELECT SUM(amount) INTO actplus FROM journalWHERE plus=compte; select sum(amount) INTO actminus from journal where minus=compte; actres := actplus -actminus; RETURN actres; END; ' LANGUAGE 'plpgsql'; Now this works fine, until it hits one of the cases where either of the selects returns an empty result (meaning that no line conforming to the contraint could be found) in this case even if the other select returns a value, the whole function does return nothing.... what did i wrong, or what do i have to change, to assume the value 0 if no hit was found to the select? BTW i am wondering if the same thing could have been achieved with sole SQL, and if yes, how.... -- ciao bboett ============================================================== bboett@earthling.net http://inforezo.u-strasbg.fr/~bboett http://erm1.u-strasbg.fr/~bboett =============================================================== the total amount of intelligence on earth is constant. human population is growing....
В списке pgsql-sql по дате отправления: