Skip to content

Commit 87ff645

Browse files
Razicanabonander
andauthored
Exposing the Oid of PostgreSQL types (#2507)
* Exposing the Oid of PostgreSQL types * Do not panic if OID is not set * Update sqlx-postgres/src/type_info.rs Co-authored-by: Austin Bonander <[email protected]> * cargo fmt --------- Co-authored-by: Austin Bonander <[email protected]>
1 parent c2e54ea commit 87ff645

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

sqlx-postgres/src/type_info.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,25 @@ impl PgTypeInfo {
166166
self.0.kind()
167167
}
168168

169+
/// Returns the OID for this type, if available.
170+
///
171+
/// The OID may not be available if SQLx only knows the type by name.
172+
/// It will have to be resolved by a `PgConnection` at runtime which
173+
/// will yield a new and semantically distinct `TypeInfo` instance.
174+
///
175+
/// This method does not perform any such lookup.
176+
///
177+
/// ### Note
178+
/// With the exception of [the default `pg_type` catalog][pg_type], type OIDs are *not* stable in PostgreSQL.
179+
/// If a type is added by an extension, its OID will be assigned when the `CREATE EXTENSION` statement is executed,
180+
/// and so can change depending on what extensions are installed and in what order, as well as the exact
181+
/// version of PostgreSQL.
182+
///
183+
/// [pg_type]: https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat
184+
pub fn oid(&self) -> Option<Oid> {
185+
self.0.try_oid()
186+
}
187+
169188
#[doc(hidden)]
170189
pub fn __type_feature_gate(&self) -> Option<&'static str> {
171190
if [

0 commit comments

Comments
 (0)