#include "fmgr.h"#include "access/tupdesc.h"#include "executor/executor.h"#include "executor/tuptable.h"
Go to the source code of this file.
Data Structures | |
| struct | AttInMetadata |
| struct | FuncCallContext |
Defines | |
| #define | HeapTupleGetDatum(_tuple) PointerGetDatum((_tuple)->t_data) |
| #define | TupleGetDatum(_slot, _tuple) PointerGetDatum((_tuple)->t_data) |
| #define | SRF_IS_FIRSTCALL() (fcinfo->flinfo->fn_extra == NULL) |
| #define | SRF_FIRSTCALL_INIT() init_MultiFuncCall(fcinfo) |
| #define | SRF_PERCALL_SETUP() per_MultiFuncCall(fcinfo) |
| #define | SRF_RETURN_NEXT(_funcctx, _result) |
| #define | SRF_RETURN_DONE(_funcctx) |
Typedefs | |
| typedef struct AttInMetadata | AttInMetadata |
| typedef struct FuncCallContext | FuncCallContext |
| typedef enum TypeFuncClass | TypeFuncClass |
Enumerations | |
| enum | TypeFuncClass { TYPEFUNC_SCALAR, TYPEFUNC_COMPOSITE, TYPEFUNC_RECORD, TYPEFUNC_OTHER } |
Functions | |
| TypeFuncClass | get_call_result_type (FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc) |
| TypeFuncClass | get_expr_result_type (Node *expr, Oid *resultTypeId, TupleDesc *resultTupleDesc) |
| TypeFuncClass | get_func_result_type (Oid functionId, Oid *resultTypeId, TupleDesc *resultTupleDesc) |
| bool | resolve_polymorphic_argtypes (int numargs, Oid *argtypes, char *argmodes, Node *call_expr) |
| int | get_func_arg_info (HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, char **p_argmodes) |
| int | get_func_input_arg_names (Datum proargnames, Datum proargmodes, char ***arg_names) |
| char * | get_func_result_name (Oid functionId) |
| TupleDesc | build_function_result_tupdesc_d (Datum proallargtypes, Datum proargmodes, Datum proargnames) |
| TupleDesc | build_function_result_tupdesc_t (HeapTuple procTuple) |
| TupleDesc | RelationNameGetTupleDesc (const char *relname) |
| TupleDesc | TypeGetTupleDesc (Oid typeoid, List *colaliases) |
| TupleDesc | BlessTupleDesc (TupleDesc tupdesc) |
| AttInMetadata * | TupleDescGetAttInMetadata (TupleDesc tupdesc) |
| HeapTuple | BuildTupleFromCStrings (AttInMetadata *attinmeta, char **values) |
| TupleTableSlot * | TupleDescGetSlot (TupleDesc tupdesc) |
| FuncCallContext * | init_MultiFuncCall (PG_FUNCTION_ARGS) |
| FuncCallContext * | per_MultiFuncCall (PG_FUNCTION_ARGS) |
| void | end_MultiFuncCall (PG_FUNCTION_ARGS, FuncCallContext *funcctx) |
| #define HeapTupleGetDatum | ( | _tuple | ) | PointerGetDatum((_tuple)->t_data) |
Definition at line 219 of file funcapi.h.
Referenced by aclexplode(), bt_metap(), bt_page_items(), bt_page_stats(), build_pgstattuple_type(), dblink_get_pkey(), exec_eval_datum(), ExecEvalConvertRowtype(), ExecEvalFieldStore(), ExecEvalRow(), heap_page_items(), hstore_each(), hstore_populate_record(), json_populate_record(), page_header(), pg_buffercache_pages(), pg_get_keywords(), pg_get_multixact_members(), pg_identify_object(), pg_lock_status(), pg_logdir_ls(), pg_prepared_xact(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_activity(), pg_timezone_abbrevs(), pg_timezone_names(), pg_xlogfile_name_offset(), pgrowlocks(), pgstatginindex(), pgstatindex(), plperl_hash_to_datum(), PLyGenericObject_ToComposite(), PLyMapping_ToComposite(), PLySequence_ToComposite(), prs_process_call(), show_all_settings(), ts_process_call(), and tt_process_call().
| #define SRF_FIRSTCALL_INIT | ( | ) | init_MultiFuncCall(fcinfo) |
Definition at line 283 of file funcapi.h.
Referenced by aclexplode(), array_unnest(), bt_page_items(), dblink_get_pkey(), generate_series_step_int4(), generate_series_step_int8(), generate_series_timestamp(), generate_series_timestamptz(), generate_subscripts(), heap_page_items(), hstore_each(), hstore_skeys(), hstore_svals(), json_object_keys(), normal_rand(), pg_buffercache_pages(), pg_get_keywords(), pg_get_multixact_members(), pg_listening_channels(), pg_lock_status(), pg_logdir_ls(), pg_ls_dir(), pg_prepared_xact(), pg_stat_get_activity(), pg_stat_get_backend_idset(), pg_tablespace_databases(), pg_timezone_abbrevs(), pg_timezone_names(), pgrowlocks(), regexp_matches(), regexp_split_to_table(), show_all_settings(), ts_parse_byid(), ts_parse_byname(), ts_stat1(), ts_stat2(), ts_token_type_byid(), ts_token_type_byname(), and txid_snapshot_xip().
| #define SRF_IS_FIRSTCALL | ( | ) | (fcinfo->flinfo->fn_extra == NULL) |
Definition at line 281 of file funcapi.h.
Referenced by aclexplode(), array_unnest(), bt_page_items(), dblink_get_pkey(), generate_series_step_int4(), generate_series_step_int8(), generate_series_timestamp(), generate_series_timestamptz(), generate_subscripts(), heap_page_items(), hstore_each(), hstore_skeys(), hstore_svals(), json_object_keys(), normal_rand(), pg_buffercache_pages(), pg_get_keywords(), pg_get_multixact_members(), pg_listening_channels(), pg_lock_status(), pg_logdir_ls(), pg_ls_dir(), pg_prepared_xact(), pg_stat_get_activity(), pg_stat_get_backend_idset(), pg_tablespace_databases(), pg_timezone_abbrevs(), pg_timezone_names(), pgrowlocks(), regexp_matches(), regexp_split_to_table(), show_all_settings(), ts_parse_byid(), ts_parse_byname(), ts_stat1(), ts_stat2(), ts_token_type_byid(), ts_token_type_byname(), and txid_snapshot_xip().
| #define SRF_PERCALL_SETUP | ( | ) | per_MultiFuncCall(fcinfo) |
Definition at line 285 of file funcapi.h.
Referenced by aclexplode(), array_unnest(), bt_page_items(), dblink_get_pkey(), generate_series_step_int4(), generate_series_step_int8(), generate_series_timestamp(), generate_series_timestamptz(), generate_subscripts(), heap_page_items(), hstore_each(), hstore_skeys(), hstore_svals(), json_object_keys(), normal_rand(), pg_buffercache_pages(), pg_get_keywords(), pg_get_multixact_members(), pg_listening_channels(), pg_lock_status(), pg_logdir_ls(), pg_ls_dir(), pg_prepared_xact(), pg_stat_get_activity(), pg_stat_get_backend_idset(), pg_tablespace_databases(), pg_timezone_abbrevs(), pg_timezone_names(), pgrowlocks(), regexp_matches(), regexp_split_to_table(), show_all_settings(), ts_parse_byid(), ts_parse_byname(), ts_stat1(), ts_stat2(), ts_token_type_byid(), ts_token_type_byname(), and txid_snapshot_xip().
| #define SRF_RETURN_DONE | ( | _funcctx | ) |
do { \ ReturnSetInfo *rsi; \ end_MultiFuncCall(fcinfo, _funcctx); \ rsi = (ReturnSetInfo *) fcinfo->resultinfo; \ rsi->isDone = ExprEndResult; \ PG_RETURN_NULL(); \ } while (0)
Definition at line 296 of file funcapi.h.
Referenced by aclexplode(), array_unnest(), bt_page_items(), dblink_get_pkey(), generate_series_step_int4(), generate_series_step_int8(), generate_series_timestamp(), generate_series_timestamptz(), generate_subscripts(), heap_page_items(), hstore_each(), hstore_skeys(), hstore_svals(), json_object_keys(), normal_rand(), pg_buffercache_pages(), pg_get_keywords(), pg_get_multixact_members(), pg_listening_channels(), pg_lock_status(), pg_logdir_ls(), pg_ls_dir(), pg_prepared_xact(), pg_stat_get_activity(), pg_stat_get_backend_idset(), pg_tablespace_databases(), pg_timezone_abbrevs(), pg_timezone_names(), pgrowlocks(), regexp_matches(), regexp_split_to_table(), show_all_settings(), ts_parse_byid(), ts_parse_byname(), ts_stat1(), ts_stat2(), ts_token_type_byid(), ts_token_type_byname(), and txid_snapshot_xip().
| #define SRF_RETURN_NEXT | ( | _funcctx, | ||
| _result | ||||
| ) |
do { \ ReturnSetInfo *rsi; \ (_funcctx)->call_cntr++; \ rsi = (ReturnSetInfo *) fcinfo->resultinfo; \ rsi->isDone = ExprMultipleResult; \ PG_RETURN_DATUM(_result); \ } while (0)
Definition at line 287 of file funcapi.h.
Referenced by aclexplode(), array_unnest(), bt_page_items(), dblink_get_pkey(), generate_series_step_int4(), generate_series_step_int8(), generate_series_timestamp(), generate_series_timestamptz(), generate_subscripts(), heap_page_items(), hstore_each(), hstore_skeys(), hstore_svals(), json_object_keys(), normal_rand(), pg_buffercache_pages(), pg_get_keywords(), pg_get_multixact_members(), pg_listening_channels(), pg_lock_status(), pg_logdir_ls(), pg_ls_dir(), pg_prepared_xact(), pg_stat_get_activity(), pg_stat_get_backend_idset(), pg_tablespace_databases(), pg_timezone_abbrevs(), pg_timezone_names(), pgrowlocks(), regexp_matches(), regexp_split_to_table(), show_all_settings(), ts_parse_byid(), ts_parse_byname(), ts_stat1(), ts_stat2(), ts_token_type_byid(), ts_token_type_byname(), and txid_snapshot_xip().
| #define TupleGetDatum | ( | _slot, | ||
| _tuple | ||||
| ) | PointerGetDatum((_tuple)->t_data) |
| typedef struct AttInMetadata AttInMetadata |
| typedef struct FuncCallContext FuncCallContext |
| typedef enum TypeFuncClass TypeFuncClass |
| enum TypeFuncClass |
Definition at line 150 of file funcapi.h.
{
TYPEFUNC_SCALAR, /* scalar result type */
TYPEFUNC_COMPOSITE, /* determinable rowtype result */
TYPEFUNC_RECORD, /* indeterminate rowtype result */
TYPEFUNC_OTHER /* bogus type, eg pseudotype */
} TypeFuncClass;
Definition at line 1001 of file execTuples.c.
References assign_record_type_typmod(), RECORDOID, tupleDesc::tdtypeid, and tupleDesc::tdtypmod.
Referenced by aclexplode(), each_worker(), exec_eval_datum(), exec_get_datum_type(), exec_get_datum_type_info(), ExecInitExpr(), ExecInitFunctionScan(), init_sql_fcache(), json_array_elements(), json_populate_recordset(), pg_buffercache_pages(), pg_identify_object(), pg_lock_status(), pg_prepared_xact(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_activity(), pg_timezone_abbrevs(), pg_timezone_names(), pg_xlogfile_name_offset(), PLy_output_record_funcs(), setup_firstcall(), ts_setup_firstcall(), TupleDescGetAttInMetadata(), and TupleDescGetSlot().
{
if (tupdesc->tdtypeid == RECORDOID &&
tupdesc->tdtypmod < 0)
assign_record_type_typmod(tupdesc);
return tupdesc; /* just for notational convenience */
}
| TupleDesc build_function_result_tupdesc_d | ( | Datum | proallargtypes, | |
| Datum | proargmodes, | |||
| Datum | proargnames | |||
| ) |
Definition at line 1128 of file funcapi.c.
References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, Assert, CHAROID, CreateTemplateTupleDesc(), DatumGetArrayTypeP, deconstruct_array(), elog, ERROR, i, NULL, OIDOID, palloc(), PointerGetDatum, PROARGMODE_IN, PROARGMODE_INOUT, PROARGMODE_OUT, PROARGMODE_TABLE, PROARGMODE_VARIADIC, snprintf(), TextDatumGetCString, TEXTOID, and TupleDescInitEntry().
Referenced by build_function_result_tupdesc_t(), and ProcedureCreate().
{
TupleDesc desc;
ArrayType *arr;
int numargs;
Oid *argtypes;
char *argmodes;
Datum *argnames = NULL;
Oid *outargtypes;
char **outargnames;
int numoutargs;
int nargnames;
int i;
/* Can't have output args if columns are null */
if (proallargtypes == PointerGetDatum(NULL) ||
proargmodes == PointerGetDatum(NULL))
return NULL;
/*
* We expect the arrays to be 1-D arrays of the right types; verify that.
* For the OID and char arrays, we don't need to use deconstruct_array()
* since the array data is just going to look like a C array of values.
*/
arr = DatumGetArrayTypeP(proallargtypes); /* ensure not toasted */
numargs = ARR_DIMS(arr)[0];
if (ARR_NDIM(arr) != 1 ||
numargs < 0 ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != OIDOID)
elog(ERROR, "proallargtypes is not a 1-D Oid array");
argtypes = (Oid *) ARR_DATA_PTR(arr);
arr = DatumGetArrayTypeP(proargmodes); /* ensure not toasted */
if (ARR_NDIM(arr) != 1 ||
ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID)
elog(ERROR, "proargmodes is not a 1-D char array");
argmodes = (char *) ARR_DATA_PTR(arr);
if (proargnames != PointerGetDatum(NULL))
{
arr = DatumGetArrayTypeP(proargnames); /* ensure not toasted */
if (ARR_NDIM(arr) != 1 ||
ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array");
deconstruct_array(arr, TEXTOID, -1, false, 'i',
&argnames, NULL, &nargnames);
Assert(nargnames == numargs);
}
/* zero elements probably shouldn't happen, but handle it gracefully */
if (numargs <= 0)
return NULL;
/* extract output-argument types and names */
outargtypes = (Oid *) palloc(numargs * sizeof(Oid));
outargnames = (char **) palloc(numargs * sizeof(char *));
numoutargs = 0;
for (i = 0; i < numargs; i++)
{
char *pname;
if (argmodes[i] == PROARGMODE_IN ||
argmodes[i] == PROARGMODE_VARIADIC)
continue;
Assert(argmodes[i] == PROARGMODE_OUT ||
argmodes[i] == PROARGMODE_INOUT ||
argmodes[i] == PROARGMODE_TABLE);
outargtypes[numoutargs] = argtypes[i];
if (argnames)
pname = TextDatumGetCString(argnames[i]);
else
pname = NULL;
if (pname == NULL || pname[0] == '\0')
{
/* Parameter is not named, so gin up a column name */
pname = (char *) palloc(32);
snprintf(pname, 32, "column%d", numoutargs + 1);
}
outargnames[numoutargs] = pname;
numoutargs++;
}
/*
* If there is no output argument, or only one, the function does not
* return tuples.
*/
if (numoutargs < 2)
return NULL;
desc = CreateTemplateTupleDesc(numoutargs, false);
for (i = 0; i < numoutargs; i++)
{
TupleDescInitEntry(desc, i + 1,
outargnames[i],
outargtypes[i],
-1,
0);
}
return desc;
}
Definition at line 1080 of file funcapi.c.
References Anum_pg_proc_proallargtypes, Anum_pg_proc_proargmodes, Anum_pg_proc_proargnames, Assert, build_function_result_tupdesc_d(), GETSTRUCT, heap_attisnull(), NULL, PointerGetDatum, PROCOID, RECORDOID, and SysCacheGetAttr().
Referenced by internal_get_result_type(), and ProcedureCreate().
{
Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(procTuple);
Datum proallargtypes;
Datum proargmodes;
Datum proargnames;
bool isnull;
/* Return NULL if the function isn't declared to return RECORD */
if (procform->prorettype != RECORDOID)
return NULL;
/* If there are no OUT parameters, return NULL */
if (heap_attisnull(procTuple, Anum_pg_proc_proallargtypes) ||
heap_attisnull(procTuple, Anum_pg_proc_proargmodes))
return NULL;
/* Get the data out of the tuple */
proallargtypes = SysCacheGetAttr(PROCOID, procTuple,
Anum_pg_proc_proallargtypes,
&isnull);
Assert(!isnull);
proargmodes = SysCacheGetAttr(PROCOID, procTuple,
Anum_pg_proc_proargmodes,
&isnull);
Assert(!isnull);
proargnames = SysCacheGetAttr(PROCOID, procTuple,
Anum_pg_proc_proargnames,
&isnull);
if (isnull)
proargnames = PointerGetDatum(NULL); /* just to be sure */
return build_function_result_tupdesc_d(proallargtypes,
proargmodes,
proargnames);
}
| HeapTuple BuildTupleFromCStrings | ( | AttInMetadata * | attinmeta, | |
| char ** | values | |||
| ) |
Definition at line 1085 of file execTuples.c.
References AttInMetadata::attinfuncs, AttInMetadata::attioparams, tupleDesc::attrs, AttInMetadata::atttypmods, heap_form_tuple(), i, InputFunctionCall(), tupleDesc::natts, NULL, palloc(), pfree(), and AttInMetadata::tupdesc.
Referenced by bt_metap(), bt_page_items(), bt_page_stats(), build_pgstattuple_type(), build_tuplestore_recursively(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), materializeQueryResult(), materializeResult(), pg_get_keywords(), pg_get_multixact_members(), pg_logdir_ls(), pgrowlocks(), pgstatindex(), prs_process_call(), show_all_settings(), storeRow(), ts_process_call(), tt_process_call(), and xpath_table().
{
TupleDesc tupdesc = attinmeta->tupdesc;
int natts = tupdesc->natts;
Datum *dvalues;
bool *nulls;
int i;
HeapTuple tuple;
dvalues = (Datum *) palloc(natts * sizeof(Datum));
nulls = (bool *) palloc(natts * sizeof(bool));
/* Call the "in" function for each non-dropped attribute */
for (i = 0; i < natts; i++)
{
if (!tupdesc->attrs[i]->attisdropped)
{
/* Non-dropped attributes */
dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
values[i],
attinmeta->attioparams[i],
attinmeta->atttypmods[i]);
if (values[i] != NULL)
nulls[i] = false;
else
nulls[i] = true;
}
else
{
/* Handle dropped attributes by setting to NULL */
dvalues[i] = (Datum) 0;
nulls[i] = true;
}
}
/*
* Form a tuple
*/
tuple = heap_form_tuple(tupdesc, dvalues, nulls);
/*
* Release locally palloc'd space. XXX would probably be good to pfree
* values of pass-by-reference datums, as well.
*/
pfree(dvalues);
pfree(nulls);
return tuple;
}
| void end_MultiFuncCall | ( | PG_FUNCTION_ARGS | , | |
| FuncCallContext * | funcctx | |||
| ) |
Definition at line 156 of file funcapi.c.
References ReturnSetInfo::econtext, PointerGetDatum, shutdown_MultiFuncCall(), and UnregisterExprContextCallback().
{
ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo;
/* Deregister the shutdown callback */
UnregisterExprContextCallback(rsi->econtext,
shutdown_MultiFuncCall,
PointerGetDatum(fcinfo->flinfo));
/* But use it to do the real work */
shutdown_MultiFuncCall(PointerGetDatum(fcinfo->flinfo));
}
| TypeFuncClass get_call_result_type | ( | FunctionCallInfo | fcinfo, | |
| Oid * | resultTypeId, | |||
| TupleDesc * | resultTupleDesc | |||
| ) |
Definition at line 212 of file funcapi.c.
References FunctionCallInfoData::flinfo, FmgrInfo::fn_expr, FmgrInfo::fn_oid, internal_get_result_type(), and FunctionCallInfoData::resultinfo.
Referenced by bt_metap(), bt_page_items(), bt_page_stats(), build_pgstattuple_type(), crosstab(), each_worker(), heap_page_items(), json_populate_recordset(), materializeResult(), page_header(), pg_available_extension_versions(), pg_available_extensions(), pg_event_trigger_dropped_objects(), pg_extension_update_paths(), pg_stat_get_wal_senders(), pg_stat_statements(), pgrowlocks(), pgstatginindex(), pgstatindex(), plperl_return_next(), plperl_sv_to_datum(), plpgsql_exec_function(), PLy_function_build_args(), setup_firstcall(), and storeRow().
{
return internal_get_result_type(fcinfo->flinfo->fn_oid,
fcinfo->flinfo->fn_expr,
(ReturnSetInfo *) fcinfo->resultinfo,
resultTypeId,
resultTupleDesc);
}
| TypeFuncClass get_expr_result_type | ( | Node * | expr, | |
| Oid * | resultTypeId, | |||
| TupleDesc * | resultTupleDesc | |||
| ) |
Definition at line 228 of file funcapi.c.
References exprType(), get_opcode(), get_type_func_class(), internal_get_result_type(), IsA, lookup_rowtype_tupdesc_copy(), NULL, and TYPEFUNC_COMPOSITE.
Referenced by addRangeTableEntryForFunction(), ExecInitFunctionScan(), expandRecordVariable(), ExpandRowReference(), expandRTE(), get_name_for_var_field(), get_rte_attribute_type(), init_fcache(), and ParseComplexProjection().
{
TypeFuncClass result;
if (expr && IsA(expr, FuncExpr))
result = internal_get_result_type(((FuncExpr *) expr)->funcid,
expr,
NULL,
resultTypeId,
resultTupleDesc);
else if (expr && IsA(expr, OpExpr))
result = internal_get_result_type(get_opcode(((OpExpr *) expr)->opno),
expr,
NULL,
resultTypeId,
resultTupleDesc);
else
{
/* handle as a generic expression; no chance to resolve RECORD */
Oid typid = exprType(expr);
if (resultTypeId)
*resultTypeId = typid;
if (resultTupleDesc)
*resultTupleDesc = NULL;
result = get_type_func_class(typid);
if (result == TYPEFUNC_COMPOSITE && resultTupleDesc)
*resultTupleDesc = lookup_rowtype_tupdesc_copy(typid, -1);
}
return result;
}
| int get_func_arg_info | ( | HeapTuple | procTup, | |
| Oid ** | p_argtypes, | |||
| char *** | p_argnames, | |||
| char ** | p_argmodes | |||
| ) |
Definition at line 792 of file funcapi.c.
References Anum_pg_proc_proallargtypes, Anum_pg_proc_proargmodes, Anum_pg_proc_proargnames, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, Assert, CHAROID, DatumGetArrayTypeP, deconstruct_array(), elog, ERROR, GETSTRUCT, i, NULL, OIDOID, palloc(), PROCOID, SysCacheGetAttr(), TextDatumGetCString, and TEXTOID.
Referenced by do_compile(), MatchNamedCall(), plperl_validator(), plpgsql_validator(), PLy_procedure_create(), and print_function_arguments().
{
Form_pg_proc procStruct = (Form_pg_proc) GETSTRUCT(procTup);
Datum proallargtypes;
Datum proargmodes;
Datum proargnames;
bool isNull;
ArrayType *arr;
int numargs;
Datum *elems;
int nelems;
int i;
/* First discover the total number of parameters and get their types */
proallargtypes = SysCacheGetAttr(PROCOID, procTup,
Anum_pg_proc_proallargtypes,
&isNull);
if (!isNull)
{
/*
* We expect the arrays to be 1-D arrays of the right types; verify
* that. For the OID and char arrays, we don't need to use
* deconstruct_array() since the array data is just going to look like
* a C array of values.
*/
arr = DatumGetArrayTypeP(proallargtypes); /* ensure not toasted */
numargs = ARR_DIMS(arr)[0];
if (ARR_NDIM(arr) != 1 ||
numargs < 0 ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != OIDOID)
elog(ERROR, "proallargtypes is not a 1-D Oid array");
Assert(numargs >= procStruct->pronargs);
*p_argtypes = (Oid *) palloc(numargs * sizeof(Oid));
memcpy(*p_argtypes, ARR_DATA_PTR(arr),
numargs * sizeof(Oid));
}
else
{
/* If no proallargtypes, use proargtypes */
numargs = procStruct->proargtypes.dim1;
Assert(numargs == procStruct->pronargs);
*p_argtypes = (Oid *) palloc(numargs * sizeof(Oid));
memcpy(*p_argtypes, procStruct->proargtypes.values,
numargs * sizeof(Oid));
}
/* Get argument names, if available */
proargnames = SysCacheGetAttr(PROCOID, procTup,
Anum_pg_proc_proargnames,
&isNull);
if (isNull)
*p_argnames = NULL;
else
{
deconstruct_array(DatumGetArrayTypeP(proargnames),
TEXTOID, -1, false, 'i',
&elems, NULL, &nelems);
if (nelems != numargs) /* should not happen */
elog(ERROR, "proargnames must have the same number of elements as the function has arguments");
*p_argnames = (char **) palloc(sizeof(char *) * numargs);
for (i = 0; i < numargs; i++)
(*p_argnames)[i] = TextDatumGetCString(elems[i]);
}
/* Get argument modes, if available */
proargmodes = SysCacheGetAttr(PROCOID, procTup,
Anum_pg_proc_proargmodes,
&isNull);
if (isNull)
*p_argmodes = NULL;
else
{
arr = DatumGetArrayTypeP(proargmodes); /* ensure not toasted */
if (ARR_NDIM(arr) != 1 ||
ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID)
elog(ERROR, "proargmodes is not a 1-D char array");
*p_argmodes = (char *) palloc(numargs * sizeof(char));
memcpy(*p_argmodes, ARR_DATA_PTR(arr),
numargs * sizeof(char));
}
return numargs;
}
Definition at line 892 of file funcapi.c.
References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, CHAROID, DatumGetArrayTypeP, deconstruct_array(), elog, ERROR, i, NULL, palloc(), PointerGetDatum, PROARGMODE_IN, PROARGMODE_INOUT, PROARGMODE_VARIADIC, TextDatumGetCString, and TEXTOID.
Referenced by prepare_sql_fn_parse_info(), and ProcedureCreate().
{
ArrayType *arr;
int numargs;
Datum *argnames;
char *argmodes;
char **inargnames;
int numinargs;
int i;
/* Do nothing if null proargnames */
if (proargnames == PointerGetDatum(NULL))
{
*arg_names = NULL;
return 0;
}
/*
* We expect the arrays to be 1-D arrays of the right types; verify that.
* For proargmodes, we don't need to use deconstruct_array() since the
* array data is just going to look like a C array of values.
*/
arr = DatumGetArrayTypeP(proargnames); /* ensure not toasted */
if (ARR_NDIM(arr) != 1 ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array");
deconstruct_array(arr, TEXTOID, -1, false, 'i',
&argnames, NULL, &numargs);
if (proargmodes != PointerGetDatum(NULL))
{
arr = DatumGetArrayTypeP(proargmodes); /* ensure not toasted */
if (ARR_NDIM(arr) != 1 ||
ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID)
elog(ERROR, "proargmodes is not a 1-D char array");
argmodes = (char *) ARR_DATA_PTR(arr);
}
else
argmodes = NULL;
/* zero elements probably shouldn't happen, but handle it gracefully */
if (numargs <= 0)
{
*arg_names = NULL;
return 0;
}
/* extract input-argument names */
inargnames = (char **) palloc(numargs * sizeof(char *));
numinargs = 0;
for (i = 0; i < numargs; i++)
{
if (argmodes == NULL ||
argmodes[i] == PROARGMODE_IN ||
argmodes[i] == PROARGMODE_INOUT ||
argmodes[i] == PROARGMODE_VARIADIC)
{
char *pname = TextDatumGetCString(argnames[i]);
if (pname[0] != '\0')
inargnames[numinargs] = pname;
else
inargnames[numinargs] = NULL;
numinargs++;
}
}
*arg_names = inargnames;
return numinargs;
}
| char* get_func_result_name | ( | Oid | functionId | ) |
Definition at line 977 of file funcapi.c.
References Anum_pg_proc_proargmodes, Anum_pg_proc_proargnames, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, Assert, CHAROID, DatumGetArrayTypeP, deconstruct_array(), elog, ERROR, heap_attisnull(), HeapTupleIsValid, i, NULL, ObjectIdGetDatum, PROARGMODE_IN, PROARGMODE_INOUT, PROARGMODE_OUT, PROARGMODE_TABLE, PROARGMODE_VARIADIC, PROCOID, ReleaseSysCache(), SearchSysCache1, SysCacheGetAttr(), TextDatumGetCString, and TEXTOID.
Referenced by buildScalarFunctionAlias().
{
char *result;
HeapTuple procTuple;
Datum proargmodes;
Datum proargnames;
bool isnull;
ArrayType *arr;
int numargs;
char *argmodes;
Datum *argnames;
int numoutargs;
int nargnames;
int i;
/* First fetch the function's pg_proc row */
procTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
if (!HeapTupleIsValid(procTuple))
elog(ERROR, "cache lookup failed for function %u", functionId);
/* If there are no named OUT parameters, return NULL */
if (heap_attisnull(procTuple, Anum_pg_proc_proargmodes) ||
heap_attisnull(procTuple, Anum_pg_proc_proargnames))
result = NULL;
else
{
/* Get the data out of the tuple */
proargmodes = SysCacheGetAttr(PROCOID, procTuple,
Anum_pg_proc_proargmodes,
&isnull);
Assert(!isnull);
proargnames = SysCacheGetAttr(PROCOID, procTuple,
Anum_pg_proc_proargnames,
&isnull);
Assert(!isnull);
/*
* We expect the arrays to be 1-D arrays of the right types; verify
* that. For the char array, we don't need to use deconstruct_array()
* since the array data is just going to look like a C array of
* values.
*/
arr = DatumGetArrayTypeP(proargmodes); /* ensure not toasted */
numargs = ARR_DIMS(arr)[0];
if (ARR_NDIM(arr) != 1 ||
numargs < 0 ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID)
elog(ERROR, "proargmodes is not a 1-D char array");
argmodes = (char *) ARR_DATA_PTR(arr);
arr = DatumGetArrayTypeP(proargnames); /* ensure not toasted */
if (ARR_NDIM(arr) != 1 ||
ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array");
deconstruct_array(arr, TEXTOID, -1, false, 'i',
&argnames, NULL, &nargnames);
Assert(nargnames == numargs);
/* scan for output argument(s) */
result = NULL;
numoutargs = 0;
for (i = 0; i < numargs; i++)
{
if (argmodes[i] == PROARGMODE_IN ||
argmodes[i] == PROARGMODE_VARIADIC)
continue;
Assert(argmodes[i] == PROARGMODE_OUT ||
argmodes[i] == PROARGMODE_INOUT ||
argmodes[i] == PROARGMODE_TABLE);
if (++numoutargs > 1)
{
/* multiple out args, so forget it */
result = NULL;
break;
}
result = TextDatumGetCString(argnames[i]);
if (result == NULL || result[0] == '\0')
{
/* Parameter is not named, so forget it */
result = NULL;
break;
}
}
}
ReleaseSysCache(procTuple);
return result;
}
| TypeFuncClass get_func_result_type | ( | Oid | functionId, | |
| Oid * | resultTypeId, | |||
| TupleDesc * | resultTupleDesc | |||
| ) |
Definition at line 270 of file funcapi.c.
References internal_get_result_type(), and NULL.
Referenced by check_sql_fn_retval(), and inline_set_returning_function().
{
return internal_get_result_type(functionId,
NULL,
NULL,
resultTypeId,
resultTupleDesc);
}
| FuncCallContext* init_MultiFuncCall | ( | PG_FUNCTION_ARGS | ) |
Definition at line 51 of file funcapi.c.
References ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE, ALLOCSET_SMALL_MINSIZE, AllocSetContextCreate(), FuncCallContext::attinmeta, FuncCallContext::call_cntr, ReturnSetInfo::econtext, elog, ereport, errcode(), errmsg(), ERROR, IsA, FuncCallContext::max_calls, MemoryContextAllocZero(), FuncCallContext::multi_call_memory_ctx, NULL, PointerGetDatum, RegisterExprContextCallback(), shutdown_MultiFuncCall(), FuncCallContext::slot, FuncCallContext::tuple_desc, and FuncCallContext::user_fctx.
{
FuncCallContext *retval;
/*
* Bail if we're called in the wrong context
*/
if (fcinfo->resultinfo == NULL || !IsA(fcinfo->resultinfo, ReturnSetInfo))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that cannot accept a set")));
if (fcinfo->flinfo->fn_extra == NULL)
{
/*
* First call
*/
ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo;
MemoryContext multi_call_ctx;
/*
* Create a suitably long-lived context to hold cross-call data
*/
multi_call_ctx = AllocSetContextCreate(fcinfo->flinfo->fn_mcxt,
"SRF multi-call context",
ALLOCSET_SMALL_MINSIZE,
ALLOCSET_SMALL_INITSIZE,
ALLOCSET_SMALL_MAXSIZE);
/*
* Allocate suitably long-lived space and zero it
*/
retval = (FuncCallContext *)
MemoryContextAllocZero(multi_call_ctx,
sizeof(FuncCallContext));
/*
* initialize the elements
*/
retval->call_cntr = 0;
retval->max_calls = 0;
retval->slot = NULL;
retval->user_fctx = NULL;
retval->attinmeta = NULL;
retval->tuple_desc = NULL;
retval->multi_call_memory_ctx = multi_call_ctx;
/*
* save the pointer for cross-call use
*/
fcinfo->flinfo->fn_extra = retval;
/*
* Ensure we will get shut down cleanly if the exprcontext is not run
* to completion.
*/
RegisterExprContextCallback(rsi->econtext,
shutdown_MultiFuncCall,
PointerGetDatum(fcinfo->flinfo));
}
else
{
/* second and subsequent calls */
elog(ERROR, "init_MultiFuncCall cannot be called more than once");
/* never reached, but keep compiler happy */
retval = NULL;
}
return retval;
}
| FuncCallContext* per_MultiFuncCall | ( | PG_FUNCTION_ARGS | ) |
Definition at line 129 of file funcapi.c.
References ExecClearTuple(), NULL, and FuncCallContext::slot.
{
FuncCallContext *retval = (FuncCallContext *) fcinfo->flinfo->fn_extra;
/*
* Clear the TupleTableSlot, if present. This is for safety's sake: the
* Slot will be in a long-lived context (it better be, if the
* FuncCallContext is pointing to it), but in most usage patterns the
* tuples stored in it will be in the function's per-tuple context. So at
* the beginning of each call, the Slot will hold a dangling pointer to an
* already-recycled tuple. We clear it out here.
*
* Note: use of retval->slot is obsolete as of 8.0, and we expect that it
* will always be NULL. This is just here for backwards compatibility in
* case someone creates a slot anyway.
*/
if (retval->slot != NULL)
ExecClearTuple(retval->slot);
return retval;
}
| TupleDesc RelationNameGetTupleDesc | ( | const char * | relname | ) |
Definition at line 1246 of file funcapi.c.
References AccessShareLock, CreateTupleDescCopy(), makeRangeVarFromNameList(), relation_close(), relation_openrv(), RelationGetDescr, and stringToQualifiedNameList().
{
RangeVar *relvar;
Relation rel;
TupleDesc tupdesc;
List *relname_list;
/* Open relation and copy the tuple description */
relname_list = stringToQualifiedNameList(relname);
relvar = makeRangeVarFromNameList(relname_list);
rel = relation_openrv(relvar, AccessShareLock);
tupdesc = CreateTupleDescCopy(RelationGetDescr(rel));
relation_close(rel, AccessShareLock);
return tupdesc;
}
| bool resolve_polymorphic_argtypes | ( | int | numargs, | |
| Oid * | argtypes, | |||
| char * | argmodes, | |||
| Node * | call_expr | |||
| ) |
Definition at line 598 of file funcapi.c.
References ANYARRAYOID, ANYELEMENTOID, ANYENUMOID, ANYNONARRAYOID, ANYRANGEOID, get_call_expr_argtype(), i, OidIsValid, PROARGMODE_OUT, PROARGMODE_TABLE, and resolve_generic_type().
Referenced by plpgsql_resolve_polymorphic_argtypes().
{
bool have_anyelement_result = false;
bool have_anyarray_result = false;
bool have_anyrange_result = false;
Oid anyelement_type = InvalidOid;
Oid anyarray_type = InvalidOid;
Oid anyrange_type = InvalidOid;
int inargno;
int i;
/* First pass: resolve polymorphic inputs, check for outputs */
inargno = 0;
for (i = 0; i < numargs; i++)
{
char argmode = argmodes ? argmodes[i] : PROARGMODE_IN;
switch (argtypes[i])
{
case ANYELEMENTOID:
case ANYNONARRAYOID:
case ANYENUMOID:
if (argmode == PROARGMODE_OUT || argmode == PROARGMODE_TABLE)
have_anyelement_result = true;
else
{
if (!OidIsValid(anyelement_type))
{
anyelement_type = get_call_expr_argtype(call_expr,
inargno);
if (!OidIsValid(anyelement_type))
return false;
}
argtypes[i] = anyelement_type;
}
break;
case ANYARRAYOID:
if (argmode == PROARGMODE_OUT || argmode == PROARGMODE_TABLE)
have_anyarray_result = true;
else
{
if (!OidIsValid(anyarray_type))
{
anyarray_type = get_call_expr_argtype(call_expr,
inargno);
if (!OidIsValid(anyarray_type))
return false;
}
argtypes[i] = anyarray_type;
}
break;
case ANYRANGEOID:
if (argmode == PROARGMODE_OUT || argmode == PROARGMODE_TABLE)
have_anyrange_result = true;
else
{
if (!OidIsValid(anyrange_type))
{
anyrange_type = get_call_expr_argtype(call_expr,
inargno);
if (!OidIsValid(anyrange_type))
return false;
}
argtypes[i] = anyrange_type;
}
break;
default:
break;
}
if (argmode != PROARGMODE_OUT && argmode != PROARGMODE_TABLE)
inargno++;
}
/* Done? */
if (!have_anyelement_result && !have_anyarray_result &&
!have_anyrange_result)
return true;
/* If no input polymorphics, parser messed up */
if (!OidIsValid(anyelement_type) && !OidIsValid(anyarray_type) &&
!OidIsValid(anyrange_type))
return false;
/* If needed, deduce one polymorphic type from others */
if (have_anyelement_result && !OidIsValid(anyelement_type))
{
if (OidIsValid(anyarray_type))
anyelement_type = resolve_generic_type(ANYELEMENTOID,
anyarray_type,
ANYARRAYOID);
if (OidIsValid(anyrange_type))
{
Oid subtype = resolve_generic_type(ANYELEMENTOID,
anyrange_type,
ANYRANGEOID);
/* check for inconsistent array and range results */
if (OidIsValid(anyelement_type) && anyelement_type != subtype)
return false;
anyelement_type = subtype;
}
}
if (have_anyarray_result && !OidIsValid(anyarray_type))
anyarray_type = resolve_generic_type(ANYARRAYOID,
anyelement_type,
ANYELEMENTOID);
/*
* We can't deduce a range type from other polymorphic inputs, because
* there may be multiple range types for the same subtype.
*/
if (have_anyrange_result && !OidIsValid(anyrange_type))
return false;
/* XXX do we need to enforce ANYNONARRAY or ANYENUM here? I think not */
/* And finally replace the output column types as needed */
for (i = 0; i < numargs; i++)
{
switch (argtypes[i])
{
case ANYELEMENTOID:
case ANYNONARRAYOID:
case ANYENUMOID:
argtypes[i] = anyelement_type;
break;
case ANYARRAYOID:
argtypes[i] = anyarray_type;
break;
case ANYRANGEOID:
argtypes[i] = anyrange_type;
break;
default:
break;
}
}
return true;
}
| AttInMetadata* TupleDescGetAttInMetadata | ( | TupleDesc | tupdesc | ) |
Definition at line 1038 of file execTuples.c.
References AttInMetadata::attinfuncs, AttInMetadata::attioparams, tupleDesc::attrs, AttInMetadata::atttypmods, BlessTupleDesc(), fmgr_info(), getTypeInputInfo(), i, tupleDesc::natts, palloc(), palloc0(), and AttInMetadata::tupdesc.
Referenced by bt_metap(), bt_page_items(), bt_page_stats(), build_pgstattuple_type(), connectby_text(), connectby_text_serial(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), materializeQueryResult(), materializeResult(), pg_get_keywords(), pg_get_multixact_members(), pg_logdir_ls(), pgrowlocks(), pgstatindex(), postgresAcquireSampleRowsFunc(), postgresBeginForeignModify(), postgresBeginForeignScan(), prs_setup_firstcall(), show_all_settings(), storeRow(), ts_setup_firstcall(), tt_setup_firstcall(), and xpath_table().
{
int natts = tupdesc->natts;
int i;
Oid atttypeid;
Oid attinfuncid;
FmgrInfo *attinfuncinfo;
Oid *attioparams;
int32 *atttypmods;
AttInMetadata *attinmeta;
attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata));
/* "Bless" the tupledesc so that we can make rowtype datums with it */
attinmeta->tupdesc = BlessTupleDesc(tupdesc);
/*
* Gather info needed later to call the "in" function for each attribute
*/
attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
attioparams = (Oid *) palloc0(natts * sizeof(Oid));
atttypmods = (int32 *) palloc0(natts * sizeof(int32));
for (i = 0; i < natts; i++)
{
/* Ignore dropped attributes */
if (!tupdesc->attrs[i]->attisdropped)
{
atttypeid = tupdesc->attrs[i]->atttypid;
getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
fmgr_info(attinfuncid, &attinfuncinfo[i]);
atttypmods[i] = tupdesc->attrs[i]->atttypmod;
}
}
attinmeta->attinfuncs = attinfuncinfo;
attinmeta->attioparams = attioparams;
attinmeta->atttypmods = atttypmods;
return attinmeta;
}
| TupleTableSlot* TupleDescGetSlot | ( | TupleDesc | tupdesc | ) |
Definition at line 1018 of file execTuples.c.
References BlessTupleDesc(), and MakeSingleTupleTableSlot().
{
TupleTableSlot *slot;
/* The useful work is here */
BlessTupleDesc(tupdesc);
/* Make a standalone slot */
slot = MakeSingleTupleTableSlot(tupdesc);
/* Return the slot */
return slot;
}
Definition at line 1279 of file funcapi.c.
References tupleDesc::attrs, CreateTemplateTupleDesc(), elog, ereport, errcode(), errmsg(), ERROR, get_type_func_class(), label, linitial, list_length(), list_nth(), lookup_rowtype_tupdesc_copy(), namestrcpy(), tupleDesc::natts, NIL, NULL, strVal, tupleDesc::tdtypeid, tupleDesc::tdtypmod, TupleDescInitEntry(), TYPEFUNC_COMPOSITE, TYPEFUNC_RECORD, and TYPEFUNC_SCALAR.
{
TypeFuncClass functypclass = get_type_func_class(typeoid);
TupleDesc tupdesc = NULL;
/*
* Build a suitable tupledesc representing the output rows
*/
if (functypclass == TYPEFUNC_COMPOSITE)
{
/* Composite data type, e.g. a table's row type */
tupdesc = lookup_rowtype_tupdesc_copy(typeoid, -1);
if (colaliases != NIL)
{
int natts = tupdesc->natts;
int varattno;
/* does the list length match the number of attributes? */
if (list_length(colaliases) != natts)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("number of aliases does not match number of columns")));
/* OK, use the aliases instead */
for (varattno = 0; varattno < natts; varattno++)
{
char *label = strVal(list_nth(colaliases, varattno));
if (label != NULL)
namestrcpy(&(tupdesc->attrs[varattno]->attname), label);
}
/* The tuple type is now an anonymous record type */
tupdesc->tdtypeid = RECORDOID;
tupdesc->tdtypmod = -1;
}
}
else if (functypclass == TYPEFUNC_SCALAR)
{
/* Base data type, i.e. scalar */
char *attname;
/* the alias list is required for base types */
if (colaliases == NIL)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("no column alias was provided")));
/* the alias list length must be 1 */
if (list_length(colaliases) != 1)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("number of aliases does not match number of columns")));
/* OK, get the column alias */
attname = strVal(linitial(colaliases));
tupdesc = CreateTemplateTupleDesc(1, false);
TupleDescInitEntry(tupdesc,
(AttrNumber) 1,
attname,
typeoid,
-1,
0);
}
else if (functypclass == TYPEFUNC_RECORD)
{
/* XXX can't support this because typmod wasn't passed in ... */
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("could not determine row description for function returning record")));
}
else
{
/* crummy error message, but parser should have caught this */
elog(ERROR, "function in FROM has unsupported return type");
}
return tupdesc;
}
1.7.1