pg_describe_prepared — Get information about a prepared statement


pg_describe_prepared conn statementName


pg_describe_prepared gets information about a prepared statement. A prepared statement is created with the SQL PREPARE command. A result structure is returned, for use with pg_result to get information about the prepared statement.



The handle of the connection on which the prepared statement is defined.


The name of the prepared statement to get information about.

Return Value

Returns a result handle which can be used with pg_result to obtain information about the prepared statement.


On success, a result structure which has status PGRES_COMMAND_OK will be returned. The result structure will have no data rows, only attribute (column) information, and parameter information. If no such prepared statement exists, the result structure will have status PGRES_FATAL_ERROR. A Tcl error may be thrown under other error conditions.

Use pg_result to get information from the returned result structure, and be sure to free the returned result handle with pg_result -clear when you are done with it. To get information about the prepared statement's parameters, use the pg_result options -numParams and -paramTypes.

This command uses or emulates the PostgreSQL libpq function PQdescribePrepared.

This command was added in pgtclng-1.7.0 and in pgintcl-3.1.0.


Create a prepared statement, and get information about its result columns and its parameters:

pg_execute $conn "PREPARE myst AS SELECT * FROM mytable \
    WHERE key BETWEEN \$1 AND \$2"
set result [pg_describe_prepared $conn myst]
if {[pg_result $result -status] eq "PGRES_COMMAND_OK"} {
  puts "Prepared statement columns are: [pg_result $result -attributes]"
  puts "Prepared statement has [pg_result $result -numParams] parameters."
  puts "Prepared statement parameter types: [pg_result $result -paramTypes]"
} Logo

This version of the manual was produced for the Pgtcl-ng Sourceforge project web service site, which requires the logo on each page.

To download a logo-free copy of the manual, see the Pgtcl-ng project downloads area.