Summary
The pg_prepared_statements view displays all the prepared statements that are available in the current session. See prepare for more information about prepared statements.
(Description quoted from the official PostgreSQL documentation.)
Columns
The pg_prepared_statements system view exposes the following columns (names, types and descriptions are taken verbatim from the PostgreSQL documentation):
nametext
The identifier of the prepared statementstatementtext
The query string submitted by the client to create this prepared statement. For prepared statements created via SQL, this is the PREPARE statement submitted by the client. For prepared statements created via the frontend/backend protocol, this is the text of the prepared statement itself.prepare_timetimestamptz
The time at which the prepared statement was createdparameter_typesregtype[]
The expected parameter types for the prepared statement in the form of an array of regtype. The OID corresponding to an element of this array can be obtained by casting the regtype value to oid.result_typesregtype[]
The types of the columns returned by the prepared statement in the form of an array of regtype. The OID corresponding to an element of this array can be obtained by casting the regtype value to oid. If the prepared statement does not provide a result (e.g., a DML statement), then this field will be null.from_sqlbool
true if the prepared statement was created via the PREPARE SQL command; false if the statement was prepared via the frontend/backend protocolgeneric_plansint8
Number of times generic plan was chosencustom_plansint8
Number of times custom plan was chosen
Version applicability
Present in PostgreSQL 17, 18, 19 (verified against each release’s documentation). This is a long-standing system object that also exists in earlier PostgreSQL releases.
Related & references
Reference: PostgreSQL documentation — pg_prepared_statements.