PL/Tcl functions provide you with SPI functions to access the database and run DML/DDL statements.
The functions are the following:
spi_exec
: This executes a SQL statementspi_prepare
: This prepares a SQL statementspi_execp
: This executes a prepared statement
The spi_exec
function has the following syntax:
spi_exec ?-count n? ?-array name? command ?loop-body?
The spi_exec
function runs a SQL statement, and it takes some optional parameters, as follows:
-count
: This parameter allows you to specify the maximum number of rows processed by the command. If you provide the value 3, only 3 rows will be processed. This is similar to specifyingFETCH [n]
in a cursor.-array
: If this parameter is specified, the column values are stored into a named associative array and the column names are used as array indexes. If this parameter is not specified, the result values are stored in the Tcl variables of the same name.
If there is a loop body specified, then it is treated as a script that is...