-
Notifications
You must be signed in to change notification settings - Fork 96
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
Unable to use time::OffsetDateTime
(and likely other time types) in binds
#121
Comments
Workaround is to implement your own serialization for a newtype struct around OffsetDateTime, something like: use serde::{ser::Error, Deserialize, Serialize, Serializer};
use time::{
format_description::well_known::iso8601::{Config, EncodedConfig, FormattedComponents},
OffsetDateTime,
};
struct SafeDateTime(OffsetDateTime);
const CLICKHOUSE_CONFIG: EncodedConfig = Config::DEFAULT
.set_formatted_components(FormattedComponents::DateTime)
.encode();
impl Serialize for SafeDateTime {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> where S: Serializer {
self.0.format(&Iso8601::<CLICKHOUSE_CONFIG>)
.map_err(S::Error::custom)?
.serialize(serializer)
}
} |
Yes =( It's exactly what I do: .bind(interval.start_time.as_rfc3339_weak()) I don't think it's possible without specialization in Rust (what won't happen soon) to have a dedicated logic. Another way is to provide wrappers by the crate. |
You could remove the blanket |
It's not obvious, because it's very useful, and my production code relies heavily on it: we use a lot of wrappers like It should be much easier after stabilizing specialization in rustc |
Even Another idea could be to have a feature flag |
Binding a query like
client.query("SELECT ?fields WHERE ts > ?").bind(datetime!(2022-11-13 15:27:42 UTC))
results in runtime execution error:DB::Exception: Illegal type Tuple(UInt16, UInt8, UInt8, UInt8, UInt8, UInt32, UInt8, UInt8, UInt8)
It seems the issue is there isn't a specific serializer for these time types and ClickHouse does not accept the default representation serde generates.
The text was updated successfully, but these errors were encountered: