【发布时间】:2020-07-26 22:06:32
【问题描述】:
我想将基于以下代码的值插入到 postgresql 中的临时表中
declare @output table (AuditScratchID bigint, AuditID bigint);
merge table atb
using (select
s.ID
....
....
....
from @temporaryTableVariable s
inner join ....
...............
..............
) as s
on 1 = 2 -- Impossible Condition so they never match
when not matched then
insert (.....)
values (.....)
output s.ID, inserted.ID
into @output;
顺便提一下,我如何将值关联到临时表中
【问题讨论】:
-
我不明白如果你强迫它永远不匹配,那 MERGE 应该做什么?最后不就是一个简单的
insert into ... select from temp_table吗? -
是的,操作员甚至在评论
on 1 = 2 -- Impossible Condition so they never match -
@Andronicus:问题是:为什么?为什么这在 SQL Server 中是必需的,而不是简单的
insert into .. select from ...? -
我正在从 SQL Server 迁移到 PostgreSQL。客户编写了这样的代码,因此我想知道如何在 PostgreSQL 中处理输出子句和插入记录
标签: sql postgresql merge common-table-expression temp-tables