PostgreSQL Source Code  git master
pl_funcs.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pl_funcs.c - Misc functions 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/pl_funcs.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 
16 #include "postgres.h"
17 
18 #include "plpgsql.h"
19 #include "utils/memutils.h"
20 
21 /* ----------
22  * Local variables for namespace handling
23  *
24  * The namespace structure actually forms a tree, of which only one linear
25  * list or "chain" (from the youngest item to the root) is accessible from
26  * any one plpgsql statement. During initial parsing of a function, ns_top
27  * points to the youngest item accessible from the block currently being
28  * parsed. We store the entire tree, however, since at runtime we will need
29  * to access the chain that's relevant to any one statement.
30  *
31  * Block boundaries in the namespace chain are marked by PLPGSQL_NSTYPE_LABEL
32  * items.
33  * ----------
34  */
35 static PLpgSQL_nsitem *ns_top = NULL;
36 
37 
38 /* ----------
39  * plpgsql_ns_init Initialize namespace processing for a new function
40  * ----------
41  */
42 void
44 {
45  ns_top = NULL;
46 }
47 
48 
49 /* ----------
50  * plpgsql_ns_push Create a new namespace level
51  * ----------
52  */
53 void
54 plpgsql_ns_push(const char *label, PLpgSQL_label_type label_type)
55 {
56  if (label == NULL)
57  label = "";
58  plpgsql_ns_additem(PLPGSQL_NSTYPE_LABEL, (int) label_type, label);
59 }
60 
61 
62 /* ----------
63  * plpgsql_ns_pop Pop entries back to (and including) the last label
64  * ----------
65  */
66 void
68 {
69  Assert(ns_top != NULL);
71  ns_top = ns_top->prev;
72  ns_top = ns_top->prev;
73 }
74 
75 
76 /* ----------
77  * plpgsql_ns_top Fetch the current namespace chain end
78  * ----------
79  */
82 {
83  return ns_top;
84 }
85 
86 
87 /* ----------
88  * plpgsql_ns_additem Add an item to the current namespace chain
89  * ----------
90  */
91 void
92 plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
93 {
94  PLpgSQL_nsitem *nse;
95 
96  Assert(name != NULL);
97  /* first item added must be a label */
98  Assert(ns_top != NULL || itemtype == PLPGSQL_NSTYPE_LABEL);
99 
100  nse = palloc(offsetof(PLpgSQL_nsitem, name) + strlen(name) + 1);
101  nse->itemtype = itemtype;
102  nse->itemno = itemno;
103  nse->prev = ns_top;
104  strcpy(nse->name, name);
105  ns_top = nse;
106 }
107 
108 
109 /* ----------
110  * plpgsql_ns_lookup Lookup an identifier in the given namespace chain
111  *
112  * Note that this only searches for variables, not labels.
113  *
114  * If localmode is true, only the topmost block level is searched.
115  *
116  * name1 must be non-NULL. Pass NULL for name2 and/or name3 if parsing a name
117  * with fewer than three components.
118  *
119  * If names_used isn't NULL, *names_used receives the number of names
120  * matched: 0 if no match, 1 if name1 matched an unqualified variable name,
121  * 2 if name1 and name2 matched a block label + variable name.
122  *
123  * Note that name3 is never directly matched to anything. However, if it
124  * isn't NULL, we will disregard qualified matches to scalar variables.
125  * Similarly, if name2 isn't NULL, we disregard unqualified matches to
126  * scalar variables.
127  * ----------
128  */
130 plpgsql_ns_lookup(PLpgSQL_nsitem *ns_cur, bool localmode,
131  const char *name1, const char *name2, const char *name3,
132  int *names_used)
133 {
134  /* Outer loop iterates once per block level in the namespace chain */
135  while (ns_cur != NULL)
136  {
137  PLpgSQL_nsitem *nsitem;
138 
139  /* Check this level for unqualified match to variable name */
140  for (nsitem = ns_cur;
141  nsitem->itemtype != PLPGSQL_NSTYPE_LABEL;
142  nsitem = nsitem->prev)
143  {
144  if (strcmp(nsitem->name, name1) == 0)
145  {
146  if (name2 == NULL ||
147  nsitem->itemtype != PLPGSQL_NSTYPE_VAR)
148  {
149  if (names_used)
150  *names_used = 1;
151  return nsitem;
152  }
153  }
154  }
155 
156  /* Check this level for qualified match to variable name */
157  if (name2 != NULL &&
158  strcmp(nsitem->name, name1) == 0)
159  {
160  for (nsitem = ns_cur;
161  nsitem->itemtype != PLPGSQL_NSTYPE_LABEL;
162  nsitem = nsitem->prev)
163  {
164  if (strcmp(nsitem->name, name2) == 0)
165  {
166  if (name3 == NULL ||
167  nsitem->itemtype != PLPGSQL_NSTYPE_VAR)
168  {
169  if (names_used)
170  *names_used = 2;
171  return nsitem;
172  }
173  }
174  }
175  }
176 
177  if (localmode)
178  break; /* do not look into upper levels */
179 
180  ns_cur = nsitem->prev;
181  }
182 
183  /* This is just to suppress possibly-uninitialized-variable warnings */
184  if (names_used)
185  *names_used = 0;
186  return NULL; /* No match found */
187 }
188 
189 
190 /* ----------
191  * plpgsql_ns_lookup_label Lookup a label in the given namespace chain
192  * ----------
193  */
196 {
197  while (ns_cur != NULL)
198  {
199  if (ns_cur->itemtype == PLPGSQL_NSTYPE_LABEL &&
200  strcmp(ns_cur->name, name) == 0)
201  return ns_cur;
202  ns_cur = ns_cur->prev;
203  }
204 
205  return NULL; /* label not found */
206 }
207 
208 
209 /* ----------
210  * plpgsql_ns_find_nearest_loop Find innermost loop label in namespace chain
211  * ----------
212  */
215 {
216  while (ns_cur != NULL)
217  {
218  if (ns_cur->itemtype == PLPGSQL_NSTYPE_LABEL &&
219  ns_cur->itemno == PLPGSQL_LABEL_LOOP)
220  return ns_cur;
221  ns_cur = ns_cur->prev;
222  }
223 
224  return NULL; /* no loop found */
225 }
226 
227 
228 /*
229  * Statement type as a string, for use in error messages etc.
230  */
231 const char *
233 {
234  switch (stmt->cmd_type)
235  {
236  case PLPGSQL_STMT_BLOCK:
237  return _("statement block");
238  case PLPGSQL_STMT_ASSIGN:
239  return _("assignment");
240  case PLPGSQL_STMT_IF:
241  return "IF";
242  case PLPGSQL_STMT_CASE:
243  return "CASE";
244  case PLPGSQL_STMT_LOOP:
245  return "LOOP";
246  case PLPGSQL_STMT_WHILE:
247  return "WHILE";
248  case PLPGSQL_STMT_FORI:
249  return _("FOR with integer loop variable");
250  case PLPGSQL_STMT_FORS:
251  return _("FOR over SELECT rows");
252  case PLPGSQL_STMT_FORC:
253  return _("FOR over cursor");
255  return _("FOREACH over array");
256  case PLPGSQL_STMT_EXIT:
257  return ((PLpgSQL_stmt_exit *) stmt)->is_exit ? "EXIT" : "CONTINUE";
258  case PLPGSQL_STMT_RETURN:
259  return "RETURN";
261  return "RETURN NEXT";
263  return "RETURN QUERY";
264  case PLPGSQL_STMT_RAISE:
265  return "RAISE";
266  case PLPGSQL_STMT_ASSERT:
267  return "ASSERT";
269  return _("SQL statement");
271  return "EXECUTE";
273  return _("FOR over EXECUTE statement");
275  return ((PLpgSQL_stmt_getdiag *) stmt)->is_stacked ?
276  "GET STACKED DIAGNOSTICS" : "GET DIAGNOSTICS";
277  case PLPGSQL_STMT_OPEN:
278  return "OPEN";
279  case PLPGSQL_STMT_FETCH:
280  return ((PLpgSQL_stmt_fetch *) stmt)->is_move ? "MOVE" : "FETCH";
281  case PLPGSQL_STMT_CLOSE:
282  return "CLOSE";
284  return "PERFORM";
285  case PLPGSQL_STMT_CALL:
286  return ((PLpgSQL_stmt_call *) stmt)->is_call ? "CALL" : "DO";
287  case PLPGSQL_STMT_COMMIT:
288  return "COMMIT";
290  return "ROLLBACK";
291  }
292 
293  return "unknown";
294 }
295 
296 /*
297  * GET DIAGNOSTICS item name as a string, for use in error messages etc.
298  */
299 const char *
301 {
302  switch (kind)
303  {
305  return "ROW_COUNT";
307  return "PG_ROUTINE_OID";
309  return "PG_CONTEXT";
311  return "PG_EXCEPTION_CONTEXT";
313  return "PG_EXCEPTION_DETAIL";
315  return "PG_EXCEPTION_HINT";
317  return "RETURNED_SQLSTATE";
319  return "COLUMN_NAME";
321  return "CONSTRAINT_NAME";
323  return "PG_DATATYPE_NAME";
325  return "MESSAGE_TEXT";
327  return "TABLE_NAME";
329  return "SCHEMA_NAME";
330  }
331 
332  return "unknown";
333 }
334 
335 
336 /**********************************************************************
337  * Release memory when a PL/pgSQL function is no longer needed
338  *
339  * The code for recursing through the function tree is really only
340  * needed to locate PLpgSQL_expr nodes, which may contain references
341  * to saved SPI Plans that must be freed. The function tree itself,
342  * along with subsidiary data, is freed in one swoop by freeing the
343  * function's permanent memory context.
344  **********************************************************************/
345 static void free_stmt(PLpgSQL_stmt *stmt);
346 static void free_block(PLpgSQL_stmt_block *block);
347 static void free_assign(PLpgSQL_stmt_assign *stmt);
348 static void free_if(PLpgSQL_stmt_if *stmt);
349 static void free_case(PLpgSQL_stmt_case *stmt);
350 static void free_loop(PLpgSQL_stmt_loop *stmt);
351 static void free_while(PLpgSQL_stmt_while *stmt);
352 static void free_fori(PLpgSQL_stmt_fori *stmt);
353 static void free_fors(PLpgSQL_stmt_fors *stmt);
354 static void free_forc(PLpgSQL_stmt_forc *stmt);
356 static void free_exit(PLpgSQL_stmt_exit *stmt);
357 static void free_return(PLpgSQL_stmt_return *stmt);
360 static void free_raise(PLpgSQL_stmt_raise *stmt);
361 static void free_assert(PLpgSQL_stmt_assert *stmt);
366 static void free_open(PLpgSQL_stmt_open *stmt);
367 static void free_fetch(PLpgSQL_stmt_fetch *stmt);
368 static void free_close(PLpgSQL_stmt_close *stmt);
370 static void free_call(PLpgSQL_stmt_call *stmt);
371 static void free_commit(PLpgSQL_stmt_commit *stmt);
373 static void free_expr(PLpgSQL_expr *expr);
374 
375 
376 static void
378 {
379  switch (stmt->cmd_type)
380  {
381  case PLPGSQL_STMT_BLOCK:
383  break;
384  case PLPGSQL_STMT_ASSIGN:
386  break;
387  case PLPGSQL_STMT_IF:
389  break;
390  case PLPGSQL_STMT_CASE:
392  break;
393  case PLPGSQL_STMT_LOOP:
395  break;
396  case PLPGSQL_STMT_WHILE:
398  break;
399  case PLPGSQL_STMT_FORI:
401  break;
402  case PLPGSQL_STMT_FORS:
404  break;
405  case PLPGSQL_STMT_FORC:
407  break;
410  break;
411  case PLPGSQL_STMT_EXIT:
413  break;
414  case PLPGSQL_STMT_RETURN:
416  break;
419  break;
422  break;
423  case PLPGSQL_STMT_RAISE:
425  break;
426  case PLPGSQL_STMT_ASSERT:
428  break;
431  break;
434  break;
437  break;
440  break;
441  case PLPGSQL_STMT_OPEN:
443  break;
444  case PLPGSQL_STMT_FETCH:
446  break;
447  case PLPGSQL_STMT_CLOSE:
449  break;
452  break;
453  case PLPGSQL_STMT_CALL:
455  break;
456  case PLPGSQL_STMT_COMMIT:
458  break;
461  break;
462  default:
463  elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
464  break;
465  }
466 }
467 
468 static void
470 {
471  ListCell *s;
472 
473  foreach(s, stmts)
474  {
475  free_stmt((PLpgSQL_stmt *) lfirst(s));
476  }
477 }
478 
479 static void
481 {
482  free_stmts(block->body);
483  if (block->exceptions)
484  {
485  ListCell *e;
486 
487  foreach(e, block->exceptions->exc_list)
488  {
490 
491  free_stmts(exc->action);
492  }
493  }
494 }
495 
496 static void
498 {
499  free_expr(stmt->expr);
500 }
501 
502 static void
504 {
505  ListCell *l;
506 
507  free_expr(stmt->cond);
508  free_stmts(stmt->then_body);
509  foreach(l, stmt->elsif_list)
510  {
512 
513  free_expr(elif->cond);
514  free_stmts(elif->stmts);
515  }
516  free_stmts(stmt->else_body);
517 }
518 
519 static void
521 {
522  ListCell *l;
523 
524  free_expr(stmt->t_expr);
525  foreach(l, stmt->case_when_list)
526  {
528 
529  free_expr(cwt->expr);
530  free_stmts(cwt->stmts);
531  }
532  free_stmts(stmt->else_stmts);
533 }
534 
535 static void
537 {
538  free_stmts(stmt->body);
539 }
540 
541 static void
543 {
544  free_expr(stmt->cond);
545  free_stmts(stmt->body);
546 }
547 
548 static void
550 {
551  free_expr(stmt->lower);
552  free_expr(stmt->upper);
553  free_expr(stmt->step);
554  free_stmts(stmt->body);
555 }
556 
557 static void
559 {
560  free_stmts(stmt->body);
561  free_expr(stmt->query);
562 }
563 
564 static void
566 {
567  free_stmts(stmt->body);
568  free_expr(stmt->argquery);
569 }
570 
571 static void
573 {
574  free_expr(stmt->expr);
575  free_stmts(stmt->body);
576 }
577 
578 static void
580 {
581  ListCell *lc;
582 
583  free_expr(stmt->argquery);
584  free_expr(stmt->query);
585  free_expr(stmt->dynquery);
586  foreach(lc, stmt->params)
587  {
588  free_expr((PLpgSQL_expr *) lfirst(lc));
589  }
590 }
591 
592 static void
594 {
595  free_expr(stmt->expr);
596 }
597 
598 static void
600 {
601 }
602 
603 static void
605 {
606  free_expr(stmt->expr);
607 }
608 
609 static void
611 {
612  free_expr(stmt->expr);
613 }
614 
615 static void
617 {
618 }
619 
620 static void
622 {
623 }
624 
625 static void
627 {
628  free_expr(stmt->cond);
629 }
630 
631 static void
633 {
634  free_expr(stmt->expr);
635 }
636 
637 static void
639 {
640  free_expr(stmt->expr);
641 }
642 
643 static void
645 {
646  ListCell *lc;
647 
648  free_expr(stmt->query);
649  free_expr(stmt->dynquery);
650  foreach(lc, stmt->params)
651  {
652  free_expr((PLpgSQL_expr *) lfirst(lc));
653  }
654 }
655 
656 static void
658 {
659  ListCell *lc;
660 
661  foreach(lc, stmt->params)
662  {
663  free_expr((PLpgSQL_expr *) lfirst(lc));
664  }
665  foreach(lc, stmt->options)
666  {
668 
669  free_expr(opt->expr);
670  }
671 }
672 
673 static void
675 {
676  free_expr(stmt->cond);
677  free_expr(stmt->message);
678 }
679 
680 static void
682 {
683  free_expr(stmt->sqlstmt);
684 }
685 
686 static void
688 {
689  ListCell *lc;
690 
691  free_expr(stmt->query);
692  foreach(lc, stmt->params)
693  {
694  free_expr((PLpgSQL_expr *) lfirst(lc));
695  }
696 }
697 
698 static void
700 {
701  ListCell *lc;
702 
703  free_stmts(stmt->body);
704  free_expr(stmt->query);
705  foreach(lc, stmt->params)
706  {
707  free_expr((PLpgSQL_expr *) lfirst(lc));
708  }
709 }
710 
711 static void
713 {
714 }
715 
716 static void
718 {
719  if (expr && expr->plan)
720  {
721  SPI_freeplan(expr->plan);
722  expr->plan = NULL;
723  }
724 }
725 
726 void
728 {
729  int i;
730 
731  /* Better not call this on an in-use function */
732  Assert(func->use_count == 0);
733 
734  /* Release plans associated with variable declarations */
735  for (i = 0; i < func->ndatums; i++)
736  {
737  PLpgSQL_datum *d = func->datums[i];
738 
739  switch (d->dtype)
740  {
741  case PLPGSQL_DTYPE_VAR:
743  {
744  PLpgSQL_var *var = (PLpgSQL_var *) d;
745 
746  free_expr(var->default_val);
748  }
749  break;
750  case PLPGSQL_DTYPE_ROW:
751  break;
752  case PLPGSQL_DTYPE_REC:
753  {
754  PLpgSQL_rec *rec = (PLpgSQL_rec *) d;
755 
756  free_expr(rec->default_val);
757  }
758  break;
760  break;
761  default:
762  elog(ERROR, "unrecognized data type: %d", d->dtype);
763  }
764  }
765  func->ndatums = 0;
766 
767  /* Release plans in statement tree */
768  if (func->action)
769  free_block(func->action);
770  func->action = NULL;
771 
772  /*
773  * And finally, release all memory except the PLpgSQL_function struct
774  * itself (which has to be kept around because there may be multiple
775  * fn_extra pointers to it).
776  */
777  if (func->fn_cxt)
779  func->fn_cxt = NULL;
780 }
781 
782 
783 /**********************************************************************
784  * Debug functions for analyzing the compiled code
785  **********************************************************************/
786 static int dump_indent;
787 
788 static void dump_ind(void);
789 static void dump_stmt(PLpgSQL_stmt *stmt);
790 static void dump_block(PLpgSQL_stmt_block *block);
791 static void dump_assign(PLpgSQL_stmt_assign *stmt);
792 static void dump_if(PLpgSQL_stmt_if *stmt);
793 static void dump_case(PLpgSQL_stmt_case *stmt);
794 static void dump_loop(PLpgSQL_stmt_loop *stmt);
795 static void dump_while(PLpgSQL_stmt_while *stmt);
796 static void dump_fori(PLpgSQL_stmt_fori *stmt);
797 static void dump_fors(PLpgSQL_stmt_fors *stmt);
798 static void dump_forc(PLpgSQL_stmt_forc *stmt);
800 static void dump_exit(PLpgSQL_stmt_exit *stmt);
801 static void dump_return(PLpgSQL_stmt_return *stmt);
804 static void dump_raise(PLpgSQL_stmt_raise *stmt);
805 static void dump_assert(PLpgSQL_stmt_assert *stmt);
810 static void dump_open(PLpgSQL_stmt_open *stmt);
811 static void dump_fetch(PLpgSQL_stmt_fetch *stmt);
813 static void dump_close(PLpgSQL_stmt_close *stmt);
815 static void dump_call(PLpgSQL_stmt_call *stmt);
816 static void dump_commit(PLpgSQL_stmt_commit *stmt);
818 static void dump_expr(PLpgSQL_expr *expr);
819 
820 
821 static void
822 dump_ind(void)
823 {
824  int i;
825 
826  for (i = 0; i < dump_indent; i++)
827  printf(" ");
828 }
829 
830 static void
832 {
833  printf("%3d:", stmt->lineno);
834  switch (stmt->cmd_type)
835  {
836  case PLPGSQL_STMT_BLOCK:
838  break;
839  case PLPGSQL_STMT_ASSIGN:
841  break;
842  case PLPGSQL_STMT_IF:
844  break;
845  case PLPGSQL_STMT_CASE:
847  break;
848  case PLPGSQL_STMT_LOOP:
850  break;
851  case PLPGSQL_STMT_WHILE:
853  break;
854  case PLPGSQL_STMT_FORI:
856  break;
857  case PLPGSQL_STMT_FORS:
859  break;
860  case PLPGSQL_STMT_FORC:
862  break;
865  break;
866  case PLPGSQL_STMT_EXIT:
868  break;
869  case PLPGSQL_STMT_RETURN:
871  break;
874  break;
877  break;
878  case PLPGSQL_STMT_RAISE:
880  break;
881  case PLPGSQL_STMT_ASSERT:
883  break;
886  break;
889  break;
892  break;
895  break;
896  case PLPGSQL_STMT_OPEN:
898  break;
899  case PLPGSQL_STMT_FETCH:
901  break;
902  case PLPGSQL_STMT_CLOSE:
904  break;
907  break;
908  case PLPGSQL_STMT_CALL:
910  break;
911  case PLPGSQL_STMT_COMMIT:
913  break;
916  break;
917  default:
918  elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
919  break;
920  }
921 }
922 
923 static void
925 {
926  ListCell *s;
927 
928  dump_indent += 2;
929  foreach(s, stmts)
930  dump_stmt((PLpgSQL_stmt *) lfirst(s));
931  dump_indent -= 2;
932 }
933 
934 static void
936 {
937  char *name;
938 
939  if (block->label == NULL)
940  name = "*unnamed*";
941  else
942  name = block->label;
943 
944  dump_ind();
945  printf("BLOCK <<%s>>\n", name);
946 
947  dump_stmts(block->body);
948 
949  if (block->exceptions)
950  {
951  ListCell *e;
952 
953  foreach(e, block->exceptions->exc_list)
954  {
956  PLpgSQL_condition *cond;
957 
958  dump_ind();
959  printf(" EXCEPTION WHEN ");
960  for (cond = exc->conditions; cond; cond = cond->next)
961  {
962  if (cond != exc->conditions)
963  printf(" OR ");
964  printf("%s", cond->condname);
965  }
966  printf(" THEN\n");
967  dump_stmts(exc->action);
968  }
969  }
970 
971  dump_ind();
972  printf(" END -- %s\n", name);
973 }
974 
975 static void
977 {
978  dump_ind();
979  printf("ASSIGN var %d := ", stmt->varno);
980  dump_expr(stmt->expr);
981  printf("\n");
982 }
983 
984 static void
986 {
987  ListCell *l;
988 
989  dump_ind();
990  printf("IF ");
991  dump_expr(stmt->cond);
992  printf(" THEN\n");
993  dump_stmts(stmt->then_body);
994  foreach(l, stmt->elsif_list)
995  {
997 
998  dump_ind();
999  printf(" ELSIF ");
1000  dump_expr(elif->cond);
1001  printf(" THEN\n");
1002  dump_stmts(elif->stmts);
1003  }
1004  if (stmt->else_body != NIL)
1005  {
1006  dump_ind();
1007  printf(" ELSE\n");
1008  dump_stmts(stmt->else_body);
1009  }
1010  dump_ind();
1011  printf(" ENDIF\n");
1012 }
1013 
1014 static void
1016 {
1017  ListCell *l;
1018 
1019  dump_ind();
1020  printf("CASE %d ", stmt->t_varno);
1021  if (stmt->t_expr)
1022  dump_expr(stmt->t_expr);
1023  printf("\n");
1024  dump_indent += 6;
1025  foreach(l, stmt->case_when_list)
1026  {
1028 
1029  dump_ind();
1030  printf("WHEN ");
1031  dump_expr(cwt->expr);
1032  printf("\n");
1033  dump_ind();
1034  printf("THEN\n");
1035  dump_indent += 2;
1036  dump_stmts(cwt->stmts);
1037  dump_indent -= 2;
1038  }
1039  if (stmt->have_else)
1040  {
1041  dump_ind();
1042  printf("ELSE\n");
1043  dump_indent += 2;
1044  dump_stmts(stmt->else_stmts);
1045  dump_indent -= 2;
1046  }
1047  dump_indent -= 6;
1048  dump_ind();
1049  printf(" ENDCASE\n");
1050 }
1051 
1052 static void
1054 {
1055  dump_ind();
1056  printf("LOOP\n");
1057 
1058  dump_stmts(stmt->body);
1059 
1060  dump_ind();
1061  printf(" ENDLOOP\n");
1062 }
1063 
1064 static void
1066 {
1067  dump_ind();
1068  printf("WHILE ");
1069  dump_expr(stmt->cond);
1070  printf("\n");
1071 
1072  dump_stmts(stmt->body);
1073 
1074  dump_ind();
1075  printf(" ENDWHILE\n");
1076 }
1077 
1078 static void
1080 {
1081  dump_ind();
1082  printf("FORI %s %s\n", stmt->var->refname, (stmt->reverse) ? "REVERSE" : "NORMAL");
1083 
1084  dump_indent += 2;
1085  dump_ind();
1086  printf(" lower = ");
1087  dump_expr(stmt->lower);
1088  printf("\n");
1089  dump_ind();
1090  printf(" upper = ");
1091  dump_expr(stmt->upper);
1092  printf("\n");
1093  if (stmt->step)
1094  {
1095  dump_ind();
1096  printf(" step = ");
1097  dump_expr(stmt->step);
1098  printf("\n");
1099  }
1100  dump_indent -= 2;
1101 
1102  dump_stmts(stmt->body);
1103 
1104  dump_ind();
1105  printf(" ENDFORI\n");
1106 }
1107 
1108 static void
1110 {
1111  dump_ind();
1112  printf("FORS %s ", stmt->var->refname);
1113  dump_expr(stmt->query);
1114  printf("\n");
1115 
1116  dump_stmts(stmt->body);
1117 
1118  dump_ind();
1119  printf(" ENDFORS\n");
1120 }
1121 
1122 static void
1124 {
1125  dump_ind();
1126  printf("FORC %s ", stmt->var->refname);
1127  printf("curvar=%d\n", stmt->curvar);
1128 
1129  dump_indent += 2;
1130  if (stmt->argquery != NULL)
1131  {
1132  dump_ind();
1133  printf(" arguments = ");
1134  dump_expr(stmt->argquery);
1135  printf("\n");
1136  }
1137  dump_indent -= 2;
1138 
1139  dump_stmts(stmt->body);
1140 
1141  dump_ind();
1142  printf(" ENDFORC\n");
1143 }
1144 
1145 static void
1147 {
1148  dump_ind();
1149  printf("FOREACHA var %d ", stmt->varno);
1150  if (stmt->slice != 0)
1151  printf("SLICE %d ", stmt->slice);
1152  printf("IN ");
1153  dump_expr(stmt->expr);
1154  printf("\n");
1155 
1156  dump_stmts(stmt->body);
1157 
1158  dump_ind();
1159  printf(" ENDFOREACHA");
1160 }
1161 
1162 static void
1164 {
1165  dump_ind();
1166  printf("OPEN curvar=%d\n", stmt->curvar);
1167 
1168  dump_indent += 2;
1169  if (stmt->argquery != NULL)
1170  {
1171  dump_ind();
1172  printf(" arguments = '");
1173  dump_expr(stmt->argquery);
1174  printf("'\n");
1175  }
1176  if (stmt->query != NULL)
1177  {
1178  dump_ind();
1179  printf(" query = '");
1180  dump_expr(stmt->query);
1181  printf("'\n");
1182  }
1183  if (stmt->dynquery != NULL)
1184  {
1185  dump_ind();
1186  printf(" execute = '");
1187  dump_expr(stmt->dynquery);
1188  printf("'\n");
1189 
1190  if (stmt->params != NIL)
1191  {
1192  ListCell *lc;
1193  int i;
1194 
1195  dump_indent += 2;
1196  dump_ind();
1197  printf(" USING\n");
1198  dump_indent += 2;
1199  i = 1;
1200  foreach(lc, stmt->params)
1201  {
1202  dump_ind();
1203  printf(" parameter $%d: ", i++);
1204  dump_expr((PLpgSQL_expr *) lfirst(lc));
1205  printf("\n");
1206  }
1207  dump_indent -= 4;
1208  }
1209  }
1210  dump_indent -= 2;
1211 }
1212 
1213 static void
1215 {
1216  dump_ind();
1217 
1218  if (!stmt->is_move)
1219  {
1220  printf("FETCH curvar=%d\n", stmt->curvar);
1222 
1223  dump_indent += 2;
1224  if (stmt->target != NULL)
1225  {
1226  dump_ind();
1227  printf(" target = %d %s\n",
1228  stmt->target->dno, stmt->target->refname);
1229  }
1230  dump_indent -= 2;
1231  }
1232  else
1233  {
1234  printf("MOVE curvar=%d\n", stmt->curvar);
1236  }
1237 }
1238 
1239 static void
1241 {
1242  dump_indent += 2;
1243  dump_ind();
1244  switch (stmt->direction)
1245  {
1246  case FETCH_FORWARD:
1247  printf(" FORWARD ");
1248  break;
1249  case FETCH_BACKWARD:
1250  printf(" BACKWARD ");
1251  break;
1252  case FETCH_ABSOLUTE:
1253  printf(" ABSOLUTE ");
1254  break;
1255  case FETCH_RELATIVE:
1256  printf(" RELATIVE ");
1257  break;
1258  default:
1259  printf("??? unknown cursor direction %d", stmt->direction);
1260  }
1261 
1262  if (stmt->expr)
1263  {
1264  dump_expr(stmt->expr);
1265  printf("\n");
1266  }
1267  else
1268  printf("%ld\n", stmt->how_many);
1269 
1270  dump_indent -= 2;
1271 }
1272 
1273 static void
1275 {
1276  dump_ind();
1277  printf("CLOSE curvar=%d\n", stmt->curvar);
1278 }
1279 
1280 static void
1282 {
1283  dump_ind();
1284  printf("PERFORM expr = ");
1285  dump_expr(stmt->expr);
1286  printf("\n");
1287 }
1288 
1289 static void
1291 {
1292  dump_ind();
1293  printf("%s expr = ", stmt->is_call ? "CALL" : "DO");
1294  dump_expr(stmt->expr);
1295  printf("\n");
1296 }
1297 
1298 static void
1300 {
1301  dump_ind();
1302  if (stmt->chain)
1303  printf("COMMIT AND CHAIN\n");
1304  else
1305  printf("COMMIT\n");
1306 }
1307 
1308 static void
1310 {
1311  dump_ind();
1312  if (stmt->chain)
1313  printf("ROLLBACK AND CHAIN\n");
1314  else
1315  printf("ROLLBACK\n");
1316 }
1317 
1318 static void
1320 {
1321  dump_ind();
1322  printf("%s", stmt->is_exit ? "EXIT" : "CONTINUE");
1323  if (stmt->label != NULL)
1324  printf(" label='%s'", stmt->label);
1325  if (stmt->cond != NULL)
1326  {
1327  printf(" WHEN ");
1328  dump_expr(stmt->cond);
1329  }
1330  printf("\n");
1331 }
1332 
1333 static void
1335 {
1336  dump_ind();
1337  printf("RETURN ");
1338  if (stmt->retvarno >= 0)
1339  printf("variable %d", stmt->retvarno);
1340  else if (stmt->expr != NULL)
1341  dump_expr(stmt->expr);
1342  else
1343  printf("NULL");
1344  printf("\n");
1345 }
1346 
1347 static void
1349 {
1350  dump_ind();
1351  printf("RETURN NEXT ");
1352  if (stmt->retvarno >= 0)
1353  printf("variable %d", stmt->retvarno);
1354  else if (stmt->expr != NULL)
1355  dump_expr(stmt->expr);
1356  else
1357  printf("NULL");
1358  printf("\n");
1359 }
1360 
1361 static void
1363 {
1364  dump_ind();
1365  if (stmt->query)
1366  {
1367  printf("RETURN QUERY ");
1368  dump_expr(stmt->query);
1369  printf("\n");
1370  }
1371  else
1372  {
1373  printf("RETURN QUERY EXECUTE ");
1374  dump_expr(stmt->dynquery);
1375  printf("\n");
1376  if (stmt->params != NIL)
1377  {
1378  ListCell *lc;
1379  int i;
1380 
1381  dump_indent += 2;
1382  dump_ind();
1383  printf(" USING\n");
1384  dump_indent += 2;
1385  i = 1;
1386  foreach(lc, stmt->params)
1387  {
1388  dump_ind();
1389  printf(" parameter $%d: ", i++);
1390  dump_expr((PLpgSQL_expr *) lfirst(lc));
1391  printf("\n");
1392  }
1393  dump_indent -= 4;
1394  }
1395  }
1396 }
1397 
1398 static void
1400 {
1401  ListCell *lc;
1402  int i = 0;
1403 
1404  dump_ind();
1405  printf("RAISE level=%d", stmt->elog_level);
1406  if (stmt->condname)
1407  printf(" condname='%s'", stmt->condname);
1408  if (stmt->message)
1409  printf(" message='%s'", stmt->message);
1410  printf("\n");
1411  dump_indent += 2;
1412  foreach(lc, stmt->params)
1413  {
1414  dump_ind();
1415  printf(" parameter %d: ", i++);
1416  dump_expr((PLpgSQL_expr *) lfirst(lc));
1417  printf("\n");
1418  }
1419  if (stmt->options)
1420  {
1421  dump_ind();
1422  printf(" USING\n");
1423  dump_indent += 2;
1424  foreach(lc, stmt->options)
1425  {
1427 
1428  dump_ind();
1429  switch (opt->opt_type)
1430  {
1432  printf(" ERRCODE = ");
1433  break;
1435  printf(" MESSAGE = ");
1436  break;
1438  printf(" DETAIL = ");
1439  break;
1441  printf(" HINT = ");
1442  break;
1444  printf(" COLUMN = ");
1445  break;
1447  printf(" CONSTRAINT = ");
1448  break;
1450  printf(" DATATYPE = ");
1451  break;
1453  printf(" TABLE = ");
1454  break;
1456  printf(" SCHEMA = ");
1457  break;
1458  }
1459  dump_expr(opt->expr);
1460  printf("\n");
1461  }
1462  dump_indent -= 2;
1463  }
1464  dump_indent -= 2;
1465 }
1466 
1467 static void
1469 {
1470  dump_ind();
1471  printf("ASSERT ");
1472  dump_expr(stmt->cond);
1473  printf("\n");
1474 
1475  dump_indent += 2;
1476  if (stmt->message != NULL)
1477  {
1478  dump_ind();
1479  printf(" MESSAGE = ");
1480  dump_expr(stmt->message);
1481  printf("\n");
1482  }
1483  dump_indent -= 2;
1484 }
1485 
1486 static void
1488 {
1489  dump_ind();
1490  printf("EXECSQL ");
1491  dump_expr(stmt->sqlstmt);
1492  printf("\n");
1493 
1494  dump_indent += 2;
1495  if (stmt->target != NULL)
1496  {
1497  dump_ind();
1498  printf(" INTO%s target = %d %s\n",
1499  stmt->strict ? " STRICT" : "",
1500  stmt->target->dno, stmt->target->refname);
1501  }
1502  dump_indent -= 2;
1503 }
1504 
1505 static void
1507 {
1508  dump_ind();
1509  printf("EXECUTE ");
1510  dump_expr(stmt->query);
1511  printf("\n");
1512 
1513  dump_indent += 2;
1514  if (stmt->target != NULL)
1515  {
1516  dump_ind();
1517  printf(" INTO%s target = %d %s\n",
1518  stmt->strict ? " STRICT" : "",
1519  stmt->target->dno, stmt->target->refname);
1520  }
1521  if (stmt->params != NIL)
1522  {
1523  ListCell *lc;
1524  int i;
1525 
1526  dump_ind();
1527  printf(" USING\n");
1528  dump_indent += 2;
1529  i = 1;
1530  foreach(lc, stmt->params)
1531  {
1532  dump_ind();
1533  printf(" parameter %d: ", i++);
1534  dump_expr((PLpgSQL_expr *) lfirst(lc));
1535  printf("\n");
1536  }
1537  dump_indent -= 2;
1538  }
1539  dump_indent -= 2;
1540 }
1541 
1542 static void
1544 {
1545  dump_ind();
1546  printf("FORS %s EXECUTE ", stmt->var->refname);
1547  dump_expr(stmt->query);
1548  printf("\n");
1549  if (stmt->params != NIL)
1550  {
1551  ListCell *lc;
1552  int i;
1553 
1554  dump_indent += 2;
1555  dump_ind();
1556  printf(" USING\n");
1557  dump_indent += 2;
1558  i = 1;
1559  foreach(lc, stmt->params)
1560  {
1561  dump_ind();
1562  printf(" parameter $%d: ", i++);
1563  dump_expr((PLpgSQL_expr *) lfirst(lc));
1564  printf("\n");
1565  }
1566  dump_indent -= 4;
1567  }
1568  dump_stmts(stmt->body);
1569  dump_ind();
1570  printf(" ENDFORS\n");
1571 }
1572 
1573 static void
1575 {
1576  ListCell *lc;
1577 
1578  dump_ind();
1579  printf("GET %s DIAGNOSTICS ", stmt->is_stacked ? "STACKED" : "CURRENT");
1580  foreach(lc, stmt->diag_items)
1581  {
1582  PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc);
1583 
1584  if (lc != list_head(stmt->diag_items))
1585  printf(", ");
1586 
1587  printf("{var %d} = %s", diag_item->target,
1588  plpgsql_getdiag_kindname(diag_item->kind));
1589  }
1590  printf("\n");
1591 }
1592 
1593 static void
1595 {
1596  printf("'%s'", expr->query);
1597 }
1598 
1599 void
1601 {
1602  int i;
1603  PLpgSQL_datum *d;
1604 
1605  printf("\nExecution tree of successfully compiled PL/pgSQL function %s:\n",
1606  func->fn_signature);
1607 
1608  printf("\nFunction's data area:\n");
1609  for (i = 0; i < func->ndatums; i++)
1610  {
1611  d = func->datums[i];
1612 
1613  printf(" entry %d: ", i);
1614  switch (d->dtype)
1615  {
1616  case PLPGSQL_DTYPE_VAR:
1617  case PLPGSQL_DTYPE_PROMISE:
1618  {
1619  PLpgSQL_var *var = (PLpgSQL_var *) d;
1620 
1621  printf("VAR %-16s type %s (typoid %u) atttypmod %d\n",
1622  var->refname, var->datatype->typname,
1623  var->datatype->typoid,
1624  var->datatype->atttypmod);
1625  if (var->isconst)
1626  printf(" CONSTANT\n");
1627  if (var->notnull)
1628  printf(" NOT NULL\n");
1629  if (var->default_val != NULL)
1630  {
1631  printf(" DEFAULT ");
1632  dump_expr(var->default_val);
1633  printf("\n");
1634  }
1635  if (var->cursor_explicit_expr != NULL)
1636  {
1637  if (var->cursor_explicit_argrow >= 0)
1638  printf(" CURSOR argument row %d\n", var->cursor_explicit_argrow);
1639 
1640  printf(" CURSOR IS ");
1642  printf("\n");
1643  }
1644  if (var->promise != PLPGSQL_PROMISE_NONE)
1645  printf(" PROMISE %d\n",
1646  (int) var->promise);
1647  }
1648  break;
1649  case PLPGSQL_DTYPE_ROW:
1650  {
1651  PLpgSQL_row *row = (PLpgSQL_row *) d;
1652 
1653  printf("ROW %-16s fields", row->refname);
1654  for (int j = 0; j < row->nfields; j++)
1655  {
1656  printf(" %s=var %d", row->fieldnames[j],
1657  row->varnos[j]);
1658  }
1659  printf("\n");
1660  }
1661  break;
1662  case PLPGSQL_DTYPE_REC:
1663  printf("REC %-16s typoid %u\n",
1664  ((PLpgSQL_rec *) d)->refname,
1665  ((PLpgSQL_rec *) d)->rectypeid);
1666  if (((PLpgSQL_rec *) d)->isconst)
1667  printf(" CONSTANT\n");
1668  if (((PLpgSQL_rec *) d)->notnull)
1669  printf(" NOT NULL\n");
1670  if (((PLpgSQL_rec *) d)->default_val != NULL)
1671  {
1672  printf(" DEFAULT ");
1673  dump_expr(((PLpgSQL_rec *) d)->default_val);
1674  printf("\n");
1675  }
1676  break;
1678  printf("RECFIELD %-16s of REC %d\n",
1679  ((PLpgSQL_recfield *) d)->fieldname,
1680  ((PLpgSQL_recfield *) d)->recparentno);
1681  break;
1682  default:
1683  printf("??? unknown data type %d\n", d->dtype);
1684  }
1685  }
1686  printf("\nFunction's statements:\n");
1687 
1688  dump_indent = 0;
1689  printf("%3d:", func->action->lineno);
1690  dump_block(func->action);
1691  printf("\nEnd of execution tree of function %s\n\n", func->fn_signature);
1692  fflush(stdout);
1693 }
#define _(x)
Definition: elog.c:91
#define ERROR
Definition: elog.h:39
#define stmt
Definition: indent_codes.h:59
int j
Definition: isn.c:74
int i
Definition: isn.c:73
static void const char fflush(stdout)
Assert(fmt[strlen(fmt) - 1] !='\n')
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
void * palloc(Size size)
Definition: mcxt.c:1201
@ FETCH_RELATIVE
Definition: parsenodes.h:3163
@ FETCH_ABSOLUTE
Definition: parsenodes.h:3162
@ FETCH_FORWARD
Definition: parsenodes.h:3159
@ FETCH_BACKWARD
Definition: parsenodes.h:3160
static char * label
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
static void dump_dynexecute(PLpgSQL_stmt_dynexecute *stmt)
Definition: pl_funcs.c:1506
static void dump_return_next(PLpgSQL_stmt_return_next *stmt)
Definition: pl_funcs.c:1348
void plpgsql_ns_pop(void)
Definition: pl_funcs.c:67
const char * plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind)
Definition: pl_funcs.c:300
static void free_rollback(PLpgSQL_stmt_rollback *stmt)
Definition: pl_funcs.c:621
static void free_assign(PLpgSQL_stmt_assign *stmt)
Definition: pl_funcs.c:497
static void free_return(PLpgSQL_stmt_return *stmt)
Definition: pl_funcs.c:632
static void free_assert(PLpgSQL_stmt_assert *stmt)
Definition: pl_funcs.c:674
static void free_fori(PLpgSQL_stmt_fori *stmt)
Definition: pl_funcs.c:549
static void dump_close(PLpgSQL_stmt_close *stmt)
Definition: pl_funcs.c:1274
static void free_getdiag(PLpgSQL_stmt_getdiag *stmt)
Definition: pl_funcs.c:712
static void dump_perform(PLpgSQL_stmt_perform *stmt)
Definition: pl_funcs.c:1281
static void dump_if(PLpgSQL_stmt_if *stmt)
Definition: pl_funcs.c:985
static void free_stmts(List *stmts)
Definition: pl_funcs.c:469
static void dump_fetch(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:1214
void plpgsql_ns_init(void)
Definition: pl_funcs.c:43
static void dump_execsql(PLpgSQL_stmt_execsql *stmt)
Definition: pl_funcs.c:1487
static int dump_indent
Definition: pl_funcs.c:786
static void dump_case(PLpgSQL_stmt_case *stmt)
Definition: pl_funcs.c:1015
static void free_forc(PLpgSQL_stmt_forc *stmt)
Definition: pl_funcs.c:565
static void free_fetch(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:593
static void dump_open(PLpgSQL_stmt_open *stmt)
Definition: pl_funcs.c:1163
static void dump_assign(PLpgSQL_stmt_assign *stmt)
Definition: pl_funcs.c:976
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:924
static void free_while(PLpgSQL_stmt_while *stmt)
Definition: pl_funcs.c:542
static void dump_cursor_direction(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:1240
void plpgsql_dumptree(PLpgSQL_function *func)
Definition: pl_funcs.c:1600
static void free_raise(PLpgSQL_stmt_raise *stmt)
Definition: pl_funcs.c:657
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:35
static void dump_loop(PLpgSQL_stmt_loop *stmt)
Definition: pl_funcs.c:1053
const char * plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:232
static void free_dynexecute(PLpgSQL_stmt_dynexecute *stmt)
Definition: pl_funcs.c:687
static void dump_raise(PLpgSQL_stmt_raise *stmt)
Definition: pl_funcs.c:1399
static void dump_rollback(PLpgSQL_stmt_rollback *stmt)
Definition: pl_funcs.c:1309
static void free_if(PLpgSQL_stmt_if *stmt)
Definition: pl_funcs.c:503
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
static void dump_while(PLpgSQL_stmt_while *stmt)
Definition: pl_funcs.c:1065
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1594
static void dump_stmt(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:831
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition: pl_funcs.c:92
static void dump_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:935
static void dump_getdiag(PLpgSQL_stmt_getdiag *stmt)
Definition: pl_funcs.c:1574
static void dump_exit(PLpgSQL_stmt_exit *stmt)
Definition: pl_funcs.c:1319
static void free_commit(PLpgSQL_stmt_commit *stmt)
Definition: pl_funcs.c:616
static void free_call(PLpgSQL_stmt_call *stmt)
Definition: pl_funcs.c:610
static void free_open(PLpgSQL_stmt_open *stmt)
Definition: pl_funcs.c:579
static void free_case(PLpgSQL_stmt_case *stmt)
Definition: pl_funcs.c:520
static void free_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:480
static void free_fors(PLpgSQL_stmt_fors *stmt)
Definition: pl_funcs.c:558
static void free_execsql(PLpgSQL_stmt_execsql *stmt)
Definition: pl_funcs.c:681
static void dump_call(PLpgSQL_stmt_call *stmt)
Definition: pl_funcs.c:1290
static void free_exit(PLpgSQL_stmt_exit *stmt)
Definition: pl_funcs.c:626
static void free_close(PLpgSQL_stmt_close *stmt)
Definition: pl_funcs.c:599
static void dump_forc(PLpgSQL_stmt_forc *stmt)
Definition: pl_funcs.c:1123
static void dump_ind(void)
Definition: pl_funcs.c:822
static void free_return_query(PLpgSQL_stmt_return_query *stmt)
Definition: pl_funcs.c:644
PLpgSQL_nsitem * plpgsql_ns_top(void)
Definition: pl_funcs.c:81
static void dump_commit(PLpgSQL_stmt_commit *stmt)
Definition: pl_funcs.c:1299
static void free_return_next(PLpgSQL_stmt_return_next *stmt)
Definition: pl_funcs.c:638
static void dump_return(PLpgSQL_stmt_return *stmt)
Definition: pl_funcs.c:1334
void plpgsql_ns_push(const char *label, PLpgSQL_label_type label_type)
Definition: pl_funcs.c:54
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:717
static void free_stmt(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:377
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
static void free_foreach_a(PLpgSQL_stmt_foreach_a *stmt)
Definition: pl_funcs.c:572
static void free_loop(PLpgSQL_stmt_loop *stmt)
Definition: pl_funcs.c:536
static void dump_foreach_a(PLpgSQL_stmt_foreach_a *stmt)
Definition: pl_funcs.c:1146
static void dump_return_query(PLpgSQL_stmt_return_query *stmt)
Definition: pl_funcs.c:1362
static void dump_assert(PLpgSQL_stmt_assert *stmt)
Definition: pl_funcs.c:1468
static void dump_dynfors(PLpgSQL_stmt_dynfors *stmt)
Definition: pl_funcs.c:1543
static void dump_fori(PLpgSQL_stmt_fori *stmt)
Definition: pl_funcs.c:1079
static void dump_fors(PLpgSQL_stmt_fors *stmt)
Definition: pl_funcs.c:1109
static void free_dynfors(PLpgSQL_stmt_dynfors *stmt)
Definition: pl_funcs.c:699
static void free_perform(PLpgSQL_stmt_perform *stmt)
Definition: pl_funcs.c:604
PLpgSQL_nsitem * plpgsql_ns_lookup_label(PLpgSQL_nsitem *ns_cur, const char *name)
Definition: pl_funcs.c:195
@ 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_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_PROMISE_NONE
Definition: plpgsql.h:75
PLpgSQL_label_type
Definition: plpgsql.h:52
@ PLPGSQL_LABEL_LOOP
Definition: plpgsql.h:54
@ 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
PLpgSQL_nsitem_type
Definition: plpgsql.h:42
@ PLPGSQL_NSTYPE_VAR
Definition: plpgsql.h:44
@ PLPGSQL_NSTYPE_LABEL
Definition: plpgsql.h:43
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
#define printf(...)
Definition: port.h:244
e
Definition: preproc-init.c:82
int SPI_freeplan(SPIPlanPtr plan)
Definition: spi.c:1023
Definition: pg_list.h:54
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
SPIPlanPtr plan
Definition: plpgsql.h:222
char * query
Definition: plpgsql.h:220
unsigned long use_count
Definition: plpgsql.h:1015
MemoryContext fn_cxt
Definition: plpgsql.h:975
PLpgSQL_stmt_block * action
Definition: plpgsql.h:1007
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
PLpgSQL_raise_option_type opt_type
Definition: plpgsql.h:872
PLpgSQL_expr * expr
Definition: plpgsql.h:873
PLpgSQL_datum_type dtype
Definition: plpgsql.h:391
PLpgSQL_expr * default_val
Definition: plpgsql.h:397
int * varnos
Definition: plpgsql.h:383
char * refname
Definition: plpgsql.h:367
char ** fieldnames
Definition: plpgsql.h:382
int nfields
Definition: plpgsql.h:381
PLpgSQL_exception_block * exceptions
Definition: plpgsql.h:508
Oid typoid
Definition: plpgsql.h:201
char * typname
Definition: plpgsql.h:200
int32 atttypmod
Definition: plpgsql.h:208
PLpgSQL_promise_type promise
Definition: plpgsql.h:342
int cursor_explicit_argrow
Definition: plpgsql.h:328
bool notnull
Definition: plpgsql.h:316
bool isconst
Definition: plpgsql.h:315
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:327
PLpgSQL_type * datatype
Definition: plpgsql.h:320
PLpgSQL_expr * default_val
Definition: plpgsql.h:317
char * refname
Definition: plpgsql.h:313
const char * name