I come from SQL Server to PostgreSQL (9.0), so I am having a issue in a stored procedure / function when executing it. The function is returning this error message:
SQLSTATE: 42601;
SQLERRM: query has no destination for result data
What I need to do pass the values from columns selected by the SELECT
query along with the OUT
parameters into the result and avoid getting that error message?
CREATE OR REPLACE FUNCTION myplfunction(
IN i_param1 character varying,
IN i_param2 character varying,
IN i_param3 character varying,
IN i_param4 character varying,
OUT o_call_status integer,
OUT o_call_message character varying)
RETURNS record AS
$BODY$
DECLARE
val1 varchar;
val2 varchar;
...
IF (v_solution_id IS NULL) THEN
val1 := column1 FROM tbl2 WHERE column2= i_param1;
IF(val1 IS NULL) THEN
o_call_status := 1005;
o_call_message := column1 is not configured or invalid';
RETURN;
END IF;
SELECT 'mycolumnname1' as paramName,mycolumn1 as value FROM tb1 WHERE column1 = val
UNION ALL
SELECT 'mycolumnname2' as paramName,,mycolumn2 as value FROM tb1 WHERE column1 = val
UNION ALL
SELECT 'mycolumnname2' as paramName,,mycolumn2 as value FROM tb2 WHERE column2 = val2
WHERE tb2paramName4=i_val3;
o_call_status := 0;
o_call_message := '';
EXCEPTION WHEN OTHERS THEN
o_call_message := SQLERRM;
o_call_status := SQLSTATE;
END;
$BODY$
LANGUAGE plpgsql VOLATILE