'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
Solution 1:[1]
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 *
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | a_horse_with_no_name |
