Perl+Postgresql:如果存在 RAISE NOTICE,函数不会返回值
我注意到,当我使用 DBI 从 Perl 脚本调用 PL/PgSQL 或 PL/Perl 函数时,如果函数中使用了 RAISE NOTICE 或 elog(NOTICE),它不会返回值。 举例说明:
一个简单的表:
CREATE TABLE "public"."table1" (
"fld" INTEGER
) WITHOUT OIDS;
一个简单的函数:
CREATE OR REPLACE FUNCTION "public"."function1" () RETURNS integer AS
$body$
DECLARE
myvar INTEGER;
BEGIN
SELECT INTO myvar fld FROM table1 LIMIT 1;
RETURN myvar;
END;
$body$
LANGUAGE 'plpgsql'
一段 Perl 脚本:
use DBI;
...
my $ref = $dbh->selectcol_arrayref('SELECT function1()');
print $$ref[0];
按原样,它打印表中的值。
但是,如果我按如下方式添加“RAISE NOTICE”,则不会得到任何结果:
SELECT INTO myvar fld FROM table1 LIMIT 1;
RAISE NOTICE 'Testing';
RETURN myvar;
我是否遗漏了某些内容或此类行为是设计使然?
I noticed that when I call a PL/PgSQL or PL/Perl function from a Perl script using DBI, it does not return a value if a RAISE NOTICE or elog(NOTICE) is used in the function. To illustrate:
A simple table:
CREATE TABLE "public"."table1" (
"fld" INTEGER
) WITHOUT OIDS;
A simple function:
CREATE OR REPLACE FUNCTION "public"."function1" () RETURNS integer AS
$body$
DECLARE
myvar INTEGER;
BEGIN
SELECT INTO myvar fld FROM table1 LIMIT 1;
RETURN myvar;
END;
$body$
LANGUAGE 'plpgsql'
A piece of Perl script:
use DBI;
...
my $ref = $dbh->selectcol_arrayref('SELECT function1()');
print $ref[0];
As it is, it prints the value from the table.
But I get no result if I add RAISE NOTICE as follows:
SELECT INTO myvar fld FROM table1 LIMIT 1;
RAISE NOTICE 'Testing';
RETURN myvar;
Am I missing something or such behavior is by design?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查
client_min_messages数据库服务器的 postgresql.conf 文件中的
设置。 来自 PostgreSQL 8.3 文档:Check the
client_min_messages
setting in your database server'spostgresql.conf
file. From the PostgreSQL 8.3 docs:我无法使用 Debian 的 Perl 5.10、DBI 1.605 和 DBD::Pg 2.8.7 与 PostgreSQL 8.3.7 重现这一点。 我按照预期打印了通知。
我建议将您的问题隔离到一个小脚本(如上),并使用设置相当高的 DBI_TRACE 来运行它,看看您看到了什么差异。 也许还可以查看 DBD::Pg 的发行说明,看看他们是否提到它,也许过去曾被这些所困惑。 使用
DBI_TRACE=10
我看到了这一点:所以你应该在自己的输出中寻找类似的东西。
I can't reproduce this, using Debian's Perl 5.10, DBI 1.605 and DBD::Pg 2.8.7 against PostgreSQL 8.3.7. I get the notice printed out as expected.
I suggest isolating your problem to a small script (like above) and running it with
DBI_TRACE
set fairly high any seeing what differences you see. Maybe also looking at the release notes for DBD::Pg and seeing if they mention it maybe having been confused by these in the past. WithDBI_TRACE=10
I see this:So you should be looking for something like that in your own output.