Skip to content

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

Open
@graup

Description

@graup

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions