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