Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
regproc.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "access/htup_details.h"
#include "catalog/namespace.h"
#include "catalog/pg_class.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_database.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_type.h"
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/miscnodes.h"
#include "parser/parse_type.h"
#include "parser/scansup.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/regproc.h"
#include "utils/syscache.h"
#include "utils/varlena.h"
Include dependency graph for regproc.c:

Go to the source code of this file.

Functions

static bool parseNumericOid (char *string, Oid *result, Node *escontext)
 
static bool parseDashOrOid (char *string, Oid *result, Node *escontext)
 
static bool parseNameAndArgTypes (const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes, Node *escontext)
 
Datum regprocin (PG_FUNCTION_ARGS)
 
Datum to_regproc (PG_FUNCTION_ARGS)
 
Datum regprocout (PG_FUNCTION_ARGS)
 
Datum regprocrecv (PG_FUNCTION_ARGS)
 
Datum regprocsend (PG_FUNCTION_ARGS)
 
Datum regprocedurein (PG_FUNCTION_ARGS)
 
Datum to_regprocedure (PG_FUNCTION_ARGS)
 
char * format_procedure (Oid procedure_oid)
 
char * format_procedure_qualified (Oid procedure_oid)
 
char * format_procedure_extended (Oid procedure_oid, bits16 flags)
 
void format_procedure_parts (Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
 
Datum regprocedureout (PG_FUNCTION_ARGS)
 
Datum regprocedurerecv (PG_FUNCTION_ARGS)
 
Datum regproceduresend (PG_FUNCTION_ARGS)
 
Datum regoperin (PG_FUNCTION_ARGS)
 
Datum to_regoper (PG_FUNCTION_ARGS)
 
Datum regoperout (PG_FUNCTION_ARGS)
 
Datum regoperrecv (PG_FUNCTION_ARGS)
 
Datum regopersend (PG_FUNCTION_ARGS)
 
Datum regoperatorin (PG_FUNCTION_ARGS)
 
Datum to_regoperator (PG_FUNCTION_ARGS)
 
char * format_operator_extended (Oid operator_oid, bits16 flags)
 
char * format_operator (Oid operator_oid)
 
char * format_operator_qualified (Oid operator_oid)
 
void format_operator_parts (Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
 
Datum regoperatorout (PG_FUNCTION_ARGS)
 
Datum regoperatorrecv (PG_FUNCTION_ARGS)
 
Datum regoperatorsend (PG_FUNCTION_ARGS)
 
Datum regclassin (PG_FUNCTION_ARGS)
 
Datum to_regclass (PG_FUNCTION_ARGS)
 
Datum regclassout (PG_FUNCTION_ARGS)
 
Datum regclassrecv (PG_FUNCTION_ARGS)
 
Datum regclasssend (PG_FUNCTION_ARGS)
 
Datum regcollationin (PG_FUNCTION_ARGS)
 
Datum to_regcollation (PG_FUNCTION_ARGS)
 
Datum regcollationout (PG_FUNCTION_ARGS)
 
Datum regcollationrecv (PG_FUNCTION_ARGS)
 
Datum regcollationsend (PG_FUNCTION_ARGS)
 
Datum regtypein (PG_FUNCTION_ARGS)
 
Datum to_regtype (PG_FUNCTION_ARGS)
 
Datum to_regtypemod (PG_FUNCTION_ARGS)
 
Datum regtypeout (PG_FUNCTION_ARGS)
 
Datum regtyperecv (PG_FUNCTION_ARGS)
 
Datum regtypesend (PG_FUNCTION_ARGS)
 
Datum regconfigin (PG_FUNCTION_ARGS)
 
Datum regconfigout (PG_FUNCTION_ARGS)
 
Datum regconfigrecv (PG_FUNCTION_ARGS)
 
Datum regconfigsend (PG_FUNCTION_ARGS)
 
Datum regdictionaryin (PG_FUNCTION_ARGS)
 
Datum regdictionaryout (PG_FUNCTION_ARGS)
 
Datum regdictionaryrecv (PG_FUNCTION_ARGS)
 
Datum regdictionarysend (PG_FUNCTION_ARGS)
 
Datum regrolein (PG_FUNCTION_ARGS)
 
Datum to_regrole (PG_FUNCTION_ARGS)
 
Datum regroleout (PG_FUNCTION_ARGS)
 
Datum regrolerecv (PG_FUNCTION_ARGS)
 
Datum regrolesend (PG_FUNCTION_ARGS)
 
Datum regnamespacein (PG_FUNCTION_ARGS)
 
Datum to_regnamespace (PG_FUNCTION_ARGS)
 
Datum regnamespaceout (PG_FUNCTION_ARGS)
 
Datum regnamespacerecv (PG_FUNCTION_ARGS)
 
Datum regnamespacesend (PG_FUNCTION_ARGS)
 
Datum regdatabasein (PG_FUNCTION_ARGS)
 
Datum to_regdatabase (PG_FUNCTION_ARGS)
 
Datum regdatabaseout (PG_FUNCTION_ARGS)
 
Datum regdatabaserecv (PG_FUNCTION_ARGS)
 
Datum regdatabasesend (PG_FUNCTION_ARGS)
 
Datum text_regclass (PG_FUNCTION_ARGS)
 
ListstringToQualifiedNameList (const char *string, Node *escontext)
 

Function Documentation

◆ format_operator()

char * format_operator ( Oid  operator_oid)

Definition at line 801 of file regproc.c.

802{
803 return format_operator_extended(operator_oid, 0);
804}
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:730

References format_operator_extended().

Referenced by blvalidate(), brinvalidate(), btvalidate(), ComputeIndexAttrs(), getObjectDescription(), ginvalidate(), gistvalidate(), hashvalidate(), regoperatorout(), and spgvalidate().

◆ format_operator_extended()

char * format_operator_extended ( Oid  operator_oid,
bits16  flags 
)

Definition at line 730 of file regproc.c.

731{
732 char *result;
733 HeapTuple opertup;
734
735 opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
736
737 if (HeapTupleIsValid(opertup))
738 {
739 Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
740 char *oprname = NameStr(operform->oprname);
741 char *nspname;
743
744 /* XXX no support here for bootstrap mode */
746
748
749 /*
750 * Would this oper be found (given the right args) by regoperatorin?
751 * If not, or if caller explicitly requests it, we need to qualify it.
752 */
753 if ((flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ||
754 !OperatorIsVisible(operator_oid))
755 {
756 nspname = get_namespace_name(operform->oprnamespace);
757 appendStringInfo(&buf, "%s.",
758 quote_identifier(nspname));
759 }
760
761 appendStringInfo(&buf, "%s(", oprname);
762
763 if (operform->oprleft)
764 appendStringInfo(&buf, "%s,",
765 (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
766 format_type_be_qualified(operform->oprleft) :
767 format_type_be(operform->oprleft));
768 else
769 appendStringInfoString(&buf, "NONE,");
770
771 if (operform->oprright)
772 appendStringInfo(&buf, "%s)",
773 (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
774 format_type_be_qualified(operform->oprright) :
775 format_type_be(operform->oprright));
776 else
777 appendStringInfoString(&buf, "NONE)");
778
779 result = buf.data;
780
781 ReleaseSysCache(opertup);
782 }
783 else if ((flags & FORMAT_OPERATOR_INVALID_AS_NULL) != 0)
784 {
785 /* If object is undefined, return NULL as wanted by caller */
786 result = NULL;
787 }
788 else
789 {
790 /*
791 * If OID doesn't match any pg_operator entry, return it numerically
792 */
793 result = (char *) palloc(NAMEDATALEN);
794 snprintf(result, NAMEDATALEN, "%u", operator_oid);
795 }
796
797 return result;
798}
#define NameStr(name)
Definition: c.h:752
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:353
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3533
void * palloc(Size size)
Definition: mcxt.c:1365
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:476
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:2116
#define NAMEDATALEN
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
static char * buf
Definition: pg_test_fsync.c:72
#define snprintf
Definition: port.h:239
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:13030
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220

References appendStringInfo(), appendStringInfoString(), Assert(), buf, FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_type_be(), format_type_be_qualified(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, initStringInfo(), IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), OperatorIsVisible(), palloc(), quote_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

Referenced by format_operator(), format_operator_qualified(), getObjectDescription(), and getObjectIdentityParts().

◆ format_operator_parts()

void format_operator_parts ( Oid  operator_oid,
List **  objnames,
List **  objargs,
bool  missing_ok 
)

Definition at line 814 of file regproc.c.

816{
817 HeapTuple opertup;
818 Form_pg_operator oprForm;
819
820 opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
821 if (!HeapTupleIsValid(opertup))
822 {
823 if (!missing_ok)
824 elog(ERROR, "cache lookup failed for operator with OID %u",
825 operator_oid);
826 return;
827 }
828
829 oprForm = (Form_pg_operator) GETSTRUCT(opertup);
830 *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
831 pstrdup(NameStr(oprForm->oprname)));
832 *objargs = NIL;
833 if (oprForm->oprleft)
834 *objargs = lappend(*objargs,
835 format_type_be_qualified(oprForm->oprleft));
836 if (oprForm->oprright)
837 *objargs = lappend(*objargs,
838 format_type_be_qualified(oprForm->oprright));
839
840 ReleaseSysCache(opertup);
841}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
List * lappend(List *list, void *datum)
Definition: list.c:339
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3557
char * pstrdup(const char *in)
Definition: mcxt.c:1759
#define NIL
Definition: pg_list.h:68
#define list_make2(x1, x2)
Definition: pg_list.h:214

References elog, ERROR, format_type_be_qualified(), get_namespace_name_or_temp(), GETSTRUCT(), HeapTupleIsValid, lappend(), list_make2, NameStr, NIL, ObjectIdGetDatum(), pstrdup(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectIdentityParts().

◆ format_operator_qualified()

char * format_operator_qualified ( Oid  operator_oid)

Definition at line 807 of file regproc.c.

808{
809 return format_operator_extended(operator_oid,
811}

References format_operator_extended(), and FORMAT_OPERATOR_FORCE_QUALIFY.

◆ format_procedure()

char * format_procedure ( Oid  procedure_oid)

◆ format_procedure_extended()

char * format_procedure_extended ( Oid  procedure_oid,
bits16  flags 
)

Definition at line 332 of file regproc.c.

333{
334 char *result;
335 HeapTuple proctup;
336
337 proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
338
339 if (HeapTupleIsValid(proctup))
340 {
341 Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
342 char *proname = NameStr(procform->proname);
343 int nargs = procform->pronargs;
344 int i;
345 char *nspname;
347
348 /* XXX no support here for bootstrap mode */
350
352
353 /*
354 * Would this proc be found (given the right args) by regprocedurein?
355 * If not, or if caller requests it, we need to qualify it.
356 */
357 if ((flags & FORMAT_PROC_FORCE_QUALIFY) == 0 &&
358 FunctionIsVisible(procedure_oid))
359 nspname = NULL;
360 else
361 nspname = get_namespace_name(procform->pronamespace);
362
363 appendStringInfo(&buf, "%s(",
365 for (i = 0; i < nargs; i++)
366 {
367 Oid thisargtype = procform->proargtypes.values[i];
368
369 if (i > 0)
372 (flags & FORMAT_PROC_FORCE_QUALIFY) != 0 ?
373 format_type_be_qualified(thisargtype) :
374 format_type_be(thisargtype));
375 }
377
378 result = buf.data;
379
380 ReleaseSysCache(proctup);
381 }
382 else if ((flags & FORMAT_PROC_INVALID_AS_NULL) != 0)
383 {
384 /* If object is undefined, return NULL as wanted by caller */
385 result = NULL;
386 }
387 else
388 {
389 /* If OID doesn't match any pg_proc entry, return it numerically */
390 result = (char *) palloc(NAMEDATALEN);
391 snprintf(result, NAMEDATALEN, "%u", procedure_oid);
392 }
393
394 return result;
395}
int i
Definition: isn.c:77
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1741
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
NameData proname
Definition: pg_proc.h:35
unsigned int Oid
Definition: postgres_ext.h:32
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:13114
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert(), buf, FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_type_be(), format_type_be_qualified(), FunctionIsVisible(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, i, initStringInfo(), IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), proname, quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

Referenced by format_procedure(), format_procedure_qualified(), getObjectDescription(), and getObjectIdentityParts().

◆ format_procedure_parts()

void format_procedure_parts ( Oid  procedure_oid,
List **  objnames,
List **  objargs,
bool  missing_ok 
)

Definition at line 404 of file regproc.c.

406{
407 HeapTuple proctup;
408 Form_pg_proc procform;
409 int nargs;
410 int i;
411
412 proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
413
414 if (!HeapTupleIsValid(proctup))
415 {
416 if (!missing_ok)
417 elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
418 return;
419 }
420
421 procform = (Form_pg_proc) GETSTRUCT(proctup);
422 nargs = procform->pronargs;
423
424 *objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
425 pstrdup(NameStr(procform->proname)));
426 *objargs = NIL;
427 for (i = 0; i < nargs; i++)
428 {
429 Oid thisargtype = procform->proargtypes.values[i];
430
431 *objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
432 }
433
434 ReleaseSysCache(proctup);
435}

References elog, ERROR, format_type_be_qualified(), get_namespace_name_or_temp(), GETSTRUCT(), HeapTupleIsValid, i, lappend(), list_make2, NameStr, NIL, ObjectIdGetDatum(), pstrdup(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectIdentityParts().

◆ format_procedure_qualified()

char * format_procedure_qualified ( Oid  procedure_oid)

Definition at line 311 of file regproc.c.

312{
314}

References FORMAT_PROC_FORCE_QUALIFY, and format_procedure_extended().

◆ parseDashOrOid()

static bool parseDashOrOid ( char *  string,
Oid result,
Node escontext 
)
static

Definition at line 1993 of file regproc.c.

1994{
1995 /* '-' ? */
1996 if (strcmp(string, "-") == 0)
1997 {
1998 *result = InvalidOid;
1999 return true;
2000 }
2001
2002 /* Numeric OID? */
2003 return parseNumericOid(string, result, escontext);
2004}
#define InvalidOid
Definition: postgres_ext.h:37
static bool parseNumericOid(char *string, Oid *result, Node *escontext)
Definition: regproc.c:1968

References InvalidOid, and parseNumericOid().

Referenced by regclassin(), regcollationin(), regconfigin(), regdatabasein(), regdictionaryin(), regnamespacein(), regprocedurein(), regprocin(), regrolein(), and regtypein().

◆ parseNameAndArgTypes()

static bool parseNameAndArgTypes ( const char *  string,
bool  allowNone,
List **  names,
int *  nargs,
Oid argtypes,
Node escontext 
)
static

Definition at line 2020 of file regproc.c.

2023{
2024 char *rawname;
2025 char *ptr;
2026 char *ptr2;
2027 char *typename;
2028 bool in_quote;
2029 bool had_comma;
2030 int paren_count;
2031 Oid typeid;
2032 int32 typmod;
2033
2034 /* We need a modifiable copy of the input string. */
2035 rawname = pstrdup(string);
2036
2037 /* Scan to find the expected left paren; mustn't be quoted */
2038 in_quote = false;
2039 for (ptr = rawname; *ptr; ptr++)
2040 {
2041 if (*ptr == '"')
2042 in_quote = !in_quote;
2043 else if (*ptr == '(' && !in_quote)
2044 break;
2045 }
2046 if (*ptr == '\0')
2047 ereturn(escontext, false,
2048 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2049 errmsg("expected a left parenthesis")));
2050
2051 /* Separate the name and parse it into a list */
2052 *ptr++ = '\0';
2053 *names = stringToQualifiedNameList(rawname, escontext);
2054 if (*names == NIL)
2055 return false;
2056
2057 /* Check for the trailing right parenthesis and remove it */
2058 ptr2 = ptr + strlen(ptr);
2059 while (--ptr2 > ptr)
2060 {
2061 if (!scanner_isspace(*ptr2))
2062 break;
2063 }
2064 if (*ptr2 != ')')
2065 ereturn(escontext, false,
2066 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2067 errmsg("expected a right parenthesis")));
2068
2069 *ptr2 = '\0';
2070
2071 /* Separate the remaining string into comma-separated type names */
2072 *nargs = 0;
2073 had_comma = false;
2074
2075 for (;;)
2076 {
2077 /* allow leading whitespace */
2078 while (scanner_isspace(*ptr))
2079 ptr++;
2080 if (*ptr == '\0')
2081 {
2082 /* End of string. Okay unless we had a comma before. */
2083 if (had_comma)
2084 ereturn(escontext, false,
2085 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2086 errmsg("expected a type name")));
2087 break;
2088 }
2089 typename = ptr;
2090 /* Find end of type name --- end of string or comma */
2091 /* ... but not a quoted or parenthesized comma */
2092 in_quote = false;
2093 paren_count = 0;
2094 for (; *ptr; ptr++)
2095 {
2096 if (*ptr == '"')
2097 in_quote = !in_quote;
2098 else if (*ptr == ',' && !in_quote && paren_count == 0)
2099 break;
2100 else if (!in_quote)
2101 {
2102 switch (*ptr)
2103 {
2104 case '(':
2105 case '[':
2106 paren_count++;
2107 break;
2108 case ')':
2109 case ']':
2110 paren_count--;
2111 break;
2112 }
2113 }
2114 }
2115 if (in_quote || paren_count != 0)
2116 ereturn(escontext, false,
2117 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2118 errmsg("improper type name")));
2119
2120 ptr2 = ptr;
2121 if (*ptr == ',')
2122 {
2123 had_comma = true;
2124 *ptr++ = '\0';
2125 }
2126 else
2127 {
2128 had_comma = false;
2129 Assert(*ptr == '\0');
2130 }
2131 /* Lop off trailing whitespace */
2132 while (--ptr2 >= typename)
2133 {
2134 if (!scanner_isspace(*ptr2))
2135 break;
2136 *ptr2 = '\0';
2137 }
2138
2139 if (allowNone && pg_strcasecmp(typename, "none") == 0)
2140 {
2141 /* Special case for NONE */
2142 typeid = InvalidOid;
2143 typmod = -1;
2144 }
2145 else
2146 {
2147 /* Use full parser to resolve the type name */
2148 if (!parseTypeString(typename, &typeid, &typmod, escontext))
2149 return false;
2150 }
2151 if (*nargs >= FUNC_MAX_ARGS)
2152 ereturn(escontext, false,
2153 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
2154 errmsg("too many arguments")));
2155
2156 argtypes[*nargs] = typeid;
2157 (*nargs)++;
2158 }
2159
2160 pfree(rawname);
2161
2162 return true;
2163}
int32_t int32
Definition: c.h:535
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ereturn(context, dummy_value,...)
Definition: elog.h:278
void pfree(void *pointer)
Definition: mcxt.c:1594
bool parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, Node *escontext)
Definition: parse_type.c:785
#define FUNC_MAX_ARGS
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
List * stringToQualifiedNameList(const char *string, Node *escontext)
Definition: regproc.c:1922
bool scanner_isspace(char ch)
Definition: scansup.c:117

References Assert(), ereturn, errcode(), errmsg(), FUNC_MAX_ARGS, InvalidOid, NIL, parseTypeString(), pfree(), pg_strcasecmp(), pstrdup(), scanner_isspace(), and stringToQualifiedNameList().

Referenced by regoperatorin(), and regprocedurein().

◆ parseNumericOid()

static bool parseNumericOid ( char *  string,
Oid result,
Node escontext 
)
static

Definition at line 1968 of file regproc.c.

1969{
1970 if (string[0] >= '0' && string[0] <= '9' &&
1971 strspn(string, "0123456789") == strlen(string))
1972 {
1973 Datum oid_datum;
1974
1975 /* We need not care here whether oidin() fails or not. */
1976 (void) DirectInputFunctionCallSafe(oidin, string,
1977 InvalidOid, -1,
1978 escontext,
1979 &oid_datum);
1980 *result = DatumGetObjectId(oid_datum);
1981 return true;
1982 }
1983
1984 /* Prevent uninitialized-variable warnings from stupider compilers. */
1985 *result = InvalidOid;
1986 return false;
1987}
bool DirectInputFunctionCallSafe(PGFunction func, char *str, Oid typioparam, int32 typmod, Node *escontext, Datum *result)
Definition: fmgr.c:1639
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:37
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:252
uint64_t Datum
Definition: postgres.h:70

References DatumGetObjectId(), DirectInputFunctionCallSafe(), InvalidOid, and oidin().

Referenced by parseDashOrOid(), regoperatorin(), and regoperin().

◆ regclassin()

Datum regclassin ( PG_FUNCTION_ARGS  )

Definition at line 890 of file regproc.c.

891{
892 char *class_name_or_oid = PG_GETARG_CSTRING(0);
893 Node *escontext = fcinfo->context;
894 Oid result;
895 List *names;
896
897 /* Handle "-" or numeric OID */
898 if (parseDashOrOid(class_name_or_oid, &result, escontext))
899 PG_RETURN_OID(result);
900
901 /* Else it's a name, possibly schema-qualified */
902
903 /* The rest of this wouldn't work in bootstrap mode */
905 elog(ERROR, "regclass values must be OIDs in bootstrap mode");
906
907 /*
908 * Normal case: parse the name into components and see if it matches any
909 * pg_class entries in the current search path.
910 */
911 names = stringToQualifiedNameList(class_name_or_oid, escontext);
912 if (names == NIL)
914
915 /* We might not even have permissions on this relation; don't lock it. */
916 result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, true);
917
918 if (!OidIsValid(result))
919 ereturn(escontext, (Datum) 0,
921 errmsg("relation \"%s\" does not exist",
922 NameListToString(names))));
923
924 PG_RETURN_OID(result);
925}
#define OidIsValid(objectId)
Definition: c.h:775
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_OID(x)
Definition: fmgr.h:360
#define NoLock
Definition: lockdefs.h:34
char * NameListToString(const List *names)
Definition: namespace.c:3664
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3624
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:98
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:79
static bool parseDashOrOid(char *string, Oid *result, Node *escontext)
Definition: regproc.c:1993
Definition: pg_list.h:54
Definition: nodes.h:135

References elog, ereturn, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), ERROR, IsBootstrapProcessingMode, makeRangeVarFromNameList(), NameListToString(), NIL, NoLock, OidIsValid, parseDashOrOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, RangeVarGetRelid, and stringToQualifiedNameList().

Referenced by to_regclass().

◆ regclassout()

Datum regclassout ( PG_FUNCTION_ARGS  )

Definition at line 951 of file regproc.c.

952{
953 Oid classid = PG_GETARG_OID(0);
954 char *result;
955 HeapTuple classtup;
956
957 if (classid == InvalidOid)
958 {
959 result = pstrdup("-");
960 PG_RETURN_CSTRING(result);
961 }
962
963 classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classid));
964
965 if (HeapTupleIsValid(classtup))
966 {
967 Form_pg_class classform = (Form_pg_class) GETSTRUCT(classtup);
968 char *classname = NameStr(classform->relname);
969
970 /*
971 * In bootstrap mode, skip the fancy namespace stuff and just return
972 * the class name. (This path is only needed for debugging output
973 * anyway.)
974 */
976 result = pstrdup(classname);
977 else
978 {
979 char *nspname;
980
981 /*
982 * Would this class be found by regclassin? If not, qualify it.
983 */
984 if (RelationIsVisible(classid))
985 nspname = NULL;
986 else
987 nspname = get_namespace_name(classform->relnamespace);
988
989 result = quote_qualified_identifier(nspname, classname);
990 }
991
992 ReleaseSysCache(classtup);
993 }
994 else
995 {
996 /* If OID doesn't match any pg_class entry, return it numerically */
997 result = (char *) palloc(NAMEDATALEN);
998 snprintf(result, NAMEDATALEN, "%u", classid);
999 }
1000
1001 PG_RETURN_CSTRING(result);
1002}
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
bool RelationIsVisible(Oid relid)
Definition: namespace.c:912
FormData_pg_class * Form_pg_class
Definition: pg_class.h:156

References get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), quote_qualified_identifier(), RelationIsVisible(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

Referenced by table_to_xml_internal().

◆ regclassrecv()

Datum regclassrecv ( PG_FUNCTION_ARGS  )

Definition at line 1008 of file regproc.c.

1009{
1010 /* Exactly the same as oidrecv, so share code */
1011 return oidrecv(fcinfo);
1012}
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:60

References oidrecv().

◆ regclasssend()

Datum regclasssend ( PG_FUNCTION_ARGS  )

Definition at line 1018 of file regproc.c.

1019{
1020 /* Exactly the same as oidsend, so share code */
1021 return oidsend(fcinfo);
1022}
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:71

References oidsend().

◆ regcollationin()

Datum regcollationin ( PG_FUNCTION_ARGS  )

Definition at line 1034 of file regproc.c.

1035{
1036 char *collation_name_or_oid = PG_GETARG_CSTRING(0);
1037 Node *escontext = fcinfo->context;
1038 Oid result;
1039 List *names;
1040
1041 /* Handle "-" or numeric OID */
1042 if (parseDashOrOid(collation_name_or_oid, &result, escontext))
1043 PG_RETURN_OID(result);
1044
1045 /* Else it's a name, possibly schema-qualified */
1046
1047 /* The rest of this wouldn't work in bootstrap mode */
1049 elog(ERROR, "regcollation values must be OIDs in bootstrap mode");
1050
1051 /*
1052 * Normal case: parse the name into components and see if it matches any
1053 * pg_collation entries in the current search path.
1054 */
1055 names = stringToQualifiedNameList(collation_name_or_oid, escontext);
1056 if (names == NIL)
1058
1059 result = get_collation_oid(names, true);
1060
1061 if (!OidIsValid(result))
1062 ereturn(escontext, (Datum) 0,
1063 (errcode(ERRCODE_UNDEFINED_OBJECT),
1064 errmsg("collation \"%s\" for encoding \"%s\" does not exist",
1066
1067 PG_RETURN_OID(result);
1068}
const char * GetDatabaseEncodingName(void)
Definition: mbutils.c:1268
Oid get_collation_oid(List *collname, bool missing_ok)
Definition: namespace.c:4041

References elog, ereturn, errcode(), errmsg(), ERROR, get_collation_oid(), GetDatabaseEncodingName(), IsBootstrapProcessingMode, NameListToString(), NIL, OidIsValid, parseDashOrOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, and stringToQualifiedNameList().

Referenced by to_regcollation().

◆ regcollationout()

Datum regcollationout ( PG_FUNCTION_ARGS  )

Definition at line 1094 of file regproc.c.

1095{
1096 Oid collationid = PG_GETARG_OID(0);
1097 char *result;
1098 HeapTuple collationtup;
1099
1100 if (collationid == InvalidOid)
1101 {
1102 result = pstrdup("-");
1103 PG_RETURN_CSTRING(result);
1104 }
1105
1106 collationtup = SearchSysCache1(COLLOID, ObjectIdGetDatum(collationid));
1107
1108 if (HeapTupleIsValid(collationtup))
1109 {
1110 Form_pg_collation collationform = (Form_pg_collation) GETSTRUCT(collationtup);
1111 char *collationname = NameStr(collationform->collname);
1112
1113 /*
1114 * In bootstrap mode, skip the fancy namespace stuff and just return
1115 * the collation name. (This path is only needed for debugging output
1116 * anyway.)
1117 */
1119 result = pstrdup(collationname);
1120 else
1121 {
1122 char *nspname;
1123
1124 /*
1125 * Would this collation be found by regcollationin? If not,
1126 * qualify it.
1127 */
1128 if (CollationIsVisible(collationid))
1129 nspname = NULL;
1130 else
1131 nspname = get_namespace_name(collationform->collnamespace);
1132
1133 result = quote_qualified_identifier(nspname, collationname);
1134 }
1135
1136 ReleaseSysCache(collationtup);
1137 }
1138 else
1139 {
1140 /* If OID doesn't match any pg_collation entry, return it numerically */
1141 result = (char *) palloc(NAMEDATALEN);
1142 snprintf(result, NAMEDATALEN, "%u", collationid);
1143 }
1144
1145 PG_RETURN_CSTRING(result);
1146}
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2474
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:58

References CollationIsVisible(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

◆ regcollationrecv()

Datum regcollationrecv ( PG_FUNCTION_ARGS  )

Definition at line 1152 of file regproc.c.

1153{
1154 /* Exactly the same as oidrecv, so share code */
1155 return oidrecv(fcinfo);
1156}

References oidrecv().

◆ regcollationsend()

Datum regcollationsend ( PG_FUNCTION_ARGS  )

Definition at line 1162 of file regproc.c.

1163{
1164 /* Exactly the same as oidsend, so share code */
1165 return oidsend(fcinfo);
1166}

References oidsend().

◆ regconfigin()

Datum regconfigin ( PG_FUNCTION_ARGS  )

Definition at line 1329 of file regproc.c.

1330{
1331 char *cfg_name_or_oid = PG_GETARG_CSTRING(0);
1332 Node *escontext = fcinfo->context;
1333 Oid result;
1334 List *names;
1335
1336 /* Handle "-" or numeric OID */
1337 if (parseDashOrOid(cfg_name_or_oid, &result, escontext))
1338 PG_RETURN_OID(result);
1339
1340 /* The rest of this wouldn't work in bootstrap mode */
1342 elog(ERROR, "regconfig values must be OIDs in bootstrap mode");
1343
1344 /*
1345 * Normal case: parse the name into components and see if it matches any
1346 * pg_ts_config entries in the current search path.
1347 */
1348 names = stringToQualifiedNameList(cfg_name_or_oid, escontext);
1349 if (names == NIL)
1351
1352 result = get_ts_config_oid(names, true);
1353
1354 if (!OidIsValid(result))
1355 ereturn(escontext, (Datum) 0,
1356 (errcode(ERRCODE_UNDEFINED_OBJECT),
1357 errmsg("text search configuration \"%s\" does not exist",
1358 NameListToString(names))));
1359
1360 PG_RETURN_OID(result);
1361}
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:3222

References elog, ereturn, errcode(), errmsg(), ERROR, get_ts_config_oid(), IsBootstrapProcessingMode, NameListToString(), NIL, OidIsValid, parseDashOrOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, and stringToQualifiedNameList().

◆ regconfigout()

Datum regconfigout ( PG_FUNCTION_ARGS  )

Definition at line 1367 of file regproc.c.

1368{
1369 Oid cfgid = PG_GETARG_OID(0);
1370 char *result;
1371 HeapTuple cfgtup;
1372
1373 if (cfgid == InvalidOid)
1374 {
1375 result = pstrdup("-");
1376 PG_RETURN_CSTRING(result);
1377 }
1378
1379 cfgtup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgid));
1380
1381 if (HeapTupleIsValid(cfgtup))
1382 {
1383 Form_pg_ts_config cfgform = (Form_pg_ts_config) GETSTRUCT(cfgtup);
1384 char *cfgname = NameStr(cfgform->cfgname);
1385 char *nspname;
1386
1387 /*
1388 * Would this config be found by regconfigin? If not, qualify it.
1389 */
1390 if (TSConfigIsVisible(cfgid))
1391 nspname = NULL;
1392 else
1393 nspname = get_namespace_name(cfgform->cfgnamespace);
1394
1395 result = quote_qualified_identifier(nspname, cfgname);
1396
1397 ReleaseSysCache(cfgtup);
1398 }
1399 else
1400 {
1401 /* If OID doesn't match any pg_ts_config row, return it numerically */
1402 result = (char *) palloc(NAMEDATALEN);
1403 snprintf(result, NAMEDATALEN, "%u", cfgid);
1404 }
1405
1406 PG_RETURN_CSTRING(result);
1407}
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:3280
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48

References get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), snprintf, and TSConfigIsVisible().

◆ regconfigrecv()

Datum regconfigrecv ( PG_FUNCTION_ARGS  )

Definition at line 1413 of file regproc.c.

1414{
1415 /* Exactly the same as oidrecv, so share code */
1416 return oidrecv(fcinfo);
1417}

References oidrecv().

◆ regconfigsend()

Datum regconfigsend ( PG_FUNCTION_ARGS  )

Definition at line 1423 of file regproc.c.

1424{
1425 /* Exactly the same as oidsend, so share code */
1426 return oidsend(fcinfo);
1427}

References oidsend().

◆ regdatabasein()

Datum regdatabasein ( PG_FUNCTION_ARGS  )

Definition at line 1783 of file regproc.c.

1784{
1785 char *db_name_or_oid = PG_GETARG_CSTRING(0);
1786 Node *escontext = fcinfo->context;
1787 Oid result;
1788 List *names;
1789
1790 /* Handle "-" or numeric OID */
1791 if (parseDashOrOid(db_name_or_oid, &result, escontext))
1792 PG_RETURN_OID(result);
1793
1794 /* The rest of this wouldn't work in bootstrap mode */
1796 elog(ERROR, "regdatabase values must be OIDs in bootstrap mode");
1797
1798 /* Normal case: see if the name matches any pg_database entry. */
1799 names = stringToQualifiedNameList(db_name_or_oid, escontext);
1800 if (names == NIL)
1802
1803 if (list_length(names) != 1)
1804 ereturn(escontext, (Datum) 0,
1805 (errcode(ERRCODE_INVALID_NAME),
1806 errmsg("invalid name syntax")));
1807
1808 result = get_database_oid(strVal(linitial(names)), true);
1809
1810 if (!OidIsValid(result))
1811 ereturn(escontext, (Datum) 0,
1812 (errcode(ERRCODE_UNDEFINED_OBJECT),
1813 errmsg("database \"%s\" does not exist",
1814 strVal(linitial(names)))));
1815
1816 PG_RETURN_OID(result);
1817}
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:3167
static int list_length(const List *l)
Definition: pg_list.h:152
#define linitial(l)
Definition: pg_list.h:178
#define strVal(v)
Definition: value.h:82

References elog, ereturn, errcode(), errmsg(), ERROR, get_database_oid(), IsBootstrapProcessingMode, linitial, list_length(), NIL, OidIsValid, parseDashOrOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, stringToQualifiedNameList(), and strVal.

Referenced by to_regdatabase().

◆ regdatabaseout()

Datum regdatabaseout ( PG_FUNCTION_ARGS  )

Definition at line 1843 of file regproc.c.

1844{
1845 Oid dboid = PG_GETARG_OID(0);
1846 char *result;
1847
1848 if (dboid == InvalidOid)
1849 {
1850 result = pstrdup("-");
1851 PG_RETURN_CSTRING(result);
1852 }
1853
1854 result = get_database_name(dboid);
1855
1856 if (result)
1857 {
1858 /* pstrdup is not really necessary, but it avoids a compiler warning */
1859 result = pstrdup(quote_identifier(result));
1860 }
1861 else
1862 {
1863 /* If OID doesn't match any database, return it numerically */
1864 result = (char *) palloc(NAMEDATALEN);
1865 snprintf(result, NAMEDATALEN, "%u", dboid);
1866 }
1867
1868 PG_RETURN_CSTRING(result);
1869}
char * get_database_name(Oid dbid)
Definition: lsyscache.c:1259

References get_database_name(), InvalidOid, NAMEDATALEN, palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), quote_identifier(), and snprintf.

◆ regdatabaserecv()

Datum regdatabaserecv ( PG_FUNCTION_ARGS  )

Definition at line 1875 of file regproc.c.

1876{
1877 /* Exactly the same as oidrecv, so share code */
1878 return oidrecv(fcinfo);
1879}

References oidrecv().

◆ regdatabasesend()

Datum regdatabasesend ( PG_FUNCTION_ARGS  )

Definition at line 1885 of file regproc.c.

1886{
1887 /* Exactly the same as oidsend, so share code */
1888 return oidsend(fcinfo);
1889}

References oidsend().

◆ regdictionaryin()

Datum regdictionaryin ( PG_FUNCTION_ARGS  )

Definition at line 1439 of file regproc.c.

1440{
1441 char *dict_name_or_oid = PG_GETARG_CSTRING(0);
1442 Node *escontext = fcinfo->context;
1443 Oid result;
1444 List *names;
1445
1446 /* Handle "-" or numeric OID */
1447 if (parseDashOrOid(dict_name_or_oid, &result, escontext))
1448 PG_RETURN_OID(result);
1449
1450 /* The rest of this wouldn't work in bootstrap mode */
1452 elog(ERROR, "regdictionary values must be OIDs in bootstrap mode");
1453
1454 /*
1455 * Normal case: parse the name into components and see if it matches any
1456 * pg_ts_dict entries in the current search path.
1457 */
1458 names = stringToQualifiedNameList(dict_name_or_oid, escontext);
1459 if (names == NIL)
1461
1462 result = get_ts_dict_oid(names, true);
1463
1464 if (!OidIsValid(result))
1465 ereturn(escontext, (Datum) 0,
1466 (errcode(ERRCODE_UNDEFINED_OBJECT),
1467 errmsg("text search dictionary \"%s\" does not exist",
1468 NameListToString(names))));
1469
1470 PG_RETURN_OID(result);
1471}
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2931

References elog, ereturn, errcode(), errmsg(), ERROR, get_ts_dict_oid(), IsBootstrapProcessingMode, NameListToString(), NIL, OidIsValid, parseDashOrOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, and stringToQualifiedNameList().

◆ regdictionaryout()

Datum regdictionaryout ( PG_FUNCTION_ARGS  )

Definition at line 1477 of file regproc.c.

1478{
1479 Oid dictid = PG_GETARG_OID(0);
1480 char *result;
1481 HeapTuple dicttup;
1482
1483 if (dictid == InvalidOid)
1484 {
1485 result = pstrdup("-");
1486 PG_RETURN_CSTRING(result);
1487 }
1488
1489 dicttup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictid));
1490
1491 if (HeapTupleIsValid(dicttup))
1492 {
1493 Form_pg_ts_dict dictform = (Form_pg_ts_dict) GETSTRUCT(dicttup);
1494 char *dictname = NameStr(dictform->dictname);
1495 char *nspname;
1496
1497 /*
1498 * Would this dictionary be found by regdictionaryin? If not, qualify
1499 * it.
1500 */
1501 if (TSDictionaryIsVisible(dictid))
1502 nspname = NULL;
1503 else
1504 nspname = get_namespace_name(dictform->dictnamespace);
1505
1506 result = quote_qualified_identifier(nspname, dictname);
1507
1508 ReleaseSysCache(dicttup);
1509 }
1510 else
1511 {
1512 /* If OID doesn't match any pg_ts_dict row, return it numerically */
1513 result = (char *) palloc(NAMEDATALEN);
1514 snprintf(result, NAMEDATALEN, "%u", dictid);
1515 }
1516
1517 PG_RETURN_CSTRING(result);
1518}
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2989
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52

References get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), snprintf, and TSDictionaryIsVisible().

◆ regdictionaryrecv()

Datum regdictionaryrecv ( PG_FUNCTION_ARGS  )

Definition at line 1524 of file regproc.c.

1525{
1526 /* Exactly the same as oidrecv, so share code */
1527 return oidrecv(fcinfo);
1528}

References oidrecv().

◆ regdictionarysend()

Datum regdictionarysend ( PG_FUNCTION_ARGS  )

Definition at line 1534 of file regproc.c.

1535{
1536 /* Exactly the same as oidsend, so share code */
1537 return oidsend(fcinfo);
1538}

References oidsend().

◆ regnamespacein()

Datum regnamespacein ( PG_FUNCTION_ARGS  )

Definition at line 1666 of file regproc.c.

1667{
1668 char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
1669 Node *escontext = fcinfo->context;
1670 Oid result;
1671 List *names;
1672
1673 /* Handle "-" or numeric OID */
1674 if (parseDashOrOid(nsp_name_or_oid, &result, escontext))
1675 PG_RETURN_OID(result);
1676
1677 /* The rest of this wouldn't work in bootstrap mode */
1679 elog(ERROR, "regnamespace values must be OIDs in bootstrap mode");
1680
1681 /* Normal case: see if the name matches any pg_namespace entry. */
1682 names = stringToQualifiedNameList(nsp_name_or_oid, escontext);
1683 if (names == NIL)
1685
1686 if (list_length(names) != 1)
1687 ereturn(escontext, (Datum) 0,
1688 (errcode(ERRCODE_INVALID_NAME),
1689 errmsg("invalid name syntax")));
1690
1691 result = get_namespace_oid(strVal(linitial(names)), true);
1692
1693 if (!OidIsValid(result))
1694 ereturn(escontext, (Datum) 0,
1695 (errcode(ERRCODE_UNDEFINED_SCHEMA),
1696 errmsg("schema \"%s\" does not exist",
1697 strVal(linitial(names)))));
1698
1699 PG_RETURN_OID(result);
1700}
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3605

References elog, ereturn, errcode(), errmsg(), ERROR, get_namespace_oid(), IsBootstrapProcessingMode, linitial, list_length(), NIL, OidIsValid, parseDashOrOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, stringToQualifiedNameList(), and strVal.

Referenced by to_regnamespace().

◆ regnamespaceout()

Datum regnamespaceout ( PG_FUNCTION_ARGS  )

Definition at line 1726 of file regproc.c.

1727{
1728 Oid nspid = PG_GETARG_OID(0);
1729 char *result;
1730
1731 if (nspid == InvalidOid)
1732 {
1733 result = pstrdup("-");
1734 PG_RETURN_CSTRING(result);
1735 }
1736
1737 result = get_namespace_name(nspid);
1738
1739 if (result)
1740 {
1741 /* pstrdup is not really necessary, but it avoids a compiler warning */
1742 result = pstrdup(quote_identifier(result));
1743 }
1744 else
1745 {
1746 /* If OID doesn't match any namespace, return it numerically */
1747 result = (char *) palloc(NAMEDATALEN);
1748 snprintf(result, NAMEDATALEN, "%u", nspid);
1749 }
1750
1751 PG_RETURN_CSTRING(result);
1752}
int nspid

References get_namespace_name(), InvalidOid, NAMEDATALEN, nspid, palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), quote_identifier(), and snprintf.

◆ regnamespacerecv()

Datum regnamespacerecv ( PG_FUNCTION_ARGS  )

Definition at line 1758 of file regproc.c.

1759{
1760 /* Exactly the same as oidrecv, so share code */
1761 return oidrecv(fcinfo);
1762}

References oidrecv().

◆ regnamespacesend()

Datum regnamespacesend ( PG_FUNCTION_ARGS  )

Definition at line 1768 of file regproc.c.

1769{
1770 /* Exactly the same as oidsend, so share code */
1771 return oidsend(fcinfo);
1772}

References oidsend().

◆ regoperatorin()

Datum regoperatorin ( PG_FUNCTION_ARGS  )

Definition at line 647 of file regproc.c.

648{
649 char *opr_name_or_oid = PG_GETARG_CSTRING(0);
650 Node *escontext = fcinfo->context;
651 Oid result;
652 List *names;
653 int nargs;
654 Oid argtypes[FUNC_MAX_ARGS];
655
656 /* Handle "0" or numeric OID */
657 if (parseNumericOid(opr_name_or_oid, &result, escontext))
658 PG_RETURN_OID(result);
659
660 /* The rest of this wouldn't work in bootstrap mode */
662 elog(ERROR, "regoperator values must be OIDs in bootstrap mode");
663
664 /*
665 * Else it's a name and arguments. Parse the name and arguments, look up
666 * potential matches in the current namespace search list, and scan to see
667 * which one exactly matches the given argument types. (There will not be
668 * more than one match.)
669 */
670 if (!parseNameAndArgTypes(opr_name_or_oid, true,
671 &names, &nargs, argtypes,
672 escontext))
674
675 if (nargs == 1)
676 ereturn(escontext, (Datum) 0,
677 (errcode(ERRCODE_UNDEFINED_PARAMETER),
678 errmsg("missing argument"),
679 errhint("Use NONE to denote the missing argument of a unary operator.")));
680 if (nargs != 2)
681 ereturn(escontext, (Datum) 0,
682 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
683 errmsg("too many arguments"),
684 errhint("Provide two argument types for operator.")));
685
686 result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
687
688 if (!OidIsValid(result))
689 ereturn(escontext, (Datum) 0,
690 (errcode(ERRCODE_UNDEFINED_FUNCTION),
691 errmsg("operator does not exist: %s", opr_name_or_oid)));
692
693 PG_RETURN_OID(result);
694}
int errhint(const char *fmt,...)
Definition: elog.c:1321
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1832
static bool parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes, Node *escontext)
Definition: regproc.c:2020

References elog, ereturn, errcode(), errhint(), errmsg(), ERROR, FUNC_MAX_ARGS, IsBootstrapProcessingMode, OidIsValid, OpernameGetOprid(), parseNameAndArgTypes(), parseNumericOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, and PG_RETURN_OID.

Referenced by to_regoperator().

◆ regoperatorout()

Datum regoperatorout ( PG_FUNCTION_ARGS  )

Definition at line 847 of file regproc.c.

848{
850 char *result;
851
852 if (oprid == InvalidOid)
853 result = pstrdup("0");
854 else
855 result = format_operator(oprid);
856
857 PG_RETURN_CSTRING(result);
858}
Oid oprid(Operator op)
Definition: parse_oper.c:239
char * format_operator(Oid operator_oid)
Definition: regproc.c:801

References format_operator(), InvalidOid, oprid(), PG_GETARG_OID, PG_RETURN_CSTRING, and pstrdup().

◆ regoperatorrecv()

Datum regoperatorrecv ( PG_FUNCTION_ARGS  )

Definition at line 864 of file regproc.c.

865{
866 /* Exactly the same as oidrecv, so share code */
867 return oidrecv(fcinfo);
868}

References oidrecv().

◆ regoperatorsend()

Datum regoperatorsend ( PG_FUNCTION_ARGS  )

Definition at line 874 of file regproc.c.

875{
876 /* Exactly the same as oidsend, so share code */
877 return oidsend(fcinfo);
878}

References oidsend().

◆ regoperin()

Datum regoperin ( PG_FUNCTION_ARGS  )

Definition at line 484 of file regproc.c.

485{
486 char *opr_name_or_oid = PG_GETARG_CSTRING(0);
487 Node *escontext = fcinfo->context;
488 Oid result;
489 List *names;
490 FuncCandidateList clist;
491 int fgc_flags;
492
493 /* Handle "0" or numeric OID */
494 if (parseNumericOid(opr_name_or_oid, &result, escontext))
495 PG_RETURN_OID(result);
496
497 /* Else it's a name, possibly schema-qualified */
498
499 /* The rest of this wouldn't work in bootstrap mode */
501 elog(ERROR, "regoper values must be OIDs in bootstrap mode");
502
503 /*
504 * Normal case: parse the name into components and see if it matches any
505 * pg_operator entries in the current search path.
506 */
507 names = stringToQualifiedNameList(opr_name_or_oid, escontext);
508 if (names == NIL)
510
511 clist = OpernameGetCandidates(names, '\0', true, &fgc_flags);
512
513 if (clist == NULL)
514 ereturn(escontext, (Datum) 0,
515 (errcode(ERRCODE_UNDEFINED_FUNCTION),
516 errmsg("operator does not exist: %s", opr_name_or_oid)));
517 else if (clist->next != NULL)
518 ereturn(escontext, (Datum) 0,
519 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
520 errmsg("more than one operator named %s",
521 opr_name_or_oid)));
522
523 result = clist->oid;
524
525 PG_RETURN_OID(result);
526}
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok, int *fgc_flags)
Definition: namespace.c:1945
struct _FuncCandidateList * next
Definition: namespace.h:31

References elog, ereturn, errcode(), errmsg(), ERROR, IsBootstrapProcessingMode, _FuncCandidateList::next, NIL, _FuncCandidateList::oid, OpernameGetCandidates(), parseNumericOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, and stringToQualifiedNameList().

Referenced by to_regoper().

◆ regoperout()

Datum regoperout ( PG_FUNCTION_ARGS  )

Definition at line 552 of file regproc.c.

553{
555 char *result;
556 HeapTuple opertup;
557
558 if (oprid == InvalidOid)
559 {
560 result = pstrdup("0");
561 PG_RETURN_CSTRING(result);
562 }
563
564 opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(oprid));
565
566 if (HeapTupleIsValid(opertup))
567 {
568 Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
569 char *oprname = NameStr(operform->oprname);
570
571 /*
572 * In bootstrap mode, skip the fancy namespace stuff and just return
573 * the oper name. (This path is only needed for debugging output
574 * anyway.)
575 */
577 result = pstrdup(oprname);
578 else
579 {
580 FuncCandidateList clist;
581 int fgc_flags;
582
583 /*
584 * Would this oper be found (uniquely!) by regoperin? If not,
585 * qualify it.
586 */
588 '\0', false, &fgc_flags);
589 if (clist != NULL && clist->next == NULL &&
590 clist->oid == oprid)
591 result = pstrdup(oprname);
592 else
593 {
594 const char *nspname;
595
596 nspname = get_namespace_name(operform->oprnamespace);
597 nspname = quote_identifier(nspname);
598 result = (char *) palloc(strlen(nspname) + strlen(oprname) + 2);
599 sprintf(result, "%s.%s", nspname, oprname);
600 }
601 }
602
603 ReleaseSysCache(opertup);
604 }
605 else
606 {
607 /*
608 * If OID doesn't match any pg_operator entry, return it numerically
609 */
610 result = (char *) palloc(NAMEDATALEN);
611 snprintf(result, NAMEDATALEN, "%u", oprid);
612 }
613
614 PG_RETURN_CSTRING(result);
615}
#define list_make1(x1)
Definition: pg_list.h:212
#define sprintf
Definition: port.h:241
String * makeString(char *str)
Definition: value.c:63

References get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, IsBootstrapProcessingMode, list_make1, makeString(), NAMEDATALEN, NameStr, _FuncCandidateList::next, ObjectIdGetDatum(), _FuncCandidateList::oid, OpernameGetCandidates(), oprid(), palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), quote_identifier(), ReleaseSysCache(), SearchSysCache1(), snprintf, and sprintf.

◆ regoperrecv()

Datum regoperrecv ( PG_FUNCTION_ARGS  )

Definition at line 621 of file regproc.c.

622{
623 /* Exactly the same as oidrecv, so share code */
624 return oidrecv(fcinfo);
625}

References oidrecv().

◆ regopersend()

Datum regopersend ( PG_FUNCTION_ARGS  )

Definition at line 631 of file regproc.c.

632{
633 /* Exactly the same as oidsend, so share code */
634 return oidsend(fcinfo);
635}

References oidsend().

◆ regprocedurein()

Datum regprocedurein ( PG_FUNCTION_ARGS  )

Definition at line 229 of file regproc.c.

230{
231 char *pro_name_or_oid = PG_GETARG_CSTRING(0);
232 Node *escontext = fcinfo->context;
233 RegProcedure result;
234 List *names;
235 int nargs;
236 Oid argtypes[FUNC_MAX_ARGS];
237 FuncCandidateList clist;
238 int fgc_flags;
239
240 /* Handle "-" or numeric OID */
241 if (parseDashOrOid(pro_name_or_oid, &result, escontext))
242 PG_RETURN_OID(result);
243
244 /* The rest of this wouldn't work in bootstrap mode */
246 elog(ERROR, "regprocedure values must be OIDs in bootstrap mode");
247
248 /*
249 * Else it's a name and arguments. Parse the name and arguments, look up
250 * potential matches in the current namespace search list, and scan to see
251 * which one exactly matches the given argument types. (There will not be
252 * more than one match.)
253 */
254 if (!parseNameAndArgTypes(pro_name_or_oid, false,
255 &names, &nargs, argtypes,
256 escontext))
258
259 clist = FuncnameGetCandidates(names, nargs, NIL, false, false, false, true,
260 &fgc_flags);
261
262 for (; clist; clist = clist->next)
263 {
264 if (memcmp(clist->args, argtypes, nargs * sizeof(Oid)) == 0)
265 break;
266 }
267
268 if (clist == NULL)
269 ereturn(escontext, (Datum) 0,
270 (errcode(ERRCODE_UNDEFINED_FUNCTION),
271 errmsg("function \"%s\" does not exist", pro_name_or_oid)));
272
273 result = clist->oid;
274
275 PG_RETURN_OID(result);
276}
regproc RegProcedure
Definition: c.h:656
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool include_out_arguments, bool missing_ok, int *fgc_flags)
Definition: namespace.c:1197
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition: namespace.h:39

References _FuncCandidateList::args, elog, ereturn, errcode(), errmsg(), ERROR, FUNC_MAX_ARGS, FuncnameGetCandidates(), IsBootstrapProcessingMode, _FuncCandidateList::next, NIL, _FuncCandidateList::oid, parseDashOrOid(), parseNameAndArgTypes(), PG_GETARG_CSTRING, PG_RETURN_NULL, and PG_RETURN_OID.

Referenced by convert_function_name(), and to_regprocedure().

◆ regprocedureout()

Datum regprocedureout ( PG_FUNCTION_ARGS  )

Definition at line 441 of file regproc.c.

442{
443 RegProcedure proid = PG_GETARG_OID(0);
444 char *result;
445
446 if (proid == InvalidOid)
447 result = pstrdup("-");
448 else
449 result = format_procedure(proid);
450
451 PG_RETURN_CSTRING(result);
452}
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:305

References format_procedure(), InvalidOid, PG_GETARG_OID, PG_RETURN_CSTRING, and pstrdup().

◆ regprocedurerecv()

Datum regprocedurerecv ( PG_FUNCTION_ARGS  )

Definition at line 458 of file regproc.c.

459{
460 /* Exactly the same as oidrecv, so share code */
461 return oidrecv(fcinfo);
462}

References oidrecv().

◆ regproceduresend()

Datum regproceduresend ( PG_FUNCTION_ARGS  )

Definition at line 468 of file regproc.c.

469{
470 /* Exactly the same as oidsend, so share code */
471 return oidsend(fcinfo);
472}

References oidsend().

◆ regprocin()

Datum regprocin ( PG_FUNCTION_ARGS  )

Definition at line 67 of file regproc.c.

68{
69 char *pro_name_or_oid = PG_GETARG_CSTRING(0);
70 Node *escontext = fcinfo->context;
71 RegProcedure result;
72 List *names;
74 int fgc_flags;
75
76 /* Handle "-" or numeric OID */
77 if (parseDashOrOid(pro_name_or_oid, &result, escontext))
78 PG_RETURN_OID(result);
79
80 /* Else it's a name, possibly schema-qualified */
81
82 /*
83 * We should never get here in bootstrap mode, as all references should
84 * have been resolved by genbki.pl.
85 */
87 elog(ERROR, "regproc values must be OIDs in bootstrap mode");
88
89 /*
90 * Normal case: parse the name into components and see if it matches any
91 * pg_proc entries in the current search path.
92 */
93 names = stringToQualifiedNameList(pro_name_or_oid, escontext);
94 if (names == NIL)
96
97 clist = FuncnameGetCandidates(names, -1, NIL, false, false, false, true,
98 &fgc_flags);
99
100 if (clist == NULL)
101 ereturn(escontext, (Datum) 0,
102 (errcode(ERRCODE_UNDEFINED_FUNCTION),
103 errmsg("function \"%s\" does not exist", pro_name_or_oid)));
104 else if (clist->next != NULL)
105 ereturn(escontext, (Datum) 0,
106 (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
107 errmsg("more than one function named \"%s\"",
108 pro_name_or_oid)));
109
110 result = clist->oid;
111
112 PG_RETURN_OID(result);
113}

References elog, ereturn, errcode(), errmsg(), ERROR, FuncnameGetCandidates(), IsBootstrapProcessingMode, _FuncCandidateList::next, NIL, _FuncCandidateList::oid, parseDashOrOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, and stringToQualifiedNameList().

Referenced by to_regproc().

◆ regprocout()

Datum regprocout ( PG_FUNCTION_ARGS  )

Definition at line 139 of file regproc.c.

140{
141 RegProcedure proid = PG_GETARG_OID(0);
142 char *result;
143 HeapTuple proctup;
144
145 if (proid == InvalidOid)
146 {
147 result = pstrdup("-");
148 PG_RETURN_CSTRING(result);
149 }
150
151 proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(proid));
152
153 if (HeapTupleIsValid(proctup))
154 {
155 Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
156 char *proname = NameStr(procform->proname);
157
158 /*
159 * In bootstrap mode, skip the fancy namespace stuff and just return
160 * the proc name. (This path is only needed for debugging output
161 * anyway.)
162 */
164 result = pstrdup(proname);
165 else
166 {
167 char *nspname;
168 FuncCandidateList clist;
169 int fgc_flags;
170
171 /*
172 * Would this proc be found (uniquely!) by regprocin? If not,
173 * qualify it.
174 */
176 -1, NIL, false, false, false, false,
177 &fgc_flags);
178 if (clist != NULL && clist->next == NULL &&
179 clist->oid == proid)
180 nspname = NULL;
181 else
182 nspname = get_namespace_name(procform->pronamespace);
183
184 result = quote_qualified_identifier(nspname, proname);
185 }
186
187 ReleaseSysCache(proctup);
188 }
189 else
190 {
191 /* If OID doesn't match any pg_proc entry, return it numerically */
192 result = (char *) palloc(NAMEDATALEN);
193 snprintf(result, NAMEDATALEN, "%u", proid);
194 }
195
196 PG_RETURN_CSTRING(result);
197}

References FuncnameGetCandidates(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, IsBootstrapProcessingMode, list_make1, makeString(), NAMEDATALEN, NameStr, _FuncCandidateList::next, NIL, ObjectIdGetDatum(), _FuncCandidateList::oid, palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, proname, pstrdup(), quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

◆ regprocrecv()

Datum regprocrecv ( PG_FUNCTION_ARGS  )

Definition at line 203 of file regproc.c.

204{
205 /* Exactly the same as oidrecv, so share code */
206 return oidrecv(fcinfo);
207}

References oidrecv().

◆ regprocsend()

Datum regprocsend ( PG_FUNCTION_ARGS  )

Definition at line 213 of file regproc.c.

214{
215 /* Exactly the same as oidsend, so share code */
216 return oidsend(fcinfo);
217}

References oidsend().

◆ regrolein()

Datum regrolein ( PG_FUNCTION_ARGS  )

Definition at line 1549 of file regproc.c.

1550{
1551 char *role_name_or_oid = PG_GETARG_CSTRING(0);
1552 Node *escontext = fcinfo->context;
1553 Oid result;
1554 List *names;
1555
1556 /* Handle "-" or numeric OID */
1557 if (parseDashOrOid(role_name_or_oid, &result, escontext))
1558 PG_RETURN_OID(result);
1559
1560 /* The rest of this wouldn't work in bootstrap mode */
1562 elog(ERROR, "regrole values must be OIDs in bootstrap mode");
1563
1564 /* Normal case: see if the name matches any pg_authid entry. */
1565 names = stringToQualifiedNameList(role_name_or_oid, escontext);
1566 if (names == NIL)
1568
1569 if (list_length(names) != 1)
1570 ereturn(escontext, (Datum) 0,
1571 (errcode(ERRCODE_INVALID_NAME),
1572 errmsg("invalid name syntax")));
1573
1574 result = get_role_oid(strVal(linitial(names)), true);
1575
1576 if (!OidIsValid(result))
1577 ereturn(escontext, (Datum) 0,
1578 (errcode(ERRCODE_UNDEFINED_OBJECT),
1579 errmsg("role \"%s\" does not exist",
1580 strVal(linitial(names)))));
1581
1582 PG_RETURN_OID(result);
1583}
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5552

References elog, ereturn, errcode(), errmsg(), ERROR, get_role_oid(), IsBootstrapProcessingMode, linitial, list_length(), NIL, OidIsValid, parseDashOrOid(), PG_GETARG_CSTRING, PG_RETURN_NULL, PG_RETURN_OID, stringToQualifiedNameList(), and strVal.

Referenced by to_regrole().

◆ regroleout()

Datum regroleout ( PG_FUNCTION_ARGS  )

Definition at line 1609 of file regproc.c.

1610{
1611 Oid roleoid = PG_GETARG_OID(0);
1612 char *result;
1613
1614 if (roleoid == InvalidOid)
1615 {
1616 result = pstrdup("-");
1617 PG_RETURN_CSTRING(result);
1618 }
1619
1620 result = GetUserNameFromId(roleoid, true);
1621
1622 if (result)
1623 {
1624 /* pstrdup is not really necessary, but it avoids a compiler warning */
1625 result = pstrdup(quote_identifier(result));
1626 }
1627 else
1628 {
1629 /* If OID doesn't match any role, return it numerically */
1630 result = (char *) palloc(NAMEDATALEN);
1631 snprintf(result, NAMEDATALEN, "%u", roleoid);
1632 }
1633
1634 PG_RETURN_CSTRING(result);
1635}
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:988

References GetUserNameFromId(), InvalidOid, NAMEDATALEN, palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), quote_identifier(), and snprintf.

◆ regrolerecv()

Datum regrolerecv ( PG_FUNCTION_ARGS  )

Definition at line 1641 of file regproc.c.

1642{
1643 /* Exactly the same as oidrecv, so share code */
1644 return oidrecv(fcinfo);
1645}

References oidrecv().

◆ regrolesend()

Datum regrolesend ( PG_FUNCTION_ARGS  )

Definition at line 1651 of file regproc.c.

1652{
1653 /* Exactly the same as oidsend, so share code */
1654 return oidsend(fcinfo);
1655}

References oidsend().

◆ regtypein()

Datum regtypein ( PG_FUNCTION_ARGS  )

Definition at line 1184 of file regproc.c.

1185{
1186 char *typ_name_or_oid = PG_GETARG_CSTRING(0);
1187 Node *escontext = fcinfo->context;
1188 Oid result;
1189 int32 typmod;
1190
1191 /* Handle "-" or numeric OID */
1192 if (parseDashOrOid(typ_name_or_oid, &result, escontext))
1193 PG_RETURN_OID(result);
1194
1195 /* Else it's a type name, possibly schema-qualified or decorated */
1196
1197 /* The rest of this wouldn't work in bootstrap mode */
1199 elog(ERROR, "regtype values must be OIDs in bootstrap mode");
1200
1201 /*
1202 * Normal case: invoke the full parser to deal with special cases such as
1203 * array syntax. We don't need to check for parseTypeString failure,
1204 * since we'll just return anyway.
1205 */
1206 (void) parseTypeString(typ_name_or_oid, &result, &typmod, escontext);
1207
1208 PG_RETURN_OID(result);
1209}

References elog, ERROR, IsBootstrapProcessingMode, parseDashOrOid(), parseTypeString(), PG_GETARG_CSTRING, and PG_RETURN_OID.

Referenced by convert_type_name(), plperl_sv_to_literal(), and to_regtype().

◆ regtypeout()

Datum regtypeout ( PG_FUNCTION_ARGS  )

Definition at line 1255 of file regproc.c.

1256{
1257 Oid typid = PG_GETARG_OID(0);
1258 char *result;
1259 HeapTuple typetup;
1260
1261 if (typid == InvalidOid)
1262 {
1263 result = pstrdup("-");
1264 PG_RETURN_CSTRING(result);
1265 }
1266
1267 typetup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid));
1268
1269 if (HeapTupleIsValid(typetup))
1270 {
1271 Form_pg_type typeform = (Form_pg_type) GETSTRUCT(typetup);
1272
1273 /*
1274 * In bootstrap mode, skip the fancy namespace stuff and just return
1275 * the type name. (This path is only needed for debugging output
1276 * anyway.)
1277 */
1279 {
1280 char *typname = NameStr(typeform->typname);
1281
1282 result = pstrdup(typname);
1283 }
1284 else
1285 result = format_type_be(typid);
1286
1287 ReleaseSysCache(typetup);
1288 }
1289 else
1290 {
1291 /* If OID doesn't match any pg_type entry, return it numerically */
1292 result = (char *) palloc(NAMEDATALEN);
1293 snprintf(result, NAMEDATALEN, "%u", typid);
1294 }
1295
1296 PG_RETURN_CSTRING(result);
1297}
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
NameData typname
Definition: pg_type.h:41

References format_type_be(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, pstrdup(), ReleaseSysCache(), SearchSysCache1(), snprintf, and typname.

◆ regtyperecv()

Datum regtyperecv ( PG_FUNCTION_ARGS  )

Definition at line 1303 of file regproc.c.

1304{
1305 /* Exactly the same as oidrecv, so share code */
1306 return oidrecv(fcinfo);
1307}

References oidrecv().

◆ regtypesend()

Datum regtypesend ( PG_FUNCTION_ARGS  )

Definition at line 1313 of file regproc.c.

1314{
1315 /* Exactly the same as oidsend, so share code */
1316 return oidsend(fcinfo);
1317}

References oidsend().

◆ stringToQualifiedNameList()

List * stringToQualifiedNameList ( const char *  string,
Node escontext 
)

Definition at line 1922 of file regproc.c.

1923{
1924 char *rawname;
1925 List *result = NIL;
1926 List *namelist;
1927 ListCell *l;
1928
1929 /* We need a modifiable copy of the input string. */
1930 rawname = pstrdup(string);
1931
1932 if (!SplitIdentifierString(rawname, '.', &namelist))
1933 ereturn(escontext, NIL,
1934 (errcode(ERRCODE_INVALID_NAME),
1935 errmsg("invalid name syntax")));
1936
1937 if (namelist == NIL)
1938 ereturn(escontext, NIL,
1939 (errcode(ERRCODE_INVALID_NAME),
1940 errmsg("invalid name syntax")));
1941
1942 foreach(l, namelist)
1943 {
1944 char *curname = (char *) lfirst(l);
1945
1946 result = lappend(result, makeString(pstrdup(curname)));
1947 }
1948
1949 pfree(rawname);
1950 list_free(namelist);
1951
1952 return result;
1953}
void list_free(List *list)
Definition: list.c:1546
#define lfirst(lc)
Definition: pg_list.h:172
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:2744

References ereturn, errcode(), errmsg(), lappend(), lfirst, list_free(), makeString(), NIL, pfree(), pstrdup(), and SplitIdentifierString().

Referenced by call_pltcl_start_proc(), check_default_text_search_config(), getTSCurrentConfig(), parseNameAndArgTypes(), regclassin(), regcollationin(), regconfigin(), regdatabasein(), regdictionaryin(), regnamespacein(), regoperin(), regprocin(), regrolein(), RelationNameGetTupleDesc(), thesaurus_init(), and tsvector_update_trigger().

◆ text_regclass()

Datum text_regclass ( PG_FUNCTION_ARGS  )

Definition at line 1899 of file regproc.c.

1900{
1902 Oid result;
1903 RangeVar *rv;
1904
1906
1907 /* We might not even have permissions on this relation; don't lock it. */
1908 result = RangeVarGetRelid(rv, NoLock, false);
1909
1910 PG_RETURN_OID(result);
1911}
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
NameData relname
Definition: pg_class.h:38
Definition: c.h:693
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:2686

References makeRangeVarFromNameList(), NoLock, PG_GETARG_TEXT_PP, PG_RETURN_OID, RangeVarGetRelid, relname, and textToQualifiedNameList().

◆ to_regclass()

Datum to_regclass ( PG_FUNCTION_ARGS  )

Definition at line 933 of file regproc.c.

934{
936 Datum result;
937 ErrorSaveContext escontext = {T_ErrorSaveContext};
938
940 InvalidOid, -1,
941 (Node *) &escontext,
942 &result))
944 PG_RETURN_DATUM(result);
945}
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Datum regclassin(PG_FUNCTION_ARGS)
Definition: regproc.c:890
const char * class_name
Definition: selinux.c:32
char * text_to_cstring(const text *t)
Definition: varlena.c:214

References class_name, DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regclassin(), and text_to_cstring().

◆ to_regcollation()

Datum to_regcollation ( PG_FUNCTION_ARGS  )

Definition at line 1076 of file regproc.c.

1077{
1078 char *collation_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1079 Datum result;
1080 ErrorSaveContext escontext = {T_ErrorSaveContext};
1081
1082 if (!DirectInputFunctionCallSafe(regcollationin, collation_name,
1083 InvalidOid, -1,
1084 (Node *) &escontext,
1085 &result))
1087 PG_RETURN_DATUM(result);
1088}
Datum regcollationin(PG_FUNCTION_ARGS)
Definition: regproc.c:1034

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regcollationin(), and text_to_cstring().

◆ to_regdatabase()

Datum to_regdatabase ( PG_FUNCTION_ARGS  )

Definition at line 1825 of file regproc.c.

1826{
1827 char *db_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1828 Datum result;
1829 ErrorSaveContext escontext = {T_ErrorSaveContext};
1830
1832 InvalidOid, -1,
1833 (Node *) &escontext,
1834 &result))
1836 PG_RETURN_DATUM(result);
1837}
Datum regdatabasein(PG_FUNCTION_ARGS)
Definition: regproc.c:1783

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regdatabasein(), and text_to_cstring().

◆ to_regnamespace()

Datum to_regnamespace ( PG_FUNCTION_ARGS  )

Definition at line 1708 of file regproc.c.

1709{
1710 char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1711 Datum result;
1712 ErrorSaveContext escontext = {T_ErrorSaveContext};
1713
1715 InvalidOid, -1,
1716 (Node *) &escontext,
1717 &result))
1719 PG_RETURN_DATUM(result);
1720}
Datum regnamespacein(PG_FUNCTION_ARGS)
Definition: regproc.c:1666

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regnamespacein(), and text_to_cstring().

◆ to_regoper()

Datum to_regoper ( PG_FUNCTION_ARGS  )

Definition at line 534 of file regproc.c.

535{
536 char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
537 Datum result;
538 ErrorSaveContext escontext = {T_ErrorSaveContext};
539
541 InvalidOid, -1,
542 (Node *) &escontext,
543 &result))
545 PG_RETURN_DATUM(result);
546}
Datum regoperin(PG_FUNCTION_ARGS)
Definition: regproc.c:484

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regoperin(), and text_to_cstring().

◆ to_regoperator()

Datum to_regoperator ( PG_FUNCTION_ARGS  )

Definition at line 702 of file regproc.c.

703{
704 char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
705 Datum result;
706 ErrorSaveContext escontext = {T_ErrorSaveContext};
707
708 if (!DirectInputFunctionCallSafe(regoperatorin, opr_name_or_oid,
709 InvalidOid, -1,
710 (Node *) &escontext,
711 &result))
713 PG_RETURN_DATUM(result);
714}
Datum regoperatorin(PG_FUNCTION_ARGS)
Definition: regproc.c:647

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regoperatorin(), and text_to_cstring().

◆ to_regproc()

Datum to_regproc ( PG_FUNCTION_ARGS  )

Definition at line 121 of file regproc.c.

122{
123 char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
124 Datum result;
125 ErrorSaveContext escontext = {T_ErrorSaveContext};
126
128 InvalidOid, -1,
129 (Node *) &escontext,
130 &result))
132 PG_RETURN_DATUM(result);
133}
Datum regprocin(PG_FUNCTION_ARGS)
Definition: regproc.c:67

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regprocin(), and text_to_cstring().

◆ to_regprocedure()

Datum to_regprocedure ( PG_FUNCTION_ARGS  )

Definition at line 284 of file regproc.c.

285{
286 char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
287 Datum result;
288 ErrorSaveContext escontext = {T_ErrorSaveContext};
289
291 InvalidOid, -1,
292 (Node *) &escontext,
293 &result))
295 PG_RETURN_DATUM(result);
296}
Datum regprocedurein(PG_FUNCTION_ARGS)
Definition: regproc.c:229

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regprocedurein(), and text_to_cstring().

◆ to_regrole()

Datum to_regrole ( PG_FUNCTION_ARGS  )

Definition at line 1591 of file regproc.c.

1592{
1593 char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1594 Datum result;
1595 ErrorSaveContext escontext = {T_ErrorSaveContext};
1596
1597 if (!DirectInputFunctionCallSafe(regrolein, role_name,
1598 InvalidOid, -1,
1599 (Node *) &escontext,
1600 &result))
1602 PG_RETURN_DATUM(result);
1603}
Datum regrolein(PG_FUNCTION_ARGS)
Definition: regproc.c:1549

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regrolein(), and text_to_cstring().

◆ to_regtype()

Datum to_regtype ( PG_FUNCTION_ARGS  )

Definition at line 1217 of file regproc.c.

1218{
1219 char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1220 Datum result;
1221 ErrorSaveContext escontext = {T_ErrorSaveContext};
1222
1224 InvalidOid, -1,
1225 (Node *) &escontext,
1226 &result))
1228 PG_RETURN_DATUM(result);
1229}
Datum regtypein(PG_FUNCTION_ARGS)
Definition: regproc.c:1184

References DirectInputFunctionCallSafe(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, regtypein(), and text_to_cstring().

◆ to_regtypemod()

Datum to_regtypemod ( PG_FUNCTION_ARGS  )

Definition at line 1237 of file regproc.c.

1238{
1239 char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1240 Oid typid;
1241 int32 typmod;
1242 ErrorSaveContext escontext = {T_ErrorSaveContext};
1243
1244 /* We rely on parseTypeString to parse the input. */
1245 if (!parseTypeString(typ_name, &typid, &typmod, (Node *) &escontext))
1247
1248 PG_RETURN_INT32(typmod);
1249}
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354

References parseTypeString(), PG_GETARG_TEXT_PP, PG_RETURN_INT32, PG_RETURN_NULL, and text_to_cstring().