I have two PostgreSQL functions. One returns a set of data, including an email address and some details about the search, to a type called email_me. Another accepts the set of data from the first one and processes it through a notification system, which sends an email out with the text and details of the first one, to the email address provided by the first one.
Right now I’m testing the two functions by copy / pasting (actually exporting, formatting with single-quotes, and pasting) the result set of the first function as the arguments for the second.
My question is, how may I evoke the second function from the first, passing the values from the first into the second?
I think this suffices as the pertinent part of the function, which constructs the different element of an email, including the email address, subject, message body, and then goes on to create a list of CC’s.
-- BUILD EMAIL ELEMENTS into l_email
--we always want to know the primary_contact_email -we use it in the message body
SELECT email_address INTO l_primary_contact_email FROM users WHERE user_id = l_primary_contact_id;
l_email.email_address := l_primary_contact_email;
l_email.subject := 'Work Order: '||l_work_order_id||' '||l_work_order_name||' has been completed.';
l_email.message_body := 'Work Order: '||l_work_order_id||' , has been completed. Please verify and set to closed: ' || l_jobs_url || '/jobs?workOrderId='||l_work_order_id || '\r\n\r\n Details: \r\n\r\n' || l_asset_list;
------------------------------------------------------
SELECT automatortalk(l_email);
RETURN l_email;
Any help is greatly appreciated.
That’s possible for any combination of data types you can imagine.
Post your (simplified) functions here, and we will correct what’s not working.
This message means what it says:
The
RETURNstatement must be missing towards the end of your function. Check all involved functions! Now, if you already call the second function from within the first, there is no need to returnl_emailfrom the first, I assume? change theRETURNSclause for your function and only return what is needed.So your solution could look like this:
Read about OUT parameters here.