Skip to content

How to convert postgres query with returning clause into linq2db? #3545

Closed Answered by viceroypenguin
ademchenko asked this question in Q&A
Discussion options

You must be logged in to vote

You are looking in the right spot. In this case, you want UpdateWithOutput(), and the data you want is in the inserted record (so inserted.balance).

There is a bit of a misnomer when dealing with update/returning, which makes sense when you understand how the db engine handles update, but it is not intuitively obvious. Technically, (internally) an update is not a single operation, but actually both a delete and an insert. It is done atomically, but when processing rows, the db engine removes the old row and inserts a new row. This means that an update has both deleted and inserted output tables, which are used to reference and output the data that is removed and the data that is inserted.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ademchenko
Comment options

Answer selected by ademchenko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants