Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 671 Bytes

NOTES.md

File metadata and controls

23 lines (18 loc) · 671 Bytes

"returning" in update queries

Postgres' returning keyword is an extension to the SQL standard not supported everywhere. EntityFramework uses a temporary table to store the written rows to, and then references it in a join afterwards:

DECLARE @generated_keys table
                        (
                            [Id] uniqueidentifier
                        )

INSERT INTO Customers(FirstName)
OUTPUT inserted.CustomerID INTO @generated_keys
VALUES ('bob');

SELECT t.[CustomerID]
FROM @generated_keys AS g
         JOIN dbo.Customers AS t
              ON g.Id = t.CustomerID
WHERE @@ROWCOUNT > 0