pub struct Oid(/* private fields */);
Expand description
An object identifier in Postgres.
This is meant to be understood purely by equality. There is no sensible “order” for Oids.
§Notes
Default
shall return a sensical Oid, not necessarily a useful one.
Currently, this means that it returns the invalid Oid.
Implementations§
Source§impl Oid
impl Oid
pub const INVALID: Oid = _
Sourcepub const unsafe fn from_u32_unchecked(id: u32) -> Oid
👎Deprecated since 0.11.2: safely converts via SPI, use pg_sys::Oid::from(u32)
pub const unsafe fn from_u32_unchecked(id: u32) -> Oid
Generate an Oid from an arbitrary u32.
§Safety
This allows you to create an Oid that Postgres won’t recognize and throw it into Postgres. Don’t.
You should know what kind of object the identifier would imply before creating it. Postgres may sometimes call very different internal functions based on an Oid input. The extension programming interface of Postgres can reach deep, calling functions that assume the caller should be trusted like Postgres would trust itself. Because it is. Postgres tables can also change at runtime, so if an Oid is not a BuiltinOid, what Postgres does based on an Oid can change dynamically.
The existence of this unsafe
requirement to create arbitrary Oids does not, itself,
constitute a promise any Oid from Postgres or PGRX is guaranteed to be valid or sensical.
There are many existing problems in the way of this, for example:
Oid
includes the guaranteed-wrong values Oid::INVALID- Postgres may return arbitrary-seeming Oids, like BuiltinOid::UNKNOWNOID
- an Oid can arrive in Rust from a table a non-superuser can write
- PGRX mostly relies on Rust’s type system instead of the dynamic typing of Postgres, thus often deliberately does not bother to remember what OID something had.
So this function is merely a reminder. Even for extensions that work with many Oids,
it is not typical to need to create one from an arbitrary u32
. Prefer to use a constant,
or a BuiltinOid, or to obtain one from querying Postgres, or simply use Oid::INVALID.
Marking it as an unsafe fn
is an invitation to get an Oid from more trustworthy sources.
This includes Oid::INVALID, or BuiltinOid, or by directly calling into Postgres.
An unsafe fn
is not an officer of the law empowered to indict C programs for felonies,
nor cite SQL statements for misdemeanors, nor even truly stop you from foolishness.
Even “trustworthy” is meant here in a similar sense to how raw pointers can be “trustworthy”.
Often, you should still check if it’s null.
Sourcepub const fn from_builtin(id: u32) -> Result<Oid, NotBuiltinOid>
pub const fn from_builtin(id: u32) -> Result<Oid, NotBuiltinOid>
Gets an Oid from a u32 if it is a valid builtin declared by Postgres
pub const fn as_u32(self) -> u32
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Oid
impl<'de> Deserialize<'de> for Oid
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<BuiltinOid> for Oid
impl From<BuiltinOid> for Oid
Source§fn from(builtin: BuiltinOid) -> Oid
fn from(builtin: BuiltinOid) -> Oid
Source§impl SqlTranslatable for Oid
impl SqlTranslatable for Oid
fn argument_sql() -> Result<SqlMapping, ArgumentError>
fn return_sql() -> Result<Returns, ReturnsError>
fn type_name() -> &'static str
fn variadic() -> bool
fn optional() -> bool
fn entity() -> FunctionMetadataTypeEntity
Source§impl TryFrom<Oid> for BuiltinOid
impl TryFrom<Oid> for BuiltinOid
Source§type Error = NotBuiltinOid
type Error = NotBuiltinOid
Source§fn try_from(oid: Oid) -> Result<BuiltinOid, NotBuiltinOid>
fn try_from(oid: Oid) -> Result<BuiltinOid, NotBuiltinOid>
impl Copy for Oid
impl Eq for Oid
impl StructuralPartialEq for Oid
Auto Trait Implementations§
impl Freeze for Oid
impl RefUnwindSafe for Oid
impl Send for Oid
impl Sync for Oid
impl Unpin for Oid
impl UnwindSafe for Oid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.