PostgreSQL Source Code  git master
pg_proc.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_proc.c
4  * routines to support manipulation of the pg_proc relation
5  *
6  * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/catalog/pg_proc.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/htup_details.h"
18 #include "access/xact.h"
19 #include "catalog/dependency.h"
20 #include "catalog/indexing.h"
21 #include "catalog/objectaccess.h"
22 #include "catalog/pg_language.h"
23 #include "catalog/pg_namespace.h"
24 #include "catalog/pg_proc.h"
25 #include "catalog/pg_transform.h"
26 #include "catalog/pg_type.h"
27 #include "commands/defrem.h"
28 #include "executor/functions.h"
29 #include "funcapi.h"
30 #include "mb/pg_wchar.h"
31 #include "miscadmin.h"
32 #include "nodes/nodeFuncs.h"
33 #include "parser/parse_type.h"
34 #include "tcop/pquery.h"
35 #include "tcop/tcopprot.h"
36 #include "utils/acl.h"
37 #include "utils/builtins.h"
38 #include "utils/lsyscache.h"
39 #include "utils/regproc.h"
40 #include "utils/rel.h"
41 #include "utils/syscache.h"
42 
43 
44 typedef struct
45 {
46  char *proname;
47  char *prosrc;
49 
50 static void sql_function_parse_error_callback(void *arg);
51 static int match_prosrc_to_query(const char *prosrc, const char *queryText,
52  int cursorpos);
53 static bool match_prosrc_to_literal(const char *prosrc, const char *literal,
54  int cursorpos, int *newcursorpos);
55 
56 
57 /* ----------------------------------------------------------------
58  * ProcedureCreate
59  *
60  * Note: allParameterTypes, parameterModes, parameterNames, trftypes, and proconfig
61  * are either arrays of the proper types or NULL. We declare them Datum,
62  * not "ArrayType *", to avoid importing array.h into pg_proc.h.
63  * ----------------------------------------------------------------
64  */
66 ProcedureCreate(const char *procedureName,
67  Oid procNamespace,
68  bool replace,
69  bool returnsSet,
70  Oid returnType,
71  Oid proowner,
72  Oid languageObjectId,
73  Oid languageValidator,
74  const char *prosrc,
75  const char *probin,
76  char prokind,
77  bool security_definer,
78  bool isLeakProof,
79  bool isStrict,
80  char volatility,
81  char parallel,
82  oidvector *parameterTypes,
83  Datum allParameterTypes,
84  Datum parameterModes,
85  Datum parameterNames,
86  List *parameterDefaults,
87  Datum trftypes,
88  Datum proconfig,
89  float4 procost,
90  float4 prorows)
91 {
92  Oid retval;
93  int parameterCount;
94  int allParamCount;
95  Oid *allParams;
96  char *paramModes = NULL;
97  bool genericInParam = false;
98  bool genericOutParam = false;
99  bool anyrangeInParam = false;
100  bool anyrangeOutParam = false;
101  bool internalInParam = false;
102  bool internalOutParam = false;
103  Oid variadicType = InvalidOid;
104  Acl *proacl = NULL;
105  Relation rel;
106  HeapTuple tup;
107  HeapTuple oldtup;
108  bool nulls[Natts_pg_proc];
109  Datum values[Natts_pg_proc];
110  bool replaces[Natts_pg_proc];
111  NameData procname;
112  TupleDesc tupDesc;
113  bool is_update;
114  ObjectAddress myself,
115  referenced;
116  int i;
117  Oid trfid;
118 
119  /*
120  * sanity checks
121  */
122  Assert(PointerIsValid(prosrc));
123 
124  parameterCount = parameterTypes->dim1;
125  if (parameterCount < 0 || parameterCount > FUNC_MAX_ARGS)
126  ereport(ERROR,
127  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
128  errmsg_plural("functions cannot have more than %d argument",
129  "functions cannot have more than %d arguments",
130  FUNC_MAX_ARGS,
131  FUNC_MAX_ARGS)));
132  /* note: the above is correct, we do NOT count output arguments */
133 
134  /* Deconstruct array inputs */
135  if (allParameterTypes != PointerGetDatum(NULL))
136  {
137  /*
138  * We expect the array to be a 1-D OID array; verify that. We don't
139  * need to use deconstruct_array() since the array data is just going
140  * to look like a C array of OID values.
141  */
142  ArrayType *allParamArray = (ArrayType *) DatumGetPointer(allParameterTypes);
143 
144  allParamCount = ARR_DIMS(allParamArray)[0];
145  if (ARR_NDIM(allParamArray) != 1 ||
146  allParamCount <= 0 ||
147  ARR_HASNULL(allParamArray) ||
148  ARR_ELEMTYPE(allParamArray) != OIDOID)
149  elog(ERROR, "allParameterTypes is not a 1-D Oid array");
150  allParams = (Oid *) ARR_DATA_PTR(allParamArray);
151  Assert(allParamCount >= parameterCount);
152  /* we assume caller got the contents right */
153  }
154  else
155  {
156  allParamCount = parameterCount;
157  allParams = parameterTypes->values;
158  }
159 
160  if (parameterModes != PointerGetDatum(NULL))
161  {
162  /*
163  * We expect the array to be a 1-D CHAR array; verify that. We don't
164  * need to use deconstruct_array() since the array data is just going
165  * to look like a C array of char values.
166  */
167  ArrayType *modesArray = (ArrayType *) DatumGetPointer(parameterModes);
168 
169  if (ARR_NDIM(modesArray) != 1 ||
170  ARR_DIMS(modesArray)[0] != allParamCount ||
171  ARR_HASNULL(modesArray) ||
172  ARR_ELEMTYPE(modesArray) != CHAROID)
173  elog(ERROR, "parameterModes is not a 1-D char array");
174  paramModes = (char *) ARR_DATA_PTR(modesArray);
175  }
176 
177  /*
178  * Detect whether we have polymorphic or INTERNAL arguments. The first
179  * loop checks input arguments, the second output arguments.
180  */
181  for (i = 0; i < parameterCount; i++)
182  {
183  switch (parameterTypes->values[i])
184  {
185  case ANYARRAYOID:
186  case ANYELEMENTOID:
187  case ANYNONARRAYOID:
188  case ANYENUMOID:
189  genericInParam = true;
190  break;
191  case ANYRANGEOID:
192  genericInParam = true;
193  anyrangeInParam = true;
194  break;
195  case INTERNALOID:
196  internalInParam = true;
197  break;
198  }
199  }
200 
201  if (allParameterTypes != PointerGetDatum(NULL))
202  {
203  for (i = 0; i < allParamCount; i++)
204  {
205  if (paramModes == NULL ||
206  paramModes[i] == PROARGMODE_IN ||
207  paramModes[i] == PROARGMODE_VARIADIC)
208  continue; /* ignore input-only params */
209 
210  switch (allParams[i])
211  {
212  case ANYARRAYOID:
213  case ANYELEMENTOID:
214  case ANYNONARRAYOID:
215  case ANYENUMOID:
216  genericOutParam = true;
217  break;
218  case ANYRANGEOID:
219  genericOutParam = true;
220  anyrangeOutParam = true;
221  break;
222  case INTERNALOID:
223  internalOutParam = true;
224  break;
225  }
226  }
227  }
228 
229  /*
230  * Do not allow polymorphic return type unless at least one input argument
231  * is polymorphic. ANYRANGE return type is even stricter: must have an
232  * ANYRANGE input (since we can't deduce the specific range type from
233  * ANYELEMENT). Also, do not allow return type INTERNAL unless at least
234  * one input argument is INTERNAL.
235  */
236  if ((IsPolymorphicType(returnType) || genericOutParam)
237  && !genericInParam)
238  ereport(ERROR,
239  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
240  errmsg("cannot determine result data type"),
241  errdetail("A function returning a polymorphic type must have at least one polymorphic argument.")));
242 
243  if ((returnType == ANYRANGEOID || anyrangeOutParam) &&
244  !anyrangeInParam)
245  ereport(ERROR,
246  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
247  errmsg("cannot determine result data type"),
248  errdetail("A function returning \"anyrange\" must have at least one \"anyrange\" argument.")));
249 
250  if ((returnType == INTERNALOID || internalOutParam) && !internalInParam)
251  ereport(ERROR,
252  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
253  errmsg("unsafe use of pseudo-type \"internal\""),
254  errdetail("A function returning \"internal\" must have at least one \"internal\" argument.")));
255 
256  if (paramModes != NULL)
257  {
258  /*
259  * Only the last input parameter can be variadic; if it is, save its
260  * element type. Errors here are just elog since caller should have
261  * checked this already.
262  */
263  for (i = 0; i < allParamCount; i++)
264  {
265  switch (paramModes[i])
266  {
267  case PROARGMODE_IN:
268  case PROARGMODE_INOUT:
269  if (OidIsValid(variadicType))
270  elog(ERROR, "variadic parameter must be last");
271  break;
272  case PROARGMODE_OUT:
273  case PROARGMODE_TABLE:
274  /* okay */
275  break;
276  case PROARGMODE_VARIADIC:
277  if (OidIsValid(variadicType))
278  elog(ERROR, "variadic parameter must be last");
279  switch (allParams[i])
280  {
281  case ANYOID:
282  variadicType = ANYOID;
283  break;
284  case ANYARRAYOID:
285  variadicType = ANYELEMENTOID;
286  break;
287  default:
288  variadicType = get_element_type(allParams[i]);
289  if (!OidIsValid(variadicType))
290  elog(ERROR, "variadic parameter is not an array");
291  break;
292  }
293  break;
294  default:
295  elog(ERROR, "invalid parameter mode '%c'", paramModes[i]);
296  break;
297  }
298  }
299  }
300 
301  /*
302  * All seems OK; prepare the data to be inserted into pg_proc.
303  */
304 
305  for (i = 0; i < Natts_pg_proc; ++i)
306  {
307  nulls[i] = false;
308  values[i] = (Datum) 0;
309  replaces[i] = true;
310  }
311 
312  namestrcpy(&procname, procedureName);
313  values[Anum_pg_proc_proname - 1] = NameGetDatum(&procname);
314  values[Anum_pg_proc_pronamespace - 1] = ObjectIdGetDatum(procNamespace);
315  values[Anum_pg_proc_proowner - 1] = ObjectIdGetDatum(proowner);
316  values[Anum_pg_proc_prolang - 1] = ObjectIdGetDatum(languageObjectId);
317  values[Anum_pg_proc_procost - 1] = Float4GetDatum(procost);
318  values[Anum_pg_proc_prorows - 1] = Float4GetDatum(prorows);
319  values[Anum_pg_proc_provariadic - 1] = ObjectIdGetDatum(variadicType);
320  values[Anum_pg_proc_protransform - 1] = ObjectIdGetDatum(InvalidOid);
321  values[Anum_pg_proc_prokind - 1] = CharGetDatum(prokind);
322  values[Anum_pg_proc_prosecdef - 1] = BoolGetDatum(security_definer);
323  values[Anum_pg_proc_proleakproof - 1] = BoolGetDatum(isLeakProof);
324  values[Anum_pg_proc_proisstrict - 1] = BoolGetDatum(isStrict);
325  values[Anum_pg_proc_proretset - 1] = BoolGetDatum(returnsSet);
326  values[Anum_pg_proc_provolatile - 1] = CharGetDatum(volatility);
327  values[Anum_pg_proc_proparallel - 1] = CharGetDatum(parallel);
328  values[Anum_pg_proc_pronargs - 1] = UInt16GetDatum(parameterCount);
329  values[Anum_pg_proc_pronargdefaults - 1] = UInt16GetDatum(list_length(parameterDefaults));
330  values[Anum_pg_proc_prorettype - 1] = ObjectIdGetDatum(returnType);
331  values[Anum_pg_proc_proargtypes - 1] = PointerGetDatum(parameterTypes);
332  if (allParameterTypes != PointerGetDatum(NULL))
333  values[Anum_pg_proc_proallargtypes - 1] = allParameterTypes;
334  else
335  nulls[Anum_pg_proc_proallargtypes - 1] = true;
336  if (parameterModes != PointerGetDatum(NULL))
337  values[Anum_pg_proc_proargmodes - 1] = parameterModes;
338  else
339  nulls[Anum_pg_proc_proargmodes - 1] = true;
340  if (parameterNames != PointerGetDatum(NULL))
341  values[Anum_pg_proc_proargnames - 1] = parameterNames;
342  else
343  nulls[Anum_pg_proc_proargnames - 1] = true;
344  if (parameterDefaults != NIL)
345  values[Anum_pg_proc_proargdefaults - 1] = CStringGetTextDatum(nodeToString(parameterDefaults));
346  else
347  nulls[Anum_pg_proc_proargdefaults - 1] = true;
348  if (trftypes != PointerGetDatum(NULL))
349  values[Anum_pg_proc_protrftypes - 1] = trftypes;
350  else
351  nulls[Anum_pg_proc_protrftypes - 1] = true;
352  values[Anum_pg_proc_prosrc - 1] = CStringGetTextDatum(prosrc);
353  if (probin)
354  values[Anum_pg_proc_probin - 1] = CStringGetTextDatum(probin);
355  else
356  nulls[Anum_pg_proc_probin - 1] = true;
357  if (proconfig != PointerGetDatum(NULL))
358  values[Anum_pg_proc_proconfig - 1] = proconfig;
359  else
360  nulls[Anum_pg_proc_proconfig - 1] = true;
361  /* proacl will be determined later */
362 
363  rel = heap_open(ProcedureRelationId, RowExclusiveLock);
364  tupDesc = RelationGetDescr(rel);
365 
366  /* Check for pre-existing definition */
368  PointerGetDatum(procedureName),
369  PointerGetDatum(parameterTypes),
370  ObjectIdGetDatum(procNamespace));
371 
372  if (HeapTupleIsValid(oldtup))
373  {
374  /* There is one; okay to replace it? */
375  Form_pg_proc oldproc = (Form_pg_proc) GETSTRUCT(oldtup);
376  Datum proargnames;
377  bool isnull;
378 
379  if (!replace)
380  ereport(ERROR,
381  (errcode(ERRCODE_DUPLICATE_FUNCTION),
382  errmsg("function \"%s\" already exists with same argument types",
383  procedureName)));
384  if (!pg_proc_ownercheck(HeapTupleGetOid(oldtup), proowner))
386  procedureName);
387 
388  /* Not okay to change routine kind */
389  if (oldproc->prokind != prokind)
390  ereport(ERROR,
391  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
392  errmsg("cannot change routine kind"),
393  (oldproc->prokind == PROKIND_AGGREGATE ?
394  errdetail("\"%s\" is an aggregate function.", procedureName) :
395  oldproc->prokind == PROKIND_FUNCTION ?
396  errdetail("\"%s\" is a function.", procedureName) :
397  oldproc->prokind == PROKIND_PROCEDURE ?
398  errdetail("\"%s\" is a procedure.", procedureName) :
399  oldproc->prokind == PROKIND_WINDOW ?
400  errdetail("\"%s\" is a window function.", procedureName) :
401  0)));
402 
403  /*
404  * Not okay to change the return type of the existing proc, since
405  * existing rules, views, etc may depend on the return type.
406  */
407  if (returnType != oldproc->prorettype ||
408  returnsSet != oldproc->proretset)
409  ereport(ERROR,
410  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
411  errmsg("cannot change return type of existing function"),
412  errhint("Use DROP FUNCTION %s first.",
413  format_procedure(HeapTupleGetOid(oldtup)))));
414 
415  /*
416  * If it returns RECORD, check for possible change of record type
417  * implied by OUT parameters
418  */
419  if (returnType == RECORDOID)
420  {
421  TupleDesc olddesc;
422  TupleDesc newdesc;
423 
424  olddesc = build_function_result_tupdesc_t(oldtup);
425  newdesc = build_function_result_tupdesc_d(prokind,
426  allParameterTypes,
427  parameterModes,
428  parameterNames);
429  if (olddesc == NULL && newdesc == NULL)
430  /* ok, both are runtime-defined RECORDs */ ;
431  else if (olddesc == NULL || newdesc == NULL ||
432  !equalTupleDescs(olddesc, newdesc))
433  ereport(ERROR,
434  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
435  errmsg("cannot change return type of existing function"),
436  errdetail("Row type defined by OUT parameters is different."),
437  errhint("Use DROP FUNCTION %s first.",
438  format_procedure(HeapTupleGetOid(oldtup)))));
439  }
440 
441  /*
442  * If there were any named input parameters, check to make sure the
443  * names have not been changed, as this could break existing calls. We
444  * allow adding names to formerly unnamed parameters, though.
445  */
446  proargnames = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup,
447  Anum_pg_proc_proargnames,
448  &isnull);
449  if (!isnull)
450  {
451  Datum proargmodes;
452  char **old_arg_names;
453  char **new_arg_names;
454  int n_old_arg_names;
455  int n_new_arg_names;
456  int j;
457 
458  proargmodes = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup,
459  Anum_pg_proc_proargmodes,
460  &isnull);
461  if (isnull)
462  proargmodes = PointerGetDatum(NULL); /* just to be sure */
463 
464  n_old_arg_names = get_func_input_arg_names(proargnames,
465  proargmodes,
466  &old_arg_names);
467  n_new_arg_names = get_func_input_arg_names(parameterNames,
468  parameterModes,
469  &new_arg_names);
470  for (j = 0; j < n_old_arg_names; j++)
471  {
472  if (old_arg_names[j] == NULL)
473  continue;
474  if (j >= n_new_arg_names || new_arg_names[j] == NULL ||
475  strcmp(old_arg_names[j], new_arg_names[j]) != 0)
476  ereport(ERROR,
477  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
478  errmsg("cannot change name of input parameter \"%s\"",
479  old_arg_names[j]),
480  errhint("Use DROP FUNCTION %s first.",
481  format_procedure(HeapTupleGetOid(oldtup)))));
482  }
483  }
484 
485  /*
486  * If there are existing defaults, check compatibility: redefinition
487  * must not remove any defaults nor change their types. (Removing a
488  * default might cause a function to fail to satisfy an existing call.
489  * Changing type would only be possible if the associated parameter is
490  * polymorphic, and in such cases a change of default type might alter
491  * the resolved output type of existing calls.)
492  */
493  if (oldproc->pronargdefaults != 0)
494  {
495  Datum proargdefaults;
496  List *oldDefaults;
497  ListCell *oldlc;
498  ListCell *newlc;
499 
500  if (list_length(parameterDefaults) < oldproc->pronargdefaults)
501  ereport(ERROR,
502  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
503  errmsg("cannot remove parameter defaults from existing function"),
504  errhint("Use DROP FUNCTION %s first.",
505  format_procedure(HeapTupleGetOid(oldtup)))));
506 
507  proargdefaults = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup,
508  Anum_pg_proc_proargdefaults,
509  &isnull);
510  Assert(!isnull);
511  oldDefaults = castNode(List, stringToNode(TextDatumGetCString(proargdefaults)));
512  Assert(list_length(oldDefaults) == oldproc->pronargdefaults);
513 
514  /* new list can have more defaults than old, advance over 'em */
515  newlc = list_head(parameterDefaults);
516  for (i = list_length(parameterDefaults) - oldproc->pronargdefaults;
517  i > 0;
518  i--)
519  newlc = lnext(newlc);
520 
521  foreach(oldlc, oldDefaults)
522  {
523  Node *oldDef = (Node *) lfirst(oldlc);
524  Node *newDef = (Node *) lfirst(newlc);
525 
526  if (exprType(oldDef) != exprType(newDef))
527  ereport(ERROR,
528  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
529  errmsg("cannot change data type of existing parameter default value"),
530  errhint("Use DROP FUNCTION %s first.",
531  format_procedure(HeapTupleGetOid(oldtup)))));
532  newlc = lnext(newlc);
533  }
534  }
535 
536  /*
537  * Do not change existing ownership or permissions, either. Note
538  * dependency-update code below has to agree with this decision.
539  */
540  replaces[Anum_pg_proc_proowner - 1] = false;
541  replaces[Anum_pg_proc_proacl - 1] = false;
542 
543  /* Okay, do it... */
544  tup = heap_modify_tuple(oldtup, tupDesc, values, nulls, replaces);
545  CatalogTupleUpdate(rel, &tup->t_self, tup);
546 
547  ReleaseSysCache(oldtup);
548  is_update = true;
549  }
550  else
551  {
552  /* Creating a new procedure */
553 
554  /* First, get default permissions and set up proacl */
555  proacl = get_user_default_acl(OBJECT_FUNCTION, proowner,
556  procNamespace);
557  if (proacl != NULL)
558  values[Anum_pg_proc_proacl - 1] = PointerGetDatum(proacl);
559  else
560  nulls[Anum_pg_proc_proacl - 1] = true;
561 
562  tup = heap_form_tuple(tupDesc, values, nulls);
563  CatalogTupleInsert(rel, tup);
564  is_update = false;
565  }
566 
567 
568  retval = HeapTupleGetOid(tup);
569 
570  /*
571  * Create dependencies for the new function. If we are updating an
572  * existing function, first delete any existing pg_depend entries.
573  * (However, since we are not changing ownership or permissions, the
574  * shared dependencies do *not* need to change, and we leave them alone.)
575  */
576  if (is_update)
577  deleteDependencyRecordsFor(ProcedureRelationId, retval, true);
578 
579  myself.classId = ProcedureRelationId;
580  myself.objectId = retval;
581  myself.objectSubId = 0;
582 
583  /* dependency on namespace */
584  referenced.classId = NamespaceRelationId;
585  referenced.objectId = procNamespace;
586  referenced.objectSubId = 0;
587  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
588 
589  /* dependency on implementation language */
590  referenced.classId = LanguageRelationId;
591  referenced.objectId = languageObjectId;
592  referenced.objectSubId = 0;
593  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
594 
595  /* dependency on return type */
596  referenced.classId = TypeRelationId;
597  referenced.objectId = returnType;
598  referenced.objectSubId = 0;
599  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
600 
601  /* dependency on transform used by return type, if any */
602  if ((trfid = get_transform_oid(returnType, languageObjectId, true)))
603  {
604  referenced.classId = TransformRelationId;
605  referenced.objectId = trfid;
606  referenced.objectSubId = 0;
607  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
608  }
609 
610  /* dependency on parameter types */
611  for (i = 0; i < allParamCount; i++)
612  {
613  referenced.classId = TypeRelationId;
614  referenced.objectId = allParams[i];
615  referenced.objectSubId = 0;
616  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
617 
618  /* dependency on transform used by parameter type, if any */
619  if ((trfid = get_transform_oid(allParams[i], languageObjectId, true)))
620  {
621  referenced.classId = TransformRelationId;
622  referenced.objectId = trfid;
623  referenced.objectSubId = 0;
624  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
625  }
626  }
627 
628  /* dependency on parameter default expressions */
629  if (parameterDefaults)
630  recordDependencyOnExpr(&myself, (Node *) parameterDefaults,
632 
633  /* dependency on owner */
634  if (!is_update)
635  recordDependencyOnOwner(ProcedureRelationId, retval, proowner);
636 
637  /* dependency on any roles mentioned in ACL */
638  if (!is_update && proacl != NULL)
639  {
640  int nnewmembers;
641  Oid *newmembers;
642 
643  nnewmembers = aclmembers(proacl, &newmembers);
644  updateAclDependencies(ProcedureRelationId, retval, 0,
645  proowner,
646  0, NULL,
647  nnewmembers, newmembers);
648  }
649 
650  /* dependency on extension */
651  recordDependencyOnCurrentExtension(&myself, is_update);
652 
653  heap_freetuple(tup);
654 
655  /* Post creation hook for new function */
656  InvokeObjectPostCreateHook(ProcedureRelationId, retval, 0);
657 
659 
660  /* Verify function body */
661  if (OidIsValid(languageValidator))
662  {
663  ArrayType *set_items = NULL;
664  int save_nestlevel = 0;
665 
666  /* Advance command counter so new tuple can be seen by validator */
668 
669  /*
670  * Set per-function configuration parameters so that the validation is
671  * done with the environment the function expects. However, if
672  * check_function_bodies is off, we don't do this, because that would
673  * create dump ordering hazards that pg_dump doesn't know how to deal
674  * with. (For example, a SET clause might refer to a not-yet-created
675  * text search configuration.) This means that the validator
676  * shouldn't complain about anything that might depend on a GUC
677  * parameter when check_function_bodies is off.
678  */
680  {
681  set_items = (ArrayType *) DatumGetPointer(proconfig);
682  if (set_items) /* Need a new GUC nesting level */
683  {
684  save_nestlevel = NewGUCNestLevel();
685  ProcessGUCArray(set_items,
689  }
690  }
691 
692  OidFunctionCall1(languageValidator, ObjectIdGetDatum(retval));
693 
694  if (set_items)
695  AtEOXact_GUC(true, save_nestlevel);
696  }
697 
698  return myself;
699 }
700 
701 
702 
703 /*
704  * Validator for internal functions
705  *
706  * Check that the given internal function name (the "prosrc" value) is
707  * a known builtin function.
708  */
709 Datum
711 {
712  Oid funcoid = PG_GETARG_OID(0);
713  HeapTuple tuple;
714  bool isnull;
715  Datum tmp;
716  char *prosrc;
717 
718  if (!CheckFunctionValidatorAccess(fcinfo->flinfo->fn_oid, funcoid))
719  PG_RETURN_VOID();
720 
721  /*
722  * We do not honor check_function_bodies since it's unlikely the function
723  * name will be found later if it isn't there now.
724  */
725 
726  tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
727  if (!HeapTupleIsValid(tuple))
728  elog(ERROR, "cache lookup failed for function %u", funcoid);
729 
730  tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
731  if (isnull)
732  elog(ERROR, "null prosrc");
733  prosrc = TextDatumGetCString(tmp);
734 
735  if (fmgr_internal_function(prosrc) == InvalidOid)
736  ereport(ERROR,
737  (errcode(ERRCODE_UNDEFINED_FUNCTION),
738  errmsg("there is no built-in function named \"%s\"",
739  prosrc)));
740 
741  ReleaseSysCache(tuple);
742 
743  PG_RETURN_VOID();
744 }
745 
746 
747 
748 /*
749  * Validator for C language functions
750  *
751  * Make sure that the library file exists, is loadable, and contains
752  * the specified link symbol. Also check for a valid function
753  * information record.
754  */
755 Datum
757 {
758  Oid funcoid = PG_GETARG_OID(0);
759  void *libraryhandle;
760  HeapTuple tuple;
761  bool isnull;
762  Datum tmp;
763  char *prosrc;
764  char *probin;
765 
766  if (!CheckFunctionValidatorAccess(fcinfo->flinfo->fn_oid, funcoid))
767  PG_RETURN_VOID();
768 
769  /*
770  * It'd be most consistent to skip the check if !check_function_bodies,
771  * but the purpose of that switch is to be helpful for pg_dump loading,
772  * and for pg_dump loading it's much better if we *do* check.
773  */
774 
775  tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
776  if (!HeapTupleIsValid(tuple))
777  elog(ERROR, "cache lookup failed for function %u", funcoid);
778 
779  tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
780  if (isnull)
781  elog(ERROR, "null prosrc for C function %u", funcoid);
782  prosrc = TextDatumGetCString(tmp);
783 
784  tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_probin, &isnull);
785  if (isnull)
786  elog(ERROR, "null probin for C function %u", funcoid);
787  probin = TextDatumGetCString(tmp);
788 
789  (void) load_external_function(probin, prosrc, true, &libraryhandle);
790  (void) fetch_finfo_record(libraryhandle, prosrc);
791 
792  ReleaseSysCache(tuple);
793 
794  PG_RETURN_VOID();
795 }
796 
797 
798 /*
799  * Validator for SQL language functions
800  *
801  * Parse it here in order to be sure that it contains no syntax errors.
802  */
803 Datum
805 {
806  Oid funcoid = PG_GETARG_OID(0);
807  HeapTuple tuple;
808  Form_pg_proc proc;
809  List *raw_parsetree_list;
810  List *querytree_list;
811  ListCell *lc;
812  bool isnull;
813  Datum tmp;
814  char *prosrc;
815  parse_error_callback_arg callback_arg;
816  ErrorContextCallback sqlerrcontext;
817  bool haspolyarg;
818  int i;
819 
820  if (!CheckFunctionValidatorAccess(fcinfo->flinfo->fn_oid, funcoid))
821  PG_RETURN_VOID();
822 
823  tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
824  if (!HeapTupleIsValid(tuple))
825  elog(ERROR, "cache lookup failed for function %u", funcoid);
826  proc = (Form_pg_proc) GETSTRUCT(tuple);
827 
828  /* Disallow pseudotype result */
829  /* except for RECORD, VOID, or polymorphic */
830  if (get_typtype(proc->prorettype) == TYPTYPE_PSEUDO &&
831  proc->prorettype != RECORDOID &&
832  proc->prorettype != VOIDOID &&
833  !IsPolymorphicType(proc->prorettype))
834  ereport(ERROR,
835  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
836  errmsg("SQL functions cannot return type %s",
837  format_type_be(proc->prorettype))));
838 
839  /* Disallow pseudotypes in arguments */
840  /* except for polymorphic */
841  haspolyarg = false;
842  for (i = 0; i < proc->pronargs; i++)
843  {
844  if (get_typtype(proc->proargtypes.values[i]) == TYPTYPE_PSEUDO)
845  {
846  if (IsPolymorphicType(proc->proargtypes.values[i]))
847  haspolyarg = true;
848  else
849  ereport(ERROR,
850  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
851  errmsg("SQL functions cannot have arguments of type %s",
852  format_type_be(proc->proargtypes.values[i]))));
853  }
854  }
855 
856  /* Postpone body checks if !check_function_bodies */
858  {
859  tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
860  if (isnull)
861  elog(ERROR, "null prosrc");
862 
863  prosrc = TextDatumGetCString(tmp);
864 
865  /*
866  * Setup error traceback support for ereport().
867  */
868  callback_arg.proname = NameStr(proc->proname);
869  callback_arg.prosrc = prosrc;
870 
872  sqlerrcontext.arg = (void *) &callback_arg;
873  sqlerrcontext.previous = error_context_stack;
874  error_context_stack = &sqlerrcontext;
875 
876  /*
877  * We can't do full prechecking of the function definition if there
878  * are any polymorphic input types, because actual datatypes of
879  * expression results will be unresolvable. The check will be done at
880  * runtime instead.
881  *
882  * We can run the text through the raw parser though; this will at
883  * least catch silly syntactic errors.
884  */
885  raw_parsetree_list = pg_parse_query(prosrc);
886 
887  if (!haspolyarg)
888  {
889  /*
890  * OK to do full precheck: analyze and rewrite the queries, then
891  * verify the result type.
892  */
894 
895  /* But first, set up parameter information */
896  pinfo = prepare_sql_fn_parse_info(tuple, NULL, InvalidOid);
897 
898  querytree_list = NIL;
899  foreach(lc, raw_parsetree_list)
900  {
901  RawStmt *parsetree = lfirst_node(RawStmt, lc);
902  List *querytree_sublist;
903 
904  querytree_sublist = pg_analyze_and_rewrite_params(parsetree,
905  prosrc,
907  pinfo,
908  NULL);
909  querytree_list = list_concat(querytree_list,
910  querytree_sublist);
911  }
912 
913  check_sql_fn_statements(querytree_list);
914  (void) check_sql_fn_retval(funcoid, proc->prorettype,
915  querytree_list,
916  NULL, NULL);
917  }
918 
919  error_context_stack = sqlerrcontext.previous;
920  }
921 
922  ReleaseSysCache(tuple);
923 
924  PG_RETURN_VOID();
925 }
926 
927 /*
928  * Error context callback for handling errors in SQL function definitions
929  */
930 static void
932 {
933  parse_error_callback_arg *callback_arg = (parse_error_callback_arg *) arg;
934 
935  /* See if it's a syntax error; if so, transpose to CREATE FUNCTION */
936  if (!function_parse_error_transpose(callback_arg->prosrc))
937  {
938  /* If it's not a syntax error, push info onto context stack */
939  errcontext("SQL function \"%s\"", callback_arg->proname);
940  }
941 }
942 
943 /*
944  * Adjust a syntax error occurring inside the function body of a CREATE
945  * FUNCTION or DO command. This can be used by any function validator or
946  * anonymous-block handler, not only for SQL-language functions.
947  * It is assumed that the syntax error position is initially relative to the
948  * function body string (as passed in). If possible, we adjust the position
949  * to reference the original command text; if we can't manage that, we set
950  * up an "internal query" syntax error instead.
951  *
952  * Returns true if a syntax error was processed, false if not.
953  */
954 bool
956 {
957  int origerrposition;
958  int newerrposition;
959  const char *queryText;
960 
961  /*
962  * Nothing to do unless we are dealing with a syntax error that has a
963  * cursor position.
964  *
965  * Some PLs may prefer to report the error position as an internal error
966  * to begin with, so check that too.
967  */
968  origerrposition = geterrposition();
969  if (origerrposition <= 0)
970  {
971  origerrposition = getinternalerrposition();
972  if (origerrposition <= 0)
973  return false;
974  }
975 
976  /* We can get the original query text from the active portal (hack...) */
978  queryText = ActivePortal->sourceText;
979 
980  /* Try to locate the prosrc in the original text */
981  newerrposition = match_prosrc_to_query(prosrc, queryText, origerrposition);
982 
983  if (newerrposition > 0)
984  {
985  /* Successful, so fix error position to reference original query */
986  errposition(newerrposition);
987  /* Get rid of any report of the error as an "internal query" */
989  internalerrquery(NULL);
990  }
991  else
992  {
993  /*
994  * If unsuccessful, convert the position to an internal position
995  * marker and give the function text as the internal query.
996  */
997  errposition(0);
998  internalerrposition(origerrposition);
999  internalerrquery(prosrc);
1000  }
1001 
1002  return true;
1003 }
1004 
1005 /*
1006  * Try to locate the string literal containing the function body in the
1007  * given text of the CREATE FUNCTION or DO command. If successful, return
1008  * the character (not byte) index within the command corresponding to the
1009  * given character index within the literal. If not successful, return 0.
1010  */
1011 static int
1012 match_prosrc_to_query(const char *prosrc, const char *queryText,
1013  int cursorpos)
1014 {
1015  /*
1016  * Rather than fully parsing the original command, we just scan the
1017  * command looking for $prosrc$ or 'prosrc'. This could be fooled (though
1018  * not in any very probable scenarios), so fail if we find more than one
1019  * match.
1020  */
1021  int prosrclen = strlen(prosrc);
1022  int querylen = strlen(queryText);
1023  int matchpos = 0;
1024  int curpos;
1025  int newcursorpos;
1026 
1027  for (curpos = 0; curpos < querylen - prosrclen; curpos++)
1028  {
1029  if (queryText[curpos] == '$' &&
1030  strncmp(prosrc, &queryText[curpos + 1], prosrclen) == 0 &&
1031  queryText[curpos + 1 + prosrclen] == '$')
1032  {
1033  /*
1034  * Found a $foo$ match. Since there are no embedded quoting
1035  * characters in a dollar-quoted literal, we don't have to do any
1036  * fancy arithmetic; just offset by the starting position.
1037  */
1038  if (matchpos)
1039  return 0; /* multiple matches, fail */
1040  matchpos = pg_mbstrlen_with_len(queryText, curpos + 1)
1041  + cursorpos;
1042  }
1043  else if (queryText[curpos] == '\'' &&
1044  match_prosrc_to_literal(prosrc, &queryText[curpos + 1],
1045  cursorpos, &newcursorpos))
1046  {
1047  /*
1048  * Found a 'foo' match. match_prosrc_to_literal() has adjusted
1049  * for any quotes or backslashes embedded in the literal.
1050  */
1051  if (matchpos)
1052  return 0; /* multiple matches, fail */
1053  matchpos = pg_mbstrlen_with_len(queryText, curpos + 1)
1054  + newcursorpos;
1055  }
1056  }
1057 
1058  return matchpos;
1059 }
1060 
1061 /*
1062  * Try to match the given source text to a single-quoted literal.
1063  * If successful, adjust newcursorpos to correspond to the character
1064  * (not byte) index corresponding to cursorpos in the source text.
1065  *
1066  * At entry, literal points just past a ' character. We must check for the
1067  * trailing quote.
1068  */
1069 static bool
1070 match_prosrc_to_literal(const char *prosrc, const char *literal,
1071  int cursorpos, int *newcursorpos)
1072 {
1073  int newcp = cursorpos;
1074  int chlen;
1075 
1076  /*
1077  * This implementation handles backslashes and doubled quotes in the
1078  * string literal. It does not handle the SQL syntax for literals
1079  * continued across line boundaries.
1080  *
1081  * We do the comparison a character at a time, not a byte at a time, so
1082  * that we can do the correct cursorpos math.
1083  */
1084  while (*prosrc)
1085  {
1086  cursorpos--; /* characters left before cursor */
1087 
1088  /*
1089  * Check for backslashes and doubled quotes in the literal; adjust
1090  * newcp when one is found before the cursor.
1091  */
1092  if (*literal == '\\')
1093  {
1094  literal++;
1095  if (cursorpos > 0)
1096  newcp++;
1097  }
1098  else if (*literal == '\'')
1099  {
1100  if (literal[1] != '\'')
1101  goto fail;
1102  literal++;
1103  if (cursorpos > 0)
1104  newcp++;
1105  }
1106  chlen = pg_mblen(prosrc);
1107  if (strncmp(prosrc, literal, chlen) != 0)
1108  goto fail;
1109  prosrc += chlen;
1110  literal += chlen;
1111  }
1112 
1113  if (*literal == '\'' && literal[1] != '\'')
1114  {
1115  /* success */
1116  *newcursorpos = newcp;
1117  return true;
1118  }
1119 
1120 fail:
1121  /* Must set *newcursorpos to suppress compiler warning */
1122  *newcursorpos = newcp;
1123  return false;
1124 }
1125 
1126 List *
1128 {
1129  ArrayType *array = DatumGetArrayTypeP(datum);
1130  Datum *values;
1131  int nelems;
1132  int i;
1133  List *result = NIL;
1134 
1135  deconstruct_array(array,
1136  OIDOID,
1137  sizeof(Oid), true, 'i',
1138  &values, NULL, &nelems);
1139  for (i = 0; i < nelems; i++)
1140  result = lappend_oid(result, values[i]);
1141  return result;
1142 }
ObjectAddress ProcedureCreate(const char *procedureName, Oid procNamespace, bool replace, bool returnsSet, Oid returnType, Oid proowner, Oid languageObjectId, Oid languageValidator, const char *prosrc, const char *probin, char prokind, bool security_definer, bool isLeakProof, bool isStrict, char volatility, char parallel, oidvector *parameterTypes, Datum allParameterTypes, Datum parameterModes, Datum parameterNames, List *parameterDefaults, Datum trftypes, Datum proconfig, float4 procost, float4 prorows)
Definition: pg_proc.c:66
#define NIL
Definition: pg_list.h:69
Definition: c.h:555
void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
Definition: pg_shdepend.c:421
void * stringToNode(char *str)
Definition: read.c:39
#define NameGetDatum(X)
Definition: postgres.h:580
int errhint(const char *fmt,...)
Definition: elog.c:987
#define GETSTRUCT(TUP)
Definition: htup_details.h:668
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:145
#define RelationGetDescr(relation)
Definition: rel.h:433
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:850
#define castNode(_type_, nodeptr)
Definition: nodes.h:585
Portal ActivePortal
Definition: pquery.c:35
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2502
#define PointerGetDatum(X)
Definition: postgres.h:541
void check_sql_fn_statements(List *queryTreeList)
Definition: functions.c:1500
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
Definition: functions.c:273
TupleDesc build_function_result_tupdesc_d(char prokind, Datum proallargtypes, Datum proargmodes, Datum proargnames)
Definition: funcapi.c:1226
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
Definition: pg_depend.c:191
Definition: nodes.h:516
int errcode(int sqlerrcode)
Definition: elog.c:575
bool check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList, bool *modifyTargetList, JunkFilter **junkFilter)
Definition: functions.c:1586
bool superuser(void)
Definition: superuser.c:47
char get_typtype(Oid typid)
Definition: lsyscache.c:2383
char * format_type_be(Oid type_oid)
Definition: format_type.c:328
List * list_concat(List *list1, List *list2)
Definition: list.c:321
Datum fmgr_c_validator(PG_FUNCTION_ARGS)
Definition: pg_proc.c:756
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1074
#define heap_close(r, l)
Definition: heapam.h:97
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:159
bool check_function_bodies
Definition: guc.c:449
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1773
unsigned int Oid
Definition: postgres_ext.h:31
int namestrcpy(Name name, const char *str)
Definition: name.c:216
void(* callback)(void *arg)
Definition: elog.h:239
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
struct ErrorContextCallback * previous
Definition: elog.h:238
#define OidIsValid(objectId)
Definition: c.h:605
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:794
ErrorContextCallback * error_context_stack
Definition: elog.c:88
#define FUNC_MAX_ARGS
Oid fmgr_internal_function(const char *proname)
Definition: fmgr.c:625
List * oid_array_to_list(Datum datum)
Definition: pg_proc.c:1127
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3349
TupleDesc build_function_result_tupdesc_t(HeapTuple procTuple)
Definition: funcapi.c:1176
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
Oid CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:163
bool CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid)
Definition: fmgr.c:2179
#define ARR_DIMS(a)
Definition: array.h:279
List * pg_parse_query(const char *query_string)
Definition: postgres.c:609
Definition: guc.h:75
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:1134
Datum Float4GetDatum(float4 X)
Definition: fmgr.c:1889
ItemPointerData t_self
Definition: htup.h:65
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:628
#define lfirst_node(type, lc)
Definition: pg_list.h:109
Definition: c.h:570
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Definition: params.h:108
#define ARR_DATA_PTR(a)
Definition: array.h:307
#define PG_GETARG_OID(n)
Definition: fmgr.h:245
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:563
int dim1
Definition: c.h:561
#define RowExclusiveLock
Definition: lockdefs.h:38
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:5322
int errdetail(const char *fmt,...)
Definition: elog.c:873
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
Definition: dependency.c:1360
Datum fmgr_sql_validator(PG_FUNCTION_ARGS)
Definition: pg_proc.c:804
int geterrposition(void)
Definition: elog.c:1257
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
static bool match_prosrc_to_literal(const char *prosrc, const char *literal, int cursorpos, int *newcursorpos)
Definition: pg_proc.c:1070
#define ARR_HASNULL(a)
Definition: array.h:276
PGFunction load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:94
#define lnext(lc)
Definition: pg_list.h:105
#define ereport(elevel, rest)
Definition: elog.h:122
int getinternalerrposition(void)
Definition: elog.c:1274
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
float float4
Definition: c.h:457
int get_func_input_arg_names(Datum proargnames, Datum proargmodes, char ***arg_names)
Definition: funcapi.c:988
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:367
void CommandCounterIncrement(void)
Definition: xact.c:914
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
const char * sourceText
Definition: portal.h:134
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:132
#define BoolGetDatum(X)
Definition: postgres.h:387
#define InvalidOid
Definition: postgres_ext.h:36
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:9688
static void sql_function_parse_error_callback(void *arg)
Definition: pg_proc.c:931
int internalerrquery(const char *query)
Definition: elog.c:1161
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:323
#define PG_RETURN_VOID()
Definition: fmgr.h:314
int aclmembers(const Acl *acl, Oid **roleids)
Definition: acl.c:1473
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:139
bool function_parse_error_transpose(const char *prosrc)
Definition: pg_proc.c:955
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:211
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
static int list_length(const List *l)
Definition: pg_list.h:89
PortalStatus status
Definition: portal.h:148
int pg_mblen(const char *mbstr)
Definition: mbutils.c:760
List * pg_analyze_and_rewrite_params(RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
Definition: postgres.c:688
#define ARR_NDIM(a)
Definition: array.h:275
const Pg_finfo_record * fetch_finfo_record(void *filehandle, const char *funcname)
Definition: fmgr.c:470
#define CharGetDatum(X)
Definition: postgres.h:401
#define DatumGetPointer(X)
Definition: postgres.h:534
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3449
static Datum values[MAXATTR]
Definition: bootstrap.c:164
int NewGUCNestLevel(void)
Definition: guc.c:5308
Datum fmgr_internal_validator(PG_FUNCTION_ARGS)
Definition: pg_proc.c:710
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define errcontext
Definition: elog.h:164
#define NameStr(name)
Definition: c.h:576
#define CStringGetTextDatum(s)
Definition: builtins.h:95
char * nodeToString(const void *obj)
Definition: outfuncs.c:4339
bool equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
Definition: tupdesc.c:409
void * arg
#define PG_FUNCTION_ARGS
Definition: fmgr.h:163
#define elog
Definition: elog.h:219
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node *call_expr, Oid inputCollation)
Definition: functions.c:184
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:707
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:1173
Definition: pg_list.h:45
#define PointerIsValid(pointer)
Definition: c.h:593
#define ARR_ELEMTYPE(a)
Definition: array.h:277
#define UInt16GetDatum(X)
Definition: postgres.h:450
static int match_prosrc_to_query(const char *prosrc, const char *queryText, int cursorpos)
Definition: pg_proc.c:1012
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4829
int errposition(int cursorpos)
Definition: elog.c:1125
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
Definition: aclchk.c:5451
int internalerrposition(int cursorpos)
Definition: elog.c:1141
#define DatumGetArrayTypeP(X)
Definition: array.h:246