Skip to content

[Bug]: SQL: CREATE TABLEs inside BEGIN; … COMMIT; still dropped when a DO $$ … END $$; block makes tree-sitter-sql emit a top-level block (follow-up to #2953) #3886

Closed

Description

@mininic1

Pre-flight checks

  • I have checked the Troubleshooting section in the README

What happened?

extract_sql silently drops every CREATE TABLE inside a BEGIN; … COMMIT; transaction when the transaction also contains a DO $$ … END $$; block.

tree-sitter-sql parses BEGIN; as the opener of a block that closes on the END of the DO body. The top-level node is then block instead of transaction. Since #2953, the top-level dispatch in graphify/extractors/sql.py walks statement, transaction, ERROR and a few Firebird types, but not block, so nothing inside it is extracted. The create_table nodes are still in the tree, under the block. No error or warning is printed.

Expected: users is extracted as a table node.
Actual: only the file node is produced.

Real-world impact: on an 850-line PostgreSQL schema.sql (PL/pgSQL trigger functions plus a few idempotent DO $$ blocks), 8 of the 11 CREATE TABLE statements and all their triggers are missing from the graph.

Steps to reproduce

1. Save as `repro.sql`:


BEGIN;

CREATE TABLE users (
    id BIGSERIAL PRIMARY KEY
);

DO $$
BEGIN
    IF NOT EXISTS (SELECT 1 FROM pg_trigger WHERE tgname = 't') THEN
        CREATE TRIGGER t BEFORE UPDATE ON users
        FOR EACH ROW EXECUTE FUNCTION touch();
    END IF;
END $$;

COMMIT;


2. Run in a fresh env:


uvx --from 'graphifyy[sql]==0.9.70' python -c "
from pathlib import Path
from graphify.extract import extract_sql
print([n['label'] for n in extract_sql(Path('repro.sql'))['nodes']])
"


3. Control case: replace `BEGIN;` with `BEGIN TRANSACTION;` (equivalent in PostgreSQL) and run again. `users` is now extracted.

Error output or graph output

No traceback: the failure is silent.


# BEGIN;
['repro.sql']

# BEGIN TRANSACTION;
['repro.sql', 'users']


Top-level nodes of the tree-sitter-sql parse (type, start row, end row):


# BEGIN;
[('block', 1, 12), ('ERROR', 12, 12), ('ERROR', 13, 15)]

# BEGIN TRANSACTION;
[('transaction', 1, 15)]

Graphify version

0.9.70

Operating System

Linux

Python Version

3.12

Installation Method

uv tool install (recommended)

Additional Environment Details

  • tree-sitter-sql 0.3.11, py-tree-sitter 0.25.2
  • Also reproduced on graphifyy 0.9.53 (uv tool install 'graphifyy[sql]==0.9.53')
  • Reproduced on 0.9.70 in a clean throwaway env (uvx --from 'graphifyy[sql]==0.9.70'), not from a git checkout of v8
  • No provider environment variables set: this is AST-only extraction, no LLM involved

Additional context

Related:

Activity

  1. added
    bug
    on Sep 27, 2026
  2. github-actions commented on Sep 27, 2026

    @github-actions

    Thanks for opening this issue, @mininic1. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  3. added a commit that references this issue on Sep 29, 2026
    452e7b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions