↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQL Commands

EXECUTE

execute a prepared statement

English manual coverage begins with PostgreSQL 6.4. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

anchor
SQL-EXECUTE
file
sql-execute.html
lang
en
name
EXECUTE
purpose
execute a prepared statement
purpose zh
执行一个预备语句
sections same as
Unknown
slug
18
synopsis html
EXECUTE <em class="replaceable"><code>name</code></em> [ ( <em class="replaceable"><code>parameter</code></em> [, ...] ) ]
synopsis text
EXECUTE name [ ( parameter [, ...] ) ]

Syntax

EXECUTE name [ ( parameter [, ...] ) ]
Syntax diagrams

Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.

EXECUTE name ( parameter , )

Definition PG 18

EXECUTE name [ ( parameter [, ...] ) ]

Description

EXECUTE is used to execute a previously prepared statement. Since prepared statements only exist for the duration of a session, the prepared statement must have been created by a PREPARE statement executed earlier in the current session.

If the PREPARE statement that created the statement specified some parameters, a compatible set of parameters must be passed to the EXECUTE statement, or else an error is raised. Note that (unlike functions) prepared statements are not overloaded based on the type or number of their parameters; the name of a prepared statement must be unique within a database session.

For more information on the creation and usage of prepared statements, see PREPARE.

Parameters

name

The name of the prepared statement to execute.

parameter

The actual value of a parameter to the prepared statement. This must be an expression yielding a value that is compatible with the data type of this parameter, as was determined when the prepared statement was created.

Outputs

The command tag returned by EXECUTE is that of the prepared statement, and not EXECUTE.

Examples

Examples are given in Examples in the PREPARE documentation.

Compatibility

The SQL standard includes an EXECUTE statement, but it is only for use in embedded SQL. This version of the EXECUTE statement also uses a somewhat different syntax.

See Also

DEALLOCATE, PREPARE

Compare versions

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · wiki-repair-20261023:ca390920a7790f4a283ce2cf78ac3f33fda5aa6b8678664d7a45e26ddca57fb9

Text language: en · wiki-repair-20261023:ca390920a7790f4a283ce2cf78ac3f33fda5aa6b8678664d7a45e26ddca57fb9