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.
Unlisten
UNLISTEN * or UNLISTEN channel.
Fields
target: UnlistenTargetSet
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.
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
options: TransactionOptionsReset
RESET ALL or RESET parameter.
Fields
target: ResetTargetDiscard
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
target: DiscardTargetDeallocate
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 PreparedStatements’ LRU.
Fields
target: DeallocateTargetBegin
BEGIN [transaction_mode ...] or START TRANSACTION [transaction_mode ...]. Folded to a single variant since
PostgreSQL treats them identically.
Fields
options: TransactionOptionsCommit
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
impl Statement
Sourcepub fn is_read_only(&self) -> bool
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.
Sourcepub fn is_read_write_override(&self) -> bool
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 WRITESET TRANSACTION READ WRITESET SESSION CHARACTERISTICS AS TRANSACTION READ WRITESET default_transaction_read_only = <false-ish>orTO DEFAULT(the compiled default for that GUC isoff, so resetting it to default means read-write)RESET default_transaction_read_only(identical effect toSET ... TO DEFAULT— both revert to the compiled default)RESET ALL(sweeps every session setting, includingdefault_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§
impl Eq for Statement
impl StructuralPartialEq for Statement
Auto Trait Implementations§
impl Forget for Statement
impl Freeze for Statement
impl Move for Statement
impl RefUnwindSafe for Statement
impl Send for Statement
impl Sync for Statement
impl Unpin for Statement
impl UnsafeUnpin for Statement
impl UnwindSafe for Statement
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.