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