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

References format_operator_extended().

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

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

◆ format_operator_extended()

char* format_operator_extended ( Oid  operator_oid,
bits16  flags 
)

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

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

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

◆ format_operator_qualified()

char* format_operator_qualified ( Oid  operator_oid)

Definition at line 857 of file regproc.c.

References format_operator_extended(), and FORMAT_OPERATOR_FORCE_QUALIFY.

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

◆ format_procedure()

char* format_procedure ( Oid  procedure_oid)

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

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

◆ format_procedure_extended()

char* format_procedure_extended ( Oid  procedure_oid,
bits16  flags 
)

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

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

◆ format_procedure_parts()

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

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

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

◆ format_procedure_qualified()

char* format_procedure_qualified ( Oid  procedure_oid)

Definition at line 328 of file regproc.c.

References FORMAT_PROC_FORCE_QUALIFY, and format_procedure_extended().

329 {
331 }
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:349
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20

◆ stringToQualifiedNameList()

List* stringToQualifiedNameList ( const char *  string)

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

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