I am trying to create a postgres function that just returns the friends that a user has in the database. It should just return the first and last names of all the user's friends. However, I keep getting this error:
[42601] ERROR: query has no destination for result data
It does not make sense to me because I am returning a table with all the first and last names.
Here is my function. Does anyone know why this would be the case? I could not find the answer anywhere else.
create or replace function getFriends(pEmail text)
returns TABLE(pkUser int, FirstName text, LastName text)
language plpgsql
as
$$
declare pk int;
begin
select "pkUser" into pk from users where "Email"=pEmail;
select
"pkUser", "FirstName", "LastName"
from users u
inner join friends f on u."pkUser" = f."User2ID"
where f."User1ID"=pk;
select "pkUser", "FirstName", u."LastName"
from users u
inner join friends f on u."pkUser" = (f."User1ID")
where f."User2ID"=pk;
end
$$;