Skip to content
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(snowflake): Manually escape single quotes in colon operator #4104

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

VaggelisD
Copy link
Collaborator

Fixes #4090

Snowflake allows JSON extraction through the colon operator such as col:ab, and double quotes (col:"ab") can optionally be used to include special characters in the key.

This will be roundtripped/transpiled to a string literal in the respective function such as GET_PATH(..., 'ab') which can break queries if single quotes are in the json key.

For this reason, this PR escapes those paths at parse time in _parse_colon_as_variant_extract(). Note that Databricks uses backticks for special characters so it won't be affected.

sqlglot/parser.py Outdated Show resolved Hide resolved
@georgesittas georgesittas merged commit b10255e into main Sep 10, 2024
6 checks passed
@georgesittas georgesittas deleted the vaggelisd/sf_json_escape branch September 10, 2024 17: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.

Using singe quote as part of JSON object key leads to invalid SQL generation
2 participants