PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
regproc.h File Reference
#include "nodes/pg_list.h"
Include dependency graph for regproc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FORMAT_PROC_INVALID_AS_NULL   0x01 /* NULL if undefined */
 
#define FORMAT_PROC_FORCE_QUALIFY   0x02 /* force qualification */
 
#define FORMAT_OPERATOR_INVALID_AS_NULL   0x01 /* NULL if undefined */
 
#define FORMAT_OPERATOR_FORCE_QUALIFY   0x02 /* force qualification */
 

Functions

char * format_procedure_extended (Oid procedure_oid, bits16 flags)
 
char * format_operator_extended (Oid operator_oid, bits16 flags)
 
ListstringToQualifiedNameList (const char *string, Node *escontext)
 
char * format_procedure (Oid procedure_oid)
 
char * format_procedure_qualified (Oid procedure_oid)
 
void format_procedure_parts (Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
 
char * format_operator (Oid operator_oid)
 
char * format_operator_qualified (Oid operator_oid)
 
void format_operator_parts (Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
 

Macro Definition Documentation

◆ FORMAT_OPERATOR_FORCE_QUALIFY

#define FORMAT_OPERATOR_FORCE_QUALIFY   0x02 /* force qualification */

Definition at line 25 of file regproc.h.

◆ FORMAT_OPERATOR_INVALID_AS_NULL

#define FORMAT_OPERATOR_INVALID_AS_NULL   0x01 /* NULL if undefined */

Definition at line 24 of file regproc.h.

◆ FORMAT_PROC_FORCE_QUALIFY

#define FORMAT_PROC_FORCE_QUALIFY   0x02 /* force qualification */

Definition at line 20 of file regproc.h.

◆ FORMAT_PROC_INVALID_AS_NULL

#define FORMAT_PROC_INVALID_AS_NULL   0x01 /* NULL if undefined */

Definition at line 19 of file regproc.h.

Function Documentation

◆ format_operator()

char* format_operator ( Oid  operator_oid)

Definition at line 793 of file regproc.c.

794 {
795  return format_operator_extended(operator_oid, 0);
796 }
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:722

References format_operator_extended().

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

◆ format_operator_extended()

char* format_operator_extended ( Oid  operator_oid,
bits16  flags 
)

Definition at line 722 of file regproc.c.

723 {
724  char *result;
725  HeapTuple opertup;
726 
727  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
728 
729  if (HeapTupleIsValid(opertup))
730  {
731  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
732  char *oprname = NameStr(operform->oprname);
733  char *nspname;
735 
736  /* XXX no support here for bootstrap mode */
738 
740 
741  /*
742  * Would this oper be found (given the right args) by regoperatorin?
743  * If not, or if caller explicitly requests it, we need to qualify it.
744  */
745  if ((flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ||
746  !OperatorIsVisible(operator_oid))
747  {
748  nspname = get_namespace_name(operform->oprnamespace);
749  appendStringInfo(&buf, "%s.",
750  quote_identifier(nspname));
751  }
752 
753  appendStringInfo(&buf, "%s(", oprname);
754 
755  if (operform->oprleft)
756  appendStringInfo(&buf, "%s,",
757  (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
758  format_type_be_qualified(operform->oprleft) :
759  format_type_be(operform->oprleft));
760  else
761  appendStringInfoString(&buf, "NONE,");
762 
763  if (operform->oprright)
764  appendStringInfo(&buf, "%s)",
765  (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
766  format_type_be_qualified(operform->oprright) :
767  format_type_be(operform->oprright));
768  else
769  appendStringInfoString(&buf, "NONE)");
770 
771  result = buf.data;
772 
773  ReleaseSysCache(opertup);
774  }
775  else if ((flags & FORMAT_OPERATOR_INVALID_AS_NULL) != 0)
776  {
777  /* If object is undefined, return NULL as wanted by caller */
778  result = NULL;
779  }
780  else
781  {
782  /*
783  * If OID doesn't match any pg_operator entry, return it numerically
784  */
785  result = (char *) palloc(NAMEDATALEN);
786  snprintf(result, NAMEDATALEN, "%u", operator_oid);
787  }
788 
789  return result;
790 }
#define NameStr(name)
Definition: c.h:751
#define Assert(condition)
Definition: c.h:863
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:353
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
void * palloc(Size size)
Definition: mcxt.c:1317
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:454
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:2049
#define NAMEDATALEN
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
static char * buf
Definition: pg_test_fsync.c:72
#define snprintf
Definition: port.h:238
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:12868
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:94
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:179
void initStringInfo(StringInfo str)
Definition: stringinfo.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221

References appendStringInfo(), appendStringInfoString(), Assert, buf, FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_type_be(), format_type_be_qualified(), get_namespace_name(), GETSTRUCT, HeapTupleIsValid, initStringInfo(), IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), OperatorIsVisible(), palloc(), quote_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

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

◆ format_operator_parts()

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

Definition at line 806 of file regproc.c.

808 {
809  HeapTuple opertup;
810  Form_pg_operator oprForm;
811 
812  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
813  if (!HeapTupleIsValid(opertup))
814  {
815  if (!missing_ok)
816  elog(ERROR, "cache lookup failed for operator with OID %u",
817  operator_oid);
818  return;
819  }
820 
821  oprForm = (Form_pg_operator) GETSTRUCT(opertup);
822  *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
823  pstrdup(NameStr(oprForm->oprname)));
824  *objargs = NIL;
825  if (oprForm->oprleft)
826  *objargs = lappend(*objargs,
827  format_type_be_qualified(oprForm->oprleft));
828  if (oprForm->oprright)
829  *objargs = lappend(*objargs,
830  format_type_be_qualified(oprForm->oprright));
831 
832  ReleaseSysCache(opertup);
833 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
List * lappend(List *list, void *datum)
Definition: list.c:339
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3390
char * pstrdup(const char *in)
Definition: mcxt.c:1696
#define NIL
Definition: pg_list.h:68
#define list_make2(x1, x2)
Definition: pg_list.h:214

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

Referenced by getObjectIdentityParts().

◆ format_operator_qualified()

char* format_operator_qualified ( Oid  operator_oid)

Definition at line 799 of file regproc.c.

800 {
801  return format_operator_extended(operator_oid,
803 }

References format_operator_extended(), and FORMAT_OPERATOR_FORCE_QUALIFY.

◆ format_procedure()

char* format_procedure ( Oid  procedure_oid)

◆ format_procedure_extended()

char* format_procedure_extended ( Oid  procedure_oid,
bits16  flags 
)

Definition at line 326 of file regproc.c.

327 {
328  char *result;
329  HeapTuple proctup;
330 
331  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
332 
333  if (HeapTupleIsValid(proctup))
334  {
335  Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
336  char *proname = NameStr(procform->proname);
337  int nargs = procform->pronargs;
338  int i;
339  char *nspname;
341 
342  /* XXX no support here for bootstrap mode */
344 
346 
347  /*
348  * Would this proc be found (given the right args) by regprocedurein?
349  * If not, or if caller requests it, we need to qualify it.
350  */
351  if ((flags & FORMAT_PROC_FORCE_QUALIFY) == 0 &&
352  FunctionIsVisible(procedure_oid))
353  nspname = NULL;
354  else
355  nspname = get_namespace_name(procform->pronamespace);
356 
357  appendStringInfo(&buf, "%s(",
359  for (i = 0; i < nargs; i++)
360  {
361  Oid thisargtype = procform->proargtypes.values[i];
362 
363  if (i > 0)
364  appendStringInfoChar(&buf, ',');
366  (flags & FORMAT_PROC_FORCE_QUALIFY) != 0 ?
367  format_type_be_qualified(thisargtype) :
368  format_type_be(thisargtype));
369  }
370  appendStringInfoChar(&buf, ')');
371 
372  result = buf.data;
373 
374  ReleaseSysCache(proctup);
375  }
376  else if ((flags & FORMAT_PROC_INVALID_AS_NULL) != 0)
377  {
378  /* If object is undefined, return NULL as wanted by caller */
379  result = NULL;
380  }
381  else
382  {
383  /* If OID doesn't match any pg_proc entry, return it numerically */
384  result = (char *) palloc(NAMEDATALEN);
385  snprintf(result, NAMEDATALEN, "%u", procedure_oid);
386  }
387 
388  return result;
389 }
int i
Definition: isn.c:72
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1696
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
NameData proname
Definition: pg_proc.h:35
unsigned int Oid
Definition: postgres_ext.h:31
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:12952
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:191

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, buf, FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_type_be(), format_type_be_qualified(), FunctionIsVisible(), get_namespace_name(), GETSTRUCT, HeapTupleIsValid, i, initStringInfo(), IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), proname, quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

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

◆ format_procedure_parts()

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

Definition at line 398 of file regproc.c.

400 {
401  HeapTuple proctup;
402  Form_pg_proc procform;
403  int nargs;
404  int i;
405 
406  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
407 
408  if (!HeapTupleIsValid(proctup))
409  {
410  if (!missing_ok)
411  elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
412  return;
413  }
414 
415  procform = (Form_pg_proc) GETSTRUCT(proctup);
416  nargs = procform->pronargs;
417 
418  *objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
419  pstrdup(NameStr(procform->proname)));
420  *objargs = NIL;
421  for (i = 0; i < nargs; i++)
422  {
423  Oid thisargtype = procform->proargtypes.values[i];
424 
425  *objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
426  }
427 
428  ReleaseSysCache(proctup);
429 }

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

Referenced by getObjectIdentityParts().

◆ format_procedure_qualified()

char* format_procedure_qualified ( Oid  procedure_oid)

Definition at line 305 of file regproc.c.

306 {
308 }

References FORMAT_PROC_FORCE_QUALIFY, and format_procedure_extended().

◆ stringToQualifiedNameList()

List* stringToQualifiedNameList ( const char *  string,
Node escontext 
)

Definition at line 1797 of file regproc.c.

1798 {
1799  char *rawname;
1800  List *result = NIL;
1801  List *namelist;
1802  ListCell *l;
1803 
1804  /* We need a modifiable copy of the input string. */
1805  rawname = pstrdup(string);
1806 
1807  if (!SplitIdentifierString(rawname, '.', &namelist))
1808  ereturn(escontext, NIL,
1809  (errcode(ERRCODE_INVALID_NAME),
1810  errmsg("invalid name syntax")));
1811 
1812  if (namelist == NIL)
1813  ereturn(escontext, NIL,
1814  (errcode(ERRCODE_INVALID_NAME),
1815  errmsg("invalid name syntax")));
1816 
1817  foreach(l, namelist)
1818  {
1819  char *curname = (char *) lfirst(l);
1820 
1821  result = lappend(result, makeString(pstrdup(curname)));
1822  }
1823 
1824  pfree(rawname);
1825  list_free(namelist);
1826 
1827  return result;
1828 }
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereturn(context, dummy_value,...)
Definition: elog.h:277
void list_free(List *list)
Definition: list.c:1546
void pfree(void *pointer)
Definition: mcxt.c:1521
#define lfirst(lc)
Definition: pg_list.h:172
Definition: pg_list.h:54
String * makeString(char *str)
Definition: value.c:63
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3432

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

Referenced by call_pltcl_start_proc(), check_default_text_search_config(), getTSCurrentConfig(), parseNameAndArgTypes(), regclassin(), regcollationin(), regconfigin(), regdictionaryin(), regnamespacein(), regoperin(), regprocin(), regrolein(), RelationNameGetTupleDesc(), thesaurus_init(), and tsvector_update_trigger().