Skip to content

fix(analyser): add a semicolon before the COMMIT of banUncommittedTransaction when the last statement has none - #1062

Merged
psteinroe merged 3 commits into
mainfrom
fix/commit-fix-adds-semicolon
Nov 2, 2026
Merged

psteinroe merged 3 commits into
mainfrom
fix/commit-fix-adds-semicolon

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Stacked on #1044.

#1044 drops banUncommittedTransaction's fix when the file's last statement has no semicolon, since adding \ncommit; after it doesn't parse. The fix can add the semicolon instead:

begin;
create table users (id bigint)
-- fix: create table users (id bigint);
--      commit;

While writing the spec I found that the fix put the COMMIT into the body of a SQL function when the file ends with a CREATE FUNCTION: the analyser took the end of the last statement from the last entry of its statement list, which is the last statement of the function's body. The fix guard didn't catch it, since the function still parses with commit; in its body.

What changed

  • The analyser takes the end of a file, or section, from its last top-level statement (parsed or not), and records whether that statement ends with a semicolon.
  • AnalysedFileContext::append_statement(sql) replaces end_offset: it returns where to insert what to add a statement after the last one, with a ; first if the last statement has none. Without the text of the last statement, it assumes a semicolon, and fix(analyser): check fixes that edit after their statement on the file #1044's guard still checks the fix on the file.

Tests

  • banUncommittedTransaction/no_semicolon_at_the_end.sql now has the fix ...;\ncommit; (the harness checks that it parses).
  • New spec banUncommittedTransaction/function_at_the_end.sql: the COMMIT goes after the CREATE FUNCTION. Without the change, it goes into the function body.
  • cargo test -p pgls_analyser, cargo clippy --workspace --all-targets -- -D warnings.

@psteinroe
psteinroe added this pull request to stack #1098 November 1, 2026 09:17
Base automatically changed from fix/fix-guard-reparses-edits-outside-statement to main November 1, 2026 12:05
@psteinroe
psteinroe force-pushed the fix/commit-fix-adds-semicolon branch from e76fc09 to c885787 Compare November 1, 2026 12:05
@psteinroe
psteinroe merged commit e305cb5 into main Nov 2, 2026
12 checks passed
@psteinroe
psteinroe deleted the fix/commit-fix-adds-semicolon branch November 2, 2026 18:48
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.

2 participants