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_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 text_regclass (PG_FUNCTION_ARGS)
 
ListstringToQualifiedNameList (const char *string, Node *escontext)
 

Function Documentation

◆ format_operator()

char* format_operator ( Oid  operator_oid)

Definition at line 793 of file regproc.c.

794 {
795  return format_operator_extended(operator_oid, 0);
796 }
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:722

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 722 of file regproc.c.

723 {
724  char *result;
725  HeapTuple opertup;
726 
727  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
728 
729  if (HeapTupleIsValid(opertup))
730  {
731  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
732  char *oprname = NameStr(operform->oprname);
733  char *nspname;
735 
736  /* XXX no support here for bootstrap mode */
738 
740 
741  /*
742  * Would this oper be found (given the right args) by regoperatorin?
743  * If not, or if caller explicitly requests it, we need to qualify it.
744  */
745  if ((flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ||
746  !OperatorIsVisible(operator_oid))
747  {
748  nspname = get_namespace_name(operform->oprnamespace);
749  appendStringInfo(&buf, "%s.",
750  quote_identifier(nspname));
751  }
752 
753  appendStringInfo(&buf, "%s(", oprname);
754 
755  if (operform->oprleft)
756  appendStringInfo(&buf, "%s,",
757  (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
758  format_type_be_qualified(operform->oprleft) :
759  format_type_be(operform->oprleft));
760  else
761  appendStringInfoString(&buf, "NONE,");
762 
763  if (operform->oprright)
764  appendStringInfo(&buf, "%s)",
765  (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
766  format_type_be_qualified(operform->oprright) :
767  format_type_be(operform->oprright));
768  else
769  appendStringInfoString(&buf, "NONE)");
770 
771  result = buf.data;
772 
773  ReleaseSysCache(opertup);
774  }
775  else if ((flags & FORMAT_OPERATOR_INVALID_AS_NULL) != 0)
776  {
777  /* If object is undefined, return NULL as wanted by caller */
778  result = NULL;
779  }
780  else
781  {
782  /*
783  * If OID doesn't match any pg_operator entry, return it numerically
784  */
785  result = (char *) palloc(NAMEDATALEN);
786  snprintf(result, NAMEDATALEN, "%u", operator_oid);
787  }
788 
789  return result;
790 }
#define NameStr(name)
Definition: c.h:746
#define Assert(condition)
Definition: c.h:858
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
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
void * palloc(Size size)
Definition: mcxt.c:1316
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:454
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:2034
#define NAMEDATALEN
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
static char * buf
Definition: pg_test_fsync.c:73
#define snprintf
Definition: port.h:238
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
#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:12623
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:182
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:266
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:218

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 806 of file regproc.c.

808 {
809  HeapTuple opertup;
810  Form_pg_operator oprForm;
811 
812  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
813  if (!HeapTupleIsValid(opertup))
814  {
815  if (!missing_ok)
816  elog(ERROR, "cache lookup failed for operator with OID %u",
817  operator_oid);
818  return;
819  }
820 
821  oprForm = (Form_pg_operator) GETSTRUCT(opertup);
822  *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
823  pstrdup(NameStr(oprForm->oprname)));
824  *objargs = NIL;
825  if (oprForm->oprleft)
826  *objargs = lappend(*objargs,
827  format_type_be_qualified(oprForm->oprleft));
828  if (oprForm->oprright)
829  *objargs = lappend(*objargs,
830  format_type_be_qualified(oprForm->oprright));
831 
832  ReleaseSysCache(opertup);
833 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
List * lappend(List *list, void *datum)
Definition: list.c:339
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3390
char * pstrdup(const char *in)
Definition: mcxt.c:1695
#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 799 of file regproc.c.

800 {
801  return format_operator_extended(operator_oid,
803 }

References format_operator_extended(), and FORMAT_OPERATOR_FORCE_QUALIFY.

◆ format_procedure()

char* format_procedure ( Oid  procedure_oid)

Definition at line 299 of file regproc.c.

300 {
301  return format_procedure_extended(procedure_oid, 0);
302 }
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:326

References format_procedure_extended().

Referenced by blvalidate(), brinvalidate(), btvalidate(), do_compile(), getObjectDescription(), ginvalidate(), gistvalidate(), hashvalidate(), initialize_peragg(), pg_logical_slot_get_changes_guts(), ProcedureCreate(), regprocedureout(), and spgvalidate().

◆ format_procedure_extended()

char* format_procedure_extended ( Oid  procedure_oid,
bits16  flags 
)

Definition at line 326 of file regproc.c.

327 {
328  char *result;
329  HeapTuple proctup;
330 
331  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
332 
333  if (HeapTupleIsValid(proctup))
334  {
335  Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
336  char *proname = NameStr(procform->proname);
337  int nargs = procform->pronargs;
338  int i;
339  char *nspname;
341 
342  /* XXX no support here for bootstrap mode */
344 
346 
347  /*
348  * Would this proc be found (given the right args) by regprocedurein?
349  * If not, or if caller requests it, we need to qualify it.
350  */
351  if ((flags & FORMAT_PROC_FORCE_QUALIFY) == 0 &&
352  FunctionIsVisible(procedure_oid))
353  nspname = NULL;
354  else
355  nspname = get_namespace_name(procform->pronamespace);
356 
357  appendStringInfo(&buf, "%s(",
359  for (i = 0; i < nargs; i++)
360  {
361  Oid thisargtype = procform->proargtypes.values[i];
362 
363  if (i > 0)
364  appendStringInfoChar(&buf, ',');
366  (flags & FORMAT_PROC_FORCE_QUALIFY) != 0 ?
367  format_type_be_qualified(thisargtype) :
368  format_type_be(thisargtype));
369  }
370  appendStringInfoChar(&buf, ')');
371 
372  result = buf.data;
373 
374  ReleaseSysCache(proctup);
375  }
376  else if ((flags & FORMAT_PROC_INVALID_AS_NULL) != 0)
377  {
378  /* If object is undefined, return NULL as wanted by caller */
379  result = NULL;
380  }
381  else
382  {
383  /* If OID doesn't match any pg_proc entry, return it numerically */
384  result = (char *) palloc(NAMEDATALEN);
385  snprintf(result, NAMEDATALEN, "%u", procedure_oid);
386  }
387 
388  return result;
389 }
int i
Definition: isn.c:73
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1681
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:31
#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:12707
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:194

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 398 of file regproc.c.

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

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 305 of file regproc.c.

306 {
308 }

References FORMAT_PROC_FORCE_QUALIFY, and format_procedure_extended().

◆ parseDashOrOid()

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

Definition at line 1868 of file regproc.c.

1869 {
1870  /* '-' ? */
1871  if (strcmp(string, "-") == 0)
1872  {
1873  *result = InvalidOid;
1874  return true;
1875  }
1876 
1877  /* Numeric OID? */
1878  return parseNumericOid(string, result, escontext);
1879 }
#define InvalidOid
Definition: postgres_ext.h:36
static bool parseNumericOid(char *string, Oid *result, Node *escontext)
Definition: regproc.c:1843

References InvalidOid, and parseNumericOid().

Referenced by regclassin(), regcollationin(), regconfigin(), 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 1895 of file regproc.c.

1898 {
1899  char *rawname;
1900  char *ptr;
1901  char *ptr2;
1902  char *typename;
1903  bool in_quote;
1904  bool had_comma;
1905  int paren_count;
1906  Oid typeid;
1907  int32 typmod;
1908 
1909  /* We need a modifiable copy of the input string. */
1910  rawname = pstrdup(string);
1911 
1912  /* Scan to find the expected left paren; mustn't be quoted */
1913  in_quote = false;
1914  for (ptr = rawname; *ptr; ptr++)
1915  {
1916  if (*ptr == '"')
1917  in_quote = !in_quote;
1918  else if (*ptr == '(' && !in_quote)
1919  break;
1920  }
1921  if (*ptr == '\0')
1922  ereturn(escontext, false,
1923  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1924  errmsg("expected a left parenthesis")));
1925 
1926  /* Separate the name and parse it into a list */
1927  *ptr++ = '\0';
1928  *names = stringToQualifiedNameList(rawname, escontext);
1929  if (*names == NIL)
1930  return false;
1931 
1932  /* Check for the trailing right parenthesis and remove it */
1933  ptr2 = ptr + strlen(ptr);
1934  while (--ptr2 > ptr)
1935  {
1936  if (!scanner_isspace(*ptr2))
1937  break;
1938  }
1939  if (*ptr2 != ')')
1940  ereturn(escontext, false,
1941  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1942  errmsg("expected a right parenthesis")));
1943 
1944  *ptr2 = '\0';
1945 
1946  /* Separate the remaining string into comma-separated type names */
1947  *nargs = 0;
1948  had_comma = false;
1949 
1950  for (;;)
1951  {
1952  /* allow leading whitespace */
1953  while (scanner_isspace(*ptr))
1954  ptr++;
1955  if (*ptr == '\0')
1956  {
1957  /* End of string. Okay unless we had a comma before. */
1958  if (had_comma)
1959  ereturn(escontext, false,
1960  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1961  errmsg("expected a type name")));
1962  break;
1963  }
1964  typename = ptr;
1965  /* Find end of type name --- end of string or comma */
1966  /* ... but not a quoted or parenthesized comma */
1967  in_quote = false;
1968  paren_count = 0;
1969  for (; *ptr; ptr++)
1970  {
1971  if (*ptr == '"')
1972  in_quote = !in_quote;
1973  else if (*ptr == ',' && !in_quote && paren_count == 0)
1974  break;
1975  else if (!in_quote)
1976  {
1977  switch (*ptr)
1978  {
1979  case '(':
1980  case '[':
1981  paren_count++;
1982  break;
1983  case ')':
1984  case ']':
1985  paren_count--;
1986  break;
1987  }
1988  }
1989  }
1990  if (in_quote || paren_count != 0)
1991  ereturn(escontext, false,
1992  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1993  errmsg("improper type name")));
1994 
1995  ptr2 = ptr;
1996  if (*ptr == ',')
1997  {
1998  had_comma = true;
1999  *ptr++ = '\0';
2000  }
2001  else
2002  {
2003  had_comma = false;
2004  Assert(*ptr == '\0');
2005  }
2006  /* Lop off trailing whitespace */
2007  while (--ptr2 >= typename)
2008  {
2009  if (!scanner_isspace(*ptr2))
2010  break;
2011  *ptr2 = '\0';
2012  }
2013 
2014  if (allowNone && pg_strcasecmp(typename, "none") == 0)
2015  {
2016  /* Special case for NONE */
2017  typeid = InvalidOid;
2018  typmod = -1;
2019  }
2020  else
2021  {
2022  /* Use full parser to resolve the type name */
2023  if (!parseTypeString(typename, &typeid, &typmod, escontext))
2024  return false;
2025  }
2026  if (*nargs >= FUNC_MAX_ARGS)
2027  ereturn(escontext, false,
2028  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
2029  errmsg("too many arguments")));
2030 
2031  argtypes[*nargs] = typeid;
2032  (*nargs)++;
2033  }
2034 
2035  pfree(rawname);
2036 
2037  return true;
2038 }
signed int int32
Definition: c.h:494
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ereturn(context, dummy_value,...)
Definition: elog.h:276
void pfree(void *pointer)
Definition: mcxt.c:1520
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:1797
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 1843 of file regproc.c.

1844 {
1845  if (string[0] >= '0' && string[0] <= '9' &&
1846  strspn(string, "0123456789") == strlen(string))
1847  {
1848  Datum oid_datum;
1849 
1850  /* We need not care here whether oidin() fails or not. */
1851  (void) DirectInputFunctionCallSafe(oidin, string,
1852  InvalidOid, -1,
1853  escontext,
1854  &oid_datum);
1855  *result = DatumGetObjectId(oid_datum);
1856  return true;
1857  }
1858 
1859  /* Prevent uninitialized-variable warnings from stupider compilers. */
1860  *result = InvalidOid;
1861  return false;
1862 }
bool DirectInputFunctionCallSafe(PGFunction func, char *str, Oid typioparam, int32 typmod, fmNodePtr escontext, Datum *result)
Definition: fmgr.c:1640
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:37
uintptr_t Datum
Definition: postgres.h:64
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242

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

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

◆ regclassin()

Datum regclassin ( PG_FUNCTION_ARGS  )

Definition at line 882 of file regproc.c.

883 {
884  char *class_name_or_oid = PG_GETARG_CSTRING(0);
885  Node *escontext = fcinfo->context;
886  Oid result;
887  List *names;
888 
889  /* Handle "-" or numeric OID */
890  if (parseDashOrOid(class_name_or_oid, &result, escontext))
891  PG_RETURN_OID(result);
892 
893  /* Else it's a name, possibly schema-qualified */
894 
895  /* The rest of this wouldn't work in bootstrap mode */
897  elog(ERROR, "regclass values must be OIDs in bootstrap mode");
898 
899  /*
900  * Normal case: parse the name into components and see if it matches any
901  * pg_class entries in the current search path.
902  */
903  names = stringToQualifiedNameList(class_name_or_oid, escontext);
904  if (names == NIL)
905  PG_RETURN_NULL();
906 
907  /* We might not even have permissions on this relation; don't lock it. */
908  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, true);
909 
910  if (!OidIsValid(result))
911  ereturn(escontext, (Datum) 0,
913  errmsg("relation \"%s\" does not exist",
914  NameListToString(names))));
915 
916  PG_RETURN_OID(result);
917 }
#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
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3539
char * NameListToString(const List *names)
Definition: namespace.c:3579
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:80
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:78
static bool parseDashOrOid(char *string, Oid *result, Node *escontext)
Definition: regproc.c:1868
Definition: pg_list.h:54
Definition: nodes.h:129

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 943 of file regproc.c.

944 {
945  Oid classid = PG_GETARG_OID(0);
946  char *result;
947  HeapTuple classtup;
948 
949  if (classid == InvalidOid)
950  {
951  result = pstrdup("-");
952  PG_RETURN_CSTRING(result);
953  }
954 
955  classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classid));
956 
957  if (HeapTupleIsValid(classtup))
958  {
959  Form_pg_class classform = (Form_pg_class) GETSTRUCT(classtup);
960  char *classname = NameStr(classform->relname);
961 
962  /*
963  * In bootstrap mode, skip the fancy namespace stuff and just return
964  * the class name. (This path is only needed for debugging output
965  * anyway.)
966  */
968  result = pstrdup(classname);
969  else
970  {
971  char *nspname;
972 
973  /*
974  * Would this class be found by regclassin? If not, qualify it.
975  */
976  if (RelationIsVisible(classid))
977  nspname = NULL;
978  else
979  nspname = get_namespace_name(classform->relnamespace);
980 
981  result = quote_qualified_identifier(nspname, classname);
982  }
983 
984  ReleaseSysCache(classtup);
985  }
986  else
987  {
988  /* If OID doesn't match any pg_class entry, return it numerically */
989  result = (char *) palloc(NAMEDATALEN);
990  snprintf(result, NAMEDATALEN, "%u", classid);
991  }
992 
993  PG_RETURN_CSTRING(result);
994 }
#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:898
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153

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 1000 of file regproc.c.

1001 {
1002  /* Exactly the same as oidrecv, so share code */
1003  return oidrecv(fcinfo);
1004 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:60

References oidrecv().

◆ regclasssend()

Datum regclasssend ( PG_FUNCTION_ARGS  )

Definition at line 1010 of file regproc.c.

1011 {
1012  /* Exactly the same as oidsend, so share code */
1013  return oidsend(fcinfo);
1014 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:71

References oidsend().

◆ regcollationin()

Datum regcollationin ( PG_FUNCTION_ARGS  )

Definition at line 1026 of file regproc.c.

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

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 1086 of file regproc.c.

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

1145 {
1146  /* Exactly the same as oidrecv, so share code */
1147  return oidrecv(fcinfo);
1148 }

References oidrecv().

◆ regcollationsend()

Datum regcollationsend ( PG_FUNCTION_ARGS  )

Definition at line 1154 of file regproc.c.

1155 {
1156  /* Exactly the same as oidsend, so share code */
1157  return oidsend(fcinfo);
1158 }

References oidsend().

◆ regconfigin()

Datum regconfigin ( PG_FUNCTION_ARGS  )

Definition at line 1321 of file regproc.c.

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

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 1359 of file regproc.c.

1360 {
1361  Oid cfgid = PG_GETARG_OID(0);
1362  char *result;
1363  HeapTuple cfgtup;
1364 
1365  if (cfgid == InvalidOid)
1366  {
1367  result = pstrdup("-");
1368  PG_RETURN_CSTRING(result);
1369  }
1370 
1371  cfgtup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgid));
1372 
1373  if (HeapTupleIsValid(cfgtup))
1374  {
1375  Form_pg_ts_config cfgform = (Form_pg_ts_config) GETSTRUCT(cfgtup);
1376  char *cfgname = NameStr(cfgform->cfgname);
1377  char *nspname;
1378 
1379  /*
1380  * Would this config be found by regconfigin? If not, qualify it.
1381  */
1382  if (TSConfigIsVisible(cfgid))
1383  nspname = NULL;
1384  else
1385  nspname = get_namespace_name(cfgform->cfgnamespace);
1386 
1387  result = quote_qualified_identifier(nspname, cfgname);
1388 
1389  ReleaseSysCache(cfgtup);
1390  }
1391  else
1392  {
1393  /* If OID doesn't match any pg_ts_config row, return it numerically */
1394  result = (char *) palloc(NAMEDATALEN);
1395  snprintf(result, NAMEDATALEN, "%u", cfgid);
1396  }
1397 
1398  PG_RETURN_CSTRING(result);
1399 }
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:3195
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 1405 of file regproc.c.

1406 {
1407  /* Exactly the same as oidrecv, so share code */
1408  return oidrecv(fcinfo);
1409 }

References oidrecv().

◆ regconfigsend()

Datum regconfigsend ( PG_FUNCTION_ARGS  )

Definition at line 1415 of file regproc.c.

1416 {
1417  /* Exactly the same as oidsend, so share code */
1418  return oidsend(fcinfo);
1419 }

References oidsend().

◆ regdictionaryin()

Datum regdictionaryin ( PG_FUNCTION_ARGS  )

Definition at line 1431 of file regproc.c.

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

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 1469 of file regproc.c.

1470 {
1471  Oid dictid = PG_GETARG_OID(0);
1472  char *result;
1473  HeapTuple dicttup;
1474 
1475  if (dictid == InvalidOid)
1476  {
1477  result = pstrdup("-");
1478  PG_RETURN_CSTRING(result);
1479  }
1480 
1481  dicttup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictid));
1482 
1483  if (HeapTupleIsValid(dicttup))
1484  {
1485  Form_pg_ts_dict dictform = (Form_pg_ts_dict) GETSTRUCT(dicttup);
1486  char *dictname = NameStr(dictform->dictname);
1487  char *nspname;
1488 
1489  /*
1490  * Would this dictionary be found by regdictionaryin? If not, qualify
1491  * it.
1492  */
1493  if (TSDictionaryIsVisible(dictid))
1494  nspname = NULL;
1495  else
1496  nspname = get_namespace_name(dictform->dictnamespace);
1497 
1498  result = quote_qualified_identifier(nspname, dictname);
1499 
1500  ReleaseSysCache(dicttup);
1501  }
1502  else
1503  {
1504  /* If OID doesn't match any pg_ts_dict row, return it numerically */
1505  result = (char *) palloc(NAMEDATALEN);
1506  snprintf(result, NAMEDATALEN, "%u", dictid);
1507  }
1508 
1509  PG_RETURN_CSTRING(result);
1510 }
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2904
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 1516 of file regproc.c.

1517 {
1518  /* Exactly the same as oidrecv, so share code */
1519  return oidrecv(fcinfo);
1520 }

References oidrecv().

◆ regdictionarysend()

Datum regdictionarysend ( PG_FUNCTION_ARGS  )

Definition at line 1526 of file regproc.c.

1527 {
1528  /* Exactly the same as oidsend, so share code */
1529  return oidsend(fcinfo);
1530 }

References oidsend().

◆ regnamespacein()

Datum regnamespacein ( PG_FUNCTION_ARGS  )

Definition at line 1658 of file regproc.c.

1659 {
1660  char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
1661  Node *escontext = fcinfo->context;
1662  Oid result;
1663  List *names;
1664 
1665  /* Handle "-" or numeric OID */
1666  if (parseDashOrOid(nsp_name_or_oid, &result, escontext))
1667  PG_RETURN_OID(result);
1668 
1669  /* The rest of this wouldn't work in bootstrap mode */
1671  elog(ERROR, "regnamespace values must be OIDs in bootstrap mode");
1672 
1673  /* Normal case: see if the name matches any pg_namespace entry. */
1674  names = stringToQualifiedNameList(nsp_name_or_oid, escontext);
1675  if (names == NIL)
1676  PG_RETURN_NULL();
1677 
1678  if (list_length(names) != 1)
1679  ereturn(escontext, (Datum) 0,
1680  (errcode(ERRCODE_INVALID_NAME),
1681  errmsg("invalid name syntax")));
1682 
1683  result = get_namespace_oid(strVal(linitial(names)), true);
1684 
1685  if (!OidIsValid(result))
1686  ereturn(escontext, (Datum) 0,
1687  (errcode(ERRCODE_UNDEFINED_SCHEMA),
1688  errmsg("schema \"%s\" does not exist",
1689  strVal(linitial(names)))));
1690 
1691  PG_RETURN_OID(result);
1692 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3520
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_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 1718 of file regproc.c.

1719 {
1720  Oid nspid = PG_GETARG_OID(0);
1721  char *result;
1722 
1723  if (nspid == InvalidOid)
1724  {
1725  result = pstrdup("-");
1726  PG_RETURN_CSTRING(result);
1727  }
1728 
1729  result = get_namespace_name(nspid);
1730 
1731  if (result)
1732  {
1733  /* pstrdup is not really necessary, but it avoids a compiler warning */
1734  result = pstrdup(quote_identifier(result));
1735  }
1736  else
1737  {
1738  /* If OID doesn't match any namespace, return it numerically */
1739  result = (char *) palloc(NAMEDATALEN);
1740  snprintf(result, NAMEDATALEN, "%u", nspid);
1741  }
1742 
1743  PG_RETURN_CSTRING(result);
1744 }
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 1750 of file regproc.c.

1751 {
1752  /* Exactly the same as oidrecv, so share code */
1753  return oidrecv(fcinfo);
1754 }

References oidrecv().

◆ regnamespacesend()

Datum regnamespacesend ( PG_FUNCTION_ARGS  )

Definition at line 1760 of file regproc.c.

1761 {
1762  /* Exactly the same as oidsend, so share code */
1763  return oidsend(fcinfo);
1764 }

References oidsend().

◆ regoperatorin()

Datum regoperatorin ( PG_FUNCTION_ARGS  )

Definition at line 639 of file regproc.c.

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

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 839 of file regproc.c.

840 {
841  Oid oprid = PG_GETARG_OID(0);
842  char *result;
843 
844  if (oprid == InvalidOid)
845  result = pstrdup("0");
846  else
847  result = format_operator(oprid);
848 
849  PG_RETURN_CSTRING(result);
850 }
Oid oprid(Operator op)
Definition: parse_oper.c:238
char * format_operator(Oid operator_oid)
Definition: regproc.c:793

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

◆ regoperatorrecv()

Datum regoperatorrecv ( PG_FUNCTION_ARGS  )

Definition at line 856 of file regproc.c.

857 {
858  /* Exactly the same as oidrecv, so share code */
859  return oidrecv(fcinfo);
860 }

References oidrecv().

◆ regoperatorsend()

Datum regoperatorsend ( PG_FUNCTION_ARGS  )

Definition at line 866 of file regproc.c.

867 {
868  /* Exactly the same as oidsend, so share code */
869  return oidsend(fcinfo);
870 }

References oidsend().

◆ regoperin()

Datum regoperin ( PG_FUNCTION_ARGS  )

Definition at line 478 of file regproc.c.

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

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

614 {
615  /* Exactly the same as oidrecv, so share code */
616  return oidrecv(fcinfo);
617 }

References oidrecv().

◆ regopersend()

Datum regopersend ( PG_FUNCTION_ARGS  )

Definition at line 623 of file regproc.c.

624 {
625  /* Exactly the same as oidsend, so share code */
626  return oidsend(fcinfo);
627 }

References oidsend().

◆ regprocedurein()

Datum regprocedurein ( PG_FUNCTION_ARGS  )

Definition at line 224 of file regproc.c.

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

436 {
437  RegProcedure proid = PG_GETARG_OID(0);
438  char *result;
439 
440  if (proid == InvalidOid)
441  result = pstrdup("-");
442  else
443  result = format_procedure(proid);
444 
445  PG_RETURN_CSTRING(result);
446 }
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:299

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

◆ regprocedurerecv()

Datum regprocedurerecv ( PG_FUNCTION_ARGS  )

Definition at line 452 of file regproc.c.

453 {
454  /* Exactly the same as oidrecv, so share code */
455  return oidrecv(fcinfo);
456 }

References oidrecv().

◆ regproceduresend()

Datum regproceduresend ( PG_FUNCTION_ARGS  )

Definition at line 462 of file regproc.c.

463 {
464  /* Exactly the same as oidsend, so share code */
465  return oidsend(fcinfo);
466 }

References oidsend().

◆ regprocin()

Datum regprocin ( PG_FUNCTION_ARGS  )

Definition at line 66 of file regproc.c.

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

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 136 of file regproc.c.

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

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 198 of file regproc.c.

199 {
200  /* Exactly the same as oidrecv, so share code */
201  return oidrecv(fcinfo);
202 }

References oidrecv().

◆ regprocsend()

Datum regprocsend ( PG_FUNCTION_ARGS  )

Definition at line 208 of file regproc.c.

209 {
210  /* Exactly the same as oidsend, so share code */
211  return oidsend(fcinfo);
212 }

References oidsend().

◆ regrolein()

Datum regrolein ( PG_FUNCTION_ARGS  )

Definition at line 1541 of file regproc.c.

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

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 1601 of file regproc.c.

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

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 1633 of file regproc.c.

1634 {
1635  /* Exactly the same as oidrecv, so share code */
1636  return oidrecv(fcinfo);
1637 }

References oidrecv().

◆ regrolesend()

Datum regrolesend ( PG_FUNCTION_ARGS  )

Definition at line 1643 of file regproc.c.

1644 {
1645  /* Exactly the same as oidsend, so share code */
1646  return oidsend(fcinfo);
1647 }

References oidsend().

◆ regtypein()

Datum regtypein ( PG_FUNCTION_ARGS  )

Definition at line 1176 of file regproc.c.

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

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 1247 of file regproc.c.

1248 {
1249  Oid typid = PG_GETARG_OID(0);
1250  char *result;
1251  HeapTuple typetup;
1252 
1253  if (typid == InvalidOid)
1254  {
1255  result = pstrdup("-");
1256  PG_RETURN_CSTRING(result);
1257  }
1258 
1259  typetup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid));
1260 
1261  if (HeapTupleIsValid(typetup))
1262  {
1263  Form_pg_type typeform = (Form_pg_type) GETSTRUCT(typetup);
1264 
1265  /*
1266  * In bootstrap mode, skip the fancy namespace stuff and just return
1267  * the type name. (This path is only needed for debugging output
1268  * anyway.)
1269  */
1271  {
1272  char *typname = NameStr(typeform->typname);
1273 
1274  result = pstrdup(typname);
1275  }
1276  else
1277  result = format_type_be(typid);
1278 
1279  ReleaseSysCache(typetup);
1280  }
1281  else
1282  {
1283  /* If OID doesn't match any pg_type entry, return it numerically */
1284  result = (char *) palloc(NAMEDATALEN);
1285  snprintf(result, NAMEDATALEN, "%u", typid);
1286  }
1287 
1288  PG_RETURN_CSTRING(result);
1289 }
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 1295 of file regproc.c.

1296 {
1297  /* Exactly the same as oidrecv, so share code */
1298  return oidrecv(fcinfo);
1299 }

References oidrecv().

◆ regtypesend()

Datum regtypesend ( PG_FUNCTION_ARGS  )

Definition at line 1305 of file regproc.c.

1306 {
1307  /* Exactly the same as oidsend, so share code */
1308  return oidsend(fcinfo);
1309 }

References oidsend().

◆ stringToQualifiedNameList()

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

Definition at line 1797 of file regproc.c.

1798 {
1799  char *rawname;
1800  List *result = NIL;
1801  List *namelist;
1802  ListCell *l;
1803 
1804  /* We need a modifiable copy of the input string. */
1805  rawname = pstrdup(string);
1806 
1807  if (!SplitIdentifierString(rawname, '.', &namelist))
1808  ereturn(escontext, NIL,
1809  (errcode(ERRCODE_INVALID_NAME),
1810  errmsg("invalid name syntax")));
1811 
1812  if (namelist == NIL)
1813  ereturn(escontext, NIL,
1814  (errcode(ERRCODE_INVALID_NAME),
1815  errmsg("invalid name syntax")));
1816 
1817  foreach(l, namelist)
1818  {
1819  char *curname = (char *) lfirst(l);
1820 
1821  result = lappend(result, makeString(pstrdup(curname)));
1822  }
1823 
1824  pfree(rawname);
1825  list_free(namelist);
1826 
1827  return result;
1828 }
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:3457

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(), regdictionaryin(), regnamespacein(), regoperin(), regprocin(), regrolein(), RelationNameGetTupleDesc(), thesaurus_init(), and tsvector_update_trigger().

◆ text_regclass()

Datum text_regclass ( PG_FUNCTION_ARGS  )

Definition at line 1774 of file regproc.c.

1775 {
1777  Oid result;
1778  RangeVar *rv;
1779 
1781 
1782  /* We might not even have permissions on this relation; don't lock it. */
1783  result = RangeVarGetRelid(rv, NoLock, false);
1784 
1785  PG_RETURN_OID(result);
1786 }
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
NameData relname
Definition: pg_class.h:38
Definition: c.h:687
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3399

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 925 of file regproc.c.

926 {
928  Datum result;
929  ErrorSaveContext escontext = {T_ErrorSaveContext};
930 
932  InvalidOid, -1,
933  (Node *) &escontext,
934  &result))
935  PG_RETURN_NULL();
936  PG_RETURN_DATUM(result);
937 }
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Datum regclassin(PG_FUNCTION_ARGS)
Definition: regproc.c:882
const char * class_name
Definition: selinux.c:32
char * text_to_cstring(const text *t)
Definition: varlena.c:217

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 1068 of file regproc.c.

1069 {
1070  char *collation_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1071  Datum result;
1072  ErrorSaveContext escontext = {T_ErrorSaveContext};
1073 
1074  if (!DirectInputFunctionCallSafe(regcollationin, collation_name,
1075  InvalidOid, -1,
1076  (Node *) &escontext,
1077  &result))
1078  PG_RETURN_NULL();
1079  PG_RETURN_DATUM(result);
1080 }
Datum regcollationin(PG_FUNCTION_ARGS)
Definition: regproc.c:1026

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

◆ to_regnamespace()

Datum to_regnamespace ( PG_FUNCTION_ARGS  )

Definition at line 1700 of file regproc.c.

1701 {
1702  char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1703  Datum result;
1704  ErrorSaveContext escontext = {T_ErrorSaveContext};
1705 
1707  InvalidOid, -1,
1708  (Node *) &escontext,
1709  &result))
1710  PG_RETURN_NULL();
1711  PG_RETURN_DATUM(result);
1712 }
Datum regnamespacein(PG_FUNCTION_ARGS)
Definition: regproc.c:1658

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 527 of file regproc.c.

528 {
529  char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
530  Datum result;
531  ErrorSaveContext escontext = {T_ErrorSaveContext};
532 
533  if (!DirectInputFunctionCallSafe(regoperin, opr_name,
534  InvalidOid, -1,
535  (Node *) &escontext,
536  &result))
537  PG_RETURN_NULL();
538  PG_RETURN_DATUM(result);
539 }
Datum regoperin(PG_FUNCTION_ARGS)
Definition: regproc.c:478

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 694 of file regproc.c.

695 {
696  char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
697  Datum result;
698  ErrorSaveContext escontext = {T_ErrorSaveContext};
699 
700  if (!DirectInputFunctionCallSafe(regoperatorin, opr_name_or_oid,
701  InvalidOid, -1,
702  (Node *) &escontext,
703  &result))
704  PG_RETURN_NULL();
705  PG_RETURN_DATUM(result);
706 }
Datum regoperatorin(PG_FUNCTION_ARGS)
Definition: regproc.c:639

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 118 of file regproc.c.

119 {
120  char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
121  Datum result;
122  ErrorSaveContext escontext = {T_ErrorSaveContext};
123 
124  if (!DirectInputFunctionCallSafe(regprocin, pro_name,
125  InvalidOid, -1,
126  (Node *) &escontext,
127  &result))
128  PG_RETURN_NULL();
129  PG_RETURN_DATUM(result);
130 }
Datum regprocin(PG_FUNCTION_ARGS)
Definition: regproc.c:66

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 278 of file regproc.c.

279 {
280  char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
281  Datum result;
282  ErrorSaveContext escontext = {T_ErrorSaveContext};
283 
285  InvalidOid, -1,
286  (Node *) &escontext,
287  &result))
288  PG_RETURN_NULL();
289  PG_RETURN_DATUM(result);
290 }
Datum regprocedurein(PG_FUNCTION_ARGS)
Definition: regproc.c:224

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 1583 of file regproc.c.

1584 {
1585  char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1586  Datum result;
1587  ErrorSaveContext escontext = {T_ErrorSaveContext};
1588 
1589  if (!DirectInputFunctionCallSafe(regrolein, role_name,
1590  InvalidOid, -1,
1591  (Node *) &escontext,
1592  &result))
1593  PG_RETURN_NULL();
1594  PG_RETURN_DATUM(result);
1595 }
Datum regrolein(PG_FUNCTION_ARGS)
Definition: regproc.c:1541

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 1209 of file regproc.c.

1210 {
1211  char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1212  Datum result;
1213  ErrorSaveContext escontext = {T_ErrorSaveContext};
1214 
1215  if (!DirectInputFunctionCallSafe(regtypein, typ_name,
1216  InvalidOid, -1,
1217  (Node *) &escontext,
1218  &result))
1219  PG_RETURN_NULL();
1220  PG_RETURN_DATUM(result);
1221 }
Datum regtypein(PG_FUNCTION_ARGS)
Definition: regproc.c:1176

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 1229 of file regproc.c.

1230 {
1231  char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1232  Oid typid;
1233  int32 typmod;
1234  ErrorSaveContext escontext = {T_ErrorSaveContext};
1235 
1236  /* We rely on parseTypeString to parse the input. */
1237  if (!parseTypeString(typ_name, &typid, &typmod, (Node *) &escontext))
1238  PG_RETURN_NULL();
1239 
1240  PG_RETURN_INT32(typmod);
1241 }
#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().