but I cant manage to call it.
CREATE or replace FUNCTION wyplaty_dla_prac_o_email (threshold_value integer,email_of text)
RETURNS TABLE(f1 int,f2 timestamp)
AS
$$
begin
select amount, payment_date from payment p join customer c on p.customer_id=c.customer_id
where amount > 1ドル and email =2ドル;
end;
$$
LANGUAGE plpgsql;
and when I call it
select * from wyplaty_dla_prac_o_email(6,'[email protected]')
it says that ERROR: It was not indicated where the query results should be saved
1 Answer 1
You're missing a return statement. Your function is executing a query but not doing anything with the result, which is producing the error.
You need to return the results of your query like so:
CREATE or replace FUNCTION wyplaty_dla_prac_o_email (threshold_value integer,email_of text)
RETURNS TABLE(f1 int,f2 timestamp)
AS $$ begin
return query
select amount, payment_date from payment p join
customer c on p.customer_id=c.customer_id
where amount > 1ドル and email =2ドル;
end; $$
LANGUAGE plpgsql;
Alternatively you could just specify the function in SQL instead of using plpgsql if it's just a wrapper around a query and save yourself the overhead.
answered Aug 12, 2021 at 19:26
Johannes H.
6,1671 gold badge23 silver badges44 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Johannes H.
I did say that in the last paragraph as well. But yes, that's correct.
lang-sql