[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)
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 ofv8 - No provider environment variables set: this is AST-only extraction, no LLM involved
Additional context
Related:
- #2953:
BEGIN; … COMMIT;wrapping (the case this follows up) - #1910, #2180: PL/pgSQL
ERRORnodes
Source: Graphify-Labs/graphify