I have a function that returns results to me, but the result is not what I expected and capturing the error message I get this:
query has no destination for result data
this is my code postgresql:
CREATE OR REPLACE FUNCTION teltonika_funelement(
raw character varying,
tipo integer)
RETURNS TABLE(id integer, nombre character varying, value1 character varying)
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE i INT=1;
y INT=1;
Len1 INT;
---------------------------------------------------------------------------
BEGIN
CREATE TEMP TABLE Elements(ID Integer, Nombre CHARACTER VARYING, Value2 CHARACTER VARYING);
IF Tipo=1 THEN
Len1 := LENGTH(Raw)/4;
WHILE i<=Len1
LOOP
INSERT INTO Elements
SELECT
hex_to_int(SUBSTRING(Raw FROM y FOR 2))
,NULL
,SUBSTRING(Raw FROM y+2 FOR 2);
y := y+4;
i := i+1;
END LOOP;
END IF;
---------------------------------------------------------------------------
---------------------------------------------------------------------------
IF Tipo = 2 THEN
Len1 := LENGTH(Raw)/6;
WHILE i<=Len1
LOOP
INSERT INTO Elements
SELECT
hex_to_int(SUBSTRING(Raw FROM y FOR 2))
,NULL
,SUBSTRING(Raw FROM y+2 FOR 4);
y := y+6;
i := i+1;
END LOOP;
END IF;
---------------------------------------------------------------------------
---------------------------------------------------------------------------
IF Tipo = 4 THEN
Len1 := LENGTH(Raw)/10;
WHILE i<=Len1
LOOP
INSERT INTO Elements
SELECT
hex_to_int(SUBSTRING(Raw FROM y FOR 2))
,NULL
,SUBSTRING(Raw FROM y+2 FOR 8);
y := y+10;
i := i+1;
END LOOP;
END IF;
---------------------------------------------------------------------------
---------------------------------------------------------------------------
---------------------------------------------------------------------------
IF Tipo = 8 THEN
Len1 := LENGTH(Raw)/18;
WHILE i<=Len1
LOOP
INSERT INTO Elements
SELECT
hex_to_int(SUBSTRING(Raw FROM y FOR 2))
,NULL
,SUBSTRING(Raw FROM y+2 FOR 16);
y := y+18;
i := i+1;
END LOOP;
END IF;
---------------------------------------------------------------------------
SELECT
E.ID
,PropertyName
,CASE
WHEN (TypeParser = 'INT' AND Active=1) THEN (hex_to_int(Value2):: VARCHAR)
WHEN (TypeParser = 'DECIMAL(18,1)/1000' AND Active=1) THEN ((hex_to_int(Value2)/1000)::VARCHAR)
ELSE
Value2
END Value1
FROM Elements E
LEFT JOIN Teltonika_Tbl_ElementsConf TE ON TE.PropertyID=E.ID;
END;
$BODY$;
ALTER FUNCTION public.teltonika_funelement(character varying, integer)
OWNER TO postgres;
this is the error message:
query has no destination for result data
I can not find the cause of the error I have tried changing the return like this:
RETURNS TEXT AS
How could I solve it, I really appreciate your help