Operation precedence on postgress

Posted by user24691 on Stack Overflow See other posts from Stack Overflow or by user24691
Published on 2013-07-01T17:02:14Z Indexed on 2013/07/01 17:05 UTC
Read the original article Hit count: 134

Filed under:
|

I have set new division on postgress pg_operator table because i want tath when is division by zero return 0.

i have write this:

create operator / ( procedure = zero_division, leftarg = double precision, rightarg = double precision);

where zero_division is:

CREATE OR REPLACE FUNCTION zero_division(double precision, double precision)
RETURNS double precision AS
'select case when $2 = 0 then 0 else $1 / $2::real end;'
LANGUAGE sql IMMUTABLE
COST 100;

when i run value/ 0 i get error of division.

© Stack Overflow or respective owner

Related posts about postgresql-9.1

Related posts about precedence