---
cuppy_hub: salesforce
cuppy_path: reference/official/data360/data-cloud-query-guide/references/dc-sql-reference/prepare.md
cuppy_section: docs
cuppy_doc: 4ZX5-VVK1
cuppy_doc_uuid: d31fb71d-5e22-4a40-9677-62f91c737ac7
cuppy_permalink: https://cuppy.io/salesforce/d/4ZX5-VVK1
cuppy_version: 1
cuppy_updated: 2026-10-23T16:16:52.575Z
cuppy_canonical: https://cuppy.io/salesforce/docs/reference/official/data360/data-cloud-query-guide/references/dc-sql-reference/prepare
cuppy_mcp: https://cuppy.io/mcp
cuppy_body_sha256: a84ff9266f545237b74d9ecfd5a7808d171528880d53acdf8fbd79f40742bf27
# cuppy_body_sha256 is over the document body ALONE, excluding both generated blocks.
---

> Mirror of <https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/prepare.html> (Salesforce, Data 360 Query Guide), read 2026-10-23. Salesforce's own page is the authority; this copy exists because that site refuses non-browser readers.

## PREPARE

**Applies to:** ❌ Data 360 SQL ✅ Tableau Hyper API

Prepare a statement for execution.

`PREPARE` creates a prepared statement. A prepared statement is a server-side object that can be used to optimize performance. When the `PREPARE` statement is executed, the specified statement is parsed, analyzed, optimized and compiled. When an `EXECUTE` command is subsequently issued, the prepared statement is simply executed. This division of labor avoids repetitive parse and compilation work.

Prepared statements can take parameters: values that are substituted into the statement when it is executed. When creating the prepared statement, refer to parameters by position, using `$1`, `$2`, etc. A corresponding list of parameter data types can optionally be specified. If a list of types is not given, the type of each parameter is inferred from the context in which it is first referenced (if possible). When executing the statement, specify the actual values for these parameters in the `EXECUTE` statement. Refer to [EXECUTE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/execute.html) for more information about that.

Prepared statements only last for the duration of the current database session. When the session ends, the prepared statement is forgotten, so it must be recreated before being used again. This also means that a single prepared statement cannot be used by multiple simultaneous database clients; however, each client can create their own prepared statement to use. Prepared statements can be manually cleaned up using the [DEALLOCATE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/deallocate.html) command.

Prepared statements potentially have the largest performance advantage when a single session is being used to execute a large number of similar statements. The performance difference will be particularly significant if the statements are complex to plan or compile, e.g., if the query involves a join of many tables or requires the application of several rules. If the statement is relatively simple to plan and compile but relatively expensive to execute, the performance advantage of prepared statements will be less noticeable.

`<name>`
An arbitrary name given to this particular prepared statement. It must be unique within a single session and is subsequently used to execute or deallocate this prepared statement.

`<data_type>`
The data type of a parameter to the prepared statement. If the data type of a particular parameter is unspecified, it will be inferred from the context in which the parameter is first referenced. To refer to the parameters in the prepared statement itself, use `$1`, `$2`, etc.

`<statement>`
Any `SELECT`, `INSERT`, `UPDATE`, `DELETE`, or `VALUES` statement.

Prepared statements do not re-generate query plans for executions of the statement with different values supplied as parameters. As such, the generic plan might perform worse than the plan that would be generated by an equivalent query with hard-coded arguments.

Certain table modifications might cause re-compilation, and thus generation of a new query plan for prepared statements that access that table. These include schema changes like renaming or dropping and re-creating a table or view with the same name.

Although the main point of a prepared statement is to avoid repeated optimization and compilation of the statement, Hyper will force re-planning and re-compilation of the statement before using it whenever database objects used in the statement have undergone definitional (DDL) changes since the previous use of the prepared statement. Further causes of re-planning and re-compilation are the insertion of a null value in a column that only contains non-null values and, conversely, the removal of the only null value in an otherwise non-null column. In that case, prepared statements that access the table containing the column are recompiled on demand during the next execution.

Non-qualified references to tables and views (i.e., without a schema name as prefix) are translated into their qualified counterparts when a prepared statement is created. Therefore, the results delivered by the execution of a prepared statement will not change if the search path is changed or if tables are created that would cause name resolution to be different at the time of execution.

Create a prepared statement for an `INSERT` statement, and then execute it:

Create a prepared statement for a `SELECT` statement, and then execute it:

Note that the data type of the second parameter is not specified, so it is inferred from the context in which `$2` is used.

The SQL standard includes a `PREPARE` statement, but it is only for use in embedded SQL. This version of the `PREPARE` statement also uses a somewhat different syntax, which is derived from PostgreSQL.


---
<!-- cuppy -->
You are reading one file. The same content is free over MCP at https://cuppy.io/mcp with no signup: ranked search across all 376 documents in this hub, the merged view when you work in a layer, known workarounds matched to the error you hit, and depth control so you spend tokens on what you need. Start with the `_hello` tool. How to connect: https://cuppy.io/salesforce/ Something wrong in this document? Report it with the `session feedback` tool on the same endpoint.
<!-- /cuppy -->
