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 "miscadmin.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 void parseNameAndArgTypes (const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
 
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 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)
 

Function Documentation

◆ format_operator()

char* format_operator ( Oid  operator_oid)

Definition at line 851 of file regproc.c.

References format_operator_extended().

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

852 {
853  return format_operator_extended(operator_oid, 0);
854 }
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:780

◆ format_operator_extended()

char* format_operator_extended ( Oid  operator_oid,
bits16  flags 
)

Definition at line 780 of file regproc.c.

References appendStringInfo(), appendStringInfoString(), Assert, buf, StringInfoData::data, 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(), OPEROID, palloc(), quote_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

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

781 {
782  char *result;
783  HeapTuple opertup;
784 
785  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
786 
787  if (HeapTupleIsValid(opertup))
788  {
789  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
790  char *oprname = NameStr(operform->oprname);
791  char *nspname;
793 
794  /* XXX no support here for bootstrap mode */
796 
797  initStringInfo(&buf);
798 
799  /*
800  * Would this oper be found (given the right args) by regoperatorin?
801  * If not, or if caller explicitly requests it, we need to qualify it.
802  */
803  if ((flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ||
804  !OperatorIsVisible(operator_oid))
805  {
806  nspname = get_namespace_name(operform->oprnamespace);
807  appendStringInfo(&buf, "%s.",
808  quote_identifier(nspname));
809  }
810 
811  appendStringInfo(&buf, "%s(", oprname);
812 
813  if (operform->oprleft)
814  appendStringInfo(&buf, "%s,",
815  (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
816  format_type_be_qualified(operform->oprleft) :
817  format_type_be(operform->oprleft));
818  else
819  appendStringInfoString(&buf, "NONE,");
820 
821  if (operform->oprright)
822  appendStringInfo(&buf, "%s)",
823  (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
824  format_type_be_qualified(operform->oprright) :
825  format_type_be(operform->oprright));
826  else
827  appendStringInfoString(&buf, "NONE)");
828 
829  result = buf.data;
830 
831  ReleaseSysCache(opertup);
832  }
833  else if ((flags & FORMAT_OPERATOR_INVALID_AS_NULL) != 0)
834  {
835  /* If object is undefined, return NULL as wanted by caller */
836  result = NULL;
837  }
838  else
839  {
840  /*
841  * If OID doesn't match any pg_operator entry, return it numerically
842  */
843  result = (char *) palloc(NAMEDATALEN);
844  snprintf(result, NAMEDATALEN, "%u", operator_oid);
845  }
846 
847  return result;
848 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10706
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:1746
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define NAMEDATALEN
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
static char * buf
Definition: pg_test_fsync.c:67
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:745
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
void * palloc(Size size)
Definition: mcxt.c:950
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25

◆ format_operator_parts()

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

Definition at line 864 of file regproc.c.

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

Referenced by getObjectIdentityParts().

866 {
867  HeapTuple opertup;
868  Form_pg_operator oprForm;
869 
870  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
871  if (!HeapTupleIsValid(opertup))
872  {
873  if (!missing_ok)
874  elog(ERROR, "cache lookup failed for operator with OID %u",
875  operator_oid);
876  return;
877  }
878 
879  oprForm = (Form_pg_operator) GETSTRUCT(opertup);
880  *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
881  pstrdup(NameStr(oprForm->oprname)));
882  *objargs = NIL;
883  if (oprForm->oprleft)
884  *objargs = lappend(*objargs,
885  format_type_be_qualified(oprForm->oprleft));
886  if (oprForm->oprright)
887  *objargs = lappend(*objargs,
888  format_type_be_qualified(oprForm->oprright));
889 
890  ReleaseSysCache(opertup);
891 }
#define list_make2(x1, x2)
Definition: pg_list.h:229
#define NIL
Definition: pg_list.h:65
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1187
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
List * lappend(List *list, void *datum)
Definition: list.c:321
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3215
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:622

◆ format_operator_qualified()

char* format_operator_qualified ( Oid  operator_oid)

Definition at line 857 of file regproc.c.

References format_operator_extended(), and FORMAT_OPERATOR_FORCE_QUALIFY.

858 {
859  return format_operator_extended(operator_oid,
861 }
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:780
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25

◆ format_procedure()

char* format_procedure ( Oid  procedure_oid)

Definition at line 322 of file regproc.c.

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().

323 {
324  return format_procedure_extended(procedure_oid, 0);
325 }
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:349

◆ format_procedure_extended()

char* format_procedure_extended ( Oid  procedure_oid,
bits16  flags 
)

Definition at line 349 of file regproc.c.

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, buf, StringInfoData::data, 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(), PROCOID, proname, quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

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

350 {
351  char *result;
352  HeapTuple proctup;
353 
354  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
355 
356  if (HeapTupleIsValid(proctup))
357  {
358  Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
359  char *proname = NameStr(procform->proname);
360  int nargs = procform->pronargs;
361  int i;
362  char *nspname;
364 
365  /* XXX no support here for bootstrap mode */
367 
368  initStringInfo(&buf);
369 
370  /*
371  * Would this proc be found (given the right args) by regprocedurein?
372  * If not, or if caller requests it, we need to qualify it.
373  */
374  if ((flags & FORMAT_PROC_FORCE_QUALIFY) == 0 &&
375  FunctionIsVisible(procedure_oid))
376  nspname = NULL;
377  else
378  nspname = get_namespace_name(procform->pronamespace);
379 
380  appendStringInfo(&buf, "%s(",
381  quote_qualified_identifier(nspname, proname));
382  for (i = 0; i < nargs; i++)
383  {
384  Oid thisargtype = procform->proargtypes.values[i];
385 
386  if (i > 0)
387  appendStringInfoChar(&buf, ',');
389  (flags & FORMAT_PROC_FORCE_QUALIFY) != 0 ?
390  format_type_be_qualified(thisargtype) :
391  format_type_be(thisargtype));
392  }
393  appendStringInfoChar(&buf, ')');
394 
395  result = buf.data;
396 
397  ReleaseSysCache(proctup);
398  }
399  else if ((flags & FORMAT_PROC_INVALID_AS_NULL) != 0)
400  {
401  /* If object is undefined, return NULL as wanted by caller */
402  result = NULL;
403  }
404  else
405  {
406  /* If OID doesn't match any pg_proc entry, return it numerically */
407  result = (char *) palloc(NAMEDATALEN);
408  snprintf(result, NAMEDATALEN, "%u", procedure_oid);
409  }
410 
411  return result;
412 }
NameData proname
Definition: pg_proc.h:35
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1413
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
static char * buf
Definition: pg_test_fsync.c:67
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10790
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:745
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20
void * palloc(Size size)
Definition: mcxt.c:950
int i
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193

◆ format_procedure_parts()

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

Definition at line 421 of file regproc.c.

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

Referenced by getObjectIdentityParts().

423 {
424  HeapTuple proctup;
425  Form_pg_proc procform;
426  int nargs;
427  int i;
428 
429  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
430 
431  if (!HeapTupleIsValid(proctup))
432  {
433  if (!missing_ok)
434  elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
435  return;
436  }
437 
438  procform = (Form_pg_proc) GETSTRUCT(proctup);
439  nargs = procform->pronargs;
440 
441  *objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
442  pstrdup(NameStr(procform->proname)));
443  *objargs = NIL;
444  for (i = 0; i < nargs; i++)
445  {
446  Oid thisargtype = procform->proargtypes.values[i];
447 
448  *objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
449  }
450 
451  ReleaseSysCache(proctup);
452 }
#define list_make2(x1, x2)
Definition: pg_list.h:229
#define NIL
Definition: pg_list.h:65
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1187
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
List * lappend(List *list, void *datum)
Definition: list.c:321
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3215
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:622

◆ format_procedure_qualified()

char* format_procedure_qualified ( Oid  procedure_oid)

Definition at line 328 of file regproc.c.

References FORMAT_PROC_FORCE_QUALIFY, and format_procedure_extended().

329 {
331 }
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:349
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20

◆ parseNameAndArgTypes()

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

Definition at line 1924 of file regproc.c.

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

Referenced by regoperatorin(), regprocedurein(), to_regoperator(), and to_regprocedure().

1926 {
1927  char *rawname;
1928  char *ptr;
1929  char *ptr2;
1930  char *typename;
1931  bool in_quote;
1932  bool had_comma;
1933  int paren_count;
1934  Oid typeid;
1935  int32 typmod;
1936 
1937  /* We need a modifiable copy of the input string. */
1938  rawname = pstrdup(string);
1939 
1940  /* Scan to find the expected left paren; mustn't be quoted */
1941  in_quote = false;
1942  for (ptr = rawname; *ptr; ptr++)
1943  {
1944  if (*ptr == '"')
1945  in_quote = !in_quote;
1946  else if (*ptr == '(' && !in_quote)
1947  break;
1948  }
1949  if (*ptr == '\0')
1950  ereport(ERROR,
1951  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1952  errmsg("expected a left parenthesis")));
1953 
1954  /* Separate the name and parse it into a list */
1955  *ptr++ = '\0';
1956  *names = stringToQualifiedNameList(rawname);
1957 
1958  /* Check for the trailing right parenthesis and remove it */
1959  ptr2 = ptr + strlen(ptr);
1960  while (--ptr2 > ptr)
1961  {
1962  if (!scanner_isspace(*ptr2))
1963  break;
1964  }
1965  if (*ptr2 != ')')
1966  ereport(ERROR,
1967  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1968  errmsg("expected a right parenthesis")));
1969 
1970  *ptr2 = '\0';
1971 
1972  /* Separate the remaining string into comma-separated type names */
1973  *nargs = 0;
1974  had_comma = false;
1975 
1976  for (;;)
1977  {
1978  /* allow leading whitespace */
1979  while (scanner_isspace(*ptr))
1980  ptr++;
1981  if (*ptr == '\0')
1982  {
1983  /* End of string. Okay unless we had a comma before. */
1984  if (had_comma)
1985  ereport(ERROR,
1986  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1987  errmsg("expected a type name")));
1988  break;
1989  }
1990  typename = ptr;
1991  /* Find end of type name --- end of string or comma */
1992  /* ... but not a quoted or parenthesized comma */
1993  in_quote = false;
1994  paren_count = 0;
1995  for (; *ptr; ptr++)
1996  {
1997  if (*ptr == '"')
1998  in_quote = !in_quote;
1999  else if (*ptr == ',' && !in_quote && paren_count == 0)
2000  break;
2001  else if (!in_quote)
2002  {
2003  switch (*ptr)
2004  {
2005  case '(':
2006  case '[':
2007  paren_count++;
2008  break;
2009  case ')':
2010  case ']':
2011  paren_count--;
2012  break;
2013  }
2014  }
2015  }
2016  if (in_quote || paren_count != 0)
2017  ereport(ERROR,
2018  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2019  errmsg("improper type name")));
2020 
2021  ptr2 = ptr;
2022  if (*ptr == ',')
2023  {
2024  had_comma = true;
2025  *ptr++ = '\0';
2026  }
2027  else
2028  {
2029  had_comma = false;
2030  Assert(*ptr == '\0');
2031  }
2032  /* Lop off trailing whitespace */
2033  while (--ptr2 >= typename)
2034  {
2035  if (!scanner_isspace(*ptr2))
2036  break;
2037  *ptr2 = '\0';
2038  }
2039 
2040  if (allowNone && pg_strcasecmp(typename, "none") == 0)
2041  {
2042  /* Special case for NONE */
2043  typeid = InvalidOid;
2044  typmod = -1;
2045  }
2046  else
2047  {
2048  /* Use full parser to resolve the type name */
2049  parseTypeString(typename, &typeid, &typmod, false);
2050  }
2051  if (*nargs >= FUNC_MAX_ARGS)
2052  ereport(ERROR,
2053  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
2054  errmsg("too many arguments")));
2055 
2056  argtypes[*nargs] = typeid;
2057  (*nargs)++;
2058  }
2059 
2060  pfree(rawname);
2061 }
char * pstrdup(const char *in)
Definition: mcxt.c:1187
int errcode(int sqlerrcode)
Definition: elog.c:610
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:362
#define FUNC_MAX_ARGS
void pfree(void *pointer)
Definition: mcxt.c:1057
#define ERROR
Definition: elog.h:43
bool scanner_isspace(char ch)
Definition: scansup.c:210
void parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:832
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:745
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ regclassin()

Datum regclassin ( PG_FUNCTION_ARGS  )

Definition at line 940 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ERROR, InvalidOid, IsBootstrapProcessingMode, makeRangeVarFromNameList(), NoLock, oidin(), PG_GETARG_CSTRING, PG_RETURN_OID, RangeVarGetRelid, and stringToQualifiedNameList().

941 {
942  char *class_name_or_oid = PG_GETARG_CSTRING(0);
943  Oid result = InvalidOid;
944  List *names;
945 
946  /* '-' ? */
947  if (strcmp(class_name_or_oid, "-") == 0)
949 
950  /* Numeric OID? */
951  if (class_name_or_oid[0] >= '0' &&
952  class_name_or_oid[0] <= '9' &&
953  strspn(class_name_or_oid, "0123456789") == strlen(class_name_or_oid))
954  {
956  CStringGetDatum(class_name_or_oid)));
957  PG_RETURN_OID(result);
958  }
959 
960  /* Else it's a name, possibly schema-qualified */
961 
962  /* The rest of this wouldn't work in bootstrap mode */
964  elog(ERROR, "regclass values must be OIDs in bootstrap mode");
965 
966  /*
967  * Normal case: parse the name into components and see if it matches any
968  * pg_class entries in the current search path.
969  */
970  names = stringToQualifiedNameList(class_name_or_oid);
971 
972  /* We might not even have permissions on this relation; don't lock it. */
973  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, false);
974 
975  PG_RETURN_OID(result);
976 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:78
#define DatumGetObjectId(X)
Definition: postgres.h:500
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regclassout()

Datum regclassout ( PG_FUNCTION_ARGS  )

Definition at line 1009 of file regproc.c.

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

Referenced by table_to_xml_internal().

1010 {
1011  Oid classid = PG_GETARG_OID(0);
1012  char *result;
1013  HeapTuple classtup;
1014 
1015  if (classid == InvalidOid)
1016  {
1017  result = pstrdup("-");
1018  PG_RETURN_CSTRING(result);
1019  }
1020 
1021  classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classid));
1022 
1023  if (HeapTupleIsValid(classtup))
1024  {
1025  Form_pg_class classform = (Form_pg_class) GETSTRUCT(classtup);
1026  char *classname = NameStr(classform->relname);
1027 
1028  /*
1029  * In bootstrap mode, skip the fancy namespace stuff and just return
1030  * the class name. (This path is only needed for debugging output
1031  * anyway.)
1032  */
1034  result = pstrdup(classname);
1035  else
1036  {
1037  char *nspname;
1038 
1039  /*
1040  * Would this class be found by regclassin? If not, qualify it.
1041  */
1042  if (RelationIsVisible(classid))
1043  nspname = NULL;
1044  else
1045  nspname = get_namespace_name(classform->relnamespace);
1046 
1047  result = quote_qualified_identifier(nspname, classname);
1048  }
1049 
1050  ReleaseSysCache(classtup);
1051  }
1052  else
1053  {
1054  /* If OID doesn't match any pg_class entry, return it numerically */
1055  result = (char *) palloc(NAMEDATALEN);
1056  snprintf(result, NAMEDATALEN, "%u", classid);
1057  }
1058 
1059  PG_RETURN_CSTRING(result);
1060 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1187
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10790
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
void * palloc(Size size)
Definition: mcxt.c:950
bool RelationIsVisible(Oid relid)
Definition: namespace.c:708
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193

◆ regclassrecv()

Datum regclassrecv ( PG_FUNCTION_ARGS  )

Definition at line 1066 of file regproc.c.

References oidrecv().

1067 {
1068  /* Exactly the same as oidrecv, so share code */
1069  return oidrecv(fcinfo);
1070 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regclasssend()

Datum regclasssend ( PG_FUNCTION_ARGS  )

Definition at line 1076 of file regproc.c.

References oidsend().

1077 {
1078  /* Exactly the same as oidsend, so share code */
1079  return oidsend(fcinfo);
1080 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regcollationin()

Datum regcollationin ( PG_FUNCTION_ARGS  )

Definition at line 1092 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ERROR, get_collation_oid(), InvalidOid, IsBootstrapProcessingMode, oidin(), PG_GETARG_CSTRING, PG_RETURN_OID, and stringToQualifiedNameList().

1093 {
1094  char *collation_name_or_oid = PG_GETARG_CSTRING(0);
1095  Oid result = InvalidOid;
1096  List *names;
1097 
1098  /* '-' ? */
1099  if (strcmp(collation_name_or_oid, "-") == 0)
1101 
1102  /* Numeric OID? */
1103  if (collation_name_or_oid[0] >= '0' &&
1104  collation_name_or_oid[0] <= '9' &&
1105  strspn(collation_name_or_oid, "0123456789") == strlen(collation_name_or_oid))
1106  {
1108  CStringGetDatum(collation_name_or_oid)));
1109  PG_RETURN_OID(result);
1110  }
1111 
1112  /* Else it's a name, possibly schema-qualified */
1113 
1114  /* The rest of this wouldn't work in bootstrap mode */
1116  elog(ERROR, "regcollation values must be OIDs in bootstrap mode");
1117 
1118  /*
1119  * Normal case: parse the name into components and see if it matches any
1120  * pg_collation entries in the current search path.
1121  */
1122  names = stringToQualifiedNameList(collation_name_or_oid);
1123 
1124  result = get_collation_oid(names, false);
1125 
1126  PG_RETURN_OID(result);
1127 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3600
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regcollationout()

Datum regcollationout ( PG_FUNCTION_ARGS  )

Definition at line 1160 of file regproc.c.

References CollationIsVisible(), COLLOID, 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.

1161 {
1162  Oid collationid = PG_GETARG_OID(0);
1163  char *result;
1164  HeapTuple collationtup;
1165 
1166  if (collationid == InvalidOid)
1167  {
1168  result = pstrdup("-");
1169  PG_RETURN_CSTRING(result);
1170  }
1171 
1172  collationtup = SearchSysCache1(COLLOID, ObjectIdGetDatum(collationid));
1173 
1174  if (HeapTupleIsValid(collationtup))
1175  {
1176  Form_pg_collation collationform = (Form_pg_collation) GETSTRUCT(collationtup);
1177  char *collationname = NameStr(collationform->collname);
1178 
1179  /*
1180  * In bootstrap mode, skip the fancy namespace stuff and just return
1181  * the collation name. (This path is only needed for debugging output
1182  * anyway.)
1183  */
1185  result = pstrdup(collationname);
1186  else
1187  {
1188  char *nspname;
1189 
1190  /*
1191  * Would this collation be found by regcollationin? If not,
1192  * qualify it.
1193  */
1194  if (CollationIsVisible(collationid))
1195  nspname = NULL;
1196  else
1197  nspname = get_namespace_name(collationform->collnamespace);
1198 
1199  result = quote_qualified_identifier(nspname, collationname);
1200  }
1201 
1202  ReleaseSysCache(collationtup);
1203  }
1204  else
1205  {
1206  /* If OID doesn't match any pg_collation entry, return it numerically */
1207  result = (char *) palloc(NAMEDATALEN);
1208  snprintf(result, NAMEDATALEN, "%u", collationid);
1209  }
1210 
1211  PG_RETURN_CSTRING(result);
1212 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1187
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2047
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10790
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
void * palloc(Size size)
Definition: mcxt.c:950
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193

◆ regcollationrecv()

Datum regcollationrecv ( PG_FUNCTION_ARGS  )

Definition at line 1218 of file regproc.c.

References oidrecv().

1219 {
1220  /* Exactly the same as oidrecv, so share code */
1221  return oidrecv(fcinfo);
1222 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regcollationsend()

Datum regcollationsend ( PG_FUNCTION_ARGS  )

Definition at line 1228 of file regproc.c.

References oidsend().

1229 {
1230  /* Exactly the same as oidsend, so share code */
1231  return oidsend(fcinfo);
1232 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regconfigin()

Datum regconfigin ( PG_FUNCTION_ARGS  )

Definition at line 1386 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ERROR, get_ts_config_oid(), InvalidOid, IsBootstrapProcessingMode, oidin(), PG_GETARG_CSTRING, PG_RETURN_OID, and stringToQualifiedNameList().

1387 {
1388  char *cfg_name_or_oid = PG_GETARG_CSTRING(0);
1389  Oid result;
1390  List *names;
1391 
1392  /* '-' ? */
1393  if (strcmp(cfg_name_or_oid, "-") == 0)
1395 
1396  /* Numeric OID? */
1397  if (cfg_name_or_oid[0] >= '0' &&
1398  cfg_name_or_oid[0] <= '9' &&
1399  strspn(cfg_name_or_oid, "0123456789") == strlen(cfg_name_or_oid))
1400  {
1402  CStringGetDatum(cfg_name_or_oid)));
1403  PG_RETURN_OID(result);
1404  }
1405 
1406  /* The rest of this wouldn't work in bootstrap mode */
1408  elog(ERROR, "regconfig values must be OIDs in bootstrap mode");
1409 
1410  /*
1411  * Normal case: parse the name into components and see if it matches any
1412  * pg_ts_config entries in the current search path.
1413  */
1414  names = stringToQualifiedNameList(cfg_name_or_oid);
1415 
1416  result = get_ts_config_oid(names, false);
1417 
1418  PG_RETURN_OID(result);
1419 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2678
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regconfigout()

Datum regconfigout ( PG_FUNCTION_ARGS  )

Definition at line 1425 of file regproc.c.

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

1426 {
1427  Oid cfgid = PG_GETARG_OID(0);
1428  char *result;
1429  HeapTuple cfgtup;
1430 
1431  if (cfgid == InvalidOid)
1432  {
1433  result = pstrdup("-");
1434  PG_RETURN_CSTRING(result);
1435  }
1436 
1437  cfgtup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgid));
1438 
1439  if (HeapTupleIsValid(cfgtup))
1440  {
1441  Form_pg_ts_config cfgform = (Form_pg_ts_config) GETSTRUCT(cfgtup);
1442  char *cfgname = NameStr(cfgform->cfgname);
1443  char *nspname;
1444 
1445  /*
1446  * Would this config be found by regconfigin? If not, qualify it.
1447  */
1448  if (TSConfigIsVisible(cfgid))
1449  nspname = NULL;
1450  else
1451  nspname = get_namespace_name(cfgform->cfgnamespace);
1452 
1453  result = quote_qualified_identifier(nspname, cfgname);
1454 
1455  ReleaseSysCache(cfgtup);
1456  }
1457  else
1458  {
1459  /* If OID doesn't match any pg_ts_config row, return it numerically */
1460  result = (char *) palloc(NAMEDATALEN);
1461  snprintf(result, NAMEDATALEN, "%u", cfgid);
1462  }
1463 
1464  PG_RETURN_CSTRING(result);
1465 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
char * pstrdup(const char *in)
Definition: mcxt.c:1187
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2736
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10790
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:950
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193

◆ regconfigrecv()

Datum regconfigrecv ( PG_FUNCTION_ARGS  )

Definition at line 1471 of file regproc.c.

References oidrecv().

1472 {
1473  /* Exactly the same as oidrecv, so share code */
1474  return oidrecv(fcinfo);
1475 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regconfigsend()

Datum regconfigsend ( PG_FUNCTION_ARGS  )

Definition at line 1481 of file regproc.c.

References oidsend().

1482 {
1483  /* Exactly the same as oidsend, so share code */
1484  return oidsend(fcinfo);
1485 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regdictionaryin()

Datum regdictionaryin ( PG_FUNCTION_ARGS  )

Definition at line 1497 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ERROR, get_ts_dict_oid(), InvalidOid, IsBootstrapProcessingMode, oidin(), PG_GETARG_CSTRING, PG_RETURN_OID, and stringToQualifiedNameList().

1498 {
1499  char *dict_name_or_oid = PG_GETARG_CSTRING(0);
1500  Oid result;
1501  List *names;
1502 
1503  /* '-' ? */
1504  if (strcmp(dict_name_or_oid, "-") == 0)
1506 
1507  /* Numeric OID? */
1508  if (dict_name_or_oid[0] >= '0' &&
1509  dict_name_or_oid[0] <= '9' &&
1510  strspn(dict_name_or_oid, "0123456789") == strlen(dict_name_or_oid))
1511  {
1513  CStringGetDatum(dict_name_or_oid)));
1514  PG_RETURN_OID(result);
1515  }
1516 
1517  /* The rest of this wouldn't work in bootstrap mode */
1519  elog(ERROR, "regdictionary values must be OIDs in bootstrap mode");
1520 
1521  /*
1522  * Normal case: parse the name into components and see if it matches any
1523  * pg_ts_dict entries in the current search path.
1524  */
1525  names = stringToQualifiedNameList(dict_name_or_oid);
1526 
1527  result = get_ts_dict_oid(names, false);
1528 
1529  PG_RETURN_OID(result);
1530 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2425
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regdictionaryout()

Datum regdictionaryout ( PG_FUNCTION_ARGS  )

Definition at line 1536 of file regproc.c.

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

1537 {
1538  Oid dictid = PG_GETARG_OID(0);
1539  char *result;
1540  HeapTuple dicttup;
1541 
1542  if (dictid == InvalidOid)
1543  {
1544  result = pstrdup("-");
1545  PG_RETURN_CSTRING(result);
1546  }
1547 
1548  dicttup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictid));
1549 
1550  if (HeapTupleIsValid(dicttup))
1551  {
1552  Form_pg_ts_dict dictform = (Form_pg_ts_dict) GETSTRUCT(dicttup);
1553  char *dictname = NameStr(dictform->dictname);
1554  char *nspname;
1555 
1556  /*
1557  * Would this dictionary be found by regdictionaryin? If not, qualify
1558  * it.
1559  */
1560  if (TSDictionaryIsVisible(dictid))
1561  nspname = NULL;
1562  else
1563  nspname = get_namespace_name(dictform->dictnamespace);
1564 
1565  result = quote_qualified_identifier(nspname, dictname);
1566 
1567  ReleaseSysCache(dicttup);
1568  }
1569  else
1570  {
1571  /* If OID doesn't match any pg_ts_dict row, return it numerically */
1572  result = (char *) palloc(NAMEDATALEN);
1573  snprintf(result, NAMEDATALEN, "%u", dictid);
1574  }
1575 
1576  PG_RETURN_CSTRING(result);
1577 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1187
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2483
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10790
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:950
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193

◆ regdictionaryrecv()

Datum regdictionaryrecv ( PG_FUNCTION_ARGS  )

Definition at line 1583 of file regproc.c.

References oidrecv().

1584 {
1585  /* Exactly the same as oidrecv, so share code */
1586  return oidrecv(fcinfo);
1587 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regdictionarysend()

Datum regdictionarysend ( PG_FUNCTION_ARGS  )

Definition at line 1593 of file regproc.c.

References oidsend().

1594 {
1595  /* Exactly the same as oidsend, so share code */
1596  return oidsend(fcinfo);
1597 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regnamespacein()

Datum regnamespacein ( PG_FUNCTION_ARGS  )

Definition at line 1733 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, get_namespace_oid(), InvalidOid, IsBootstrapProcessingMode, linitial, list_length(), oidin(), PG_GETARG_CSTRING, PG_RETURN_OID, stringToQualifiedNameList(), and strVal.

1734 {
1735  char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
1736  Oid result;
1737  List *names;
1738 
1739  /* '-' ? */
1740  if (strcmp(nsp_name_or_oid, "-") == 0)
1742 
1743  /* Numeric OID? */
1744  if (nsp_name_or_oid[0] >= '0' &&
1745  nsp_name_or_oid[0] <= '9' &&
1746  strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
1747  {
1749  CStringGetDatum(nsp_name_or_oid)));
1750  PG_RETURN_OID(result);
1751  }
1752 
1753  /* The rest of this wouldn't work in bootstrap mode */
1755  elog(ERROR, "regnamespace values must be OIDs in bootstrap mode");
1756 
1757  /* Normal case: see if the name matches any pg_namespace entry. */
1758  names = stringToQualifiedNameList(nsp_name_or_oid);
1759 
1760  if (list_length(names) != 1)
1761  ereport(ERROR,
1762  (errcode(ERRCODE_INVALID_NAME),
1763  errmsg("invalid name syntax")));
1764 
1765  result = get_namespace_oid(strVal(linitial(names)), false);
1766 
1767  PG_RETURN_OID(result);
1768 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3042
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
static int list_length(const List *l)
Definition: pg_list.h:169
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regnamespaceout()

Datum regnamespaceout ( PG_FUNCTION_ARGS  )

Definition at line 1801 of file regproc.c.

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

1802 {
1803  Oid nspid = PG_GETARG_OID(0);
1804  char *result;
1805 
1806  if (nspid == InvalidOid)
1807  {
1808  result = pstrdup("-");
1809  PG_RETURN_CSTRING(result);
1810  }
1811 
1812  result = get_namespace_name(nspid);
1813 
1814  if (result)
1815  {
1816  /* pstrdup is not really necessary, but it avoids a compiler warning */
1817  result = pstrdup(quote_identifier(result));
1818  }
1819  else
1820  {
1821  /* If OID doesn't match any namespace, return it numerically */
1822  result = (char *) palloc(NAMEDATALEN);
1823  snprintf(result, NAMEDATALEN, "%u", nspid);
1824  }
1825 
1826  PG_RETURN_CSTRING(result);
1827 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10706
char * pstrdup(const char *in)
Definition: mcxt.c:1187
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:950
#define snprintf
Definition: port.h:193

◆ regnamespacerecv()

Datum regnamespacerecv ( PG_FUNCTION_ARGS  )

Definition at line 1833 of file regproc.c.

References oidrecv().

1834 {
1835  /* Exactly the same as oidrecv, so share code */
1836  return oidrecv(fcinfo);
1837 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regnamespacesend()

Datum regnamespacesend ( PG_FUNCTION_ARGS  )

Definition at line 1843 of file regproc.c.

References oidsend().

1844 {
1845  /* Exactly the same as oidsend, so share code */
1846  return oidsend(fcinfo);
1847 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regoperatorin()

Datum regoperatorin ( PG_FUNCTION_ARGS  )

Definition at line 673 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ereport, errcode(), errhint(), errmsg(), ERROR, FUNC_MAX_ARGS, InvalidOid, IsBootstrapProcessingMode, oidin(), OidIsValid, OpernameGetOprid(), parseNameAndArgTypes(), PG_GETARG_CSTRING, and PG_RETURN_OID.

674 {
675  char *opr_name_or_oid = PG_GETARG_CSTRING(0);
676  Oid result;
677  List *names;
678  int nargs;
679  Oid argtypes[FUNC_MAX_ARGS];
680 
681  /* '0' ? */
682  if (strcmp(opr_name_or_oid, "0") == 0)
684 
685  /* Numeric OID? */
686  if (opr_name_or_oid[0] >= '0' &&
687  opr_name_or_oid[0] <= '9' &&
688  strspn(opr_name_or_oid, "0123456789") == strlen(opr_name_or_oid))
689  {
691  CStringGetDatum(opr_name_or_oid)));
692  PG_RETURN_OID(result);
693  }
694 
695  /* The rest of this wouldn't work in bootstrap mode */
697  elog(ERROR, "regoperator values must be OIDs in bootstrap mode");
698 
699  /*
700  * Else it's a name and arguments. Parse the name and arguments, look up
701  * potential matches in the current namespace search list, and scan to see
702  * which one exactly matches the given argument types. (There will not be
703  * more than one match.)
704  */
705  parseNameAndArgTypes(opr_name_or_oid, true, &names, &nargs, argtypes);
706  if (nargs == 1)
707  ereport(ERROR,
708  (errcode(ERRCODE_UNDEFINED_PARAMETER),
709  errmsg("missing argument"),
710  errhint("Use NONE to denote the missing argument of a unary operator.")));
711  if (nargs != 2)
712  ereport(ERROR,
713  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
714  errmsg("too many arguments"),
715  errhint("Provide two argument types for operator.")));
716 
717  result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
718 
719  if (!OidIsValid(result))
720  ereport(ERROR,
721  (errcode(ERRCODE_UNDEFINED_FUNCTION),
722  errmsg("operator does not exist: %s", opr_name_or_oid)));
723 
724  PG_RETURN_OID(result);
725 }
int errhint(const char *fmt,...)
Definition: elog.c:1071
#define DatumGetObjectId(X)
Definition: postgres.h:500
int errcode(int sqlerrcode)
Definition: elog.c:610
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
#define FUNC_MAX_ARGS
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1483
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
Definition: regproc.c:1924
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regoperatorout()

Datum regoperatorout ( PG_FUNCTION_ARGS  )

Definition at line 897 of file regproc.c.

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

898 {
899  Oid oprid = PG_GETARG_OID(0);
900  char *result;
901 
902  if (oprid == InvalidOid)
903  result = pstrdup("0");
904  else
905  result = format_operator(oprid);
906 
907  PG_RETURN_CSTRING(result);
908 }
Oid oprid(Operator op)
Definition: parse_oper.c:250
char * pstrdup(const char *in)
Definition: mcxt.c:1187
char * format_operator(Oid operator_oid)
Definition: regproc.c:851
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361

◆ regoperatorrecv()

Datum regoperatorrecv ( PG_FUNCTION_ARGS  )

Definition at line 914 of file regproc.c.

References oidrecv().

915 {
916  /* Exactly the same as oidrecv, so share code */
917  return oidrecv(fcinfo);
918 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regoperatorsend()

Datum regoperatorsend ( PG_FUNCTION_ARGS  )

Definition at line 924 of file regproc.c.

References oidsend().

925 {
926  /* Exactly the same as oidsend, so share code */
927  return oidsend(fcinfo);
928 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regoperin()

Datum regoperin ( PG_FUNCTION_ARGS  )

Definition at line 501 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, InvalidOid, IsBootstrapProcessingMode, _FuncCandidateList::next, _FuncCandidateList::oid, oidin(), OpernameGetCandidates(), PG_GETARG_CSTRING, PG_RETURN_OID, and stringToQualifiedNameList().

502 {
503  char *opr_name_or_oid = PG_GETARG_CSTRING(0);
504  Oid result = InvalidOid;
505  List *names;
506  FuncCandidateList clist;
507 
508  /* '0' ? */
509  if (strcmp(opr_name_or_oid, "0") == 0)
511 
512  /* Numeric OID? */
513  if (opr_name_or_oid[0] >= '0' &&
514  opr_name_or_oid[0] <= '9' &&
515  strspn(opr_name_or_oid, "0123456789") == strlen(opr_name_or_oid))
516  {
518  CStringGetDatum(opr_name_or_oid)));
519  PG_RETURN_OID(result);
520  }
521 
522  /* Else it's a name, possibly schema-qualified */
523 
524  /* The rest of this wouldn't work in bootstrap mode */
526  elog(ERROR, "regoper values must be OIDs in bootstrap mode");
527 
528  /*
529  * Normal case: parse the name into components and see if it matches any
530  * pg_operator entries in the current search path.
531  */
532  names = stringToQualifiedNameList(opr_name_or_oid);
533  clist = OpernameGetCandidates(names, '\0', false);
534 
535  if (clist == NULL)
536  ereport(ERROR,
537  (errcode(ERRCODE_UNDEFINED_FUNCTION),
538  errmsg("operator does not exist: %s", opr_name_or_oid)));
539  else if (clist->next != NULL)
540  ereport(ERROR,
541  (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
542  errmsg("more than one operator named %s",
543  opr_name_or_oid)));
544 
545  result = clist->oid;
546 
547  PG_RETURN_OID(result);
548 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
int errcode(int sqlerrcode)
Definition: elog.c:610
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1586
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
struct _FuncCandidateList * next
Definition: namespace.h:30
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regoperout()

Datum regoperout ( PG_FUNCTION_ARGS  )

Definition at line 579 of file regproc.c.

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

580 {
581  Oid oprid = PG_GETARG_OID(0);
582  char *result;
583  HeapTuple opertup;
584 
585  if (oprid == InvalidOid)
586  {
587  result = pstrdup("0");
588  PG_RETURN_CSTRING(result);
589  }
590 
591  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(oprid));
592 
593  if (HeapTupleIsValid(opertup))
594  {
595  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
596  char *oprname = NameStr(operform->oprname);
597 
598  /*
599  * In bootstrap mode, skip the fancy namespace stuff and just return
600  * the oper name. (This path is only needed for debugging output
601  * anyway.)
602  */
604  result = pstrdup(oprname);
605  else
606  {
607  FuncCandidateList clist;
608 
609  /*
610  * Would this oper be found (uniquely!) by regoperin? If not,
611  * qualify it.
612  */
613  clist = OpernameGetCandidates(list_make1(makeString(oprname)),
614  '\0', false);
615  if (clist != NULL && clist->next == NULL &&
616  clist->oid == oprid)
617  result = pstrdup(oprname);
618  else
619  {
620  const char *nspname;
621 
622  nspname = get_namespace_name(operform->oprnamespace);
623  nspname = quote_identifier(nspname);
624  result = (char *) palloc(strlen(nspname) + strlen(oprname) + 2);
625  sprintf(result, "%s.%s", nspname, oprname);
626  }
627  }
628 
629  ReleaseSysCache(opertup);
630  }
631  else
632  {
633  /*
634  * If OID doesn't match any pg_operator entry, return it numerically
635  */
636  result = (char *) palloc(NAMEDATALEN);
637  snprintf(result, NAMEDATALEN, "%u", oprid);
638  }
639 
640  PG_RETURN_CSTRING(result);
641 }
Value * makeString(char *str)
Definition: value.c:53
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10706
Oid oprid(Operator op)
Definition: parse_oper.c:250
char * pstrdup(const char *in)
Definition: mcxt.c:1187
unsigned int Oid
Definition: postgres_ext.h:31
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1586
#define list_make1(x1)
Definition: pg_list.h:227
#define NAMEDATALEN
#define sprintf
Definition: port.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
struct _FuncCandidateList * next
Definition: namespace.h:30
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
void * palloc(Size size)
Definition: mcxt.c:950
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193

◆ regoperrecv()

Datum regoperrecv ( PG_FUNCTION_ARGS  )

Definition at line 647 of file regproc.c.

References oidrecv().

648 {
649  /* Exactly the same as oidrecv, so share code */
650  return oidrecv(fcinfo);
651 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regopersend()

Datum regopersend ( PG_FUNCTION_ARGS  )

Definition at line 657 of file regproc.c.

References oidsend().

658 {
659  /* Exactly the same as oidsend, so share code */
660  return oidsend(fcinfo);
661 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regprocedurein()

Datum regprocedurein ( PG_FUNCTION_ARGS  )

Definition at line 230 of file regproc.c.

References _FuncCandidateList::args, CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, FUNC_MAX_ARGS, FuncnameGetCandidates(), InvalidOid, IsBootstrapProcessingMode, _FuncCandidateList::next, NIL, _FuncCandidateList::oid, oidin(), parseNameAndArgTypes(), PG_GETARG_CSTRING, and PG_RETURN_OID.

Referenced by convert_function_name().

231 {
232  char *pro_name_or_oid = PG_GETARG_CSTRING(0);
233  RegProcedure result = InvalidOid;
234  List *names;
235  int nargs;
236  Oid argtypes[FUNC_MAX_ARGS];
237  FuncCandidateList clist;
238 
239  /* '-' ? */
240  if (strcmp(pro_name_or_oid, "-") == 0)
242 
243  /* Numeric OID? */
244  if (pro_name_or_oid[0] >= '0' &&
245  pro_name_or_oid[0] <= '9' &&
246  strspn(pro_name_or_oid, "0123456789") == strlen(pro_name_or_oid))
247  {
249  CStringGetDatum(pro_name_or_oid)));
250  PG_RETURN_OID(result);
251  }
252 
253  /* The rest of this wouldn't work in bootstrap mode */
255  elog(ERROR, "regprocedure values must be OIDs in bootstrap mode");
256 
257  /*
258  * Else it's a name and arguments. Parse the name and arguments, look up
259  * potential matches in the current namespace search list, and scan to see
260  * which one exactly matches the given argument types. (There will not be
261  * more than one match.)
262  */
263  parseNameAndArgTypes(pro_name_or_oid, false, &names, &nargs, argtypes);
264 
265  clist = FuncnameGetCandidates(names, nargs, NIL, false, false, false);
266 
267  for (; clist; clist = clist->next)
268  {
269  if (memcmp(clist->args, argtypes, nargs * sizeof(Oid)) == 0)
270  break;
271  }
272 
273  if (clist == NULL)
274  ereport(ERROR,
275  (errcode(ERRCODE_UNDEFINED_FUNCTION),
276  errmsg("function \"%s\" does not exist", pro_name_or_oid)));
277 
278  result = clist->oid;
279 
280  PG_RETURN_OID(result);
281 }
#define NIL
Definition: pg_list.h:65
#define DatumGetObjectId(X)
Definition: postgres.h:500
regproc RegProcedure
Definition: c.h:518
int errcode(int sqlerrcode)
Definition: elog.c:610
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
#define FUNC_MAX_ARGS
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition: namespace.h:37
#define ERROR
Definition: elog.h:43
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
#define CStringGetDatum(X)
Definition: postgres.h:578
struct _FuncCandidateList * next
Definition: namespace.h:30
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
Definition: regproc.c:1924
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regprocedureout()

Datum regprocedureout ( PG_FUNCTION_ARGS  )

Definition at line 458 of file regproc.c.

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

459 {
460  RegProcedure proid = PG_GETARG_OID(0);
461  char *result;
462 
463  if (proid == InvalidOid)
464  result = pstrdup("-");
465  else
466  result = format_procedure(proid);
467 
468  PG_RETURN_CSTRING(result);
469 }
char * pstrdup(const char *in)
Definition: mcxt.c:1187
regproc RegProcedure
Definition: c.h:518
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define InvalidOid
Definition: postgres_ext.h:36
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:322
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361

◆ regprocedurerecv()

Datum regprocedurerecv ( PG_FUNCTION_ARGS  )

Definition at line 475 of file regproc.c.

References oidrecv().

476 {
477  /* Exactly the same as oidrecv, so share code */
478  return oidrecv(fcinfo);
479 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regproceduresend()

Datum regproceduresend ( PG_FUNCTION_ARGS  )

Definition at line 485 of file regproc.c.

References oidsend().

486 {
487  /* Exactly the same as oidsend, so share code */
488  return oidsend(fcinfo);
489 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regprocin()

Datum regprocin ( PG_FUNCTION_ARGS  )

Definition at line 61 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, FuncnameGetCandidates(), InvalidOid, IsBootstrapProcessingMode, _FuncCandidateList::next, NIL, _FuncCandidateList::oid, oidin(), PG_GETARG_CSTRING, PG_RETURN_OID, and stringToQualifiedNameList().

62 {
63  char *pro_name_or_oid = PG_GETARG_CSTRING(0);
64  RegProcedure result = InvalidOid;
65  List *names;
66  FuncCandidateList clist;
67 
68  /* '-' ? */
69  if (strcmp(pro_name_or_oid, "-") == 0)
71 
72  /* Numeric OID? */
73  if (pro_name_or_oid[0] >= '0' &&
74  pro_name_or_oid[0] <= '9' &&
75  strspn(pro_name_or_oid, "0123456789") == strlen(pro_name_or_oid))
76  {
78  CStringGetDatum(pro_name_or_oid)));
79  PG_RETURN_OID(result);
80  }
81 
82  /* Else it's a name, possibly schema-qualified */
83 
84  /*
85  * We should never get here in bootstrap mode, as all references should
86  * have been resolved by genbki.pl.
87  */
89  elog(ERROR, "regproc values must be OIDs in bootstrap mode");
90 
91  /*
92  * Normal case: parse the name into components and see if it matches any
93  * pg_proc entries in the current search path.
94  */
95  names = stringToQualifiedNameList(pro_name_or_oid);
96  clist = FuncnameGetCandidates(names, -1, NIL, false, false, false);
97 
98  if (clist == NULL)
99  ereport(ERROR,
100  (errcode(ERRCODE_UNDEFINED_FUNCTION),
101  errmsg("function \"%s\" does not exist", pro_name_or_oid)));
102  else if (clist->next != NULL)
103  ereport(ERROR,
104  (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
105  errmsg("more than one function named \"%s\"",
106  pro_name_or_oid)));
107 
108  result = clist->oid;
109 
110  PG_RETURN_OID(result);
111 }
#define NIL
Definition: pg_list.h:65
#define DatumGetObjectId(X)
Definition: postgres.h:500
regproc RegProcedure
Definition: c.h:518
int errcode(int sqlerrcode)
Definition: elog.c:610
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
#define ERROR
Definition: elog.h:43
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
#define CStringGetDatum(X)
Definition: postgres.h:578
struct _FuncCandidateList * next
Definition: namespace.h:30
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regprocout()

Datum regprocout ( PG_FUNCTION_ARGS  )

Definition at line 142 of file regproc.c.

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, PROCOID, proname, pstrdup(), quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

143 {
144  RegProcedure proid = PG_GETARG_OID(0);
145  char *result;
146  HeapTuple proctup;
147 
148  if (proid == InvalidOid)
149  {
150  result = pstrdup("-");
151  PG_RETURN_CSTRING(result);
152  }
153 
154  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(proid));
155 
156  if (HeapTupleIsValid(proctup))
157  {
158  Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
159  char *proname = NameStr(procform->proname);
160 
161  /*
162  * In bootstrap mode, skip the fancy namespace stuff and just return
163  * the proc name. (This path is only needed for debugging output
164  * anyway.)
165  */
167  result = pstrdup(proname);
168  else
169  {
170  char *nspname;
171  FuncCandidateList clist;
172 
173  /*
174  * Would this proc be found (uniquely!) by regprocin? If not,
175  * qualify it.
176  */
177  clist = FuncnameGetCandidates(list_make1(makeString(proname)),
178  -1, NIL, false, false, false);
179  if (clist != NULL && clist->next == NULL &&
180  clist->oid == proid)
181  nspname = NULL;
182  else
183  nspname = get_namespace_name(procform->pronamespace);
184 
185  result = quote_qualified_identifier(nspname, proname);
186  }
187 
188  ReleaseSysCache(proctup);
189  }
190  else
191  {
192  /* If OID doesn't match any pg_proc entry, return it numerically */
193  result = (char *) palloc(NAMEDATALEN);
194  snprintf(result, NAMEDATALEN, "%u", proid);
195  }
196 
197  PG_RETURN_CSTRING(result);
198 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:65
NameData proname
Definition: pg_proc.h:35
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1187
regproc RegProcedure
Definition: c.h:518
#define list_make1(x1)
Definition: pg_list.h:227
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
struct _FuncCandidateList * next
Definition: namespace.h:30
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10790
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
void * palloc(Size size)
Definition: mcxt.c:950
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193

◆ regprocrecv()

Datum regprocrecv ( PG_FUNCTION_ARGS  )

Definition at line 204 of file regproc.c.

References oidrecv().

205 {
206  /* Exactly the same as oidrecv, so share code */
207  return oidrecv(fcinfo);
208 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regprocsend()

Datum regprocsend ( PG_FUNCTION_ARGS  )

Definition at line 214 of file regproc.c.

References oidsend().

215 {
216  /* Exactly the same as oidsend, so share code */
217  return oidsend(fcinfo);
218 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regrolein()

Datum regrolein ( PG_FUNCTION_ARGS  )

Definition at line 1608 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, get_role_oid(), InvalidOid, IsBootstrapProcessingMode, linitial, list_length(), oidin(), PG_GETARG_CSTRING, PG_RETURN_OID, stringToQualifiedNameList(), and strVal.

1609 {
1610  char *role_name_or_oid = PG_GETARG_CSTRING(0);
1611  Oid result;
1612  List *names;
1613 
1614  /* '-' ? */
1615  if (strcmp(role_name_or_oid, "-") == 0)
1617 
1618  /* Numeric OID? */
1619  if (role_name_or_oid[0] >= '0' &&
1620  role_name_or_oid[0] <= '9' &&
1621  strspn(role_name_or_oid, "0123456789") == strlen(role_name_or_oid))
1622  {
1624  CStringGetDatum(role_name_or_oid)));
1625  PG_RETURN_OID(result);
1626  }
1627 
1628  /* The rest of this wouldn't work in bootstrap mode */
1630  elog(ERROR, "regrole values must be OIDs in bootstrap mode");
1631 
1632  /* Normal case: see if the name matches any pg_authid entry. */
1633  names = stringToQualifiedNameList(role_name_or_oid);
1634 
1635  if (list_length(names) != 1)
1636  ereport(ERROR,
1637  (errcode(ERRCODE_INVALID_NAME),
1638  errmsg("invalid name syntax")));
1639 
1640  result = get_role_oid(strVal(linitial(names)), false);
1641 
1642  PG_RETURN_OID(result);
1643 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5175
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
static int list_length(const List *l)
Definition: pg_list.h:169
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regroleout()

Datum regroleout ( PG_FUNCTION_ARGS  )

Definition at line 1676 of file regproc.c.

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

1677 {
1678  Oid roleoid = PG_GETARG_OID(0);
1679  char *result;
1680 
1681  if (roleoid == InvalidOid)
1682  {
1683  result = pstrdup("-");
1684  PG_RETURN_CSTRING(result);
1685  }
1686 
1687  result = GetUserNameFromId(roleoid, true);
1688 
1689  if (result)
1690  {
1691  /* pstrdup is not really necessary, but it avoids a compiler warning */
1692  result = pstrdup(quote_identifier(result));
1693  }
1694  else
1695  {
1696  /* If OID doesn't match any role, return it numerically */
1697  result = (char *) palloc(NAMEDATALEN);
1698  snprintf(result, NAMEDATALEN, "%u", roleoid);
1699  }
1700 
1701  PG_RETURN_CSTRING(result);
1702 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10706
char * pstrdup(const char *in)
Definition: mcxt.c:1187
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define InvalidOid
Definition: postgres_ext.h:36
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:891
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:950
#define snprintf
Definition: port.h:193

◆ regrolerecv()

Datum regrolerecv ( PG_FUNCTION_ARGS  )

Definition at line 1708 of file regproc.c.

References oidrecv().

1709 {
1710  /* Exactly the same as oidrecv, so share code */
1711  return oidrecv(fcinfo);
1712 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regrolesend()

Datum regrolesend ( PG_FUNCTION_ARGS  )

Definition at line 1718 of file regproc.c.

References oidsend().

1719 {
1720  /* Exactly the same as oidsend, so share code */
1721  return oidsend(fcinfo);
1722 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regtypein()

Datum regtypein ( PG_FUNCTION_ARGS  )

Definition at line 1250 of file regproc.c.

References CStringGetDatum, DatumGetObjectId, DirectFunctionCall1, elog, ERROR, InvalidOid, IsBootstrapProcessingMode, oidin(), parseTypeString(), PG_GETARG_CSTRING, and PG_RETURN_OID.

Referenced by convert_type_name(), and plperl_sv_to_literal().

1251 {
1252  char *typ_name_or_oid = PG_GETARG_CSTRING(0);
1253  Oid result = InvalidOid;
1254  int32 typmod;
1255 
1256  /* '-' ? */
1257  if (strcmp(typ_name_or_oid, "-") == 0)
1259 
1260  /* Numeric OID? */
1261  if (typ_name_or_oid[0] >= '0' &&
1262  typ_name_or_oid[0] <= '9' &&
1263  strspn(typ_name_or_oid, "0123456789") == strlen(typ_name_or_oid))
1264  {
1266  CStringGetDatum(typ_name_or_oid)));
1267  PG_RETURN_OID(result);
1268  }
1269 
1270  /* Else it's a type name, possibly schema-qualified or decorated */
1271 
1272  /* The rest of this wouldn't work in bootstrap mode */
1274  elog(ERROR, "regtype values must be OIDs in bootstrap mode");
1275 
1276  /*
1277  * Normal case: invoke the full parser to deal with special cases such as
1278  * array syntax.
1279  */
1280  parseTypeString(typ_name_or_oid, &result, &typmod, false);
1281 
1282  PG_RETURN_OID(result);
1283 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:362
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
void parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:832
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regtypeout()

Datum regtypeout ( PG_FUNCTION_ARGS  )

Definition at line 1312 of file regproc.c.

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

1313 {
1314  Oid typid = PG_GETARG_OID(0);
1315  char *result;
1316  HeapTuple typetup;
1317 
1318  if (typid == InvalidOid)
1319  {
1320  result = pstrdup("-");
1321  PG_RETURN_CSTRING(result);
1322  }
1323 
1324  typetup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid));
1325 
1326  if (HeapTupleIsValid(typetup))
1327  {
1328  Form_pg_type typeform = (Form_pg_type) GETSTRUCT(typetup);
1329 
1330  /*
1331  * In bootstrap mode, skip the fancy namespace stuff and just return
1332  * the type name. (This path is only needed for debugging output
1333  * anyway.)
1334  */
1336  {
1337  char *typname = NameStr(typeform->typname);
1338 
1339  result = pstrdup(typname);
1340  }
1341  else
1342  result = format_type_be(typid);
1343 
1344  ReleaseSysCache(typetup);
1345  }
1346  else
1347  {
1348  /* If OID doesn't match any pg_type entry, return it numerically */
1349  result = (char *) palloc(NAMEDATALEN);
1350  snprintf(result, NAMEDATALEN, "%u", typid);
1351  }
1352 
1353  PG_RETURN_CSTRING(result);
1354 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1187
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
NameData typname
Definition: pg_type.h:41
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
void * palloc(Size size)
Definition: mcxt.c:950
#define NameStr(name)
Definition: c.h:622
#define snprintf
Definition: port.h:193

◆ regtyperecv()

Datum regtyperecv ( PG_FUNCTION_ARGS  )

Definition at line 1360 of file regproc.c.

References oidrecv().

1361 {
1362  /* Exactly the same as oidrecv, so share code */
1363  return oidrecv(fcinfo);
1364 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regtypesend()

Datum regtypesend ( PG_FUNCTION_ARGS  )

Definition at line 1370 of file regproc.c.

References oidsend().

1371 {
1372  /* Exactly the same as oidsend, so share code */
1373  return oidsend(fcinfo);
1374 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ stringToQualifiedNameList()

List* stringToQualifiedNameList ( const char *  string)

Definition at line 1876 of file regproc.c.

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

Referenced by call_pltcl_start_proc(), check_TSCurrentConfig(), getTSCurrentConfig(), parseNameAndArgTypes(), regclassin(), regcollationin(), regconfigin(), regdictionaryin(), regnamespacein(), regoperin(), regprocin(), regrolein(), RelationNameGetTupleDesc(), thesaurus_init(), to_regclass(), to_regcollation(), to_regnamespace(), to_regoper(), to_regproc(), to_regrole(), and tsvector_update_trigger().

1877 {
1878  char *rawname;
1879  List *result = NIL;
1880  List *namelist;
1881  ListCell *l;
1882 
1883  /* We need a modifiable copy of the input string. */
1884  rawname = pstrdup(string);
1885 
1886  if (!SplitIdentifierString(rawname, '.', &namelist))
1887  ereport(ERROR,
1888  (errcode(ERRCODE_INVALID_NAME),
1889  errmsg("invalid name syntax")));
1890 
1891  if (namelist == NIL)
1892  ereport(ERROR,
1893  (errcode(ERRCODE_INVALID_NAME),
1894  errmsg("invalid name syntax")));
1895 
1896  foreach(l, namelist)
1897  {
1898  char *curname = (char *) lfirst(l);
1899 
1900  result = lappend(result, makeString(pstrdup(curname)));
1901  }
1902 
1903  pfree(rawname);
1904  list_free(namelist);
1905 
1906  return result;
1907 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1187
int errcode(int sqlerrcode)
Definition: elog.c:610
void pfree(void *pointer)
Definition: mcxt.c:1057
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3702
List * lappend(List *list, void *datum)
Definition: list.c:321
#define ereport(elevel,...)
Definition: elog.h:144
#define lfirst(lc)
Definition: pg_list.h:190
int errmsg(const char *fmt,...)
Definition: elog.c:824
void list_free(List *list)
Definition: list.c:1376
Definition: pg_list.h:50

◆ text_regclass()

Datum text_regclass ( PG_FUNCTION_ARGS  )

Definition at line 1857 of file regproc.c.

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

1858 {
1860  Oid result;
1861  RangeVar *rv;
1862 
1864 
1865  /* We might not even have permissions on this relation; don't lock it. */
1866  result = RangeVarGetRelid(rv, NoLock, false);
1867 
1868  PG_RETURN_OID(result);
1869 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:78
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define NoLock
Definition: lockdefs.h:34
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3644
Definition: c.h:562
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ to_regclass()

Datum to_regclass ( PG_FUNCTION_ARGS  )

Definition at line 984 of file regproc.c.

References class_name, makeRangeVarFromNameList(), NoLock, OidIsValid, PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, RangeVarGetRelid, stringToQualifiedNameList(), and text_to_cstring().

985 {
987  Oid result;
988  List *names;
989 
990  /*
991  * Parse the name into components and see if it matches any pg_class
992  * entries in the current search path.
993  */
994  names = stringToQualifiedNameList(class_name);
995 
996  /* We might not even have permissions on this relation; don't lock it. */
997  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, true);
998 
999  if (OidIsValid(result))
1000  PG_RETURN_OID(result);
1001  else
1002  PG_RETURN_NULL();
1003 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:78
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define NoLock
Definition: lockdefs.h:34
const char * class_name
Definition: selinux.c:32
char * text_to_cstring(const text *t)
Definition: varlena.c:221
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regcollation()

Datum to_regcollation ( PG_FUNCTION_ARGS  )

Definition at line 1135 of file regproc.c.

References get_collation_oid(), OidIsValid, PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, stringToQualifiedNameList(), and text_to_cstring().

1136 {
1137  char *collation_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1138  Oid result;
1139  List *names;
1140 
1141  /*
1142  * Parse the name into components and see if it matches any pg_collation
1143  * entries in the current search path.
1144  */
1145  names = stringToQualifiedNameList(collation_name);
1146 
1147  /* We might not even have permissions on this relation; don't lock it. */
1148  result = get_collation_oid(names, true);
1149 
1150  if (OidIsValid(result))
1151  PG_RETURN_OID(result);
1152  else
1153  PG_RETURN_NULL();
1154 }
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
char * text_to_cstring(const text *t)
Definition: varlena.c:221
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3600
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regnamespace()

Datum to_regnamespace ( PG_FUNCTION_ARGS  )

Definition at line 1776 of file regproc.c.

References ereport, errcode(), errmsg(), ERROR, get_namespace_oid(), linitial, list_length(), OidIsValid, PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, stringToQualifiedNameList(), strVal, and text_to_cstring().

1777 {
1778  char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1779  Oid result;
1780  List *names;
1781 
1782  names = stringToQualifiedNameList(nsp_name);
1783 
1784  if (list_length(names) != 1)
1785  ereport(ERROR,
1786  (errcode(ERRCODE_INVALID_NAME),
1787  errmsg("invalid name syntax")));
1788 
1789  result = get_namespace_oid(strVal(linitial(names)), true);
1790 
1791  if (OidIsValid(result))
1792  PG_RETURN_OID(result);
1793  else
1794  PG_RETURN_NULL();
1795 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3042
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
static int list_length(const List *l)
Definition: pg_list.h:169
char * text_to_cstring(const text *t)
Definition: varlena.c:221
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regoper()

Datum to_regoper ( PG_FUNCTION_ARGS  )

Definition at line 556 of file regproc.c.

References _FuncCandidateList::next, _FuncCandidateList::oid, OpernameGetCandidates(), PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, stringToQualifiedNameList(), and text_to_cstring().

557 {
558  char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
559  List *names;
560  FuncCandidateList clist;
561 
562  /*
563  * Parse the name into components and see if it matches any pg_operator
564  * entries in the current search path.
565  */
566  names = stringToQualifiedNameList(opr_name);
567  clist = OpernameGetCandidates(names, '\0', true);
568 
569  if (clist == NULL || clist->next != NULL)
570  PG_RETURN_NULL();
571 
572  PG_RETURN_OID(clist->oid);
573 }
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1586
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
struct _FuncCandidateList * next
Definition: namespace.h:30
char * text_to_cstring(const text *t)
Definition: varlena.c:221
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regoperator()

Datum to_regoperator ( PG_FUNCTION_ARGS  )

Definition at line 733 of file regproc.c.

References ereport, errcode(), errhint(), errmsg(), ERROR, FUNC_MAX_ARGS, OidIsValid, OpernameGetOprid(), parseNameAndArgTypes(), PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, and text_to_cstring().

734 {
735  char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
736  Oid result;
737  List *names;
738  int nargs;
739  Oid argtypes[FUNC_MAX_ARGS];
740 
741  /*
742  * Parse the name and arguments, look up potential matches in the current
743  * namespace search list, and scan to see which one exactly matches the
744  * given argument types. (There will not be more than one match.)
745  */
746  parseNameAndArgTypes(opr_name_or_oid, true, &names, &nargs, argtypes);
747  if (nargs == 1)
748  ereport(ERROR,
749  (errcode(ERRCODE_UNDEFINED_PARAMETER),
750  errmsg("missing argument"),
751  errhint("Use NONE to denote the missing argument of a unary operator.")));
752  if (nargs != 2)
753  ereport(ERROR,
754  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
755  errmsg("too many arguments"),
756  errhint("Provide two argument types for operator.")));
757 
758  result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
759 
760  if (!OidIsValid(result))
761  PG_RETURN_NULL();
762 
763  PG_RETURN_OID(result);
764 }
int errhint(const char *fmt,...)
Definition: elog.c:1071
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define FUNC_MAX_ARGS
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1483
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
Definition: regproc.c:1924
char * text_to_cstring(const text *t)
Definition: varlena.c:221
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regproc()

Datum to_regproc ( PG_FUNCTION_ARGS  )

Definition at line 119 of file regproc.c.

References FuncnameGetCandidates(), _FuncCandidateList::next, NIL, _FuncCandidateList::oid, PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, stringToQualifiedNameList(), and text_to_cstring().

120 {
121  char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
122  List *names;
123  FuncCandidateList clist;
124 
125  /*
126  * Parse the name into components and see if it matches any pg_proc
127  * entries in the current search path.
128  */
129  names = stringToQualifiedNameList(pro_name);
130  clist = FuncnameGetCandidates(names, -1, NIL, false, false, true);
131 
132  if (clist == NULL || clist->next != NULL)
133  PG_RETURN_NULL();
134 
135  PG_RETURN_OID(clist->oid);
136 }
#define NIL
Definition: pg_list.h:65
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
struct _FuncCandidateList * next
Definition: namespace.h:30
char * text_to_cstring(const text *t)
Definition: varlena.c:221
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regprocedure()

Datum to_regprocedure ( PG_FUNCTION_ARGS  )

Definition at line 289 of file regproc.c.

References _FuncCandidateList::args, FUNC_MAX_ARGS, FuncnameGetCandidates(), _FuncCandidateList::next, NIL, _FuncCandidateList::oid, parseNameAndArgTypes(), PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, and text_to_cstring().

290 {
291  char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
292  List *names;
293  int nargs;
294  Oid argtypes[FUNC_MAX_ARGS];
295  FuncCandidateList clist;
296 
297  /*
298  * Parse the name and arguments, look up potential matches in the current
299  * namespace search list, and scan to see which one exactly matches the
300  * given argument types. (There will not be more than one match.)
301  */
302  parseNameAndArgTypes(pro_name, false, &names, &nargs, argtypes);
303 
304  clist = FuncnameGetCandidates(names, nargs, NIL, false, false, true);
305 
306  for (; clist; clist = clist->next)
307  {
308  if (memcmp(clist->args, argtypes, nargs * sizeof(Oid)) == 0)
309  PG_RETURN_OID(clist->oid);
310  }
311 
312  PG_RETURN_NULL();
313 }
#define NIL
Definition: pg_list.h:65
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define FUNC_MAX_ARGS
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition: namespace.h:37
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
struct _FuncCandidateList * next
Definition: namespace.h:30
static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
Definition: regproc.c:1924
char * text_to_cstring(const text *t)
Definition: varlena.c:221
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regrole()

Datum to_regrole ( PG_FUNCTION_ARGS  )

Definition at line 1651 of file regproc.c.

References ereport, errcode(), errmsg(), ERROR, get_role_oid(), linitial, list_length(), OidIsValid, PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, stringToQualifiedNameList(), strVal, and text_to_cstring().

1652 {
1653  char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1654  Oid result;
1655  List *names;
1656 
1657  names = stringToQualifiedNameList(role_name);
1658 
1659  if (list_length(names) != 1)
1660  ereport(ERROR,
1661  (errcode(ERRCODE_INVALID_NAME),
1662  errmsg("invalid name syntax")));
1663 
1664  result = get_role_oid(strVal(linitial(names)), true);
1665 
1666  if (OidIsValid(result))
1667  PG_RETURN_OID(result);
1668  else
1669  PG_RETURN_NULL();
1670 }
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5175
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
static int list_length(const List *l)
Definition: pg_list.h:169
char * text_to_cstring(const text *t)
Definition: varlena.c:221
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1876
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regtype()

Datum to_regtype ( PG_FUNCTION_ARGS  )

Definition at line 1291 of file regproc.c.

References OidIsValid, parseTypeString(), PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_OID, and text_to_cstring().

1292 {
1293  char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1294  Oid result;
1295  int32 typmod;
1296 
1297  /*
1298  * Invoke the full parser to deal with special cases such as array syntax.
1299  */
1300  parseTypeString(typ_name, &result, &typmod, true);
1301 
1302  if (OidIsValid(result))
1303  PG_RETURN_OID(result);
1304  else
1305  PG_RETURN_NULL();
1306 }
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
signed int int32
Definition: c.h:362
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
void parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:832
char * text_to_cstring(const text *t)
Definition: varlena.c:221
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344