Skip to main content

Statement

Enum Statement 

Source
pub enum Statement {
Show 16 variants Listen { channel: String, }, Unlisten { target: UnlistenTarget, }, Set { scope: SetScope, parameter: String, value: SetValue, }, SetTransaction { options: TransactionOptions, }, Reset { target: ResetTarget, }, Discard { target: DiscardTarget, }, Deallocate { target: DeallocateTarget, }, Begin { options: TransactionOptions, }, Commit, Rollback, Select, Insert, Update, Delete, Copy, Other,
}
Expand description

A parsed SQL statement.

The parser only inspects leading tokens, so multi-statement queries are classified by their first statement.

Variants§

§

Listen

LISTEN channel. The channel name is lowercased for unquoted identifiers and case-preserved for "quoted" identifiers — matching PostgreSQL’s own rules.

Fields

§channel: String
§

Unlisten

UNLISTEN * or UNLISTEN channel.

Fields

§

Set

SET [SESSION | LOCAL] parameter (= | TO) value — a regular GUC assignment.

SET TRANSACTION ... and SET SESSION CHARACTERISTICS AS TRANSACTION ... are parsed as Statement::SetTransaction instead; those configure transaction characteristics, not a parameter value.

Fields

§scope: SetScope
§parameter: String
§value: SetValue
§

SetTransaction

SET TRANSACTION <modes> (for the current transaction) or SET SESSION CHARACTERISTICS AS TRANSACTION <modes> (session defaults for future transactions). Both share the same transaction-mode grammar, so they flatten to a single variant.

Fields

§

Reset

RESET ALL or RESET parameter.

Fields

§

Discard

DISCARD ALL | PLANS | SEQUENCES | TEMPORARY | TEMP.

The subtarget matters: only DISCARD ALL drops prepared statements (via its embedded DEALLOCATE ALL) and resets session GUCs. PLANS only invalidates cached query plans — the prepared statements themselves persist. SEQUENCES and TEMPORARY do not touch the pool state halephant tracks. See DiscardTarget for the full list.

Fields

§

Deallocate

DEALLOCATE [PREPARE] (name | ALL).

The PREPARE keyword between DEALLOCATE and the target is optional noise in PostgreSQL’s grammar; the parser collapses both forms to the same variant.

Halephant intercepts this at the transaction layer: the server only knows the canonical (hashed) name halephant assigned during Parse rewriting, so a raw DEALLOCATE my_stmt would error out with “prepared statement does not exist”. The interceptor resolves the client-side name against ClientPrepared, releases the refcount in the global StatementStore, and synthesises a CommandComplete response without forwarding to the server — the actual server-side statement is eventually reclaimed by ServerPrepared’s LRU.

Fields

§

Begin

BEGIN [transaction_mode ...] or START TRANSACTION [transaction_mode ...]. Folded to a single variant since PostgreSQL treats them identically.

Fields

§

Commit

COMMIT (or its END alias).

§

Rollback

ROLLBACK or ABORT (including ROLLBACK TO SAVEPOINT ...).

§

Select

SELECT ..., TABLE ..., VALUES ..., or a WITH ... SELECT/TABLE/VALUES.

§

Insert

INSERT ..., or a WITH ... INSERT.

§

Update

UPDATE ..., or a WITH ... UPDATE.

§

Delete

DELETE ..., TRUNCATE ..., or a WITH ... DELETE.

§

Copy

COPY ....

§

Other

Anything else: DDL, empty input, bare punctuation, statements whose leading keyword is not recognised. Halephant forwards these without further inspection.

Implementations§

Source§

impl Statement

Source

pub fn is_read_only(&self) -> bool

Returns true when the statement itself is read-only — currently only plain SELECT. This is a statement property, independent of any transaction-level read-only mode the caller tracks separately.

Source

pub fn is_read_write_override(&self) -> bool

Returns true when the statement attempts to switch a read-only transaction back to read-write. Covers every variant that can flip the effective read/write mode:

  • BEGIN READ WRITE / START TRANSACTION READ WRITE
  • SET TRANSACTION READ WRITE
  • SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE
  • SET default_transaction_read_only = <false-ish> or TO DEFAULT (the compiled default for that GUC is off, so resetting it to default means read-write)
  • RESET default_transaction_read_only (identical effect to SET ... TO DEFAULT — both revert to the compiled default)
  • RESET ALL (sweeps every session setting, including default_transaction_read_only)

Halephant uses this to reject writes on replica-routed transactions without having to re-parse the statement. Missing any of the above would let a client silently restore read-write on a replica-routed connection.

Trait Implementations§

Source§

impl Clone for Statement

Source§

fn clone(&self) -> Statement

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Statement

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Statement

Source§

fn eq(&self, other: &Statement) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Statement

Source§

impl StructuralPartialEq for Statement

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

Source§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
Source§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
Source§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
Source§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
Source§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a MaybeRef.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,