我想将以下循环的结果存储在表中:
DO $$
DECLARE rec RECORD;
BEGIN
FOR rec IN SELECT c1 FROM t1
LOOP
SELECT foo(rec.c1);
END LOOP;
END; $$
LANGUAGE 'plpgsql';
我该怎么做?
答案 0 :(得分:1)
根本不需要循环。事实上,你甚至不需要一个功能:
insert into some_table (some_column)
select foo(c1)
from t1
或者,如果您想根据查询创建表格:
create table_some
as
select foo(c1) as some_column
from t1;