[][src]Struct pgx::rel::PgRelation

pub struct PgRelation { /* fields omitted */ }

Implementations

impl PgRelation[src]

pub unsafe fn from_pg(ptr: Relation) -> Self[src]

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

pub fn from_pg_owned(ptr: Relation) -> Self[src]

Wrap a Postgres-provided pg_sys::Relation.

The provided Relation will be closed via pg_sys::RelationClose when this instance is dropped

pub unsafe fn open(oid: Oid) -> Self[src]

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.

pub fn with_lock(oid: Oid, lockmode: LOCKMODE) -> Self[src]

relation_open - open any relation by relation OID

If lockmode is not "NoLock", the specified kind of lock is obtained on the relation. (Generally, NoLock should only be used if the caller knows it has some appropriate lock on the relation already.)

An error is raised if the relation does not exist.

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

pub unsafe fn open_with_name(relname: &str) -> Result<Self, &'static str>[src]

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.

pub fn open_with_name_and_share_lock(
    relname: &str
) -> Result<Self, &'static str>
[src]

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.

pub fn name(&self) -> &str[src]

RelationGetRelationName Returns the rel's name.

Note that the name is only unique within the containing namespace.

pub fn oid(&self) -> Oid[src]

RelationGetRelid Returns the OID of the relation

pub fn namespace_oid(&self) -> Oid[src]

RelationGetNamespace Returns the rel's namespace OID.

pub fn namespace(&self) -> &str[src]

What is the name of the namespace in which this relation is located?

pub fn heap_relation(&self) -> Option<PgRelation>[src]

If this PgRelation represents an index, return the PgRelation for the heap relation to which it is attached

pub fn indicies(&self, lockmode: LOCKMODE) -> impl Iterator<Item = PgRelation>[src]

Return an iterator of indices, as PgRelations, attached to this relation

pub fn tuple_desc(&self) -> PgTupleDesc<'_>[src]

Returned a wrapped PgTupleDesc

The returned PgTupleDesc is tied to the lifetime of this PgRelation instance.

use pgx::{PgRelation, pg_sys};
let 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);

pub fn reltuples(&self) -> Option<f32>[src]

Number of tuples in this relation (not always up-to-date)

pub fn is_table(&self) -> bool[src]

pub fn is_matview(&self) -> bool[src]

pub fn is_index(&self) -> bool[src]

pub fn is_view(&self) -> bool[src]

pub fn is_sequence(&self) -> bool[src]

pub fn is_composite_type(&self) -> bool[src]

pub fn is_foreign_table(&self) -> bool[src]

pub fn is_partitioned_table(&self) -> bool[src]

pub fn is_toast_value(&self) -> bool[src]

pub fn to_owned(mut self: Self) -> Self[src]

ensures that the returned PgRelation is closed by Rust when it is dropped

Methods from Deref<Target = PgBox<RelationData>>

pub fn is_null(&self) -> bool[src]

Are we boxing a NULL?

pub fn as_ptr(&self) -> *mut T[src]

Return the boxed pointer, so that it can be passed back into a Postgres function

Trait Implementations

impl Clone for PgRelation[src]

pub fn clone(&self) -> Self[src]

Same as calling PgRelation::with_lock(AccessShareLock) on the underlying relation id

impl Deref for PgRelation[src]

type Target = PgBox<RelationData>

The resulting type after dereferencing.

impl Drop for PgRelation[src]

impl FromDatum for PgRelation[src]

impl IntoDatum for PgRelation[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.