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-2024, 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 {
163 
164 /*
165  * RAISE statement options
166  */
168 {
179 
180 /*
181  * Behavioral modes for plpgsql variable resolution
182  */
184 {
185  PLPGSQL_RESOLVE_ERROR, /* throw error if ambiguous */
186  PLPGSQL_RESOLVE_VARIABLE, /* prefer plpgsql var to table column */
187  PLPGSQL_RESOLVE_COLUMN, /* prefer table column to plpgsql var */
189 
190 
191 /**********************************************************************
192  * Node and structure definitions
193  **********************************************************************/
194 
195 /*
196  * Postgres data type
197  */
198 typedef struct PLpgSQL_type
199 {
200  char *typname; /* (simple) name of the type */
201  Oid typoid; /* OID of the data type */
202  PLpgSQL_type_type ttype; /* PLPGSQL_TTYPE_ code */
203  int16 typlen; /* stuff copied from its pg_type entry */
204  bool typbyval;
205  char typtype;
206  Oid collation; /* from pg_type, but can be overridden */
207  bool typisarray; /* is "true" array, or domain over one */
208  int32 atttypmod; /* typmod (taken from someplace else) */
209  /* Remaining fields are used only for named composite types (not RECORD) */
210  TypeName *origtypname; /* type name as written by user */
211  TypeCacheEntry *tcache; /* typcache entry for composite type */
212  uint64 tupdesc_id; /* last-seen tupdesc identifier */
214 
215 /*
216  * SQL Query to plan and execute
217  */
218 typedef struct PLpgSQL_expr
219 {
220  char *query; /* query string, verbatim from function body */
221  RawParseMode parseMode; /* raw_parser() mode to use */
222  SPIPlanPtr plan; /* plan, or NULL if not made yet */
223  Bitmapset *paramnos; /* all dnos referenced by this query */
224 
225  /* function containing this expr (not set until we first parse query) */
227 
228  /* namespace chain visible to this expr */
230 
231  /* fields for "simple expression" fast-path execution: */
232  Expr *expr_simple_expr; /* NULL means not a simple expr */
233  Oid expr_simple_type; /* result type Oid, if simple */
234  int32 expr_simple_typmod; /* result typmod, if simple */
235  bool expr_simple_mutable; /* true if simple expr is mutable */
236 
237  /*
238  * These fields are used to optimize assignments to expanded-datum
239  * variables. If this expression is the source of an assignment to a
240  * simple variable, target_param holds that variable's dno; else it's -1.
241  * If we match a Param within expr_simple_expr to such a variable, that
242  * Param's address is stored in expr_rw_param; then expression code
243  * generation will allow the value for that Param to be passed read/write.
244  */
245  int target_param; /* dno of assign target, or -1 if none */
246  Param *expr_rw_param; /* read/write Param within expr, if any */
247 
248  /*
249  * If the expression was ever determined to be simple, we remember its
250  * CachedPlanSource and CachedPlan here. If expr_simple_plan_lxid matches
251  * current LXID, then we hold a refcount on expr_simple_plan in the
252  * current transaction. Otherwise we need to get one before re-using it.
253  */
254  CachedPlanSource *expr_simple_plansource; /* extracted from "plan" */
255  CachedPlan *expr_simple_plan; /* extracted from "plan" */
257 
258  /*
259  * if expr is simple AND prepared in current transaction,
260  * expr_simple_state and expr_simple_in_use are valid. Test validity by
261  * seeing if expr_simple_lxid matches current LXID. (If not,
262  * expr_simple_state probably points at garbage!)
263  */
264  ExprState *expr_simple_state; /* eval tree for expr_simple_expr */
265  bool expr_simple_in_use; /* true if eval tree is active */
268 
269 /*
270  * Generic datum array item
271  *
272  * PLpgSQL_datum is the common supertype for PLpgSQL_var, PLpgSQL_row,
273  * PLpgSQL_rec, and PLpgSQL_recfield.
274  */
275 typedef struct PLpgSQL_datum
276 {
278  int dno;
280 
281 /*
282  * Scalar or composite variable
283  *
284  * The variants PLpgSQL_var, PLpgSQL_row, and PLpgSQL_rec share these
285  * fields.
286  */
287 typedef struct PLpgSQL_variable
288 {
290  int dno;
291  char *refname;
292  int lineno;
293  bool isconst;
294  bool notnull;
297 
298 /*
299  * Scalar variable
300  *
301  * DTYPE_VAR and DTYPE_PROMISE datums both use this struct type.
302  * A PROMISE datum works exactly like a VAR datum for most purposes,
303  * but if it is read without having previously been assigned to, then
304  * a special "promised" value is computed and assigned to the datum
305  * before the read is performed. This technique avoids the overhead of
306  * computing the variable's value in cases where we expect that many
307  * functions will never read it.
308  */
309 typedef struct PLpgSQL_var
310 {
312  int dno;
313  char *refname;
314  int lineno;
315  bool isconst;
316  bool notnull;
318  /* end of PLpgSQL_variable fields */
319 
321 
322  /*
323  * Variables declared as CURSOR FOR <query> are mostly like ordinary
324  * scalar variables of type refcursor, but they have these additional
325  * properties:
326  */
330 
331  /* Fields below here can change at runtime */
332 
334  bool isnull;
335  bool freeval;
336 
337  /*
338  * The promise field records which "promised" value to assign if the
339  * promise must be honored. If it's a normal variable, or the promise has
340  * been fulfilled, this is PLPGSQL_PROMISE_NONE.
341  */
344 
345 /*
346  * Row variable - this represents one or more variables that are listed in an
347  * INTO clause, FOR-loop targetlist, cursor argument list, etc. We also use
348  * a row to represent a function's OUT parameters when there's more than one.
349  *
350  * Note that there's no way to name the row as such from PL/pgSQL code,
351  * so many functions don't need to support these.
352  *
353  * That also means that there's no real name for the row variable, so we
354  * conventionally set refname to "(unnamed row)". We could leave it NULL,
355  * but it's too convenient to be able to assume that refname is valid in
356  * all variants of PLpgSQL_variable.
357  *
358  * isconst, notnull, and default_val are unsupported (and hence
359  * always zero/null) for a row. The member variables of a row should have
360  * been checked to be writable at compile time, so isconst is correctly set
361  * to false. notnull and default_val aren't applicable.
362  */
363 typedef struct PLpgSQL_row
364 {
366  int dno;
367  char *refname;
368  int lineno;
369  bool isconst;
370  bool notnull;
372  /* end of PLpgSQL_variable fields */
373 
374  /*
375  * rowtupdesc is only set up if we might need to convert the row into a
376  * composite datum, which currently only happens for OUT parameters.
377  * Otherwise it is NULL.
378  */
380 
381  int nfields;
382  char **fieldnames;
383  int *varnos;
385 
386 /*
387  * Record variable (any composite type, including RECORD)
388  */
389 typedef struct PLpgSQL_rec
390 {
392  int dno;
393  char *refname;
394  int lineno;
395  bool isconst;
396  bool notnull;
398  /* end of PLpgSQL_variable fields */
399 
400  /*
401  * Note: for non-RECORD cases, we may from time to time re-look-up the
402  * composite type, using datatype->origtypname. That can result in
403  * changing rectypeid.
404  */
405 
406  PLpgSQL_type *datatype; /* can be NULL, if rectypeid is RECORDOID */
407  Oid rectypeid; /* declared type of variable */
408  /* RECFIELDs for this record are chained together for easy access */
409  int firstfield; /* dno of first RECFIELD, or -1 if none */
410 
411  /* Fields below here can change at runtime */
412 
413  /* We always store record variables as "expanded" records */
416 
417 /*
418  * Field in record
419  */
420 typedef struct PLpgSQL_recfield
421 {
423  int dno;
424  /* end of PLpgSQL_datum fields */
425 
426  char *fieldname; /* name of field */
427  int recparentno; /* dno of parent record */
428  int nextfield; /* dno of next child, or -1 if none */
429  uint64 rectupledescid; /* record's tupledesc ID as of last lookup */
430  ExpandedRecordFieldInfo finfo; /* field's attnum and type info */
431  /* if rectupledescid == INVALID_TUPLEDESC_IDENTIFIER, finfo isn't valid */
433 
434 /*
435  * Item in the compilers namespace tree
436  */
437 typedef struct PLpgSQL_nsitem
438 {
440 
441  /*
442  * For labels, itemno is a value of enum PLpgSQL_label_type. For other
443  * itemtypes, itemno is the associated PLpgSQL_datum's dno.
444  */
445  int itemno;
447  char name[FLEXIBLE_ARRAY_MEMBER]; /* nul-terminated string */
449 
450 /*
451  * Generic execution node
452  */
453 typedef struct PLpgSQL_stmt
454 {
456  int lineno;
457 
458  /*
459  * Unique statement ID in this function (starting at 1; 0 is invalid/not
460  * set). This can be used by a profiler as the index for an array of
461  * per-statement metrics.
462  */
463  unsigned int stmtid;
465 
466 /*
467  * One EXCEPTION condition name
468  */
469 typedef struct PLpgSQL_condition
470 {
471  int sqlerrstate; /* SQLSTATE code */
472  char *condname; /* condition name (for debugging) */
475 
476 /*
477  * EXCEPTION block
478  */
480 {
483  List *exc_list; /* List of WHEN clauses */
485 
486 /*
487  * One EXCEPTION ... WHEN clause
488  */
489 typedef struct PLpgSQL_exception
490 {
491  int lineno;
493  List *action; /* List of statements */
495 
496 /*
497  * Block of statements
498  */
499 typedef struct PLpgSQL_stmt_block
500 {
502  int lineno;
503  unsigned int stmtid;
504  char *label;
505  List *body; /* List of statements */
506  int n_initvars; /* Length of initvarnos[] */
507  int *initvarnos; /* dnos of variables declared in this block */
510 
511 /*
512  * Assign statement
513  */
514 typedef struct PLpgSQL_stmt_assign
515 {
517  int lineno;
518  unsigned int stmtid;
519  int varno;
522 
523 /*
524  * PERFORM statement
525  */
526 typedef struct PLpgSQL_stmt_perform
527 {
529  int lineno;
530  unsigned int stmtid;
533 
534 /*
535  * CALL statement
536  */
537 typedef struct PLpgSQL_stmt_call
538 {
540  int lineno;
541  unsigned int stmtid;
543  bool is_call;
546 
547 /*
548  * COMMIT statement
549  */
550 typedef struct PLpgSQL_stmt_commit
551 {
553  int lineno;
554  unsigned int stmtid;
555  bool chain;
557 
558 /*
559  * ROLLBACK statement
560  */
561 typedef struct PLpgSQL_stmt_rollback
562 {
564  int lineno;
565  unsigned int stmtid;
566  bool chain;
568 
569 /*
570  * GET DIAGNOSTICS item
571  */
572 typedef struct PLpgSQL_diag_item
573 {
574  PLpgSQL_getdiag_kind kind; /* id for diagnostic value desired */
575  int target; /* where to assign it */
577 
578 /*
579  * GET DIAGNOSTICS statement
580  */
581 typedef struct PLpgSQL_stmt_getdiag
582 {
584  int lineno;
585  unsigned int stmtid;
586  bool is_stacked; /* STACKED or CURRENT diagnostics area? */
587  List *diag_items; /* List of PLpgSQL_diag_item */
589 
590 /*
591  * IF statement
592  */
593 typedef struct PLpgSQL_stmt_if
594 {
596  int lineno;
597  unsigned int stmtid;
598  PLpgSQL_expr *cond; /* boolean expression for THEN */
599  List *then_body; /* List of statements */
600  List *elsif_list; /* List of PLpgSQL_if_elsif structs */
601  List *else_body; /* List of statements */
603 
604 /*
605  * one ELSIF arm of IF statement
606  */
607 typedef struct PLpgSQL_if_elsif
608 {
609  int lineno;
610  PLpgSQL_expr *cond; /* boolean expression for this case */
611  List *stmts; /* List of statements */
613 
614 /*
615  * CASE statement
616  */
617 typedef struct PLpgSQL_stmt_case
618 {
620  int lineno;
621  unsigned int stmtid;
622  PLpgSQL_expr *t_expr; /* test expression, or NULL if none */
623  int t_varno; /* var to store test expression value into */
624  List *case_when_list; /* List of PLpgSQL_case_when structs */
625  bool have_else; /* flag needed because list could be empty */
626  List *else_stmts; /* List of statements */
628 
629 /*
630  * one arm of CASE statement
631  */
632 typedef struct PLpgSQL_case_when
633 {
634  int lineno;
635  PLpgSQL_expr *expr; /* boolean expression for this case */
636  List *stmts; /* List of statements */
638 
639 /*
640  * Unconditional LOOP statement
641  */
642 typedef struct PLpgSQL_stmt_loop
643 {
645  int lineno;
646  unsigned int stmtid;
647  char *label;
648  List *body; /* List of statements */
650 
651 /*
652  * WHILE cond LOOP statement
653  */
654 typedef struct PLpgSQL_stmt_while
655 {
657  int lineno;
658  unsigned int stmtid;
659  char *label;
661  List *body; /* List of statements */
663 
664 /*
665  * FOR statement with integer loopvar
666  */
667 typedef struct PLpgSQL_stmt_fori
668 {
670  int lineno;
671  unsigned int stmtid;
672  char *label;
676  PLpgSQL_expr *step; /* NULL means default (ie, BY 1) */
677  int reverse;
678  List *body; /* List of statements */
680 
681 /*
682  * PLpgSQL_stmt_forq represents a FOR statement running over a SQL query.
683  * It is the common supertype of PLpgSQL_stmt_fors, PLpgSQL_stmt_forc
684  * and PLpgSQL_stmt_dynfors.
685  */
686 typedef struct PLpgSQL_stmt_forq
687 {
689  int lineno;
690  unsigned int stmtid;
691  char *label;
692  PLpgSQL_variable *var; /* Loop variable (record or row) */
693  List *body; /* List of statements */
695 
696 /*
697  * FOR statement running over SELECT
698  */
699 typedef struct PLpgSQL_stmt_fors
700 {
702  int lineno;
703  unsigned int stmtid;
704  char *label;
705  PLpgSQL_variable *var; /* Loop variable (record or row) */
706  List *body; /* List of statements */
707  /* end of fields that must match PLpgSQL_stmt_forq */
710 
711 /*
712  * FOR statement running over cursor
713  */
714 typedef struct PLpgSQL_stmt_forc
715 {
717  int lineno;
718  unsigned int stmtid;
719  char *label;
720  PLpgSQL_variable *var; /* Loop variable (record or row) */
721  List *body; /* List of statements */
722  /* end of fields that must match PLpgSQL_stmt_forq */
723  int curvar;
724  PLpgSQL_expr *argquery; /* cursor arguments if any */
726 
727 /*
728  * FOR statement running over EXECUTE
729  */
730 typedef struct PLpgSQL_stmt_dynfors
731 {
733  int lineno;
734  unsigned int stmtid;
735  char *label;
736  PLpgSQL_variable *var; /* Loop variable (record or row) */
737  List *body; /* List of statements */
738  /* end of fields that must match PLpgSQL_stmt_forq */
740  List *params; /* USING expressions */
742 
743 /*
744  * FOREACH item in array loop
745  */
747 {
749  int lineno;
750  unsigned int stmtid;
751  char *label;
752  int varno; /* loop target variable */
753  int slice; /* slice dimension, or 0 */
754  PLpgSQL_expr *expr; /* array expression */
755  List *body; /* List of statements */
757 
758 /*
759  * OPEN a curvar
760  */
761 typedef struct PLpgSQL_stmt_open
762 {
764  int lineno;
765  unsigned int stmtid;
766  int curvar;
771  List *params; /* USING expressions */
773 
774 /*
775  * FETCH or MOVE statement
776  */
777 typedef struct PLpgSQL_stmt_fetch
778 {
780  int lineno;
781  unsigned int stmtid;
782  PLpgSQL_variable *target; /* target (record or row) */
783  int curvar; /* cursor variable to fetch from */
784  FetchDirection direction; /* fetch direction */
785  long how_many; /* count, if constant (expr is NULL) */
786  PLpgSQL_expr *expr; /* count, if expression */
787  bool is_move; /* is this a fetch or move? */
788  bool returns_multiple_rows; /* can return more than one row? */
790 
791 /*
792  * CLOSE curvar
793  */
794 typedef struct PLpgSQL_stmt_close
795 {
797  int lineno;
798  unsigned int stmtid;
799  int curvar;
801 
802 /*
803  * EXIT or CONTINUE statement
804  */
805 typedef struct PLpgSQL_stmt_exit
806 {
808  int lineno;
809  unsigned int stmtid;
810  bool is_exit; /* Is this an exit or a continue? */
811  char *label; /* NULL if it's an unlabeled EXIT/CONTINUE */
814 
815 /*
816  * RETURN statement
817  */
818 typedef struct PLpgSQL_stmt_return
819 {
821  int lineno;
822  unsigned int stmtid;
824  int retvarno;
826 
827 /*
828  * RETURN NEXT statement
829  */
831 {
833  int lineno;
834  unsigned int stmtid;
836  int retvarno;
838 
839 /*
840  * RETURN QUERY statement
841  */
843 {
845  int lineno;
846  unsigned int stmtid;
847  PLpgSQL_expr *query; /* if static query */
848  PLpgSQL_expr *dynquery; /* if dynamic query (RETURN QUERY EXECUTE) */
849  List *params; /* USING arguments for dynamic query */
851 
852 /*
853  * RAISE statement
854  */
855 typedef struct PLpgSQL_stmt_raise
856 {
858  int lineno;
859  unsigned int stmtid;
861  char *condname; /* condition name, SQLSTATE, or NULL */
862  char *message; /* old-style message format literal, or NULL */
863  List *params; /* list of expressions for old-style message */
864  List *options; /* list of PLpgSQL_raise_option */
866 
867 /*
868  * RAISE statement option
869  */
870 typedef struct PLpgSQL_raise_option
871 {
875 
876 /*
877  * ASSERT statement
878  */
879 typedef struct PLpgSQL_stmt_assert
880 {
882  int lineno;
883  unsigned int stmtid;
887 
888 /*
889  * Generic SQL statement to execute
890  */
891 typedef struct PLpgSQL_stmt_execsql
892 {
894  int lineno;
895  unsigned int stmtid;
897  bool mod_stmt; /* is the stmt INSERT/UPDATE/DELETE/MERGE? */
898  bool mod_stmt_set; /* is mod_stmt valid yet? */
899  bool into; /* INTO supplied? */
900  bool strict; /* INTO STRICT flag */
901  PLpgSQL_variable *target; /* INTO target (record or row) */
903 
904 /*
905  * Dynamic SQL string to execute
906  */
908 {
910  int lineno;
911  unsigned int stmtid;
912  PLpgSQL_expr *query; /* string expression */
913  bool into; /* INTO supplied? */
914  bool strict; /* INTO STRICT flag */
915  PLpgSQL_variable *target; /* INTO target (record or row) */
916  List *params; /* USING expressions */
918 
919 /*
920  * Hash lookup key for functions
921  */
922 typedef struct PLpgSQL_func_hashkey
923 {
925 
926  bool isTrigger; /* true if called as a DML trigger */
927  bool isEventTrigger; /* true if called as an event trigger */
928 
929  /* be careful that pad bytes in this struct get zeroed! */
930 
931  /*
932  * For a trigger function, the OID of the trigger is part of the hash key
933  * --- we want to compile the trigger function separately for each trigger
934  * it is used with, in case the rowtype or transition table names are
935  * different. Zero if not called as a DML trigger.
936  */
938 
939  /*
940  * We must include the input collation as part of the hash key too,
941  * because we have to generate different plans (with different Param
942  * collations) for different collation settings.
943  */
945 
946  /*
947  * We include actual argument types in the hash key to support polymorphic
948  * PLpgSQL functions. Be careful that extra positions are zeroed!
949  */
952 
953 /*
954  * Trigger type
955  */
956 typedef enum PLpgSQL_trigtype
957 {
962 
963 /*
964  * Complete compiled function
965  */
966 typedef struct PLpgSQL_function
967 {
974  PLpgSQL_func_hashkey *fn_hashkey; /* back-link to hashtable key */
976 
982  bool fn_retset;
985 
986  int fn_nargs;
992 
994 
996 
997  /* extra checks */
1000 
1001  /* the datums representing the function's local variables */
1002  int ndatums;
1004  Size copiable_size; /* space for locally instantiated datums */
1005 
1006  /* function body parsetree */
1008 
1009  /* data derived while parsing body */
1010  unsigned int nstatements; /* counter for assigning stmtids */
1011  bool requires_procedure_resowner; /* contains CALL or DO? */
1012 
1013  /* these fields change when the function is used */
1015  unsigned long use_count;
1017 
1018 /*
1019  * Runtime execution data
1020  */
1021 typedef struct PLpgSQL_execstate
1022 {
1023  PLpgSQL_function *func; /* function being executed */
1024 
1025  TriggerData *trigdata; /* if regular trigger, data about firing */
1026  EventTriggerData *evtrigdata; /* if event trigger, data about firing */
1027 
1030  Oid rettype; /* type of current retval */
1031 
1032  Oid fn_rettype; /* info about declared function rettype */
1034  bool retisset;
1035 
1037  bool atomic;
1038 
1039  char *exitlabel; /* the "target" label of the current EXIT or
1040  * CONTINUE stmt, if any */
1041  ErrorData *cur_error; /* current exception handler's error */
1042 
1043  Tuplestorestate *tuple_store; /* SRFs accumulate results here */
1044  TupleDesc tuple_store_desc; /* descriptor for tuples in tuple_store */
1048 
1050 
1051  /*
1052  * The datums representing the function's local variables. Some of these
1053  * are local storage in this execstate, but some just point to the shared
1054  * copy belonging to the PLpgSQL_function, depending on whether or not we
1055  * need any per-execution state for the datum's dtype.
1056  */
1057  int ndatums;
1059  /* context containing variable values (same as func's SPI_proc context) */
1061 
1062  /*
1063  * paramLI is what we use to pass local variable values to the executor.
1064  * It does not have a ParamExternData array; we just dynamically
1065  * instantiate parameter data as needed. By convention, PARAM_EXTERN
1066  * Params have paramid equal to the dno of the referenced local variable.
1067  */
1069 
1070  /* EState and resowner to use for "simple" expression evaluation */
1073 
1074  /* if running nonatomic procedure or DO block, resowner to use for CALL */
1076 
1077  /* 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);
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 PGDLLEXPORT 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);
1246 extern PLpgSQL_type *plpgsql_parse_cwordtype(List *idents);
1249 extern PGDLLEXPORT PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32 typmod,
1250  Oid collation,
1251  TypeName *origtypname);
1253 extern PLpgSQL_variable *plpgsql_build_variable(const char *refname, int lineno,
1254  PLpgSQL_type *dtype,
1255  bool add2namespace);
1256 extern PLpgSQL_rec *plpgsql_build_record(const char *refname, int lineno,
1257  PLpgSQL_type *dtype, Oid rectypeid,
1258  bool add2namespace);
1260  const char *fldname);
1261 extern PGDLLEXPORT int plpgsql_recognize_err_condition(const char *condname,
1262  bool allow_sqlstate);
1263 extern PLpgSQL_condition *plpgsql_parse_err_condition(char *condname);
1264 extern void plpgsql_adddatum(PLpgSQL_datum *newdatum);
1265 extern int plpgsql_add_initdatums(int **varnos);
1266 extern void plpgsql_HashTableInit(void);
1267 
1268 /*
1269  * Functions in pl_exec.c
1270  */
1272  FunctionCallInfo fcinfo,
1273  EState *simple_eval_estate,
1274  ResourceOwner simple_eval_resowner,
1275  ResourceOwner procedure_resowner,
1276  bool atomic);
1278  TriggerData *trigdata);
1280  EventTriggerData *trigdata);
1281 extern void plpgsql_xact_cb(XactEvent event, void *arg);
1282 extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid,
1283  SubTransactionId parentSubid, void *arg);
1285  PLpgSQL_datum *datum);
1287  PLpgSQL_datum *datum,
1288  Oid *typeId, int32 *typMod,
1289  Oid *collation);
1290 
1291 /*
1292  * Functions for namespace handling in pl_funcs.c
1293  */
1294 extern void plpgsql_ns_init(void);
1295 extern void plpgsql_ns_push(const char *label,
1296  PLpgSQL_label_type label_type);
1297 extern void plpgsql_ns_pop(void);
1298 extern PLpgSQL_nsitem *plpgsql_ns_top(void);
1299 extern void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name);
1300 extern PGDLLEXPORT PLpgSQL_nsitem *plpgsql_ns_lookup(PLpgSQL_nsitem *ns_cur, bool localmode,
1301  const char *name1, const char *name2,
1302  const char *name3, int *names_used);
1304  const char *name);
1306 
1307 /*
1308  * Other functions in pl_funcs.c
1309  */
1310 extern PGDLLEXPORT const char *plpgsql_stmt_typename(PLpgSQL_stmt *stmt);
1311 extern const char *plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind);
1313 extern void plpgsql_dumptree(PLpgSQL_function *func);
1314 
1315 /*
1316  * Scanner functions in pl_scanner.c
1317  */
1318 extern int plpgsql_base_yylex(void);
1319 extern int plpgsql_yylex(void);
1320 extern int plpgsql_token_length(void);
1321 extern void plpgsql_push_back_token(int token);
1324  int startlocation, int endlocation);
1325 extern int plpgsql_peek(void);
1326 extern void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc,
1327  int *tok2_loc);
1328 extern int plpgsql_scanner_errposition(int location);
1329 extern void plpgsql_yyerror(const char *message) pg_attribute_noreturn();
1330 extern int plpgsql_location_to_lineno(int location);
1331 extern int plpgsql_latest_lineno(void);
1332 extern void plpgsql_scanner_init(const char *str);
1333 extern void plpgsql_scanner_finish(void);
1334 
1335 /*
1336  * Externs in gram.y
1337  */
1338 extern int plpgsql_yyparse(void);
1339 
1340 #endif /* PLPGSQL_H */
signed short int16
Definition: c.h:493
uint32 SubTransactionId
Definition: c.h:656
signed int int32
Definition: c.h:494
#define pg_attribute_noreturn()
Definition: c.h:217
#define PGDLLEXPORT
Definition: c.h:1331
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:398
uint32 LocalTransactionId
Definition: c.h:654
uint32 TransactionId
Definition: c.h:652
size_t Size
Definition: c.h:605
const char * str
#define stmt
Definition: indent_codes.h:59
#define ident
Definition: indent_codes.h:47
#define token
Definition: indent_globs.h:126
static struct @155 value
FetchDirection
Definition: parsenodes.h:3326
RawParseMode
Definition: parser.h:38
void * arg
static char * label
#define FUNC_MAX_ARGS
static char * buf
Definition: pg_test_fsync.c:73
PGDLLEXPORT 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
struct PLpgSQL_stmt_dynexecute PLpgSQL_stmt_dynexecute
void plpgsql_scanner_finish(void)
Definition: pl_scanner.c:630
PLpgSQL_recfield * plpgsql_build_recfield(PLpgSQL_rec *rec, const char *fldname)
Definition: pl_comp.c:1997
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:489
struct PLpgSQL_stmt_assert PLpgSQL_stmt_assert
PLpgSQL_type * plpgsql_build_datatype_arrayof(PLpgSQL_type *dtype)
Definition: pl_comp.c:2178
@ 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
PLpgSQL_resolve_option
Definition: plpgsql.h:184
@ PLPGSQL_RESOLVE_COLUMN
Definition: plpgsql.h:187
@ PLPGSQL_RESOLVE_ERROR
Definition: plpgsql.h:185
@ PLPGSQL_RESOLVE_VARIABLE
Definition: plpgsql.h:186
struct PLpgSQL_stmt_open PLpgSQL_stmt_open
int plpgsql_extra_warnings
Definition: pl_handler.c:52
PLpgSQL_trigtype
Definition: plpgsql.h:957
@ PLPGSQL_DML_TRIGGER
Definition: plpgsql.h:958
@ PLPGSQL_NOT_TRIGGER
Definition: plpgsql.h:960
@ PLPGSQL_EVENT_TRIGGER
Definition: plpgsql.h:959
struct PLpgSQL_func_hashkey PLpgSQL_func_hashkey
struct PLpgSQL_stmt_fetch PLpgSQL_stmt_fetch
struct PLpgSQL_raise_option PLpgSQL_raise_option
int plpgsql_add_initdatums(int **varnos)
Definition: pl_comp.c:2374
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:1903
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:1759
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
void plpgsql_ns_init(void)
Definition: pl_funcs.c:43
PGDLLEXPORT void plpgsql_parser_setup(struct ParseState *pstate, PLpgSQL_expr *expr)
Definition: pl_comp.c:1077
struct PLpgSQL_stmt_dynfors PLpgSQL_stmt_dynfors
PGDLLEXPORT PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation, TypeName *origtypname)
Definition: pl_comp.c:2044
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:1796
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:481
struct PLcword PLcword
PLpgSQL_variable * plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, bool add2namespace)
Definition: pl_comp.c:1840
struct PLpgSQL_stmt_perform PLpgSQL_stmt_perform
int plpgsql_location_to_lineno(int location)
Definition: pl_scanner.c:555
struct PLpgSQL_diag_item PLpgSQL_diag_item
struct PLpgSQL_row PLpgSQL_row
void plpgsql_HashTableInit(void)
Definition: pl_comp.c:2595
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:5543
PGDLLEXPORT Oid plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate, PLpgSQL_datum *datum)
Definition: pl_exec.c:5458
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:1600
char * plpgsql_error_funcname
Definition: pl_comp.c:49
PLpgSQL_raise_option_type
Definition: plpgsql.h:168
@ PLPGSQL_RAISEOPTION_COLUMN
Definition: plpgsql.h:173
@ PLPGSQL_RAISEOPTION_TABLE
Definition: plpgsql.h:176
@ PLPGSQL_RAISEOPTION_SCHEMA
Definition: plpgsql.h:177
@ PLPGSQL_RAISEOPTION_CONSTRAINT
Definition: plpgsql.h:174
@ PLPGSQL_RAISEOPTION_DETAIL
Definition: plpgsql.h:171
@ PLPGSQL_RAISEOPTION_MESSAGE
Definition: plpgsql.h:170
@ PLPGSQL_RAISEOPTION_HINT
Definition: plpgsql.h:172
@ PLPGSQL_RAISEOPTION_ERRCODE
Definition: plpgsql.h:169
@ PLPGSQL_RAISEOPTION_DATATYPE
Definition: plpgsql.h:175
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:2245
struct PLpgSQL_stmt_return PLpgSQL_stmt_return
bool plpgsql_token_is_unreserved_keyword(int token)
Definition: pl_scanner.c:404
void plpgsql_yyerror(const char *message) pg_attribute_noreturn()
Definition: pl_scanner.c:516
struct PLwdatum PLwdatum
struct PLpgSQL_stmt_exit PLpgSQL_stmt_exit
struct PLpgSQL_stmt_block PLpgSQL_stmt_block
struct PLpgSQL_rec PLpgSQL_rec
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:727
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:421
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:1606
PGDLLEXPORT const char * plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:232
bool plpgsql_parse_dblword(char *word1, char *word2, PLwdatum *wdatum, PLcword *cword)
Definition: pl_comp.c:1441
struct PLpgSQL_stmt_commit PLpgSQL_stmt_commit
struct PLpgSQL_datum PLpgSQL_datum
void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc, int *tok2_loc)
Definition: pl_scanner.c:456
struct PLpgSQL_case_when PLpgSQL_case_when
void plpgsql_adddatum(PLpgSQL_datum *newdatum)
Definition: pl_comp.c:2313
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:589
int plpgsql_token_length(void)
Definition: pl_scanner.c:313
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:1386
bool plpgsql_DumpExecTree
Definition: pl_comp.c:50
HeapTuple plpgsql_exec_trigger(PLpgSQL_function *func, TriggerData *trigdata)
Definition: pl_exec.c:922
int plpgsql_extra_errors
Definition: pl_handler.c:53
int plpgsql_peek(void)
Definition: pl_scanner.c:437
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:81
PLpgSQL_function * plpgsql_compile_inline(char *proc_source)
Definition: pl_comp.c:843
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:8495
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:1162
bool plpgsql_parse_tripword(char *word1, char *word2, char *word3, PLwdatum *wdatum, PLcword *cword)
Definition: pl_comp.c:1522
struct PLpgSQL_exception PLpgSQL_exception
PGDLLEXPORT PLpgSQL_function * plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator)
Definition: pl_comp.c:136
struct PLpgSQL_condition PLpgSQL_condition
struct PLpgSQL_recfield PLpgSQL_recfield
void plpgsql_scanner_init(const char *str)
Definition: pl_scanner.c:603
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
PGDLLEXPORT int plpgsql_recognize_err_condition(const char *condname, bool allow_sqlstate)
Definition: pl_comp.c:2209
PLpgSQL_type * plpgsql_parse_cwordtype(List *idents)
Definition: pl_comp.c:1647
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:387
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:8453
PLpgSQL_getdiag_kind
Definition: plpgsql.h:148
@ PLPGSQL_GETDIAG_ERROR_DETAIL
Definition: plpgsql.h:153
@ PLPGSQL_GETDIAG_SCHEMA_NAME
Definition: plpgsql.h:161
@ PLPGSQL_GETDIAG_MESSAGE_TEXT
Definition: plpgsql.h:159
@ PLPGSQL_GETDIAG_DATATYPE_NAME
Definition: plpgsql.h:158
@ PLPGSQL_GETDIAG_TABLE_NAME
Definition: plpgsql.h:160
@ PLPGSQL_GETDIAG_CONSTRAINT_NAME
Definition: plpgsql.h:157
@ PLPGSQL_GETDIAG_COLUMN_NAME
Definition: plpgsql.h:156
@ PLPGSQL_GETDIAG_ROW_COUNT
Definition: plpgsql.h:149
@ PLPGSQL_GETDIAG_RETURNED_SQLSTATE
Definition: plpgsql.h:155
@ PLPGSQL_GETDIAG_CONTEXT
Definition: plpgsql.h:151
@ PLPGSQL_GETDIAG_ERROR_HINT
Definition: plpgsql.h:154
@ PLPGSQL_GETDIAG_ERROR_CONTEXT
Definition: plpgsql.h:152
@ PLPGSQL_GETDIAG_ROUTINE_OID
Definition: plpgsql.h:150
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:64
unsigned int Oid
Definition: postgres_ext.h:31
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
Definition: regcomp.c:1474
Definition: dynahash.c:220
Definition: pg_list.h:54
List * idents
Definition: plpgsql.h:1172
PLpgSQL_expr * expr
Definition: plpgsql.h:635
char * condname
Definition: plpgsql.h:472
struct PLpgSQL_condition * next
Definition: plpgsql.h:473
PLpgSQL_datum_type dtype
Definition: plpgsql.h:277
PLpgSQL_getdiag_kind kind
Definition: plpgsql.h:574
PLpgSQL_condition * conditions
Definition: plpgsql.h:492
EState * simple_eval_estate
Definition: plpgsql.h:1071
TriggerData * trigdata
Definition: plpgsql.h:1025
PLpgSQL_datum ** datums
Definition: plpgsql.h:1058
ParamListInfo paramLI
Definition: plpgsql.h:1068
char * exitlabel
Definition: plpgsql.h:1039
ResourceOwner simple_eval_resowner
Definition: plpgsql.h:1072
ExprContext * eval_econtext
Definition: plpgsql.h:1087
ResourceOwner procedure_resowner
Definition: plpgsql.h:1075
PLpgSQL_function * func
Definition: plpgsql.h:1023
HTAB * cast_hash
Definition: plpgsql.h:1078
Tuplestorestate * tuple_store
Definition: plpgsql.h:1043
PLpgSQL_variable * err_var
Definition: plpgsql.h:1091
MemoryContext tuple_store_cxt
Definition: plpgsql.h:1045
TupleDesc tuple_store_desc
Definition: plpgsql.h:1044
MemoryContext datum_context
Definition: plpgsql.h:1060
ReturnSetInfo * rsi
Definition: plpgsql.h:1047
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:1026
ErrorData * cur_error
Definition: plpgsql.h:1041
ResourceOwner tuple_store_owner
Definition: plpgsql.h:1046
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:254
CachedPlan * expr_simple_plan
Definition: plpgsql.h:255
Oid expr_simple_type
Definition: plpgsql.h:233
int target_param
Definition: plpgsql.h:245
Expr * expr_simple_expr
Definition: plpgsql.h:232
SPIPlanPtr plan
Definition: plpgsql.h:222
struct PLpgSQL_nsitem * ns
Definition: plpgsql.h:229
ExprState * expr_simple_state
Definition: plpgsql.h:264
RawParseMode parseMode
Definition: plpgsql.h:221
struct PLpgSQL_function * func
Definition: plpgsql.h:226
bool expr_simple_mutable
Definition: plpgsql.h:235
bool expr_simple_in_use
Definition: plpgsql.h:265
Bitmapset * paramnos
Definition: plpgsql.h:223
Param * expr_rw_param
Definition: plpgsql.h:246
LocalTransactionId expr_simple_plan_lxid
Definition: plpgsql.h:256
LocalTransactionId expr_simple_lxid
Definition: plpgsql.h:266
char * query
Definition: plpgsql.h:220
int32 expr_simple_typmod
Definition: plpgsql.h:234
Oid argtypes[FUNC_MAX_ARGS]
Definition: plpgsql.h:950
bool print_strict_params
Definition: plpgsql.h:995
bool requires_procedure_resowner
Definition: plpgsql.h:1011
unsigned long use_count
Definition: plpgsql.h:1015
PLpgSQL_trigtype fn_is_trigger
Definition: plpgsql.h:972
Oid fn_input_collation
Definition: plpgsql.h:973
TransactionId fn_xmin
Definition: plpgsql.h:970
ItemPointerData fn_tid
Definition: plpgsql.h:971
bool fn_retbyval
Definition: plpgsql.h:979
bool fn_retisdomain
Definition: plpgsql.h:981
MemoryContext fn_cxt
Definition: plpgsql.h:975
int fn_argvarnos[FUNC_MAX_ARGS]
Definition: plpgsql.h:987
PLpgSQL_stmt_block * action
Definition: plpgsql.h:1007
Size copiable_size
Definition: plpgsql.h:1004
unsigned int nstatements
Definition: plpgsql.h:1010
bool fn_readonly
Definition: plpgsql.h:983
bool fn_retistuple
Definition: plpgsql.h:980
struct PLpgSQL_execstate * cur_estate
Definition: plpgsql.h:1014
int out_param_varno
Definition: plpgsql.h:988
PLpgSQL_resolve_option resolve_option
Definition: plpgsql.h:993
PLpgSQL_func_hashkey * fn_hashkey
Definition: plpgsql.h:974
int extra_warnings
Definition: plpgsql.h:998
PLpgSQL_datum ** datums
Definition: plpgsql.h:1003
char * fn_signature
Definition: plpgsql.h:968
PLpgSQL_expr * cond
Definition: plpgsql.h:610
List * stmts
Definition: plpgsql.h:611
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:447
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:446
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:439
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:872
PLpgSQL_expr * expr
Definition: plpgsql.h:873
ExpandedRecordHeader * erh
Definition: plpgsql.h:414
PLpgSQL_type * datatype
Definition: plpgsql.h:406
bool notnull
Definition: plpgsql.h:396
PLpgSQL_datum_type dtype
Definition: plpgsql.h:391
int firstfield
Definition: plpgsql.h:409
Oid rectypeid
Definition: plpgsql.h:407
bool isconst
Definition: plpgsql.h:395
int lineno
Definition: plpgsql.h:394
char * refname
Definition: plpgsql.h:393
PLpgSQL_expr * default_val
Definition: plpgsql.h:397
uint64 rectupledescid
Definition: plpgsql.h:429
PLpgSQL_datum_type dtype
Definition: plpgsql.h:422
char * fieldname
Definition: plpgsql.h:426
ExpandedRecordFieldInfo finfo
Definition: plpgsql.h:430
TupleDesc rowtupdesc
Definition: plpgsql.h:379
PLpgSQL_expr * default_val
Definition: plpgsql.h:371
bool isconst
Definition: plpgsql.h:369
int lineno
Definition: plpgsql.h:368
PLpgSQL_datum_type dtype
Definition: plpgsql.h:365
bool notnull
Definition: plpgsql.h:370
int * varnos
Definition: plpgsql.h:383
char * refname
Definition: plpgsql.h:367
char ** fieldnames
Definition: plpgsql.h:382
int nfields
Definition: plpgsql.h:381
unsigned int stmtid
Definition: plpgsql.h:883
PLpgSQL_expr * cond
Definition: plpgsql.h:884
PLpgSQL_expr * message
Definition: plpgsql.h:885
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:881
PLpgSQL_expr * expr
Definition: plpgsql.h:520
unsigned int stmtid
Definition: plpgsql.h:518
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:516
PLpgSQL_exception_block * exceptions
Definition: plpgsql.h:508
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:501
unsigned int stmtid
Definition: plpgsql.h:503
PLpgSQL_variable * target
Definition: plpgsql.h:544
PLpgSQL_expr * expr
Definition: plpgsql.h:542
unsigned int stmtid
Definition: plpgsql.h:541
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:539
List * case_when_list
Definition: plpgsql.h:624
List * else_stmts
Definition: plpgsql.h:626
PLpgSQL_expr * t_expr
Definition: plpgsql.h:622
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:619
unsigned int stmtid
Definition: plpgsql.h:621
unsigned int stmtid
Definition: plpgsql.h:798
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:796
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:552
unsigned int stmtid
Definition: plpgsql.h:554
PLpgSQL_expr * query
Definition: plpgsql.h:912
unsigned int stmtid
Definition: plpgsql.h:911
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:909
PLpgSQL_variable * target
Definition: plpgsql.h:915
unsigned int stmtid
Definition: plpgsql.h:734
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:732
PLpgSQL_variable * var
Definition: plpgsql.h:736
PLpgSQL_expr * query
Definition: plpgsql.h:739
PLpgSQL_variable * target
Definition: plpgsql.h:901
PLpgSQL_expr * sqlstmt
Definition: plpgsql.h:896
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:893
unsigned int stmtid
Definition: plpgsql.h:895
unsigned int stmtid
Definition: plpgsql.h:809
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:807
PLpgSQL_expr * cond
Definition: plpgsql.h:812
FetchDirection direction
Definition: plpgsql.h:784
bool returns_multiple_rows
Definition: plpgsql.h:788
PLpgSQL_variable * target
Definition: plpgsql.h:782
unsigned int stmtid
Definition: plpgsql.h:781
PLpgSQL_expr * expr
Definition: plpgsql.h:786
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:779
unsigned int stmtid
Definition: plpgsql.h:718
PLpgSQL_variable * var
Definition: plpgsql.h:720
PLpgSQL_expr * argquery
Definition: plpgsql.h:724
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:716
unsigned int stmtid
Definition: plpgsql.h:750
PLpgSQL_expr * expr
Definition: plpgsql.h:754
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:748
unsigned int stmtid
Definition: plpgsql.h:671
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:669
PLpgSQL_expr * upper
Definition: plpgsql.h:675
PLpgSQL_expr * lower
Definition: plpgsql.h:674
PLpgSQL_expr * step
Definition: plpgsql.h:676
PLpgSQL_var * var
Definition: plpgsql.h:673
unsigned int stmtid
Definition: plpgsql.h:690
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:688
PLpgSQL_variable * var
Definition: plpgsql.h:692
PLpgSQL_variable * var
Definition: plpgsql.h:705
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:701
PLpgSQL_expr * query
Definition: plpgsql.h:708
unsigned int stmtid
Definition: plpgsql.h:703
unsigned int stmtid
Definition: plpgsql.h:585
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:583
PLpgSQL_expr * cond
Definition: plpgsql.h:598
List * elsif_list
Definition: plpgsql.h:600
List * else_body
Definition: plpgsql.h:601
List * then_body
Definition: plpgsql.h:599
unsigned int stmtid
Definition: plpgsql.h:597
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:595
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:644
unsigned int stmtid
Definition: plpgsql.h:646
unsigned int stmtid
Definition: plpgsql.h:765
PLpgSQL_expr * argquery
Definition: plpgsql.h:768
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:763
PLpgSQL_expr * dynquery
Definition: plpgsql.h:770
PLpgSQL_expr * query
Definition: plpgsql.h:769
PLpgSQL_expr * expr
Definition: plpgsql.h:531
unsigned int stmtid
Definition: plpgsql.h:530
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:528
unsigned int stmtid
Definition: plpgsql.h:859
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:857
PLpgSQL_expr * expr
Definition: plpgsql.h:835
unsigned int stmtid
Definition: plpgsql.h:834
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:832
PLpgSQL_expr * dynquery
Definition: plpgsql.h:848
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:844
unsigned int stmtid
Definition: plpgsql.h:846
PLpgSQL_expr * query
Definition: plpgsql.h:847
unsigned int stmtid
Definition: plpgsql.h:822
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:820
PLpgSQL_expr * expr
Definition: plpgsql.h:823
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:563
unsigned int stmtid
Definition: plpgsql.h:565
unsigned int stmtid
Definition: plpgsql.h:658
PLpgSQL_expr * cond
Definition: plpgsql.h:660
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:656
int lineno
Definition: plpgsql.h:456
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:455
unsigned int stmtid
Definition: plpgsql.h:463
char typtype
Definition: plpgsql.h:205
TypeName * origtypname
Definition: plpgsql.h:210
bool typisarray
Definition: plpgsql.h:207
TypeCacheEntry * tcache
Definition: plpgsql.h:211
uint64 tupdesc_id
Definition: plpgsql.h:212
Oid collation
Definition: plpgsql.h:206
PLpgSQL_type_type ttype
Definition: plpgsql.h:202
Oid typoid
Definition: plpgsql.h:201
char * typname
Definition: plpgsql.h:200
int16 typlen
Definition: plpgsql.h:203
int32 atttypmod
Definition: plpgsql.h:208
bool typbyval
Definition: plpgsql.h:204
int lineno
Definition: plpgsql.h:314
PLpgSQL_promise_type promise
Definition: plpgsql.h:342
PLpgSQL_datum_type dtype
Definition: plpgsql.h:311
bool freeval
Definition: plpgsql.h:335
int cursor_explicit_argrow
Definition: plpgsql.h:328
int cursor_options
Definition: plpgsql.h:329
bool notnull
Definition: plpgsql.h:316
bool isconst
Definition: plpgsql.h:315
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:327
bool isnull
Definition: plpgsql.h:334
PLpgSQL_type * datatype
Definition: plpgsql.h:320
PLpgSQL_expr * default_val
Definition: plpgsql.h:317
char * refname
Definition: plpgsql.h:313
Datum value
Definition: plpgsql.h:333
PLpgSQL_expr * default_val
Definition: plpgsql.h:295
PLpgSQL_datum_type dtype
Definition: plpgsql.h:289
char * refname
Definition: plpgsql.h:291
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:304
const char * name
SubXactEvent
Definition: xact.h:141
XactEvent
Definition: xact.h:127