< 返回版块

javasn 发表于 2020-01-07 18:37

大侠们好! deadpool-postgres(tokio-postgres)的timestamp到底对应Rust中的哪个类型? 我试过用Rust的i64/i32/u32/u64,以及postgres-types中的Timestamp等都不行,提示类型不匹配,如下: panicked at 'error retrieving column time_edited: error deserializing column 2: cannot convert between the Rust type postgres_types::special::Timestamp<i64> and the Postgres type timestamp',

评论区

写评论
phper-chen 2020-01-16 17:39

人家的类型是包过的struct 你不能直接拿rust的基础数据类型比较的

作者 javasn 2020-01-08 09:43

deadpool的作者回答了(用std::time::SystemTime或第三方库chrono的DataTime): This is actually a topic for tokio-postgres. You can use the chrono crate which is supported by tokio-postgres (https://docs.rs/tokio-postgres/0.5.1/tokio_postgres/types/trait.FromSql.html) by activating the with-chrono-0_4 feature. (See: https://github.com/sfackler/rust-postgres/blob/master/tokio-postgres/Cargo.toml#L31)

Add this to your crates.toml dependencies or update the tokio-postgres dependency:

[dependencies] tokio-postgres = { version="0.5.1", features=["with-chrono-0_4"] } And then use it:

let a: chrono::DateTimechrono::offset::Utc = row.get("time_edited");

作者 javasn 2020-01-07 18:39

let a: Timestamp = row.get("time_edited");这句发生panic: panicked at 'error retrieving column time_edited: error deserializing column 2: cannot convert between the Rust type postgres_types::special::Timestamp<i64> and the Postgres type timestamp',

1 共 3 条评论, 1 页