How would I return the return value of a function from within a function (eg. foo()
calls bar()
)?
create or replace function bar ()
returns text
as $$
begin
select md5(random()::text);
end
$$ language 'plpgsql';
create or replace function foo ()
returns text
as $$
begin
return select bar ();
end
$$ language 'plpgsql';
I keep getting errors like query has no destination for result data
You need to provide something to accept the output of the query:
CREATE OR REPLACE FUNCTION public.bar()
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
md5_val text;
begin
select into md5_val md5(random()::text);
return md5_val;
end
$function$
;
create or replace function foo ()
returns text
as $$
declare
md5_val2 text;
begin
select into md5_val2 bar();
return md5_val2;
end
$$ language 'plpgsql';
select * from foo();
foo
----------------------------------
ac6a4910fac3472d226dc54bb147336e
See:
https://www.postgresql.org/docs/current/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments