Skip to content

Commit 46956c6

Browse files
author
Peng Ren
committed
Fix reserved keyword issue
1 parent bcbd4c6 commit 46956c6

7 files changed

Lines changed: 235 additions & 48 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Parameters are substituted into the MongoDB filter during execution, providing p
230230
- **Array access**: `items[0].name`, `orders[1].total`
231231
- **Complex queries**: `WHERE customer.profile.age > 18 AND orders[0].status = 'paid'`
232232

233-
> **Note**: Avoid SQL reserved words (`user`, `data`, `value`, `count`, etc.) as unquoted field names. Use alternatives or bracket notation for arrays.
233+
> **Note**: Avoid SQL reserved words (`user`, `data`, `value`, `count`, etc.) as unquoted field names. Use alternatives names, or wrap them in double quotes if you must use them.
234234
235235
### Sorting and Limiting
236236

pymongosql/sql/handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def normalize_field_path(path: str) -> str:
6262
s = re.sub(r"\[\s*['\"]([^'\"]+)['\"]\s*\]", r".\1", s)
6363
# Convert numeric bracket indexes [0] -> .0
6464
s = re.sub(r"\[\s*(\d+)\s*\]", r".\1", s)
65+
# Unquote quoted identifiers in dot notation (e.g., "date" -> date)
66+
s = re.sub(r'"([^"]+)"', r"\1", s)
6567
# Collapse multiple dots and strip leading/trailing dots
6668
s = re.sub(r"\.{2,}", ".", s).strip(".")
6769
return s

0 commit comments

Comments
 (0)