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 char * format_operator_internal (Oid operator_oid, bool force_qualify)
 
static char * format_procedure_internal (Oid procedure_oid, bool force_qualify)
 
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)
 
void format_procedure_parts (Oid procedure_oid, List **objnames, List **objargs)
 
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 (Oid operator_oid)
 
char * format_operator_qualified (Oid operator_oid)
 
void format_operator_parts (Oid operator_oid, List **objnames, List **objargs)
 
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 821 of file regproc.c.

References format_operator_internal().

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

822 {
823  return format_operator_internal(operator_oid, false);
824 }
static char * format_operator_internal(Oid operator_oid, bool force_qualify)
Definition: regproc.c:756

◆ format_operator_internal()

static char * format_operator_internal ( Oid  operator_oid,
bool  force_qualify 
)
static

Definition at line 756 of file regproc.c.

References appendStringInfo(), appendStringInfoString(), Assert, buf, StringInfoData::data, 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(), and format_operator_qualified().

757 {
758  char *result;
759  HeapTuple opertup;
760 
761  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
762 
763  if (HeapTupleIsValid(opertup))
764  {
765  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
766  char *oprname = NameStr(operform->oprname);
767  char *nspname;
769 
770  /* XXX no support here for bootstrap mode */
772 
773  initStringInfo(&buf);
774 
775  /*
776  * Would this oper be found (given the right args) by regoperatorin?
777  * If not, or if caller explicitly requests it, we need to qualify it.
778  */
779  if (force_qualify || !OperatorIsVisible(operator_oid))
780  {
781  nspname = get_namespace_name(operform->oprnamespace);
782  appendStringInfo(&buf, "%s.",
783  quote_identifier(nspname));
784  }
785 
786  appendStringInfo(&buf, "%s(", oprname);
787 
788  if (operform->oprleft)
789  appendStringInfo(&buf, "%s,",
790  force_qualify ?
791  format_type_be_qualified(operform->oprleft) :
792  format_type_be(operform->oprleft));
793  else
794  appendStringInfoString(&buf, "NONE,");
795 
796  if (operform->oprright)
797  appendStringInfo(&buf, "%s)",
798  force_qualify ?
799  format_type_be_qualified(operform->oprright) :
800  format_type_be(operform->oprright));
801  else
802  appendStringInfoString(&buf, "NONE)");
803 
804  result = buf.data;
805 
806  ReleaseSysCache(opertup);
807  }
808  else
809  {
810  /*
811  * If OID doesn't match any pg_operator entry, return it numerically
812  */
813  result = (char *) palloc(NAMEDATALEN);
814  snprintf(result, NAMEDATALEN, "%u", operator_oid);
815  }
816 
817  return result;
818 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10724
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:1747
char * format_type_be(Oid type_oid)
Definition: format_type.c:327
#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:3155
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
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:738
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:337
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ format_operator_parts()

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

Definition at line 833 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().

834 {
835  HeapTuple opertup;
836  Form_pg_operator oprForm;
837 
838  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
839  if (!HeapTupleIsValid(opertup))
840  elog(ERROR, "cache lookup failed for operator with OID %u",
841  operator_oid);
842 
843  oprForm = (Form_pg_operator) GETSTRUCT(opertup);
844  *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
845  pstrdup(NameStr(oprForm->oprname)));
846  *objargs = NIL;
847  if (oprForm->oprleft)
848  *objargs = lappend(*objargs,
849  format_type_be_qualified(oprForm->oprleft));
850  if (oprForm->oprright)
851  *objargs = lappend(*objargs,
852  format_type_be_qualified(oprForm->oprright));
853 
854  ReleaseSysCache(opertup);
855 }
#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:1186
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
List * lappend(List *list, void *datum)
Definition: list.c:322
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:337
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3179
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:615

◆ format_operator_qualified()

char* format_operator_qualified ( Oid  operator_oid)

Definition at line 827 of file regproc.c.

References format_operator_internal().

Referenced by getObjectIdentityParts().

828 {
829  return format_operator_internal(operator_oid, true);
830 }
static char * format_operator_internal(Oid operator_oid, bool force_qualify)
Definition: regproc.c:756

◆ format_procedure()

char* format_procedure ( Oid  procedure_oid)

Definition at line 324 of file regproc.c.

References format_procedure_internal().

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

325 {
326  return format_procedure_internal(procedure_oid, false);
327 }
static char * format_procedure_internal(Oid procedure_oid, bool force_qualify)
Definition: regproc.c:343

◆ format_procedure_internal()

static char * format_procedure_internal ( Oid  procedure_oid,
bool  force_qualify 
)
static

Definition at line 343 of file regproc.c.

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, buf, StringInfoData::data, 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(), and format_procedure_qualified().

344 {
345  char *result;
346  HeapTuple proctup;
347 
348  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
349 
350  if (HeapTupleIsValid(proctup))
351  {
352  Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
353  char *proname = NameStr(procform->proname);
354  int nargs = procform->pronargs;
355  int i;
356  char *nspname;
358 
359  /* XXX no support here for bootstrap mode */
361 
362  initStringInfo(&buf);
363 
364  /*
365  * Would this proc be found (given the right args) by regprocedurein?
366  * If not, or if caller requests it, we need to qualify it.
367  */
368  if (!force_qualify && FunctionIsVisible(procedure_oid))
369  nspname = NULL;
370  else
371  nspname = get_namespace_name(procform->pronamespace);
372 
373  appendStringInfo(&buf, "%s(",
374  quote_qualified_identifier(nspname, proname));
375  for (i = 0; i < nargs; i++)
376  {
377  Oid thisargtype = procform->proargtypes.values[i];
378 
379  if (i > 0)
380  appendStringInfoChar(&buf, ',');
382  force_qualify ?
383  format_type_be_qualified(thisargtype) :
384  format_type_be(thisargtype));
385  }
386  appendStringInfoChar(&buf, ')');
387 
388  result = buf.data;
389 
390  ReleaseSysCache(proctup);
391  }
392  else
393  {
394  /* If OID doesn't match any pg_proc entry, return it numerically */
395  result = (char *) palloc(NAMEDATALEN);
396  snprintf(result, NAMEDATALEN, "%u", procedure_oid);
397  }
398 
399  return result;
400 }
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:327
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:3155
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:10808
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
#define Assert(condition)
Definition: c.h:738
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:337
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
int i
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ format_procedure_parts()

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

Definition at line 409 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().

410 {
411  HeapTuple proctup;
412  Form_pg_proc procform;
413  int nargs;
414  int i;
415 
416  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
417 
418  if (!HeapTupleIsValid(proctup))
419  elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
420 
421  procform = (Form_pg_proc) GETSTRUCT(proctup);
422  nargs = procform->pronargs;
423 
424  *objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
425  pstrdup(NameStr(procform->proname)));
426  *objargs = NIL;
427  for (i = 0; i < nargs; i++)
428  {
429  Oid thisargtype = procform->proargtypes.values[i];
430 
431  *objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
432  }
433 
434  ReleaseSysCache(proctup);
435 }
#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:1186
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:322
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:337
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3179
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:615

◆ format_procedure_qualified()

char* format_procedure_qualified ( Oid  procedure_oid)

Definition at line 330 of file regproc.c.

References format_procedure_internal().

Referenced by getObjectIdentityParts().

331 {
332  return format_procedure_internal(procedure_oid, true);
333 }
static char * format_procedure_internal(Oid procedure_oid, bool force_qualify)
Definition: regproc.c:343

◆ parseNameAndArgTypes()

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

Definition at line 1887 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().

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

◆ regclassin()

Datum regclassin ( PG_FUNCTION_ARGS  )

Definition at line 904 of file regproc.c.

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

905 {
906  char *class_name_or_oid = PG_GETARG_CSTRING(0);
907  Oid result = InvalidOid;
908  List *names;
909 
910  /* '-' ? */
911  if (strcmp(class_name_or_oid, "-") == 0)
913 
914  /* Numeric OID? */
915  if (class_name_or_oid[0] >= '0' &&
916  class_name_or_oid[0] <= '9' &&
917  strspn(class_name_or_oid, "0123456789") == strlen(class_name_or_oid))
918  {
920  CStringGetDatum(class_name_or_oid)));
921  PG_RETURN_OID(result);
922  }
923 
924  /* Else it's a name, possibly schema-qualified */
925 
926  /* The rest of this wouldn't work in bootstrap mode */
928  elog(ERROR, "regclass values must be OIDs in bootstrap mode");
929 
930  /*
931  * Normal case: parse the name into components and see if it matches any
932  * pg_class entries in the current search path.
933  */
934  names = stringToQualifiedNameList(class_name_or_oid);
935 
936  /* We might not even have permissions on this relation; don't lock it. */
937  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, false);
938 
939  PG_RETURN_OID(result);
940 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:78
#define DatumGetObjectId(X)
Definition: postgres.h:500
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
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:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regclassout()

Datum regclassout ( PG_FUNCTION_ARGS  )

Definition at line 973 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().

974 {
975  Oid classid = PG_GETARG_OID(0);
976  char *result;
977  HeapTuple classtup;
978 
979  if (classid == InvalidOid)
980  {
981  result = pstrdup("-");
982  PG_RETURN_CSTRING(result);
983  }
984 
985  classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classid));
986 
987  if (HeapTupleIsValid(classtup))
988  {
989  Form_pg_class classform = (Form_pg_class) GETSTRUCT(classtup);
990  char *classname = NameStr(classform->relname);
991 
992  /*
993  * In bootstrap mode, skip the fancy namespace stuff and just return
994  * the class name. (This path is only needed for debugging output
995  * anyway.)
996  */
998  result = pstrdup(classname);
999  else
1000  {
1001  char *nspname;
1002 
1003  /*
1004  * Would this class be found by regclassin? If not, qualify it.
1005  */
1006  if (RelationIsVisible(classid))
1007  nspname = NULL;
1008  else
1009  nspname = get_namespace_name(classform->relnamespace);
1010 
1011  result = quote_qualified_identifier(nspname, classname);
1012  }
1013 
1014  ReleaseSysCache(classtup);
1015  }
1016  else
1017  {
1018  /* If OID doesn't match any pg_class entry, return it numerically */
1019  result = (char *) palloc(NAMEDATALEN);
1020  snprintf(result, NAMEDATALEN, "%u", classid);
1021  }
1022 
1023  PG_RETURN_CSTRING(result);
1024 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
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:3155
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10808
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:356
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
void * palloc(Size size)
Definition: mcxt.c:949
bool RelationIsVisible(Oid relid)
Definition: namespace.c:708
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ regclassrecv()

Datum regclassrecv ( PG_FUNCTION_ARGS  )

Definition at line 1030 of file regproc.c.

References oidrecv().

1031 {
1032  /* Exactly the same as oidrecv, so share code */
1033  return oidrecv(fcinfo);
1034 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regclasssend()

Datum regclasssend ( PG_FUNCTION_ARGS  )

Definition at line 1040 of file regproc.c.

References oidsend().

1041 {
1042  /* Exactly the same as oidsend, so share code */
1043  return oidsend(fcinfo);
1044 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regcollationin()

Datum regcollationin ( PG_FUNCTION_ARGS  )

Definition at line 1056 of file regproc.c.

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

1057 {
1058  char *collation_name_or_oid = PG_GETARG_CSTRING(0);
1059  Oid result = InvalidOid;
1060  List *names;
1061 
1062  /* '-' ? */
1063  if (strcmp(collation_name_or_oid, "-") == 0)
1065 
1066  /* Numeric OID? */
1067  if (collation_name_or_oid[0] >= '0' &&
1068  collation_name_or_oid[0] <= '9' &&
1069  strspn(collation_name_or_oid, "0123456789") == strlen(collation_name_or_oid))
1070  {
1072  CStringGetDatum(collation_name_or_oid)));
1073  PG_RETURN_OID(result);
1074  }
1075 
1076  /* Else it's a name, possibly schema-qualified */
1077 
1078  /* The rest of this wouldn't work in bootstrap mode */
1080  elog(ERROR, "regcollation values must be OIDs in bootstrap mode");
1081 
1082  /*
1083  * Normal case: parse the name into components and see if it matches any
1084  * pg_collation entries in the current search path.
1085  */
1086  names = stringToQualifiedNameList(collation_name_or_oid);
1087 
1088  result = get_collation_oid(names, false);
1089 
1090  PG_RETURN_OID(result);
1091 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
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:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3601
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regcollationout()

Datum regcollationout ( PG_FUNCTION_ARGS  )

Definition at line 1124 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.

1125 {
1126  Oid collationid = PG_GETARG_OID(0);
1127  char *result;
1128  HeapTuple collationtup;
1129 
1130  if (collationid == InvalidOid)
1131  {
1132  result = pstrdup("-");
1133  PG_RETURN_CSTRING(result);
1134  }
1135 
1136  collationtup = SearchSysCache1(COLLOID, ObjectIdGetDatum(collationid));
1137 
1138  if (HeapTupleIsValid(collationtup))
1139  {
1140  Form_pg_collation collationform = (Form_pg_collation) GETSTRUCT(collationtup);
1141  char *collationname = NameStr(collationform->collname);
1142 
1143  /*
1144  * In bootstrap mode, skip the fancy namespace stuff and just return
1145  * the collation name. (This path is only needed for debugging output
1146  * anyway.)
1147  */
1149  result = pstrdup(collationname);
1150  else
1151  {
1152  char *nspname;
1153 
1154  /*
1155  * Would this collation be found by regcollationin? If not, qualify it.
1156  */
1157  if (CollationIsVisible(collationid))
1158  nspname = NULL;
1159  else
1160  nspname = get_namespace_name(collationform->collnamespace);
1161 
1162  result = quote_qualified_identifier(nspname, collationname);
1163  }
1164 
1165  ReleaseSysCache(collationtup);
1166  }
1167  else
1168  {
1169  /* If OID doesn't match any pg_collation entry, return it numerically */
1170  result = (char *) palloc(NAMEDATALEN);
1171  snprintf(result, NAMEDATALEN, "%u", collationid);
1172  }
1173 
1174  PG_RETURN_CSTRING(result);
1175 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
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:3155
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2048
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10808
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:356
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ regcollationrecv()

Datum regcollationrecv ( PG_FUNCTION_ARGS  )

Definition at line 1181 of file regproc.c.

References oidrecv().

1182 {
1183  /* Exactly the same as oidrecv, so share code */
1184  return oidrecv(fcinfo);
1185 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regcollationsend()

Datum regcollationsend ( PG_FUNCTION_ARGS  )

Definition at line 1191 of file regproc.c.

References oidsend().

1192 {
1193  /* Exactly the same as oidsend, so share code */
1194  return oidsend(fcinfo);
1195 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regconfigin()

Datum regconfigin ( PG_FUNCTION_ARGS  )

Definition at line 1349 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().

1350 {
1351  char *cfg_name_or_oid = PG_GETARG_CSTRING(0);
1352  Oid result;
1353  List *names;
1354 
1355  /* '-' ? */
1356  if (strcmp(cfg_name_or_oid, "-") == 0)
1358 
1359  /* Numeric OID? */
1360  if (cfg_name_or_oid[0] >= '0' &&
1361  cfg_name_or_oid[0] <= '9' &&
1362  strspn(cfg_name_or_oid, "0123456789") == strlen(cfg_name_or_oid))
1363  {
1365  CStringGetDatum(cfg_name_or_oid)));
1366  PG_RETURN_OID(result);
1367  }
1368 
1369  /* The rest of this wouldn't work in bootstrap mode */
1371  elog(ERROR, "regconfig values must be OIDs in bootstrap mode");
1372 
1373  /*
1374  * Normal case: parse the name into components and see if it matches any
1375  * pg_ts_config entries in the current search path.
1376  */
1377  names = stringToQualifiedNameList(cfg_name_or_oid);
1378 
1379  result = get_ts_config_oid(names, false);
1380 
1381  PG_RETURN_OID(result);
1382 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2679
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
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:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regconfigout()

Datum regconfigout ( PG_FUNCTION_ARGS  )

Definition at line 1388 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.

1389 {
1390  Oid cfgid = PG_GETARG_OID(0);
1391  char *result;
1392  HeapTuple cfgtup;
1393 
1394  if (cfgid == InvalidOid)
1395  {
1396  result = pstrdup("-");
1397  PG_RETURN_CSTRING(result);
1398  }
1399 
1400  cfgtup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgid));
1401 
1402  if (HeapTupleIsValid(cfgtup))
1403  {
1404  Form_pg_ts_config cfgform = (Form_pg_ts_config) GETSTRUCT(cfgtup);
1405  char *cfgname = NameStr(cfgform->cfgname);
1406  char *nspname;
1407 
1408  /*
1409  * Would this config be found by regconfigin? If not, qualify it.
1410  */
1411  if (TSConfigIsVisible(cfgid))
1412  nspname = NULL;
1413  else
1414  nspname = get_namespace_name(cfgform->cfgnamespace);
1415 
1416  result = quote_qualified_identifier(nspname, cfgname);
1417 
1418  ReleaseSysCache(cfgtup);
1419  }
1420  else
1421  {
1422  /* If OID doesn't match any pg_ts_config row, return it numerically */
1423  result = (char *) palloc(NAMEDATALEN);
1424  snprintf(result, NAMEDATALEN, "%u", cfgid);
1425  }
1426 
1427  PG_RETURN_CSTRING(result);
1428 }
#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:1186
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2737
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3155
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10808
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:356
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ regconfigrecv()

Datum regconfigrecv ( PG_FUNCTION_ARGS  )

Definition at line 1434 of file regproc.c.

References oidrecv().

1435 {
1436  /* Exactly the same as oidrecv, so share code */
1437  return oidrecv(fcinfo);
1438 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regconfigsend()

Datum regconfigsend ( PG_FUNCTION_ARGS  )

Definition at line 1444 of file regproc.c.

References oidsend().

1445 {
1446  /* Exactly the same as oidsend, so share code */
1447  return oidsend(fcinfo);
1448 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regdictionaryin()

Datum regdictionaryin ( PG_FUNCTION_ARGS  )

Definition at line 1460 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().

1461 {
1462  char *dict_name_or_oid = PG_GETARG_CSTRING(0);
1463  Oid result;
1464  List *names;
1465 
1466  /* '-' ? */
1467  if (strcmp(dict_name_or_oid, "-") == 0)
1469 
1470  /* Numeric OID? */
1471  if (dict_name_or_oid[0] >= '0' &&
1472  dict_name_or_oid[0] <= '9' &&
1473  strspn(dict_name_or_oid, "0123456789") == strlen(dict_name_or_oid))
1474  {
1476  CStringGetDatum(dict_name_or_oid)));
1477  PG_RETURN_OID(result);
1478  }
1479 
1480  /* The rest of this wouldn't work in bootstrap mode */
1482  elog(ERROR, "regdictionary values must be OIDs in bootstrap mode");
1483 
1484  /*
1485  * Normal case: parse the name into components and see if it matches any
1486  * pg_ts_dict entries in the current search path.
1487  */
1488  names = stringToQualifiedNameList(dict_name_or_oid);
1489 
1490  result = get_ts_dict_oid(names, false);
1491 
1492  PG_RETURN_OID(result);
1493 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2426
#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:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regdictionaryout()

Datum regdictionaryout ( PG_FUNCTION_ARGS  )

Definition at line 1499 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.

1500 {
1501  Oid dictid = PG_GETARG_OID(0);
1502  char *result;
1503  HeapTuple dicttup;
1504 
1505  if (dictid == InvalidOid)
1506  {
1507  result = pstrdup("-");
1508  PG_RETURN_CSTRING(result);
1509  }
1510 
1511  dicttup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictid));
1512 
1513  if (HeapTupleIsValid(dicttup))
1514  {
1515  Form_pg_ts_dict dictform = (Form_pg_ts_dict) GETSTRUCT(dicttup);
1516  char *dictname = NameStr(dictform->dictname);
1517  char *nspname;
1518 
1519  /*
1520  * Would this dictionary be found by regdictionaryin? If not, qualify
1521  * it.
1522  */
1523  if (TSDictionaryIsVisible(dictid))
1524  nspname = NULL;
1525  else
1526  nspname = get_namespace_name(dictform->dictnamespace);
1527 
1528  result = quote_qualified_identifier(nspname, dictname);
1529 
1530  ReleaseSysCache(dicttup);
1531  }
1532  else
1533  {
1534  /* If OID doesn't match any pg_ts_dict row, return it numerically */
1535  result = (char *) palloc(NAMEDATALEN);
1536  snprintf(result, NAMEDATALEN, "%u", dictid);
1537  }
1538 
1539  PG_RETURN_CSTRING(result);
1540 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
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:3155
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2484
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10808
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:356
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ regdictionaryrecv()

Datum regdictionaryrecv ( PG_FUNCTION_ARGS  )

Definition at line 1546 of file regproc.c.

References oidrecv().

1547 {
1548  /* Exactly the same as oidrecv, so share code */
1549  return oidrecv(fcinfo);
1550 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regdictionarysend()

Datum regdictionarysend ( PG_FUNCTION_ARGS  )

Definition at line 1556 of file regproc.c.

References oidsend().

1557 {
1558  /* Exactly the same as oidsend, so share code */
1559  return oidsend(fcinfo);
1560 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regnamespacein()

Datum regnamespacein ( PG_FUNCTION_ARGS  )

Definition at line 1696 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.

1697 {
1698  char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
1699  Oid result;
1700  List *names;
1701 
1702  /* '-' ? */
1703  if (strcmp(nsp_name_or_oid, "-") == 0)
1705 
1706  /* Numeric OID? */
1707  if (nsp_name_or_oid[0] >= '0' &&
1708  nsp_name_or_oid[0] <= '9' &&
1709  strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
1710  {
1712  CStringGetDatum(nsp_name_or_oid)));
1713  PG_RETURN_OID(result);
1714  }
1715 
1716  /* The rest of this wouldn't work in bootstrap mode */
1718  elog(ERROR, "regnamespace values must be OIDs in bootstrap mode");
1719 
1720  /* Normal case: see if the name matches any pg_namespace entry. */
1721  names = stringToQualifiedNameList(nsp_name_or_oid);
1722 
1723  if (list_length(names) != 1)
1724  ereport(ERROR,
1725  (errcode(ERRCODE_INVALID_NAME),
1726  errmsg("invalid name syntax")));
1727 
1728  result = get_namespace_oid(strVal(linitial(names)), false);
1729 
1730  PG_RETURN_OID(result);
1731 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3043
#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:619
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:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regnamespaceout()

Datum regnamespaceout ( PG_FUNCTION_ARGS  )

Definition at line 1764 of file regproc.c.

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

1765 {
1766  Oid nspid = PG_GETARG_OID(0);
1767  char *result;
1768 
1769  if (nspid == InvalidOid)
1770  {
1771  result = pstrdup("-");
1772  PG_RETURN_CSTRING(result);
1773  }
1774 
1775  result = get_namespace_name(nspid);
1776 
1777  if (result)
1778  {
1779  /* pstrdup is not really necessary, but it avoids a compiler warning */
1780  result = pstrdup(quote_identifier(result));
1781  }
1782  else
1783  {
1784  /* If OID doesn't match any namespace, return it numerically */
1785  result = (char *) palloc(NAMEDATALEN);
1786  snprintf(result, NAMEDATALEN, "%u", nspid);
1787  }
1788 
1789  PG_RETURN_CSTRING(result);
1790 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10724
char * pstrdup(const char *in)
Definition: mcxt.c:1186
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3155
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:356
void * palloc(Size size)
Definition: mcxt.c:949
#define snprintf
Definition: port.h:192

◆ regnamespacerecv()

Datum regnamespacerecv ( PG_FUNCTION_ARGS  )

Definition at line 1796 of file regproc.c.

References oidrecv().

1797 {
1798  /* Exactly the same as oidrecv, so share code */
1799  return oidrecv(fcinfo);
1800 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regnamespacesend()

Datum regnamespacesend ( PG_FUNCTION_ARGS  )

Definition at line 1806 of file regproc.c.

References oidsend().

1807 {
1808  /* Exactly the same as oidsend, so share code */
1809  return oidsend(fcinfo);
1810 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regoperatorin()

Datum regoperatorin ( PG_FUNCTION_ARGS  )

Definition at line 656 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.

657 {
658  char *opr_name_or_oid = PG_GETARG_CSTRING(0);
659  Oid result;
660  List *names;
661  int nargs;
662  Oid argtypes[FUNC_MAX_ARGS];
663 
664  /* '0' ? */
665  if (strcmp(opr_name_or_oid, "0") == 0)
667 
668  /* Numeric OID? */
669  if (opr_name_or_oid[0] >= '0' &&
670  opr_name_or_oid[0] <= '9' &&
671  strspn(opr_name_or_oid, "0123456789") == strlen(opr_name_or_oid))
672  {
674  CStringGetDatum(opr_name_or_oid)));
675  PG_RETURN_OID(result);
676  }
677 
678  /* The rest of this wouldn't work in bootstrap mode */
680  elog(ERROR, "regoperator values must be OIDs in bootstrap mode");
681 
682  /*
683  * Else it's a name and arguments. Parse the name and arguments, look up
684  * potential matches in the current namespace search list, and scan to see
685  * which one exactly matches the given argument types. (There will not be
686  * more than one match.)
687  */
688  parseNameAndArgTypes(opr_name_or_oid, true, &names, &nargs, argtypes);
689  if (nargs == 1)
690  ereport(ERROR,
691  (errcode(ERRCODE_UNDEFINED_PARAMETER),
692  errmsg("missing argument"),
693  errhint("Use NONE to denote the missing argument of a unary operator.")));
694  if (nargs != 2)
695  ereport(ERROR,
696  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
697  errmsg("too many arguments"),
698  errhint("Provide two argument types for operator.")));
699 
700  result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
701 
702  if (!OidIsValid(result))
703  ereport(ERROR,
704  (errcode(ERRCODE_UNDEFINED_FUNCTION),
705  errmsg("operator does not exist: %s", opr_name_or_oid)));
706 
707  PG_RETURN_OID(result);
708 }
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:619
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
#define FUNC_MAX_ARGS
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1484
#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:1887
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regoperatorout()

Datum regoperatorout ( PG_FUNCTION_ARGS  )

Definition at line 861 of file regproc.c.

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

862 {
863  Oid oprid = PG_GETARG_OID(0);
864  char *result;
865 
866  if (oprid == InvalidOid)
867  result = pstrdup("0");
868  else
869  result = format_operator(oprid);
870 
871  PG_RETURN_CSTRING(result);
872 }
Oid oprid(Operator op)
Definition: parse_oper.c:245
char * pstrdup(const char *in)
Definition: mcxt.c:1186
char * format_operator(Oid operator_oid)
Definition: regproc.c:821
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:356

◆ regoperatorrecv()

Datum regoperatorrecv ( PG_FUNCTION_ARGS  )

Definition at line 878 of file regproc.c.

References oidrecv().

879 {
880  /* Exactly the same as oidrecv, so share code */
881  return oidrecv(fcinfo);
882 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regoperatorsend()

Datum regoperatorsend ( PG_FUNCTION_ARGS  )

Definition at line 888 of file regproc.c.

References oidsend().

889 {
890  /* Exactly the same as oidsend, so share code */
891  return oidsend(fcinfo);
892 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regoperin()

Datum regoperin ( PG_FUNCTION_ARGS  )

Definition at line 484 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().

485 {
486  char *opr_name_or_oid = PG_GETARG_CSTRING(0);
487  Oid result = InvalidOid;
488  List *names;
489  FuncCandidateList clist;
490 
491  /* '0' ? */
492  if (strcmp(opr_name_or_oid, "0") == 0)
494 
495  /* Numeric OID? */
496  if (opr_name_or_oid[0] >= '0' &&
497  opr_name_or_oid[0] <= '9' &&
498  strspn(opr_name_or_oid, "0123456789") == strlen(opr_name_or_oid))
499  {
501  CStringGetDatum(opr_name_or_oid)));
502  PG_RETURN_OID(result);
503  }
504 
505  /* Else it's a name, possibly schema-qualified */
506 
507  /* The rest of this wouldn't work in bootstrap mode */
509  elog(ERROR, "regoper values must be OIDs in bootstrap mode");
510 
511  /*
512  * Normal case: parse the name into components and see if it matches any
513  * pg_operator entries in the current search path.
514  */
515  names = stringToQualifiedNameList(opr_name_or_oid);
516  clist = OpernameGetCandidates(names, '\0', false);
517 
518  if (clist == NULL)
519  ereport(ERROR,
520  (errcode(ERRCODE_UNDEFINED_FUNCTION),
521  errmsg("operator does not exist: %s", opr_name_or_oid)));
522  else if (clist->next != NULL)
523  ereport(ERROR,
524  (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
525  errmsg("more than one operator named %s",
526  opr_name_or_oid)));
527 
528  result = clist->oid;
529 
530  PG_RETURN_OID(result);
531 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
int errcode(int sqlerrcode)
Definition: elog.c:610
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
unsigned int Oid
Definition: postgres_ext.h:31
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1587
#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:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regoperout()

Datum regoperout ( PG_FUNCTION_ARGS  )

Definition at line 562 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.

563 {
564  Oid oprid = PG_GETARG_OID(0);
565  char *result;
566  HeapTuple opertup;
567 
568  if (oprid == InvalidOid)
569  {
570  result = pstrdup("0");
571  PG_RETURN_CSTRING(result);
572  }
573 
574  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(oprid));
575 
576  if (HeapTupleIsValid(opertup))
577  {
578  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
579  char *oprname = NameStr(operform->oprname);
580 
581  /*
582  * In bootstrap mode, skip the fancy namespace stuff and just return
583  * the oper name. (This path is only needed for debugging output
584  * anyway.)
585  */
587  result = pstrdup(oprname);
588  else
589  {
590  FuncCandidateList clist;
591 
592  /*
593  * Would this oper be found (uniquely!) by regoperin? If not,
594  * qualify it.
595  */
596  clist = OpernameGetCandidates(list_make1(makeString(oprname)),
597  '\0', false);
598  if (clist != NULL && clist->next == NULL &&
599  clist->oid == oprid)
600  result = pstrdup(oprname);
601  else
602  {
603  const char *nspname;
604 
605  nspname = get_namespace_name(operform->oprnamespace);
606  nspname = quote_identifier(nspname);
607  result = (char *) palloc(strlen(nspname) + strlen(oprname) + 2);
608  sprintf(result, "%s.%s", nspname, oprname);
609  }
610  }
611 
612  ReleaseSysCache(opertup);
613  }
614  else
615  {
616  /*
617  * If OID doesn't match any pg_operator entry, return it numerically
618  */
619  result = (char *) palloc(NAMEDATALEN);
620  snprintf(result, NAMEDATALEN, "%u", oprid);
621  }
622 
623  PG_RETURN_CSTRING(result);
624 }
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:10724
Oid oprid(Operator op)
Definition: parse_oper.c:245
char * pstrdup(const char *in)
Definition: mcxt.c:1186
unsigned int Oid
Definition: postgres_ext.h:31
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1587
#define list_make1(x1)
Definition: pg_list.h:227
#define NAMEDATALEN
#define sprintf
Definition: port.h:194
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3155
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
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:356
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ regoperrecv()

Datum regoperrecv ( PG_FUNCTION_ARGS  )

Definition at line 630 of file regproc.c.

References oidrecv().

631 {
632  /* Exactly the same as oidrecv, so share code */
633  return oidrecv(fcinfo);
634 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regopersend()

Datum regopersend ( PG_FUNCTION_ARGS  )

Definition at line 640 of file regproc.c.

References oidsend().

641 {
642  /* Exactly the same as oidsend, so share code */
643  return oidsend(fcinfo);
644 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regprocedurein()

Datum regprocedurein ( PG_FUNCTION_ARGS  )

Definition at line 232 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().

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

◆ regprocedureout()

Datum regprocedureout ( PG_FUNCTION_ARGS  )

Definition at line 441 of file regproc.c.

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

442 {
443  RegProcedure proid = PG_GETARG_OID(0);
444  char *result;
445 
446  if (proid == InvalidOid)
447  result = pstrdup("-");
448  else
449  result = format_procedure(proid);
450 
451  PG_RETURN_CSTRING(result);
452 }
char * pstrdup(const char *in)
Definition: mcxt.c:1186
regproc RegProcedure
Definition: c.h:511
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define InvalidOid
Definition: postgres_ext.h:36
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:324
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:356

◆ regprocedurerecv()

Datum regprocedurerecv ( PG_FUNCTION_ARGS  )

Definition at line 458 of file regproc.c.

References oidrecv().

459 {
460  /* Exactly the same as oidrecv, so share code */
461  return oidrecv(fcinfo);
462 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regproceduresend()

Datum regproceduresend ( PG_FUNCTION_ARGS  )

Definition at line 468 of file regproc.c.

References oidsend().

469 {
470  /* Exactly the same as oidsend, so share code */
471  return oidsend(fcinfo);
472 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regprocin()

Datum regprocin ( PG_FUNCTION_ARGS  )

Definition at line 63 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().

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

◆ regprocout()

Datum regprocout ( PG_FUNCTION_ARGS  )

Definition at line 144 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.

145 {
146  RegProcedure proid = PG_GETARG_OID(0);
147  char *result;
148  HeapTuple proctup;
149 
150  if (proid == InvalidOid)
151  {
152  result = pstrdup("-");
153  PG_RETURN_CSTRING(result);
154  }
155 
156  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(proid));
157 
158  if (HeapTupleIsValid(proctup))
159  {
160  Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
161  char *proname = NameStr(procform->proname);
162 
163  /*
164  * In bootstrap mode, skip the fancy namespace stuff and just return
165  * the proc name. (This path is only needed for debugging output
166  * anyway.)
167  */
169  result = pstrdup(proname);
170  else
171  {
172  char *nspname;
173  FuncCandidateList clist;
174 
175  /*
176  * Would this proc be found (uniquely!) by regprocin? If not,
177  * qualify it.
178  */
179  clist = FuncnameGetCandidates(list_make1(makeString(proname)),
180  -1, NIL, false, false, false);
181  if (clist != NULL && clist->next == NULL &&
182  clist->oid == proid)
183  nspname = NULL;
184  else
185  nspname = get_namespace_name(procform->pronamespace);
186 
187  result = quote_qualified_identifier(nspname, proname);
188  }
189 
190  ReleaseSysCache(proctup);
191  }
192  else
193  {
194  /* If OID doesn't match any pg_proc entry, return it numerically */
195  result = (char *) palloc(NAMEDATALEN);
196  snprintf(result, NAMEDATALEN, "%u", proid);
197  }
198 
199  PG_RETURN_CSTRING(result);
200 }
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:1186
regproc RegProcedure
Definition: c.h:511
#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:3155
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
struct _FuncCandidateList * next
Definition: namespace.h:30
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10808
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:356
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ regprocrecv()

Datum regprocrecv ( PG_FUNCTION_ARGS  )

Definition at line 206 of file regproc.c.

References oidrecv().

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

◆ regprocsend()

Datum regprocsend ( PG_FUNCTION_ARGS  )

Definition at line 216 of file regproc.c.

References oidsend().

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

◆ regrolein()

Datum regrolein ( PG_FUNCTION_ARGS  )

Definition at line 1571 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.

1572 {
1573  char *role_name_or_oid = PG_GETARG_CSTRING(0);
1574  Oid result;
1575  List *names;
1576 
1577  /* '-' ? */
1578  if (strcmp(role_name_or_oid, "-") == 0)
1580 
1581  /* Numeric OID? */
1582  if (role_name_or_oid[0] >= '0' &&
1583  role_name_or_oid[0] <= '9' &&
1584  strspn(role_name_or_oid, "0123456789") == strlen(role_name_or_oid))
1585  {
1587  CStringGetDatum(role_name_or_oid)));
1588  PG_RETURN_OID(result);
1589  }
1590 
1591  /* The rest of this wouldn't work in bootstrap mode */
1593  elog(ERROR, "regrole values must be OIDs in bootstrap mode");
1594 
1595  /* Normal case: see if the name matches any pg_authid entry. */
1596  names = stringToQualifiedNameList(role_name_or_oid);
1597 
1598  if (list_length(names) != 1)
1599  ereport(ERROR,
1600  (errcode(ERRCODE_INVALID_NAME),
1601  errmsg("invalid name syntax")));
1602 
1603  result = get_role_oid(strVal(linitial(names)), false);
1604 
1605  PG_RETURN_OID(result);
1606 }
#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:619
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5183
#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:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regroleout()

Datum regroleout ( PG_FUNCTION_ARGS  )

Definition at line 1639 of file regproc.c.

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

1640 {
1641  Oid roleoid = PG_GETARG_OID(0);
1642  char *result;
1643 
1644  if (roleoid == InvalidOid)
1645  {
1646  result = pstrdup("-");
1647  PG_RETURN_CSTRING(result);
1648  }
1649 
1650  result = GetUserNameFromId(roleoid, true);
1651 
1652  if (result)
1653  {
1654  /* pstrdup is not really necessary, but it avoids a compiler warning */
1655  result = pstrdup(quote_identifier(result));
1656  }
1657  else
1658  {
1659  /* If OID doesn't match any role, return it numerically */
1660  result = (char *) palloc(NAMEDATALEN);
1661  snprintf(result, NAMEDATALEN, "%u", roleoid);
1662  }
1663 
1664  PG_RETURN_CSTRING(result);
1665 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10724
char * pstrdup(const char *in)
Definition: mcxt.c:1186
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define InvalidOid
Definition: postgres_ext.h:36
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:854
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:356
void * palloc(Size size)
Definition: mcxt.c:949
#define snprintf
Definition: port.h:192

◆ regrolerecv()

Datum regrolerecv ( PG_FUNCTION_ARGS  )

Definition at line 1671 of file regproc.c.

References oidrecv().

1672 {
1673  /* Exactly the same as oidrecv, so share code */
1674  return oidrecv(fcinfo);
1675 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regrolesend()

Datum regrolesend ( PG_FUNCTION_ARGS  )

Definition at line 1681 of file regproc.c.

References oidsend().

1682 {
1683  /* Exactly the same as oidsend, so share code */
1684  return oidsend(fcinfo);
1685 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ regtypein()

Datum regtypein ( PG_FUNCTION_ARGS  )

Definition at line 1213 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().

1214 {
1215  char *typ_name_or_oid = PG_GETARG_CSTRING(0);
1216  Oid result = InvalidOid;
1217  int32 typmod;
1218 
1219  /* '-' ? */
1220  if (strcmp(typ_name_or_oid, "-") == 0)
1222 
1223  /* Numeric OID? */
1224  if (typ_name_or_oid[0] >= '0' &&
1225  typ_name_or_oid[0] <= '9' &&
1226  strspn(typ_name_or_oid, "0123456789") == strlen(typ_name_or_oid))
1227  {
1229  CStringGetDatum(typ_name_or_oid)));
1230  PG_RETURN_OID(result);
1231  }
1232 
1233  /* Else it's a type name, possibly schema-qualified or decorated */
1234 
1235  /* The rest of this wouldn't work in bootstrap mode */
1237  elog(ERROR, "regtype values must be OIDs in bootstrap mode");
1238 
1239  /*
1240  * Normal case: invoke the full parser to deal with special cases such as
1241  * array syntax.
1242  */
1243  parseTypeString(typ_name_or_oid, &result, &typmod, false);
1244 
1245  PG_RETURN_OID(result);
1246 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:355
#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:392
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ regtypeout()

Datum regtypeout ( PG_FUNCTION_ARGS  )

Definition at line 1275 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.

1276 {
1277  Oid typid = PG_GETARG_OID(0);
1278  char *result;
1279  HeapTuple typetup;
1280 
1281  if (typid == InvalidOid)
1282  {
1283  result = pstrdup("-");
1284  PG_RETURN_CSTRING(result);
1285  }
1286 
1287  typetup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid));
1288 
1289  if (HeapTupleIsValid(typetup))
1290  {
1291  Form_pg_type typeform = (Form_pg_type) GETSTRUCT(typetup);
1292 
1293  /*
1294  * In bootstrap mode, skip the fancy namespace stuff and just return
1295  * the type name. (This path is only needed for debugging output
1296  * anyway.)
1297  */
1299  {
1300  char *typname = NameStr(typeform->typname);
1301 
1302  result = pstrdup(typname);
1303  }
1304  else
1305  result = format_type_be(typid);
1306 
1307  ReleaseSysCache(typetup);
1308  }
1309  else
1310  {
1311  /* If OID doesn't match any pg_type entry, return it numerically */
1312  result = (char *) palloc(NAMEDATALEN);
1313  snprintf(result, NAMEDATALEN, "%u", typid);
1314  }
1315 
1316  PG_RETURN_CSTRING(result);
1317 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
char * format_type_be(Oid type_oid)
Definition: format_type.c:327
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:270
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:356
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:192

◆ regtyperecv()

Datum regtyperecv ( PG_FUNCTION_ARGS  )

Definition at line 1323 of file regproc.c.

References oidrecv().

1324 {
1325  /* Exactly the same as oidrecv, so share code */
1326  return oidrecv(fcinfo);
1327 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140

◆ regtypesend()

Datum regtypesend ( PG_FUNCTION_ARGS  )

Definition at line 1333 of file regproc.c.

References oidsend().

1334 {
1335  /* Exactly the same as oidsend, so share code */
1336  return oidsend(fcinfo);
1337 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151

◆ stringToQualifiedNameList()

List* stringToQualifiedNameList ( const char *  string)

Definition at line 1839 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().

1840 {
1841  char *rawname;
1842  List *result = NIL;
1843  List *namelist;
1844  ListCell *l;
1845 
1846  /* We need a modifiable copy of the input string. */
1847  rawname = pstrdup(string);
1848 
1849  if (!SplitIdentifierString(rawname, '.', &namelist))
1850  ereport(ERROR,
1851  (errcode(ERRCODE_INVALID_NAME),
1852  errmsg("invalid name syntax")));
1853 
1854  if (namelist == NIL)
1855  ereport(ERROR,
1856  (errcode(ERRCODE_INVALID_NAME),
1857  errmsg("invalid name syntax")));
1858 
1859  foreach(l, namelist)
1860  {
1861  char *curname = (char *) lfirst(l);
1862 
1863  result = lappend(result, makeString(pstrdup(curname)));
1864  }
1865 
1866  pfree(rawname);
1867  list_free(namelist);
1868 
1869  return result;
1870 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1186
int errcode(int sqlerrcode)
Definition: elog.c:610
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3672
List * lappend(List *list, void *datum)
Definition: list.c:322
#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:1377
Definition: pg_list.h:50

◆ text_regclass()

Datum text_regclass ( PG_FUNCTION_ARGS  )

Definition at line 1820 of file regproc.c.

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

1821 {
1823  Oid result;
1824  RangeVar *rv;
1825 
1827 
1828  /* We might not even have permissions on this relation; don't lock it. */
1829  result = RangeVarGetRelid(rv, NoLock, false);
1830 
1831  PG_RETURN_OID(result);
1832 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:78
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define NoLock
Definition: lockdefs.h:34
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3614
Definition: c.h:555
#define PG_RETURN_OID(x)
Definition: fmgr.h:354

◆ to_regclass()

Datum to_regclass ( PG_FUNCTION_ARGS  )

Definition at line 948 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().

949 {
951  Oid result;
952  List *names;
953 
954  /*
955  * Parse the name into components and see if it matches any pg_class
956  * entries in the current search path.
957  */
958  names = stringToQualifiedNameList(class_name);
959 
960  /* We might not even have permissions on this relation; don't lock it. */
961  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, true);
962 
963  if (OidIsValid(result))
964  PG_RETURN_OID(result);
965  else
966  PG_RETURN_NULL();
967 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:78
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define NoLock
Definition: lockdefs.h:34
const char * class_name
Definition: selinux.c:32
char * text_to_cstring(const text *t)
Definition: varlena.c:204
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339

◆ to_regcollation()

Datum to_regcollation ( PG_FUNCTION_ARGS  )

Definition at line 1099 of file regproc.c.

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

1100 {
1101  char *collation_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1102  Oid result;
1103  List *names;
1104 
1105  /*
1106  * Parse the name into components and see if it matches any pg_collation
1107  * entries in the current search path.
1108  */
1109  names = stringToQualifiedNameList(collation_name);
1110 
1111  /* We might not even have permissions on this relation; don't lock it. */
1112  result = get_collation_oid(names, true);
1113 
1114  if (OidIsValid(result))
1115  PG_RETURN_OID(result);
1116  else
1117  PG_RETURN_NULL();
1118 }
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
char * text_to_cstring(const text *t)
Definition: varlena.c:204
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3601
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339

◆ to_regnamespace()

Datum to_regnamespace ( PG_FUNCTION_ARGS  )

Definition at line 1739 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().

1740 {
1741  char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1742  Oid result;
1743  List *names;
1744 
1745  names = stringToQualifiedNameList(nsp_name);
1746 
1747  if (list_length(names) != 1)
1748  ereport(ERROR,
1749  (errcode(ERRCODE_INVALID_NAME),
1750  errmsg("invalid name syntax")));
1751 
1752  result = get_namespace_oid(strVal(linitial(names)), true);
1753 
1754  if (OidIsValid(result))
1755  PG_RETURN_OID(result);
1756  else
1757  PG_RETURN_NULL();
1758 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3043
#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:644
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#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:204
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339

◆ to_regoper()

Datum to_regoper ( PG_FUNCTION_ARGS  )

Definition at line 539 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().

540 {
541  char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
542  List *names;
543  FuncCandidateList clist;
544 
545  /*
546  * Parse the name into components and see if it matches any pg_operator
547  * entries in the current search path.
548  */
549  names = stringToQualifiedNameList(opr_name);
550  clist = OpernameGetCandidates(names, '\0', true);
551 
552  if (clist == NULL || clist->next != NULL)
553  PG_RETURN_NULL();
554 
555  PG_RETURN_OID(clist->oid);
556 }
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1587
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
struct _FuncCandidateList * next
Definition: namespace.h:30
char * text_to_cstring(const text *t)
Definition: varlena.c:204
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339

◆ to_regoperator()

Datum to_regoperator ( PG_FUNCTION_ARGS  )

Definition at line 716 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().

717 {
718  char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
719  Oid result;
720  List *names;
721  int nargs;
722  Oid argtypes[FUNC_MAX_ARGS];
723 
724  /*
725  * Parse the name and arguments, look up potential matches in the current
726  * namespace search list, and scan to see which one exactly matches the
727  * given argument types. (There will not be more than one match.)
728  */
729  parseNameAndArgTypes(opr_name_or_oid, true, &names, &nargs, argtypes);
730  if (nargs == 1)
731  ereport(ERROR,
732  (errcode(ERRCODE_UNDEFINED_PARAMETER),
733  errmsg("missing argument"),
734  errhint("Use NONE to denote the missing argument of a unary operator.")));
735  if (nargs != 2)
736  ereport(ERROR,
737  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
738  errmsg("too many arguments"),
739  errhint("Provide two argument types for operator.")));
740 
741  result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
742 
743  if (!OidIsValid(result))
744  PG_RETURN_NULL();
745 
746  PG_RETURN_OID(result);
747 }
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:644
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define FUNC_MAX_ARGS
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1484
#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:1887
char * text_to_cstring(const text *t)
Definition: varlena.c:204
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339

◆ to_regproc()

Datum to_regproc ( PG_FUNCTION_ARGS  )

Definition at line 121 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().

122 {
123  char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
124  List *names;
125  FuncCandidateList clist;
126 
127  /*
128  * Parse the name into components and see if it matches any pg_proc
129  * entries in the current search path.
130  */
131  names = stringToQualifiedNameList(pro_name);
132  clist = FuncnameGetCandidates(names, -1, NIL, false, false, true);
133 
134  if (clist == NULL || clist->next != NULL)
135  PG_RETURN_NULL();
136 
137  PG_RETURN_OID(clist->oid);
138 }
#define NIL
Definition: pg_list.h:65
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
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:204
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339

◆ to_regprocedure()

Datum to_regprocedure ( PG_FUNCTION_ARGS  )

Definition at line 291 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().

292 {
293  char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
294  List *names;
295  int nargs;
296  Oid argtypes[FUNC_MAX_ARGS];
297  FuncCandidateList clist;
298 
299  /*
300  * Parse the name and arguments, look up potential matches in the current
301  * namespace search list, and scan to see which one exactly matches the
302  * given argument types. (There will not be more than one match.)
303  */
304  parseNameAndArgTypes(pro_name, false, &names, &nargs, argtypes);
305 
306  clist = FuncnameGetCandidates(names, nargs, NIL, false, false, true);
307 
308  for (; clist; clist = clist->next)
309  {
310  if (memcmp(clist->args, argtypes, nargs * sizeof(Oid)) == 0)
311  PG_RETURN_OID(clist->oid);
312  }
313 
314  PG_RETURN_NULL();
315 }
#define NIL
Definition: pg_list.h:65
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#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:1887
char * text_to_cstring(const text *t)
Definition: varlena.c:204
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339

◆ to_regrole()

Datum to_regrole ( PG_FUNCTION_ARGS  )

Definition at line 1614 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().

1615 {
1616  char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1617  Oid result;
1618  List *names;
1619 
1620  names = stringToQualifiedNameList(role_name);
1621 
1622  if (list_length(names) != 1)
1623  ereport(ERROR,
1624  (errcode(ERRCODE_INVALID_NAME),
1625  errmsg("invalid name syntax")));
1626 
1627  result = get_role_oid(strVal(linitial(names)), true);
1628 
1629  if (OidIsValid(result))
1630  PG_RETURN_OID(result);
1631  else
1632  PG_RETURN_NULL();
1633 }
#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:644
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5183
#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:204
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1839
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339

◆ to_regtype()

Datum to_regtype ( PG_FUNCTION_ARGS  )

Definition at line 1254 of file regproc.c.

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

1255 {
1256  char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1257  Oid result;
1258  int32 typmod;
1259 
1260  /*
1261  * Invoke the full parser to deal with special cases such as array syntax.
1262  */
1263  parseTypeString(typ_name, &result, &typmod, true);
1264 
1265  if (OidIsValid(result))
1266  PG_RETURN_OID(result);
1267  else
1268  PG_RETURN_NULL();
1269 }
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
signed int int32
Definition: c.h:355
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
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:204
#define PG_RETURN_OID(x)
Definition: fmgr.h:354
#define PG_RETURN_NULL()
Definition: fmgr.h:339