Skip to content

fix(parser): handle IF NOT EXISTS in SQL table references - #838

Open
yzxcj797 wants to merge 1 commit into
tirth8205:mainfrom
yzxcj797:fix/sql-if-not-exists-table-indexing
Open

fix(parser): handle IF NOT EXISTS in SQL table references#838
yzxcj797 wants to merge 1 commit into
tirth8205:mainfrom
yzxcj797:fix/sql-if-not-exists-table-indexing

Conversation

@yzxcj797

@yzxcj797 yzxcj797 commented Aug 11, 2026

Copy link
Copy Markdown

Pull Request

Linked issue

Closes #820

What & why

_SQL_TABLE_RE currently captures the literal IF from CREATE TABLE IF NOT EXISTS .... Because references are deduplicated, later idempotent creates in the same file can then disappear as well.

This change:

  • allows an optional IF NOT EXISTS clause when extracting CREATE TABLE and CREATE VIEW targets
  • classifies IF, NOT, and EXISTS as SQL keywords as a defensive fallback
  • adds regex and end-to-end regressions proving ordinary creates still work and multiple idempotent creates retain distinct edges

The adjacent TEMP/UNLOGGED/MATERIALIZED gaps described in the issue are intentionally left out to keep this PR atomic.

How it was tested

uv run pytest tests/test_notebook.py::TestSqlTableExtraction tests/test_multilang.py::TestSQLParsing --tb=short -q
# 21 passed

uv run ruff check code_review_graph/
# passed

uv run mypy code_review_graph/parser.py --ignore-missing-imports --no-strict-optional
# passed

Broader local runs also completed 481 tests in the two touched test modules; the remaining failures were existing Windows path-separator assertions. Whole-project mypy reached an existing Windows-only SIGKILL error in daemon_cli.py.

AI assistance

OpenAI Codex was used for repository inspection, implementation and test drafting, local verification, and review of the resulting diff.

Checklist

  • Tests added for new functionality
  • All tests pass: uv run pytest tests/ --tb=short -q (targeted tests pass; full supported-platform suite was not available on Windows)
  • Linting passes: uv run ruff check code_review_graph/
  • Type checking passes: uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional (the touched parser passes; see existing Windows SIGKILL failure above)
  • Lines are at most 100 characters
  • Docs updated where behavior changed (no user-facing documentation change required)

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.

SQL: CREATE TABLE IF NOT EXISTS indexes the table as "IF" — real table name lost, and dedup drops every later CREATE in the file

1 participant