HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

PREPARE

Function

Creates a prepared statement.

A prepared statement is a performance optimizing object on the server. PREPARE is executed to parse, analyze, and rewrite the specified query. EXECUTE is executed to plan and execute the prepared statement. This avoids repetitive parsing and analysis. After the PREPARE statement is created, it exists throughout the database session. Once it is created (even if in a transaction block), it will not be deleted when a transaction is rolled back. It can only be deleted by explicitly invoking DEALLOCATE or automatically deleted when the session ends.

Precautions

N/A

Syntax

PREPARE name [ ( data_type [, ...] ) ] AS statement;
PREPARE name FROM statement;

Parameter Description

  • name

    Specifies the name of a prepared statement. It must be unique in the session.

  • data_type

    Specifies the data type of the parameter.

  • statement

    Specifies a SELECT, INSERT, UPDATE, DELETE, MERGE INTO, or VALUES statement.

Examples

MogDB=# CREATE TABLE test(name text, age int);
CREATE TABLE
MogDB=# INSERT INTO test values('a',18);
INSERT 0 1
MogDB=# PREPARE stmt FROM SELECT * FROM test;
PREPARE
MogDB=# EXECUTE stmt;
 name | age 
------+-----
 a    |  18
(1 row)
Copyright © 2011-2024 www.enmotech.com All rights reserved.