1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-24 09:27:52 +03:00

Add result_types column to pg_prepared_statements view

Containing the types of the columns returned by the prepared
statement.

Prompted by question from IRC user mlvzk.

Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/871qwpo7te.fsf@wibble.ilmari.org
This commit is contained in:
Peter Eisentraut
2022-07-05 07:21:40 +02:00
parent eb64ceac7e
commit 84ad713cf8
7 changed files with 74 additions and 52 deletions

View File

@@ -683,8 +683,16 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
hash_seq_init(&hash_seq, prepared_queries);
while ((prep_stmt = hash_seq_search(&hash_seq)) != NULL)
{
Datum values[7];
bool nulls[7];
TupleDesc result_desc;
Oid *result_types;
Datum values[8];
bool nulls[8];
result_desc = prep_stmt->plansource->resultDesc;
result_types = (Oid *) palloc(result_desc->natts * sizeof(Oid));
for (int i = 0; i < result_desc->natts; i++)
result_types[i] = result_desc->attrs[i].atttypid;
MemSet(nulls, 0, sizeof(nulls));
@@ -693,9 +701,10 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
values[2] = TimestampTzGetDatum(prep_stmt->prepare_time);
values[3] = build_regtype_array(prep_stmt->plansource->param_types,
prep_stmt->plansource->num_params);
values[4] = BoolGetDatum(prep_stmt->from_sql);
values[5] = Int64GetDatumFast(prep_stmt->plansource->num_generic_plans);
values[6] = Int64GetDatumFast(prep_stmt->plansource->num_custom_plans);
values[4] = build_regtype_array(result_types, result_desc->natts);
values[5] = BoolGetDatum(prep_stmt->from_sql);
values[6] = Int64GetDatumFast(prep_stmt->plansource->num_generic_plans);
values[7] = Int64GetDatumFast(prep_stmt->plansource->num_custom_plans);
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
values, nulls);