RETURNING clause mistakenly added to CREATE and ALTER table statements #2119
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When trying to create or alter a table that includes a foreign key constraint and an
ON DELETE
orON UPDATE
clause, the parser incorrectly marks theCommandType
asDELETE
orUPDATE
, respectively. Combined with areturningColumns
of{"*"}
(which is the default when just passing in theautoGeneratedKeys
flag toexecute
inPgStatement
) this causes aRETURNING
clause to be added where it is invalid.This PR adds four test cases showing the issue.
This PR also adds two new
CommandType
values forCREATE
andALTER
to detect this scenario and prevent theRETURNING
clause from being added. This is my first PR to this project and while the tests are passing, there may be a better implementation. I defer to the more seasoned contributors.I want to add that while using
executeUpdate
would solve this issue handily, it is unfortunately not exposed by the application framework. They simply usepublic boolean execute(String sql, int autoGeneratedKeys)
and trust this JDBC driver to handle it. I am also working on that project to be more correct in their implementation as well. I think this feature will be a benefit to all regardless of any change in downstream frameworks.Thank you for your time!
All Submissions:
New Feature Submissions:
./gradlew autostyleCheck checkstyleAll
pass ?Changes to Existing Features: