如何 "PERFORM" 返回多个 rows/columns 的 CTE 查询?

How to "PERFORM" a CTE query returning multiple rows/columns?

作为这个问题的后续:

我试试:

perform (with test_as_cte as(select * from myTable) select * from test_as_cte);

但是得到如下错误:

SQL Error [42601]: ERROR: subquery must return only one column
Where: PL/pgSQL function inline_code_block line 9 at PERFORM

如果我在上面的代码中用 myCol 替换 * 就没有错误。

但是,我需要使用 CTE 和 return 多列进行实际性能测试。

括号中的 WITH 查询被视为 sub-select。只要它 returns 一个 单个值 (一行的一列),它就可以正常工作。否则您必须将其视为子查询并像这样调用它(在 PL/pgSQL 代码块内!):

PERFORM * FROM (with test_as_cte as (select * from b2) select * from test_as_cte t) sub;

或者只是:

PERFORM FROM (<any SELECT query>) sub;

The manual:

PERFORM query;

This executes query and discards the result. Write the query the same way you would write an SQL SELECT command, but replace the initial keyword SELECT with PERFORM. For WITH queries, use PERFORM and then place the query in parentheses. (In this case, the query can only return one row.)

我认为这可能更清楚。我会建议对文档进行修复。