PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_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/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/acl.h"
#include "utils/regproc.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 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

char* format_operator ( Oid  operator_oid)

Definition at line 820 of file regproc.c.

References format_operator_internal().

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

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

Definition at line 755 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(), result, SearchSysCache1, and snprintf().

Referenced by format_operator(), and format_operator_qualified().

756 {
757  char *result;
758  HeapTuple opertup;
759 
760  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
761 
762  if (HeapTupleIsValid(opertup))
763  {
764  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
765  char *oprname = NameStr(operform->oprname);
766  char *nspname;
768 
769  /* XXX no support here for bootstrap mode */
771 
772  initStringInfo(&buf);
773 
774  /*
775  * Would this oper be found (given the right args) by regoperatorin?
776  * If not, or if caller explicitly requests it, we need to qualify it.
777  */
778  if (force_qualify || !OperatorIsVisible(operator_oid))
779  {
780  nspname = get_namespace_name(operform->oprnamespace);
781  appendStringInfo(&buf, "%s.",
782  quote_identifier(nspname));
783  }
784 
785  appendStringInfo(&buf, "%s(", oprname);
786 
787  if (operform->oprleft)
788  appendStringInfo(&buf, "%s,",
789  force_qualify ?
790  format_type_be_qualified(operform->oprleft) :
791  format_type_be(operform->oprleft));
792  else
793  appendStringInfoString(&buf, "NONE,");
794 
795  if (operform->oprright)
796  appendStringInfo(&buf, "%s)",
797  force_qualify ?
798  format_type_be_qualified(operform->oprright) :
799  format_type_be(operform->oprright));
800  else
801  appendStringInfoString(&buf, "NONE)");
802 
803  result = buf.data;
804 
805  ReleaseSysCache(opertup);
806  }
807  else
808  {
809  /*
810  * If OID doesn't match any pg_operator entry, return it numerically
811  */
812  result = (char *) palloc(NAMEDATALEN);
813  snprintf(result, NAMEDATALEN, "%u", operator_oid);
814  }
815 
816  return result;
817 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10280
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:1707
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define NAMEDATALEN
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
static char * buf
Definition: pg_test_fsync.c:66
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:675
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:104
FormData_pg_operator* Form_pg_operator
Definition: pg_operator.h:57
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
void * palloc(Size size)
Definition: mcxt.c:849
#define NameStr(name)
Definition: c.h:499
void format_operator_parts ( Oid  operator_oid,
List **  objnames,
List **  objargs 
)

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

833 {
834  HeapTuple opertup;
835  Form_pg_operator oprForm;
836 
837  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
838  if (!HeapTupleIsValid(opertup))
839  elog(ERROR, "cache lookup failed for operator with OID %u",
840  operator_oid);
841 
842  oprForm = (Form_pg_operator) GETSTRUCT(opertup);
843  *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
844  pstrdup(NameStr(oprForm->oprname)));
845  *objargs = NIL;
846  if (oprForm->oprleft)
847  *objargs = lappend(*objargs,
848  format_type_be_qualified(oprForm->oprleft));
849  if (oprForm->oprright)
850  *objargs = lappend(*objargs,
851  format_type_be_qualified(oprForm->oprright));
852 
853  ReleaseSysCache(opertup);
854 }
#define list_make2(x1, x2)
Definition: pg_list.h:140
#define NIL
Definition: pg_list.h:69
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1077
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
List * lappend(List *list, void *datum)
Definition: list.c:128
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:104
FormData_pg_operator* Form_pg_operator
Definition: pg_operator.h:57
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3057
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
char* format_operator_qualified ( Oid  operator_oid)

Definition at line 826 of file regproc.c.

References format_operator_internal().

Referenced by getObjectIdentityParts().

827 {
828  return format_operator_internal(operator_oid, true);
829 }
static char * format_operator_internal(Oid operator_oid, bool force_qualify)
Definition: regproc.c:755
char* format_procedure ( Oid  procedure_oid)

Definition at line 323 of file regproc.c.

References format_procedure_internal().

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

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

Definition at line 342 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, NULL, ObjectIdGetDatum, palloc(), PROCOID, quote_qualified_identifier(), ReleaseSysCache(), result, SearchSysCache1, and snprintf().

Referenced by format_procedure(), and format_procedure_qualified().

343 {
344  char *result;
345  HeapTuple proctup;
346 
347  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
348 
349  if (HeapTupleIsValid(proctup))
350  {
351  Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
352  char *proname = NameStr(procform->proname);
353  int nargs = procform->pronargs;
354  int i;
355  char *nspname;
357 
358  /* XXX no support here for bootstrap mode */
360 
361  initStringInfo(&buf);
362 
363  /*
364  * Would this proc be found (given the right args) by regprocedurein?
365  * If not, or if caller requests it, we need to qualify it.
366  */
367  if (!force_qualify && FunctionIsVisible(procedure_oid))
368  nspname = NULL;
369  else
370  nspname = get_namespace_name(procform->pronamespace);
371 
372  appendStringInfo(&buf, "%s(",
373  quote_qualified_identifier(nspname, proname));
374  for (i = 0; i < nargs; i++)
375  {
376  Oid thisargtype = procform->proargtypes.values[i];
377 
378  if (i > 0)
379  appendStringInfoChar(&buf, ',');
381  force_qualify ?
382  format_type_be_qualified(thisargtype) :
383  format_type_be(thisargtype));
384  }
385  appendStringInfoChar(&buf, ')');
386 
387  result = buf.data;
388 
389  ReleaseSysCache(proctup);
390  }
391  else
392  {
393  /* If OID doesn't match any pg_proc entry, return it numerically */
394  result = (char *) palloc(NAMEDATALEN);
395  snprintf(result, NAMEDATALEN, "%u", procedure_oid);
396  }
397 
398  return result;
399 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1374
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define NAMEDATALEN
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
static char * buf
Definition: pg_test_fsync.c:66
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:169
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10366
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:104
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
void * palloc(Size size)
Definition: mcxt.c:849
int i
#define NameStr(name)
Definition: c.h:499
void format_procedure_parts ( Oid  procedure_oid,
List **  objnames,
List **  objargs 
)

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

409 {
410  HeapTuple proctup;
411  Form_pg_proc procform;
412  int nargs;
413  int i;
414 
415  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
416 
417  if (!HeapTupleIsValid(proctup))
418  elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
419 
420  procform = (Form_pg_proc) GETSTRUCT(proctup);
421  nargs = procform->pronargs;
422 
423  *objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
424  pstrdup(NameStr(procform->proname)));
425  *objargs = NIL;
426  for (i = 0; i < nargs; i++)
427  {
428  Oid thisargtype = procform->proargtypes.values[i];
429 
430  *objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
431  }
432 
433  ReleaseSysCache(proctup);
434 }
#define list_make2(x1, x2)
Definition: pg_list.h:140
#define NIL
Definition: pg_list.h:69
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1077
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
List * lappend(List *list, void *datum)
Definition: list.c:128
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:104
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3057
int i
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
char* format_procedure_qualified ( Oid  procedure_oid)

Definition at line 329 of file regproc.c.

References format_procedure_internal().

Referenced by getObjectIdentityParts().

330 {
331  return format_procedure_internal(procedure_oid, true);
332 }
static char * format_procedure_internal(Oid procedure_oid, bool force_qualify)
Definition: regproc.c:342
static void parseNameAndArgTypes ( const char *  string,
bool  allowNone,
List **  names,
int *  nargs,
Oid argtypes 
)
static

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

1737 {
1738  char *rawname;
1739  char *ptr;
1740  char *ptr2;
1741  char *typename;
1742  bool in_quote;
1743  bool had_comma;
1744  int paren_count;
1745  Oid typeid;
1746  int32 typmod;
1747 
1748  /* We need a modifiable copy of the input string. */
1749  rawname = pstrdup(string);
1750 
1751  /* Scan to find the expected left paren; mustn't be quoted */
1752  in_quote = false;
1753  for (ptr = rawname; *ptr; ptr++)
1754  {
1755  if (*ptr == '"')
1756  in_quote = !in_quote;
1757  else if (*ptr == '(' && !in_quote)
1758  break;
1759  }
1760  if (*ptr == '\0')
1761  ereport(ERROR,
1762  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1763  errmsg("expected a left parenthesis")));
1764 
1765  /* Separate the name and parse it into a list */
1766  *ptr++ = '\0';
1767  *names = stringToQualifiedNameList(rawname);
1768 
1769  /* Check for the trailing right parenthesis and remove it */
1770  ptr2 = ptr + strlen(ptr);
1771  while (--ptr2 > ptr)
1772  {
1773  if (!scanner_isspace(*ptr2))
1774  break;
1775  }
1776  if (*ptr2 != ')')
1777  ereport(ERROR,
1778  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1779  errmsg("expected a right parenthesis")));
1780 
1781  *ptr2 = '\0';
1782 
1783  /* Separate the remaining string into comma-separated type names */
1784  *nargs = 0;
1785  had_comma = false;
1786 
1787  for (;;)
1788  {
1789  /* allow leading whitespace */
1790  while (scanner_isspace(*ptr))
1791  ptr++;
1792  if (*ptr == '\0')
1793  {
1794  /* End of string. Okay unless we had a comma before. */
1795  if (had_comma)
1796  ereport(ERROR,
1797  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1798  errmsg("expected a type name")));
1799  break;
1800  }
1801  typename = ptr;
1802  /* Find end of type name --- end of string or comma */
1803  /* ... but not a quoted or parenthesized comma */
1804  in_quote = false;
1805  paren_count = 0;
1806  for (; *ptr; ptr++)
1807  {
1808  if (*ptr == '"')
1809  in_quote = !in_quote;
1810  else if (*ptr == ',' && !in_quote && paren_count == 0)
1811  break;
1812  else if (!in_quote)
1813  {
1814  switch (*ptr)
1815  {
1816  case '(':
1817  case '[':
1818  paren_count++;
1819  break;
1820  case ')':
1821  case ']':
1822  paren_count--;
1823  break;
1824  }
1825  }
1826  }
1827  if (in_quote || paren_count != 0)
1828  ereport(ERROR,
1829  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1830  errmsg("improper type name")));
1831 
1832  ptr2 = ptr;
1833  if (*ptr == ',')
1834  {
1835  had_comma = true;
1836  *ptr++ = '\0';
1837  }
1838  else
1839  {
1840  had_comma = false;
1841  Assert(*ptr == '\0');
1842  }
1843  /* Lop off trailing whitespace */
1844  while (--ptr2 >= typename)
1845  {
1846  if (!scanner_isspace(*ptr2))
1847  break;
1848  *ptr2 = '\0';
1849  }
1850 
1851  if (allowNone && pg_strcasecmp(typename, "none") == 0)
1852  {
1853  /* Special case for NONE */
1854  typeid = InvalidOid;
1855  typmod = -1;
1856  }
1857  else
1858  {
1859  /* Use full parser to resolve the type name */
1860  parseTypeString(typename, &typeid, &typmod, false);
1861  }
1862  if (*nargs >= FUNC_MAX_ARGS)
1863  ereport(ERROR,
1864  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
1865  errmsg("too many arguments")));
1866 
1867  argtypes[*nargs] = typeid;
1868  (*nargs)++;
1869  }
1870 
1871  pfree(rawname);
1872 }
char * pstrdup(const char *in)
Definition: mcxt.c:1077
int errcode(int sqlerrcode)
Definition: elog.c:575
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:256
#define FUNC_MAX_ARGS
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool scanner_isspace(char ch)
Definition: scansup.c:221
void parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:781
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:675
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
int errmsg(const char *fmt,...)
Definition: elog.c:797
Datum regclassin ( PG_FUNCTION_ARGS  )

Definition at line 903 of file regproc.c.

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

904 {
905  char *class_name_or_oid = PG_GETARG_CSTRING(0);
907  List *names;
908 
909  /* '-' ? */
910  if (strcmp(class_name_or_oid, "-") == 0)
912 
913  /* Numeric OID? */
914  if (class_name_or_oid[0] >= '0' &&
915  class_name_or_oid[0] <= '9' &&
916  strspn(class_name_or_oid, "0123456789") == strlen(class_name_or_oid))
917  {
919  CStringGetDatum(class_name_or_oid)));
920  PG_RETURN_OID(result);
921  }
922 
923  /* Else it's a name, possibly schema-qualified */
924 
925  /* The rest of this wouldn't work in bootstrap mode */
927  elog(ERROR, "regclass values must be OIDs in bootstrap mode");
928 
929  /*
930  * Normal case: parse the name into components and see if it matches any
931  * pg_class entries in the current search path.
932  */
933  names = stringToQualifiedNameList(class_name_or_oid);
934 
935  /* We might not even have permissions on this relation; don't lock it. */
936  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, false);
937 
938  PG_RETURN_OID(result);
939 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:53
#define DatumGetObjectId(X)
Definition: postgres.h:506
return result
Definition: formatting.c:1632
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2980
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
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:584
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regclassout ( PG_FUNCTION_ARGS  )

Definition at line 972 of file regproc.c.

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

Referenced by table_to_xml_internal().

973 {
974  Oid classid = PG_GETARG_OID(0);
975  char *result;
976  HeapTuple classtup;
977 
978  if (classid == InvalidOid)
979  {
980  result = pstrdup("-");
981  PG_RETURN_CSTRING(result);
982  }
983 
984  classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classid));
985 
986  if (HeapTupleIsValid(classtup))
987  {
988  Form_pg_class classform = (Form_pg_class) GETSTRUCT(classtup);
989  char *classname = NameStr(classform->relname);
990 
991  /*
992  * In bootstrap mode, skip the fancy namespace stuff and just return
993  * the class name. (This path is only needed for debugging output
994  * anyway.)
995  */
997  result = pstrdup(classname);
998  else
999  {
1000  char *nspname;
1001 
1002  /*
1003  * Would this class be found by regclassin? If not, qualify it.
1004  */
1005  if (RelationIsVisible(classid))
1006  nspname = NULL;
1007  else
1008  nspname = get_namespace_name(classform->relnamespace);
1009 
1010  result = quote_qualified_identifier(nspname, classname);
1011  }
1012 
1013  ReleaseSysCache(classtup);
1014  }
1015  else
1016  {
1017  /* If OID doesn't match any pg_class entry, return it numerically */
1018  result = (char *) palloc(NAMEDATALEN);
1019  snprintf(result, NAMEDATALEN, "%u", classid);
1020  }
1021 
1022  PG_RETURN_CSTRING(result);
1023 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10366
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
void * palloc(Size size)
Definition: mcxt.c:849
bool RelationIsVisible(Oid relid)
Definition: namespace.c:682
#define NameStr(name)
Definition: c.h:499
Datum regclassrecv ( PG_FUNCTION_ARGS  )

Definition at line 1029 of file regproc.c.

References oidrecv().

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

Definition at line 1039 of file regproc.c.

References oidsend().

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

Definition at line 1197 of file regproc.c.

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

1198 {
1199  char *cfg_name_or_oid = PG_GETARG_CSTRING(0);
1200  Oid result;
1201  List *names;
1202 
1203  /* '-' ? */
1204  if (strcmp(cfg_name_or_oid, "-") == 0)
1206 
1207  /* Numeric OID? */
1208  if (cfg_name_or_oid[0] >= '0' &&
1209  cfg_name_or_oid[0] <= '9' &&
1210  strspn(cfg_name_or_oid, "0123456789") == strlen(cfg_name_or_oid))
1211  {
1213  CStringGetDatum(cfg_name_or_oid)));
1214  PG_RETURN_OID(result);
1215  }
1216 
1217  /* The rest of this wouldn't work in bootstrap mode */
1219  elog(ERROR, "regconfig values must be OIDs in bootstrap mode");
1220 
1221  /*
1222  * Normal case: parse the name into components and see if it matches any
1223  * pg_ts_config entries in the current search path.
1224  */
1225  names = stringToQualifiedNameList(cfg_name_or_oid);
1226 
1227  result = get_ts_config_oid(names, false);
1228 
1229  PG_RETURN_OID(result);
1230 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2596
return result
Definition: formatting.c:1632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regconfigout ( PG_FUNCTION_ARGS  )

Definition at line 1236 of file regproc.c.

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

1237 {
1238  Oid cfgid = PG_GETARG_OID(0);
1239  char *result;
1240  HeapTuple cfgtup;
1241 
1242  if (cfgid == InvalidOid)
1243  {
1244  result = pstrdup("-");
1245  PG_RETURN_CSTRING(result);
1246  }
1247 
1248  cfgtup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgid));
1249 
1250  if (HeapTupleIsValid(cfgtup))
1251  {
1252  Form_pg_ts_config cfgform = (Form_pg_ts_config) GETSTRUCT(cfgtup);
1253  char *cfgname = NameStr(cfgform->cfgname);
1254  char *nspname;
1255 
1256  /*
1257  * Would this config be found by regconfigin? If not, qualify it.
1258  */
1259  if (TSConfigIsVisible(cfgid))
1260  nspname = NULL;
1261  else
1262  nspname = get_namespace_name(cfgform->cfgnamespace);
1263 
1264  result = quote_qualified_identifier(nspname, cfgname);
1265 
1266  ReleaseSysCache(cfgtup);
1267  }
1268  else
1269  {
1270  /* If OID doesn't match any pg_ts_config row, return it numerically */
1271  result = (char *) palloc(NAMEDATALEN);
1272  snprintf(result, NAMEDATALEN, "%u", cfgid);
1273  }
1274 
1275  PG_RETURN_CSTRING(result);
1276 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:41
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2654
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10366
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:849
#define NameStr(name)
Definition: c.h:499
Datum regconfigrecv ( PG_FUNCTION_ARGS  )

Definition at line 1282 of file regproc.c.

References oidrecv().

1283 {
1284  /* Exactly the same as oidrecv, so share code */
1285  return oidrecv(fcinfo);
1286 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140
Datum regconfigsend ( PG_FUNCTION_ARGS  )

Definition at line 1292 of file regproc.c.

References oidsend().

1293 {
1294  /* Exactly the same as oidsend, so share code */
1295  return oidsend(fcinfo);
1296 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151
Datum regdictionaryin ( PG_FUNCTION_ARGS  )

Definition at line 1308 of file regproc.c.

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

1309 {
1310  char *dict_name_or_oid = PG_GETARG_CSTRING(0);
1311  Oid result;
1312  List *names;
1313 
1314  /* '-' ? */
1315  if (strcmp(dict_name_or_oid, "-") == 0)
1317 
1318  /* Numeric OID? */
1319  if (dict_name_or_oid[0] >= '0' &&
1320  dict_name_or_oid[0] <= '9' &&
1321  strspn(dict_name_or_oid, "0123456789") == strlen(dict_name_or_oid))
1322  {
1324  CStringGetDatum(dict_name_or_oid)));
1325  PG_RETURN_OID(result);
1326  }
1327 
1328  /* The rest of this wouldn't work in bootstrap mode */
1330  elog(ERROR, "regdictionary values must be OIDs in bootstrap mode");
1331 
1332  /*
1333  * Normal case: parse the name into components and see if it matches any
1334  * pg_ts_dict entries in the current search path.
1335  */
1336  names = stringToQualifiedNameList(dict_name_or_oid);
1337 
1338  result = get_ts_dict_oid(names, false);
1339 
1340  PG_RETURN_OID(result);
1341 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
return result
Definition: formatting.c:1632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2343
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regdictionaryout ( PG_FUNCTION_ARGS  )

Definition at line 1347 of file regproc.c.

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

1348 {
1349  Oid dictid = PG_GETARG_OID(0);
1350  char *result;
1351  HeapTuple dicttup;
1352 
1353  if (dictid == InvalidOid)
1354  {
1355  result = pstrdup("-");
1356  PG_RETURN_CSTRING(result);
1357  }
1358 
1359  dicttup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictid));
1360 
1361  if (HeapTupleIsValid(dicttup))
1362  {
1363  Form_pg_ts_dict dictform = (Form_pg_ts_dict) GETSTRUCT(dicttup);
1364  char *dictname = NameStr(dictform->dictname);
1365  char *nspname;
1366 
1367  /*
1368  * Would this dictionary be found by regdictionaryin? If not, qualify
1369  * it.
1370  */
1371  if (TSDictionaryIsVisible(dictid))
1372  nspname = NULL;
1373  else
1374  nspname = get_namespace_name(dictform->dictnamespace);
1375 
1376  result = quote_qualified_identifier(nspname, dictname);
1377 
1378  ReleaseSysCache(dicttup);
1379  }
1380  else
1381  {
1382  /* If OID doesn't match any pg_ts_dict row, return it numerically */
1383  result = (char *) palloc(NAMEDATALEN);
1384  snprintf(result, NAMEDATALEN, "%u", dictid);
1385  }
1386 
1387  PG_RETURN_CSTRING(result);
1388 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:45
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2401
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10366
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:849
#define NameStr(name)
Definition: c.h:499
Datum regdictionaryrecv ( PG_FUNCTION_ARGS  )

Definition at line 1394 of file regproc.c.

References oidrecv().

1395 {
1396  /* Exactly the same as oidrecv, so share code */
1397  return oidrecv(fcinfo);
1398 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140
Datum regdictionarysend ( PG_FUNCTION_ARGS  )

Definition at line 1404 of file regproc.c.

References oidsend().

1405 {
1406  /* Exactly the same as oidsend, so share code */
1407  return oidsend(fcinfo);
1408 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151
Datum regnamespacein ( PG_FUNCTION_ARGS  )

Definition at line 1544 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, result, stringToQualifiedNameList(), and strVal.

1545 {
1546  char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
1547  Oid result;
1548  List *names;
1549 
1550  /* '-' ? */
1551  if (strcmp(nsp_name_or_oid, "-") == 0)
1553 
1554  /* Numeric OID? */
1555  if (nsp_name_or_oid[0] >= '0' &&
1556  nsp_name_or_oid[0] <= '9' &&
1557  strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
1558  {
1560  CStringGetDatum(nsp_name_or_oid)));
1561  PG_RETURN_OID(result);
1562  }
1563 
1564  /* The rest of this wouldn't work in bootstrap mode */
1566  elog(ERROR, "regnamespace values must be OIDs in bootstrap mode");
1567 
1568  /* Normal case: see if the name matches any pg_namespace entry. */
1569  names = stringToQualifiedNameList(nsp_name_or_oid);
1570 
1571  if (list_length(names) != 1)
1572  ereport(ERROR,
1573  (errcode(ERRCODE_INVALID_NAME),
1574  errmsg("invalid name syntax")));
1575 
1576  result = get_namespace_oid(strVal(linitial(names)), false);
1577 
1578  PG_RETURN_OID(result);
1579 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:2962
#define DatumGetObjectId(X)
Definition: postgres.h:506
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
static int list_length(const List *l)
Definition: pg_list.h:89
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regnamespaceout ( PG_FUNCTION_ARGS  )

Definition at line 1612 of file regproc.c.

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

1613 {
1614  Oid nspid = PG_GETARG_OID(0);
1615  char *result;
1616 
1617  if (nspid == InvalidOid)
1618  {
1619  result = pstrdup("-");
1620  PG_RETURN_CSTRING(result);
1621  }
1622 
1623  result = get_namespace_name(nspid);
1624 
1625  if (result)
1626  {
1627  /* pstrdup is not really necessary, but it avoids a compiler warning */
1628  result = pstrdup(quote_identifier(result));
1629  }
1630  else
1631  {
1632  /* If OID doesn't match any namespace, return it numerically */
1633  result = (char *) palloc(NAMEDATALEN);
1634  snprintf(result, NAMEDATALEN, "%u", nspid);
1635  }
1636 
1637  PG_RETURN_CSTRING(result);
1638 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10280
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:849
Datum regnamespacerecv ( PG_FUNCTION_ARGS  )

Definition at line 1644 of file regproc.c.

References oidrecv().

1645 {
1646  /* Exactly the same as oidrecv, so share code */
1647  return oidrecv(fcinfo);
1648 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140
Datum regnamespacesend ( PG_FUNCTION_ARGS  )

Definition at line 1654 of file regproc.c.

References oidsend().

1655 {
1656  /* Exactly the same as oidsend, so share code */
1657  return oidsend(fcinfo);
1658 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151
Datum regoperatorin ( PG_FUNCTION_ARGS  )

Definition at line 655 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, PG_RETURN_OID, and result.

656 {
657  char *opr_name_or_oid = PG_GETARG_CSTRING(0);
658  Oid result;
659  List *names;
660  int nargs;
661  Oid argtypes[FUNC_MAX_ARGS];
662 
663  /* '0' ? */
664  if (strcmp(opr_name_or_oid, "0") == 0)
666 
667  /* Numeric OID? */
668  if (opr_name_or_oid[0] >= '0' &&
669  opr_name_or_oid[0] <= '9' &&
670  strspn(opr_name_or_oid, "0123456789") == strlen(opr_name_or_oid))
671  {
673  CStringGetDatum(opr_name_or_oid)));
674  PG_RETURN_OID(result);
675  }
676 
677  /* The rest of this wouldn't work in bootstrap mode */
679  elog(ERROR, "regoperator values must be OIDs in bootstrap mode");
680 
681  /*
682  * Else it's a name and arguments. Parse the name and arguments, look up
683  * potential matches in the current namespace search list, and scan to see
684  * which one exactly matches the given argument types. (There will not be
685  * more than one match.)
686  */
687  parseNameAndArgTypes(opr_name_or_oid, true, &names, &nargs, argtypes);
688  if (nargs == 1)
689  ereport(ERROR,
690  (errcode(ERRCODE_UNDEFINED_PARAMETER),
691  errmsg("missing argument"),
692  errhint("Use NONE to denote the missing argument of a unary operator.")));
693  if (nargs != 2)
694  ereport(ERROR,
695  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
696  errmsg("too many arguments"),
697  errhint("Provide two argument types for operator.")));
698 
699  result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
700 
701  if (!OidIsValid(result))
702  ereport(ERROR,
703  (errcode(ERRCODE_UNDEFINED_FUNCTION),
704  errmsg("operator does not exist: %s", opr_name_or_oid)));
705 
706  PG_RETURN_OID(result);
707 }
int errhint(const char *fmt,...)
Definition: elog.c:987
#define DatumGetObjectId(X)
Definition: postgres.h:506
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define FUNC_MAX_ARGS
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1445
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
Definition: regproc.c:1735
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regoperatorout ( PG_FUNCTION_ARGS  )

Definition at line 860 of file regproc.c.

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

861 {
862  Oid oprid = PG_GETARG_OID(0);
863  char *result;
864 
865  if (oprid == InvalidOid)
866  result = pstrdup("0");
867  else
868  result = format_operator(oprid);
869 
870  PG_RETURN_CSTRING(result);
871 }
Oid oprid(Operator op)
Definition: parse_oper.c:245
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1632
char * format_operator(Oid operator_oid)
Definition: regproc.c:820
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
Datum regoperatorrecv ( PG_FUNCTION_ARGS  )

Definition at line 877 of file regproc.c.

References oidrecv().

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

Definition at line 887 of file regproc.c.

References oidsend().

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

Definition at line 483 of file regproc.c.

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

484 {
485  char *opr_name_or_oid = PG_GETARG_CSTRING(0);
487  List *names;
488  FuncCandidateList clist;
489 
490  /* '0' ? */
491  if (strcmp(opr_name_or_oid, "0") == 0)
493 
494  /* Numeric OID? */
495  if (opr_name_or_oid[0] >= '0' &&
496  opr_name_or_oid[0] <= '9' &&
497  strspn(opr_name_or_oid, "0123456789") == strlen(opr_name_or_oid))
498  {
500  CStringGetDatum(opr_name_or_oid)));
501  PG_RETURN_OID(result);
502  }
503 
504  /* Else it's a name, possibly schema-qualified */
505 
506  /* The rest of this wouldn't work in bootstrap mode */
508  elog(ERROR, "regoper values must be OIDs in bootstrap mode");
509 
510  /*
511  * Normal case: parse the name into components and see if it matches any
512  * pg_operator entries in the current search path.
513  */
514  names = stringToQualifiedNameList(opr_name_or_oid);
515  clist = OpernameGetCandidates(names, '\0', false);
516 
517  if (clist == NULL)
518  ereport(ERROR,
519  (errcode(ERRCODE_UNDEFINED_FUNCTION),
520  errmsg("operator does not exist: %s", opr_name_or_oid)));
521  else if (clist->next != NULL)
522  ereport(ERROR,
523  (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
524  errmsg("more than one operator named %s",
525  opr_name_or_oid)));
526 
527  result = clist->oid;
528 
529  PG_RETURN_OID(result);
530 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1547
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
struct _FuncCandidateList * next
Definition: namespace.h:30
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regoperout ( PG_FUNCTION_ARGS  )

Definition at line 561 of file regproc.c.

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

562 {
563  Oid oprid = PG_GETARG_OID(0);
564  char *result;
565  HeapTuple opertup;
566 
567  if (oprid == InvalidOid)
568  {
569  result = pstrdup("0");
570  PG_RETURN_CSTRING(result);
571  }
572 
573  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(oprid));
574 
575  if (HeapTupleIsValid(opertup))
576  {
577  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
578  char *oprname = NameStr(operform->oprname);
579 
580  /*
581  * In bootstrap mode, skip the fancy namespace stuff and just return
582  * the oper name. (This path is only needed for debugging output
583  * anyway.)
584  */
586  result = pstrdup(oprname);
587  else
588  {
589  FuncCandidateList clist;
590 
591  /*
592  * Would this oper be found (uniquely!) by regoperin? If not,
593  * qualify it.
594  */
595  clist = OpernameGetCandidates(list_make1(makeString(oprname)),
596  '\0', false);
597  if (clist != NULL && clist->next == NULL &&
598  clist->oid == oprid)
599  result = pstrdup(oprname);
600  else
601  {
602  const char *nspname;
603 
604  nspname = get_namespace_name(operform->oprnamespace);
605  nspname = quote_identifier(nspname);
606  result = (char *) palloc(strlen(nspname) + strlen(oprname) + 2);
607  sprintf(result, "%s.%s", nspname, oprname);
608  }
609  }
610 
611  ReleaseSysCache(opertup);
612  }
613  else
614  {
615  /*
616  * If OID doesn't match any pg_operator entry, return it numerically
617  */
618  result = (char *) palloc(NAMEDATALEN);
619  snprintf(result, NAMEDATALEN, "%u", oprid);
620  }
621 
622  PG_RETURN_CSTRING(result);
623 }
Value * makeString(char *str)
Definition: value.c:53
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10280
Oid oprid(Operator op)
Definition: parse_oper.c:245
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1547
#define list_make1(x1)
Definition: pg_list.h:139
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
struct _FuncCandidateList * next
Definition: namespace.h:30
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
FormData_pg_operator* Form_pg_operator
Definition: pg_operator.h:57
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
void * palloc(Size size)
Definition: mcxt.c:849
#define NameStr(name)
Definition: c.h:499
Datum regoperrecv ( PG_FUNCTION_ARGS  )

Definition at line 629 of file regproc.c.

References oidrecv().

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

Definition at line 639 of file regproc.c.

References oidsend().

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

Definition at line 231 of file regproc.c.

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

Referenced by convert_function_name().

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

Definition at line 440 of file regproc.c.

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

441 {
442  RegProcedure proid = PG_GETARG_OID(0);
443  char *result;
444 
445  if (proid == InvalidOid)
446  result = pstrdup("-");
447  else
448  result = format_procedure(proid);
449 
450  PG_RETURN_CSTRING(result);
451 }
char * pstrdup(const char *in)
Definition: mcxt.c:1077
regproc RegProcedure
Definition: c.h:395
return result
Definition: formatting.c:1632
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define InvalidOid
Definition: postgres_ext.h:36
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:323
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
Datum regprocedurerecv ( PG_FUNCTION_ARGS  )

Definition at line 457 of file regproc.c.

References oidrecv().

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

Definition at line 467 of file regproc.c.

References oidsend().

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

Definition at line 62 of file regproc.c.

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

63 {
64  char *pro_name_or_oid = PG_GETARG_CSTRING(0);
66  List *names;
67  FuncCandidateList clist;
68 
69  /* '-' ? */
70  if (strcmp(pro_name_or_oid, "-") == 0)
72 
73  /* Numeric OID? */
74  if (pro_name_or_oid[0] >= '0' &&
75  pro_name_or_oid[0] <= '9' &&
76  strspn(pro_name_or_oid, "0123456789") == strlen(pro_name_or_oid))
77  {
79  CStringGetDatum(pro_name_or_oid)));
80  PG_RETURN_OID(result);
81  }
82 
83  /* Else it's a name, possibly schema-qualified */
84 
85  /*
86  * We should never get here in bootstrap mode, as all references should
87  * have been resolved by genbki.pl.
88  */
90  elog(ERROR, "regproc values must be OIDs in bootstrap mode");
91 
92  /*
93  * Normal case: parse the name into components and see if it matches any
94  * pg_proc entries in the current search path.
95  */
96  names = stringToQualifiedNameList(pro_name_or_oid);
97  clist = FuncnameGetCandidates(names, -1, NIL, false, false, false);
98 
99  if (clist == NULL)
100  ereport(ERROR,
101  (errcode(ERRCODE_UNDEFINED_FUNCTION),
102  errmsg("function \"%s\" does not exist", pro_name_or_oid)));
103  else if (clist->next != NULL)
104  ereport(ERROR,
105  (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
106  errmsg("more than one function named \"%s\"",
107  pro_name_or_oid)));
108 
109  result = clist->oid;
110 
111  PG_RETURN_OID(result);
112 }
#define NIL
Definition: pg_list.h:69
#define DatumGetObjectId(X)
Definition: postgres.h:506
regproc RegProcedure
Definition: c.h:395
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#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:903
#define CStringGetDatum(X)
Definition: postgres.h:584
struct _FuncCandidateList * next
Definition: namespace.h:30
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regprocout ( PG_FUNCTION_ARGS  )

Definition at line 143 of file regproc.c.

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

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

Definition at line 205 of file regproc.c.

References oidrecv().

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

Definition at line 215 of file regproc.c.

References oidsend().

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

Definition at line 1419 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, result, stringToQualifiedNameList(), and strVal.

1420 {
1421  char *role_name_or_oid = PG_GETARG_CSTRING(0);
1422  Oid result;
1423  List *names;
1424 
1425  /* '-' ? */
1426  if (strcmp(role_name_or_oid, "-") == 0)
1428 
1429  /* Numeric OID? */
1430  if (role_name_or_oid[0] >= '0' &&
1431  role_name_or_oid[0] <= '9' &&
1432  strspn(role_name_or_oid, "0123456789") == strlen(role_name_or_oid))
1433  {
1435  CStringGetDatum(role_name_or_oid)));
1436  PG_RETURN_OID(result);
1437  }
1438 
1439  /* The rest of this wouldn't work in bootstrap mode */
1441  elog(ERROR, "regrole values must be OIDs in bootstrap mode");
1442 
1443  /* Normal case: see if the name matches any pg_authid entry. */
1444  names = stringToQualifiedNameList(role_name_or_oid);
1445 
1446  if (list_length(names) != 1)
1447  ereport(ERROR,
1448  (errcode(ERRCODE_INVALID_NAME),
1449  errmsg("invalid name syntax")));
1450 
1451  result = get_role_oid(strVal(linitial(names)), false);
1452 
1453  PG_RETURN_OID(result);
1454 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5096
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
static int list_length(const List *l)
Definition: pg_list.h:89
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regroleout ( PG_FUNCTION_ARGS  )

Definition at line 1487 of file regproc.c.

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

1488 {
1489  Oid roleoid = PG_GETARG_OID(0);
1490  char *result;
1491 
1492  if (roleoid == InvalidOid)
1493  {
1494  result = pstrdup("-");
1495  PG_RETURN_CSTRING(result);
1496  }
1497 
1498  result = GetUserNameFromId(roleoid, true);
1499 
1500  if (result)
1501  {
1502  /* pstrdup is not really necessary, but it avoids a compiler warning */
1503  result = pstrdup(quote_identifier(result));
1504  }
1505  else
1506  {
1507  /* If OID doesn't match any role, return it numerically */
1508  result = (char *) palloc(NAMEDATALEN);
1509  snprintf(result, NAMEDATALEN, "%u", roleoid);
1510  }
1511 
1512  PG_RETURN_CSTRING(result);
1513 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10280
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define InvalidOid
Definition: postgres_ext.h:36
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:691
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:849
Datum regrolerecv ( PG_FUNCTION_ARGS  )

Definition at line 1519 of file regproc.c.

References oidrecv().

1520 {
1521  /* Exactly the same as oidrecv, so share code */
1522  return oidrecv(fcinfo);
1523 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140
Datum regrolesend ( PG_FUNCTION_ARGS  )

Definition at line 1529 of file regproc.c.

References oidsend().

1530 {
1531  /* Exactly the same as oidsend, so share code */
1532  return oidsend(fcinfo);
1533 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151
Datum regtypein ( PG_FUNCTION_ARGS  )

Definition at line 1061 of file regproc.c.

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

Referenced by convert_type_name(), and plperl_sv_to_literal().

1062 {
1063  char *typ_name_or_oid = PG_GETARG_CSTRING(0);
1064  Oid result = InvalidOid;
1065  int32 typmod;
1066 
1067  /* '-' ? */
1068  if (strcmp(typ_name_or_oid, "-") == 0)
1070 
1071  /* Numeric OID? */
1072  if (typ_name_or_oid[0] >= '0' &&
1073  typ_name_or_oid[0] <= '9' &&
1074  strspn(typ_name_or_oid, "0123456789") == strlen(typ_name_or_oid))
1075  {
1077  CStringGetDatum(typ_name_or_oid)));
1078  PG_RETURN_OID(result);
1079  }
1080 
1081  /* Else it's a type name, possibly schema-qualified or decorated */
1082 
1083  /* The rest of this wouldn't work in bootstrap mode */
1085  elog(ERROR, "regtype values must be OIDs in bootstrap mode");
1086 
1087  /*
1088  * Normal case: invoke the full parser to deal with special cases such as
1089  * array syntax.
1090  */
1091  parseTypeString(typ_name_or_oid, &result, &typmod, false);
1092 
1093  PG_RETURN_OID(result);
1094 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
return result
Definition: formatting.c:1632
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:256
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
void parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:781
#define InvalidOid
Definition: postgres_ext.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum oidin(PG_FUNCTION_ARGS)
Definition: oid.c:117
#define elog
Definition: elog.h:219
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum regtypeout ( PG_FUNCTION_ARGS  )

Definition at line 1123 of file regproc.c.

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

1124 {
1125  Oid typid = PG_GETARG_OID(0);
1126  char *result;
1127  HeapTuple typetup;
1128 
1129  if (typid == InvalidOid)
1130  {
1131  result = pstrdup("-");
1132  PG_RETURN_CSTRING(result);
1133  }
1134 
1135  typetup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid));
1136 
1137  if (HeapTupleIsValid(typetup))
1138  {
1139  Form_pg_type typeform = (Form_pg_type) GETSTRUCT(typetup);
1140 
1141  /*
1142  * In bootstrap mode, skip the fancy namespace stuff and just return
1143  * the type name. (This path is only needed for debugging output
1144  * anyway.)
1145  */
1147  {
1148  char *typname = NameStr(typeform->typname);
1149 
1150  result = pstrdup(typname);
1151  }
1152  else
1153  result = format_type_be(typid);
1154 
1155  ReleaseSysCache(typetup);
1156  }
1157  else
1158  {
1159  /* If OID doesn't match any pg_type entry, return it numerically */
1160  result = (char *) palloc(NAMEDATALEN);
1161  snprintf(result, NAMEDATALEN, "%u", typid);
1162  }
1163 
1164  PG_RETURN_CSTRING(result);
1165 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1077
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
return result
Definition: formatting.c:1632
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
FormData_pg_type * Form_pg_type
Definition: pg_type.h:233
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:370
void * palloc(Size size)
Definition: mcxt.c:849
#define NameStr(name)
Definition: c.h:499
Datum regtyperecv ( PG_FUNCTION_ARGS  )

Definition at line 1171 of file regproc.c.

References oidrecv().

1172 {
1173  /* Exactly the same as oidrecv, so share code */
1174  return oidrecv(fcinfo);
1175 }
Datum oidrecv(PG_FUNCTION_ARGS)
Definition: oid.c:140
Datum regtypesend ( PG_FUNCTION_ARGS  )

Definition at line 1181 of file regproc.c.

References oidsend().

1182 {
1183  /* Exactly the same as oidsend, so share code */
1184  return oidsend(fcinfo);
1185 }
Datum oidsend(PG_FUNCTION_ARGS)
Definition: oid.c:151
List* stringToQualifiedNameList ( const char *  string)

Definition at line 1687 of file regproc.c.

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

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

1688 {
1689  char *rawname;
1690  List *result = NIL;
1691  List *namelist;
1692  ListCell *l;
1693 
1694  /* We need a modifiable copy of the input string. */
1695  rawname = pstrdup(string);
1696 
1697  if (!SplitIdentifierString(rawname, '.', &namelist))
1698  ereport(ERROR,
1699  (errcode(ERRCODE_INVALID_NAME),
1700  errmsg("invalid name syntax")));
1701 
1702  if (namelist == NIL)
1703  ereport(ERROR,
1704  (errcode(ERRCODE_INVALID_NAME),
1705  errmsg("invalid name syntax")));
1706 
1707  foreach(l, namelist)
1708  {
1709  char *curname = (char *) lfirst(l);
1710 
1711  result = lappend(result, makeString(pstrdup(curname)));
1712  }
1713 
1714  pfree(rawname);
1715  list_free(namelist);
1716 
1717  return result;
1718 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:69
char * pstrdup(const char *in)
Definition: mcxt.c:1077
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3248
#define ereport(elevel, rest)
Definition: elog.h:122
List * lappend(List *list, void *datum)
Definition: list.c:128
#define lfirst(lc)
Definition: pg_list.h:106
int errmsg(const char *fmt,...)
Definition: elog.c:797
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
Datum text_regclass ( PG_FUNCTION_ARGS  )

Definition at line 1668 of file regproc.c.

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

1669 {
1670  text *relname = PG_GETARG_TEXT_PP(0);
1671  Oid result;
1672  RangeVar *rv;
1673 
1675 
1676  /* We might not even have permissions on this relation; don't lock it. */
1677  result = RangeVarGetRelid(rv, NoLock, false);
1678 
1679  PG_RETURN_OID(result);
1680 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:53
return result
Definition: formatting.c:1632
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2980
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define NoLock
Definition: lockdefs.h:34
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3190
Definition: c.h:439
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum to_regclass ( PG_FUNCTION_ARGS  )

Definition at line 947 of file regproc.c.

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

948 {
950  Oid result;
951  List *names;
952 
953  /*
954  * Parse the name into components and see if it matches any pg_class
955  * entries in the current search path.
956  */
957  names = stringToQualifiedNameList(class_name);
958 
959  /* We might not even have permissions on this relation; don't lock it. */
960  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, true);
961 
962  if (OidIsValid(result))
963  PG_RETURN_OID(result);
964  else
965  PG_RETURN_NULL();
966 }
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:53
return result
Definition: formatting.c:1632
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2980
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define NoLock
Definition: lockdefs.h:34
const char * class_name
Definition: selinux.c:32
char * text_to_cstring(const text *t)
Definition: varlena.c:182
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum to_regnamespace ( PG_FUNCTION_ARGS  )

Definition at line 1587 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, result, stringToQualifiedNameList(), strVal, and text_to_cstring().

1588 {
1589  char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1590  Oid result;
1591  List *names;
1592 
1593  names = stringToQualifiedNameList(nsp_name);
1594 
1595  if (list_length(names) != 1)
1596  ereport(ERROR,
1597  (errcode(ERRCODE_INVALID_NAME),
1598  errmsg("invalid name syntax")));
1599 
1600  result = get_namespace_oid(strVal(linitial(names)), true);
1601 
1602  if (OidIsValid(result))
1603  PG_RETURN_OID(result);
1604  else
1605  PG_RETURN_NULL();
1606 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:2962
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static int list_length(const List *l)
Definition: pg_list.h:89
char * text_to_cstring(const text *t)
Definition: varlena.c:182
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum to_regoper ( PG_FUNCTION_ARGS  )

Definition at line 538 of file regproc.c.

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

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

Definition at line 715 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, result, and text_to_cstring().

716 {
717  char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
718  Oid result;
719  List *names;
720  int nargs;
721  Oid argtypes[FUNC_MAX_ARGS];
722 
723  /*
724  * Parse the name and arguments, look up potential matches in the current
725  * namespace search list, and scan to see which one exactly matches the
726  * given argument types. (There will not be more than one match.)
727  */
728  parseNameAndArgTypes(opr_name_or_oid, true, &names, &nargs, argtypes);
729  if (nargs == 1)
730  ereport(ERROR,
731  (errcode(ERRCODE_UNDEFINED_PARAMETER),
732  errmsg("missing argument"),
733  errhint("Use NONE to denote the missing argument of a unary operator.")));
734  if (nargs != 2)
735  ereport(ERROR,
736  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
737  errmsg("too many arguments"),
738  errhint("Provide two argument types for operator.")));
739 
740  result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
741 
742  if (!OidIsValid(result))
743  PG_RETURN_NULL();
744 
745  PG_RETURN_OID(result);
746 }
int errhint(const char *fmt,...)
Definition: elog.c:987
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define FUNC_MAX_ARGS
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1445
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes)
Definition: regproc.c:1735
char * text_to_cstring(const text *t)
Definition: varlena.c:182
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum to_regproc ( PG_FUNCTION_ARGS  )

Definition at line 120 of file regproc.c.

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

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

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

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

Definition at line 1462 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, result, stringToQualifiedNameList(), strVal, and text_to_cstring().

1463 {
1464  char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1465  Oid result;
1466  List *names;
1467 
1468  names = stringToQualifiedNameList(role_name);
1469 
1470  if (list_length(names) != 1)
1471  ereport(ERROR,
1472  (errcode(ERRCODE_INVALID_NAME),
1473  errmsg("invalid name syntax")));
1474 
1475  result = get_role_oid(strVal(linitial(names)), true);
1476 
1477  if (OidIsValid(result))
1478  PG_RETURN_OID(result);
1479  else
1480  PG_RETURN_NULL();
1481 }
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5096
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static int list_length(const List *l)
Definition: pg_list.h:89
char * text_to_cstring(const text *t)
Definition: varlena.c:182
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1687
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: pg_list.h:45
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum to_regtype ( PG_FUNCTION_ARGS  )

Definition at line 1102 of file regproc.c.

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

1103 {
1104  char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1105  Oid result;
1106  int32 typmod;
1107 
1108  /*
1109  * Invoke the full parser to deal with special cases such as array syntax.
1110  */
1111  parseTypeString(typ_name, &result, &typmod, true);
1112 
1113  if (OidIsValid(result))
1114  PG_RETURN_OID(result);
1115  else
1116  PG_RETURN_NULL();
1117 }
return result
Definition: formatting.c:1632
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
signed int int32
Definition: c.h:256
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
void parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:781
char * text_to_cstring(const text *t)
Definition: varlena.c:182
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
#define PG_RETURN_NULL()
Definition: fmgr.h:305