PREPARE
Description
Creates a prepared statement.
A prepared statement is a performance optimizing object on the server. When the PREPARE statement is executed, the specified query is parsed, analyzed, and rewritten. When EXECUTE is executed, the prepared statement is planned and executed. 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 calling DEALLOCATE or automatically deleted when the session ends.
Precautions
The name of a PREPARE statement must be unique.
Syntax
PREPARE name FROM string
Parameters
- name
Specifies an identifier for the prepared query.
- string
Specifies a character string, which is a prepared SQL statement. The user variable @var_name is not supported. The following statements are supported:
- SELECT
- INSERT
- UPDATE
- DELETE
Examples
m_db=# PREPARE p1 FROM 'SELECT 10 < 52'; PREPARE m_db=# EXECUTE p1; ?column? ---------- t (1 row)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot