[英]PL/PGSQL: Store the result of a loop in a table
I want to store the result of the following loop in a table: 我想将以下循环的结果存储在表中:
DO $$
DECLARE rec RECORD;
BEGIN
FOR rec IN SELECT c1 FROM t1
LOOP
SELECT foo(rec.c1);
END LOOP;
END; $$
LANGUAGE 'plpgsql';
How can I do that? 我怎样才能做到这一点?
You don't need a loop for that at all. 您根本不需要循环。 In fact you don't even need a function for that:
实际上,您甚至不需要此功能:
insert into some_table (some_column)
select foo(c1)
from t1
Or if you want to create the table based on the query: 或者,如果您要基于查询创建表:
create table_some
as
select foo(c1) as some_column
from t1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.