Skip to content

feat(grammar): parse the alias and USING of DELETE and resolve UPDATE and DELETE aliases - #1135

Open
psteinroe wants to merge 1 commit into
fix/completions-keywords-after-parenthesisfrom
feat/grammar-update-delete-aliases
Open

psteinroe wants to merge 1 commit into
fix/completions-keywords-after-parenthesisfrom
feat/grammar-update-delete-aliases

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Stacked on #1134.

The alias of an UPDATE or DELETE target wasn't known to completions, so update users u ... where u.| and returning u.| offered nothing. UPDATE already parsed the alias; DELETE didn't parse one at all, nor USING.

What changed

  • Grammar: DELETE FROM [ONLY] t [*] [[AS] alias] [USING ...] [WHERE ... | WHERE CURRENT OF c] [RETURNING ...]. USING is a new delete_using node and takes the same relations and joins as UPDATE ... FROM. DELETE is now a partial rule and its FROM ends at the table, so delete | offers from, and a keyword after the table counts as the start of the next clause, which makes delete ... returning with (| offer old and new like UPDATE in fix(completions): complete keywords right after an opening parenthesis #1134.
  • The table alias query matches the alias of an update_target and of the target in DELETE's FROM. Aliases in USING are 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 after u. in WHERE and RETURNING of UPDATE and DELETE, and after an alias in USING. It fails without the change.
  • finds_update_and_delete_target_aliases for the query.
  • Grammar snapshots delete_alias_and_using and delete_where_current_of, and partial-sqls/delete.sql runs the typing-state test over DELETE. It fails on the base branch at delete.
  • delete from t returning with (|) joins the cases of completes_options_after_opening_parenthesis.
  • delete is now a statement start keyword, so it shows up in the snapshots that list them, and delete | offers from instead 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

  • DELETE's ORDER BY, LIMIT and OFFSET, which Postgres doesn't have, still parse as before.

… 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant