将返回值传递给 PostgreSQL 中的另一个函数
我有两个 PostgreSQL 函数。将一组数据返回到名为 email_me 的类型,其中包括电子邮件地址和有关搜索的一些详细信息。另一个接受来自第一个数据集的数据,并通过通知系统对其进行处理,该通知系统将包含第一个数据的文本和详细信息的电子邮件发送到第一个数据提供的电子邮件地址。
现在,我正在通过复制/粘贴(实际上是导出、用单引号格式化并粘贴)第一个函数的结果集作为第二个函数的参数来测试这两个函数。
我的问题是,如何从第一个函数调用第二个函数,将第一个函数的值传递到第二个函数?
我认为这足以作为函数的相关部分,它构造电子邮件的不同元素,包括电子邮件地址、主题、消息正文,然后继续创建抄送列表。
-- 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;
非常感谢任何帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对于您能想象到的数据类型的任意组合都是可能的。
在这里发布您的(简化的)函数,我们将纠正不起作用的部分。
此消息的含义如下:
函数末尾处必须缺少
RETURN
语句。检查所有涉及的功能!现在,如果您已经从第一个函数中调用了第二个函数,那么我认为不需要从第一个函数返回l_email
?更改函数的 RETURNS 子句并仅返回所需的内容。因此,您的解决方案可能如下所示:
阅读有关 OUT 参数 这里。
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
RETURN
statement 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_email
from the first, I assume? change theRETURNS
clause for your function and only return what is needed.So your solution could look like this:
Read about OUT parameters here.