Repository navigation
feat(grammar): parse the alias and USING of DELETE and resolve UPDATE and DELETE aliases - #1135
Open
psteinroe wants to merge 1 commit into
Conversation
… and DELETE aliases DELETE now takes an alias, USING, WHERE CURRENT OF and is a partial rule with an end, so it parses while it's typed. The table alias query finds the aliases of UPDATE and DELETE targets, so completions after `u.` offer the target's columns.
This branch has not been deployed
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.
Stacked on #1134.
The alias of an UPDATE or DELETE target wasn't known to completions, so
update users u ... where u.|andreturning u.|offered nothing. UPDATE already parsed the alias; DELETE didn't parse one at all, norUSING.What changed
DELETE FROM [ONLY] t [*] [[AS] alias] [USING ...] [WHERE ... | WHERE CURRENT OF c] [RETURNING ...].USINGis a newdelete_usingnode and takes the same relations and joins asUPDATE ... FROM. DELETE is now a partial rule and itsFROMends at the table, sodelete |offersfrom, and a keyword after the table counts as the start of the next clause, which makesdelete ... returning with (|offeroldandnewlike UPDATE in fix(completions): complete keywords right after an opening parenthesis #1134.update_targetand of the target in DELETE'sFROM. Aliases inUSINGare relations and were already found.Backwards compatibility
I parsed every statement that Postgres accepts in the 15–18 regression fixtures (127,028) with the grammar of #1134 and this one: none that parsed before has an error now, and 28 more parse.
Tests
completes_the_columns_of_update_and_delete_aliases: the columns afteru.in WHERE and RETURNING of UPDATE and DELETE, and after an alias inUSING. It fails without the change.finds_update_and_delete_target_aliasesfor the query.delete_alias_and_usinganddelete_where_current_of, andpartial-sqls/delete.sqlruns the typing-state test over DELETE. It fails on the base branch atdelete.delete from t returning with (|)joins the cases ofcompletes_options_after_opening_parenthesis.deleteis now a statement start keyword, so it shows up in the snapshots that list them, anddelete |offersfrominstead of nothing (suggests_tables_in_delete).cargo test -p pgls_treesitter_grammar -p pgls_treesitter -p pgls_completions -p pgls_hover -p pgls_semantic_tokens,cargo clippy --workspace --all-targets -- -D warnings.Not covered
ORDER BY,LIMITandOFFSET, which Postgres doesn't have, still parse as before.