Skip to content

PostgreSQL: Add support for DO statement - #2618

Merged
LucaCappelletti94 merged 9 commits into
apache:mainfrom
devtechedge:postgres-do-statement
Nov 4, 2026
Merged

LucaCappelletti94 merged 9 commits into
apache:mainfrom
devtechedge:postgres-do-statement

Conversation

@devtechedge

@devtechedge devtechedge commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

DO blocks like DO $$BEGIN RAISE NOTICE 'hi'; END$$ currently fail with "Expected: an SQL statement, found: DO".

This adds Statement::Do(DoStatement) for PostgreSQL's DO statement, gated behind a new Dialect::supports_do_statement() that is enabled for PostgreSQL.

DoStatement keeps the items of dostmt_opt_list in source order as a Vec<DoOption>, so every accepted form prints back as written. An item is a code block or LANGUAGE followed by an identifier or a string literal, and the missing code and duplicate checks are left to the server, matching PostgreSQL's grammar.

Code blocks may be single-quoted, dollar-quoted, E'' or U&''. LANGUAGE N'...' is read as the language nchar and a code block, because PostgreSQL's scanner splits it that way.

Tests in tests/sqlparser_common.rs and tests/sqlparser_postgres.rs cover the accepted forms, the round trip, the error cases and dialects without support. Five seeds under fuzz/fuzz_seeds/ cover the same syntax for the fuzzer.

The implementation and tests were drafted with an AI coding assistant (Grok 4.7 effort: xHigh), and I reviewed the diff, ran the test suite and the fuzzer, and stand by the change.

Fixes #2609

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

Labels

enhancement New feature or request PostgreSQL Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days waiting on contributor The review needs further refinements by its author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL DO statement

4 participants