PostgreSQL Source Code  git master
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)
 
char * format_procedure (Oid procedure_oid)
 
char * format_procedure_qualified (Oid procedure_oid)
 
void format_procedure_parts (Oid operator_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 */

◆ FORMAT_OPERATOR_INVALID_AS_NULL

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

◆ FORMAT_PROC_FORCE_QUALIFY

#define FORMAT_PROC_FORCE_QUALIFY   0x02 /* force qualification */

◆ FORMAT_PROC_INVALID_AS_NULL

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

Function Documentation

◆ format_operator()

char* format_operator ( Oid  operator_oid)

Definition at line 852 of file regproc.c.

References format_operator_extended().

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

853 {
854  return format_operator_extended(operator_oid, 0);
855 }
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:781

◆ format_operator_extended()

char* format_operator_extended ( Oid  operator_oid,
bits16  flags 
)

Definition at line 781 of file regproc.c.

References appendStringInfo(), appendStringInfoString(), Assert, buf, StringInfoData::data, 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(), OPEROID, palloc(), quote_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

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

782 {
783  char *result;
784  HeapTuple opertup;
785 
786  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
787 
788  if (HeapTupleIsValid(opertup))
789  {
790  Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
791  char *oprname = NameStr(operform->oprname);
792  char *nspname;
794 
795  /* XXX no support here for bootstrap mode */
797 
798  initStringInfo(&buf);
799 
800  /*
801  * Would this oper be found (given the right args) by regoperatorin?
802  * If not, or if caller explicitly requests it, we need to qualify it.
803  */
804  if ((flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ||
805  !OperatorIsVisible(operator_oid))
806  {
807  nspname = get_namespace_name(operform->oprnamespace);
808  appendStringInfo(&buf, "%s.",
809  quote_identifier(nspname));
810  }
811 
812  appendStringInfo(&buf, "%s(", oprname);
813 
814  if (operform->oprleft)
815  appendStringInfo(&buf, "%s,",
816  (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
817  format_type_be_qualified(operform->oprleft) :
818  format_type_be(operform->oprleft));
819  else
820  appendStringInfoString(&buf, "NONE,");
821 
822  if (operform->oprright)
823  appendStringInfo(&buf, "%s)",
824  (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
825  format_type_be_qualified(operform->oprright) :
826  format_type_be(operform->oprright));
827  else
828  appendStringInfoString(&buf, "NONE)");
829 
830  result = buf.data;
831 
832  ReleaseSysCache(opertup);
833  }
834  else if ((flags & FORMAT_OPERATOR_INVALID_AS_NULL) != 0)
835  {
836  /* If object is undefined, return NULL as wanted by caller */
837  result = NULL;
838  }
839  else
840  {
841  /*
842  * If OID doesn't match any pg_operator entry, return it numerically
843  */
844  result = (char *) palloc(NAMEDATALEN);
845  snprintf(result, NAMEDATALEN, "%u", operator_oid);
846  }
847 
848  return result;
849 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:11374
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:1792
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define NAMEDATALEN
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3316
static char * buf
Definition: pg_test_fsync.c:68
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:804
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:406
void * palloc(Size size)
Definition: mcxt.c:1062
#define NameStr(name)
Definition: c.h:681
#define snprintf
Definition: port.h:216
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25

◆ format_operator_parts()

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

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

867 {
868  HeapTuple opertup;
869  Form_pg_operator oprForm;
870 
871  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
872  if (!HeapTupleIsValid(opertup))
873  {
874  if (!missing_ok)
875  elog(ERROR, "cache lookup failed for operator with OID %u",
876  operator_oid);
877  return;
878  }
879 
880  oprForm = (Form_pg_operator) GETSTRUCT(opertup);
881  *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
882  pstrdup(NameStr(oprForm->oprname)));
883  *objargs = NIL;
884  if (oprForm->oprleft)
885  *objargs = lappend(*objargs,
886  format_type_be_qualified(oprForm->oprleft));
887  if (oprForm->oprright)
888  *objargs = lappend(*objargs,
889  format_type_be_qualified(oprForm->oprright));
890 
891  ReleaseSysCache(opertup);
892 }
#define list_make2(x1, x2)
Definition: pg_list.h:208
#define NIL
Definition: pg_list.h:65
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
char * pstrdup(const char *in)
Definition: mcxt.c:1299
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
List * lappend(List *list, void *datum)
Definition: list.c:336
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3340
#define elog(elevel,...)
Definition: elog.h:232
#define NameStr(name)
Definition: c.h:681

◆ format_operator_qualified()

char* format_operator_qualified ( Oid  operator_oid)

Definition at line 858 of file regproc.c.

References format_operator_extended(), and FORMAT_OPERATOR_FORCE_QUALIFY.

859 {
860  return format_operator_extended(operator_oid,
862 }
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:781
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25

◆ format_procedure()

char* format_procedure ( Oid  procedure_oid)

Definition at line 323 of file regproc.c.

References format_procedure_extended().

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

324 {
325  return format_procedure_extended(procedure_oid, 0);
326 }
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:350

◆ format_procedure_extended()

char* format_procedure_extended ( Oid  procedure_oid,
bits16  flags 
)

Definition at line 350 of file regproc.c.

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, buf, StringInfoData::data, 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(), PROCOID, proname, quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

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

351 {
352  char *result;
353  HeapTuple proctup;
354 
355  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
356 
357  if (HeapTupleIsValid(proctup))
358  {
359  Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
360  char *proname = NameStr(procform->proname);
361  int nargs = procform->pronargs;
362  int i;
363  char *nspname;
365 
366  /* XXX no support here for bootstrap mode */
368 
369  initStringInfo(&buf);
370 
371  /*
372  * Would this proc be found (given the right args) by regprocedurein?
373  * If not, or if caller requests it, we need to qualify it.
374  */
375  if ((flags & FORMAT_PROC_FORCE_QUALIFY) == 0 &&
376  FunctionIsVisible(procedure_oid))
377  nspname = NULL;
378  else
379  nspname = get_namespace_name(procform->pronamespace);
380 
381  appendStringInfo(&buf, "%s(",
382  quote_qualified_identifier(nspname, proname));
383  for (i = 0; i < nargs; i++)
384  {
385  Oid thisargtype = procform->proargtypes.values[i];
386 
387  if (i > 0)
388  appendStringInfoChar(&buf, ',');
390  (flags & FORMAT_PROC_FORCE_QUALIFY) != 0 ?
391  format_type_be_qualified(thisargtype) :
392  format_type_be(thisargtype));
393  }
394  appendStringInfoChar(&buf, ')');
395 
396  result = buf.data;
397 
398  ReleaseSysCache(proctup);
399  }
400  else if ((flags & FORMAT_PROC_INVALID_AS_NULL) != 0)
401  {
402  /* If object is undefined, return NULL as wanted by caller */
403  result = NULL;
404  }
405  else
406  {
407  /* If OID doesn't match any pg_proc entry, return it numerically */
408  result = (char *) palloc(NAMEDATALEN);
409  snprintf(result, NAMEDATALEN, "%u", procedure_oid);
410  }
411 
412  return result;
413 }
NameData proname
Definition: pg_proc.h:35
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1458
unsigned int Oid
Definition: postgres_ext.h:31
#define NAMEDATALEN
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3316
static char * buf
Definition: pg_test_fsync.c:68
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:11458
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:804
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:406
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20
void * palloc(Size size)
Definition: mcxt.c:1062
int i
#define NameStr(name)
Definition: c.h:681
#define snprintf
Definition: port.h:216

◆ format_procedure_parts()

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

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

424 {
425  HeapTuple proctup;
426  Form_pg_proc procform;
427  int nargs;
428  int i;
429 
430  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
431 
432  if (!HeapTupleIsValid(proctup))
433  {
434  if (!missing_ok)
435  elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
436  return;
437  }
438 
439  procform = (Form_pg_proc) GETSTRUCT(proctup);
440  nargs = procform->pronargs;
441 
442  *objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
443  pstrdup(NameStr(procform->proname)));
444  *objargs = NIL;
445  for (i = 0; i < nargs; i++)
446  {
447  Oid thisargtype = procform->proargtypes.values[i];
448 
449  *objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
450  }
451 
452  ReleaseSysCache(proctup);
453 }
#define list_make2(x1, x2)
Definition: pg_list.h:208
#define NIL
Definition: pg_list.h:65
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
char * pstrdup(const char *in)
Definition: mcxt.c:1299
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
List * lappend(List *list, void *datum)
Definition: list.c:336
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3340
#define elog(elevel,...)
Definition: elog.h:232
int i
#define NameStr(name)
Definition: c.h:681

◆ format_procedure_qualified()

char* format_procedure_qualified ( Oid  procedure_oid)

Definition at line 329 of file regproc.c.

References FORMAT_PROC_FORCE_QUALIFY, and format_procedure_extended().

330 {
332 }
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:350
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20

◆ stringToQualifiedNameList()

List* stringToQualifiedNameList ( const char *  string)

Definition at line 1877 of file regproc.c.

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

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

1878 {
1879  char *rawname;
1880  List *result = NIL;
1881  List *namelist;
1882  ListCell *l;
1883 
1884  /* We need a modifiable copy of the input string. */
1885  rawname = pstrdup(string);
1886 
1887  if (!SplitIdentifierString(rawname, '.', &namelist))
1888  ereport(ERROR,
1889  (errcode(ERRCODE_INVALID_NAME),
1890  errmsg("invalid name syntax")));
1891 
1892  if (namelist == NIL)
1893  ereport(ERROR,
1894  (errcode(ERRCODE_INVALID_NAME),
1895  errmsg("invalid name syntax")));
1896 
1897  foreach(l, namelist)
1898  {
1899  char *curname = (char *) lfirst(l);
1900 
1901  result = lappend(result, makeString(pstrdup(curname)));
1902  }
1903 
1904  pfree(rawname);
1905  list_free(namelist);
1906 
1907  return result;
1908 }
#define NIL
Definition: pg_list.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1299
int errcode(int sqlerrcode)
Definition: elog.c:698
String * makeString(char *str)
Definition: value.c:51
void pfree(void *pointer)
Definition: mcxt.c:1169
#define ERROR
Definition: elog.h:46
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3746
List * lappend(List *list, void *datum)
Definition: list.c:336
#define ereport(elevel,...)
Definition: elog.h:157
#define lfirst(lc)
Definition: pg_list.h:169
int errmsg(const char *fmt,...)
Definition: elog.c:909
void list_free(List *list)
Definition: list.c:1391
Definition: pg_list.h:50