pub struct PgRelation { /* private fields */ }Implementations§
Source§impl PgRelation
impl PgRelation
Sourcepub unsafe fn from_pg(ptr: Relation) -> Self
pub unsafe fn from_pg(ptr: Relation) -> Self
Wrap a Postgres-provided pg_sys::Relation.
It is assumed that Postgres will later RelationClose() the provided relation pointer.
As such, it is not closed when this instance is dropped
§Safety
This method is unsafe as we cannot ensure that this relation will later be closed by Postgres
Sourcepub unsafe fn from_pg_owned(ptr: Relation) -> Self
pub unsafe fn from_pg_owned(ptr: Relation) -> Self
Wrap a Postgres-provided pg_sys::Relation.
The provided Relation will be closed via pg_sys::RelationClose when this instance is dropped
Sourcepub unsafe fn open(oid: Oid) -> Self
pub unsafe fn open(oid: Oid) -> Self
Given a relation oid, use pg_sys::RelationIdGetRelation() to open the relation
If the specified relation oid was recently deleted, this function will panic.
Additionally, the relation is closed via pg_sys::RelationClose() when this instance is
dropped.
§Safety
The caller should already have at least AccessShareLock on the relation ID, else there are nasty race conditions.
As such, this function is unsafe as we cannot guarantee that this requirement is true.
Sourcepub unsafe fn with_lock(oid: Oid, lockmode: LOCKMODE) -> Self
pub unsafe fn with_lock(oid: Oid, lockmode: LOCKMODE) -> Self
relation_open - open any relation by relation OID
If lockmode is not “NoLock”, the specified kind of lock is obtained on the relation.
An error is raised if the relation does not exist.
§Safety
Using an inappropriate lockmode, such as using NoLock on a relation that has not been previously locked, may result in undefined behavior.
NB: a “relation” is anything with a pg_class entry. The caller is expected to check whether the relkind is something it can handle.
The opened relation is automatically closed via pg_sys::relation_close()
when this instance is dropped
Sourcepub unsafe fn open_with_name(relname: &str) -> Result<Self, &'static str>
pub unsafe fn open_with_name(relname: &str) -> Result<Self, &'static str>
Given a relation name, use pg_sys::to_regclass to look up its oid, and then
pg_sys::RelationIdGetRelation() to open the relation.
If the specified relation name is not found, we return an Err(&str).
If the specified relation was recently deleted, this function will panic.
Additionally, the relation is closed via pg_sys::RelationClose() when this instance is
dropped.
§Safety
The caller should already have at least AccessShareLock on the relation ID, else there are nasty race conditions.
As such, this function is unsafe as we cannot guarantee that this requirement is true.
Given a relation name, use pg_sys::to_regclass to look up its oid, and then
open it with an AccessShareLock
If the specified relation name is not found, we return an Err(&str).
If the specified relation was recently deleted, this function will panic.
Additionally, the relation is closed via pg_sys::RelationClose() when this instance is
dropped.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
RelationGetRelationName Returns the rel’s name.
Note that the name is only unique within the containing namespace.
Sourcepub fn namespace_oid(&self) -> Oid
pub fn namespace_oid(&self) -> Oid
RelationGetNamespace Returns the rel’s namespace OID.
Sourcepub fn namespace(&self) -> &str
pub fn namespace(&self) -> &str
What is the name of the namespace in which this relation is located?
Sourcepub fn heap_relation(&self) -> Option<PgRelation>
pub fn heap_relation(&self) -> Option<PgRelation>
If this PgRelation represents an index, return the PgRelation for the heap
relation to which it is attached
Sourcepub fn indices(&self, lockmode: LOCKMODE) -> impl Iterator<Item = PgRelation>
pub fn indices(&self, lockmode: LOCKMODE) -> impl Iterator<Item = PgRelation>
Return an iterator of indices, as PgRelations, attached to this relation
Sourcepub fn tuple_desc(&self) -> PgTupleDesc<'_>
pub fn tuple_desc(&self) -> PgTupleDesc<'_>
Returned a wrapped PgTupleDesc
The returned PgTupleDesc is tied to the lifetime of this PgRelation instance.
use pgx::{PgRelation, pg_sys};
let oid = example_pg_class_oid(42); // a valid pg_class "oid" value
let relation = unsafe { PgRelation::from_pg(pg_sys::RelationIdGetRelation(oid) ) };
let tupdesc = relation.tuple_desc();
// assert that the tuple descriptor has 12 attributes
assert_eq!(tupdesc.len(), 12);Sourcepub fn reltuples(&self) -> Option<f32>
pub fn reltuples(&self) -> Option<f32>
Number of tuples in this relation (not always up-to-date)
pub fn is_table(&self) -> bool
pub fn is_matview(&self) -> bool
pub fn is_index(&self) -> bool
pub fn is_view(&self) -> bool
pub fn is_sequence(&self) -> bool
pub fn is_composite_type(&self) -> bool
pub fn is_foreign_table(&self) -> bool
pub fn is_partitioned_table(&self) -> bool
pub fn is_toast_value(&self) -> bool
Methods from Deref<Target = PgBox<RelationData>>§
Trait Implementations§
Source§impl Clone for PgRelation
impl Clone for PgRelation
Source§impl Deref for PgRelation
impl Deref for PgRelation
Source§impl Drop for PgRelation
impl Drop for PgRelation
Source§impl FromDatum for PgRelation
impl FromDatum for PgRelation
Source§unsafe fn from_polymorphic_datum(
datum: Datum,
is_null: bool,
_typoid: Oid,
) -> Option<PgRelation>
unsafe fn from_polymorphic_datum( datum: Datum, is_null: bool, _typoid: Oid, ) -> Option<PgRelation>
from_datum for instantiating polymorphic types
which require preserving the dynamic type metadata. Read moreSource§const GET_TYPOID: bool = false
const GET_TYPOID: bool = false
from_datum?Source§unsafe fn from_datum(datum: Datum, is_null: bool) -> Option<Self>where
Self: Sized,
unsafe fn from_datum(datum: Datum, is_null: bool) -> Option<Self>where
Self: Sized,
Source§unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
typoid: Oid,
) -> Option<Self>where
Self: Sized,
unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
typoid: Oid,
) -> Option<Self>where
Self: Sized,
FromDatum::from_datum(...) from within that context. Read moreSource§unsafe fn try_from_datum(
datum: Datum,
is_null: bool,
type_oid: Oid,
) -> Result<Option<Self>, TryFromDatumError>
unsafe fn try_from_datum( datum: Datum, is_null: bool, type_oid: Oid, ) -> Result<Option<Self>, TryFromDatumError>
try_from_datum is a convenience wrapper around FromDatum::from_datum that returns a
a Result around an Option, as a Datum can be null. It’s intended to be used in
situations where the caller needs to know whether the type conversion succeeded or failed. Read moreSource§unsafe fn try_from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
type_oid: Oid,
) -> Result<Option<Self>, TryFromDatumError>
unsafe fn try_from_datum_in_memory_context( memory_context: PgMemoryContexts, datum: Datum, is_null: bool, type_oid: Oid, ) -> Result<Option<Self>, TryFromDatumError>
try_from_datum that switches to the given context to convert from DatumSource§impl IntoDatum for PgRelation
impl IntoDatum for PgRelation
Source§impl SqlTranslatable for PgRelation
impl SqlTranslatable for PgRelation
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
Auto Trait Implementations§
impl Freeze for PgRelation
impl RefUnwindSafe for PgRelation
impl !Send for PgRelation
impl !Sync for PgRelation
impl Unpin for PgRelation
impl UnwindSafe for PgRelation
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<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.