【发布时间】:2014-04-01 19:31:16
【问题描述】:
我正在尝试了解 PL/pgSQL 函数中 select 语句的查询计划,但我不断收到错误消息。我的问题:如何获取查询计划?
以下是重现问题的简单案例。
有问题的表名为 test_table。
CREATE TABLE test_table
(
name character varying,
id integer
);
函数如下:
DROP FUNCTION IF EXISTS test_function_1(INTEGER);
CREATE OR REPLACE FUNCTION test_function_1(inId INTEGER)
RETURNS TABLE(outName varchar)
AS
$$
BEGIN
-- is there a way to get the explain analyze output?
explain analyze select t.name from test_table t where t.id = inId;
-- return query select t.name from test_table t where t.id = inId;
END;
$$ LANGUAGE plpgsql;
当我跑步时
select * from test_function_1(10);
我得到错误:
ERROR: query has no destination for result data
CONTEXT: PL/pgSQL function test_function_1(integer) line 3 at SQL statement
如果我取消注释注释部分并注释掉解释分析,该函数可以正常工作。
【问题讨论】:
标签: sql postgresql plpgsql explain