将返回值传递给 PostgreSQL 中的另一个函数

发布于 2024-12-10 13:06:36 字数 1079 浏览 1 评论 0原文

我有两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十秒萌定你 2024-12-17 13:06:36

这对于您能想象到的数据类型的任意组合都是可能的。
在这里发布您的(简化的)函数,我们将纠正不起作用的部分。

此消息的含义如下:

ERROR: control reached end of function without RETURN

函数末尾处必须缺少 RETURN 语句。检查所有涉及的功能!现在,如果您已经从第一个函数中调用了第二个函数,那么我认为不需要从第一个函数返回 l_email ?更改函数的 RETURNS 子句并仅返回所需的内容。

因此,您的解决方案可能如下所示:

CREATE OR REPLACE FUNCTION f1()
  RETURNS void AS
$BODY$
BEGIN

-- do stuff

PERFORM f2(l_email);

-- as you return void, RETURN statement is not needed.
-- Else you would have to use it - or use OUT parameters.

END;
$BODY$
  LANGUAGE plpgsql VOLATILE;

阅读有关 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:

ERROR: control reached end of function without RETURN

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 return l_email from the first, I assume? change the RETURNS clause for your function and only return what is needed.

So your solution could look like this:

CREATE OR REPLACE FUNCTION f1()
  RETURNS void AS
$BODY$
BEGIN

-- do stuff

PERFORM f2(l_email);

-- as you return void, RETURN statement is not needed.
-- Else you would have to use it - or use OUT parameters.

END;
$BODY$
  LANGUAGE plpgsql VOLATILE;

Read about OUT parameters here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文