/* Handle "-" or numeric OID */ if (parseDashOrOid(pro_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* Else it's a name, possibly schema-qualified */
/* *Weshouldnevergethereinbootstrapmode,asallreferencesshould *havebeenresolvedbygenbki.pl.
*/ if (IsBootstrapProcessingMode())
elog(ERROR, "regproc values must be OIDs in bootstrap mode");
if (clist == NULL)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("function \"%s\" does not exist", pro_name_or_oid))); elseif (clist->next != NULL)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one function named \"%s\"",
pro_name_or_oid)));
result = clist->oid;
PG_RETURN_OID(result);
}
/* *to_regproc-converts"proname"toprocOID * *Ifthenameisnotfound,wereturnNULL.
*/
Datum
to_regproc(PG_FUNCTION_ARGS)
{ char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
ErrorSaveContext escontext = {T_ErrorSaveContext};
result = quote_qualified_identifier(nspname, proname);
}
ReleaseSysCache(proctup);
} else
{ /* If OID doesn't match any pg_proc entry, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", proid);
}
PG_RETURN_CSTRING(result);
}
/* *regprocrecv-convertsexternalbinaryformattoregproc
*/
Datum
regprocrecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regprocsend-convertsregproctobinaryformat
*/
Datum
regprocsend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regprocedurein-converts"proname(args)"toprocOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'-'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_procentry.
*/
Datum
regprocedurein(PG_FUNCTION_ARGS)
{ char *pro_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
RegProcedure result;
List *names; int nargs;
Oid argtypes[FUNC_MAX_ARGS];
FuncCandidateList clist;
/* Handle "-" or numeric OID */ if (parseDashOrOid(pro_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regprocedure values must be OIDs in bootstrap mode");
appendStringInfo(&buf, "%s(",
quote_qualified_identifier(nspname, proname)); for (i = 0; i < nargs; i++)
{
Oid thisargtype = procform->proargtypes.values[i];
if (i > 0)
appendStringInfoChar(&buf, ',');
appendStringInfoString(&buf,
(flags & FORMAT_PROC_FORCE_QUALIFY) != 0 ?
format_type_be_qualified(thisargtype) :
format_type_be(thisargtype));
}
appendStringInfoChar(&buf, ')');
result = buf.data;
ReleaseSysCache(proctup);
} elseif ((flags & FORMAT_PROC_INVALID_AS_NULL) != 0)
{ /* If object is undefined, return NULL as wanted by caller */
result = NULL;
} else
{ /* If OID doesn't match any pg_proc entry, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", procedure_oid);
}
return result;
}
/* *Outputanobjname/objargsrepresentationfortheprocedurewiththe *givenOID.Ifitdoesn'texist,anerroristhrown. * *Thiscanbeusedtofeedget_object_address.
*/ void
format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
{
HeapTuple proctup;
Form_pg_proc procform; int nargs; int i;
*objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
pstrdup(NameStr(procform->proname)));
*objargs = NIL; for (i = 0; i < nargs; i++)
{
Oid thisargtype = procform->proargtypes.values[i];
if (proid == InvalidOid)
result = pstrdup("-"); else
result = format_procedure(proid);
PG_RETURN_CSTRING(result);
}
/* *regprocedurerecv-convertsexternalbinaryformattoregprocedure
*/
Datum
regprocedurerecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regproceduresend-convertsregproceduretobinaryformat
*/
Datum
regproceduresend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regoperin-converts"oprname"tooperatorOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'0'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_operatorentry.
*/
Datum
regoperin(PG_FUNCTION_ARGS)
{ char *opr_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
Oid result;
List *names;
FuncCandidateList clist;
/* Handle "0" or numeric OID */ if (parseNumericOid(opr_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* Else it's a name, possibly schema-qualified */
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regoper values must be OIDs in bootstrap mode");
if (clist == NULL)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("operator does not exist: %s", opr_name_or_oid))); elseif (clist->next != NULL)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one operator named %s",
opr_name_or_oid)));
result = clist->oid;
PG_RETURN_OID(result);
}
/* *to_regoper-converts"oprname"tooperatorOID * *Ifthenameisnotfound,wereturnNULL.
*/
Datum
to_regoper(PG_FUNCTION_ARGS)
{ char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
ErrorSaveContext escontext = {T_ErrorSaveContext};
/* *regoperrecv-convertsexternalbinaryformattoregoper
*/
Datum
regoperrecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regopersend-convertsregopertobinaryformat
*/
Datum
regopersend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regoperatorin-converts"oprname(args)"tooperatorOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'0'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_operatorentry.
*/
Datum
regoperatorin(PG_FUNCTION_ARGS)
{ char *opr_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
Oid result;
List *names; int nargs;
Oid argtypes[FUNC_MAX_ARGS];
/* Handle "0" or numeric OID */ if (parseNumericOid(opr_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regoperator values must be OIDs in bootstrap mode");
if (nargs == 1)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_PARAMETER),
errmsg("missing argument"),
errhint("Use NONE to denote the missing argument of a unary operator."))); if (nargs != 2)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("too many arguments"),
errhint("Provide two argument types for operator.")));
result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
if (!OidIsValid(result))
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("operator does not exist: %s", opr_name_or_oid)));
PG_RETURN_OID(result);
}
/* *to_regoperator-converts"oprname(args)"tooperatorOID * *Ifthenameisnotfound,wereturnNULL.
*/
Datum
to_regoperator(PG_FUNCTION_ARGS)
{ char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
ErrorSaveContext escontext = {T_ErrorSaveContext};
void
format_operator_parts(Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
{
HeapTuple opertup;
Form_pg_operator oprForm;
opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid)); if (!HeapTupleIsValid(opertup))
{ if (!missing_ok)
elog(ERROR, "cache lookup failed for operator with OID %u",
operator_oid); return;
}
/* *regoperatorout-convertsoperatorOIDto"opr_name(args)"
*/
Datum
regoperatorout(PG_FUNCTION_ARGS)
{
Oid oprid = PG_GETARG_OID(0); char *result;
if (oprid == InvalidOid)
result = pstrdup("0"); else
result = format_operator(oprid);
PG_RETURN_CSTRING(result);
}
/* *regoperatorrecv-convertsexternalbinaryformattoregoperator
*/
Datum
regoperatorrecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regoperatorsend-convertsregoperatortobinaryformat
*/
Datum
regoperatorsend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regclassin-converts"classname"toclassOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'-'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_classentry.
*/
Datum
regclassin(PG_FUNCTION_ARGS)
{ char *class_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
Oid result;
List *names;
/* Handle "-" or numeric OID */ if (parseDashOrOid(class_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* Else it's a name, possibly schema-qualified */
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regclass values must be OIDs in bootstrap mode");
/* We might not even have permissions on this relation; don't lock it. */
result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, true);
if (!OidIsValid(result))
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist",
NameListToString(names))));
PG_RETURN_OID(result);
}
/* *to_regclass-converts"classname"toclassOID * *Ifthenameisnotfound,wereturnNULL.
*/
Datum
to_regclass(PG_FUNCTION_ARGS)
{ char *class_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
ErrorSaveContext escontext = {T_ErrorSaveContext};
result = quote_qualified_identifier(nspname, classname);
}
ReleaseSysCache(classtup);
} else
{ /* If OID doesn't match any pg_class entry, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", classid);
}
PG_RETURN_CSTRING(result);
}
/* *regclassrecv-convertsexternalbinaryformattoregclass
*/
Datum
regclassrecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regclasssend-convertsregclasstobinaryformat
*/
Datum
regclasssend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regcollationin-converts"collationname"tocollationOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'-'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_collationentry.
*/
Datum
regcollationin(PG_FUNCTION_ARGS)
{ char *collation_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
Oid result;
List *names;
/* Handle "-" or numeric OID */ if (parseDashOrOid(collation_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* Else it's a name, possibly schema-qualified */
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regcollation values must be OIDs in bootstrap mode");
if (!OidIsValid(result))
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("collation \"%s\" for encoding \"%s\" does not exist",
NameListToString(names), GetDatabaseEncodingName())));
PG_RETURN_OID(result);
}
/* *to_regcollation-converts"collationname"tocollationOID * *Ifthenameisnotfound,wereturnNULL.
*/
Datum
to_regcollation(PG_FUNCTION_ARGS)
{ char *collation_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
ErrorSaveContext escontext = {T_ErrorSaveContext};
result = quote_qualified_identifier(nspname, collationname);
}
ReleaseSysCache(collationtup);
} else
{ /* If OID doesn't match any pg_collation entry, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", collationid);
}
PG_RETURN_CSTRING(result);
}
/* *regcollationrecv-convertsexternalbinaryformattoregcollation
*/
Datum
regcollationrecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regcollationsend-convertsregcollationtobinaryformat
*/
Datum
regcollationsend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
result = pstrdup(typname);
} else
result = format_type_be(typid);
ReleaseSysCache(typetup);
} else
{ /* If OID doesn't match any pg_type entry, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", typid);
}
PG_RETURN_CSTRING(result);
}
/* *regtyperecv-convertsexternalbinaryformattoregtype
*/
Datum
regtyperecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regtypesend-convertsregtypetobinaryformat
*/
Datum
regtypesend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regconfigin-converts"tsconfigname"totsconfigOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'-'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_ts_configentry.
*/
Datum
regconfigin(PG_FUNCTION_ARGS)
{ char *cfg_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
Oid result;
List *names;
/* Handle "-" or numeric OID */ if (parseDashOrOid(cfg_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regconfig values must be OIDs in bootstrap mode");
if (!OidIsValid(result))
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("text search configuration \"%s\" does not exist",
NameListToString(names))));
PG_RETURN_OID(result);
}
/* *regconfigout-convertstsconfigOIDto"tsconfigname"
*/
Datum
regconfigout(PG_FUNCTION_ARGS)
{
Oid cfgid = PG_GETARG_OID(0); char *result;
HeapTuple cfgtup;
if (cfgid == InvalidOid)
{
result = pstrdup("-");
PG_RETURN_CSTRING(result);
}
result = quote_qualified_identifier(nspname, cfgname);
ReleaseSysCache(cfgtup);
} else
{ /* If OID doesn't match any pg_ts_config row, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", cfgid);
}
PG_RETURN_CSTRING(result);
}
/* *regconfigrecv-convertsexternalbinaryformattoregconfig
*/
Datum
regconfigrecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regconfigsend-convertsregconfigtobinaryformat
*/
Datum
regconfigsend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regdictionaryin-converts"tsdictionaryname"totsdictionaryOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'-'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_ts_dictentry.
*/
Datum
regdictionaryin(PG_FUNCTION_ARGS)
{ char *dict_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
Oid result;
List *names;
/* Handle "-" or numeric OID */ if (parseDashOrOid(dict_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regdictionary values must be OIDs in bootstrap mode");
if (!OidIsValid(result))
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("text search dictionary \"%s\" does not exist",
NameListToString(names))));
PG_RETURN_OID(result);
}
/* *regdictionaryout-convertstsdictionaryOIDto"tsdictionaryname"
*/
Datum
regdictionaryout(PG_FUNCTION_ARGS)
{
Oid dictid = PG_GETARG_OID(0); char *result;
HeapTuple dicttup;
if (dictid == InvalidOid)
{
result = pstrdup("-");
PG_RETURN_CSTRING(result);
}
result = quote_qualified_identifier(nspname, dictname);
ReleaseSysCache(dicttup);
} else
{ /* If OID doesn't match any pg_ts_dict row, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", dictid);
}
PG_RETURN_CSTRING(result);
}
/* *regdictionaryrecv-convertsexternalbinaryformattoregdictionary
*/
Datum
regdictionaryrecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regdictionarysend-convertsregdictionarytobinaryformat
*/
Datum
regdictionarysend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regrolein-converts"rolename"toroleOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'-'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_authidentry.
*/
Datum
regrolein(PG_FUNCTION_ARGS)
{ char *role_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
Oid result;
List *names;
/* Handle "-" or numeric OID */ if (parseDashOrOid(role_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regrole values must be OIDs in bootstrap mode");
/* Normal case: see if the name matches any pg_authid entry. */
names = stringToQualifiedNameList(role_name_or_oid, escontext); if (names == NIL)
PG_RETURN_NULL();
if (list_length(names) != 1)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax")));
result = get_role_oid(strVal(linitial(names)), true);
if (!OidIsValid(result))
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("role \"%s\" does not exist",
strVal(linitial(names)))));
PG_RETURN_OID(result);
}
/* *to_regrole-converts"rolename"toroleOID * *Ifthenameisnotfound,wereturnNULL.
*/
Datum
to_regrole(PG_FUNCTION_ARGS)
{ char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
ErrorSaveContext escontext = {T_ErrorSaveContext};
/* *regroleout-convertsroleOIDto"role_name"
*/
Datum
regroleout(PG_FUNCTION_ARGS)
{
Oid roleoid = PG_GETARG_OID(0); char *result;
if (roleoid == InvalidOid)
{
result = pstrdup("-");
PG_RETURN_CSTRING(result);
}
result = GetUserNameFromId(roleoid, true);
if (result)
{ /* pstrdup is not really necessary, but it avoids a compiler warning */
result = pstrdup(quote_identifier(result));
} else
{ /* If OID doesn't match any role, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", roleoid);
}
PG_RETURN_CSTRING(result);
}
/* *regrolerecv-convertsexternalbinaryformattoregrole
*/
Datum
regrolerecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regrolesend-convertsregroletobinaryformat
*/
Datum
regrolesend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *regnamespacein-converts"nspname"tonamespaceOID * *WealsoacceptanumericOID,forsymmetrywiththeoutputroutine. * *'-'signifiesunknown(OID0).Inallothercases,theinputmust *matchanexistingpg_namespaceentry.
*/
Datum
regnamespacein(PG_FUNCTION_ARGS)
{ char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
Oid result;
List *names;
/* Handle "-" or numeric OID */ if (parseDashOrOid(nsp_name_or_oid, &result, escontext))
PG_RETURN_OID(result);
/* The rest of this wouldn't work in bootstrap mode */ if (IsBootstrapProcessingMode())
elog(ERROR, "regnamespace values must be OIDs in bootstrap mode");
/* Normal case: see if the name matches any pg_namespace entry. */
names = stringToQualifiedNameList(nsp_name_or_oid, escontext); if (names == NIL)
PG_RETURN_NULL();
if (list_length(names) != 1)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax")));
result = get_namespace_oid(strVal(linitial(names)), true);
if (!OidIsValid(result))
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist",
strVal(linitial(names)))));
PG_RETURN_OID(result);
}
/* *to_regnamespace-converts"nspname"tonamespaceOID * *Ifthenameisnotfound,wereturnNULL.
*/
Datum
to_regnamespace(PG_FUNCTION_ARGS)
{ char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
ErrorSaveContext escontext = {T_ErrorSaveContext};
/* *regnamespaceout-convertsnamespaceOIDto"nsp_name"
*/
Datum
regnamespaceout(PG_FUNCTION_ARGS)
{
Oid nspid = PG_GETARG_OID(0); char *result;
if (nspid == InvalidOid)
{
result = pstrdup("-");
PG_RETURN_CSTRING(result);
}
result = get_namespace_name(nspid);
if (result)
{ /* pstrdup is not really necessary, but it avoids a compiler warning */
result = pstrdup(quote_identifier(result));
} else
{ /* If OID doesn't match any namespace, return it numerically */
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", nspid);
}
PG_RETURN_CSTRING(result);
}
/* *regnamespacerecv-convertsexternalbinaryformattoregnamespace
*/
Datum
regnamespacerecv(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidrecv, so share code */ return oidrecv(fcinfo);
}
/* *regnamespacesend-convertsregnamespacetobinaryformat
*/
Datum
regnamespacesend(PG_FUNCTION_ARGS)
{ /* Exactly the same as oidsend, so share code */ return oidsend(fcinfo);
}
/* *text_regclass:converttexttoregclass * *ThiscouldbereplacedbyCoerceViaIO,exceptthatweneedtotreat *text-to-regclassasanimplicitcasttosupportlegacyformsofnextval() *andrelatedfunctions.
*/
Datum
text_regclass(PG_FUNCTION_ARGS)
{
text *relname = PG_GETARG_TEXT_PP(0);
Oid result;
RangeVar *rv;
/* We need not care here whether oidin() fails or not. */
(void) DirectInputFunctionCallSafe(oidin, string,
InvalidOid, -1,
escontext,
&oid_datum);
*result = DatumGetObjectId(oid_datum); returntrue;
}
/* *GivenaCstring,parseitintoaqualifiedfunctionoroperatorname *followedbyaparenthesizedlistoftypenames.Reducethe *typenamestoanarrayofOIDs(returnedinto*nargsand*argtypes; *theargtypesarrayshouldbeofsizeFUNC_MAX_ARGS).Thefunctionor *operatornameisreturnedto*namesasaListofStrings. * *IfallowNoneistrue,accept"NONE"andreturnitasInvalidOid(thisis *forunaryoperators). * *Returnstrueonsuccess,falseonfailure(thelatteronlypossible *ifescontextisanErrorSaveContextnode).
*/ staticbool
parseNameAndArgTypes(constchar *string, bool allowNone, List **names, int *nargs, Oid *argtypes,
Node *escontext)
{ char *rawname; char *ptr; char *ptr2; char *typename; bool in_quote; bool had_comma; int paren_count;
Oid typeid;
int32 typmod;
/* We need a modifiable copy of the input string. */
rawname = pstrdup(string);
/* Scan to find the expected left paren; mustn't be quoted */
in_quote = false; for (ptr = rawname; *ptr; ptr++)
{ if (*ptr == '"')
in_quote = !in_quote; elseif (*ptr == '(' && !in_quote) break;
} if (*ptr == '\0')
ereturn(escontext, false,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a left parenthesis")));
/* Separate the name and parse it into a list */
*ptr++ = '\0';
*names = stringToQualifiedNameList(rawname, escontext); if (*names == NIL) returnfalse;
/* Check for the trailing right parenthesis and remove it */
ptr2 = ptr + strlen(ptr); while (--ptr2 > ptr)
{ if (!scanner_isspace(*ptr2)) break;
} if (*ptr2 != ')')
ereturn(escontext, false,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a right parenthesis")));
*ptr2 = '\0';
/* Separate the remaining string into comma-separated type names */
*nargs = 0;
had_comma = false;
for (;;)
{ /* allow leading whitespace */ while (scanner_isspace(*ptr))
ptr++; if (*ptr == '\0')
{ /* End of string. Okay unless we had a comma before. */ if (had_comma)
ereturn(escontext, false,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a type name"))); break;
} typename = ptr; /* Find end of type name --- end of string or comma */ /* ... but not a quoted or parenthesized comma */
in_quote = false;
paren_count = 0; for (; *ptr; ptr++)
{ if (*ptr == '"')
in_quote = !in_quote; elseif (*ptr == ',' && !in_quote && paren_count == 0) break; elseif (!in_quote)
{ switch (*ptr)
{ case'(': case'[':
paren_count++; break; case')': case']':
paren_count--; break;
}
}
} if (in_quote || paren_count != 0)
ereturn(escontext, false,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("improper type name")));
if (allowNone && pg_strcasecmp(typename, "none") == 0)
{ /* Special case for NONE */ typeid = InvalidOid;
typmod = -1;
} else
{ /* Use full parser to resolve the type name */ if (!parseTypeString(typename, &typeid, &typmod, escontext)) returnfalse;
} if (*nargs >= FUNC_MAX_ARGS)
ereturn(escontext, false,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("too many arguments")));
argtypes[*nargs] = typeid;
(*nargs)++;
}
pfree(rawname);
returntrue;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.41 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.