postgresql - 如何将集合返回函数的输出插入到表中

标签 postgresql function row plpgsql set-returning-functions

我有一个函数接受两个参数,从表中返回一些数据。想要将返回的行插入另一个函数中的临时表(具有与函数输出相同的结构)。

这样试过:

CREATE TEMP TABLE tmp1 (col1 int,  col2 int) ON COMMIT DROP;

WITH x as (select function_name(p1, p2))
    insert into tmp1 select * from x; 

函数RETURNS TABLE(val1 integer, val2 integer)

选择不起作用。

ERROR:  column "col1" is of type integer but expression is of type record
HINT:  You will need to rewrite or cast the expression.

我该怎么办?

最佳答案

这样呢?..

insert into tmp1 select * from function_name(p1, p2); 

关于postgresql - 如何将集合返回函数的输出插入到表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31045041/

相关文章:

ruby-on-rails - 在 rails 中将列类型更改为更长的字符串

C++ 应该重载函数还是 if 语句就足够了?

r - 使用 dplyr 和 add_row() 在每个组中添加行

php - Yii2 Form View 组件其他数据库

ruby-on-rails - "PG::UndefinedTable: ERROR: relation does not exist"具有正确的 Rails 命名和约定

ruby-on-rails - Heroku - ActiveRecord::ConnectionTimeoutError(无法在 5.000 秒内获得数据库连接(等待 5.000 秒))

c++ - E2321 声明未指定标签或标识符

javascript - 带参数的 Phaser 按钮处理函数

Swift:UIPickerview 选择行 ID/索引

r - 根据前一行值(在同一列中)选择特定行