Here is a simplified version of a function I have:
CREATE OR REPLACE FUNCTION my_funct(user_id integer)
RETURNS integer AS
$BODY$
DECLARE
my_var integer;
BEGIN
//....................
if not exists (select * from table1) then
return 0;
end if;
my_var := (SELECT COUNT(*) FROM table2
inner join ..............
);
RETURN (select field1 from table3) - my_var;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION my_funct(integer)
OWNER TO postgres;
But I call from Play framework, I get the error:
[PSQLException: ERROR: query has no destination for result data
Hint: If you want to discard the results of a SELECT, use PERFORM instead.
Where: PL/pgSQL function my_funct(integer) at SQL statement]
UPDATE:
------------------------------------------------
if not exists (select * from table1) then
select try_to_update_table1(user_id); -- probably the cause. only updates the table1
end if;
if not exists (select * from table1) then
return 0;
end if;
------------------------------------------------