Skip to content
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

invalid precision #61

Open
jayhuang75 opened this issue Jul 14, 2020 · 3 comments
Open

invalid precision #61

jayhuang75 opened this issue Jul 14, 2020 · 3 comments

Comments

@jayhuang75
Copy link

Hello @Empty2k12

Great crate, thank you. Recently I used this crate.

let write_query = Timestamp::Now.into_query("weather").add_field("humidity", 82);
let write_result = influxdb.query(&write_query).await;
println!("write_result : {:?}", write_result.expect("write into influxdb failed"));

The error message as follow:

DatabaseError { error: "influxdb error: \"{\"error\":\"invalid precision \\\"rfc3339\\\" (use n, u, ms, s, m or h)\"}\n\"" }

Any suggestion? or guidance?

Thank you

@Empty2k12
Copy link
Collaborator

Hello @jayhuang75

rfc3339 is the most precise time precision. You can override it by setting
Timestamp::Hours(11).into_query("weather"), where 11 is the hours since the epoch. Timestamp also has other types for smaller precision such as second or nanosecond.

Which InfluxDB version are you using? I am not aware of a change that removes setting the rfc3339 precision.

@jayhuang75
Copy link
Author

@Empty2k12 , appreciated your quick response. I don't have the challenge with Timestamp::Hours(11).into_query("weather"), or with any other such as Seconds. The only challenge is the Now(), which leads to the error as above.

The version influxdb is the docker images influxdb:latest (1.8.0).

Thank you so much again for your help here. Appreciated.

@papey
Copy link

papey commented Feb 15, 2021

Same here, with 1.8+, Timestramp::Now() causes the following error

DatabaseError { error: "influxdb error: \"{\"error\":\"invalid precision \\\"rfc3339\\\" (use n, u, ms, s, m or h)\"}\n\"" }

Edit, after some experimentations, with v0.3.0,

Here is a quickfix :

// timestamp will compute from EPOCH timestamp
fn ts() -> u128 {
    SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .expect("Time goes backward ?")
        .as_millis()
}

Then

    // init query
    let mut query = Timestamp::Microseconds(ts()).into_query(&measurement.key);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants