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