Repository navigation
fix: parse PostgreSQL SELECT with more than one locking clause - #2927
Merged
manticore-projects merged 1 commit intoNov 14, 2026
Merged
manticore-projects merged 1 commit into
manticore-projects merged 1 commit into
Conversation
PostgreSQL accepts several locking clauses in one SELECT, such as FOR UPDATE OF t FOR SHARE OF u. After the first clause, PlainSelect now reads further FOR UPDATE, FOR SHARE, FOR NO KEY UPDATE and FOR KEY SHARE clauses, each with its optional OF list, WAIT, NOWAIT or SKIP LOCKED, into Select.getAdditionalForUpdateClauses(). The first clause keeps its existing getters. toString, the deparser and the validator handle the additional clauses. Fixes JSQLParser#2926 Signed-off-by: Dylan Merigaud <dylanmerigaud@gmail.com>
Contributor
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2926.
PostgreSQL accepts several locking clauses in one
SELECT, so each table can get its own lock strength, for exampleFOR UPDATE OF t FOR SHARE OF u.PlainSelect()read oneFOR ...clause, so the issue's query stopped at the secondFOR.What changes:
AdditionalForUpdateClause(). After the first locking clause,PlainSelect()now reads any number of further clauses, each oneFOR UPDATE,FOR SHARE,FOR NO KEY UPDATEorFOR KEY SHARE, with an optionalOFtable list,WAIT n,NOWAITorSKIP LOCKED. Each becomes aForUpdateClause.FOR READ ONLYandFOR FETCH ONLYare not accepted as a second clause.SelectgetsgetAdditionalForUpdateClauses(),setAdditionalForUpdateClauses()andaddAdditionalForUpdateClause(). The first clause stays where it was:getForMode(),getForUpdateTables(),getWait(),isNoWait(),isSkipLocked()andgetForUpdate()still describe only the first one, and the new list isnullwhen there is a single clause, so a query that parsed before builds the same object.Select.appendTo()andSelectDeParserprint the additional clauses right after the first one.SelectValidatorchecks the mode, theOFtables,WAIT,NOWAITandSKIP LOCKEDof each additional clause with the same features it uses for the first one.Tests:
ForUpdateTest.testPostgresMultipleLockingClausesIssue2926: the issue's query parses and round trips; the first clause isUPDATE OF t, the additional one isSHARE OF u.ForUpdateTest.testPostgresMultipleLockingClausesWithOptions: four clauses mixing the four modes, anOFlist of two tables, a clause withoutOF,NOWAITandSKIP LOCKED.ForUpdateTest.testSingleLockingClauseHasNoAdditionalClauses: one clause leaves the listnull.SelectValidatorTest.testValidationMultipleLockingClauses: the issue's form validates for PostgreSQL, and a secondFOR NO KEY UPDATEis reported asselectForNoKeyUpdatefor Oracle.