PostgreSQL Source Code  git master
plpgsql.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * plpgsql.h - Definitions for the PL/pgSQL
4  * procedural language
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/pl/plpgsql/src/plpgsql.h
12  *
13  *-------------------------------------------------------------------------
14  */
15 
16 #ifndef PLPGSQL_H
17 #define PLPGSQL_H
18 
19 #include "access/xact.h"
20 #include "commands/event_trigger.h"
21 #include "commands/trigger.h"
22 #include "executor/spi.h"
23 #include "utils/expandedrecord.h"
24 #include "utils/typcache.h"
25 
26 
27 /**********************************************************************
28  * Definitions
29  **********************************************************************/
30 
31 /* define our text domain for translations */
32 #undef TEXTDOMAIN
33 #define TEXTDOMAIN PG_TEXTDOMAIN("plpgsql")
34 
35 #undef _
36 #define _(x) dgettext(TEXTDOMAIN, x)
37 
38 /*
39  * Compiler's namespace item types
40  */
41 typedef enum PLpgSQL_nsitem_type
42 {
43  PLPGSQL_NSTYPE_LABEL, /* block label */
44  PLPGSQL_NSTYPE_VAR, /* scalar variable */
45  PLPGSQL_NSTYPE_REC /* composite variable */
47 
48 /*
49  * A PLPGSQL_NSTYPE_LABEL stack entry must be one of these types
50  */
51 typedef enum PLpgSQL_label_type
52 {
53  PLPGSQL_LABEL_BLOCK, /* DECLARE/BEGIN block */
54  PLPGSQL_LABEL_LOOP, /* looping construct */
55  PLPGSQL_LABEL_OTHER /* anything else */
57 
58 /*
59  * Datum array node types
60  */
61 typedef enum PLpgSQL_datum_type
62 {
69 
70 /*
71  * DTYPE_PROMISE datums have these possible ways of computing the promise
72  */
74 {
75  PLPGSQL_PROMISE_NONE = 0, /* not a promise, or promise satisfied */
88 
89 /*
90  * Variants distinguished in PLpgSQL_type structs
91  */
92 typedef enum PLpgSQL_type_type
93 {
94  PLPGSQL_TTYPE_SCALAR, /* scalar types and domains */
95  PLPGSQL_TTYPE_REC, /* composite types, including RECORD */
96  PLPGSQL_TTYPE_PSEUDO /* pseudotypes */
98 
99 /*
100  * Execution tree node types
101  */
102 typedef enum PLpgSQL_stmt_type
103 {
132 
133 /*
134  * Execution node return codes
135  */
136 enum
137 {
142 };
143 
144 /*
145  * GET DIAGNOSTICS information items
146  */
148 {
162 
163 /*
164  * RAISE statement options
165  */
167 {
178 
179 /*
180  * Behavioral modes for plpgsql variable resolution
181  */
183 {
184  PLPGSQL_RESOLVE_ERROR, /* throw error if ambiguous */
185  PLPGSQL_RESOLVE_VARIABLE, /* prefer plpgsql var to table column */
186  PLPGSQL_RESOLVE_COLUMN /* prefer table column to plpgsql var */
188 
189 
190 /**********************************************************************
191  * Node and structure definitions
192  **********************************************************************/
193 
194 /*
195  * Postgres data type
196  */
197 typedef struct PLpgSQL_type
198 {
199  char *typname; /* (simple) name of the type */
200  Oid typoid; /* OID of the data type */
201  PLpgSQL_type_type ttype; /* PLPGSQL_TTYPE_ code */
202  int16 typlen; /* stuff copied from its pg_type entry */
203  bool typbyval;
204  char typtype;
205  Oid collation; /* from pg_type, but can be overridden */
206  bool typisarray; /* is "true" array, or domain over one */
207  int32 atttypmod; /* typmod (taken from someplace else) */
208  /* Remaining fields are used only for named composite types (not RECORD) */
209  TypeName *origtypname; /* type name as written by user */
210  TypeCacheEntry *tcache; /* typcache entry for composite type */
211  uint64 tupdesc_id; /* last-seen tupdesc identifier */
213 
214 /*
215  * SQL Query to plan and execute
216  */
217 typedef struct PLpgSQL_expr
218 {
219  char *query; /* query string, verbatim from function body */
220  RawParseMode parseMode; /* raw_parser() mode to use */
221  SPIPlanPtr plan; /* plan, or NULL if not made yet */
222  Bitmapset *paramnos; /* all dnos referenced by this query */
223 
224  /* function containing this expr (not set until we first parse query) */
226 
227  /* namespace chain visible to this expr */
229 
230  /* fields for "simple expression" fast-path execution: */
231  Expr *expr_simple_expr; /* NULL means not a simple expr */
232  Oid expr_simple_type; /* result type Oid, if simple */
233  int32 expr_simple_typmod; /* result typmod, if simple */
234  bool expr_simple_mutable; /* true if simple expr is mutable */
235 
236  /*
237  * These fields are used to optimize assignments to expanded-datum
238  * variables. If this expression is the source of an assignment to a
239  * simple variable, target_param holds that variable's dno; else it's -1.
240  * If we match a Param within expr_simple_expr to such a variable, that
241  * Param's address is stored in expr_rw_param; then expression code
242  * generation will allow the value for that Param to be passed read/write.
243  */
244  int target_param; /* dno of assign target, or -1 if none */
245  Param *expr_rw_param; /* read/write Param within expr, if any */
246 
247  /*
248  * If the expression was ever determined to be simple, we remember its
249  * CachedPlanSource and CachedPlan here. If expr_simple_plan_lxid matches
250  * current LXID, then we hold a refcount on expr_simple_plan in the
251  * current transaction. Otherwise we need to get one before re-using it.
252  */
253  CachedPlanSource *expr_simple_plansource; /* extracted from "plan" */
254  CachedPlan *expr_simple_plan; /* extracted from "plan" */
256 
257  /*
258  * if expr is simple AND prepared in current transaction,
259  * expr_simple_state and expr_simple_in_use are valid. Test validity by
260  * seeing if expr_simple_lxid matches current LXID. (If not,
261  * expr_simple_state probably points at garbage!)
262  */
263  ExprState *expr_simple_state; /* eval tree for expr_simple_expr */
264  bool expr_simple_in_use; /* true if eval tree is active */
267 
268 /*
269  * Generic datum array item
270  *
271  * PLpgSQL_datum is the common supertype for PLpgSQL_var, PLpgSQL_row,
272  * PLpgSQL_rec, and PLpgSQL_recfield.
273  */
274 typedef struct PLpgSQL_datum
275 {
277  int dno;
279 
280 /*
281  * Scalar or composite variable
282  *
283  * The variants PLpgSQL_var, PLpgSQL_row, and PLpgSQL_rec share these
284  * fields.
285  */
286 typedef struct PLpgSQL_variable
287 {
289  int dno;
290  char *refname;
291  int lineno;
292  bool isconst;
293  bool notnull;
296 
297 /*
298  * Scalar variable
299  *
300  * DTYPE_VAR and DTYPE_PROMISE datums both use this struct type.
301  * A PROMISE datum works exactly like a VAR datum for most purposes,
302  * but if it is read without having previously been assigned to, then
303  * a special "promised" value is computed and assigned to the datum
304  * before the read is performed. This technique avoids the overhead of
305  * computing the variable's value in cases where we expect that many
306  * functions will never read it.
307  */
308 typedef struct PLpgSQL_var
309 {
311  int dno;
312  char *refname;
313  int lineno;
314  bool isconst;
315  bool notnull;
317  /* end of PLpgSQL_variable fields */
318 
320 
321  /*
322  * Variables declared as CURSOR FOR <query> are mostly like ordinary
323  * scalar variables of type refcursor, but they have these additional
324  * properties:
325  */
329 
330  /* Fields below here can change at runtime */
331 
333  bool isnull;
334  bool freeval;
335 
336  /*
337  * The promise field records which "promised" value to assign if the
338  * promise must be honored. If it's a normal variable, or the promise has
339  * been fulfilled, this is PLPGSQL_PROMISE_NONE.
340  */
343 
344 /*
345  * Row variable - this represents one or more variables that are listed in an
346  * INTO clause, FOR-loop targetlist, cursor argument list, etc. We also use
347  * a row to represent a function's OUT parameters when there's more than one.
348  *
349  * Note that there's no way to name the row as such from PL/pgSQL code,
350  * so many functions don't need to support these.
351  *
352  * That also means that there's no real name for the row variable, so we
353  * conventionally set refname to "(unnamed row)". We could leave it NULL,
354  * but it's too convenient to be able to assume that refname is valid in
355  * all variants of PLpgSQL_variable.
356  *
357  * isconst, notnull, and default_val are unsupported (and hence
358  * always zero/null) for a row. The member variables of a row should have
359  * been checked to be writable at compile time, so isconst is correctly set
360  * to false. notnull and default_val aren't applicable.
361  */
362 typedef struct PLpgSQL_row
363 {
365  int dno;
366  char *refname;
367  int lineno;
368  bool isconst;
369  bool notnull;
371  /* end of PLpgSQL_variable fields */
372 
373  /*
374  * rowtupdesc is only set up if we might need to convert the row into a
375  * composite datum, which currently only happens for OUT parameters.
376  * Otherwise it is NULL.
377  */
379 
380  int nfields;
381  char **fieldnames;
382  int *varnos;
384 
385 /*
386  * Record variable (any composite type, including RECORD)
387  */
388 typedef struct PLpgSQL_rec
389 {
391  int dno;
392  char *refname;
393  int lineno;
394  bool isconst;
395  bool notnull;
397  /* end of PLpgSQL_variable fields */
398 
399  /*
400  * Note: for non-RECORD cases, we may from time to time re-look-up the
401  * composite type, using datatype->origtypname. That can result in
402  * changing rectypeid.
403  */
404 
405  PLpgSQL_type *datatype; /* can be NULL, if rectypeid is RECORDOID */
406  Oid rectypeid; /* declared type of variable */
407  /* RECFIELDs for this record are chained together for easy access */
408  int firstfield; /* dno of first RECFIELD, or -1 if none */
409 
410  /* Fields below here can change at runtime */
411 
412  /* We always store record variables as "expanded" records */
415 
416 /*
417  * Field in record
418  */
419 typedef struct PLpgSQL_recfield
420 {
422  int dno;
423  /* end of PLpgSQL_datum fields */
424 
425  char *fieldname; /* name of field */
426  int recparentno; /* dno of parent record */
427  int nextfield; /* dno of next child, or -1 if none */
428  uint64 rectupledescid; /* record's tupledesc ID as of last lookup */
429  ExpandedRecordFieldInfo finfo; /* field's attnum and type info */
430  /* if rectupledescid == INVALID_TUPLEDESC_IDENTIFIER, finfo isn't valid */
432 
433 /*
434  * Item in the compilers namespace tree
435  */
436 typedef struct PLpgSQL_nsitem
437 {
439 
440  /*
441  * For labels, itemno is a value of enum PLpgSQL_label_type. For other
442  * itemtypes, itemno is the associated PLpgSQL_datum's dno.
443  */
444  int itemno;
446  char name[FLEXIBLE_ARRAY_MEMBER]; /* nul-terminated string */
448 
449 /*
450  * Generic execution node
451  */
452 typedef struct PLpgSQL_stmt
453 {
455  int lineno;
456 
457  /*
458  * Unique statement ID in this function (starting at 1; 0 is invalid/not
459  * set). This can be used by a profiler as the index for an array of
460  * per-statement metrics.
461  */
462  unsigned int stmtid;
464 
465 /*
466  * One EXCEPTION condition name
467  */
468 typedef struct PLpgSQL_condition
469 {
470  int sqlerrstate; /* SQLSTATE code */
471  char *condname; /* condition name (for debugging) */
474 
475 /*
476  * EXCEPTION block
477  */
479 {
482  List *exc_list; /* List of WHEN clauses */
484 
485 /*
486  * One EXCEPTION ... WHEN clause
487  */
488 typedef struct PLpgSQL_exception
489 {
490  int lineno;
492  List *action; /* List of statements */
494 
495 /*
496  * Block of statements
497  */
498 typedef struct PLpgSQL_stmt_block
499 {
501  int lineno;
502  unsigned int stmtid;
503  char *label;
504  List *body; /* List of statements */
505  int n_initvars; /* Length of initvarnos[] */
506  int *initvarnos; /* dnos of variables declared in this block */
509 
510 /*
511  * Assign statement
512  */
513 typedef struct PLpgSQL_stmt_assign
514 {
516  int lineno;
517  unsigned int stmtid;
518  int varno;
521 
522 /*
523  * PERFORM statement
524  */
525 typedef struct PLpgSQL_stmt_perform
526 {
528  int lineno;
529  unsigned int stmtid;
532 
533 /*
534  * CALL statement
535  */
536 typedef struct PLpgSQL_stmt_call
537 {
539  int lineno;
540  unsigned int stmtid;
542  bool is_call;
545 
546 /*
547  * COMMIT statement
548  */
549 typedef struct PLpgSQL_stmt_commit
550 {
552  int lineno;
553  unsigned int stmtid;
554  bool chain;
556 
557 /*
558  * ROLLBACK statement
559  */
560 typedef struct PLpgSQL_stmt_rollback
561 {
563  int lineno;
564  unsigned int stmtid;
565  bool chain;
567 
568 /*
569  * GET DIAGNOSTICS item
570  */
571 typedef struct PLpgSQL_diag_item
572 {
573  PLpgSQL_getdiag_kind kind; /* id for diagnostic value desired */
574  int target; /* where to assign it */
576 
577 /*
578  * GET DIAGNOSTICS statement
579  */
580 typedef struct PLpgSQL_stmt_getdiag
581 {
583  int lineno;
584  unsigned int stmtid;
585  bool is_stacked; /* STACKED or CURRENT diagnostics area? */
586  List *diag_items; /* List of PLpgSQL_diag_item */
588 
589 /*
590  * IF statement
591  */
592 typedef struct PLpgSQL_stmt_if
593 {
595  int lineno;
596  unsigned int stmtid;
597  PLpgSQL_expr *cond; /* boolean expression for THEN */
598  List *then_body; /* List of statements */
599  List *elsif_list; /* List of PLpgSQL_if_elsif structs */
600  List *else_body; /* List of statements */
602 
603 /*
604  * one ELSIF arm of IF statement
605  */
606 typedef struct PLpgSQL_if_elsif
607 {
608  int lineno;
609  PLpgSQL_expr *cond; /* boolean expression for this case */
610  List *stmts; /* List of statements */
612 
613 /*
614  * CASE statement
615  */
616 typedef struct PLpgSQL_stmt_case
617 {
619  int lineno;
620  unsigned int stmtid;
621  PLpgSQL_expr *t_expr; /* test expression, or NULL if none */
622  int t_varno; /* var to store test expression value into */
623  List *case_when_list; /* List of PLpgSQL_case_when structs */
624  bool have_else; /* flag needed because list could be empty */
625  List *else_stmts; /* List of statements */
627 
628 /*
629  * one arm of CASE statement
630  */
631 typedef struct PLpgSQL_case_when
632 {
633  int lineno;
634  PLpgSQL_expr *expr; /* boolean expression for this case */
635  List *stmts; /* List of statements */
637 
638 /*
639  * Unconditional LOOP statement
640  */
641 typedef struct PLpgSQL_stmt_loop
642 {
644  int lineno;
645  unsigned int stmtid;
646  char *label;
647  List *body; /* List of statements */
649 
650 /*
651  * WHILE cond LOOP statement
652  */
653 typedef struct PLpgSQL_stmt_while
654 {
656  int lineno;
657  unsigned int stmtid;
658  char *label;
660  List *body; /* List of statements */
662 
663 /*
664  * FOR statement with integer loopvar
665  */
666 typedef struct PLpgSQL_stmt_fori
667 {
669  int lineno;
670  unsigned int stmtid;
671  char *label;
675  PLpgSQL_expr *step; /* NULL means default (ie, BY 1) */
676  int reverse;
677  List *body; /* List of statements */
679 
680 /*
681  * PLpgSQL_stmt_forq represents a FOR statement running over a SQL query.
682  * It is the common supertype of PLpgSQL_stmt_fors, PLpgSQL_stmt_forc
683  * and PLpgSQL_stmt_dynfors.
684  */
685 typedef struct PLpgSQL_stmt_forq
686 {
688  int lineno;
689  unsigned int stmtid;
690  char *label;
691  PLpgSQL_variable *var; /* Loop variable (record or row) */
692  List *body; /* List of statements */
694 
695 /*
696  * FOR statement running over SELECT
697  */
698 typedef struct PLpgSQL_stmt_fors
699 {
701  int lineno;
702  unsigned int stmtid;
703  char *label;
704  PLpgSQL_variable *var; /* Loop variable (record or row) */
705  List *body; /* List of statements */
706  /* end of fields that must match PLpgSQL_stmt_forq */
709 
710 /*
711  * FOR statement running over cursor
712  */
713 typedef struct PLpgSQL_stmt_forc
714 {
716  int lineno;
717  unsigned int stmtid;
718  char *label;
719  PLpgSQL_variable *var; /* Loop variable (record or row) */
720  List *body; /* List of statements */
721  /* end of fields that must match PLpgSQL_stmt_forq */
722  int curvar;
723  PLpgSQL_expr *argquery; /* cursor arguments if any */
725 
726 /*
727  * FOR statement running over EXECUTE
728  */
729 typedef struct PLpgSQL_stmt_dynfors
730 {
732  int lineno;
733  unsigned int stmtid;
734  char *label;
735  PLpgSQL_variable *var; /* Loop variable (record or row) */
736  List *body; /* List of statements */
737  /* end of fields that must match PLpgSQL_stmt_forq */
739  List *params; /* USING expressions */
741 
742 /*
743  * FOREACH item in array loop
744  */
746 {
748  int lineno;
749  unsigned int stmtid;
750  char *label;
751  int varno; /* loop target variable */
752  int slice; /* slice dimension, or 0 */
753  PLpgSQL_expr *expr; /* array expression */
754  List *body; /* List of statements */
756 
757 /*
758  * OPEN a curvar
759  */
760 typedef struct PLpgSQL_stmt_open
761 {
763  int lineno;
764  unsigned int stmtid;
765  int curvar;
770  List *params; /* USING expressions */
772 
773 /*
774  * FETCH or MOVE statement
775  */
776 typedef struct PLpgSQL_stmt_fetch
777 {
779  int lineno;
780  unsigned int stmtid;
781  PLpgSQL_variable *target; /* target (record or row) */
782  int curvar; /* cursor variable to fetch from */
783  FetchDirection direction; /* fetch direction */
784  long how_many; /* count, if constant (expr is NULL) */
785  PLpgSQL_expr *expr; /* count, if expression */
786  bool is_move; /* is this a fetch or move? */
787  bool returns_multiple_rows; /* can return more than one row? */
789 
790 /*
791  * CLOSE curvar
792  */
793 typedef struct PLpgSQL_stmt_close
794 {
796  int lineno;
797  unsigned int stmtid;
798  int curvar;
800 
801 /*
802  * EXIT or CONTINUE statement
803  */
804 typedef struct PLpgSQL_stmt_exit
805 {
807  int lineno;
808  unsigned int stmtid;
809  bool is_exit; /* Is this an exit or a continue? */
810  char *label; /* NULL if it's an unlabeled EXIT/CONTINUE */
813 
814 /*
815  * RETURN statement
816  */
817 typedef struct PLpgSQL_stmt_return
818 {
820  int lineno;
821  unsigned int stmtid;
823  int retvarno;
825 
826 /*
827  * RETURN NEXT statement
828  */
830 {
832  int lineno;
833  unsigned int stmtid;
835  int retvarno;
837 
838 /*
839  * RETURN QUERY statement
840  */
842 {
844  int lineno;
845  unsigned int stmtid;
846  PLpgSQL_expr *query; /* if static query */
847  PLpgSQL_expr *dynquery; /* if dynamic query (RETURN QUERY EXECUTE) */
848  List *params; /* USING arguments for dynamic query */
850 
851 /*
852  * RAISE statement
853  */
854 typedef struct PLpgSQL_stmt_raise
855 {
857  int lineno;
858  unsigned int stmtid;
860  char *condname; /* condition name, SQLSTATE, or NULL */
861  char *message; /* old-style message format literal, or NULL */
862  List *params; /* list of expressions for old-style message */
863  List *options; /* list of PLpgSQL_raise_option */
865 
866 /*
867  * RAISE statement option
868  */
869 typedef struct PLpgSQL_raise_option
870 {
874 
875 /*
876  * ASSERT statement
877  */
878 typedef struct PLpgSQL_stmt_assert
879 {
881  int lineno;
882  unsigned int stmtid;
886 
887 /*
888  * Generic SQL statement to execute
889  */
890 typedef struct PLpgSQL_stmt_execsql
891 {
893  int lineno;
894  unsigned int stmtid;
896  bool mod_stmt; /* is the stmt INSERT/UPDATE/DELETE/MERGE? */
897  bool mod_stmt_set; /* is mod_stmt valid yet? */
898  bool into; /* INTO supplied? */
899  bool strict; /* INTO STRICT flag */
900  PLpgSQL_variable *target; /* INTO target (record or row) */
902 
903 /*
904  * Dynamic SQL string to execute
905  */
907 {
909  int lineno;
910  unsigned int stmtid;
911  PLpgSQL_expr *query; /* string expression */
912  bool into; /* INTO supplied? */
913  bool strict; /* INTO STRICT flag */
914  PLpgSQL_variable *target; /* INTO target (record or row) */
915  List *params; /* USING expressions */
917 
918 /*
919  * Hash lookup key for functions
920  */
921 typedef struct PLpgSQL_func_hashkey
922 {
924 
925  bool isTrigger; /* true if called as a DML trigger */
926  bool isEventTrigger; /* true if called as an event trigger */
927 
928  /* be careful that pad bytes in this struct get zeroed! */
929 
930  /*
931  * For a trigger function, the OID of the trigger is part of the hash key
932  * --- we want to compile the trigger function separately for each trigger
933  * it is used with, in case the rowtype or transition table names are
934  * different. Zero if not called as a DML trigger.
935  */
937 
938  /*
939  * We must include the input collation as part of the hash key too,
940  * because we have to generate different plans (with different Param
941  * collations) for different collation settings.
942  */
944 
945  /*
946  * We include actual argument types in the hash key to support polymorphic
947  * PLpgSQL functions. Be careful that extra positions are zeroed!
948  */
951 
952 /*
953  * Trigger type
954  */
955 typedef enum PLpgSQL_trigtype
956 {
961 
962 /*
963  * Complete compiled function
964  */
965 typedef struct PLpgSQL_function
966 {
973  PLpgSQL_func_hashkey *fn_hashkey; /* back-link to hashtable key */
975 
981  bool fn_retset;
984 
985  int fn_nargs;
991 
993 
995 
996  /* extra checks */
999 
1000  /* the datums representing the function's local variables */
1001  int ndatums;
1003  Size copiable_size; /* space for locally instantiated datums */
1004 
1005  /* function body parsetree */
1007 
1008  /* data derived while parsing body */
1009  unsigned int nstatements; /* counter for assigning stmtids */
1010  bool requires_procedure_resowner; /* contains CALL or DO? */
1011 
1012  /* these fields change when the function is used */
1014  unsigned long use_count;
1016 
1017 /*
1018  * Runtime execution data
1019  */
1020 typedef struct PLpgSQL_execstate
1021 {
1022  PLpgSQL_function *func; /* function being executed */
1023 
1024  TriggerData *trigdata; /* if regular trigger, data about firing */
1025  EventTriggerData *evtrigdata; /* if event trigger, data about firing */
1026 
1029  Oid rettype; /* type of current retval */
1030 
1031  Oid fn_rettype; /* info about declared function rettype */
1033  bool retisset;
1034 
1036  bool atomic;
1037 
1038  char *exitlabel; /* the "target" label of the current EXIT or
1039  * CONTINUE stmt, if any */
1040  ErrorData *cur_error; /* current exception handler's error */
1041 
1042  Tuplestorestate *tuple_store; /* SRFs accumulate results here */
1043  TupleDesc tuple_store_desc; /* descriptor for tuples in tuple_store */
1047 
1049 
1050  /*
1051  * The datums representing the function's local variables. Some of these
1052  * are local storage in this execstate, but some just point to the shared
1053  * copy belonging to the PLpgSQL_function, depending on whether or not we
1054  * need any per-execution state for the datum's dtype.
1055  */
1056  int ndatums;
1058  /* context containing variable values (same as func's SPI_proc context) */
1060 
1061  /*
1062  * paramLI is what we use to pass local variable values to the executor.
1063  * It does not have a ParamExternData array; we just dynamically
1064  * instantiate parameter data as needed. By convention, PARAM_EXTERN
1065  * Params have paramid equal to the dno of the referenced local variable.
1066  */
1068 
1069  /* EState and resowner to use for "simple" expression evaluation */
1072 
1073  /* if running nonatomic procedure or DO block, resowner to use for CALL */
1075 
1076  /* lookup table to use for executing type casts */
1079 
1080  /* memory context for statement-lifespan temporary values */
1081  MemoryContext stmt_mcontext; /* current stmt context, or NULL if none */
1082  MemoryContext stmt_mcontext_parent; /* parent of current context */
1083 
1084  /* temporary state for results from evaluation of query or expr */
1087  ExprContext *eval_econtext; /* for executing simple expressions */
1088 
1089  /* status information for error context reporting */
1090  PLpgSQL_stmt *err_stmt; /* current stmt */
1091  PLpgSQL_variable *err_var; /* current variable, if in a DECLARE section */
1092  const char *err_text; /* additional state info */
1093 
1094  void *plugin_info; /* reserved for use by optional plugin */
1096 
1097 /*
1098  * A PLpgSQL_plugin structure represents an instrumentation plugin.
1099  * To instrument PL/pgSQL, a plugin library must access the rendezvous
1100  * variable "PLpgSQL_plugin" and set it to point to a PLpgSQL_plugin struct.
1101  * Typically the struct could just be static data in the plugin library.
1102  * We expect that a plugin would do this at library load time (_PG_init()).
1103  *
1104  * This structure is basically a collection of function pointers --- at
1105  * various interesting points in pl_exec.c, we call these functions
1106  * (if the pointers are non-NULL) to give the plugin a chance to watch
1107  * what we are doing.
1108  *
1109  * func_setup is called when we start a function, before we've initialized
1110  * the local variables defined by the function.
1111  *
1112  * func_beg is called when we start a function, after we've initialized
1113  * the local variables.
1114  *
1115  * func_end is called at the end of a function.
1116  *
1117  * stmt_beg and stmt_end are called before and after (respectively) each
1118  * statement.
1119  *
1120  * Also, immediately before any call to func_setup, PL/pgSQL fills in the
1121  * remaining fields with pointers to some of its own functions, allowing the
1122  * plugin to invoke those functions conveniently. The exposed functions are:
1123  * plpgsql_exec_error_callback
1124  * exec_assign_expr
1125  * exec_assign_value
1126  * exec_eval_datum
1127  * exec_cast_value
1128  * (plpgsql_exec_error_callback is not actually meant to be called by the
1129  * plugin, but rather to allow it to identify PL/pgSQL error context stack
1130  * frames. The others are useful for debugger-like plugins to examine and
1131  * set variables.)
1132  */
1133 typedef struct PLpgSQL_plugin
1134 {
1135  /* Function pointers set up by the plugin */
1137  void (*func_beg) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
1138  void (*func_end) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
1139  void (*stmt_beg) (PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt);
1140  void (*stmt_end) (PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt);
1141 
1142  /* Function pointers set by PL/pgSQL itself */
1143  void (*error_callback) (void *arg);
1144  void (*assign_expr) (PLpgSQL_execstate *estate,
1145  PLpgSQL_datum *target,
1146  PLpgSQL_expr *expr);
1148  PLpgSQL_datum *target,
1149  Datum value, bool isNull,
1150  Oid valtype, int32 valtypmod);
1151  void (*eval_datum) (PLpgSQL_execstate *estate, PLpgSQL_datum *datum,
1152  Oid *typeId, int32 *typetypmod,
1153  Datum *value, bool *isnull);
1155  Datum value, bool *isnull,
1156  Oid valtype, int32 valtypmod,
1157  Oid reqtype, int32 reqtypmod);
1159 
1160 /*
1161  * Struct types used during parsing
1162  */
1163 
1164 typedef struct PLword
1165 {
1166  char *ident; /* palloc'd converted identifier */
1167  bool quoted; /* Was it double-quoted? */
1169 
1170 typedef struct PLcword
1171 {
1172  List *idents; /* composite identifiers (list of String) */
1174 
1175 typedef struct PLwdatum
1176 {
1177  PLpgSQL_datum *datum; /* referenced variable */
1178  char *ident; /* valid if simple name */
1179  bool quoted;
1180  List *idents; /* valid if composite name */
1182 
1183 /**********************************************************************
1184  * Global variable declarations
1185  **********************************************************************/
1186 
1187 typedef enum
1188 {
1189  IDENTIFIER_LOOKUP_NORMAL, /* normal processing of var names */
1190  IDENTIFIER_LOOKUP_DECLARE, /* In DECLARE --- don't look up names */
1191  IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */
1193 
1195 
1196 extern int plpgsql_variable_conflict;
1197 
1198 extern bool plpgsql_print_strict_params;
1199 
1200 extern bool plpgsql_check_asserts;
1201 
1202 /* extra compile-time and run-time checks */
1203 #define PLPGSQL_XCHECK_NONE 0
1204 #define PLPGSQL_XCHECK_SHADOWVAR (1 << 1)
1205 #define PLPGSQL_XCHECK_TOOMANYROWS (1 << 2)
1206 #define PLPGSQL_XCHECK_STRICTMULTIASSIGNMENT (1 << 3)
1207 #define PLPGSQL_XCHECK_ALL ((int) ~0)
1208 
1209 extern int plpgsql_extra_warnings;
1210 extern int plpgsql_extra_errors;
1211 
1212 extern bool plpgsql_check_syntax;
1213 extern bool plpgsql_DumpExecTree;
1214 
1216 
1217 extern int plpgsql_nDatums;
1218 extern PLpgSQL_datum **plpgsql_Datums;
1219 
1220 extern char *plpgsql_error_funcname;
1221 
1224 
1226 
1227 /**********************************************************************
1228  * Function declarations
1229  **********************************************************************/
1230 
1231 /*
1232  * Functions in pl_comp.c
1233  */
1235  bool forValidator);
1236 extern PLpgSQL_function *plpgsql_compile_inline(char *proc_source);
1237 extern void plpgsql_parser_setup(struct ParseState *pstate,
1238  PLpgSQL_expr *expr);
1239 extern bool plpgsql_parse_word(char *word1, const char *yytxt, bool lookup,
1240  PLwdatum *wdatum, PLword *word);
1241 extern bool plpgsql_parse_dblword(char *word1, char *word2,
1242  PLwdatum *wdatum, PLcword *cword);
1243 extern bool plpgsql_parse_tripword(char *word1, char *word2, char *word3,
1244  PLwdatum *wdatum, PLcword *cword);
1245 extern PLpgSQL_type *plpgsql_parse_wordtype(char *ident);
1246 extern PLpgSQL_type *plpgsql_parse_cwordtype(List *idents);
1247 extern PLpgSQL_type *plpgsql_parse_wordrowtype(char *ident);
1249 extern PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32 typmod,
1250  Oid collation,
1251  TypeName *origtypname);
1252 extern PLpgSQL_variable *plpgsql_build_variable(const char *refname, int lineno,
1253  PLpgSQL_type *dtype,
1254  bool add2namespace);
1255 extern PLpgSQL_rec *plpgsql_build_record(const char *refname, int lineno,
1256  PLpgSQL_type *dtype, Oid rectypeid,
1257  bool add2namespace);
1259  const char *fldname);
1260 extern int plpgsql_recognize_err_condition(const char *condname,
1261  bool allow_sqlstate);
1262 extern PLpgSQL_condition *plpgsql_parse_err_condition(char *condname);
1263 extern void plpgsql_adddatum(PLpgSQL_datum *newdatum);
1264 extern int plpgsql_add_initdatums(int **varnos);
1265 extern void plpgsql_HashTableInit(void);
1266 
1267 /*
1268  * Functions in pl_handler.c
1269  */
1270 extern void _PG_init(void);
1271 
1272 /*
1273  * Functions in pl_exec.c
1274  */
1276  FunctionCallInfo fcinfo,
1277  EState *simple_eval_estate,
1278  ResourceOwner simple_eval_resowner,
1279  ResourceOwner procedure_resowner,
1280  bool atomic);
1282  TriggerData *trigdata);
1284  EventTriggerData *trigdata);
1285 extern void plpgsql_xact_cb(XactEvent event, void *arg);
1286 extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid,
1287  SubTransactionId parentSubid, void *arg);
1289  PLpgSQL_datum *datum);
1291  PLpgSQL_datum *datum,
1292  Oid *typeId, int32 *typMod,
1293  Oid *collation);
1294 
1295 /*
1296  * Functions for namespace handling in pl_funcs.c
1297  */
1298 extern void plpgsql_ns_init(void);
1299 extern void plpgsql_ns_push(const char *label,
1300  PLpgSQL_label_type label_type);
1301 extern void plpgsql_ns_pop(void);
1302 extern PLpgSQL_nsitem *plpgsql_ns_top(void);
1303 extern void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name);
1304 extern PLpgSQL_nsitem *plpgsql_ns_lookup(PLpgSQL_nsitem *ns_cur, bool localmode,
1305  const char *name1, const char *name2,
1306  const char *name3, int *names_used);
1308  const char *name);
1310 
1311 /*
1312  * Other functions in pl_funcs.c
1313  */
1314 extern const char *plpgsql_stmt_typename(PLpgSQL_stmt *stmt);
1315 extern const char *plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind);
1317 extern void plpgsql_dumptree(PLpgSQL_function *func);
1318 
1319 /*
1320  * Scanner functions in pl_scanner.c
1321  */
1322 extern int plpgsql_base_yylex(void);
1323 extern int plpgsql_yylex(void);
1324 extern void plpgsql_push_back_token(int token);
1325 extern bool plpgsql_token_is_unreserved_keyword(int token);
1327  int startlocation, int endlocation);
1328 extern int plpgsql_peek(void);
1329 extern void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc,
1330  int *tok2_loc);
1331 extern int plpgsql_scanner_errposition(int location);
1332 extern void plpgsql_yyerror(const char *message) pg_attribute_noreturn();
1333 extern int plpgsql_location_to_lineno(int location);
1334 extern int plpgsql_latest_lineno(void);
1335 extern void plpgsql_scanner_init(const char *str);
1336 extern void plpgsql_scanner_finish(void);
1337 
1338 /*
1339  * Externs in gram.y
1340  */
1341 extern int plpgsql_yyparse(void);
1342 
1343 #endif /* PLPGSQL_H */
signed short int16
Definition: c.h:428
uint32 SubTransactionId
Definition: c.h:591
signed int int32
Definition: c.h:429
#define pg_attribute_noreturn()
Definition: c.h:179
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:350
uint32 LocalTransactionId
Definition: c.h:589
uint32 TransactionId
Definition: c.h:587
size_t Size
Definition: c.h:540
const char * name
Definition: encode.c:561
static struct @151 value
FetchDirection
Definition: parsenodes.h:3203
RawParseMode
Definition: parser.h:38
void * arg
static char * label
#define FUNC_MAX_ARGS
static char * buf
Definition: pg_test_fsync.c:67
struct PLpgSQL_stmt_dynexecute PLpgSQL_stmt_dynexecute
void plpgsql_scanner_finish(void)
Definition: pl_scanner.c:613
PLpgSQL_recfield * plpgsql_build_recfield(PLpgSQL_rec *rec, const char *fldname)
Definition: pl_comp.c:2044
void plpgsql_ns_pop(void)
Definition: pl_funcs.c:67
struct PLpgSQL_type PLpgSQL_type
const char * plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind)
Definition: pl_funcs.c:300
int plpgsql_variable_conflict
Definition: pl_handler.c:44
struct PLpgSQL_stmt_while PLpgSQL_stmt_while
struct PLpgSQL_function PLpgSQL_function
bool plpgsql_check_asserts
Definition: pl_handler.c:48
int plpgsql_scanner_errposition(int location)
Definition: pl_scanner.c:472
struct PLpgSQL_stmt_assert PLpgSQL_stmt_assert
PLpgSQL_resolve_option
Definition: plpgsql.h:183
@ PLPGSQL_RESOLVE_COLUMN
Definition: plpgsql.h:186
@ PLPGSQL_RESOLVE_ERROR
Definition: plpgsql.h:184
@ PLPGSQL_RESOLVE_VARIABLE
Definition: plpgsql.h:185
struct PLpgSQL_stmt_open PLpgSQL_stmt_open
int plpgsql_extra_warnings
Definition: pl_handler.c:52
PLpgSQL_trigtype
Definition: plpgsql.h:956
@ PLPGSQL_DML_TRIGGER
Definition: plpgsql.h:957
@ PLPGSQL_NOT_TRIGGER
Definition: plpgsql.h:959
@ PLPGSQL_EVENT_TRIGGER
Definition: plpgsql.h:958
struct PLpgSQL_func_hashkey PLpgSQL_func_hashkey
struct PLpgSQL_stmt_fetch PLpgSQL_stmt_fetch
struct PLpgSQL_raise_option PLpgSQL_raise_option
void plpgsql_parser_setup(struct ParseState *pstate, PLpgSQL_expr *expr)
Definition: pl_comp.c:1081
int plpgsql_add_initdatums(int **varnos)
Definition: pl_comp.c:2394
MemoryContext plpgsql_compile_tmp_cxt
Definition: pl_comp.c:56
PLpgSQL_rec * plpgsql_build_record(const char *refname, int lineno, PLpgSQL_type *dtype, Oid rectypeid, bool add2namespace)
Definition: pl_comp.c:1950
struct PLpgSQL_variable PLpgSQL_variable
struct PLpgSQL_nsitem PLpgSQL_nsitem
struct PLpgSQL_stmt_getdiag PLpgSQL_stmt_getdiag
struct PLpgSQL_stmt_return_next PLpgSQL_stmt_return_next
PLpgSQL_stmt_type
Definition: plpgsql.h:103
@ PLPGSQL_STMT_DYNFORS
Definition: plpgsql.h:122
@ PLPGSQL_STMT_FORI
Definition: plpgsql.h:110
@ PLPGSQL_STMT_FETCH
Definition: plpgsql.h:125
@ PLPGSQL_STMT_CASE
Definition: plpgsql.h:107
@ PLPGSQL_STMT_OPEN
Definition: plpgsql.h:124
@ PLPGSQL_STMT_ROLLBACK
Definition: plpgsql.h:130
@ PLPGSQL_STMT_COMMIT
Definition: plpgsql.h:129
@ PLPGSQL_STMT_RETURN_QUERY
Definition: plpgsql.h:117
@ PLPGSQL_STMT_RETURN
Definition: plpgsql.h:115
@ PLPGSQL_STMT_CLOSE
Definition: plpgsql.h:126
@ PLPGSQL_STMT_WHILE
Definition: plpgsql.h:109
@ PLPGSQL_STMT_BLOCK
Definition: plpgsql.h:104
@ PLPGSQL_STMT_FORS
Definition: plpgsql.h:111
@ PLPGSQL_STMT_FORC
Definition: plpgsql.h:112
@ PLPGSQL_STMT_IF
Definition: plpgsql.h:106
@ PLPGSQL_STMT_PERFORM
Definition: plpgsql.h:127
@ PLPGSQL_STMT_LOOP
Definition: plpgsql.h:108
@ PLPGSQL_STMT_ASSERT
Definition: plpgsql.h:119
@ PLPGSQL_STMT_FOREACH_A
Definition: plpgsql.h:113
@ PLPGSQL_STMT_GETDIAG
Definition: plpgsql.h:123
@ PLPGSQL_STMT_RETURN_NEXT
Definition: plpgsql.h:116
@ PLPGSQL_STMT_ASSIGN
Definition: plpgsql.h:105
@ PLPGSQL_STMT_EXIT
Definition: plpgsql.h:114
@ PLPGSQL_STMT_EXECSQL
Definition: plpgsql.h:120
@ PLPGSQL_STMT_RAISE
Definition: plpgsql.h:118
@ PLPGSQL_STMT_CALL
Definition: plpgsql.h:128
@ PLPGSQL_STMT_DYNEXECUTE
Definition: plpgsql.h:121
PLpgSQL_type * plpgsql_parse_wordrowtype(char *ident)
Definition: pl_comp.c:1802
void _PG_init(void)
Definition: auth_delay.c:56
PLpgSQL_type_type
Definition: plpgsql.h:93
@ PLPGSQL_TTYPE_PSEUDO
Definition: plpgsql.h:96
@ PLPGSQL_TTYPE_REC
Definition: plpgsql.h:95
@ PLPGSQL_TTYPE_SCALAR
Definition: plpgsql.h:94
struct PLpgSQL_if_elsif PLpgSQL_if_elsif
int plpgsql_recognize_err_condition(const char *condname, bool allow_sqlstate)
Definition: pl_comp.c:2229
void plpgsql_ns_init(void)
Definition: pl_funcs.c:43
struct PLpgSQL_stmt_dynfors PLpgSQL_stmt_dynfors
struct PLpgSQL_stmt PLpgSQL_stmt
struct PLpgSQL_stmt_call PLpgSQL_stmt_call
struct PLpgSQL_stmt_fors PLpgSQL_stmt_fors
PLpgSQL_type * plpgsql_parse_cwordrowtype(List *idents)
Definition: pl_comp.c:1839
Datum plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo, EState *simple_eval_estate, ResourceOwner simple_eval_resowner, ResourceOwner procedure_resowner, bool atomic)
Definition: pl_exec.c:471
struct PLcword PLcword
PLpgSQL_variable * plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, bool add2namespace)
Definition: pl_comp.c:1887
struct PLpgSQL_stmt_perform PLpgSQL_stmt_perform
int plpgsql_location_to_lineno(int location)
Definition: pl_scanner.c:538
struct PLpgSQL_diag_item PLpgSQL_diag_item
struct PLpgSQL_row PLpgSQL_row
void plpgsql_HashTableInit(void)
Definition: pl_comp.c:2589
IdentifierLookup
Definition: plpgsql.h:1188
@ IDENTIFIER_LOOKUP_DECLARE
Definition: plpgsql.h:1190
@ IDENTIFIER_LOOKUP_NORMAL
Definition: plpgsql.h:1189
@ IDENTIFIER_LOOKUP_EXPR
Definition: plpgsql.h:1191
struct PLpgSQL_var PLpgSQL_var
void plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate, PLpgSQL_datum *datum, Oid *typeId, int32 *typMod, Oid *collation)
Definition: pl_exec.c:5520
IdentifierLookup plpgsql_IdentifierLookup
Definition: pl_scanner.c:26
struct PLpgSQL_stmt_raise PLpgSQL_stmt_raise
void plpgsql_dumptree(PLpgSQL_function *func)
Definition: pl_funcs.c:1598
char * plpgsql_error_funcname
Definition: pl_comp.c:49
PLpgSQL_raise_option_type
Definition: plpgsql.h:167
@ PLPGSQL_RAISEOPTION_COLUMN
Definition: plpgsql.h:172
@ PLPGSQL_RAISEOPTION_TABLE
Definition: plpgsql.h:175
@ PLPGSQL_RAISEOPTION_SCHEMA
Definition: plpgsql.h:176
@ PLPGSQL_RAISEOPTION_CONSTRAINT
Definition: plpgsql.h:173
@ PLPGSQL_RAISEOPTION_DETAIL
Definition: plpgsql.h:170
@ PLPGSQL_RAISEOPTION_MESSAGE
Definition: plpgsql.h:169
@ PLPGSQL_RAISEOPTION_HINT
Definition: plpgsql.h:171
@ PLPGSQL_RAISEOPTION_ERRCODE
Definition: plpgsql.h:168
@ PLPGSQL_RAISEOPTION_DATATYPE
Definition: plpgsql.h:174
PLpgSQL_stmt_block * plpgsql_parse_result
Definition: pl_comp.c:42
bool plpgsql_print_strict_params
Definition: pl_handler.c:46
bool plpgsql_check_syntax
Definition: pl_comp.c:51
PLpgSQL_condition * plpgsql_parse_err_condition(char *condname)
Definition: pl_comp.c:2265
struct PLpgSQL_stmt_return PLpgSQL_stmt_return
bool plpgsql_token_is_unreserved_keyword(int token)
Definition: pl_scanner.c:387
const char * plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:232
void plpgsql_yyerror(const char *message) pg_attribute_noreturn()
Definition: pl_scanner.c:499
struct PLwdatum PLwdatum
struct PLpgSQL_stmt_exit PLpgSQL_stmt_exit
struct PLpgSQL_stmt_block PLpgSQL_stmt_block
struct PLpgSQL_rec PLpgSQL_rec
PLpgSQL_function * plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator)
Definition: pl_comp.c:136
struct PLpgSQL_stmt_loop PLpgSQL_stmt_loop
PLpgSQL_promise_type
Definition: plpgsql.h:74
@ PLPGSQL_PROMISE_TG_RELID
Definition: plpgsql.h:80
@ PLPGSQL_PROMISE_NONE
Definition: plpgsql.h:75
@ PLPGSQL_PROMISE_TG_WHEN
Definition: plpgsql.h:77
@ PLPGSQL_PROMISE_TG_ARGV
Definition: plpgsql.h:84
@ PLPGSQL_PROMISE_TG_TABLE_SCHEMA
Definition: plpgsql.h:82
@ PLPGSQL_PROMISE_TG_EVENT
Definition: plpgsql.h:85
@ PLPGSQL_PROMISE_TG_TABLE_NAME
Definition: plpgsql.h:81
@ PLPGSQL_PROMISE_TG_TAG
Definition: plpgsql.h:86
@ PLPGSQL_PROMISE_TG_OP
Definition: plpgsql.h:79
@ PLPGSQL_PROMISE_TG_LEVEL
Definition: plpgsql.h:78
@ PLPGSQL_PROMISE_TG_NARGS
Definition: plpgsql.h:83
@ PLPGSQL_PROMISE_TG_NAME
Definition: plpgsql.h:76
struct PLpgSQL_stmt_forc PLpgSQL_stmt_forc
int plpgsql_yyparse(void)
struct PLpgSQL_stmt_return_query PLpgSQL_stmt_return_query
PLpgSQL_plugin ** plpgsql_plugin_ptr
Definition: pl_handler.c:56
struct PLpgSQL_stmt_case PLpgSQL_stmt_case
struct PLpgSQL_stmt_foreach_a PLpgSQL_stmt_foreach_a
void plpgsql_free_function_memory(PLpgSQL_function *func)
Definition: pl_funcs.c:725
PLpgSQL_nsitem * plpgsql_ns_find_nearest_loop(PLpgSQL_nsitem *ns_cur)
Definition: pl_funcs.c:214
void plpgsql_append_source_text(StringInfo buf, int startlocation, int endlocation)
Definition: pl_scanner.c:404
struct PLpgSQL_expr PLpgSQL_expr
struct PLpgSQL_stmt_close PLpgSQL_stmt_close
struct PLpgSQL_plugin PLpgSQL_plugin
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition: pl_funcs.c:92
PLpgSQL_function * plpgsql_curr_compile
Definition: pl_comp.c:53
PLpgSQL_type * plpgsql_parse_wordtype(char *ident)
Definition: pl_comp.c:1616
bool plpgsql_parse_dblword(char *word1, char *word2, PLwdatum *wdatum, PLcword *cword)
Definition: pl_comp.c:1451
struct PLpgSQL_stmt_commit PLpgSQL_stmt_commit
struct PLpgSQL_datum PLpgSQL_datum
@ PLPGSQL_RC_RETURN
Definition: plpgsql.h:140
@ PLPGSQL_RC_EXIT
Definition: plpgsql.h:139
@ PLPGSQL_RC_OK
Definition: plpgsql.h:138
@ PLPGSQL_RC_CONTINUE
Definition: plpgsql.h:141
void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc, int *tok2_loc)
Definition: pl_scanner.c:439
struct PLpgSQL_case_when PLpgSQL_case_when
void plpgsql_adddatum(PLpgSQL_datum *newdatum)
Definition: pl_comp.c:2333
struct PLpgSQL_exception_block PLpgSQL_exception_block
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:46
PLpgSQL_label_type
Definition: plpgsql.h:52
@ PLPGSQL_LABEL_LOOP
Definition: plpgsql.h:54
@ PLPGSQL_LABEL_OTHER
Definition: plpgsql.h:55
@ PLPGSQL_LABEL_BLOCK
Definition: plpgsql.h:53
struct PLpgSQL_stmt_execsql PLpgSQL_stmt_execsql
int plpgsql_latest_lineno(void)
Definition: pl_scanner.c:572
int plpgsql_yylex(void)
Definition: pl_scanner.c:146
bool plpgsql_parse_word(char *word1, const char *yytxt, bool lookup, PLwdatum *wdatum, PLword *word)
Definition: pl_comp.c:1396
bool plpgsql_DumpExecTree
Definition: pl_comp.c:50
HeapTuple plpgsql_exec_trigger(PLpgSQL_function *func, TriggerData *trigdata)
Definition: pl_exec.c:912
int plpgsql_extra_errors
Definition: pl_handler.c:53
int plpgsql_peek(void)
Definition: pl_scanner.c:420
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:81
PLpgSQL_function * plpgsql_compile_inline(char *proc_source)
Definition: pl_comp.c:847
struct PLpgSQL_stmt_rollback PLpgSQL_stmt_rollback
struct PLpgSQL_execstate PLpgSQL_execstate
void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
Definition: pl_exec.c:8454
void plpgsql_ns_push(const char *label, PLpgSQL_label_type label_type)
Definition: pl_funcs.c:54
void plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
Definition: pl_exec.c:1152
PLpgSQL_nsitem * plpgsql_ns_lookup(PLpgSQL_nsitem *ns_cur, bool localmode, const char *name1, const char *name2, const char *name3, int *names_used)
Definition: pl_funcs.c:130
bool plpgsql_parse_tripword(char *word1, char *word2, char *word3, PLwdatum *wdatum, PLcword *cword)
Definition: pl_comp.c:1532
struct PLpgSQL_exception PLpgSQL_exception
struct PLpgSQL_condition PLpgSQL_condition
struct PLpgSQL_recfield PLpgSQL_recfield
void plpgsql_scanner_init(const char *str)
Definition: pl_scanner.c:586
int plpgsql_base_yylex(void)
PLpgSQL_datum_type
Definition: plpgsql.h:62
@ PLPGSQL_DTYPE_ROW
Definition: plpgsql.h:64
@ PLPGSQL_DTYPE_PROMISE
Definition: plpgsql.h:67
@ PLPGSQL_DTYPE_RECFIELD
Definition: plpgsql.h:66
@ PLPGSQL_DTYPE_REC
Definition: plpgsql.h:65
@ PLPGSQL_DTYPE_VAR
Definition: plpgsql.h:63
struct PLpgSQL_stmt_forq PLpgSQL_stmt_forq
PLpgSQL_type * plpgsql_parse_cwordtype(List *idents)
Definition: pl_comp.c:1682
PLpgSQL_nsitem_type
Definition: plpgsql.h:42
@ PLPGSQL_NSTYPE_VAR
Definition: plpgsql.h:44
@ PLPGSQL_NSTYPE_REC
Definition: plpgsql.h:45
@ PLPGSQL_NSTYPE_LABEL
Definition: plpgsql.h:43
void plpgsql_push_back_token(int token)
Definition: pl_scanner.c:370
struct PLword PLword
struct PLpgSQL_stmt_if PLpgSQL_stmt_if
struct PLpgSQL_stmt_fori PLpgSQL_stmt_fori
int plpgsql_nDatums
Definition: pl_comp.c:45
void plpgsql_xact_cb(XactEvent event, void *arg)
Definition: pl_exec.c:8412
PLpgSQL_getdiag_kind
Definition: plpgsql.h:148
@ PLPGSQL_GETDIAG_ERROR_DETAIL
Definition: plpgsql.h:152
@ PLPGSQL_GETDIAG_SCHEMA_NAME
Definition: plpgsql.h:160
@ PLPGSQL_GETDIAG_MESSAGE_TEXT
Definition: plpgsql.h:158
@ PLPGSQL_GETDIAG_DATATYPE_NAME
Definition: plpgsql.h:157
@ PLPGSQL_GETDIAG_TABLE_NAME
Definition: plpgsql.h:159
@ PLPGSQL_GETDIAG_CONSTRAINT_NAME
Definition: plpgsql.h:156
@ PLPGSQL_GETDIAG_COLUMN_NAME
Definition: plpgsql.h:155
@ PLPGSQL_GETDIAG_ROW_COUNT
Definition: plpgsql.h:149
@ PLPGSQL_GETDIAG_RETURNED_SQLSTATE
Definition: plpgsql.h:154
@ PLPGSQL_GETDIAG_CONTEXT
Definition: plpgsql.h:150
@ PLPGSQL_GETDIAG_ERROR_HINT
Definition: plpgsql.h:153
@ PLPGSQL_GETDIAG_ERROR_CONTEXT
Definition: plpgsql.h:151
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation, TypeName *origtypname)
Definition: pl_comp.c:2091
Oid plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate, PLpgSQL_datum *datum)
Definition: pl_exec.c:5435
PLpgSQL_nsitem * plpgsql_ns_lookup_label(PLpgSQL_nsitem *ns_cur, const char *name)
Definition: pl_funcs.c:195
struct PLpgSQL_stmt_assign PLpgSQL_stmt_assign
uintptr_t Datum
Definition: postgres.h:411
unsigned int Oid
Definition: postgres_ext.h:31
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1432
Definition: dynahash.c:220
Definition: pg_list.h:51
List * idents
Definition: plpgsql.h:1172
PLpgSQL_expr * expr
Definition: plpgsql.h:634
char * condname
Definition: plpgsql.h:471
struct PLpgSQL_condition * next
Definition: plpgsql.h:472
PLpgSQL_datum_type dtype
Definition: plpgsql.h:276
PLpgSQL_getdiag_kind kind
Definition: plpgsql.h:573
PLpgSQL_condition * conditions
Definition: plpgsql.h:491
EState * simple_eval_estate
Definition: plpgsql.h:1070
TriggerData * trigdata
Definition: plpgsql.h:1024
PLpgSQL_datum ** datums
Definition: plpgsql.h:1057
ParamListInfo paramLI
Definition: plpgsql.h:1067
char * exitlabel
Definition: plpgsql.h:1038
ResourceOwner simple_eval_resowner
Definition: plpgsql.h:1071
ExprContext * eval_econtext
Definition: plpgsql.h:1087
ResourceOwner procedure_resowner
Definition: plpgsql.h:1074
PLpgSQL_function * func
Definition: plpgsql.h:1022
HTAB * cast_hash
Definition: plpgsql.h:1077
Tuplestorestate * tuple_store
Definition: plpgsql.h:1042
PLpgSQL_variable * err_var
Definition: plpgsql.h:1091
MemoryContext tuple_store_cxt
Definition: plpgsql.h:1044
TupleDesc tuple_store_desc
Definition: plpgsql.h:1043
MemoryContext datum_context
Definition: plpgsql.h:1059
ReturnSetInfo * rsi
Definition: plpgsql.h:1046
MemoryContext stmt_mcontext
Definition: plpgsql.h:1081
PLpgSQL_stmt * err_stmt
Definition: plpgsql.h:1090
const char * err_text
Definition: plpgsql.h:1092
SPITupleTable * eval_tuptable
Definition: plpgsql.h:1085
EventTriggerData * evtrigdata
Definition: plpgsql.h:1025
ErrorData * cur_error
Definition: plpgsql.h:1040
ResourceOwner tuple_store_owner
Definition: plpgsql.h:1045
MemoryContext cast_hash_context
Definition: plpgsql.h:1078
MemoryContext stmt_mcontext_parent
Definition: plpgsql.h:1082
void * plugin_info
Definition: plpgsql.h:1094
uint64 eval_processed
Definition: plpgsql.h:1086
CachedPlanSource * expr_simple_plansource
Definition: plpgsql.h:253
CachedPlan * expr_simple_plan
Definition: plpgsql.h:254
Oid expr_simple_type
Definition: plpgsql.h:232
int target_param
Definition: plpgsql.h:244
Expr * expr_simple_expr
Definition: plpgsql.h:231
SPIPlanPtr plan
Definition: plpgsql.h:221
struct PLpgSQL_nsitem * ns
Definition: plpgsql.h:228
ExprState * expr_simple_state
Definition: plpgsql.h:263
RawParseMode parseMode
Definition: plpgsql.h:220
struct PLpgSQL_function * func
Definition: plpgsql.h:225
bool expr_simple_mutable
Definition: plpgsql.h:234
bool expr_simple_in_use
Definition: plpgsql.h:264
Bitmapset * paramnos
Definition: plpgsql.h:222
Param * expr_rw_param
Definition: plpgsql.h:245
LocalTransactionId expr_simple_plan_lxid
Definition: plpgsql.h:255
LocalTransactionId expr_simple_lxid
Definition: plpgsql.h:265
char * query
Definition: plpgsql.h:219
int32 expr_simple_typmod
Definition: plpgsql.h:233
Oid argtypes[FUNC_MAX_ARGS]
Definition: plpgsql.h:949
bool print_strict_params
Definition: plpgsql.h:994
bool requires_procedure_resowner
Definition: plpgsql.h:1010
unsigned long use_count
Definition: plpgsql.h:1014
PLpgSQL_trigtype fn_is_trigger
Definition: plpgsql.h:971
Oid fn_input_collation
Definition: plpgsql.h:972
TransactionId fn_xmin
Definition: plpgsql.h:969
ItemPointerData fn_tid
Definition: plpgsql.h:970
bool fn_retbyval
Definition: plpgsql.h:978
bool fn_retisdomain
Definition: plpgsql.h:980
MemoryContext fn_cxt
Definition: plpgsql.h:974
int fn_argvarnos[FUNC_MAX_ARGS]
Definition: plpgsql.h:986
PLpgSQL_stmt_block * action
Definition: plpgsql.h:1006
Size copiable_size
Definition: plpgsql.h:1003
unsigned int nstatements
Definition: plpgsql.h:1009
bool fn_readonly
Definition: plpgsql.h:982
bool fn_retistuple
Definition: plpgsql.h:979
struct PLpgSQL_execstate * cur_estate
Definition: plpgsql.h:1013
int out_param_varno
Definition: plpgsql.h:987
PLpgSQL_resolve_option resolve_option
Definition: plpgsql.h:992
PLpgSQL_func_hashkey * fn_hashkey
Definition: plpgsql.h:973
int extra_warnings
Definition: plpgsql.h:997
PLpgSQL_datum ** datums
Definition: plpgsql.h:1002
char * fn_signature
Definition: plpgsql.h:967
PLpgSQL_expr * cond
Definition: plpgsql.h:609
List * stmts
Definition: plpgsql.h:610
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:446
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:445
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:438
void(* stmt_end)(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
Definition: plpgsql.h:1140
void(* func_beg)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:1137
Datum(* cast_value)(PLpgSQL_execstate *estate, Datum value, bool *isnull, Oid valtype, int32 valtypmod, Oid reqtype, int32 reqtypmod)
Definition: plpgsql.h:1154
void(* error_callback)(void *arg)
Definition: plpgsql.h:1143
void(* func_end)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:1138
void(* assign_expr)(PLpgSQL_execstate *estate, PLpgSQL_datum *target, PLpgSQL_expr *expr)
Definition: plpgsql.h:1144
void(* func_setup)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
Definition: plpgsql.h:1136
void(* assign_value)(PLpgSQL_execstate *estate, PLpgSQL_datum *target, Datum value, bool isNull, Oid valtype, int32 valtypmod)
Definition: plpgsql.h:1147
void(* eval_datum)(PLpgSQL_execstate *estate, PLpgSQL_datum *datum, Oid *typeId, int32 *typetypmod, Datum *value, bool *isnull)
Definition: plpgsql.h:1151
void(* stmt_beg)(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
Definition: plpgsql.h:1139
PLpgSQL_raise_option_type opt_type
Definition: plpgsql.h:871
PLpgSQL_expr * expr
Definition: plpgsql.h:872
ExpandedRecordHeader * erh
Definition: plpgsql.h:413
PLpgSQL_type * datatype
Definition: plpgsql.h:405
bool notnull
Definition: plpgsql.h:395
PLpgSQL_datum_type dtype
Definition: plpgsql.h:390
int firstfield
Definition: plpgsql.h:408
Oid rectypeid
Definition: plpgsql.h:406
bool isconst
Definition: plpgsql.h:394
int lineno
Definition: plpgsql.h:393
char * refname
Definition: plpgsql.h:392
PLpgSQL_expr * default_val
Definition: plpgsql.h:396
uint64 rectupledescid
Definition: plpgsql.h:428
PLpgSQL_datum_type dtype
Definition: plpgsql.h:421
char * fieldname
Definition: plpgsql.h:425
ExpandedRecordFieldInfo finfo
Definition: plpgsql.h:429
TupleDesc rowtupdesc
Definition: plpgsql.h:378
PLpgSQL_expr * default_val
Definition: plpgsql.h:370
bool isconst
Definition: plpgsql.h:368
int lineno
Definition: plpgsql.h:367
PLpgSQL_datum_type dtype
Definition: plpgsql.h:364
bool notnull
Definition: plpgsql.h:369
int * varnos
Definition: plpgsql.h:382
char * refname
Definition: plpgsql.h:366
char ** fieldnames
Definition: plpgsql.h:381
int nfields
Definition: plpgsql.h:380
unsigned int stmtid
Definition: plpgsql.h:882
PLpgSQL_expr * cond
Definition: plpgsql.h:883
PLpgSQL_expr * message
Definition: plpgsql.h:884
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:880
PLpgSQL_expr * expr
Definition: plpgsql.h:519
unsigned int stmtid
Definition: plpgsql.h:517
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:515
PLpgSQL_exception_block * exceptions
Definition: plpgsql.h:507
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:500
unsigned int stmtid
Definition: plpgsql.h:502
PLpgSQL_variable * target
Definition: plpgsql.h:543
PLpgSQL_expr * expr
Definition: plpgsql.h:541
unsigned int stmtid
Definition: plpgsql.h:540
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:538
List * case_when_list
Definition: plpgsql.h:623
List * else_stmts
Definition: plpgsql.h:625
PLpgSQL_expr * t_expr
Definition: plpgsql.h:621
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:618
unsigned int stmtid
Definition: plpgsql.h:620
unsigned int stmtid
Definition: plpgsql.h:797
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:795
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:551
unsigned int stmtid
Definition: plpgsql.h:553
PLpgSQL_expr * query
Definition: plpgsql.h:911
unsigned int stmtid
Definition: plpgsql.h:910
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:908
PLpgSQL_variable * target
Definition: plpgsql.h:914
unsigned int stmtid
Definition: plpgsql.h:733
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:731
PLpgSQL_variable * var
Definition: plpgsql.h:735
PLpgSQL_expr * query
Definition: plpgsql.h:738
PLpgSQL_variable * target
Definition: plpgsql.h:900
PLpgSQL_expr * sqlstmt
Definition: plpgsql.h:895
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:892
unsigned int stmtid
Definition: plpgsql.h:894
unsigned int stmtid
Definition: plpgsql.h:808
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:806
PLpgSQL_expr * cond
Definition: plpgsql.h:811
FetchDirection direction
Definition: plpgsql.h:783
bool returns_multiple_rows
Definition: plpgsql.h:787
PLpgSQL_variable * target
Definition: plpgsql.h:781
unsigned int stmtid
Definition: plpgsql.h:780
PLpgSQL_expr * expr
Definition: plpgsql.h:785
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:778
unsigned int stmtid
Definition: plpgsql.h:717
PLpgSQL_variable * var
Definition: plpgsql.h:719
PLpgSQL_expr * argquery
Definition: plpgsql.h:723
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:715
unsigned int stmtid
Definition: plpgsql.h:749
PLpgSQL_expr * expr
Definition: plpgsql.h:753
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:747
unsigned int stmtid
Definition: plpgsql.h:670
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:668
PLpgSQL_expr * upper
Definition: plpgsql.h:674
PLpgSQL_expr * lower
Definition: plpgsql.h:673
PLpgSQL_expr * step
Definition: plpgsql.h:675
PLpgSQL_var * var
Definition: plpgsql.h:672
unsigned int stmtid
Definition: plpgsql.h:689
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:687
PLpgSQL_variable * var
Definition: plpgsql.h:691
PLpgSQL_variable * var
Definition: plpgsql.h:704
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:700
PLpgSQL_expr * query
Definition: plpgsql.h:707
unsigned int stmtid
Definition: plpgsql.h:702
unsigned int stmtid
Definition: plpgsql.h:584
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:582
PLpgSQL_expr * cond
Definition: plpgsql.h:597
List * elsif_list
Definition: plpgsql.h:599
List * else_body
Definition: plpgsql.h:600
List * then_body
Definition: plpgsql.h:598
unsigned int stmtid
Definition: plpgsql.h:596
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:594
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:643
unsigned int stmtid
Definition: plpgsql.h:645
unsigned int stmtid
Definition: plpgsql.h:764
PLpgSQL_expr * argquery
Definition: plpgsql.h:767
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:762
PLpgSQL_expr * dynquery
Definition: plpgsql.h:769
PLpgSQL_expr * query
Definition: plpgsql.h:768
PLpgSQL_expr * expr
Definition: plpgsql.h:530
unsigned int stmtid
Definition: plpgsql.h:529
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:527
unsigned int stmtid
Definition: plpgsql.h:858
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:856
PLpgSQL_expr * expr
Definition: plpgsql.h:834
unsigned int stmtid
Definition: plpgsql.h:833
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:831
PLpgSQL_expr * dynquery
Definition: plpgsql.h:847
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:843
unsigned int stmtid
Definition: plpgsql.h:845
PLpgSQL_expr * query
Definition: plpgsql.h:846
unsigned int stmtid
Definition: plpgsql.h:821
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:819
PLpgSQL_expr * expr
Definition: plpgsql.h:822
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:562
unsigned int stmtid
Definition: plpgsql.h:564
unsigned int stmtid
Definition: plpgsql.h:657
PLpgSQL_expr * cond
Definition: plpgsql.h:659
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:655
int lineno
Definition: plpgsql.h:455
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:454
unsigned int stmtid
Definition: plpgsql.h:462
char typtype
Definition: plpgsql.h:204
TypeName * origtypname
Definition: plpgsql.h:209
bool typisarray
Definition: plpgsql.h:206
TypeCacheEntry * tcache
Definition: plpgsql.h:210
uint64 tupdesc_id
Definition: plpgsql.h:211
Oid collation
Definition: plpgsql.h:205
PLpgSQL_type_type ttype
Definition: plpgsql.h:201
Oid typoid
Definition: plpgsql.h:200
char * typname
Definition: plpgsql.h:199
int16 typlen
Definition: plpgsql.h:202
int32 atttypmod
Definition: plpgsql.h:207
bool typbyval
Definition: plpgsql.h:203
int lineno
Definition: plpgsql.h:313
PLpgSQL_promise_type promise
Definition: plpgsql.h:341
PLpgSQL_datum_type dtype
Definition: plpgsql.h:310
bool freeval
Definition: plpgsql.h:334
int cursor_explicit_argrow
Definition: plpgsql.h:327
int cursor_options
Definition: plpgsql.h:328
bool notnull
Definition: plpgsql.h:315
bool isconst
Definition: plpgsql.h:314
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:326
bool isnull
Definition: plpgsql.h:333
PLpgSQL_type * datatype
Definition: plpgsql.h:319
PLpgSQL_expr * default_val
Definition: plpgsql.h:316
char * refname
Definition: plpgsql.h:312
Datum value
Definition: plpgsql.h:332
PLpgSQL_expr * default_val
Definition: plpgsql.h:294
PLpgSQL_datum_type dtype
Definition: plpgsql.h:288
char * refname
Definition: plpgsql.h:290
List * idents
Definition: plpgsql.h:1180
char * ident
Definition: plpgsql.h:1178
PLpgSQL_datum * datum
Definition: plpgsql.h:1177
bool quoted
Definition: plpgsql.h:1179
char * ident
Definition: plpgsql.h:1166
bool quoted
Definition: plpgsql.h:1167
Definition: zic.c:302
SubXactEvent
Definition: xact.h:128
XactEvent
Definition: xact.h:114