Skip to content

Comments

Handle dollar-quoted strings in SQL analyzer#15

Merged
datastx merged 2 commits intomainfrom
claude/fix-dbt-config-y2C9T
Feb 23, 2026
Merged

Handle dollar-quoted strings in SQL analyzer#15
datastx merged 2 commits intomainfrom
claude/fix-dbt-config-y2C9T

Conversation

@datastx
Copy link
Owner

@datastx datastx commented Feb 23, 2026

Summary

This PR adds support for properly handling PostgreSQL dollar-quoted strings (e.g., $$...$$ ) in the SQL analyzer to prevent them from being incorrectly parsed as comments or other syntax elements.

Key Changes

  • lexer.rs: Made scan_dollar_string() function public so it can be reused by the analyzer
  • analyzer.rs: Added logic to detect and skip dollar-quoted strings during SQL analysis, preventing them from interfering with comment and syntax detection
  • golden_test.rs: Added test case for dbt configuration with dollar-quoted regex patterns

Implementation Details

The analyzer now checks for dollar-quoted strings ($...$) before processing other syntax elements. When a dollar sign is encountered, it calls scan_dollar_string() to determine if it's the start of a dollar-quoted string. If valid, the entire string is skipped, ensuring that content within dollar quotes (such as regex patterns in regexp_substr() calls) is not misinterpreted as SQL syntax.

This fix enables proper formatting of dbt models that use dollar-quoted strings for complex regex patterns while maintaining correct handling of Jinja templating and other SQL constructs.

https://claude.ai/code/session_01HZFB5jseiADk1UEzJi1Y8E

The validate_comment_markers pre-lex validation was not skipping
dollar-quoted strings ($$...$$), so content like $$/\*\s*...\*/$$
was incorrectly detected as an unmatched block comment close.

https://claude.ai/code/session_01HZFB5jseiADk1UEzJi1Y8E
Replace proprietary SQL with a minimal, generic fixture that exercises
the same bug: dollar-quoted strings containing /* and */ patterns being
misinterpreted as block comment markers. Reduces the fixture from ~300
lines to ~65 lines while preserving all key elements (dbt config block,
dollar-quoted regex, jinja refs, incremental block).

https://claude.ai/code/session_01HZFB5jseiADk1UEzJi1Y8E
@datastx datastx merged commit 1760f02 into main Feb 23, 2026
9 checks passed
@datastx datastx deleted the claude/fix-dbt-config-y2C9T branch February 24, 2026 07:04
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.

2 participants