> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/15/server-programming/server-programming-interface/spi-interface/spi-spi-execute-plan.md).

# SPI\_execute\_plan

## SPI\_execute\_plan

SPI\_execute\_plan — execute a statement prepared by `SPI_prepare`

### Synopsis

```

int SPI_execute_plan(SPIPlanPtr plan, Datum * values, const char * nulls,
                     bool read_only, long count)
```

### Description

`SPI_execute_plan` executes a statement prepared by `SPI_prepare` or one of its siblings. *`read_only`* and *`count`* have the same interpretation as in `SPI_execute`.

### Arguments

`SPIPlanPtr`` `*`plan`*

prepared statement (returned by `SPI_prepare`)

`Datum *`` `*`values`*

An array of actual parameter values. Must have same length as the statement's number of arguments.

`const char *`` `*`nulls`*

An array describing which parameters are null. Must have same length as the statement's number of arguments.

If *`nulls`* is `NULL` then `SPI_execute_plan` assumes that no parameters are null. Otherwise, each entry of the *`nulls`* array should be `' '` if the corresponding parameter value is non-null, or `'n'` if the corresponding parameter value is null. (In the latter case, the actual value in the corresponding *`values`* entry doesn't matter.) Note that *`nulls`* is not a text string, just an array: it does not need a `'\0'` terminator.

`bool`` `*`read_only`*

`true` for read-only execution

`long`` `*`count`*

maximum number of rows to return, or `0` for no limit

### Return Value

The return value is the same as for `SPI_execute`, with the following additional possible error (negative) results:

`SPI_ERROR_ARGUMENT`

if *`plan`* is `NULL` or invalid, or *`count`* is less than 0

`SPI_ERROR_PARAM`

if *`values`* is `NULL` and *`plan`* was prepared with some parameters

`SPI_processed` and `SPI_tuptable` are set as in `SPI_execute` if successful.

***

原文：[PostgreSQL 15.19 Documentation](/15/server-programming/server-programming-interface/spi-interface/spi-spi-execute-plan.md)（英文原文，待翻譯）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/15/server-programming/server-programming-interface/spi-interface/spi-spi-execute-plan.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
