-
Notifications
You must be signed in to change notification settings - Fork 5
fix(parser): support quoted identifiers in DML and DDL statements #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(parser): support quoted identifiers in DML and DDL statements #201
Conversation
- Changed DML parsers (INSERT, UPDATE, DELETE, MERGE) to use isIdentifier() instead of isType(TokenTypeIdentifier) for table/column name parsing - Changed DDL parsers (CREATE, DROP, TRUNCATE, REFRESH) similarly - Added comprehensive tests for double-quoted identifiers in all DML/DDL statements The existing isIdentifier() method correctly handles both regular identifiers and double-quoted strings (TokenTypeDoubleQuotedString), but the DML/DDL parsers were bypassing this by checking for TokenTypeIdentifier directly. This fix ensures ANSI SQL double-quoted identifiers work consistently across all statement types, matching the existing behavior in SELECT. Fixes ajitpratap0#200
|
@claude review |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
1 similar comment
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
PR Review: Double-Quoted Identifier SupportThanks for this fix! The core approach is correct - using 🔴 High Priority: Missing Changes in
|
| Missing Tests | Code Changes |
|---|---|
| MERGE statements | 6 locations modified, 0 tests |
| REFRESH MATERIALIZED VIEW | Modified but not tested |
| CREATE MATERIALIZED VIEW | Modified but not tested |
| ON CONFLICT with quoted identifiers | Modified but not tested |
Please add tests for:
// MERGE with quoted identifiers
`MERGE INTO "target" t USING "source" s ON t.id = s.id WHEN MATCHED THEN UPDATE SET "col" = s.val`
// REFRESH MATERIALIZED VIEW
`REFRESH MATERIALIZED VIEW "my-view"`
// ON CONFLICT
`INSERT INTO "users" ("id") VALUES (1) ON CONFLICT ("id") DO UPDATE SET "name" = EXCLUDED."name"`🟡 Test Quality Improvements
The tests should follow GoSQLX patterns more closely:
- Add AST release - Currently no
ast.ReleaseAST()calls (potential memory leak):
tree, err := parser.Parse(tokens)
if err != nil {
t.Fatalf(...)
}
defer ast.ReleaseAST(tree) // Add this- Use NewParser() - Replace
&Parser{}with proper pooling:
parser := NewParser()
defer parser.Release()- Add AST validation - Verify the quoted identifier is correctly stored:
// After parsing INSERT INTO "users" ...
if insertStmt.TableName != "users" { // or `"users"` depending on how it's stored
t.Errorf("expected table name 'users', got '%s'", insertStmt.TableName)
}- Add edge case tests:
// Spaces in identifier
`SELECT * FROM "table name"`
// Reserved word as identifier
`SELECT "select", "from" FROM users`
// Schema-qualified with quotes
`SELECT * FROM "schema"."table"`Summary
| Category | Status |
|---|---|
| dml.go changes | ✅ Correct |
| ddl.go changes | ✅ Correct |
| cte.go | ❌ Missing updates |
| select.go | |
| Test coverage | |
| Test quality |
Please address the cte.go changes and add MERGE tests at minimum before merging. The other items can be follow-up improvements if needed.
Address PR review feedback:
1. cte.go: Use isIdentifier() for CTE name and column parsing
- Line 112: CTE name now supports double-quoted identifiers
- Line 124: CTE column list now supports double-quoted identifiers
2. select.go: Use isIdentifier() for constraint/reference parsing
- Line 171: REFERENCES table name
- Line 183: REFERENCES column list
- Line 329: FOREIGN KEY table reference
- Line 401: Constraint column list (parseConstraintColumnList)
3. Improved test quality in double_quoted_identifier_test.go:
- Use NewParser()/Release() instead of &Parser{}
- Add ast.ReleaseAST() to prevent memory leaks
- Add new test cases for CTE, MERGE, REFRESH MATERIALIZED VIEW,
ON CONFLICT, and edge cases
- Fix token converter to handle asterisk (*) correctly
All tests pass including race detection.
The existing isIdentifier() method correctly handles both regular identifiers and double-quoted strings (TokenTypeDoubleQuotedString), but the DML/DDL parsers were bypassing this by checking for TokenTypeIdentifier directly.
This fix ensures ANSI SQL double-quoted identifiers work consistently across all statement types, matching the existing behavior in SELECT.
Fixes #200
Description
Brief description of what this PR does.
Type of Change
Changes Made
Testing
go test ./...)go test -race ./...)go test -bench=. ./...)Test Coverage
Performance Impact
Benchmark Results (if applicable)
Checklist
Related Issues
Closes #(issue number)
Screenshots (if applicable)
Add any relevant screenshots here.
Additional Notes
Any additional information that reviewers should know.