-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting computed value after insert/update/delete. #181
Comments
@richardpauljones, Sorry it's taken so long to get back to you on this. Can you help me understand what values are being returned in these cases? I am trying to work out whether there is similar function in the existing plugins. |
So the normal behaviour of SQL server for an insert/update/delete is just to return the number of rows affected. This is different in PostgreSQL, where the default behaviour is to return the record you have just inserted/updated/deleted. To get the same behaviour you need to added the OUTPUT statement as I have shown in my examples above. I found this issue while trying to run the PostgreSQL test project against my experimental ODBC database driver. The test that breaks is func testInsertID() { |
I believe the default behavior in PostgreSQL is to just return the number of rows affected. In the case where you are doing an insert and have the If the positioning of the If the positioning is important then it becomes a little more difficult. You could either patch the clause into the built query or perhaps implement a build method that accepts the query instance and generates the desired output. |
Thanks for that. Yes the positioning of the Output statement is important. |
@richardpauljones Do you require any further assistance on this issue? |
I am going to mark this issue as closed. If you require anything further please reopen. |
SQL Server seems to have the following Syntax for returning the computed values after an insert.
INSERT INTO “tableInsertOSX” (“a”, “b”)
OUTPUT INSERTED.a,INSERTED.b <-------- need this to return values from an insert.
VALUES (‘apricot’, ‘3’)
Suggest adding a new property to kquery.insert .prevalues
UPDATE "tableInsert2OSX"
set b='3'
OUTPUT INSERTED.b <----- need this to return values from update.
WHERE a = 'apricot'
Suggest adding a new property to kquery.update .prewhere
DELETE FROM "tableUpdateOSX"
OUTPUT DELETED.b <----- need this to return valued from a a delete
WHERE "tableUpdateOSX"."b" = '2'
Suggest adding a new property to kquery.delete .prewhere
This should follow the same sort of structure as suffix.
The text was updated successfully, but these errors were encountered: