EXECUTE

Function

Executes a prepared statement. Because a prepared statement exists only in the lifetime of the session, the prepared statement must be created earlier in the current session by using the PREPARE statement.

Precautions

  • If the PREPARE statement creating the prepared statement declares certain parameters, the parameter set transferred to the EXECUTE statement must be compatible. Otherwise, an error occurs.

  • Compared with the original openGauss, Dolphin modifies the PREPARE syntax to support the EXECUTE USING syntax.

Syntax

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

Parameter Description

  • name

    Specifies the name of the prepared statement to be executed.

  • parameter

    Specifies a parameter of the prepared statement. It must be of the same data type as that specified parameter in creating and generating the prepared statement.

Examples

--Create the reason table.
openGauss=# CREATE TABLE tpcds.reason ( 
    CD_DEMO_SK          INTEGER          NOT NULL,
    CD_GENDER           character(16)            ,
    CD_MARITAL_STATUS   character(100)
)
;

--Insert data.
openGauss=# INSERT INTO tpcds.reason VALUES(51, 'AAAAAAAADDAAAAAA', 'reason 51');

--Create the reason_t1 table.
openGauss=# CREATE TABLE tpcds.reason_t1 AS TABLE tpcds.reason;

--Create a prepared statement for an INSERT statement and execute the prepared statement.
openGauss=# PREPARE insert_reason(integer,character(16),character(100)) AS INSERT INTO tpcds.reason_t1 VALUES($1,$2,$3);

openGauss=# EXECUTE insert_reason(52, 'AAAAAAAADDAAAAAA', 'reason 52'); 

openGauss=# EXECUTE insert_reason USING 52, 'AAAAAAAADDAAAAAA', 'reason 52'; 

--Delete the reason and reason_t1 tables.
openGauss=# DROP TABLE tpcds.reason;
openGauss=# DROP TABLE tpcds.reason_t1;
Feedback
编组 3备份
    openGauss 2024-10-11 00:55:40
    cancel