diff --git a/sqlx-core/src/postgres/connection/establish.rs b/sqlx-core/src/postgres/connection/establish.rs index bd23780026..83b5097676 100644 --- a/sqlx-core/src/postgres/connection/establish.rs +++ b/sqlx-core/src/postgres/connection/establish.rs @@ -32,8 +32,7 @@ impl PgConnection { // Sets the time zone for displaying and interpreting time stamps. ("TimeZone", "UTC"), // Adjust postgres to return precise values for floats - // NOTE: This is default in postgres 12+ - ("extra_float_digits", "3"), + ("extra_float_digits", options.extra_float_digits.as_str()), ]; if let Some(ref application_name) = options.application_name { diff --git a/sqlx-core/src/postgres/options/mod.rs b/sqlx-core/src/postgres/options/mod.rs index 05a0aef2af..47eee8962c 100644 --- a/sqlx-core/src/postgres/options/mod.rs +++ b/sqlx-core/src/postgres/options/mod.rs @@ -88,6 +88,7 @@ pub struct PgConnectOptions { pub(crate) application_name: Option, pub(crate) log_settings: LogSettings, pub(crate) options: Option, + pub(crate) extra_float_digits: String, } impl Default for PgConnectOptions { @@ -149,6 +150,8 @@ impl PgConnectOptions { application_name: var("PGAPPNAME").ok(), log_settings: Default::default(), options: var("PGOPTIONS").ok(), + // NOTE: This is default in postgres 12+ + extra_float_digits: "3".to_owned(), } } @@ -378,6 +381,20 @@ impl PgConnectOptions { _ => None, } } + + /// Sets the extra float digits. Defaults to 3 + /// + /// # Example + /// + /// ```rust + /// # use sqlx_core::postgres::PgConnectOptions; + /// let options = PgConnectOptions::new() + /// .extra_float_digits("2"); + /// ``` + pub fn extra_float_digits(mut self, extra_float_digits: &str) -> Self { + self.extra_float_digits = extra_float_digits.to_owned(); + self + } } fn default_host(port: u16) -> String {