How to return a value from a function if no value is found
问题 I'm attempting to return 0.0 if the following function does not return anything: CREATE OR REPLACE FUNCTION get_height(firstn VARCHAR, lastn VARCHAR) RETURNS FLOAT AS $$ DECLARE height FLOAT = 0.0; BEGIN SELECT into height AVG(((p.h_feet * 12) + p.h_inches) * 2.54) FROM player p WHERE p.firstname = firstn AND p.lastname = lastn; RETURN height; END; $$ LANGUAGE plpgsql; I've tried searching for it and found that COALESCE does not work. Does anyone have any ideas how to solve this? Table