Skip to content

feat: soft-split SQL statements at 2+ blank lines when ; is missing - #124

Open
Blankll wants to merge 3 commits into
masterfrom
feat/soft-split-missing-semicolon
Open

feat: soft-split SQL statements at 2+ blank lines when ; is missing#124
Blankll wants to merge 3 commits into
masterfrom
feat/soft-split-missing-semicolon

Conversation

@Blankll

@Blankll Blankll commented Jul 28, 2026

Copy link
Copy Markdown
Member

Problem

When a user forgets a ; between two SQL statements, the entire text is sent as one query and PostgreSQL returns a syntax error like:

syntax error at or near "SELECT"

This is a common UX friction — users often write multiple queries separated by blank lines without remembering the trailing ;.

Solution

Added splitRangesAtBlankLines() that runs as a post-processing step after the standard ;-based split. For each statement range, it scans for 2+ consecutive blank lines followed by a SQL keyword. When found, the range is split at that point.

Split keywords: SELECT, CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, TRUNCATE, GRANT, REVOKE, EXPLAIN, SHOW, DESCRIBE, USE, SET, CALL, EXEC/EXECUTE, BEGIN, COMMIT, ROLLBACK, DECLARE, ANALYZE, VACUUM, PRAGMA, REFRESH, COPY, WITH, MERGE, REPLACE

Safety: Requires 2+ blank lines (not 1) to avoid false positives — a single blank line within a multi-line statement won't split it.

Example

SELECT * FROM users;
-- forget ;
SELECT * FROM orders;

→ Still one statement (1 blank line, safe)

SELECT * FROM users;


SELECT * FROM orders;

→ Split into 2 statements (2 blank lines + SELECT keyword)

Verification

  • 452 tests pass (no regressions)
  • 6 new test cases covering multi-statement, single-blank (no split), mixed ;/blank-line, and position correctness
  • Lint clean

When statements are separated by 2+ blank lines followed by a SQL keyword (SELECT, INSERT, CREATE, etc.), automatically split them into separate statements even without a ; delimiter. This recovers gracefully from forgotten semicolons between queries.
@Blankll
Blankll force-pushed the feat/soft-split-missing-semicolon branch 4 times, most recently from eaafac4 to 8dd7e58 Compare July 28, 2026 14:32
When statements are separated by 2+ blank lines followed by a SQL keyword, auto-split into separate statements even without ; delimiter. Also handles comment lines between blank lines, and suppresses false splits for CTE main queries (WITH ... AS (...) \n\n\n SELECT ...).
@Blankll
Blankll force-pushed the feat/soft-split-missing-semicolon branch from 8dd7e58 to e97e6aa Compare July 28, 2026 14:32
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