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

Format for Value renders incorrect escaping of quote characters in BigQuery #1695

Open
graup opened this issue Jan 31, 2025 · 0 comments
Open

Comments

@graup
Copy link
Contributor

graup commented Jan 31, 2025

impl fmt::Display for EscapeQuotedString (which is used when formatting a Value expr) uses double quote character escaping (like '' or "") which is a syntax error in BigQuery.

This was also reported in PRQL: PRQL/prql#5099

To fix this, I think we need to make this method aware of the dialect. And potentially add a new supports rule (like supports_backslash_escaping?) If someone could chime in on the approach I can take a stab at it.

Here is a failing test case you can add to tests/sqlparser_bigquery.rs

#[test]
fn test_quote_escape() {
    bigquery().verified_expr(r#"JSON '{"foo":"bar\'s"}'"#); // Wrong output: JSON '{"foo":"bar''s"}'
    bigquery().verified_expr(r#"JSON "{\"foo\":\"bar's\"}""#); // Wrong output: JSON "{""foo"":""bar's""}"
}

Both of these are valid BigQuery syntax. They get parsed into the AST correctly but get formatted incorrectly.

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

No branches or pull requests

1 participant