Repository: duckdb/duckdb
File: src/function/table/system/duckdb_prepared_statements.cpp (C++)

Code before:
#include "duckdb/common/exception.hpp"
#include "duckdb/main/client_context.hpp"
#include "duckdb/parser/parser.hpp"
#include "duckdb/main/client_data.hpp"
#include "duckdb/main/prepared_statement_data.hpp"

namespace duckdb {

struct DuckDBPreparedStatementsData : public GlobalTableFunctionState {
	DuckDBPreparedStatementsData() : offset(0) {
	}

	vector<std::pair<string, shared_ptr<PreparedStatementData>>> entries;
	idx_t offset;
};

static unique_ptr<FunctionData> DuckDBPreparedStatementsBind(ClientContext &context, TableFunctionBindInput &input,
                                                             vector<LogicalType> &return_types, vector<string> &names) {
	names.emplace_back("name");
	return_types.emplace_back(LogicalType::VARCHAR);

	names.emplace_back("statement");
	return_types.emplace_back(LogicalType::VARCHAR);

	names.emplace_back("prepare_time");
	return_types.emplace_back(LogicalType::TIMESTAMP);

	names.emplace_back("parameter_types");
	return_types.emplace_back(LogicalType::LIST(LogicalType::VARCHAR));

	names.emplace_back("result_types");
	return_types.emplace_back(LogicalType::LIST(LogicalType::VARCHAR));

	names.emplace_back("from_sql");
	return_types.emplace_back(LogicalType::BOOLEAN);

	names.emplace_back("generic_plans");
	return_types.emplace_back(LogicalType::BIGINT);

	names.emplace_back("custom_plans");
	return_types.emplace_back(LogicalType::BIGINT);

	return nullptr;
}

unique_ptr<GlobalTableFunctionState> DuckDBPreparedStatementsInit(ClientContext &context,
                                                                  TableFunctionInitInput &input) {
	auto result = make_uniq<DuckDBPreparedStatementsData>();
	auto &prepared_statements = context.client_data->prepared_statements;
	for (auto &it : prepared_statements) {
		result->entries.emplace_back(it.first, it.second);

Review comment (suggestion):
We don't need to have properties we don't support here - the `duckdb_XXX` functions are always subject to additions in the future. We can just introduce unsupported elements in the view that we create for `pg_prepared_statements` as constants

Code after:
#include "duckdb/common/exception.hpp"
#include "duckdb/main/client_context.hpp"
#include "duckdb/parser/parser.hpp"
#include "duckdb/main/client_data.hpp"
#include "duckdb/main/prepared_statement_data.hpp"

namespace duckdb {

struct DuckDBPreparedStatementsData : public GlobalTableFunctionState {
	DuckDBPreparedStatementsData() : offset(0) {
	}

	vector<std::pair<string, shared_ptr<PreparedStatementData>>> entries;
	idx_t offset;
};

static unique_ptr<FunctionData> DuckDBPreparedStatementsBind(ClientContext &context, TableFunctionBindInput &input,
                                                             vector<LogicalType> &return_types, vector<string> &names) {
	names.emplace_back("name");
	return_types.emplace_back(LogicalType::VARCHAR);

	names.emplace_back("statement");
	return_types.emplace_back(LogicalType::VARCHAR);

	names.emplace_back("parameter_types");
	return_types.emplace_back(LogicalType::LIST(LogicalType::VARCHAR));

	names.emplace_back("result_types");
	return_types.emplace_back(LogicalType::LIST(LogicalType::VARCHAR));
	return nullptr;
}

unique_ptr<GlobalTableFunctionState> DuckDBPreparedStatementsInit(ClientContext &context,
                                                                  TableFunctionInitInput &input) {
	auto result = make_uniq<DuckDBPreparedStatementsData>();
	auto &prepared_statements = context.client_data->prepared_statements;
	for (auto &it : prepared_statements) {
		result->entries.emplace_back(it.first, it.second);
	}
	return std::move(result);
}

void DuckDBPreparedStatementsFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
	auto &data = data_p.global_state->Cast<DuckDBPreparedStatementsData>();
	if (data.offset >= data.entries.size()) {
		// finished returning values
		return;
	}
	// start returning values
	// either fill up the chunk or return all the remaining columns
	idx_t count = 0;