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-2021, 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 */
212 } PLpgSQL_type;
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 */
266 } PLpgSQL_expr;
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;
278 } PLpgSQL_datum;
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  */
342 } PLpgSQL_var;
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;
383 } PLpgSQL_row;
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 */
414 } PLpgSQL_rec;
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;
463 } PLpgSQL_stmt;
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? */
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  */
949  Oid argtypes[FUNC_MAX_ARGS];
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;
986  int fn_argvarnos[FUNC_MAX_ARGS];
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  const char *err_text; /* additional state info */
1092 
1093  void *plugin_info; /* reserved for use by optional plugin */
1095 
1096 /*
1097  * A PLpgSQL_plugin structure represents an instrumentation plugin.
1098  * To instrument PL/pgSQL, a plugin library must access the rendezvous
1099  * variable "PLpgSQL_plugin" and set it to point to a PLpgSQL_plugin struct.
1100  * Typically the struct could just be static data in the plugin library.
1101  * We expect that a plugin would do this at library load time (_PG_init()).
1102  * It must also be careful to set the rendezvous variable back to NULL
1103  * if it is unloaded (_PG_fini()).
1104  *
1105  * This structure is basically a collection of function pointers --- at
1106  * various interesting points in pl_exec.c, we call these functions
1107  * (if the pointers are non-NULL) to give the plugin a chance to watch
1108  * what we are doing.
1109  *
1110  * func_setup is called when we start a function, before we've initialized
1111  * the local variables defined by the function.
1112  *
1113  * func_beg is called when we start a function, after we've initialized
1114  * the local variables.
1115  *
1116  * func_end is called at the end of a function.
1117  *
1118  * stmt_beg and stmt_end are called before and after (respectively) each
1119  * statement.
1120  *
1121  * Also, immediately before any call to func_setup, PL/pgSQL fills in the
1122  * error_callback and assign_expr fields with pointers to its own
1123  * plpgsql_exec_error_callback and exec_assign_expr functions. This is
1124  * a somewhat ad-hoc expedient to simplify life for debugger plugins.
1125  */
1126 typedef struct PLpgSQL_plugin
1127 {
1128  /* Function pointers set up by the plugin */
1129  void (*func_setup) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
1130  void (*func_beg) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
1131  void (*func_end) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
1132  void (*stmt_beg) (PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt);
1133  void (*stmt_end) (PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt);
1134 
1135  /* Function pointers set by PL/pgSQL itself */
1136  void (*error_callback) (void *arg);
1137  void (*assign_expr) (PLpgSQL_execstate *estate, PLpgSQL_datum *target,
1138  PLpgSQL_expr *expr);
1139 } PLpgSQL_plugin;
1140 
1141 /*
1142  * Struct types used during parsing
1143  */
1144 
1145 typedef struct PLword
1146 {
1147  char *ident; /* palloc'd converted identifier */
1148  bool quoted; /* Was it double-quoted? */
1149 } PLword;
1150 
1151 typedef struct PLcword
1152 {
1153  List *idents; /* composite identifiers (list of String) */
1154 } PLcword;
1155 
1156 typedef struct PLwdatum
1157 {
1158  PLpgSQL_datum *datum; /* referenced variable */
1159  char *ident; /* valid if simple name */
1160  bool quoted;
1161  List *idents; /* valid if composite name */
1162 } PLwdatum;
1163 
1164 /**********************************************************************
1165  * Global variable declarations
1166  **********************************************************************/
1167 
1168 typedef enum
1169 {
1170  IDENTIFIER_LOOKUP_NORMAL, /* normal processing of var names */
1171  IDENTIFIER_LOOKUP_DECLARE, /* In DECLARE --- don't look up names */
1172  IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */
1174 
1176 
1177 extern int plpgsql_variable_conflict;
1178 
1179 extern bool plpgsql_print_strict_params;
1180 
1181 extern bool plpgsql_check_asserts;
1182 
1183 /* extra compile-time and run-time checks */
1184 #define PLPGSQL_XCHECK_NONE 0
1185 #define PLPGSQL_XCHECK_SHADOWVAR (1 << 1)
1186 #define PLPGSQL_XCHECK_TOOMANYROWS (1 << 2)
1187 #define PLPGSQL_XCHECK_STRICTMULTIASSIGNMENT (1 << 3)
1188 #define PLPGSQL_XCHECK_ALL ((int) ~0)
1189 
1190 extern int plpgsql_extra_warnings;
1191 extern int plpgsql_extra_errors;
1192 
1193 extern bool plpgsql_check_syntax;
1194 extern bool plpgsql_DumpExecTree;
1195 
1197 
1198 extern int plpgsql_nDatums;
1199 extern PLpgSQL_datum **plpgsql_Datums;
1200 
1201 extern char *plpgsql_error_funcname;
1202 
1205 
1207 
1208 /**********************************************************************
1209  * Function declarations
1210  **********************************************************************/
1211 
1212 /*
1213  * Functions in pl_comp.c
1214  */
1216  bool forValidator);
1217 extern PLpgSQL_function *plpgsql_compile_inline(char *proc_source);
1218 extern void plpgsql_parser_setup(struct ParseState *pstate,
1219  PLpgSQL_expr *expr);
1220 extern bool plpgsql_parse_word(char *word1, const char *yytxt, bool lookup,
1221  PLwdatum *wdatum, PLword *word);
1222 extern bool plpgsql_parse_dblword(char *word1, char *word2,
1223  PLwdatum *wdatum, PLcword *cword);
1224 extern bool plpgsql_parse_tripword(char *word1, char *word2, char *word3,
1225  PLwdatum *wdatum, PLcword *cword);
1226 extern PLpgSQL_type *plpgsql_parse_wordtype(char *ident);
1227 extern PLpgSQL_type *plpgsql_parse_cwordtype(List *idents);
1228 extern PLpgSQL_type *plpgsql_parse_wordrowtype(char *ident);
1230 extern PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32 typmod,
1231  Oid collation,
1233 extern PLpgSQL_variable *plpgsql_build_variable(const char *refname, int lineno,
1234  PLpgSQL_type *dtype,
1235  bool add2namespace);
1236 extern PLpgSQL_rec *plpgsql_build_record(const char *refname, int lineno,
1237  PLpgSQL_type *dtype, Oid rectypeid,
1238  bool add2namespace);
1240  const char *fldname);
1241 extern int plpgsql_recognize_err_condition(const char *condname,
1242  bool allow_sqlstate);
1243 extern PLpgSQL_condition *plpgsql_parse_err_condition(char *condname);
1244 extern void plpgsql_adddatum(PLpgSQL_datum *newdatum);
1245 extern int plpgsql_add_initdatums(int **varnos);
1246 extern void plpgsql_HashTableInit(void);
1247 
1248 /*
1249  * Functions in pl_handler.c
1250  */
1251 extern void _PG_init(void);
1252 
1253 /*
1254  * Functions in pl_exec.c
1255  */
1257  FunctionCallInfo fcinfo,
1258  EState *simple_eval_estate,
1259  ResourceOwner simple_eval_resowner,
1260  ResourceOwner procedure_resowner,
1261  bool atomic);
1263  TriggerData *trigdata);
1265  EventTriggerData *trigdata);
1266 extern void plpgsql_xact_cb(XactEvent event, void *arg);
1267 extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid,
1268  SubTransactionId parentSubid, void *arg);
1270  PLpgSQL_datum *datum);
1272  PLpgSQL_datum *datum,
1273  Oid *typeId, int32 *typMod,
1274  Oid *collation);
1275 
1276 /*
1277  * Functions for namespace handling in pl_funcs.c
1278  */
1279 extern void plpgsql_ns_init(void);
1280 extern void plpgsql_ns_push(const char *label,
1281  PLpgSQL_label_type label_type);
1282 extern void plpgsql_ns_pop(void);
1283 extern PLpgSQL_nsitem *plpgsql_ns_top(void);
1284 extern void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name);
1285 extern PLpgSQL_nsitem *plpgsql_ns_lookup(PLpgSQL_nsitem *ns_cur, bool localmode,
1286  const char *name1, const char *name2,
1287  const char *name3, int *names_used);
1289  const char *name);
1291 
1292 /*
1293  * Other functions in pl_funcs.c
1294  */
1295 extern const char *plpgsql_stmt_typename(PLpgSQL_stmt *stmt);
1296 extern const char *plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind);
1298 extern void plpgsql_dumptree(PLpgSQL_function *func);
1299 
1300 /*
1301  * Scanner functions in pl_scanner.c
1302  */
1303 extern int plpgsql_base_yylex(void);
1304 extern int plpgsql_yylex(void);
1305 extern void plpgsql_push_back_token(int token);
1306 extern bool plpgsql_token_is_unreserved_keyword(int token);
1308  int startlocation, int endlocation);
1309 extern int plpgsql_peek(void);
1310 extern void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc,
1311  int *tok2_loc);
1312 extern int plpgsql_scanner_errposition(int location);
1313 extern void plpgsql_yyerror(const char *message) pg_attribute_noreturn();
1314 extern int plpgsql_location_to_lineno(int location);
1315 extern int plpgsql_latest_lineno(void);
1316 extern void plpgsql_scanner_init(const char *str);
1317 extern void plpgsql_scanner_finish(void);
1318 
1319 /*
1320  * Externs in gram.y
1321  */
1322 extern int plpgsql_yyparse(void);
1323 
1324 #endif /* PLPGSQL_H */
int plpgsql_nDatums
Definition: pl_comp.c:45
PLpgSQL_promise_type promise
Definition: plpgsql.h:341
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:81
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:762
signed short int16
Definition: c.h:428
bool fn_retbyval
Definition: plpgsql.h:978
int plpgsql_yyparse(void)
PLpgSQL_datum_type dtype
Definition: plpgsql.h:390
PLpgSQL_raise_option_type
Definition: plpgsql.h:166
int plpgsql_extra_warnings
Definition: pl_handler.c:52
HTAB * cast_hash
Definition: plpgsql.h:1077
unsigned int stmtid
Definition: plpgsql.h:780
XactEvent
Definition: xact.h:113
#define pg_attribute_noreturn()
Definition: c.h:179
struct PLpgSQL_stmt_dynexecute PLpgSQL_stmt_dynexecute
PLpgSQL_expr * query
Definition: plpgsql.h:911
struct PLpgSQL_stmt_forq PLpgSQL_stmt_forq
bool print_strict_params
Definition: plpgsql.h:994
PLpgSQL_datum ** datums
Definition: plpgsql.h:1002
struct PLpgSQL_stmt_block PLpgSQL_stmt_block
PLpgSQL_expr * cond
Definition: plpgsql.h:597
unsigned int stmtid
Definition: plpgsql.h:517
PLpgSQL_expr * cond
Definition: plpgsql.h:659
unsigned int stmtid
Definition: plpgsql.h:564
PLpgSQL_nsitem * plpgsql_ns_find_nearest_loop(PLpgSQL_nsitem *ns_cur)
Definition: pl_funcs.c:214
struct PLpgSQL_stmt_return_query PLpgSQL_stmt_return_query
List * then_body
Definition: plpgsql.h:598
PLpgSQL_expr * expr
Definition: plpgsql.h:753
PLpgSQL_func_hashkey * fn_hashkey
Definition: plpgsql.h:973
char * refname
Definition: plpgsql.h:366
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:668
ItemPointerData fn_tid
Definition: plpgsql.h:970
unsigned int nstatements
Definition: plpgsql.h:1009
TypeCacheEntry * tcache
Definition: plpgsql.h:210
struct PLpgSQL_stmt_raise PLpgSQL_stmt_raise
char * query
Definition: plpgsql.h:219
unsigned int stmtid
Definition: plpgsql.h:702
struct PLpgSQL_stmt_fori PLpgSQL_stmt_fori
SPITupleTable * eval_tuptable
Definition: plpgsql.h:1085
FetchDirection direction
Definition: plpgsql.h:783
struct PLpgSQL_stmt_getdiag PLpgSQL_stmt_getdiag
FetchDirection
Definition: parsenodes.h:2853
int lineno
Definition: plpgsql.h:455
PLpgSQL_function * plpgsql_compile_inline(char *proc_source)
Definition: pl_comp.c:847
unsigned int stmtid
Definition: plpgsql.h:733
PLpgSQL_plugin ** plpgsql_plugin_ptr
Definition: pl_handler.c:56
char * refname
Definition: plpgsql.h:312
struct PLpgSQL_execstate PLpgSQL_execstate
Param * expr_rw_param
Definition: plpgsql.h:245
ResourceOwner simple_eval_resowner
Definition: plpgsql.h:1071
struct PLpgSQL_stmt_call PLpgSQL_stmt_call
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:715
uint64 eval_processed
Definition: plpgsql.h:1086
struct PLpgSQL_stmt_commit PLpgSQL_stmt_commit
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:594
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:515
uint32 TransactionId
Definition: c.h:587
unsigned int stmtid
Definition: plpgsql.h:821
PLpgSQL_expr * expr
Definition: plpgsql.h:822
List * elsif_list
Definition: plpgsql.h:599
PLpgSQL_type * datatype
Definition: plpgsql.h:405
int extra_warnings
Definition: plpgsql.h:997
PLpgSQL_stmt * err_stmt
Definition: plpgsql.h:1090
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:687
PLpgSQL_datum_type dtype
Definition: plpgsql.h:310
int plpgsql_recognize_err_condition(const char *condname, bool allow_sqlstate)
Definition: pl_comp.c:2229
unsigned int stmtid
Definition: plpgsql.h:670
TypeName * origtypname
Definition: plpgsql.h:209
PLpgSQL_stmt_block * action
Definition: plpgsql.h:1006
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:551
PLpgSQL_type * plpgsql_parse_cwordtype(List *idents)
Definition: pl_comp.c:1682
void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc, int *tok2_loc)
Definition: pl_scanner.c:439
TriggerData * trigdata
Definition: plpgsql.h:1024
void plpgsql_append_source_text(StringInfo buf, int startlocation, int endlocation)
Definition: pl_scanner.c:404
PLpgSQL_expr * default_val
Definition: plpgsql.h:294
unsigned int stmtid
Definition: plpgsql.h:833
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:326
List * stmts
Definition: plpgsql.h:610
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:538
PLpgSQL_variable * var
Definition: plpgsql.h:719
ResourceOwner tuple_store_owner
Definition: plpgsql.h:1045
IdentifierLookup
Definition: plpgsql.h:1168
PLpgSQL_rec * plpgsql_build_record(const char *refname, int lineno, PLpgSQL_type *dtype, Oid rectypeid, bool add2namespace)
Definition: pl_comp.c:1950
unsigned int stmtid
Definition: plpgsql.h:894
struct PLpgSQL_plugin PLpgSQL_plugin
struct PLpgSQL_stmt PLpgSQL_stmt
int plpgsql_base_yylex(void)
PLpgSQL_datum ** plpgsql_Datums
Definition: pl_comp.c:46
char * condname
Definition: plpgsql.h:471
PLpgSQL_type * datatype
Definition: plpgsql.h:319
PLpgSQL_datum_type
Definition: plpgsql.h:61
PLpgSQL_type * plpgsql_parse_wordtype(char *ident)
Definition: pl_comp.c:1616
struct PLpgSQL_stmt_exit PLpgSQL_stmt_exit
void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
Definition: pl_exec.c:8385
PLpgSQL_type_type ttype
Definition: plpgsql.h:201
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:892
struct PLpgSQL_variable PLpgSQL_variable
bool isconst
Definition: plpgsql.h:314
TransactionId fn_xmin
Definition: plpgsql.h:969
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:350
MemoryContext cast_hash_context
Definition: plpgsql.h:1078
ExpandedRecordHeader * erh
Definition: plpgsql.h:413
PLpgSQL_expr * sqlstmt
Definition: plpgsql.h:895
struct PLpgSQL_condition * next
Definition: plpgsql.h:472
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:582
bool plpgsql_check_asserts
Definition: pl_handler.c:48
PLpgSQL_type * plpgsql_parse_wordrowtype(char *ident)
Definition: pl_comp.c:1802
uint64 tupdesc_id
Definition: plpgsql.h:211
struct PLpgSQL_stmt_dynfors PLpgSQL_stmt_dynfors
PLpgSQL_expr * dynquery
Definition: plpgsql.h:769
PLpgSQL_recfield * plpgsql_build_recfield(PLpgSQL_rec *rec, const char *fldname)
Definition: pl_comp.c:2044
uint32 SubTransactionId
Definition: c.h:591
unsigned int stmtid
Definition: plpgsql.h:717
struct PLpgSQL_exception PLpgSQL_exception
void * plugin_info
Definition: plpgsql.h:1093
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:562
PLpgSQL_function * func
Definition: plpgsql.h:1022
PLpgSQL_expr * expr
Definition: plpgsql.h:530
PLpgSQL_expr * cond
Definition: plpgsql.h:609
unsigned int stmtid
Definition: plpgsql.h:797
char * ident
Definition: plpgsql.h:1147
unsigned int Oid
Definition: postgres_ext.h:31
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition: pl_funcs.c:92
int plpgsql_scanner_errposition(int location)
Definition: pl_scanner.c:472
unsigned int stmtid
Definition: plpgsql.h:657
RawParseMode
Definition: parser.h:37
struct PLpgSQL_type PLpgSQL_type
List * else_stmts
Definition: plpgsql.h:625
PLpgSQL_datum_type dtype
Definition: plpgsql.h:276
bool requires_procedure_resowner
Definition: plpgsql.h:1010
struct PLpgSQL_var PLpgSQL_var
char * refname
Definition: plpgsql.h:392
PLpgSQL_expr * lower
Definition: plpgsql.h:673
IdentifierLookup plpgsql_IdentifierLookup
Definition: pl_scanner.c:26
bool plpgsql_print_strict_params
Definition: pl_handler.c:46
int plpgsql_latest_lineno(void)
Definition: pl_scanner.c:572
PLpgSQL_getdiag_kind kind
Definition: plpgsql.h:573
SPIPlanPtr plan
Definition: plpgsql.h:221
unsigned int stmtid
Definition: plpgsql.h:645
signed int int32
Definition: c.h:429
PLpgSQL_raise_option_type opt_type
Definition: plpgsql.h:871
PLpgSQL_datum ** datums
Definition: plpgsql.h:1057
unsigned int stmtid
Definition: plpgsql.h:845
PLpgSQL_resolve_option resolve_option
Definition: plpgsql.h:992
struct PLpgSQL_stmt_close PLpgSQL_stmt_close
PLpgSQL_expr * query
Definition: plpgsql.h:846
#define FUNC_MAX_ARGS
struct PLpgSQL_stmt_fors PLpgSQL_stmt_fors
bool notnull
Definition: plpgsql.h:315
struct PLpgSQL_stmt_forc PLpgSQL_stmt_forc
void plpgsql_parser_setup(struct ParseState *pstate, PLpgSQL_expr *expr)
Definition: pl_comp.c:1081
void plpgsql_free_function_memory(PLpgSQL_function *func)
Definition: pl_funcs.c:725
int out_param_varno
Definition: plpgsql.h:987
Definition: dynahash.c:219
char * plpgsql_error_funcname
Definition: pl_comp.c:49
int cursor_explicit_argrow
Definition: plpgsql.h:327
Bitmapset * paramnos
Definition: plpgsql.h:222
TupleDesc tuple_store_desc
Definition: plpgsql.h:1043
unsigned int stmtid
Definition: plpgsql.h:620
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:655
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:908
ParamListInfo paramLI
Definition: plpgsql.h:1067
PLpgSQL_expr * expr
Definition: plpgsql.h:834
Oid plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate, PLpgSQL_datum *datum)
Definition: pl_exec.c:5403
void plpgsql_scanner_init(const char *str)
Definition: pl_scanner.c:586
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:856
CachedPlanSource * expr_simple_plansource
Definition: plpgsql.h:253
MemoryContext tuple_store_cxt
Definition: plpgsql.h:1044
unsigned int stmtid
Definition: plpgsql.h:502
const char * plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind)
Definition: pl_funcs.c:300
PLpgSQL_promise_type
Definition: plpgsql.h:73
PLpgSQL_var * var
Definition: plpgsql.h:672
char ** fieldnames
Definition: plpgsql.h:381
struct PLpgSQL_execstate * cur_estate
Definition: plpgsql.h:1013
EState * simple_eval_estate
Definition: plpgsql.h:1070
bool plpgsql_parse_word(char *word1, const char *yytxt, bool lookup, PLwdatum *wdatum, PLword *word)
Definition: pl_comp.c:1396
struct PLpgSQL_func_hashkey PLpgSQL_func_hashkey
void _PG_init(void)
Definition: auth_delay.c:56
struct PLpgSQL_stmt_while PLpgSQL_stmt_while
PLpgSQL_expr * message
Definition: plpgsql.h:884
PLpgSQL_variable * target
Definition: plpgsql.h:900
PLpgSQL_label_type
Definition: plpgsql.h:51
PLpgSQL_expr * default_val
Definition: plpgsql.h:316
unsigned long use_count
Definition: plpgsql.h:1014
int plpgsql_yylex(void)
Definition: pl_scanner.c:146
List * idents
Definition: plpgsql.h:1153
void plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate, PLpgSQL_datum *datum, Oid *typeId, int32 *typMod, Oid *collation)
Definition: pl_exec.c:5488
struct PLpgSQL_nsitem * ns
Definition: plpgsql.h:228
bool fn_readonly
Definition: plpgsql.h:982
struct PLpgSQL_stmt_foreach_a PLpgSQL_stmt_foreach_a
static char * buf
Definition: pg_test_fsync.c:68
struct PLword PLword
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:880
void plpgsql_adddatum(PLpgSQL_datum *newdatum)
Definition: pl_comp.c:2333
PLpgSQL_variable * var
Definition: plpgsql.h:704
int cursor_options
Definition: plpgsql.h:328
struct PLpgSQL_stmt_return PLpgSQL_stmt_return
void plpgsql_push_back_token(int token)
Definition: pl_scanner.c:370
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:470
struct PLpgSQL_stmt_fetch PLpgSQL_stmt_fetch
ResourceOwner procedure_resowner
Definition: plpgsql.h:1074
Definition: zic.c:301
ReturnSetInfo * rsi
Definition: plpgsql.h:1046
Expr * expr_simple_expr
Definition: plpgsql.h:231
uint32 LocalTransactionId
Definition: c.h:589
MemoryContext fn_cxt
Definition: plpgsql.h:974
struct PLpgSQL_case_when PLpgSQL_case_when
List * idents
Definition: plpgsql.h:1161
PLpgSQL_expr * expr
Definition: plpgsql.h:634
List * case_when_list
Definition: plpgsql.h:623
PLpgSQL_function * plpgsql_curr_compile
Definition: pl_comp.c:53
bool freeval
Definition: plpgsql.h:334
Tuplestorestate * tuple_store
Definition: plpgsql.h:1042
PLpgSQL_expr * query
Definition: plpgsql.h:738
void plpgsql_yyerror(const char *message) pg_attribute_noreturn()
Definition: pl_scanner.c:499
unsigned int stmtid
Definition: plpgsql.h:596
int * varnos
Definition: plpgsql.h:382
bool fn_retisdomain
Definition: plpgsql.h:980
uint64 rectupledescid
Definition: plpgsql.h:428
Oid fn_input_collation
Definition: plpgsql.h:972
const char * plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:232
bool typbyval
Definition: plpgsql.h:203
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:831
struct PLpgSQL_datum PLpgSQL_datum
Oid collation
Definition: plpgsql.h:205
unsigned int stmtid
Definition: plpgsql.h:882
PLpgSQL_expr * expr
Definition: plpgsql.h:541
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:806
ErrorData * cur_error
Definition: plpgsql.h:1040
SubXactEvent
Definition: xact.h:127
ExprState * expr_simple_state
Definition: plpgsql.h:263
void plpgsql_HashTableInit(void)
Definition: pl_comp.c:2589
bool expr_simple_mutable
Definition: plpgsql.h:234
MemoryContext stmt_mcontext_parent
Definition: plpgsql.h:1082
bool typisarray
Definition: plpgsql.h:206
int target_param
Definition: plpgsql.h:244
PLpgSQL_stmt_type
Definition: plpgsql.h:102
struct PLpgSQL_exception_block PLpgSQL_exception_block
CachedPlan * expr_simple_plan
Definition: plpgsql.h:254
struct PLpgSQL_function PLpgSQL_function
uintptr_t Datum
Definition: postgres.h:411
struct PLpgSQL_rec PLpgSQL_rec
bool quoted
Definition: plpgsql.h:1148
PLpgSQL_getdiag_kind
Definition: plpgsql.h:147
ExpandedRecordFieldInfo finfo
Definition: plpgsql.h:429
static char * label
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
PLpgSQL_datum_type dtype
Definition: plpgsql.h:421
EventTriggerData * evtrigdata
Definition: plpgsql.h:1025
PLpgSQL_expr * cond
Definition: plpgsql.h:811
LocalTransactionId expr_simple_lxid
Definition: plpgsql.h:265
const char * err_text
Definition: plpgsql.h:1091
struct PLpgSQL_recfield PLpgSQL_recfield
unsigned int stmtid
Definition: plpgsql.h:910
PLpgSQL_expr * query
Definition: plpgsql.h:768
struct PLpgSQL_stmt_if PLpgSQL_stmt_if
Datum value
Definition: plpgsql.h:332
unsigned int stmtid
Definition: plpgsql.h:858
bool isconst
Definition: plpgsql.h:394
struct PLpgSQL_function * func
Definition: plpgsql.h:225
PLpgSQL_variable * var
Definition: plpgsql.h:735
PLpgSQL_condition * conditions
Definition: plpgsql.h:491
PLpgSQL_trigtype fn_is_trigger
Definition: plpgsql.h:971
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:445
unsigned int stmtid
Definition: plpgsql.h:529
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:527
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:795
unsigned int stmtid
Definition: plpgsql.h:540
struct PLpgSQL_row PLpgSQL_row
int nfields
Definition: plpgsql.h:380
int lineno
Definition: plpgsql.h:313
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:500
void plpgsql_ns_init(void)
Definition: pl_funcs.c:43
bool plpgsql_parse_dblword(char *word1, char *word2, PLwdatum *wdatum, PLcword *cword)
Definition: pl_comp.c:1451
PLpgSQL_exception_block * exceptions
Definition: plpgsql.h:507
bool isconst
Definition: plpgsql.h:368
struct PLpgSQL_stmt_case PLpgSQL_stmt_case
struct PLpgSQL_stmt_perform PLpgSQL_stmt_perform
ExprContext * eval_econtext
Definition: plpgsql.h:1087
size_t Size
Definition: c.h:540
char * fn_signature
Definition: plpgsql.h:967
List * else_body
Definition: plpgsql.h:600
PLpgSQL_type_type
Definition: plpgsql.h:92
PLpgSQL_datum * datum
Definition: plpgsql.h:1158
char * typname
Definition: plpgsql.h:199
unsigned int stmtid
Definition: plpgsql.h:749
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:731
PLpgSQL_expr * step
Definition: plpgsql.h:675
PLpgSQL_expr * t_expr
Definition: plpgsql.h:621
char * refname
Definition: plpgsql.h:290
unsigned int stmtid
Definition: plpgsql.h:808
PLpgSQL_expr * dynquery
Definition: plpgsql.h:847
PLpgSQL_datum_type dtype
Definition: plpgsql.h:288
PLpgSQL_variable * var
Definition: plpgsql.h:691
PLpgSQL_expr * expr
Definition: plpgsql.h:785
bool plpgsql_DumpExecTree
Definition: pl_comp.c:50
const char * name
Definition: encode.c:561
unsigned int stmtid
Definition: plpgsql.h:553
PLpgSQL_expr * expr
Definition: plpgsql.h:519
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1432
struct PLpgSQL_condition PLpgSQL_condition
PLpgSQL_expr * expr
Definition: plpgsql.h:872
MemoryContext datum_context
Definition: plpgsql.h:1059
char typtype
Definition: plpgsql.h:204
bool plpgsql_parse_tripword(char *word1, char *word2, char *word3, PLwdatum *wdatum, PLcword *cword)
Definition: pl_comp.c:1532
bool plpgsql_check_syntax
Definition: pl_comp.c:51
struct PLpgSQL_nsitem PLpgSQL_nsitem
struct PLpgSQL_raise_option PLpgSQL_raise_option
PLpgSQL_variable * plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, bool add2namespace)
Definition: pl_comp.c:1887
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:643
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation, TypeName *origtypname)
Definition: pl_comp.c:2091
PLpgSQL_variable * target
Definition: plpgsql.h:543
bool quoted
Definition: plpgsql.h:1160
int32 expr_simple_typmod
Definition: plpgsql.h:233
char * ident
Definition: plpgsql.h:1159
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
int32 atttypmod
Definition: plpgsql.h:207
unsigned int stmtid
Definition: plpgsql.h:764
RawParseMode parseMode
Definition: plpgsql.h:220
PLpgSQL_expr * argquery
Definition: plpgsql.h:767
PLpgSQL_type * plpgsql_parse_cwordrowtype(List *idents)
Definition: pl_comp.c:1839
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:438
struct PLpgSQL_stmt_execsql PLpgSQL_stmt_execsql
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:700
struct PLpgSQL_diag_item PLpgSQL_diag_item
TupleDesc rowtupdesc
Definition: plpgsql.h:378
unsigned int stmtid
Definition: plpgsql.h:689
bool fn_retistuple
Definition: plpgsql.h:979
PLpgSQL_expr * argquery
Definition: plpgsql.h:723
void plpgsql_ns_push(const char *label, PLpgSQL_label_type label_type)
Definition: pl_funcs.c:54
void * arg
MemoryContext stmt_mcontext
Definition: plpgsql.h:1081
PLpgSQL_trigtype
Definition: plpgsql.h:955
void plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
Definition: pl_exec.c:1146
PLpgSQL_expr * upper
Definition: plpgsql.h:674
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:454
PLpgSQL_resolve_option
Definition: plpgsql.h:182
struct PLwdatum PLwdatum
int plpgsql_location_to_lineno(int location)
Definition: pl_scanner.c:538
Size copiable_size
Definition: plpgsql.h:1003
struct PLpgSQL_stmt_assert PLpgSQL_stmt_assert
LocalTransactionId expr_simple_plan_lxid
Definition: plpgsql.h:255
bool expr_simple_in_use
Definition: plpgsql.h:264
struct PLpgSQL_if_elsif PLpgSQL_if_elsif
struct PLpgSQL_stmt_return_next PLpgSQL_stmt_return_next
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:618
PLpgSQL_expr * query
Definition: plpgsql.h:707
int16 typlen
Definition: plpgsql.h:202
void plpgsql_xact_cb(XactEvent event, void *arg)
Definition: pl_exec.c:8343
char * exitlabel
Definition: plpgsql.h:1038
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:843
PLpgSQL_variable * target
Definition: plpgsql.h:781
PLpgSQL_expr * cond
Definition: plpgsql.h:883
PLpgSQL_variable * target
Definition: plpgsql.h:914
int plpgsql_peek(void)
Definition: pl_scanner.c:420
struct PLpgSQL_stmt_loop PLpgSQL_stmt_loop
Oid rectypeid
Definition: plpgsql.h:406
bool plpgsql_token_is_unreserved_keyword(int token)
Definition: pl_scanner.c:387
struct PLpgSQL_stmt_rollback PLpgSQL_stmt_rollback
unsigned int stmtid
Definition: plpgsql.h:462
MemoryContext plpgsql_compile_tmp_cxt
Definition: pl_comp.c:56
int plpgsql_add_initdatums(int **varnos)
Definition: pl_comp.c:2394
PLpgSQL_expr * default_val
Definition: plpgsql.h:396
bool notnull
Definition: plpgsql.h:395
int plpgsql_extra_errors
Definition: pl_handler.c:53
PLpgSQL_condition * plpgsql_parse_err_condition(char *condname)
Definition: pl_comp.c:2265
Definition: pg_list.h:50
int plpgsql_variable_conflict
Definition: pl_handler.c:44
char * fieldname
Definition: plpgsql.h:425
int lineno
Definition: plpgsql.h:393
PLpgSQL_function * plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator)
Definition: pl_comp.c:136
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:819
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:778
void plpgsql_dumptree(PLpgSQL_function *func)
Definition: pl_funcs.c:1598
void plpgsql_ns_pop(void)
Definition: pl_funcs.c:67
PLpgSQL_datum_type dtype
Definition: plpgsql.h:364
PLpgSQL_stmt_block * plpgsql_parse_result
Definition: pl_comp.c:42
PLpgSQL_expr * default_val
Definition: plpgsql.h:370
void plpgsql_scanner_finish(void)
Definition: pl_scanner.c:613
struct PLpgSQL_expr PLpgSQL_expr
Oid expr_simple_type
Definition: plpgsql.h:232
int firstfield
Definition: plpgsql.h:408
HeapTuple plpgsql_exec_trigger(PLpgSQL_function *func, TriggerData *trigdata)
Definition: pl_exec.c:906
PLpgSQL_nsitem_type
Definition: plpgsql.h:41
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:747
int lineno
Definition: plpgsql.h:367
bool isnull
Definition: plpgsql.h:333
unsigned int stmtid
Definition: plpgsql.h:584
struct PLcword PLcword
bool returns_multiple_rows
Definition: plpgsql.h:787
bool notnull
Definition: plpgsql.h:369
Oid typoid
Definition: plpgsql.h:200
struct PLpgSQL_stmt_open PLpgSQL_stmt_open