Basic PL/pgSQL executable statements [YSQL]

Basic PL/pgSQL executable statements

The following table lists all of the basic PL/pgSQL executable statements.

  • The Statement Name column links to the page where the semantics are described.
  • The Syntax rule name column links to the definition on the omnibus Grammar Diagrams reference page.
STATEMENT NAME SYNTAX RULE NAME COMMENT
"assert" statement plpgsql_assert_stmt abort the current server call if the assertion tests "false"
"assign" statement plpgsql_assignment_stmt e.g. "a := b + c;" and "v := (select count(*) from s.t)". No further explanation is needed.
Bare SQL statement plpgsql_static_bare_sql_stmt ANY embedded SQL statement (including DDL, etc) that doesn't return values
"close" statement plpgsql_close_cursor_stmt close a cursor (using "refcursor" variable)
"continue" statement plpgsql_continue_stmt start the next iteration of a loop (or enclosing loop)
"execute" statement plpgsql_dynamic_sql_stmt execute a dynamic SQL statement, optionally with "into" clause for returned values
"exit" statement plpgsql_exit_stmt exit from a loop (or enclosing loop)
"fetch" statement plpgsql_fetch_from_cursor_stmt fetch from a cursor (using "refcursor" variable)
"get diagnostics" statement plpgsql_get_diagnostics_stmt get diagnostic info about the most-recently-executed SQL statement
"get stacked diagnostics" statement plpgsql_get_stacked_diagnostics_stmt get diagnostic info about the exception that brought the point of execution to the present handler
"insert, update, delete into" statement plpgsql_static_dml_returning_stmt embedded "insert", "update", or "delete" statement with "into" clause for returned values
"move" statement plpgsql_move_in_cursor_stmt move in cursor — not yet supported, see Beware Issue #6514
"open" statement plpgsql_open_cursor_stmt open a cursor (using "refcursor" variable)
"perform" statement plpgsql_perform_stmt execute a "select" statement without returning rows
"raise" statement plpgsql_raise_stmt "raise info" or... "warning" or... "exception"
"return" statement plpgsql_return_stmt exit from subprogram to caller, optionally returning value(s)
"select into" statement plpgsql_static_select_into_stmt embedded single-row "select" with "into" clause for returned values