Skip to main content

PlPgSqlStmt

Enum PlPgSqlStmt 

Source
pub enum PlPgSqlStmt {
Show 18 variants Assign { target: AssignTarget, value: Expr, }, SelectInto { var: String, body: Box<SelectStatement>, }, Return(ReturnTarget), ReturnNext(Expr), ReturnQuery(Box<SelectStatement>), ReturnQueryExecute { sql: Expr, }, If { branches: Vec<(Expr, Vec<PlPgSqlStmt>)>, else_branch: Vec<PlPgSqlStmt>, }, Raise { level: RaiseLevel, message: String, args: Vec<Expr>, }, EmbeddedSql(Box<Statement>), Assert { condition: Expr, message: Option<Expr>, }, While { condition: Expr, body: Vec<PlPgSqlStmt>, }, ForRange { var: String, start: Expr, end: Expr, reverse: bool, body: Vec<PlPgSqlStmt>, }, Loop { body: Vec<PlPgSqlStmt>, }, Exit { when: Option<Expr>, }, Continue { when: Option<Expr>, }, ExecuteDynamic { sql: Expr, }, ForQuery { var: String, query: Box<SelectStatement>, body: Vec<PlPgSqlStmt>, }, ForExecute { var: String, sql_expr: Expr, body: Vec<PlPgSqlStmt>, },
}

Variants§

§

Assign

NEW.col := expr; or OLD.col := expr;. OLD is parsed for clarity in error reporting (PG also forbids it) — the executor errors with a clear “OLD is read-only” message.

Fields

§value: Expr
§

SelectInto

v7.16.2 — plpgsql SELECT <projection> INTO <var> [FROM …] (mailrs round-10 migrate-042). The body is the SELECT statement with the INTO clause stripped; the engine runs it via Engine::execute, takes the first row’s first column, and assigns to the local variable in the DECLARE scope. Single-column / single-row queries only at v7.16.2; multi-target (INTO a, b) is a v7.16.x follow-up.

Fields

§

Return(ReturnTarget)

RETURN <target>; — trigger functions canonically return NEW / OLD / NULL; v7.12.4 also accepts a bare expression for forward compatibility with scalar UDFs.

§

ReturnNext(Expr)

v7.39 (read01 round 66) — RETURN NEXT <expr>;: append one row to the set a SETOF function is building, and KEEP GOING. Not a return.

§

ReturnQuery(Box<SelectStatement>)

v7.39 (read01 round 66) — RETURN QUERY <select>;: append every row the query yields, and keep going. It used to desugar to a side-effect statement whose result was DISCARDED — in a SETOF function that is the whole answer thrown away.

§

ReturnQueryExecute

v7.39 (read01 round 68) — RETURN QUERY EXECUTE <sql expr>: the dynamic twin. Its rows go to the set too; it used to run and discard them.

Fields

§sql: Expr
§

If

v7.12.6 — IF cond THEN body [ELSIF cond THEN body]* [ELSE body] END IF;. Branches are tried in order; first truthy condition wins; the optional ELSE runs when no condition matched.

Fields

§branches: Vec<(Expr, Vec<PlPgSqlStmt>)>
§else_branch: Vec<PlPgSqlStmt>
§

Raise

v7.12.6 — RAISE <level> '<fmt>' [, args]*;. Level is one of NOTICE / WARNING / INFO / LOG / DEBUG (logging — observable side effect only) or EXCEPTION (aborts the trigger and propagates as an error). v7.12.6 supports the basic format-string substitution PG uses (% placeholders consumed positionally).

Fields

§message: String
§args: Vec<Expr>
§

EmbeddedSql(Box<Statement>)

v7.12.6 — embedded SQL statement inside the trigger body (INSERT INTO …, UPDATE …, DELETE FROM …, SELECT …). NEW.col / OLD.col references inside the embedded statement’s expression tree are substituted with the current trigger context before the engine re-executes the statement. Recursion depth into nested triggers is bounded by the engine’s existing trigger-fire guard.

§

Assert

v7.37.20 (20.14) — ASSERT <condition> [, <message>];. If the condition evaluates falsy the trigger / DO block aborts with the message (defaulting to a generic shape when none is provided). Same propagation shape as RAISE EXCEPTION — the error reaches the caller’s query path. PG’s behaviour is identical except for a plpgsql.check_asserts GUC that can disable the check globally; SPG always evaluates.

Fields

§condition: Expr
§message: Option<Expr>
§

While

v7.37.20 (20.3) — WHILE <condition> LOOP <body> END LOOP;. Iterate the body while condition evaluates truthy. Iteration count is bounded by WHILE_LOOP_BUDGET to prevent runaway loops; the executor errors out when reached. EXIT / CONTINUE inside the body queue with 20.2.

Fields

§condition: Expr
§

ForRange

v7.37.20 (20.4) — `FOR IN [REVERSE] .. LOOP

END LOOP;`. Integer iteration; `var` is BigInt-valued; bounds inclusive on both sides. REVERSE walks backward. Iteration budget guards runaway.

Fields

§start: Expr
§end: Expr
§reverse: bool
§

Loop

v7.37.20 (20.2) — bare LOOP <body> END LOOP;. Runs the body repeatedly; only EXIT [WHEN <cond>] breaks out. Iteration budget guards runaway.

Fields

§

Exit

v7.37.20 (20.2) — EXIT [WHEN <condition>]; inside a loop. Unconditional (no WHEN) or conditional (only breaks when condition is truthy). Bubbles up as BodyOutcome::Break which the enclosing loop catches. Outside a loop it’s a no-op.

Fields

§when: Option<Expr>
§

Continue

v7.37.20 (20.2) — CONTINUE [WHEN <condition>]; inside a loop. Same shape as EXIT but bubbles up as BodyOutcome::Continue which the enclosing loop catches, skipping the remainder of the body and jumping to the next iteration.

Fields

§when: Option<Expr>
§

ExecuteDynamic

v7.37.20 (20.13) — EXECUTE <string_expr>; runs a runtime- computed SQL statement. The expression is evaluated to a text value, the resulting string is parsed and dispatched through the engine like an EmbeddedSql. USING <param_list> for placeholder binding queues with v7.40 PL/pgSQL epic.

Fields

§sql: Expr
§

ForQuery

v7.37.20 (20.5) — FOR <var> IN <select_body> LOOP <body> END LOOP;. Runs the SELECT once, iterates the resulting rows, binds the first column of each row to var as a scalar Value, then runs the body per iteration. EXIT / CONTINUE / ASSERT / RAISE etc. propagate through the enclosing loop’s BodyOutcome discipline the same way FOR range and WHILE do. Full record-binding (var as composite carrying all columns) queues with v7.40 record type infrastructure.

§

ForExecute

v7.37.20 (20.6) — `FOR IN EXECUTE <string_expr> LOOP

END LOOP;`. Same shape as ForQuery but the SELECT is computed at runtime from a text expression, parsed on the fly, then iterated. Enables dynamic queries where the projection / FROM / WHERE clauses depend on runtime values.

Fields

§sql_expr: Expr

Trait Implementations§

Source§

impl Clone for PlPgSqlStmt

Source§

fn clone(&self) -> PlPgSqlStmt

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 PlPgSqlStmt

Source§

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

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

impl Display for PlPgSqlStmt

Source§

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

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

impl PartialEq for PlPgSqlStmt

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PlPgSqlStmt

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.