Handle dollar-quoted strings in SQL analyzer#15
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
scan_dollar_string()function public so it can be reused by the analyzerImplementation Details
The analyzer now checks for dollar-quoted strings (
$...$) before processing other syntax elements. When a dollar sign is encountered, it callsscan_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 inregexp_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