【问题标题】:Bulk insert in more than one column in PostgreSQL在 PostgreSQL 中的多列中批量插入
【发布时间】:2011-11-21 15:27:08
【问题描述】:

我有一个批量插入查询

insert into table1(shift) select value from table2 where transid='shiftid'

此查询将 table2 中的所有移位值插入到我的 table1 移位列中。

但是如果我想在 table1 的多列中插入记录,但我的选择查询将只返回一列,比如:

select value from table1 where transid in ('shiftid','gradeid','currencyid')

它将返回包含所有值的一列。但我想插入:

insert into table1(shift,grade,currency) ...........

任何人都可以为我填写....吗?希望你能理解我的要求。

【问题讨论】:

  • 我怀疑您混淆了 columnrow (除其他外)这两个术语。您应该在问题中包含两个表的表定义

标签: sql postgresql


【解决方案1】:

我不知道您的表是什么样的,但您只需要确保 INSERT 和 SELECT 中的列数匹配并且它们具有兼容的类型。所以是这样的:

insert into table1 (shift, grade, currency)
select shift_id, grade_id, currency_id
from table2
where transid in ('shiftid', 'gradeid', 'currencyid')

SELECT 中的列取决于table2 的样子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多