簡體   English   中英

等效於與 SQL 服務器中的 output 子句合並到 Postgresql

[英]Equivalent for Merge with output clause in SQL Server to Postgresql

我想將基於以下代碼的值插入到 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... select 要查看插入的行,請使用returning子句

insert into atb (...)
select ... columns ...
from some_table
  join other_table on ...
returning *

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM