Tuesday, May 16, 2023

Dividing Number Return ZERO Postgres

 If you are also facing same issue, here is solution


EARLIER

select (15/20)
 
Output

0

NOW

use this command to get correct output in postgres

select (15/20::float)::numeric(5,2)

Output 

0.75 

 

you can Also  create function in database

CREATE OR REPLACE FUNCTION dvdrental1(part int, fullv int) RETURNS float AS $$
BEGIN
  RAISE NOTICE 'PROGRESS IN PERCENT : %', (part/fullv::float)::numeric(5,2);
  RETURN part/fullv::float;
END;
$$  LANGUAGE plpgsql VOLATILE
  COST 100;

No comments:

Post a Comment

web stats