Back to Materialize

EXECUTE

doc/user/content/sql/execute.md

123991 B
Original Source

EXECUTE plans and executes prepared statements. Since prepared statements only last the duration of a session, the statement must have been prepared during the current session.

If the PREPARE statement specified some parameters, you must pass values compatible with those parameters to EXECUTE. Values are considered compatible here when they can be assignment cast. (This is the same category of casting that happens for INSERT.)

Syntax

{{% include-syntax file="examples/execute" example="syntax" %}}

Example

The following example prepares a statement a and runs it using the EXECUTE statement:

mzsql
PREPARE a AS SELECT 1 + $1;
EXECUTE a (2);

All prepared statements will be cleared at the end of a session. You can also explicitly deallocate the statement using DEALLOCATE.