I've created functions and one of them is:
CREATE OR REPLACE FUNCTION core.cal_status(
er_v DOUBLE PRECISION,
cell_v DOUBLE PRECISION
) RETURNS DOUBLE PRECISION
LANGUAGE plpgsql
AS $$
DECLARE out DOUBLE PRECISION;
BEGIN
IF er_v < 15 THEN out := 'LOW_LOAD';
ELSEIF cell_v < 60 THEN out := 'LOW_LOAD';
ELSEIF er_v > 40 THEN out := 'CONGESTED';
ELSEIF cell_v > 80 THEN out := 'CONGESTED';
ELSEIF cell_v >60 and cell_v < 80 THEN out := 'HIGH_LOAD';
END IF;
RETURN out;
END;
$$;
When I call functions with this:
LEFT JOIN LATERAL core.cal_status(
er_v,
cell_v) status ON true
I got next error:
ERROR: invalid input syntax for type double precision: "LOW_LOAD" Where: PL/pgSQL function core.cal_status(double precision,double precision) line 4 at assignment
What is this about, I guess it's something with output type, but not sure.
RETURNS DOUBLE PRECISION
means you need a double value afterout :=
;). – shA.ttext
. The error is not surprising or misleading. – Gordon Linoff