PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2025, 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"
24#include "catalog/pg_language.h"
26#include "catalog/pg_proc.h"
28#include "catalog/pg_type.h"
29#include "executor/functions.h"
30#include "funcapi.h"
31#include "mb/pg_wchar.h"
32#include "miscadmin.h"
33#include "nodes/nodeFuncs.h"
34#include "parser/parse_coerce.h"
35#include "pgstat.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
47typedef struct
48{
49 char *proname;
50 char *prosrc;
52
53static void sql_function_parse_error_callback(void *arg);
54static int match_prosrc_to_query(const char *prosrc, const char *queryText,
55 int cursorpos);
56static bool match_prosrc_to_literal(const char *prosrc, const char *literal,
57 int cursorpos, int *newcursorpos);
58
59
60/* ----------------------------------------------------------------
61 * ProcedureCreate
62 *
63 * procedureName: string name of routine (proname)
64 * procNamespace: OID of namespace (pronamespace)
65 * replace: true to allow replacement of an existing pg_proc entry
66 * returnsSet: returns set? (proretset)
67 * returnType: OID of result type (prorettype)
68 * proowner: OID of owner role (proowner)
69 * languageObjectId: OID of function language (prolang)
70 * languageValidator: OID of validator function to apply, if any
71 * prosrc: string form of function definition (prosrc)
72 * probin: string form of binary reference, or NULL (probin)
73 * prosqlbody: Node tree of pre-parsed SQL body, or NULL (prosqlbody)
74 * prokind: function/aggregate/procedure/etc code (prokind)
75 * security_definer: security definer? (prosecdef)
76 * isLeakProof: leak proof? (proleakproof)
77 * isStrict: strict? (proisstrict)
78 * volatility: volatility code (provolatile)
79 * parallel: parallel safety code (proparallel)
80 * parameterTypes: input parameter types, as an oidvector (proargtypes)
81 * allParameterTypes: all parameter types, as an OID array (proallargtypes)
82 * parameterModes: parameter modes, as a "char" array (proargmodes)
83 * parameterNames: parameter names, as a text array (proargnames)
84 * parameterDefaults: defaults, as a List of Node trees (proargdefaults)
85 * trftypes: transformable type OIDs, as an OID array (protrftypes)
86 * trfoids: List of transform OIDs that routine should depend on
87 * proconfig: GUC set clauses, as a text array (proconfig)
88 * prosupport: OID of support function, if any (prosupport)
89 * procost: cost factor (procost)
90 * prorows: estimated output rows for a SRF (prorows)
91 *
92 * Note: allParameterTypes, parameterModes, parameterNames, trftypes, and proconfig
93 * are either arrays of the proper types or NULL. We declare them Datum,
94 * not "ArrayType *", to avoid importing array.h into pg_proc.h.
95 * ----------------------------------------------------------------
96 */
98ProcedureCreate(const char *procedureName,
99 Oid procNamespace,
100 bool replace,
101 bool returnsSet,
102 Oid returnType,
103 Oid proowner,
104 Oid languageObjectId,
105 Oid languageValidator,
106 const char *prosrc,
107 const char *probin,
108 Node *prosqlbody,
109 char prokind,
110 bool security_definer,
111 bool isLeakProof,
112 bool isStrict,
113 char volatility,
114 char parallel,
115 oidvector *parameterTypes,
116 Datum allParameterTypes,
117 Datum parameterModes,
118 Datum parameterNames,
119 List *parameterDefaults,
120 Datum trftypes,
121 List *trfoids,
122 Datum proconfig,
123 Oid prosupport,
124 float4 procost,
125 float4 prorows)
126{
127 Oid retval;
128 int parameterCount;
129 int allParamCount;
130 Oid *allParams;
131 char *paramModes = NULL;
132 Oid variadicType = InvalidOid;
133 Acl *proacl = NULL;
134 Relation rel;
135 HeapTuple tup;
136 HeapTuple oldtup;
137 bool nulls[Natts_pg_proc];
138 Datum values[Natts_pg_proc];
139 bool replaces[Natts_pg_proc];
140 NameData procname;
141 TupleDesc tupDesc;
142 bool is_update;
143 ObjectAddress myself,
144 referenced;
145 char *detailmsg;
146 int i;
147 ObjectAddresses *addrs;
148
149 /*
150 * sanity checks
151 */
152 Assert(PointerIsValid(prosrc));
153
154 parameterCount = parameterTypes->dim1;
155 if (parameterCount < 0 || parameterCount > FUNC_MAX_ARGS)
157 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
158 errmsg_plural("functions cannot have more than %d argument",
159 "functions cannot have more than %d arguments",
161 FUNC_MAX_ARGS)));
162 /* note: the above is correct, we do NOT count output arguments */
163
164 /* Deconstruct array inputs */
165 if (allParameterTypes != PointerGetDatum(NULL))
166 {
167 /*
168 * We expect the array to be a 1-D OID array; verify that. We don't
169 * need to use deconstruct_array() since the array data is just going
170 * to look like a C array of OID values.
171 */
172 ArrayType *allParamArray = (ArrayType *) DatumGetPointer(allParameterTypes);
173
174 allParamCount = ARR_DIMS(allParamArray)[0];
175 if (ARR_NDIM(allParamArray) != 1 ||
176 allParamCount <= 0 ||
177 ARR_HASNULL(allParamArray) ||
178 ARR_ELEMTYPE(allParamArray) != OIDOID)
179 elog(ERROR, "allParameterTypes is not a 1-D Oid array");
180 allParams = (Oid *) ARR_DATA_PTR(allParamArray);
181 Assert(allParamCount >= parameterCount);
182 /* we assume caller got the contents right */
183 }
184 else
185 {
186 allParamCount = parameterCount;
187 allParams = parameterTypes->values;
188 }
189
190 if (parameterModes != PointerGetDatum(NULL))
191 {
192 /*
193 * We expect the array to be a 1-D CHAR array; verify that. We don't
194 * need to use deconstruct_array() since the array data is just going
195 * to look like a C array of char values.
196 */
197 ArrayType *modesArray = (ArrayType *) DatumGetPointer(parameterModes);
198
199 if (ARR_NDIM(modesArray) != 1 ||
200 ARR_DIMS(modesArray)[0] != allParamCount ||
201 ARR_HASNULL(modesArray) ||
202 ARR_ELEMTYPE(modesArray) != CHAROID)
203 elog(ERROR, "parameterModes is not a 1-D char array");
204 paramModes = (char *) ARR_DATA_PTR(modesArray);
205 }
206
207 /*
208 * Do not allow polymorphic return type unless there is a polymorphic
209 * input argument that we can use to deduce the actual return type.
210 */
211 detailmsg = check_valid_polymorphic_signature(returnType,
212 parameterTypes->values,
213 parameterCount);
214 if (detailmsg)
216 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
217 errmsg("cannot determine result data type"),
218 errdetail_internal("%s", detailmsg)));
219
220 /*
221 * Also, do not allow return type INTERNAL unless at least one input
222 * argument is INTERNAL.
223 */
224 detailmsg = check_valid_internal_signature(returnType,
225 parameterTypes->values,
226 parameterCount);
227 if (detailmsg)
229 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
230 errmsg("unsafe use of pseudo-type \"internal\""),
231 errdetail_internal("%s", detailmsg)));
232
233 /*
234 * Apply the same tests to any OUT arguments.
235 */
236 if (allParameterTypes != PointerGetDatum(NULL))
237 {
238 for (i = 0; i < allParamCount; i++)
239 {
240 if (paramModes == NULL ||
241 paramModes[i] == PROARGMODE_IN ||
242 paramModes[i] == PROARGMODE_VARIADIC)
243 continue; /* ignore input-only params */
244
245 detailmsg = check_valid_polymorphic_signature(allParams[i],
246 parameterTypes->values,
247 parameterCount);
248 if (detailmsg)
250 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
251 errmsg("cannot determine result data type"),
252 errdetail_internal("%s", detailmsg)));
253 detailmsg = check_valid_internal_signature(allParams[i],
254 parameterTypes->values,
255 parameterCount);
256 if (detailmsg)
258 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
259 errmsg("unsafe use of pseudo-type \"internal\""),
260 errdetail_internal("%s", detailmsg)));
261 }
262 }
263
264 /* Identify variadic argument type, if any */
265 if (paramModes != NULL)
266 {
267 /*
268 * Only the last input parameter can be variadic; if it is, save its
269 * element type. Errors here are just elog since caller should have
270 * checked this already.
271 */
272 for (i = 0; i < allParamCount; i++)
273 {
274 switch (paramModes[i])
275 {
276 case PROARGMODE_IN:
277 case PROARGMODE_INOUT:
278 if (OidIsValid(variadicType))
279 elog(ERROR, "variadic parameter must be last");
280 break;
281 case PROARGMODE_OUT:
282 if (OidIsValid(variadicType) && prokind == PROKIND_PROCEDURE)
283 elog(ERROR, "variadic parameter must be last");
284 break;
285 case PROARGMODE_TABLE:
286 /* okay */
287 break;
288 case PROARGMODE_VARIADIC:
289 if (OidIsValid(variadicType))
290 elog(ERROR, "variadic parameter must be last");
291 switch (allParams[i])
292 {
293 case ANYOID:
294 variadicType = ANYOID;
295 break;
296 case ANYARRAYOID:
297 variadicType = ANYELEMENTOID;
298 break;
299 case ANYCOMPATIBLEARRAYOID:
300 variadicType = ANYCOMPATIBLEOID;
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_prosupport - 1] = ObjectIdGetDatum(prosupport);
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 (prosqlbody)
373 values[Anum_pg_proc_prosqlbody - 1] = CStringGetTextDatum(nodeToString(prosqlbody));
374 else
375 nulls[Anum_pg_proc_prosqlbody - 1] = true;
376 if (proconfig != PointerGetDatum(NULL))
377 values[Anum_pg_proc_proconfig - 1] = proconfig;
378 else
379 nulls[Anum_pg_proc_proconfig - 1] = true;
380 /* proacl will be determined later */
381
382 rel = table_open(ProcedureRelationId, RowExclusiveLock);
383 tupDesc = RelationGetDescr(rel);
384
385 /* Check for pre-existing definition */
386 oldtup = SearchSysCache3(PROCNAMEARGSNSP,
387 PointerGetDatum(procedureName),
388 PointerGetDatum(parameterTypes),
389 ObjectIdGetDatum(procNamespace));
390
391 if (HeapTupleIsValid(oldtup))
392 {
393 /* There is one; okay to replace it? */
394 Form_pg_proc oldproc = (Form_pg_proc) GETSTRUCT(oldtup);
395 Datum proargnames;
396 bool isnull;
397 const char *dropcmd;
398
399 if (!replace)
401 (errcode(ERRCODE_DUPLICATE_FUNCTION),
402 errmsg("function \"%s\" already exists with same argument types",
403 procedureName)));
404 if (!object_ownercheck(ProcedureRelationId, oldproc->oid, proowner))
406 procedureName);
407
408 /* Not okay to change routine kind */
409 if (oldproc->prokind != prokind)
411 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
412 errmsg("cannot change routine kind"),
413 (oldproc->prokind == PROKIND_AGGREGATE ?
414 errdetail("\"%s\" is an aggregate function.", procedureName) :
415 oldproc->prokind == PROKIND_FUNCTION ?
416 errdetail("\"%s\" is a function.", procedureName) :
417 oldproc->prokind == PROKIND_PROCEDURE ?
418 errdetail("\"%s\" is a procedure.", procedureName) :
419 oldproc->prokind == PROKIND_WINDOW ?
420 errdetail("\"%s\" is a window function.", procedureName) :
421 0)));
422
423 dropcmd = (prokind == PROKIND_PROCEDURE ? "DROP PROCEDURE" :
424 prokind == PROKIND_AGGREGATE ? "DROP AGGREGATE" :
425 "DROP FUNCTION");
426
427 /*
428 * Not okay to change the return type of the existing proc, since
429 * existing rules, views, etc may depend on the return type.
430 *
431 * In case of a procedure, a changing return type means that whether
432 * the procedure has output parameters was changed. Since there is no
433 * user visible return type, we produce a more specific error message.
434 */
435 if (returnType != oldproc->prorettype ||
436 returnsSet != oldproc->proretset)
438 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
439 prokind == PROKIND_PROCEDURE
440 ? errmsg("cannot change whether a procedure has output parameters")
441 : errmsg("cannot change return type of existing function"),
442
443 /*
444 * translator: first %s is DROP FUNCTION, DROP PROCEDURE, or DROP
445 * AGGREGATE
446 */
447 errhint("Use %s %s first.",
448 dropcmd,
449 format_procedure(oldproc->oid))));
450
451 /*
452 * If it returns RECORD, check for possible change of record type
453 * implied by OUT parameters
454 */
455 if (returnType == RECORDOID)
456 {
457 TupleDesc olddesc;
458 TupleDesc newdesc;
459
460 olddesc = build_function_result_tupdesc_t(oldtup);
461 newdesc = build_function_result_tupdesc_d(prokind,
462 allParameterTypes,
463 parameterModes,
464 parameterNames);
465 if (olddesc == NULL && newdesc == NULL)
466 /* ok, both are runtime-defined RECORDs */ ;
467 else if (olddesc == NULL || newdesc == NULL ||
468 !equalRowTypes(olddesc, newdesc))
470 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
471 errmsg("cannot change return type of existing function"),
472 errdetail("Row type defined by OUT parameters is different."),
473 /* translator: first %s is DROP FUNCTION or DROP PROCEDURE */
474 errhint("Use %s %s first.",
475 dropcmd,
476 format_procedure(oldproc->oid))));
477 }
478
479 /*
480 * If there were any named input parameters, check to make sure the
481 * names have not been changed, as this could break existing calls. We
482 * allow adding names to formerly unnamed parameters, though.
483 */
484 proargnames = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup,
485 Anum_pg_proc_proargnames,
486 &isnull);
487 if (!isnull)
488 {
489 Datum proargmodes;
490 char **old_arg_names;
491 char **new_arg_names;
492 int n_old_arg_names;
493 int n_new_arg_names;
494 int j;
495
496 proargmodes = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup,
497 Anum_pg_proc_proargmodes,
498 &isnull);
499 if (isnull)
500 proargmodes = PointerGetDatum(NULL); /* just to be sure */
501
502 n_old_arg_names = get_func_input_arg_names(proargnames,
503 proargmodes,
504 &old_arg_names);
505 n_new_arg_names = get_func_input_arg_names(parameterNames,
506 parameterModes,
507 &new_arg_names);
508 for (j = 0; j < n_old_arg_names; j++)
509 {
510 if (old_arg_names[j] == NULL)
511 continue;
512 if (j >= n_new_arg_names || new_arg_names[j] == NULL ||
513 strcmp(old_arg_names[j], new_arg_names[j]) != 0)
515 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
516 errmsg("cannot change name of input parameter \"%s\"",
517 old_arg_names[j]),
518 /* translator: first %s is DROP FUNCTION or DROP PROCEDURE */
519 errhint("Use %s %s first.",
520 dropcmd,
521 format_procedure(oldproc->oid))));
522 }
523 }
524
525 /*
526 * If there are existing defaults, check compatibility: redefinition
527 * must not remove any defaults nor change their types. (Removing a
528 * default might cause a function to fail to satisfy an existing call.
529 * Changing type would only be possible if the associated parameter is
530 * polymorphic, and in such cases a change of default type might alter
531 * the resolved output type of existing calls.)
532 */
533 if (oldproc->pronargdefaults != 0)
534 {
535 Datum proargdefaults;
536 List *oldDefaults;
537 ListCell *oldlc;
538 ListCell *newlc;
539
540 if (list_length(parameterDefaults) < oldproc->pronargdefaults)
542 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
543 errmsg("cannot remove parameter defaults from existing function"),
544 /* translator: first %s is DROP FUNCTION or DROP PROCEDURE */
545 errhint("Use %s %s first.",
546 dropcmd,
547 format_procedure(oldproc->oid))));
548
549 proargdefaults = SysCacheGetAttrNotNull(PROCNAMEARGSNSP, oldtup,
550 Anum_pg_proc_proargdefaults);
551 oldDefaults = castNode(List, stringToNode(TextDatumGetCString(proargdefaults)));
552 Assert(list_length(oldDefaults) == oldproc->pronargdefaults);
553
554 /* new list can have more defaults than old, advance over 'em */
555 newlc = list_nth_cell(parameterDefaults,
556 list_length(parameterDefaults) -
557 oldproc->pronargdefaults);
558
559 foreach(oldlc, oldDefaults)
560 {
561 Node *oldDef = (Node *) lfirst(oldlc);
562 Node *newDef = (Node *) lfirst(newlc);
563
564 if (exprType(oldDef) != exprType(newDef))
566 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
567 errmsg("cannot change data type of existing parameter default value"),
568 /* translator: first %s is DROP FUNCTION or DROP PROCEDURE */
569 errhint("Use %s %s first.",
570 dropcmd,
571 format_procedure(oldproc->oid))));
572 newlc = lnext(parameterDefaults, newlc);
573 }
574 }
575
576 /*
577 * Do not change existing oid, ownership or permissions, either. Note
578 * dependency-update code below has to agree with this decision.
579 */
580 replaces[Anum_pg_proc_oid - 1] = false;
581 replaces[Anum_pg_proc_proowner - 1] = false;
582 replaces[Anum_pg_proc_proacl - 1] = false;
583
584 /* Okay, do it... */
585 tup = heap_modify_tuple(oldtup, tupDesc, values, nulls, replaces);
586 CatalogTupleUpdate(rel, &tup->t_self, tup);
587
588 ReleaseSysCache(oldtup);
589 is_update = true;
590 }
591 else
592 {
593 /* Creating a new procedure */
594 Oid newOid;
595
596 /* First, get default permissions and set up proacl */
597 proacl = get_user_default_acl(OBJECT_FUNCTION, proowner,
598 procNamespace);
599 if (proacl != NULL)
600 values[Anum_pg_proc_proacl - 1] = PointerGetDatum(proacl);
601 else
602 nulls[Anum_pg_proc_proacl - 1] = true;
603
604 newOid = GetNewOidWithIndex(rel, ProcedureOidIndexId,
605 Anum_pg_proc_oid);
606 values[Anum_pg_proc_oid - 1] = ObjectIdGetDatum(newOid);
607 tup = heap_form_tuple(tupDesc, values, nulls);
608 CatalogTupleInsert(rel, tup);
609 is_update = false;
610 }
611
612
613 retval = ((Form_pg_proc) GETSTRUCT(tup))->oid;
614
615 /*
616 * Create dependencies for the new function. If we are updating an
617 * existing function, first delete any existing pg_depend entries.
618 * (However, since we are not changing ownership or permissions, the
619 * shared dependencies do *not* need to change, and we leave them alone.)
620 */
621 if (is_update)
622 deleteDependencyRecordsFor(ProcedureRelationId, retval, true);
623
624 addrs = new_object_addresses();
625
626 ObjectAddressSet(myself, ProcedureRelationId, retval);
627
628 /* dependency on namespace */
629 ObjectAddressSet(referenced, NamespaceRelationId, procNamespace);
630 add_exact_object_address(&referenced, addrs);
631
632 /* dependency on implementation language */
633 ObjectAddressSet(referenced, LanguageRelationId, languageObjectId);
634 add_exact_object_address(&referenced, addrs);
635
636 /* dependency on return type */
637 ObjectAddressSet(referenced, TypeRelationId, returnType);
638 add_exact_object_address(&referenced, addrs);
639
640 /* dependency on parameter types */
641 for (i = 0; i < allParamCount; i++)
642 {
643 ObjectAddressSet(referenced, TypeRelationId, allParams[i]);
644 add_exact_object_address(&referenced, addrs);
645 }
646
647 /* dependency on transforms, if any */
648 foreach_oid(transformid, trfoids)
649 {
650 ObjectAddressSet(referenced, TransformRelationId, transformid);
651 add_exact_object_address(&referenced, addrs);
652 }
653
654 /* dependency on support function, if any */
655 if (OidIsValid(prosupport))
656 {
657 ObjectAddressSet(referenced, ProcedureRelationId, prosupport);
658 add_exact_object_address(&referenced, addrs);
659 }
660
663
664 /* dependency on SQL routine body */
665 if (languageObjectId == SQLlanguageId && prosqlbody)
666 recordDependencyOnExpr(&myself, prosqlbody, NIL, DEPENDENCY_NORMAL);
667
668 /* dependency on parameter default expressions */
669 if (parameterDefaults)
670 recordDependencyOnExpr(&myself, (Node *) parameterDefaults,
672
673 /* dependency on owner */
674 if (!is_update)
675 recordDependencyOnOwner(ProcedureRelationId, retval, proowner);
676
677 /* dependency on any roles mentioned in ACL */
678 if (!is_update)
679 recordDependencyOnNewAcl(ProcedureRelationId, retval, 0,
680 proowner, proacl);
681
682 /* dependency on extension */
683 recordDependencyOnCurrentExtension(&myself, is_update);
684
685 heap_freetuple(tup);
686
687 /* Post creation hook for new function */
688 InvokeObjectPostCreateHook(ProcedureRelationId, retval, 0);
689
691
692 /* Verify function body */
693 if (OidIsValid(languageValidator))
694 {
695 ArrayType *set_items = NULL;
696 int save_nestlevel = 0;
697
698 /* Advance command counter so new tuple can be seen by validator */
700
701 /*
702 * Set per-function configuration parameters so that the validation is
703 * done with the environment the function expects. However, if
704 * check_function_bodies is off, we don't do this, because that would
705 * create dump ordering hazards that pg_dump doesn't know how to deal
706 * with. (For example, a SET clause might refer to a not-yet-created
707 * text search configuration.) This means that the validator
708 * shouldn't complain about anything that might depend on a GUC
709 * parameter when check_function_bodies is off.
710 */
712 {
713 set_items = (ArrayType *) DatumGetPointer(proconfig);
714 if (set_items) /* Need a new GUC nesting level */
715 {
716 save_nestlevel = NewGUCNestLevel();
717 ProcessGUCArray(set_items,
721 }
722 }
723
724 OidFunctionCall1(languageValidator, ObjectIdGetDatum(retval));
725
726 if (set_items)
727 AtEOXact_GUC(true, save_nestlevel);
728 }
729
730 /* ensure that stats are dropped if transaction aborts */
731 if (!is_update)
733
734 return myself;
735}
736
737
738
739/*
740 * Validator for internal functions
741 *
742 * Check that the given internal function name (the "prosrc" value) is
743 * a known builtin function.
744 */
745Datum
747{
748 Oid funcoid = PG_GETARG_OID(0);
749 HeapTuple tuple;
750 Datum tmp;
751 char *prosrc;
752
753 if (!CheckFunctionValidatorAccess(fcinfo->flinfo->fn_oid, funcoid))
755
756 /*
757 * We do not honor check_function_bodies since it's unlikely the function
758 * name will be found later if it isn't there now.
759 */
760
761 tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
762 if (!HeapTupleIsValid(tuple))
763 elog(ERROR, "cache lookup failed for function %u", funcoid);
764
765 tmp = SysCacheGetAttrNotNull(PROCOID, tuple, Anum_pg_proc_prosrc);
766 prosrc = TextDatumGetCString(tmp);
767
768 if (fmgr_internal_function(prosrc) == InvalidOid)
770 (errcode(ERRCODE_UNDEFINED_FUNCTION),
771 errmsg("there is no built-in function named \"%s\"",
772 prosrc)));
773
774 ReleaseSysCache(tuple);
775
777}
778
779
780
781/*
782 * Validator for C language functions
783 *
784 * Make sure that the library file exists, is loadable, and contains
785 * the specified link symbol. Also check for a valid function
786 * information record.
787 */
788Datum
790{
791 Oid funcoid = PG_GETARG_OID(0);
792 void *libraryhandle;
793 HeapTuple tuple;
794 Datum tmp;
795 char *prosrc;
796 char *probin;
797
798 if (!CheckFunctionValidatorAccess(fcinfo->flinfo->fn_oid, funcoid))
800
801 /*
802 * It'd be most consistent to skip the check if !check_function_bodies,
803 * but the purpose of that switch is to be helpful for pg_dump loading,
804 * and for pg_dump loading it's much better if we *do* check.
805 */
806
807 tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
808 if (!HeapTupleIsValid(tuple))
809 elog(ERROR, "cache lookup failed for function %u", funcoid);
810
811 tmp = SysCacheGetAttrNotNull(PROCOID, tuple, Anum_pg_proc_prosrc);
812 prosrc = TextDatumGetCString(tmp);
813
814 tmp = SysCacheGetAttrNotNull(PROCOID, tuple, Anum_pg_proc_probin);
815 probin = TextDatumGetCString(tmp);
816
817 (void) load_external_function(probin, prosrc, true, &libraryhandle);
818 (void) fetch_finfo_record(libraryhandle, prosrc);
819
820 ReleaseSysCache(tuple);
821
823}
824
825
826/*
827 * Validator for SQL language functions
828 *
829 * Parse it here in order to be sure that it contains no syntax errors.
830 */
831Datum
833{
834 Oid funcoid = PG_GETARG_OID(0);
835 HeapTuple tuple;
836 Form_pg_proc proc;
837 List *raw_parsetree_list;
838 List *querytree_list;
839 ListCell *lc;
840 bool isnull;
841 Datum tmp;
842 char *prosrc;
843 parse_error_callback_arg callback_arg;
844 ErrorContextCallback sqlerrcontext;
845 bool haspolyarg;
846 int i;
847
848 if (!CheckFunctionValidatorAccess(fcinfo->flinfo->fn_oid, funcoid))
850
851 tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
852 if (!HeapTupleIsValid(tuple))
853 elog(ERROR, "cache lookup failed for function %u", funcoid);
854 proc = (Form_pg_proc) GETSTRUCT(tuple);
855
856 /* Disallow pseudotype result */
857 /* except for RECORD, VOID, or polymorphic */
858 if (get_typtype(proc->prorettype) == TYPTYPE_PSEUDO &&
859 proc->prorettype != RECORDOID &&
860 proc->prorettype != VOIDOID &&
861 !IsPolymorphicType(proc->prorettype))
863 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
864 errmsg("SQL functions cannot return type %s",
865 format_type_be(proc->prorettype))));
866
867 /* Disallow pseudotypes in arguments */
868 /* except for polymorphic */
869 haspolyarg = false;
870 for (i = 0; i < proc->pronargs; i++)
871 {
872 if (get_typtype(proc->proargtypes.values[i]) == TYPTYPE_PSEUDO)
873 {
874 if (IsPolymorphicType(proc->proargtypes.values[i]))
875 haspolyarg = true;
876 else
878 (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
879 errmsg("SQL functions cannot have arguments of type %s",
880 format_type_be(proc->proargtypes.values[i]))));
881 }
882 }
883
884 /* Postpone body checks if !check_function_bodies */
886 {
887 tmp = SysCacheGetAttrNotNull(PROCOID, tuple, Anum_pg_proc_prosrc);
888 prosrc = TextDatumGetCString(tmp);
889
890 /*
891 * Setup error traceback support for ereport().
892 */
893 callback_arg.proname = NameStr(proc->proname);
894 callback_arg.prosrc = prosrc;
895
897 sqlerrcontext.arg = &callback_arg;
898 sqlerrcontext.previous = error_context_stack;
899 error_context_stack = &sqlerrcontext;
900
901 /* If we have prosqlbody, pay attention to that not prosrc */
902 tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosqlbody, &isnull);
903 if (!isnull)
904 {
905 Node *n;
906 List *stored_query_list;
907
909 if (IsA(n, List))
910 stored_query_list = linitial(castNode(List, n));
911 else
912 stored_query_list = list_make1(n);
913
914 querytree_list = NIL;
915 foreach(lc, stored_query_list)
916 {
917 Query *parsetree = lfirst_node(Query, lc);
918 List *querytree_sublist;
919
920 /*
921 * Typically, we'd have acquired locks already while parsing
922 * the body of the CREATE FUNCTION command. However, a
923 * validator function cannot assume that it's only called in
924 * that context.
925 */
926 AcquireRewriteLocks(parsetree, true, false);
927 querytree_sublist = pg_rewrite_query(parsetree);
928 querytree_list = lappend(querytree_list, querytree_sublist);
929 }
930 }
931 else
932 {
933 /*
934 * We can't do full prechecking of the function definition if
935 * there are any polymorphic input types, because actual datatypes
936 * of expression results will be unresolvable. The check will be
937 * done at runtime instead.
938 *
939 * We can run the text through the raw parser though; this will at
940 * least catch silly syntactic errors.
941 */
942 raw_parsetree_list = pg_parse_query(prosrc);
943 querytree_list = NIL;
944
945 if (!haspolyarg)
946 {
947 /*
948 * OK to do full precheck: analyze and rewrite the queries,
949 * then verify the result type.
950 */
952
953 /* But first, set up parameter information */
954 pinfo = prepare_sql_fn_parse_info(tuple, NULL, InvalidOid);
955
956 foreach(lc, raw_parsetree_list)
957 {
958 RawStmt *parsetree = lfirst_node(RawStmt, lc);
959 List *querytree_sublist;
960
961 querytree_sublist = pg_analyze_and_rewrite_withcb(parsetree,
962 prosrc,
964 pinfo,
965 NULL);
966 querytree_list = lappend(querytree_list,
967 querytree_sublist);
968 }
969 }
970 }
971
972 if (!haspolyarg)
973 {
974 Oid rettype;
975 TupleDesc rettupdesc;
976
977 check_sql_fn_statements(querytree_list);
978
979 (void) get_func_result_type(funcoid, &rettype, &rettupdesc);
980
981 (void) check_sql_fn_retval(querytree_list,
982 rettype, rettupdesc,
983 proc->prokind,
984 false);
985 }
986
987 error_context_stack = sqlerrcontext.previous;
988 }
989
990 ReleaseSysCache(tuple);
991
993}
994
995/*
996 * Error context callback for handling errors in SQL function definitions
997 */
998static void
1000{
1002
1003 /* See if it's a syntax error; if so, transpose to CREATE FUNCTION */
1004 if (!function_parse_error_transpose(callback_arg->prosrc))
1005 {
1006 /* If it's not a syntax error, push info onto context stack */
1007 errcontext("SQL function \"%s\"", callback_arg->proname);
1008 }
1009}
1010
1011/*
1012 * Adjust a syntax error occurring inside the function body of a CREATE
1013 * FUNCTION or DO command. This can be used by any function validator or
1014 * anonymous-block handler, not only for SQL-language functions.
1015 * It is assumed that the syntax error position is initially relative to the
1016 * function body string (as passed in). If possible, we adjust the position
1017 * to reference the original command text; if we can't manage that, we set
1018 * up an "internal query" syntax error instead.
1019 *
1020 * Returns true if a syntax error was processed, false if not.
1021 */
1022bool
1024{
1025 int origerrposition;
1026 int newerrposition;
1027
1028 /*
1029 * Nothing to do unless we are dealing with a syntax error that has a
1030 * cursor position.
1031 *
1032 * Some PLs may prefer to report the error position as an internal error
1033 * to begin with, so check that too.
1034 */
1035 origerrposition = geterrposition();
1036 if (origerrposition <= 0)
1037 {
1038 origerrposition = getinternalerrposition();
1039 if (origerrposition <= 0)
1040 return false;
1041 }
1042
1043 /* We can get the original query text from the active portal (hack...) */
1045 {
1046 const char *queryText = ActivePortal->sourceText;
1047
1048 /* Try to locate the prosrc in the original text */
1049 newerrposition = match_prosrc_to_query(prosrc, queryText,
1050 origerrposition);
1051 }
1052 else
1053 {
1054 /*
1055 * Quietly give up if no ActivePortal. This is an unusual situation
1056 * but it can happen in, e.g., logical replication workers.
1057 */
1058 newerrposition = -1;
1059 }
1060
1061 if (newerrposition > 0)
1062 {
1063 /* Successful, so fix error position to reference original query */
1064 errposition(newerrposition);
1065 /* Get rid of any report of the error as an "internal query" */
1067 internalerrquery(NULL);
1068 }
1069 else
1070 {
1071 /*
1072 * If unsuccessful, convert the position to an internal position
1073 * marker and give the function text as the internal query.
1074 */
1075 errposition(0);
1076 internalerrposition(origerrposition);
1077 internalerrquery(prosrc);
1078 }
1079
1080 return true;
1081}
1082
1083/*
1084 * Try to locate the string literal containing the function body in the
1085 * given text of the CREATE FUNCTION or DO command. If successful, return
1086 * the character (not byte) index within the command corresponding to the
1087 * given character index within the literal. If not successful, return 0.
1088 */
1089static int
1090match_prosrc_to_query(const char *prosrc, const char *queryText,
1091 int cursorpos)
1092{
1093 /*
1094 * Rather than fully parsing the original command, we just scan the
1095 * command looking for $prosrc$ or 'prosrc'. This could be fooled (though
1096 * not in any very probable scenarios), so fail if we find more than one
1097 * match.
1098 */
1099 int prosrclen = strlen(prosrc);
1100 int querylen = strlen(queryText);
1101 int matchpos = 0;
1102 int curpos;
1103 int newcursorpos;
1104
1105 for (curpos = 0; curpos < querylen - prosrclen; curpos++)
1106 {
1107 if (queryText[curpos] == '$' &&
1108 strncmp(prosrc, &queryText[curpos + 1], prosrclen) == 0 &&
1109 queryText[curpos + 1 + prosrclen] == '$')
1110 {
1111 /*
1112 * Found a $foo$ match. Since there are no embedded quoting
1113 * characters in a dollar-quoted literal, we don't have to do any
1114 * fancy arithmetic; just offset by the starting position.
1115 */
1116 if (matchpos)
1117 return 0; /* multiple matches, fail */
1118 matchpos = pg_mbstrlen_with_len(queryText, curpos + 1)
1119 + cursorpos;
1120 }
1121 else if (queryText[curpos] == '\'' &&
1122 match_prosrc_to_literal(prosrc, &queryText[curpos + 1],
1123 cursorpos, &newcursorpos))
1124 {
1125 /*
1126 * Found a 'foo' match. match_prosrc_to_literal() has adjusted
1127 * for any quotes or backslashes embedded in the literal.
1128 */
1129 if (matchpos)
1130 return 0; /* multiple matches, fail */
1131 matchpos = pg_mbstrlen_with_len(queryText, curpos + 1)
1132 + newcursorpos;
1133 }
1134 }
1135
1136 return matchpos;
1137}
1138
1139/*
1140 * Try to match the given source text to a single-quoted literal.
1141 * If successful, adjust newcursorpos to correspond to the character
1142 * (not byte) index corresponding to cursorpos in the source text.
1143 *
1144 * At entry, literal points just past a ' character. We must check for the
1145 * trailing quote.
1146 */
1147static bool
1148match_prosrc_to_literal(const char *prosrc, const char *literal,
1149 int cursorpos, int *newcursorpos)
1150{
1151 int newcp = cursorpos;
1152 int chlen;
1153
1154 /*
1155 * This implementation handles backslashes and doubled quotes in the
1156 * string literal. It does not handle the SQL syntax for literals
1157 * continued across line boundaries.
1158 *
1159 * We do the comparison a character at a time, not a byte at a time, so
1160 * that we can do the correct cursorpos math.
1161 */
1162 while (*prosrc)
1163 {
1164 cursorpos--; /* characters left before cursor */
1165
1166 /*
1167 * Check for backslashes and doubled quotes in the literal; adjust
1168 * newcp when one is found before the cursor.
1169 */
1170 if (*literal == '\\')
1171 {
1172 literal++;
1173 if (cursorpos > 0)
1174 newcp++;
1175 }
1176 else if (*literal == '\'')
1177 {
1178 if (literal[1] != '\'')
1179 goto fail;
1180 literal++;
1181 if (cursorpos > 0)
1182 newcp++;
1183 }
1184 chlen = pg_mblen(prosrc);
1185 if (strncmp(prosrc, literal, chlen) != 0)
1186 goto fail;
1187 prosrc += chlen;
1188 literal += chlen;
1189 }
1190
1191 if (*literal == '\'' && literal[1] != '\'')
1192 {
1193 /* success */
1194 *newcursorpos = newcp;
1195 return true;
1196 }
1197
1198fail:
1199 /* Must set *newcursorpos to suppress compiler warning */
1200 *newcursorpos = newcp;
1201 return false;
1202}
1203
1204List *
1206{
1207 ArrayType *array = DatumGetArrayTypeP(datum);
1208 Datum *values;
1209 int nelems;
1210 int i;
1211 List *result = NIL;
1212
1213 deconstruct_array_builtin(array, OIDOID, &values, NULL, &nelems);
1214 for (i = 0; i < nelems; i++)
1215 result = lappend_oid(result, values[i]);
1216 return result;
1217}
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
Definition: aclchk.c:4312
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2639
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4075
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
Definition: aclchk.c:4232
#define ARR_NDIM(a)
Definition: array.h:290
#define ARR_DATA_PTR(a)
Definition: array.h:322
#define DatumGetArrayTypeP(X)
Definition: array.h:261
#define ARR_ELEMTYPE(a)
Definition: array.h:292
#define ARR_DIMS(a)
Definition: array.h:294
#define ARR_HASNULL(a)
Definition: array.h:291
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3697
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define NameStr(name)
Definition: c.h:717
#define PointerIsValid(pointer)
Definition: c.h:734
float float4
Definition: c.h:600
#define OidIsValid(objectId)
Definition: c.h:746
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:450
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
Definition: dependency.c:2757
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
Definition: dependency.c:1553
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2548
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2502
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2788
@ DEPENDENCY_NORMAL
Definition: dependency.h:33
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:95
int getinternalerrposition(void)
Definition: elog.c:1634
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1181
int internalerrquery(const char *query)
Definition: elog.c:1504
int internalerrposition(int cursorpos)
Definition: elog.c:1484
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1231
int errdetail(const char *fmt,...)
Definition: elog.c:1204
ErrorContextCallback * error_context_stack
Definition: elog.c:95
int errhint(const char *fmt,...)
Definition: elog.c:1318
int geterrposition(void)
Definition: elog.c:1617
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
int errposition(int cursorpos)
Definition: elog.c:1468
#define errcontext
Definition: elog.h:197
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define ereport(elevel,...)
Definition: elog.h:149
Oid fmgr_internal_function(const char *proname)
Definition: fmgr.c:595
bool CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid)
Definition: fmgr.c:2145
const Pg_finfo_record * fetch_finfo_record(void *filehandle, const char *funcname)
Definition: fmgr.c:455
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:720
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
TupleDesc build_function_result_tupdesc_t(HeapTuple procTuple)
Definition: funcapi.c:1705
TupleDesc build_function_result_tupdesc_d(char prokind, Datum proallargtypes, Datum proargmodes, Datum proargnames)
Definition: funcapi.c:1751
int get_func_input_arg_names(Datum proargnames, Datum proargmodes, char ***arg_names)
Definition: funcapi.c:1522
TypeFuncClass get_func_result_type(Oid functionId, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:410
bool check_sql_fn_retval(List *queryTreeLists, Oid rettype, TupleDesc rettupdesc, char prokind, bool insertDroppedCols)
Definition: functions.c:2074
void check_sql_fn_statements(List *queryTreeLists)
Definition: functions.c:1993
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
Definition: functions.c:336
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node *call_expr, Oid inputCollation)
Definition: functions.c:247
int NewGUCNestLevel(void)
Definition: guc.c:2235
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:6457
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:2262
@ GUC_ACTION_SAVE
Definition: guc.h:205
@ PGC_S_SESSION
Definition: guc.h:126
@ PGC_SUSET
Definition: guc.h:78
@ PGC_USERSET
Definition: guc.h:79
bool check_function_bodies
Definition: guc_tables.c:528
Assert(PointerIsAligned(start, uint64))
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition: heaptuple.c:1210
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:313
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
int j
Definition: isn.c:78
int i
Definition: isn.c:77
List * lappend(List *list, void *datum)
Definition: list.c:339
List * lappend_oid(List *list, Oid datum)
Definition: list.c:375
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2899
char get_typtype(Oid typid)
Definition: lsyscache.c:2769
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:1057
int pg_mblen(const char *mbstr)
Definition: mbutils.c:1023
void namestrcpy(Name name, const char *str)
Definition: name.c:233
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
#define castNode(_type_, nodeptr)
Definition: nodes.h:182
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:173
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
char * nodeToString(const void *obj)
Definition: outfuncs.c:797
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Definition: params.h:108
char * check_valid_internal_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
char * check_valid_polymorphic_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
@ OBJECT_FUNCTION
Definition: parsenodes.h:2336
void * arg
#define FUNC_MAX_ARGS
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
Definition: pg_depend.c:301
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:193
#define lfirst(lc)
Definition: pg_list.h:172
#define lfirst_node(type, lc)
Definition: pg_list.h:176
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define list_make1(x1)
Definition: pg_list.h:212
#define linitial(l)
Definition: pg_list.h:178
static ListCell * list_nth_cell(const List *list, int n)
Definition: pg_list.h:277
#define foreach_oid(var, lst)
Definition: pg_list.h:471
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
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, Node *prosqlbody, 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, List *trfoids, Datum proconfig, Oid prosupport, float4 procost, float4 prorows)
Definition: pg_proc.c:98
static void sql_function_parse_error_callback(void *arg)
Definition: pg_proc.c:999
Datum fmgr_internal_validator(PG_FUNCTION_ARGS)
Definition: pg_proc.c:746
Datum fmgr_c_validator(PG_FUNCTION_ARGS)
Definition: pg_proc.c:789
List * oid_array_to_list(Datum datum)
Definition: pg_proc.c:1205
static bool match_prosrc_to_literal(const char *prosrc, const char *literal, int cursorpos, int *newcursorpos)
Definition: pg_proc.c:1148
bool function_parse_error_transpose(const char *prosrc)
Definition: pg_proc.c:1023
Datum fmgr_sql_validator(PG_FUNCTION_ARGS)
Definition: pg_proc.c:832
static int match_prosrc_to_query(const char *prosrc, const char *queryText, int cursorpos)
Definition: pg_proc.c:1090
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:168
void pgstat_create_function(Oid proid)
@ PORTAL_ACTIVE
Definition: portal.h:108
List * pg_analyze_and_rewrite_withcb(RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
Definition: postgres.c:758
List * pg_parse_query(const char *query_string)
Definition: postgres.c:603
List * pg_rewrite_query(Query *query)
Definition: postgres.c:798
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
static Datum Float4GetDatum(float4 X)
Definition: postgres.h:480
uintptr_t Datum
Definition: postgres.h:69
static Datum UInt16GetDatum(uint16 X)
Definition: postgres.h:197
static Datum BoolGetDatum(bool X)
Definition: postgres.h:107
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
static Datum NameGetDatum(const NameData *X)
Definition: postgres.h:378
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
static Datum CharGetDatum(char X)
Definition: postgres.h:127
#define InvalidOid
Definition: postgres_ext.h:35
unsigned int Oid
Definition: postgres_ext.h:30
Portal ActivePortal
Definition: pquery.c:37
void * stringToNode(const char *str)
Definition: read.c:90
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:299
#define RelationGetDescr(relation)
Definition: rel.h:542
void AcquireRewriteLocks(Query *parsetree, bool forExecute, bool forUpdatePushedDown)
struct ErrorContextCallback * previous
Definition: elog.h:297
void(* callback)(void *arg)
Definition: elog.h:298
ItemPointerData t_self
Definition: htup.h:65
Definition: pg_list.h:54
Definition: nodes.h:135
const char * sourceText
Definition: portal.h:136
PortalStatus status
Definition: portal.h:151
Definition: c.h:712
Definition: c.h:697
int dim1
Definition: c.h:702
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:704
bool superuser(void)
Definition: superuser.c:46
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:243
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:600
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:631
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
bool equalRowTypes(TupleDesc tupdesc1, TupleDesc tupdesc2)
Definition: tupdesc.c:770
void CommandCounterIncrement(void)
Definition: xact.c:1100