简体   繁体   中英

Equivalent for Merge with output clause in SQL Server to Postgresql

I want to insert values based on below code to a temporary table in 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;

Just to mention, how can I correlate values into temporary table

I don't understand the use of MERGE to begin with.

This seems like a straightforward insert... select . To see the inserted rows, use the returning clause

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM