Skip to content

Serialization of NULL in parameters is incorrect #384

@abonander

Description

@abonander

Assuming impl<T: Primitive> Primitive for Option<T> {} which does not exist as-of writing:

    let result = client
        .query("SELECT {val1: Nullable(String)} AS result")
        .param("val1", Option::<String>::None)
        .fetch_one::<Option<String>>()
        .await
        .expect("failed to fetch string");
    assert_eq!(result, None);

This will actually return the literal string "NULL" instead of None.

This is because ParamSerializer emits a literal string NULL for None:

self.writer.write_str("NULL")?;

However, the proper literal for NULL in query parameters is \N (which is not a valid string escape so it cannot be misinterpreted): ClickHouse/ClickHouse#29665 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions