-
-
Notifications
You must be signed in to change notification settings - Fork 458
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
Support the interval
type when appropriate Rust types are developed
#60
Comments
I believe I left it off because it doesn't match up 1:1 with an existing Rust type. Timespec is a significantly higher precision type, and I'm a bit leery of silently lossy conversions in the Rust -> Postgres direction. That being said, mapping it to Timespec isn't the end of the world, though I wouldn't be surprised if date had a different wire format than timestamp, which would require some changes to the |
Another example is the |
I solved my immediate issue by using timestamp in the database. I agree Timespec is the wrong rust type to map Postgres date to. Yes, there is no Rust type that maps to Postgres interval yet. Someone was supposed to be working on a Jodatime-like / JSR-310 datetime system. Hopefully that will have a ReadablePeriod type, which maps to Postgres interval. |
date
, time
, and interval
types when appropriate Rust types are developed
Is rust-chrono a good choice? |
I've added support mapping |
date
, time
, and interval
types when appropriate Rust types are developedinterval
type when appropriate Rust types are developed
@sfackler would there be interest if I wrote a "simple" mapping for the interval type? More specifically it would have the following interface and other additions if required: pub fn new(microseconds: i64, days: i32, months: i32) -> Interval;
pub fn microseconds(&self) -> i64;
pub fn days(&self) -> i32;
pub fn months(&self) -> i32;
pub fn to_sql_standard(&self) -> String;
pub fn to_postgres(&self) -> String;
pub fn to_postgres_verbose(&self) -> String;
pub fn to_iso_8601(&self) -> String; and will also implement the Any input would be appreciated. |
This affects me as well. My current workaround is
The The @TheServerAsterisk suggestion makes sense to me. Though I'd suggest having a |
I have a dedicated interval type here if anyone is interested. |
How foolish is it to wish for |
A Duration could be converted to a Postgres interval, but not vice versa: #60 (comment). |
|
As noted in the comment directly above yours, those types aren't equivalent: #60 (comment) |
Is there any reason why we can't have the SELECT foo_id FROM foo WHERE foo.expire_ts > CURRENT_TIMESTAMP + INTERVAL $1 |
I attempted to add Above and in the docs, it is mentioned that intervals consists of months, days and microseconds. Further, // Maybe?
struct Interval {
months: i32,
days: i32,
microseconds: i64,
} But I'm not sure and I couldn't find any information on how those are written to the binary buffer. I briefly tried to dig through the postgres code, but gosh, I haven't read C code in a long time. And I just couldn't find anything relevant. Finally, how would one convert
But how exactly? Especially since days and months vary in length (the whole point of this weird representation), one surely couldn't do any |
Yes, if you prefer I did the job for my crate: https://github.com/elephantry/elephantry/blob/3.0.0-beta.2/core/src/sql/date/interval.rs |
I was running into the same limitation. Using Not sure if that is a recipe to implement this out-of-the-box or even the other way around (from postgres to Duration). But it worked for me. |
Sorry for pinging, but what is the best approach to solve this? |
There is a crate, chrono-intervals that provides |
I think going the way SQLx did it with |
Is there a reason { name: date, oid: 1082 } is not included? I realize a timestamp is more precise, but (at the very least) existing databases may use date.
I tried to add support for it at https://github.com/mikedilger/rust-postgres/commit/7f4637956f65c9086705c444ba93d30c4f593177 but I'm not sure that's right. When I try using it, it triggers a RefCell already borrowed error (#34 or rust-lang/rust#13246)
The text was updated successfully, but these errors were encountered: