From 2b265b2c8edf67c27bc1632d68dba76914f3e909 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Wed, 12 Oct 2022 17:28:05 +0200 Subject: [PATCH 1/4] Exposing the Oid of PostgreSQL types --- sqlx-postgres/src/type_info.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sqlx-postgres/src/type_info.rs b/sqlx-postgres/src/type_info.rs index ae211d0d3a..7d7c5c3e0d 100644 --- a/sqlx-postgres/src/type_info.rs +++ b/sqlx-postgres/src/type_info.rs @@ -166,6 +166,11 @@ impl PgTypeInfo { self.0.kind() } + /// Returns the OID for this type. + pub fn oid(&self) -> Oid { + self.0.oid() + } + #[doc(hidden)] pub fn __type_feature_gate(&self) -> Option<&'static str> { if [ From a4ca29a7fce232a8afe4fc5bc668acb765269ef3 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Fri, 19 May 2023 16:31:06 +0200 Subject: [PATCH 2/4] Do not panic if OID is not set --- sqlx-postgres/src/type_info.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sqlx-postgres/src/type_info.rs b/sqlx-postgres/src/type_info.rs index 7d7c5c3e0d..7d1a9c7ef1 100644 --- a/sqlx-postgres/src/type_info.rs +++ b/sqlx-postgres/src/type_info.rs @@ -166,9 +166,9 @@ impl PgTypeInfo { self.0.kind() } - /// Returns the OID for this type. - pub fn oid(&self) -> Oid { - self.0.oid() + /// Returns the OID for this type, if any. + pub fn try_oid(&self) -> Option { + self.0.try_oid() } #[doc(hidden)] From c92c68aabce4c24f70df951009c4bb3452478b31 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Tue, 13 Jun 2023 07:02:01 +0200 Subject: [PATCH 3/4] Update sqlx-postgres/src/type_info.rs Co-authored-by: Austin Bonander --- sqlx-postgres/src/type_info.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sqlx-postgres/src/type_info.rs b/sqlx-postgres/src/type_info.rs index 7d1a9c7ef1..bd1c099699 100644 --- a/sqlx-postgres/src/type_info.rs +++ b/sqlx-postgres/src/type_info.rs @@ -166,8 +166,22 @@ impl PgTypeInfo { self.0.kind() } - /// Returns the OID for this type, if any. - pub fn try_oid(&self) -> Option { + /// Returns the OID for this type, if available. + /// + /// The OID may not be available if SQLx only knows the type by name. + /// It will have to be resolved by a `PgConnection` at runtime which + /// will yield a new and semantically distinct `TypeInfo` instance. + /// + /// This method does not perform any such lookup. + /// + /// ### Note + /// With the exception of [the default `pg_type` catalog][pg_type], type OIDs are *not* stable in PostgreSQL. + /// If a type is added by an extension, its OID will be assigned when the `CREATE EXTENSION` statement is executed, + /// and so can change depending on what extensions are installed and in what order, as well as the exact + /// version of PostgreSQL. + /// + /// [pg_type]: https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat + pub fn oid(&self) -> Option { self.0.try_oid() } From eab08fdebd3fcfcdf56ddace1e97340a9ef90b33 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Tue, 13 Jun 2023 20:26:03 +0200 Subject: [PATCH 4/4] cargo fmt --- sqlx-postgres/src/type_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-postgres/src/type_info.rs b/sqlx-postgres/src/type_info.rs index bd1c099699..b44bded580 100644 --- a/sqlx-postgres/src/type_info.rs +++ b/sqlx-postgres/src/type_info.rs @@ -169,7 +169,7 @@ impl PgTypeInfo { /// Returns the OID for this type, if available. /// /// The OID may not be available if SQLx only knows the type by name. - /// It will have to be resolved by a `PgConnection` at runtime which + /// It will have to be resolved by a `PgConnection` at runtime which /// will yield a new and semantically distinct `TypeInfo` instance. /// /// This method does not perform any such lookup.