Skip to content
Discussion options

You must be logged in to vote

The reason you're seeing a mismatch is that Postgres's INET type isn't just an IP address: it's an IP address plus a network prefix (like /32 or /128). While std::net::IpAddr represents the address, it doesn't carry that prefix information, which is why sqlx defaults to more specific types.

To fix this, you should use the IpNetwork type from the ipnetwork crate (if you have that feature enabled in sqlx). It converts seamlessly from IpAddr:

use ipnetwork::IpNetwork;

// Convert your IpAddr into the network type sqlx expects
let ip_param: IpNetwork = sensor_log_row.ip_address.into();

let result = sqlx::query!(
    r#"INSERT INTO sensor_logs (ip_address) VALUES ($1) RETURNING id"#,
    ip_p…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by h-m-88
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants