1

下面的代码在w_add_ax_extra(1, 'k', 'v')以前给出错误是w_add_ax_extra(some_id, kv.k, kv.v)我将其更改k, v为重现相同的错误

declare
  kv record;
begin
  -- Lines skipped
  for kv in select * from (select (each(extras)).*) as f(k,v) loop
    raise notice 'key=%,value=%',kv.k,kv.v;
    w_add_ax_extra(1, 'k', 'v');
  end loop;
  -- Lines Skipped
end

我收到语法错误,但不明白我缺少什么

ERROR:  syntax error at or near "w_add_ax_extra"
LINE 1: w_add_ax_extra(1, 'k', 'v')

但是,如果我这样做的dummy = w_add_ax_extra(1, 'k', 'v')话。是的,这个函数返回一个整数。但我不需要将它存储在这里。是否必须保留返回值?

4

1 回答 1

7

来自精美手册

39.5.2。执行没有结果的命令

[...]

有时对表达式或 SELECT 查询求值但丢弃结果很有用,例如在调用具有副作用但没有有用结果值的函数时。要在 PL/pgSQL 中执行此操作,请使用 PERFORM 语句:

PERFORM query;

强调我的。你不是通过说类似的话来调用函数f();,你需要perform f();或者select f() into ...;

for kv in select * from (select (each(extras)).*) as f(k,v) loop
    raise notice 'key=%,value=%',kv.k,kv.v;
    perform w_add_ax_extra(1, 'k', 'v');
end loop;
于 2012-04-09T04:30:42.927 回答