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

References format_operator_internal().

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

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

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

755 {
756  char *result;
757  HeapTuple opertup;
758 
759  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
760 
761  if (HeapTupleIsValid(opertup))
762  {
763  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
764  char *oprname = NameStr(operform->oprname);
765  char *nspname;
767 
768  /* XXX no support here for bootstrap mode */
770 
771  initStringInfo(&buf);
772 
773  /*
774  * Would this oper be found (given the right args) by regoperatorin?
775  * If not, or if caller explicitly requests it, we need to qualify it.
776  */
777  if (force_qualify || !OperatorIsVisible(operator_oid))
778  {
779  nspname = get_namespace_name(operform->oprnamespace);
780  appendStringInfo(&buf, "%s.",
781  quote_identifier(nspname));
782  }
783 
784  appendStringInfo(&buf, "%s(", oprname);
785 
786  if (operform->oprleft)
787  appendStringInfo(&buf, "%s,",
788  force_qualify ?
789  format_type_be_qualified(operform->oprleft) :
790  format_type_be(operform->oprleft));
791  else
792  appendStringInfoString(&buf, "NONE,");
793 
794  if (operform->oprright)
795  appendStringInfo(&buf, "%s)",
796  force_qualify ?
797  format_type_be_qualified(operform->oprright) :
798  format_type_be(operform->oprright));
799  else
800  appendStringInfoString(&buf, "NONE)");
801 
802  result = buf.data;
803 
804  ReleaseSysCache(opertup);
805  }
806  else
807  {
808  /*
809  * If OID doesn't match any pg_operator entry, return it numerically
810  */
811  result = (char *) palloc(NAMEDATALEN);
812  snprintf(result, NAMEDATALEN, "%u", operator_oid);
813  }
814 
815  return result;
816 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10284
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:365
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 831 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().

832 {
833  HeapTuple opertup;
834  Form_pg_operator oprForm;
835 
836  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
837  if (!HeapTupleIsValid(opertup))
838  elog(ERROR, "cache lookup failed for operator with OID %u",
839  operator_oid);
840 
841  oprForm = (Form_pg_operator) GETSTRUCT(opertup);
842  *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
843  pstrdup(NameStr(oprForm->oprname)));
844  *objargs = NIL;
845  if (oprForm->oprleft)
846  *objargs = lappend(*objargs,
847  format_type_be_qualified(oprForm->oprleft));
848  if (oprForm->oprright)
849  *objargs = lappend(*objargs,
850  format_type_be_qualified(oprForm->oprright));
851 
852  ReleaseSysCache(opertup);
853 }
#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 825 of file regproc.c.

References format_operator_internal().

Referenced by getObjectIdentityParts().

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

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

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

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

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

408 {
409  HeapTuple proctup;
410  Form_pg_proc procform;
411  int nargs;
412  int i;
413 
414  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
415 
416  if (!HeapTupleIsValid(proctup))
417  elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
418 
419  procform = (Form_pg_proc) GETSTRUCT(proctup);
420  nargs = procform->pronargs;
421 
422  *objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
423  pstrdup(NameStr(procform->proname)));
424  *objargs = NIL;
425  for (i = 0; i < nargs; i++)
426  {
427  Oid thisargtype = procform->proargtypes.values[i];
428 
429  *objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
430  }
431 
432  ReleaseSysCache(proctup);
433 }
#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 328 of file regproc.c.

References format_procedure_internal().

Referenced by getObjectIdentityParts().

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

Definition at line 1734 of file regproc.c.

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

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

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

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

903 {
904  char *class_name_or_oid = PG_GETARG_CSTRING(0);
906  List *names;
907 
908  /* '-' ? */
909  if (strcmp(class_name_or_oid, "-") == 0)
911 
912  /* Numeric OID? */
913  if (class_name_or_oid[0] >= '0' &&
914  class_name_or_oid[0] <= '9' &&
915  strspn(class_name_or_oid, "0123456789") == strlen(class_name_or_oid))
916  {
918  CStringGetDatum(class_name_or_oid)));
919  PG_RETURN_OID(result);
920  }
921 
922  /* Else it's a name, possibly schema-qualified */
923 
924  /* The rest of this wouldn't work in bootstrap mode */
926  elog(ERROR, "regclass values must be OIDs in bootstrap mode");
927 
928  /*
929  * Normal case: parse the name into components and see if it matches any
930  * pg_class entries in the current search path.
931  */
932  names = stringToQualifiedNameList(class_name_or_oid);
933 
934  /* We might not even have permissions on this relation; don't lock it. */
935  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, false);
936 
937  PG_RETURN_OID(result);
938 }
#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:365
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1686
#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 971 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().

972 {
973  Oid classid = PG_GETARG_OID(0);
974  char *result;
975  HeapTuple classtup;
976 
977  if (classid == InvalidOid)
978  {
979  result = pstrdup("-");
980  PG_RETURN_CSTRING(result);
981  }
982 
983  classtup = SearchSysCache1(RELOID, ObjectIdGetDatum(classid));
984 
985  if (HeapTupleIsValid(classtup))
986  {
987  Form_pg_class classform = (Form_pg_class) GETSTRUCT(classtup);
988  char *classname = NameStr(classform->relname);
989 
990  /*
991  * In bootstrap mode, skip the fancy namespace stuff and just return
992  * the class name. (This path is only needed for debugging output
993  * anyway.)
994  */
996  result = pstrdup(classname);
997  else
998  {
999  char *nspname;
1000 
1001  /*
1002  * Would this class be found by regclassin? If not, qualify it.
1003  */
1004  if (RelationIsVisible(classid))
1005  nspname = NULL;
1006  else
1007  nspname = get_namespace_name(classform->relnamespace);
1008 
1009  result = quote_qualified_identifier(nspname, classname);
1010  }
1011 
1012  ReleaseSysCache(classtup);
1013  }
1014  else
1015  {
1016  /* If OID doesn't match any pg_class entry, return it numerically */
1017  result = (char *) palloc(NAMEDATALEN);
1018  snprintf(result, NAMEDATALEN, "%u", classid);
1019  }
1020 
1021  PG_RETURN_CSTRING(result);
1022 }
#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:10370
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:365
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 1028 of file regproc.c.

References oidrecv().

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

Definition at line 1038 of file regproc.c.

References oidsend().

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

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

1197 {
1198  char *cfg_name_or_oid = PG_GETARG_CSTRING(0);
1199  Oid result;
1200  List *names;
1201 
1202  /* '-' ? */
1203  if (strcmp(cfg_name_or_oid, "-") == 0)
1205 
1206  /* Numeric OID? */
1207  if (cfg_name_or_oid[0] >= '0' &&
1208  cfg_name_or_oid[0] <= '9' &&
1209  strspn(cfg_name_or_oid, "0123456789") == strlen(cfg_name_or_oid))
1210  {
1212  CStringGetDatum(cfg_name_or_oid)));
1213  PG_RETURN_OID(result);
1214  }
1215 
1216  /* The rest of this wouldn't work in bootstrap mode */
1218  elog(ERROR, "regconfig values must be OIDs in bootstrap mode");
1219 
1220  /*
1221  * Normal case: parse the name into components and see if it matches any
1222  * pg_ts_config entries in the current search path.
1223  */
1224  names = stringToQualifiedNameList(cfg_name_or_oid);
1225 
1226  result = get_ts_config_oid(names, false);
1227 
1228  PG_RETURN_OID(result);
1229 }
#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:365
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1686
#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 1235 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.

1236 {
1237  Oid cfgid = PG_GETARG_OID(0);
1238  char *result;
1239  HeapTuple cfgtup;
1240 
1241  if (cfgid == InvalidOid)
1242  {
1243  result = pstrdup("-");
1244  PG_RETURN_CSTRING(result);
1245  }
1246 
1247  cfgtup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgid));
1248 
1249  if (HeapTupleIsValid(cfgtup))
1250  {
1251  Form_pg_ts_config cfgform = (Form_pg_ts_config) GETSTRUCT(cfgtup);
1252  char *cfgname = NameStr(cfgform->cfgname);
1253  char *nspname;
1254 
1255  /*
1256  * Would this config be found by regconfigin? If not, qualify it.
1257  */
1258  if (TSConfigIsVisible(cfgid))
1259  nspname = NULL;
1260  else
1261  nspname = get_namespace_name(cfgform->cfgnamespace);
1262 
1263  result = quote_qualified_identifier(nspname, cfgname);
1264 
1265  ReleaseSysCache(cfgtup);
1266  }
1267  else
1268  {
1269  /* If OID doesn't match any pg_ts_config row, return it numerically */
1270  result = (char *) palloc(NAMEDATALEN);
1271  snprintf(result, NAMEDATALEN, "%u", cfgid);
1272  }
1273 
1274  PG_RETURN_CSTRING(result);
1275 }
#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:10370
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 1281 of file regproc.c.

References oidrecv().

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

Definition at line 1291 of file regproc.c.

References oidsend().

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

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

1308 {
1309  char *dict_name_or_oid = PG_GETARG_CSTRING(0);
1310  Oid result;
1311  List *names;
1312 
1313  /* '-' ? */
1314  if (strcmp(dict_name_or_oid, "-") == 0)
1316 
1317  /* Numeric OID? */
1318  if (dict_name_or_oid[0] >= '0' &&
1319  dict_name_or_oid[0] <= '9' &&
1320  strspn(dict_name_or_oid, "0123456789") == strlen(dict_name_or_oid))
1321  {
1323  CStringGetDatum(dict_name_or_oid)));
1324  PG_RETURN_OID(result);
1325  }
1326 
1327  /* The rest of this wouldn't work in bootstrap mode */
1329  elog(ERROR, "regdictionary values must be OIDs in bootstrap mode");
1330 
1331  /*
1332  * Normal case: parse the name into components and see if it matches any
1333  * pg_ts_dict entries in the current search path.
1334  */
1335  names = stringToQualifiedNameList(dict_name_or_oid);
1336 
1337  result = get_ts_dict_oid(names, false);
1338 
1339  PG_RETURN_OID(result);
1340 }
#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:365
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1686
#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 1346 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.

1347 {
1348  Oid dictid = PG_GETARG_OID(0);
1349  char *result;
1350  HeapTuple dicttup;
1351 
1352  if (dictid == InvalidOid)
1353  {
1354  result = pstrdup("-");
1355  PG_RETURN_CSTRING(result);
1356  }
1357 
1358  dicttup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictid));
1359 
1360  if (HeapTupleIsValid(dicttup))
1361  {
1362  Form_pg_ts_dict dictform = (Form_pg_ts_dict) GETSTRUCT(dicttup);
1363  char *dictname = NameStr(dictform->dictname);
1364  char *nspname;
1365 
1366  /*
1367  * Would this dictionary be found by regdictionaryin? If not, qualify
1368  * it.
1369  */
1370  if (TSDictionaryIsVisible(dictid))
1371  nspname = NULL;
1372  else
1373  nspname = get_namespace_name(dictform->dictnamespace);
1374 
1375  result = quote_qualified_identifier(nspname, dictname);
1376 
1377  ReleaseSysCache(dicttup);
1378  }
1379  else
1380  {
1381  /* If OID doesn't match any pg_ts_dict row, return it numerically */
1382  result = (char *) palloc(NAMEDATALEN);
1383  snprintf(result, NAMEDATALEN, "%u", dictid);
1384  }
1385 
1386  PG_RETURN_CSTRING(result);
1387 }
#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:10370
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 1393 of file regproc.c.

References oidrecv().

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

Definition at line 1403 of file regproc.c.

References oidsend().

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

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

1544 {
1545  char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
1546  Oid result;
1547  List *names;
1548 
1549  /* '-' ? */
1550  if (strcmp(nsp_name_or_oid, "-") == 0)
1552 
1553  /* Numeric OID? */
1554  if (nsp_name_or_oid[0] >= '0' &&
1555  nsp_name_or_oid[0] <= '9' &&
1556  strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
1557  {
1559  CStringGetDatum(nsp_name_or_oid)));
1560  PG_RETURN_OID(result);
1561  }
1562 
1563  /* The rest of this wouldn't work in bootstrap mode */
1565  elog(ERROR, "regnamespace values must be OIDs in bootstrap mode");
1566 
1567  /* Normal case: see if the name matches any pg_namespace entry. */
1568  names = stringToQualifiedNameList(nsp_name_or_oid);
1569 
1570  if (list_length(names) != 1)
1571  ereport(ERROR,
1572  (errcode(ERRCODE_INVALID_NAME),
1573  errmsg("invalid name syntax")));
1574 
1575  result = get_namespace_oid(strVal(linitial(names)), false);
1576 
1577  PG_RETURN_OID(result);
1578 }
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:365
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1686
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 1611 of file regproc.c.

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

1612 {
1613  Oid nspid = PG_GETARG_OID(0);
1614  char *result;
1615 
1616  if (nspid == InvalidOid)
1617  {
1618  result = pstrdup("-");
1619  PG_RETURN_CSTRING(result);
1620  }
1621 
1622  result = get_namespace_name(nspid);
1623 
1624  if (result)
1625  {
1626  /* pstrdup is not really necessary, but it avoids a compiler warning */
1627  result = pstrdup(quote_identifier(result));
1628  }
1629  else
1630  {
1631  /* If OID doesn't match any namespace, return it numerically */
1632  result = (char *) palloc(NAMEDATALEN);
1633  snprintf(result, NAMEDATALEN, "%u", nspid);
1634  }
1635 
1636  PG_RETURN_CSTRING(result);
1637 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10284
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 1643 of file regproc.c.

References oidrecv().

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

Definition at line 1653 of file regproc.c.

References oidsend().

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

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

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

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

860 {
861  Oid oprid = PG_GETARG_OID(0);
862  char *result;
863 
864  if (oprid == InvalidOid)
865  result = pstrdup("0");
866  else
867  result = format_operator(oprid);
868 
869  PG_RETURN_CSTRING(result);
870 }
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:819
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 876 of file regproc.c.

References oidrecv().

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

Definition at line 886 of file regproc.c.

References oidsend().

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

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

483 {
484  char *opr_name_or_oid = PG_GETARG_CSTRING(0);
486  List *names;
487  FuncCandidateList clist;
488 
489  /* '0' ? */
490  if (strcmp(opr_name_or_oid, "0") == 0)
492 
493  /* Numeric OID? */
494  if (opr_name_or_oid[0] >= '0' &&
495  opr_name_or_oid[0] <= '9' &&
496  strspn(opr_name_or_oid, "0123456789") == strlen(opr_name_or_oid))
497  {
499  CStringGetDatum(opr_name_or_oid)));
500  PG_RETURN_OID(result);
501  }
502 
503  /* Else it's a name, possibly schema-qualified */
504 
505  /* The rest of this wouldn't work in bootstrap mode */
507  elog(ERROR, "regoper values must be OIDs in bootstrap mode");
508 
509  /*
510  * Normal case: parse the name into components and see if it matches any
511  * pg_operator entries in the current search path.
512  */
513  names = stringToQualifiedNameList(opr_name_or_oid);
514  clist = OpernameGetCandidates(names, '\0', false);
515 
516  if (clist == NULL)
517  ereport(ERROR,
518  (errcode(ERRCODE_UNDEFINED_FUNCTION),
519  errmsg("operator does not exist: %s", opr_name_or_oid)));
520  else if (clist->next != NULL)
521  ereport(ERROR,
522  (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
523  errmsg("more than one operator named %s",
524  opr_name_or_oid)));
525 
526  result = clist->oid;
527 
528  PG_RETURN_OID(result);
529 }
#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:365
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1686
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 560 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().

561 {
562  Oid oprid = PG_GETARG_OID(0);
563  char *result;
564  HeapTuple opertup;
565 
566  if (oprid == InvalidOid)
567  {
568  result = pstrdup("0");
569  PG_RETURN_CSTRING(result);
570  }
571 
572  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(oprid));
573 
574  if (HeapTupleIsValid(opertup))
575  {
576  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
577  char *oprname = NameStr(operform->oprname);
578 
579  /*
580  * In bootstrap mode, skip the fancy namespace stuff and just return
581  * the oper name. (This path is only needed for debugging output
582  * anyway.)
583  */
585  result = pstrdup(oprname);
586  else
587  {
588  FuncCandidateList clist;
589 
590  /*
591  * Would this oper be found (uniquely!) by regoperin? If not,
592  * qualify it.
593  */
594  clist = OpernameGetCandidates(list_make1(makeString(oprname)),
595  '\0', false);
596  if (clist != NULL && clist->next == NULL &&
597  clist->oid == oprid)
598  result = pstrdup(oprname);
599  else
600  {
601  const char *nspname;
602 
603  nspname = get_namespace_name(operform->oprnamespace);
604  nspname = quote_identifier(nspname);
605  result = (char *) palloc(strlen(nspname) + strlen(oprname) + 2);
606  sprintf(result, "%s.%s", nspname, oprname);
607  }
608  }
609 
610  ReleaseSysCache(opertup);
611  }
612  else
613  {
614  /*
615  * If OID doesn't match any pg_operator entry, return it numerically
616  */
617  result = (char *) palloc(NAMEDATALEN);
618  snprintf(result, NAMEDATALEN, "%u", oprid);
619  }
620 
621  PG_RETURN_CSTRING(result);
622 }
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:10284
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:365
void * palloc(Size size)
Definition: mcxt.c:849
#define NameStr(name)
Definition: c.h:499
Datum regoperrecv ( PG_FUNCTION_ARGS  )

Definition at line 628 of file regproc.c.

References oidrecv().

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

Definition at line 638 of file regproc.c.

References oidsend().

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

Definition at line 230 of file regproc.c.

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

Referenced by convert_function_name().

231 {
232  char *pro_name_or_oid = PG_GETARG_CSTRING(0);
234  List *names;
235  int nargs;
236  Oid argtypes[FUNC_MAX_ARGS];
237  FuncCandidateList clist;
238 
239  /* '-' ? */
240  if (strcmp(pro_name_or_oid, "-") == 0)
242 
243  /* Numeric OID? */
244  if (pro_name_or_oid[0] >= '0' &&
245  pro_name_or_oid[0] <= '9' &&
246  strspn(pro_name_or_oid, "0123456789") == strlen(pro_name_or_oid))
247  {
249  CStringGetDatum(pro_name_or_oid)));
250  PG_RETURN_OID(result);
251  }
252 
253  /* The rest of this wouldn't work in bootstrap mode */
255  elog(ERROR, "regprocedure values must be OIDs in bootstrap mode");
256 
257  /*
258  * Else it's a name and arguments. Parse the name and arguments, look up
259  * potential matches in the current namespace search list, and scan to see
260  * which one exactly matches the given argument types. (There will not be
261  * more than one match.)
262  */
263  parseNameAndArgTypes(pro_name_or_oid, false, &names, &nargs, argtypes);
264 
265  clist = FuncnameGetCandidates(names, nargs, NIL, false, false, false);
266 
267  for (; clist; clist = clist->next)
268  {
269  if (memcmp(clist->args, argtypes, nargs * sizeof(Oid)) == 0)
270  break;
271  }
272 
273  if (clist == NULL)
274  ereport(ERROR,
275  (errcode(ERRCODE_UNDEFINED_FUNCTION),
276  errmsg("function \"%s\" does not exist", pro_name_or_oid)));
277 
278  result = clist->oid;
279 
280  PG_RETURN_OID(result);
281 }
#define NIL
Definition: pg_list.h: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:1734
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
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 439 of file regproc.c.

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

440 {
441  RegProcedure proid = PG_GETARG_OID(0);
442  char *result;
443 
444  if (proid == InvalidOid)
445  result = pstrdup("-");
446  else
447  result = format_procedure(proid);
448 
449  PG_RETURN_CSTRING(result);
450 }
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:322
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
Datum regprocedurerecv ( PG_FUNCTION_ARGS  )

Definition at line 456 of file regproc.c.

References oidrecv().

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

Definition at line 466 of file regproc.c.

References oidsend().

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

Definition at line 61 of file regproc.c.

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

62 {
63  char *pro_name_or_oid = PG_GETARG_CSTRING(0);
65  List *names;
66  FuncCandidateList clist;
67 
68  /* '-' ? */
69  if (strcmp(pro_name_or_oid, "-") == 0)
71 
72  /* Numeric OID? */
73  if (pro_name_or_oid[0] >= '0' &&
74  pro_name_or_oid[0] <= '9' &&
75  strspn(pro_name_or_oid, "0123456789") == strlen(pro_name_or_oid))
76  {
78  CStringGetDatum(pro_name_or_oid)));
79  PG_RETURN_OID(result);
80  }
81 
82  /* Else it's a name, possibly schema-qualified */
83 
84  /*
85  * We should never get here in bootstrap mode, as all references should
86  * have been resolved by genbki.pl.
87  */
89  elog(ERROR, "regproc values must be OIDs in bootstrap mode");
90 
91  /*
92  * Normal case: parse the name into components and see if it matches any
93  * pg_proc entries in the current search path.
94  */
95  names = stringToQualifiedNameList(pro_name_or_oid);
96  clist = FuncnameGetCandidates(names, -1, NIL, false, false, false);
97 
98  if (clist == NULL)
99  ereport(ERROR,
100  (errcode(ERRCODE_UNDEFINED_FUNCTION),
101  errmsg("function \"%s\" does not exist", pro_name_or_oid)));
102  else if (clist->next != NULL)
103  ereport(ERROR,
104  (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
105  errmsg("more than one function named \"%s\"",
106  pro_name_or_oid)));
107 
108  result = clist->oid;
109 
110  PG_RETURN_OID(result);
111 }
#define NIL
Definition: pg_list.h: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:365
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1686
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 142 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().

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

Definition at line 204 of file regproc.c.

References oidrecv().

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

Definition at line 214 of file regproc.c.

References oidsend().

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

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

1419 {
1420  char *role_name_or_oid = PG_GETARG_CSTRING(0);
1421  Oid result;
1422  List *names;
1423 
1424  /* '-' ? */
1425  if (strcmp(role_name_or_oid, "-") == 0)
1427 
1428  /* Numeric OID? */
1429  if (role_name_or_oid[0] >= '0' &&
1430  role_name_or_oid[0] <= '9' &&
1431  strspn(role_name_or_oid, "0123456789") == strlen(role_name_or_oid))
1432  {
1434  CStringGetDatum(role_name_or_oid)));
1435  PG_RETURN_OID(result);
1436  }
1437 
1438  /* The rest of this wouldn't work in bootstrap mode */
1440  elog(ERROR, "regrole values must be OIDs in bootstrap mode");
1441 
1442  /* Normal case: see if the name matches any pg_authid entry. */
1443  names = stringToQualifiedNameList(role_name_or_oid);
1444 
1445  if (list_length(names) != 1)
1446  ereport(ERROR,
1447  (errcode(ERRCODE_INVALID_NAME),
1448  errmsg("invalid name syntax")));
1449 
1450  result = get_role_oid(strVal(linitial(names)), false);
1451 
1452  PG_RETURN_OID(result);
1453 }
#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:365
List * stringToQualifiedNameList(const char *string)
Definition: regproc.c:1686
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 1486 of file regproc.c.

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

1487 {
1488  Oid roleoid = PG_GETARG_OID(0);
1489  char *result;
1490 
1491  if (roleoid == InvalidOid)
1492  {
1493  result = pstrdup("-");
1494  PG_RETURN_CSTRING(result);
1495  }
1496 
1497  result = GetUserNameFromId(roleoid, true);
1498 
1499  if (result)
1500  {
1501  /* pstrdup is not really necessary, but it avoids a compiler warning */
1502  result = pstrdup(quote_identifier(result));
1503  }
1504  else
1505  {
1506  /* If OID doesn't match any role, return it numerically */
1507  result = (char *) palloc(NAMEDATALEN);
1508  snprintf(result, NAMEDATALEN, "%u", roleoid);
1509  }
1510 
1511  PG_RETURN_CSTRING(result);
1512 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10284
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 1518 of file regproc.c.

References oidrecv().

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

Definition at line 1528 of file regproc.c.

References oidsend().

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

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

1061 {
1062  char *typ_name_or_oid = PG_GETARG_CSTRING(0);
1063  Oid result = InvalidOid;
1064  int32 typmod;
1065 
1066  /* '-' ? */
1067  if (strcmp(typ_name_or_oid, "-") == 0)
1069 
1070  /* Numeric OID? */
1071  if (typ_name_or_oid[0] >= '0' &&
1072  typ_name_or_oid[0] <= '9' &&
1073  strspn(typ_name_or_oid, "0123456789") == strlen(typ_name_or_oid))
1074  {
1076  CStringGetDatum(typ_name_or_oid)));
1077  PG_RETURN_OID(result);
1078  }
1079 
1080  /* Else it's a type name, possibly schema-qualified or decorated */
1081 
1082  /* The rest of this wouldn't work in bootstrap mode */
1084  elog(ERROR, "regtype values must be OIDs in bootstrap mode");
1085 
1086  /*
1087  * Normal case: invoke the full parser to deal with special cases such as
1088  * array syntax.
1089  */
1090  parseTypeString(typ_name_or_oid, &result, &typmod, false);
1091 
1092  PG_RETURN_OID(result);
1093 }
#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:365
#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 1122 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.

1123 {
1124  Oid typid = PG_GETARG_OID(0);
1125  char *result;
1126  HeapTuple typetup;
1127 
1128  if (typid == InvalidOid)
1129  {
1130  result = pstrdup("-");
1131  PG_RETURN_CSTRING(result);
1132  }
1133 
1134  typetup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid));
1135 
1136  if (HeapTupleIsValid(typetup))
1137  {
1138  Form_pg_type typeform = (Form_pg_type) GETSTRUCT(typetup);
1139 
1140  /*
1141  * In bootstrap mode, skip the fancy namespace stuff and just return
1142  * the type name. (This path is only needed for debugging output
1143  * anyway.)
1144  */
1146  {
1147  char *typname = NameStr(typeform->typname);
1148 
1149  result = pstrdup(typname);
1150  }
1151  else
1152  result = format_type_be(typid);
1153 
1154  ReleaseSysCache(typetup);
1155  }
1156  else
1157  {
1158  /* If OID doesn't match any pg_type entry, return it numerically */
1159  result = (char *) palloc(NAMEDATALEN);
1160  snprintf(result, NAMEDATALEN, "%u", typid);
1161  }
1162 
1163  PG_RETURN_CSTRING(result);
1164 }
#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:365
void * palloc(Size size)
Definition: mcxt.c:849
#define NameStr(name)
Definition: c.h:499
Datum regtyperecv ( PG_FUNCTION_ARGS  )

Definition at line 1170 of file regproc.c.

References oidrecv().

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

Definition at line 1180 of file regproc.c.

References oidsend().

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

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

1687 {
1688  char *rawname;
1689  List *result = NIL;
1690  List *namelist;
1691  ListCell *l;
1692 
1693  /* We need a modifiable copy of the input string. */
1694  rawname = pstrdup(string);
1695 
1696  if (!SplitIdentifierString(rawname, '.', &namelist))
1697  ereport(ERROR,
1698  (errcode(ERRCODE_INVALID_NAME),
1699  errmsg("invalid name syntax")));
1700 
1701  if (namelist == NIL)
1702  ereport(ERROR,
1703  (errcode(ERRCODE_INVALID_NAME),
1704  errmsg("invalid name syntax")));
1705 
1706  foreach(l, namelist)
1707  {
1708  char *curname = (char *) lfirst(l);
1709 
1710  result = lappend(result, makeString(pstrdup(curname)));
1711  }
1712 
1713  pfree(rawname);
1714  list_free(namelist);
1715 
1716  return result;
1717 }
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:3247
#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 1667 of file regproc.c.

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

1668 {
1669  text *relname = PG_GETARG_TEXT_PP(0);
1670  Oid result;
1671  RangeVar *rv;
1672 
1674 
1675  /* We might not even have permissions on this relation; don't lock it. */
1676  result = RangeVarGetRelid(rv, NoLock, false);
1677 
1678  PG_RETURN_OID(result);
1679 }
#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:3189
Definition: c.h:439
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum to_regclass ( PG_FUNCTION_ARGS  )

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

947 {
949  Oid result;
950  List *names;
951 
952  /*
953  * Parse the name into components and see if it matches any pg_class
954  * entries in the current search path.
955  */
956  names = stringToQualifiedNameList(class_name);
957 
958  /* We might not even have permissions on this relation; don't lock it. */
959  result = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, true);
960 
961  if (OidIsValid(result))
962  PG_RETURN_OID(result);
963  else
964  PG_RETURN_NULL();
965 }
#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:1686
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 1586 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().

1587 {
1588  char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1589  Oid result;
1590  List *names;
1591 
1592  names = stringToQualifiedNameList(nsp_name);
1593 
1594  if (list_length(names) != 1)
1595  ereport(ERROR,
1596  (errcode(ERRCODE_INVALID_NAME),
1597  errmsg("invalid name syntax")));
1598 
1599  result = get_namespace_oid(strVal(linitial(names)), true);
1600 
1601  if (OidIsValid(result))
1602  PG_RETURN_OID(result);
1603  else
1604  PG_RETURN_NULL();
1605 }
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:1686
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 537 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().

538 {
539  char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
540  List *names;
541  FuncCandidateList clist;
542 
543  /*
544  * Parse the name into components and see if it matches any pg_operator
545  * entries in the current search path.
546  */
547  names = stringToQualifiedNameList(opr_name);
548  clist = OpernameGetCandidates(names, '\0', true);
549 
550  if (clist == NULL || clist->next != NULL)
551  PG_RETURN_NULL();
552 
553  PG_RETURN_OID(clist->oid);
554 }
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:1686
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 714 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().

715 {
716  char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
717  Oid result;
718  List *names;
719  int nargs;
720  Oid argtypes[FUNC_MAX_ARGS];
721 
722  /*
723  * Parse the name and arguments, look up potential matches in the current
724  * namespace search list, and scan to see which one exactly matches the
725  * given argument types. (There will not be more than one match.)
726  */
727  parseNameAndArgTypes(opr_name_or_oid, true, &names, &nargs, argtypes);
728  if (nargs == 1)
729  ereport(ERROR,
730  (errcode(ERRCODE_UNDEFINED_PARAMETER),
731  errmsg("missing argument"),
732  errhint("Use NONE to denote the missing argument of a unary operator.")));
733  if (nargs != 2)
734  ereport(ERROR,
735  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
736  errmsg("too many arguments"),
737  errhint("Provide two argument types for operator.")));
738 
739  result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
740 
741  if (!OidIsValid(result))
742  PG_RETURN_NULL();
743 
744  PG_RETURN_OID(result);
745 }
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:1734
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 119 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().

120 {
121  char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
122  List *names;
123  FuncCandidateList clist;
124 
125  /*
126  * Parse the name into components and see if it matches any pg_proc
127  * entries in the current search path.
128  */
129  names = stringToQualifiedNameList(pro_name);
130  clist = FuncnameGetCandidates(names, -1, NIL, false, false, true);
131 
132  if (clist == NULL || clist->next != NULL)
133  PG_RETURN_NULL();
134 
135  PG_RETURN_OID(clist->oid);
136 }
#define NIL
Definition: pg_list.h: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:1686
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 289 of file regproc.c.

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

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

1462 {
1463  char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1464  Oid result;
1465  List *names;
1466 
1467  names = stringToQualifiedNameList(role_name);
1468 
1469  if (list_length(names) != 1)
1470  ereport(ERROR,
1471  (errcode(ERRCODE_INVALID_NAME),
1472  errmsg("invalid name syntax")));
1473 
1474  result = get_role_oid(strVal(linitial(names)), true);
1475 
1476  if (OidIsValid(result))
1477  PG_RETURN_OID(result);
1478  else
1479  PG_RETURN_NULL();
1480 }
#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:1686
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 1101 of file regproc.c.

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

1102 {
1103  char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
1104  Oid result;
1105  int32 typmod;
1106 
1107  /*
1108  * Invoke the full parser to deal with special cases such as array syntax.
1109  */
1110  parseTypeString(typ_name, &result, &typmod, true);
1111 
1112  if (OidIsValid(result))
1113  PG_RETURN_OID(result);
1114  else
1115  PG_RETURN_NULL();
1116 }
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