Keep Oracle procedure declarations in split statement by gaoflow · Pull Request #858 · andialbrecht/sqlparse · GitHub
Skip to content

Keep Oracle procedure declarations in split statement#858

Open
gaoflow wants to merge 1 commit into
andialbrecht:masterfrom
gaoflow:fix-692-oracle-procedure-split
Open

Keep Oracle procedure declarations in split statement#858
gaoflow wants to merge 1 commit into
andialbrecht:masterfrom
gaoflow:fix-692-oracle-procedure-split

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 25, 2026

Copy link
Copy Markdown

Summary

  • keep Oracle-style CREATE PROCEDURE ... AS declaration sections in the same split statement as their BEGIN ... END body
  • avoid treating dollar-quoted PostgreSQL function bodies after AS as declaration sections
  • add regression coverage for both cases

Closes #692

Tests

  • uv run --group dev --python 3.11 pytest tests/test_split.py::test_split_oracle_procedure_with_declarations tests/test_split.py::test_split_function_with_dollar_quoted_body_and_following_statement -q
  • uv run --group dev --python 3.11 pytest tests/test_split.py -q
  • uv run --group dev --python 3.11 pytest tests/ -q
  • uv run --group dev ruff check sqlparse/ tests/test_split.py
  • git diff --check

Copilot AI review requested due to automatic review settings June 25, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the statement-splitting logic so sqlparse.split() keeps Oracle CREATE PROCEDURE ... AS/IS declaration sections together with their BEGIN ... END bodies, while avoiding misclassification of PostgreSQL dollar-quoted function bodies after AS as declaration blocks (which could otherwise interfere with splitting subsequent statements).

Changes:

  • Track CREATE {FUNCTION|PROCEDURE|PACKAGE|TRIGGER} blocks and detect AS/IS as a “body follows” marker.
  • Treat the first non-whitespace/comment token after AS/IS as either:
    • a literal body (e.g., dollar-quoted), or
    • the start of an implicit Oracle-style declaration section (modeled as a DECLARE block) until BEGIN.
  • Add regression tests for Oracle procedure declarations (issue #692) and PostgreSQL dollar-quoted function bodies followed by another statement.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
sqlparse/engine/statement_splitter.py Adds state to detect CREATE block bodies after AS/IS and handle Oracle declarations vs. literal bodies correctly.
tests/test_split.py Adds regression tests covering Oracle procedure declarations and PostgreSQL dollar-quoted function body splitting behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Split does not work properly

2 participants