函数的返回值 [英] Return Value of a Function

查看:85
本文介绍了函数的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从函数返回一行数据。我一直在寻找HTML

文档并且没有发现任何有价值的内容。如果我尝试返回一个类型为

RECORD的变量,我会收到以下错误:

注意:plpgsql:在第0行编译last_log期间出现错误

错误:fmgr_info:函数0:缓存查找失败


我可能还有其他几个错误的函数,所以我真正的问题

是, 我可以返回RECORD类型的值吗?

-

引用:56

警惕嫉妒公众自由。怀疑每个人都会接近那个宝石。不幸的是,没有任何东西可以保留它,但是下来 -

正确的力量。每当你放弃这种力量时,你就不可避免地被毁了。


--Patrick Henry


工作:1-336-372- 6812

电话:1-336-363-4719

电子邮件: te *** @ esc1.com


---------------------------(播出结束)---------------------------

提示8:解释分析是你的朋友

/>

I need to return a row of data from a function. I''ve been looking the the HTML
docs and have found nothing of value. If I try to return a variable of type
RECORD, I get the following error:
NOTICE: plpgsql: ERROR during compile of last_log near line 0
ERROR: fmgr_info: function 0: cache lookup failed

I may have several other things wrong with this function, so my real question
is, "Can I return a value of type RECORD?"
--
Quote: 56
"Guard with jealous attention the public liberty. Suspect every one who
approaches that jewel. Unfortunately, nothing will preserve it but down-
right force. Whenever you give up that force, you are inevitably ruined."

--Patrick Henry

Work: 1-336-372-6812
Cell: 1-336-363-4719
email: te***@esc1.com

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

推荐答案

2004年2月2日星期一14:36,Terry Lee Tucker写道:
On Monday 02 February 2004 14:36, Terry Lee Tucker wrote:

我可能还有其他几个这个函数有问题,所以我真正的问题是,我可以返回类型为RECORD的值吗?

I may have several other things wrong with this function, so my real
question is, "Can I return a value of type RECORD?"




是的,但是你可以它必须对它做任何事情(除非你从另一个函数中调用它是
)。


你可以返回一个SETOF myrowtype只包含一行 -

,这可能就是你所追求的。那么你可以这样做:


SELECT * FROM set_returning_function(1,''a'');


-

Richard Huxton

Archonet Ltd


--------------------- ------(广播结束)---------------------------

提示1:订阅和取消订阅命令转到 ma*******@postgresql.org



Yes, but you can''t necessarily do anything with it (unless you''re calling it
from another function).

You could return a SETOF myrowtype where the set contains only one row -
that''s probably what you''re after. Then you can do things like:

SELECT * FROM set_returning_function(1,''a'');

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org


Terry Lee Tucker< te *** @ esc1.com>写道:
Terry Lee Tucker <te***@esc1.com> writes:
我需要从函数返回一行数据。我一直在寻找HTML
文档,并没有发现任何有价值的内容。如果我尝试返回一个类型为
RECORD的变量,我会收到以下错误:
注意:plpgsql:在第0行编译last_log期间发生错误
错误:fmgr_info:函数0:缓存查找失败


你运行的Postgres版本是什么?我们曾经有过一些错误,

会允许无意义的错误消息出现在角落

的情况下。我不完全确定他们都已经走了。如果你在上面,那么
7.4。*我很想知道你做了什么。

我可能还有其他一些问题,所以这个功能,所以我真正的问题是,我可以返回RECORD类型的值吗?
I need to return a row of data from a function. I''ve been looking the the HTML
docs and have found nothing of value. If I try to return a variable of type
RECORD, I get the following error:
NOTICE: plpgsql: ERROR during compile of last_log near line 0
ERROR: fmgr_info: function 0: cache lookup failed
What Postgres version are you running? We used to have some bugs that
would allow unhelpful error messages like that to emerge in corner
cases. I''m not completely sure that they''re all gone. If you''re on
7.4.* I''d be interested to see exactly what you did.
I may have several other things wrong with this function, so my real question
is, "Can I return a value of type RECORD?"




如果你知道你在做什么。调用查询必须为记录指定一个

结构。


(乔,我找不到使用函数的自包含示例 - 在7.4文档中搜索后返回 -

记录。当然有一个?)


问候,tom lane

---------------------------(广播结束)------------- --------------

提示1:订阅和取消订阅命令转至 ma ******* @ postgresql.org



If you know what you''re doing. The calling query has to specify a
structure for the record.

(Joe, I couldn''t find a self-contained example using a function-returning-
record after a bit of searching in the 7.4 docs. Surely there is one?)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org


Richard Huxton< de*@archonet.com>写道:
Richard Huxton <de*@archonet.com> writes:
你可以返回一个SETOF myrowtype,其中集合只包含一行 -
这可能就是你所追求的。然后你可以做以下事情:
SELECT * FROM set_returning_function(1,''a'');
You could return a SETOF myrowtype where the set contains only one row -
that''s probably what you''re after. Then you can do things like: SELECT * FROM set_returning_function(1,''a'');




你很困惑SETOF回来了复合类型---实际上它们

是可以单独使用的正交特征。显然,这个领域的文件可以得到改善:-(


问候,汤姆小巷


---------------------------(广播结束)------------------ ---------

提示7:别忘了增加免费空间地图设置



You''re confusing SETOF with returning a composite type --- actually they
are orthogonal features that can be used separately. Obviously the docs
could stand to be improved in this area :-(

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don''t forget to increase your free space map settings


这篇关于函数的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆