ClickHouse / clickhouse-rs

Official pure Rust typed client for ClickHouse DB
https://clickhouse.com
Apache License 2.0
283 stars 84 forks source link

Unable to serialize `Option<_>` bind #119

Closed v3xro closed 1 month ago

v3xro commented 1 month ago

Trying to write

client
  .query("SELECT ?fields FROM table WHERE nullable_field = ?")
  .bind(None)

fails at runtime with:

invalid param: invalid SQL: invalid argument: serialize_none is unsupported

The pattern of having nullable binds is quite common in server-side applications so I would have expected Option<_> support in binds somewhere (or maybe I missed it).

loyd commented 1 month ago

optional filters

Do you mean filters that can either be provided or not by user? Yes, it's quite common, but implementation is tricky without parsing SQL. I mean, the filter should be totally ignored in such case

v3xro commented 1 month ago

optional filters

Do you mean filters that can either be provided or not by user? Yes, it's quite common, but implementation is tricky without parsing SQL. I mean, the filter should be totally ignored in such case

I've simplified the example above to not include that (though ofc you should be able to write (? IS NULL OR ? = some_nullable_field) (mostly leaving this comment for search reasons unless this should be included in examples)