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:10727
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:3191
static char * buf
Definition: pg_test_fsync.c:67
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
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:193

◆ 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:321
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:337
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3215
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h: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:3191
static char * buf
Definition: pg_test_fsync.c:67
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10811
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:193

◆ 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:321
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:337
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3215
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h: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 1888 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().

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

◆ regclassout()

Datum regclassout ( PG_FUNCTION_ARGS  )

Definition at line 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:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10811
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
#define IsBootstrapProcessingMode()
Definition: miscadmin.h: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:193

◆ 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:624
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3601
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ 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,
1156  * qualify it.
1157  */
1158  if (CollationIsVisible(collationid))
1159  nspname = NULL;
1160  else
1161  nspname = get_namespace_name(collationform->collnamespace);
1162 
1163  result = quote_qualified_identifier(nspname, collationname);
1164  }
1165 
1166  ReleaseSysCache(collationtup);
1167  }
1168  else
1169  {
1170  /* If OID doesn't match any pg_collation entry, return it numerically */
1171  result = (char *) palloc(NAMEDATALEN);
1172  snprintf(result, NAMEDATALEN, "%u", collationid);
1173  }
1174 
1175  PG_RETURN_CSTRING(result);
1176 }
#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:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2048
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10811
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:193

◆ regcollationrecv()

Datum regcollationrecv ( PG_FUNCTION_ARGS  )

Definition at line 1182 of file regproc.c.

References oidrecv().

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

◆ regcollationsend()

Datum regcollationsend ( PG_FUNCTION_ARGS  )

Definition at line 1192 of file regproc.c.

References oidsend().

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

◆ regconfigin()

Datum regconfigin ( PG_FUNCTION_ARGS  )

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

1351 {
1352  char *cfg_name_or_oid = PG_GETARG_CSTRING(0);
1353  Oid result;
1354  List *names;
1355 
1356  /* '-' ? */
1357  if (strcmp(cfg_name_or_oid, "-") == 0)
1359 
1360  /* Numeric OID? */
1361  if (cfg_name_or_oid[0] >= '0' &&
1362  cfg_name_or_oid[0] <= '9' &&
1363  strspn(cfg_name_or_oid, "0123456789") == strlen(cfg_name_or_oid))
1364  {
1366  CStringGetDatum(cfg_name_or_oid)));
1367  PG_RETURN_OID(result);
1368  }
1369 
1370  /* The rest of this wouldn't work in bootstrap mode */
1372  elog(ERROR, "regconfig values must be OIDs in bootstrap mode");
1373 
1374  /*
1375  * Normal case: parse the name into components and see if it matches any
1376  * pg_ts_config entries in the current search path.
1377  */
1378  names = stringToQualifiedNameList(cfg_name_or_oid);
1379 
1380  result = get_ts_config_oid(names, false);
1381 
1382  PG_RETURN_OID(result);
1383 }
#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:624
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regconfigout()

Datum regconfigout ( PG_FUNCTION_ARGS  )

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

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

◆ regconfigrecv()

Datum regconfigrecv ( PG_FUNCTION_ARGS  )

Definition at line 1435 of file regproc.c.

References oidrecv().

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

◆ regconfigsend()

Datum regconfigsend ( PG_FUNCTION_ARGS  )

Definition at line 1445 of file regproc.c.

References oidsend().

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

◆ regdictionaryin()

Datum regdictionaryin ( PG_FUNCTION_ARGS  )

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

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

◆ regdictionaryout()

Datum regdictionaryout ( PG_FUNCTION_ARGS  )

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

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

◆ regdictionaryrecv()

Datum regdictionaryrecv ( PG_FUNCTION_ARGS  )

Definition at line 1547 of file regproc.c.

References oidrecv().

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

◆ regdictionarysend()

Datum regdictionarysend ( PG_FUNCTION_ARGS  )

Definition at line 1557 of file regproc.c.

References oidsend().

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

◆ regnamespacein()

Datum regnamespacein ( PG_FUNCTION_ARGS  )

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

1698 {
1699  char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
1700  Oid result;
1701  List *names;
1702 
1703  /* '-' ? */
1704  if (strcmp(nsp_name_or_oid, "-") == 0)
1706 
1707  /* Numeric OID? */
1708  if (nsp_name_or_oid[0] >= '0' &&
1709  nsp_name_or_oid[0] <= '9' &&
1710  strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
1711  {
1713  CStringGetDatum(nsp_name_or_oid)));
1714  PG_RETURN_OID(result);
1715  }
1716 
1717  /* The rest of this wouldn't work in bootstrap mode */
1719  elog(ERROR, "regnamespace values must be OIDs in bootstrap mode");
1720 
1721  /* Normal case: see if the name matches any pg_namespace entry. */
1722  names = stringToQualifiedNameList(nsp_name_or_oid);
1723 
1724  if (list_length(names) != 1)
1725  ereport(ERROR,
1726  (errcode(ERRCODE_INVALID_NAME),
1727  errmsg("invalid name syntax")));
1728 
1729  result = get_namespace_oid(strVal(linitial(names)), false);
1730 
1731  PG_RETURN_OID(result);
1732 }
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:624
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
static int list_length(const List *l)
Definition: pg_list.h:169
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regnamespaceout()

Datum regnamespaceout ( PG_FUNCTION_ARGS  )

Definition at line 1765 of file regproc.c.

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

1766 {
1767  Oid nspid = PG_GETARG_OID(0);
1768  char *result;
1769 
1770  if (nspid == InvalidOid)
1771  {
1772  result = pstrdup("-");
1773  PG_RETURN_CSTRING(result);
1774  }
1775 
1776  result = get_namespace_name(nspid);
1777 
1778  if (result)
1779  {
1780  /* pstrdup is not really necessary, but it avoids a compiler warning */
1781  result = pstrdup(quote_identifier(result));
1782  }
1783  else
1784  {
1785  /* If OID doesn't match any namespace, return it numerically */
1786  result = (char *) palloc(NAMEDATALEN);
1787  snprintf(result, NAMEDATALEN, "%u", nspid);
1788  }
1789 
1790  PG_RETURN_CSTRING(result);
1791 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10727
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:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:949
#define snprintf
Definition: port.h:193

◆ regnamespacerecv()

Datum regnamespacerecv ( PG_FUNCTION_ARGS  )

Definition at line 1797 of file regproc.c.

References oidrecv().

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

◆ regnamespacesend()

Datum regnamespacesend ( PG_FUNCTION_ARGS  )

Definition at line 1807 of file regproc.c.

References oidsend().

1808 {
1809  /* Exactly the same as oidsend, so share code */
1810  return oidsend(fcinfo);
1811 }
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:624
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:1888
#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:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regoperatorout()

Datum regoperatorout ( PG_FUNCTION_ARGS  )

Definition at line 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:275
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361

◆ regoperatorrecv()

Datum regoperatorrecv ( PG_FUNCTION_ARGS  )

Definition at line 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:624
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:1840
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regoperout()

Datum regoperout ( PG_FUNCTION_ARGS  )

Definition at line 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:10727
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:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
struct _FuncCandidateList * next
Definition: namespace.h:30
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:193

◆ 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:624
unsigned int Oid
Definition: postgres_ext.h:31
#define FUNC_MAX_ARGS
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition: namespace.h:37
#define ERROR
Definition: elog.h:43
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
#define CStringGetDatum(X)
Definition: postgres.h:578
struct _FuncCandidateList * next
Definition: namespace.h:30
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
Definition: regproc.c:1888
#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:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regprocedureout()

Datum regprocedureout ( PG_FUNCTION_ARGS  )

Definition at line 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:275
#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:361

◆ 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:624
#define ERROR
Definition: elog.h:43
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
#define CStringGetDatum(X)
Definition: postgres.h:578
struct _FuncCandidateList * next
Definition: namespace.h:30
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regprocout()

Datum regprocout ( PG_FUNCTION_ARGS  )

Definition at line 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:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
struct _FuncCandidateList * next
Definition: namespace.h:30
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10811
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:193

◆ 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 1572 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.

1573 {
1574  char *role_name_or_oid = PG_GETARG_CSTRING(0);
1575  Oid result;
1576  List *names;
1577 
1578  /* '-' ? */
1579  if (strcmp(role_name_or_oid, "-") == 0)
1581 
1582  /* Numeric OID? */
1583  if (role_name_or_oid[0] >= '0' &&
1584  role_name_or_oid[0] <= '9' &&
1585  strspn(role_name_or_oid, "0123456789") == strlen(role_name_or_oid))
1586  {
1588  CStringGetDatum(role_name_or_oid)));
1589  PG_RETURN_OID(result);
1590  }
1591 
1592  /* The rest of this wouldn't work in bootstrap mode */
1594  elog(ERROR, "regrole values must be OIDs in bootstrap mode");
1595 
1596  /* Normal case: see if the name matches any pg_authid entry. */
1597  names = stringToQualifiedNameList(role_name_or_oid);
1598 
1599  if (list_length(names) != 1)
1600  ereport(ERROR,
1601  (errcode(ERRCODE_INVALID_NAME),
1602  errmsg("invalid name syntax")));
1603 
1604  result = get_role_oid(strVal(linitial(names)), false);
1605 
1606  PG_RETURN_OID(result);
1607 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5175
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
static int list_length(const List *l)
Definition: pg_list.h:169
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ regroleout()

Datum regroleout ( PG_FUNCTION_ARGS  )

Definition at line 1640 of file regproc.c.

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

1641 {
1642  Oid roleoid = PG_GETARG_OID(0);
1643  char *result;
1644 
1645  if (roleoid == InvalidOid)
1646  {
1647  result = pstrdup("-");
1648  PG_RETURN_CSTRING(result);
1649  }
1650 
1651  result = GetUserNameFromId(roleoid, true);
1652 
1653  if (result)
1654  {
1655  /* pstrdup is not really necessary, but it avoids a compiler warning */
1656  result = pstrdup(quote_identifier(result));
1657  }
1658  else
1659  {
1660  /* If OID doesn't match any role, return it numerically */
1661  result = (char *) palloc(NAMEDATALEN);
1662  snprintf(result, NAMEDATALEN, "%u", roleoid);
1663  }
1664 
1665  PG_RETURN_CSTRING(result);
1666 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10727
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:275
#define InvalidOid
Definition: postgres_ext.h:36
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:863
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:949
#define snprintf
Definition: port.h:193

◆ regrolerecv()

Datum regrolerecv ( PG_FUNCTION_ARGS  )

Definition at line 1672 of file regproc.c.

References oidrecv().

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

◆ regrolesend()

Datum regrolesend ( PG_FUNCTION_ARGS  )

Definition at line 1682 of file regproc.c.

References oidsend().

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

◆ regtypein()

Datum regtypein ( PG_FUNCTION_ARGS  )

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

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

◆ regtypeout()

Datum regtypeout ( PG_FUNCTION_ARGS  )

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

1277 {
1278  Oid typid = PG_GETARG_OID(0);
1279  char *result;
1280  HeapTuple typetup;
1281 
1282  if (typid == InvalidOid)
1283  {
1284  result = pstrdup("-");
1285  PG_RETURN_CSTRING(result);
1286  }
1287 
1288  typetup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid));
1289 
1290  if (HeapTupleIsValid(typetup))
1291  {
1292  Form_pg_type typeform = (Form_pg_type) GETSTRUCT(typetup);
1293 
1294  /*
1295  * In bootstrap mode, skip the fancy namespace stuff and just return
1296  * the type name. (This path is only needed for debugging output
1297  * anyway.)
1298  */
1300  {
1301  char *typname = NameStr(typeform->typname);
1302 
1303  result = pstrdup(typname);
1304  }
1305  else
1306  result = format_type_be(typid);
1307 
1308  ReleaseSysCache(typetup);
1309  }
1310  else
1311  {
1312  /* If OID doesn't match any pg_type entry, return it numerically */
1313  result = (char *) palloc(NAMEDATALEN);
1314  snprintf(result, NAMEDATALEN, "%u", typid);
1315  }
1316 
1317  PG_RETURN_CSTRING(result);
1318 }
#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:275
NameData typname
Definition: pg_type.h:41
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
void * palloc(Size size)
Definition: mcxt.c:949
#define NameStr(name)
Definition: c.h:615
#define snprintf
Definition: port.h:193

◆ regtyperecv()

Datum regtyperecv ( PG_FUNCTION_ARGS  )

Definition at line 1324 of file regproc.c.

References oidrecv().

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

◆ regtypesend()

Datum regtypesend ( PG_FUNCTION_ARGS  )

Definition at line 1334 of file regproc.c.

References oidsend().

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

◆ stringToQualifiedNameList()

List* stringToQualifiedNameList ( const char *  string)

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

1841 {
1842  char *rawname;
1843  List *result = NIL;
1844  List *namelist;
1845  ListCell *l;
1846 
1847  /* We need a modifiable copy of the input string. */
1848  rawname = pstrdup(string);
1849 
1850  if (!SplitIdentifierString(rawname, '.', &namelist))
1851  ereport(ERROR,
1852  (errcode(ERRCODE_INVALID_NAME),
1853  errmsg("invalid name syntax")));
1854 
1855  if (namelist == NIL)
1856  ereport(ERROR,
1857  (errcode(ERRCODE_INVALID_NAME),
1858  errmsg("invalid name syntax")));
1859 
1860  foreach(l, namelist)
1861  {
1862  char *curname = (char *) lfirst(l);
1863 
1864  result = lappend(result, makeString(pstrdup(curname)));
1865  }
1866 
1867  pfree(rawname);
1868  list_free(namelist);
1869 
1870  return result;
1871 }
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:3686
List * lappend(List *list, void *datum)
Definition: list.c:321
#define ereport(elevel,...)
Definition: elog.h:144
#define lfirst(lc)
Definition: pg_list.h:190
int errmsg(const char *fmt,...)
Definition: elog.c:824
void list_free(List *list)
Definition: list.c:1376
Definition: pg_list.h:50

◆ text_regclass()

Datum text_regclass ( PG_FUNCTION_ARGS  )

Definition at line 1821 of file regproc.c.

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

1822 {
1824  Oid result;
1825  RangeVar *rv;
1826 
1828 
1829  /* We might not even have permissions on this relation; don't lock it. */
1830  result = RangeVarGetRelid(rv, NoLock, false);
1831 
1832  PG_RETURN_OID(result);
1833 }
#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:308
#define NoLock
Definition: lockdefs.h:34
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3628
Definition: c.h:555
#define PG_RETURN_OID(x)
Definition: fmgr.h:359

◆ 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:308
#define NoLock
Definition: lockdefs.h:34
const char * class_name
Definition: selinux.c:32
char * text_to_cstring(const text *t)
Definition: varlena.c:205
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regcollation()

Datum to_regcollation ( PG_FUNCTION_ARGS  )

Definition at line 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:308
char * text_to_cstring(const text *t)
Definition: varlena.c:205
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
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:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regnamespace()

Datum to_regnamespace ( PG_FUNCTION_ARGS  )

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

1741 {
1742  char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1743  Oid result;
1744  List *names;
1745 
1746  names = stringToQualifiedNameList(nsp_name);
1747 
1748  if (list_length(names) != 1)
1749  ereport(ERROR,
1750  (errcode(ERRCODE_INVALID_NAME),
1751  errmsg("invalid name syntax")));
1752 
1753  result = get_namespace_oid(strVal(linitial(names)), true);
1754 
1755  if (OidIsValid(result))
1756  PG_RETURN_OID(result);
1757  else
1758  PG_RETURN_NULL();
1759 }
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:308
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
static int list_length(const List *l)
Definition: pg_list.h:169
char * text_to_cstring(const text *t)
Definition: varlena.c:205
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regoper()

Datum to_regoper ( PG_FUNCTION_ARGS  )

Definition at line 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:308
struct _FuncCandidateList * next
Definition: namespace.h:30
char * text_to_cstring(const text *t)
Definition: varlena.c:205
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regoperator()

Datum to_regoperator ( PG_FUNCTION_ARGS  )

Definition at line 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:308
#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:1888
char * text_to_cstring(const text *t)
Definition: varlena.c:205
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regproc()

Datum to_regproc ( PG_FUNCTION_ARGS  )

Definition at line 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:308
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
struct _FuncCandidateList * next
Definition: namespace.h:30
char * text_to_cstring(const text *t)
Definition: varlena.c:205
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regprocedure()

Datum to_regprocedure ( PG_FUNCTION_ARGS  )

Definition at line 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:308
#define FUNC_MAX_ARGS
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition: namespace.h:37
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
struct _FuncCandidateList * next
Definition: namespace.h:30
static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
Definition: regproc.c:1888
char * text_to_cstring(const text *t)
Definition: varlena.c:205
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regrole()

Datum to_regrole ( PG_FUNCTION_ARGS  )

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

1616 {
1617  char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1618  Oid result;
1619  List *names;
1620 
1621  names = stringToQualifiedNameList(role_name);
1622 
1623  if (list_length(names) != 1)
1624  ereport(ERROR,
1625  (errcode(ERRCODE_INVALID_NAME),
1626  errmsg("invalid name syntax")));
1627 
1628  result = get_role_oid(strVal(linitial(names)), true);
1629 
1630  if (OidIsValid(result))
1631  PG_RETURN_OID(result);
1632  else
1633  PG_RETURN_NULL();
1634 }
#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:308
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5175
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
static int list_length(const List *l)
Definition: pg_list.h:169
char * text_to_cstring(const text *t)
Definition: varlena.c:205
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1840
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ to_regtype()

Datum to_regtype ( PG_FUNCTION_ARGS  )

Definition at line 1255 of file regproc.c.

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

1256 {
1257  char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1258  Oid result;
1259  int32 typmod;
1260 
1261  /*
1262  * Invoke the full parser to deal with special cases such as array syntax.
1263  */
1264  parseTypeString(typ_name, &result, &typmod, true);
1265 
1266  if (OidIsValid(result))
1267  PG_RETURN_OID(result);
1268  else
1269  PG_RETURN_NULL();
1270 }
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:308
void parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:832
char * text_to_cstring(const text *t)
Definition: varlena.c:205
#define PG_RETURN_OID(x)
Definition: fmgr.h:359
#define PG_RETURN_NULL()
Definition: fmgr.h:344