我試圖創建a PL/pgSQL function,它應該填充一個臨時表,然後從它返回所有行(稍後它將成爲一個連接),但我不知道哪個返回類型指定它:如何創建返回多行的PL/pgSQL函數
create or replace function pref_daily_misere() returns void as $BODY$
begin
create temporary table temp_best (id varchar not null) on commit drop;
insert into temp_best (id) select id from pref_money where
yw = to_char(current_timestamp - interval '1 week', 'IYYY-IW')
order by money desc limit 10;
select id from temp_best;
end;
$BODY$ language plpgsql;
上述工作的陳述自己的,但給我的錯誤
# select pref_daily_misere();
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT: PL/pgSQL function "pref_daily_misere" line 7 at SQL statement
當我嘗試調用它在我的PostgreSQL數據庫8.4.11。
這可能是因爲我錯誤地指定了返回上面的void,但我不知道使用哪種返回類型,而忽略返回類型是編譯錯誤。
是否有任何理由將上述內容隱藏起來?一個視圖(或CTE)似乎非常適合,恕我直言。 (可能除了醜陋的限制) – wildplasser
這不是一個完整的功能,我會在稍後添加更多的東西。 –