How to return the value of function 2 from within function 1

francistheturd

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

Adrian Klaver

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to get value return from a function within a loop?

How to return a value within a function with an event listener?

How to return the value given by the gps within a function

How to return value from this function?

How to return a value from a function

How to return a value from a function, which is generated inside a callback function within?

How to retrieve value from within nested function

How to return a function within a function and display it in return

How to return a value from a function if no value is found

Getting return value from function within get request

How to replace/modify something in a call to function 1 from within function 2 (both in their separate files)

How do I pass a return value to another function and assign the return value to a variable within that function?

How can I return a value within a nested function?

Swift: How do I return a value within an asynchronous urlsession function?

How to correctly return value from function?

How to return a value from a function in Java?

How do I return value from this function

How to return by value from native function?

How to return a value from a function of type `LPCTSTR`?

How to return value from function to main thread?

How to return custom value from function call?

How to get a return value from a connect function

How to return value from a function in gwidgets

How to capture return value from function in vim?

React, how to return a value from function to component?

How to return the value resolved from promise in function?

How to return value from debounced function in javascript?

How to return a value from an EventEmitter function?

How to return a value from a stored procedure (not function)?