---
name: "SPI_keepplan"
section: "3"
platform: "linux"
package: "postgresql"
version: "18.6-4"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/SPI_keepplan"
---

# SPI\_keepplan(3)

save a prepared statement

## NAME

SPI\_keepplan - save a prepared statement

## SYNOPSIS

```
int SPI_keepplan(SPIPlanPtr plan)
```

## DESCRIPTION

**SPI\_keepplan** saves a passed statement (prepared by **SPI\_prepare**) so that it will not be freed by **SPI\_finish** nor by the transaction manager. This gives you the ability to reuse prepared statements in the subsequent invocations of your C function in the current session.

## ARGUMENTS

SPIPlanPtr *plan*

the prepared statement to be saved

## RETURN VALUE

0 on success; SPI\_ERROR\_ARGUMENT if *plan* is NULL or invalid

## NOTES

The passed-in statement is relocated to permanent storage by means of pointer adjustment (no data copying is required). If you later wish to delete it, use **SPI\_freeplan** on it.
