PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pl_funcs.c File Reference
#include "postgres.h"
#include "plpgsql.h"
#include "utils/memutils.h"
Include dependency graph for pl_funcs.c:

Go to the source code of this file.

Macros

#define plpgsql_statement_tree_walker(s, sw, ew, c)
 
#define S_WALK(st)   stmt_callback(st, context)
 
#define E_WALK(ex)   expr_callback(ex, context)
 
#define S_LIST_WALK(lst)   foreach_ptr(PLpgSQL_stmt, st, lst) S_WALK(st)
 
#define E_LIST_WALK(lst)   foreach_ptr(PLpgSQL_expr, ex, lst) E_WALK(ex)
 

Typedefs

typedef void(* plpgsql_stmt_walker_callback) (PLpgSQL_stmt *stmt, void *context)
 
typedef void(* plpgsql_expr_walker_callback) (PLpgSQL_expr *expr, void *context)
 

Functions

void plpgsql_ns_init (void)
 
void plpgsql_ns_push (const char *label, PLpgSQL_label_type label_type)
 
void plpgsql_ns_pop (void)
 
PLpgSQL_nsitemplpgsql_ns_top (void)
 
void plpgsql_ns_additem (PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
 
PLpgSQL_nsitemplpgsql_ns_lookup (PLpgSQL_nsitem *ns_cur, bool localmode, const char *name1, const char *name2, const char *name3, int *names_used)
 
PLpgSQL_nsitemplpgsql_ns_lookup_label (PLpgSQL_nsitem *ns_cur, const char *name)
 
PLpgSQL_nsitemplpgsql_ns_find_nearest_loop (PLpgSQL_nsitem *ns_cur)
 
const charplpgsql_stmt_typename (PLpgSQL_stmt *stmt)
 
const charplpgsql_getdiag_kindname (PLpgSQL_getdiag_kind kind)
 
static void plpgsql_statement_tree_walker_impl (PLpgSQL_stmt *stmt, plpgsql_stmt_walker_callback stmt_callback, plpgsql_expr_walker_callback expr_callback, void *context)
 
static void mark_stmt (PLpgSQL_stmt *stmt, Bitmapset *local_dnos)
 
static void mark_expr (PLpgSQL_expr *expr, Bitmapset *local_dnos)
 
void plpgsql_mark_local_assignment_targets (PLpgSQL_function *func)
 
static void free_stmt (PLpgSQL_stmt *stmt, void *context)
 
static void free_expr (PLpgSQL_expr *expr, void *context)
 
void plpgsql_free_function_memory (PLpgSQL_function *func)
 
void plpgsql_delete_callback (CachedFunction *cfunc)
 
static void dump_ind (void)
 
static void dump_stmt (PLpgSQL_stmt *stmt)
 
static void dump_block (PLpgSQL_stmt_block *block)
 
static void dump_assign (PLpgSQL_stmt_assign *stmt)
 
static void dump_if (PLpgSQL_stmt_if *stmt)
 
static void dump_case (PLpgSQL_stmt_case *stmt)
 
static void dump_loop (PLpgSQL_stmt_loop *stmt)
 
static void dump_while (PLpgSQL_stmt_while *stmt)
 
static void dump_fori (PLpgSQL_stmt_fori *stmt)
 
static void dump_fors (PLpgSQL_stmt_fors *stmt)
 
static void dump_forc (PLpgSQL_stmt_forc *stmt)
 
static void dump_foreach_a (PLpgSQL_stmt_foreach_a *stmt)
 
static void dump_exit (PLpgSQL_stmt_exit *stmt)
 
static void dump_return (PLpgSQL_stmt_return *stmt)
 
static void dump_return_next (PLpgSQL_stmt_return_next *stmt)
 
static void dump_return_query (PLpgSQL_stmt_return_query *stmt)
 
static void dump_raise (PLpgSQL_stmt_raise *stmt)
 
static void dump_assert (PLpgSQL_stmt_assert *stmt)
 
static void dump_execsql (PLpgSQL_stmt_execsql *stmt)
 
static void dump_dynexecute (PLpgSQL_stmt_dynexecute *stmt)
 
static void dump_dynfors (PLpgSQL_stmt_dynfors *stmt)
 
static void dump_getdiag (PLpgSQL_stmt_getdiag *stmt)
 
static void dump_open (PLpgSQL_stmt_open *stmt)
 
static void dump_fetch (PLpgSQL_stmt_fetch *stmt)
 
static void dump_cursor_direction (PLpgSQL_stmt_fetch *stmt)
 
static void dump_close (PLpgSQL_stmt_close *stmt)
 
static void dump_perform (PLpgSQL_stmt_perform *stmt)
 
static void dump_call (PLpgSQL_stmt_call *stmt)
 
static void dump_commit (PLpgSQL_stmt_commit *stmt)
 
static void dump_rollback (PLpgSQL_stmt_rollback *stmt)
 
static void dump_expr (PLpgSQL_expr *expr)
 
static void dump_stmts (List *stmts)
 
void plpgsql_dumptree (PLpgSQL_function *func)
 

Variables

static PLpgSQL_nsitemns_top = NULL
 
static int dump_indent
 

Macro Definition Documentation

◆ E_LIST_WALK

#define E_LIST_WALK (   lst)    foreach_ptr(PLpgSQL_expr, ex, lst) E_WALK(ex)

◆ E_WALK

#define E_WALK (   ex)    expr_callback(ex, context)

◆ plpgsql_statement_tree_walker

#define plpgsql_statement_tree_walker (   s,
  sw,
  ew,
  c 
)
Value:
void(* plpgsql_stmt_walker_callback)(PLpgSQL_stmt *stmt, void *context)
Definition pl_funcs.c:349
static void plpgsql_statement_tree_walker_impl(PLpgSQL_stmt *stmt, plpgsql_stmt_walker_callback stmt_callback, plpgsql_expr_walker_callback expr_callback, void *context)
Definition pl_funcs.c:364
void(* plpgsql_expr_walker_callback)(PLpgSQL_expr *expr, void *context)
Definition pl_funcs.c:351
char * c
static int fb(int x)

Definition at line 359 of file pl_funcs.c.

367{
368#define S_WALK(st) stmt_callback(st, context)
369#define E_WALK(ex) expr_callback(ex, context)
370#define S_LIST_WALK(lst) foreach_ptr(PLpgSQL_stmt, st, lst) S_WALK(st)
371#define E_LIST_WALK(lst) foreach_ptr(PLpgSQL_expr, ex, lst) E_WALK(ex)
372
373 switch (stmt->cmd_type)
374 {
376 {
378
379 S_LIST_WALK(bstmt->body);
380 if (bstmt->exceptions)
381 {
382 foreach_ptr(PLpgSQL_exception, exc, bstmt->exceptions->exc_list)
383 {
384 /* conditions list has no interesting sub-structure */
385 S_LIST_WALK(exc->action);
386 }
387 }
388 break;
389 }
391 {
393
394 E_WALK(astmt->expr);
395 break;
396 }
397 case PLPGSQL_STMT_IF:
398 {
400
401 E_WALK(ifstmt->cond);
402 S_LIST_WALK(ifstmt->then_body);
404 {
405 E_WALK(elif->cond);
406 S_LIST_WALK(elif->stmts);
407 }
408 S_LIST_WALK(ifstmt->else_body);
409 break;
410 }
412 {
414
415 E_WALK(cstmt->t_expr);
416 foreach_ptr(PLpgSQL_case_when, cwt, cstmt->case_when_list)
417 {
418 E_WALK(cwt->expr);
419 S_LIST_WALK(cwt->stmts);
420 }
421 S_LIST_WALK(cstmt->else_stmts);
422 break;
423 }
425 {
427
428 S_LIST_WALK(lstmt->body);
429 break;
430 }
432 {
434
435 E_WALK(wstmt->cond);
436 S_LIST_WALK(wstmt->body);
437 break;
438 }
440 {
442
443 E_WALK(fori->lower);
444 E_WALK(fori->upper);
445 E_WALK(fori->step);
446 S_LIST_WALK(fori->body);
447 break;
448 }
450 {
452
453 S_LIST_WALK(fors->body);
454 E_WALK(fors->query);
455 break;
456 }
458 {
460
461 S_LIST_WALK(forc->body);
462 E_WALK(forc->argquery);
463 break;
464 }
466 {
468
469 E_WALK(fstmt->expr);
470 S_LIST_WALK(fstmt->body);
471 break;
472 }
474 {
476
477 E_WALK(estmt->cond);
478 break;
479 }
481 {
483
484 E_WALK(rstmt->expr);
485 break;
486 }
488 {
490
491 E_WALK(rstmt->expr);
492 break;
493 }
495 {
497
498 E_WALK(rstmt->query);
499 E_WALK(rstmt->dynquery);
500 E_LIST_WALK(rstmt->params);
501 break;
502 }
504 {
506
507 E_LIST_WALK(rstmt->params);
509 {
510 E_WALK(opt->expr);
511 }
512 break;
513 }
515 {
517
518 E_WALK(astmt->cond);
519 E_WALK(astmt->message);
520 break;
521 }
523 {
525
526 E_WALK(xstmt->sqlstmt);
527 break;
528 }
530 {
532
533 E_WALK(dstmt->query);
534 E_LIST_WALK(dstmt->params);
535 break;
536 }
538 {
540
541 S_LIST_WALK(dstmt->body);
542 E_WALK(dstmt->query);
543 E_LIST_WALK(dstmt->params);
544 break;
545 }
547 {
548 /* no interesting sub-structure */
549 break;
550 }
552 {
554
555 E_WALK(ostmt->argquery);
556 E_WALK(ostmt->query);
557 E_WALK(ostmt->dynquery);
558 E_LIST_WALK(ostmt->params);
559 break;
560 }
562 {
564
565 E_WALK(fstmt->expr);
566 break;
567 }
569 {
570 /* no interesting sub-structure */
571 break;
572 }
574 {
576
577 E_WALK(pstmt->expr);
578 break;
579 }
581 {
583
584 E_WALK(cstmt->expr);
585 break;
586 }
589 {
590 /* no interesting sub-structure */
591 break;
592 }
593 default:
594 elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
595 break;
596 }
597}
598
599
600/**********************************************************************
601 * Mark assignment source expressions that have local target variables,
602 * that is, the target variable is declared within the exception block
603 * most closely containing the assignment itself. (Such target variables
604 * need not be preserved if the assignment's source expression raises an
605 * error, since the variable will no longer be accessible afterwards.
606 * Detecting this allows better optimization.)
607 *
608 * This code need not be called if the plpgsql function contains no exception
609 * blocks, because mark_expr_as_assignment_source will have set all the flags
610 * to true already. Also, we need not reconsider default-value expressions
611 * for variables, because variable declarations are necessarily within the
612 * nearest exception block. (In DECLARE ... BEGIN ... EXCEPTION ... END, the
613 * variable initializations are done before entering the exception scope.)
614 *
615 * Within the recursion, local_dnos is a Bitmapset of dnos of variables
616 * known to be declared within the current exception level.
617 **********************************************************************/
619static void mark_expr(PLpgSQL_expr *expr, Bitmapset *local_dnos);
620
621static void
623{
624 if (stmt == NULL)
625 return;
626 if (stmt->cmd_type == PLPGSQL_STMT_BLOCK)
627 {
629
630 if (block->exceptions)
631 {
632 /*
633 * The block creates a new exception scope, so variables declared
634 * at outer levels are nonlocal. For that matter, so are any
635 * variables declared in the block's DECLARE section. Hence, we
636 * must pass down empty local_dnos.
637 */
639 }
640 else
641 {
642 /*
643 * Otherwise, the block does not create a new exception scope, and
644 * any variables it declares can also be considered local within
645 * it. Note that only initializable datum types (VAR, REC) are
646 * included in initvarnos; but that's sufficient for our purposes.
647 */
649 for (int i = 0; i < block->n_initvars; i++)
652 local_dnos);
654 }
655 }
656 else
658}
659
660static void
662{
663 /*
664 * If this expression has an assignment target, check whether the target
665 * is local, and mark the expression accordingly.
666 */
667 if (expr && expr->target_param >= 0)
669}
670
671void
673{
675
676 /* Function parameters can be treated as local targets at outer level */
678 for (int i = 0; i < func->fn_nargs; i++)
682}
683
684
685/**********************************************************************
686 * Release memory when a PL/pgSQL function is no longer needed
687 *
688 * This code only needs to deal with cleaning up PLpgSQL_expr nodes,
689 * which may contain references to saved SPI Plans that must be freed.
690 * The function tree itself, along with subsidiary data, is freed in
691 * one swoop by freeing the function's permanent memory context.
692 **********************************************************************/
693static void free_stmt(PLpgSQL_stmt *stmt, void *context);
694static void free_expr(PLpgSQL_expr *expr, void *context);
695
696static void
697free_stmt(PLpgSQL_stmt *stmt, void *context)
698{
699 if (stmt == NULL)
700 return;
702}
703
704static void
705free_expr(PLpgSQL_expr *expr, void *context)
706{
707 if (expr && expr->plan)
708 {
709 SPI_freeplan(expr->plan);
710 expr->plan = NULL;
711 }
712}
713
714void
716{
717 int i;
718
719 /* Better not call this on an in-use function */
720 Assert(func->cfunc.use_count == 0);
721
722 /* Release plans associated with variable declarations */
723 for (i = 0; i < func->ndatums; i++)
724 {
725 PLpgSQL_datum *d = func->datums[i];
726
727 switch (d->dtype)
728 {
731 {
732 PLpgSQL_var *var = (PLpgSQL_var *) d;
733
736 }
737 break;
739 break;
741 {
742 PLpgSQL_rec *rec = (PLpgSQL_rec *) d;
743
745 }
746 break;
748 break;
749 default:
750 elog(ERROR, "unrecognized data type: %d", d->dtype);
751 }
752 }
753 func->ndatums = 0;
754
755 /* Release plans in statement tree */
756 free_stmt((PLpgSQL_stmt *) func->action, NULL);
757 func->action = NULL;
758
759 /*
760 * And finally, release all memory except the PLpgSQL_function struct
761 * itself (which has to be kept around because there may be multiple
762 * fn_extra pointers to it).
763 */
764 if (func->fn_cxt)
766 func->fn_cxt = NULL;
767}
768
769/* Deletion callback used by funccache.c */
770void
772{
774}
775
776
777/**********************************************************************
778 * Debug functions for analyzing the compiled code
779 *
780 * Sadly, there doesn't seem to be any way to let plpgsql_statement_tree_walker
781 * bear some of the burden for this.
782 **********************************************************************/
783static int dump_indent;
784
785static void dump_ind(void);
786static void dump_stmt(PLpgSQL_stmt *stmt);
787static void dump_block(PLpgSQL_stmt_block *block);
789static void dump_if(PLpgSQL_stmt_if *stmt);
790static void dump_case(PLpgSQL_stmt_case *stmt);
791static void dump_loop(PLpgSQL_stmt_loop *stmt);
793static void dump_fori(PLpgSQL_stmt_fori *stmt);
794static void dump_fors(PLpgSQL_stmt_fors *stmt);
795static void dump_forc(PLpgSQL_stmt_forc *stmt);
797static void dump_exit(PLpgSQL_stmt_exit *stmt);
807static void dump_open(PLpgSQL_stmt_open *stmt);
812static void dump_call(PLpgSQL_stmt_call *stmt);
815static void dump_expr(PLpgSQL_expr *expr);
816
817
818static void
819dump_ind(void)
820{
821 int i;
822
823 for (i = 0; i < dump_indent; i++)
824 printf(" ");
825}
826
827static void
829{
830 printf("%3d:", stmt->lineno);
831 switch (stmt->cmd_type)
832 {
835 break;
838 break;
839 case PLPGSQL_STMT_IF:
841 break;
844 break;
847 break;
850 break;
853 break;
856 break;
859 break;
862 break;
865 break;
868 break;
871 break;
874 break;
877 break;
880 break;
883 break;
886 break;
889 break;
892 break;
895 break;
898 break;
901 break;
904 break;
907 break;
910 break;
913 break;
914 default:
915 elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
916 break;
917 }
918}
919
920static void
921dump_stmts(List *stmts)
922{
923 ListCell *s;
924
925 dump_indent += 2;
926 foreach(s, stmts)
928 dump_indent -= 2;
929}
930
931static void
933{
934 char *name;
935
936 if (block->label == NULL)
937 name = "*unnamed*";
938 else
939 name = block->label;
940
941 dump_ind();
942 printf("BLOCK <<%s>>\n", name);
943
944 dump_stmts(block->body);
945
946 if (block->exceptions)
947 {
948 ListCell *e;
949
950 foreach(e, block->exceptions->exc_list)
951 {
953 PLpgSQL_condition *cond;
954
955 dump_ind();
956 printf(" EXCEPTION WHEN ");
957 for (cond = exc->conditions; cond; cond = cond->next)
958 {
959 if (cond != exc->conditions)
960 printf(" OR ");
961 printf("%s", cond->condname);
962 }
963 printf(" THEN\n");
964 dump_stmts(exc->action);
965 }
966 }
967
968 dump_ind();
969 printf(" END -- %s\n", name);
970}
971
972static void
974{
975 dump_ind();
976 printf("ASSIGN var %d := ", stmt->varno);
977 dump_expr(stmt->expr);
978 printf("\n");
979}
980
981static void
983{
984 ListCell *l;
985
986 dump_ind();
987 printf("IF ");
988 dump_expr(stmt->cond);
989 printf(" THEN\n");
990 dump_stmts(stmt->then_body);
991 foreach(l, stmt->elsif_list)
992 {
994
995 dump_ind();
996 printf(" ELSIF ");
997 dump_expr(elif->cond);
998 printf(" THEN\n");
999 dump_stmts(elif->stmts);
1000 }
1001 if (stmt->else_body != NIL)
1002 {
1003 dump_ind();
1004 printf(" ELSE\n");
1005 dump_stmts(stmt->else_body);
1006 }
1007 dump_ind();
1008 printf(" ENDIF\n");
1009}
1010
1011static void
1013{
1014 ListCell *l;
1015
1016 dump_ind();
1017 printf("CASE %d ", stmt->t_varno);
1018 if (stmt->t_expr)
1019 dump_expr(stmt->t_expr);
1020 printf("\n");
1021 dump_indent += 6;
1022 foreach(l, stmt->case_when_list)
1023 {
1025
1026 dump_ind();
1027 printf("WHEN ");
1028 dump_expr(cwt->expr);
1029 printf("\n");
1030 dump_ind();
1031 printf("THEN\n");
1032 dump_indent += 2;
1033 dump_stmts(cwt->stmts);
1034 dump_indent -= 2;
1035 }
1036 if (stmt->have_else)
1037 {
1038 dump_ind();
1039 printf("ELSE\n");
1040 dump_indent += 2;
1041 dump_stmts(stmt->else_stmts);
1042 dump_indent -= 2;
1043 }
1044 dump_indent -= 6;
1045 dump_ind();
1046 printf(" ENDCASE\n");
1047}
1048
1049static void
1051{
1052 dump_ind();
1053 printf("LOOP\n");
1054
1055 dump_stmts(stmt->body);
1056
1057 dump_ind();
1058 printf(" ENDLOOP\n");
1059}
1060
1061static void
1063{
1064 dump_ind();
1065 printf("WHILE ");
1066 dump_expr(stmt->cond);
1067 printf("\n");
1068
1069 dump_stmts(stmt->body);
1070
1071 dump_ind();
1072 printf(" ENDWHILE\n");
1073}
1074
1075static void
1077{
1078 dump_ind();
1079 printf("FORI %s %s\n", stmt->var->refname, (stmt->reverse) ? "REVERSE" : "NORMAL");
1080
1081 dump_indent += 2;
1082 dump_ind();
1083 printf(" lower = ");
1084 dump_expr(stmt->lower);
1085 printf("\n");
1086 dump_ind();
1087 printf(" upper = ");
1088 dump_expr(stmt->upper);
1089 printf("\n");
1090 if (stmt->step)
1091 {
1092 dump_ind();
1093 printf(" step = ");
1094 dump_expr(stmt->step);
1095 printf("\n");
1096 }
1097 dump_indent -= 2;
1098
1099 dump_stmts(stmt->body);
1100
1101 dump_ind();
1102 printf(" ENDFORI\n");
1103}
1104
1105static void
1107{
1108 dump_ind();
1109 printf("FORS %s ", stmt->var->refname);
1110 dump_expr(stmt->query);
1111 printf("\n");
1112
1113 dump_stmts(stmt->body);
1114
1115 dump_ind();
1116 printf(" ENDFORS\n");
1117}
1118
1119static void
1121{
1122 dump_ind();
1123 printf("FORC %s ", stmt->var->refname);
1124 printf("curvar=%d\n", stmt->curvar);
1125
1126 dump_indent += 2;
1127 if (stmt->argquery != NULL)
1128 {
1129 dump_ind();
1130 printf(" arguments = ");
1131 dump_expr(stmt->argquery);
1132 printf("\n");
1133 }
1134 dump_indent -= 2;
1135
1136 dump_stmts(stmt->body);
1137
1138 dump_ind();
1139 printf(" ENDFORC\n");
1140}
1141
1142static void
1144{
1145 dump_ind();
1146 printf("FOREACHA var %d ", stmt->varno);
1147 if (stmt->slice != 0)
1148 printf("SLICE %d ", stmt->slice);
1149 printf("IN ");
1150 dump_expr(stmt->expr);
1151 printf("\n");
1152
1153 dump_stmts(stmt->body);
1154
1155 dump_ind();
1156 printf(" ENDFOREACHA");
1157}
1158
1159static void
1161{
1162 dump_ind();
1163 printf("OPEN curvar=%d\n", stmt->curvar);
1164
1165 dump_indent += 2;
1166 if (stmt->argquery != NULL)
1167 {
1168 dump_ind();
1169 printf(" arguments = '");
1170 dump_expr(stmt->argquery);
1171 printf("'\n");
1172 }
1173 if (stmt->query != NULL)
1174 {
1175 dump_ind();
1176 printf(" query = '");
1177 dump_expr(stmt->query);
1178 printf("'\n");
1179 }
1180 if (stmt->dynquery != NULL)
1181 {
1182 dump_ind();
1183 printf(" execute = '");
1184 dump_expr(stmt->dynquery);
1185 printf("'\n");
1186
1187 if (stmt->params != NIL)
1188 {
1189 ListCell *lc;
1190 int i;
1191
1192 dump_indent += 2;
1193 dump_ind();
1194 printf(" USING\n");
1195 dump_indent += 2;
1196 i = 1;
1197 foreach(lc, stmt->params)
1198 {
1199 dump_ind();
1200 printf(" parameter $%d: ", i++);
1202 printf("\n");
1203 }
1204 dump_indent -= 4;
1205 }
1206 }
1207 dump_indent -= 2;
1208}
1209
1210static void
1212{
1213 dump_ind();
1214
1215 if (!stmt->is_move)
1216 {
1217 printf("FETCH curvar=%d\n", stmt->curvar);
1219
1220 dump_indent += 2;
1221 if (stmt->target != NULL)
1222 {
1223 dump_ind();
1224 printf(" target = %d %s\n",
1225 stmt->target->dno, stmt->target->refname);
1226 }
1227 dump_indent -= 2;
1228 }
1229 else
1230 {
1231 printf("MOVE curvar=%d\n", stmt->curvar);
1233 }
1234}
1235
1236static void
1238{
1239 dump_indent += 2;
1240 dump_ind();
1241 switch (stmt->direction)
1242 {
1243 case FETCH_FORWARD:
1244 printf(" FORWARD ");
1245 break;
1246 case FETCH_BACKWARD:
1247 printf(" BACKWARD ");
1248 break;
1249 case FETCH_ABSOLUTE:
1250 printf(" ABSOLUTE ");
1251 break;
1252 case FETCH_RELATIVE:
1253 printf(" RELATIVE ");
1254 break;
1255 default:
1256 printf("??? unknown cursor direction %d", stmt->direction);
1257 }
1258
1259 if (stmt->expr)
1260 {
1261 dump_expr(stmt->expr);
1262 printf("\n");
1263 }
1264 else
1265 printf("%ld\n", stmt->how_many);
1266
1267 dump_indent -= 2;
1268}
1269
1270static void
1272{
1273 dump_ind();
1274 printf("CLOSE curvar=%d\n", stmt->curvar);
1275}
1276
1277static void
1279{
1280 dump_ind();
1281 printf("PERFORM expr = ");
1282 dump_expr(stmt->expr);
1283 printf("\n");
1284}
1285
1286static void
1288{
1289 dump_ind();
1290 printf("%s expr = ", stmt->is_call ? "CALL" : "DO");
1291 dump_expr(stmt->expr);
1292 printf("\n");
1293}
1294
1295static void
1297{
1298 dump_ind();
1299 if (stmt->chain)
1300 printf("COMMIT AND CHAIN\n");
1301 else
1302 printf("COMMIT\n");
1303}
1304
1305static void
1307{
1308 dump_ind();
1309 if (stmt->chain)
1310 printf("ROLLBACK AND CHAIN\n");
1311 else
1312 printf("ROLLBACK\n");
1313}
1314
1315static void
1317{
1318 dump_ind();
1319 printf("%s", stmt->is_exit ? "EXIT" : "CONTINUE");
1320 if (stmt->label != NULL)
1321 printf(" label='%s'", stmt->label);
1322 if (stmt->cond != NULL)
1323 {
1324 printf(" WHEN ");
1325 dump_expr(stmt->cond);
1326 }
1327 printf("\n");
1328}
1329
1330static void
1332{
1333 dump_ind();
1334 printf("RETURN ");
1335 if (stmt->retvarno >= 0)
1336 printf("variable %d", stmt->retvarno);
1337 else if (stmt->expr != NULL)
1338 dump_expr(stmt->expr);
1339 else
1340 printf("NULL");
1341 printf("\n");
1342}
1343
1344static void
1346{
1347 dump_ind();
1348 printf("RETURN NEXT ");
1349 if (stmt->retvarno >= 0)
1350 printf("variable %d", stmt->retvarno);
1351 else if (stmt->expr != NULL)
1352 dump_expr(stmt->expr);
1353 else
1354 printf("NULL");
1355 printf("\n");
1356}
1357
1358static void
1360{
1361 dump_ind();
1362 if (stmt->query)
1363 {
1364 printf("RETURN QUERY ");
1365 dump_expr(stmt->query);
1366 printf("\n");
1367 }
1368 else
1369 {
1370 printf("RETURN QUERY EXECUTE ");
1371 dump_expr(stmt->dynquery);
1372 printf("\n");
1373 if (stmt->params != NIL)
1374 {
1375 ListCell *lc;
1376 int i;
1377
1378 dump_indent += 2;
1379 dump_ind();
1380 printf(" USING\n");
1381 dump_indent += 2;
1382 i = 1;
1383 foreach(lc, stmt->params)
1384 {
1385 dump_ind();
1386 printf(" parameter $%d: ", i++);
1388 printf("\n");
1389 }
1390 dump_indent -= 4;
1391 }
1392 }
1393}
1394
1395static void
1397{
1398 ListCell *lc;
1399 int i = 0;
1400
1401 dump_ind();
1402 printf("RAISE level=%d", stmt->elog_level);
1403 if (stmt->condname)
1404 printf(" condname='%s'", stmt->condname);
1405 if (stmt->message)
1406 printf(" message='%s'", stmt->message);
1407 printf("\n");
1408 dump_indent += 2;
1409 foreach(lc, stmt->params)
1410 {
1411 dump_ind();
1412 printf(" parameter %d: ", i++);
1414 printf("\n");
1415 }
1416 if (stmt->options)
1417 {
1418 dump_ind();
1419 printf(" USING\n");
1420 dump_indent += 2;
1421 foreach(lc, stmt->options)
1422 {
1424
1425 dump_ind();
1426 switch (opt->opt_type)
1427 {
1429 printf(" ERRCODE = ");
1430 break;
1432 printf(" MESSAGE = ");
1433 break;
1435 printf(" DETAIL = ");
1436 break;
1438 printf(" HINT = ");
1439 break;
1441 printf(" COLUMN = ");
1442 break;
1444 printf(" CONSTRAINT = ");
1445 break;
1447 printf(" DATATYPE = ");
1448 break;
1450 printf(" TABLE = ");
1451 break;
1453 printf(" SCHEMA = ");
1454 break;
1455 }
1456 dump_expr(opt->expr);
1457 printf("\n");
1458 }
1459 dump_indent -= 2;
1460 }
1461 dump_indent -= 2;
1462}
1463
1464static void
1466{
1467 dump_ind();
1468 printf("ASSERT ");
1469 dump_expr(stmt->cond);
1470 printf("\n");
1471
1472 dump_indent += 2;
1473 if (stmt->message != NULL)
1474 {
1475 dump_ind();
1476 printf(" MESSAGE = ");
1477 dump_expr(stmt->message);
1478 printf("\n");
1479 }
1480 dump_indent -= 2;
1481}
1482
1483static void
1485{
1486 dump_ind();
1487 printf("EXECSQL ");
1488 dump_expr(stmt->sqlstmt);
1489 printf("\n");
1490
1491 dump_indent += 2;
1492 if (stmt->target != NULL)
1493 {
1494 dump_ind();
1495 printf(" INTO%s target = %d %s\n",
1496 stmt->strict ? " STRICT" : "",
1497 stmt->target->dno, stmt->target->refname);
1498 }
1499 dump_indent -= 2;
1500}
1501
1502static void
1504{
1505 dump_ind();
1506 printf("EXECUTE ");
1507 dump_expr(stmt->query);
1508 printf("\n");
1509
1510 dump_indent += 2;
1511 if (stmt->target != NULL)
1512 {
1513 dump_ind();
1514 printf(" INTO%s target = %d %s\n",
1515 stmt->strict ? " STRICT" : "",
1516 stmt->target->dno, stmt->target->refname);
1517 }
1518 if (stmt->params != NIL)
1519 {
1520 ListCell *lc;
1521 int i;
1522
1523 dump_ind();
1524 printf(" USING\n");
1525 dump_indent += 2;
1526 i = 1;
1527 foreach(lc, stmt->params)
1528 {
1529 dump_ind();
1530 printf(" parameter %d: ", i++);
1532 printf("\n");
1533 }
1534 dump_indent -= 2;
1535 }
1536 dump_indent -= 2;
1537}
1538
1539static void
1541{
1542 dump_ind();
1543 printf("FORS %s EXECUTE ", stmt->var->refname);
1544 dump_expr(stmt->query);
1545 printf("\n");
1546 if (stmt->params != NIL)
1547 {
1548 ListCell *lc;
1549 int i;
1550
1551 dump_indent += 2;
1552 dump_ind();
1553 printf(" USING\n");
1554 dump_indent += 2;
1555 i = 1;
1556 foreach(lc, stmt->params)
1557 {
1558 dump_ind();
1559 printf(" parameter $%d: ", i++);
1561 printf("\n");
1562 }
1563 dump_indent -= 4;
1564 }
1565 dump_stmts(stmt->body);
1566 dump_ind();
1567 printf(" ENDFORS\n");
1568}
1569
1570static void
1572{
1573 ListCell *lc;
1574
1575 dump_ind();
1576 printf("GET %s DIAGNOSTICS ", stmt->is_stacked ? "STACKED" : "CURRENT");
1577 foreach(lc, stmt->diag_items)
1578 {
1580
1581 if (lc != list_head(stmt->diag_items))
1582 printf(", ");
1583
1584 printf("{var %d} = %s", diag_item->target,
1586 }
1587 printf("\n");
1588}
1589
1590static void
1592{
1593 printf("'%s'", expr->query);
1594 if (expr->target_param >= 0)
1595 printf(" target %d%s", expr->target_param,
1596 expr->target_is_local ? " (local)" : "");
1597}
1598
1599void
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:
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}
void bms_free(Bitmapset *a)
Definition bitmapset.c:239
bool bms_is_member(int x, const Bitmapset *a)
Definition bitmapset.c:510
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition bitmapset.c:814
Bitmapset * bms_copy(const Bitmapset *a)
Definition bitmapset.c:122
#define Assert(condition)
Definition c.h:873
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define stmt
#define ifstmt
int j
Definition isn.c:78
int i
Definition isn.c:77
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
@ FETCH_RELATIVE
@ FETCH_ABSOLUTE
@ FETCH_FORWARD
@ FETCH_BACKWARD
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
#define foreach_ptr(type, var, lst)
Definition pg_list.h:469
static ListCell * list_head(const List *l)
Definition pg_list.h:128
static void dump_dynexecute(PLpgSQL_stmt_dynexecute *stmt)
Definition pl_funcs.c:1504
static void dump_return_next(PLpgSQL_stmt_return_next *stmt)
Definition pl_funcs.c:1346
static void dump_close(PLpgSQL_stmt_close *stmt)
Definition pl_funcs.c:1272
static void dump_perform(PLpgSQL_stmt_perform *stmt)
Definition pl_funcs.c:1279
static void dump_if(PLpgSQL_stmt_if *stmt)
Definition pl_funcs.c:983
static void dump_fetch(PLpgSQL_stmt_fetch *stmt)
Definition pl_funcs.c:1212
static void dump_execsql(PLpgSQL_stmt_execsql *stmt)
Definition pl_funcs.c:1485
static int dump_indent
Definition pl_funcs.c:784
static void dump_case(PLpgSQL_stmt_case *stmt)
Definition pl_funcs.c:1013
#define E_LIST_WALK(lst)
static void dump_open(PLpgSQL_stmt_open *stmt)
Definition pl_funcs.c:1161
static void dump_assign(PLpgSQL_stmt_assign *stmt)
Definition pl_funcs.c:974
static void dump_stmts(List *stmts)
Definition pl_funcs.c:922
void plpgsql_delete_callback(CachedFunction *cfunc)
Definition pl_funcs.c:772
static void dump_cursor_direction(PLpgSQL_stmt_fetch *stmt)
Definition pl_funcs.c:1238
void plpgsql_dumptree(PLpgSQL_function *func)
Definition pl_funcs.c:1601
static void mark_stmt(PLpgSQL_stmt *stmt, Bitmapset *local_dnos)
Definition pl_funcs.c:623
#define S_LIST_WALK(lst)
#define E_WALK(ex)
static void dump_loop(PLpgSQL_stmt_loop *stmt)
Definition pl_funcs.c:1051
static void dump_raise(PLpgSQL_stmt_raise *stmt)
Definition pl_funcs.c:1397
static void dump_rollback(PLpgSQL_stmt_rollback *stmt)
Definition pl_funcs.c:1307
void plpgsql_free_function_memory(PLpgSQL_function *func)
Definition pl_funcs.c:716
static void dump_while(PLpgSQL_stmt_while *stmt)
Definition pl_funcs.c:1063
static void dump_expr(PLpgSQL_expr *expr)
Definition pl_funcs.c:1592
void plpgsql_mark_local_assignment_targets(PLpgSQL_function *func)
Definition pl_funcs.c:673
static void dump_stmt(PLpgSQL_stmt *stmt)
Definition pl_funcs.c:829
static void dump_block(PLpgSQL_stmt_block *block)
Definition pl_funcs.c:933
static void dump_getdiag(PLpgSQL_stmt_getdiag *stmt)
Definition pl_funcs.c:1572
static void dump_exit(PLpgSQL_stmt_exit *stmt)
Definition pl_funcs.c:1317
static void free_stmt(PLpgSQL_stmt *stmt, void *context)
Definition pl_funcs.c:698
static void dump_call(PLpgSQL_stmt_call *stmt)
Definition pl_funcs.c:1288
static void dump_forc(PLpgSQL_stmt_forc *stmt)
Definition pl_funcs.c:1121
static void dump_ind(void)
Definition pl_funcs.c:820
static void dump_commit(PLpgSQL_stmt_commit *stmt)
Definition pl_funcs.c:1297
static void dump_return(PLpgSQL_stmt_return *stmt)
Definition pl_funcs.c:1332
static void free_expr(PLpgSQL_expr *expr, void *context)
Definition pl_funcs.c:706
#define plpgsql_statement_tree_walker(s, sw, ew, c)
Definition pl_funcs.c:359
static void dump_foreach_a(PLpgSQL_stmt_foreach_a *stmt)
Definition pl_funcs.c:1144
static void dump_return_query(PLpgSQL_stmt_return_query *stmt)
Definition pl_funcs.c:1360
static void dump_assert(PLpgSQL_stmt_assert *stmt)
Definition pl_funcs.c:1466
static void dump_dynfors(PLpgSQL_stmt_dynfors *stmt)
Definition pl_funcs.c:1541
const char * plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind)
Definition pl_funcs.c:300
static void dump_fori(PLpgSQL_stmt_fori *stmt)
Definition pl_funcs.c:1077
static void dump_fors(PLpgSQL_stmt_fors *stmt)
Definition pl_funcs.c:1107
static void mark_expr(PLpgSQL_expr *expr, Bitmapset *local_dnos)
Definition pl_funcs.c:662
@ PLPGSQL_STMT_DYNFORS
Definition plpgsql.h:123
@ PLPGSQL_STMT_FORI
Definition plpgsql.h:111
@ PLPGSQL_STMT_FETCH
Definition plpgsql.h:126
@ PLPGSQL_STMT_CASE
Definition plpgsql.h:108
@ PLPGSQL_STMT_OPEN
Definition plpgsql.h:125
@ PLPGSQL_STMT_ROLLBACK
Definition plpgsql.h:131
@ PLPGSQL_STMT_COMMIT
Definition plpgsql.h:130
@ PLPGSQL_STMT_RETURN_QUERY
Definition plpgsql.h:118
@ PLPGSQL_STMT_RETURN
Definition plpgsql.h:116
@ PLPGSQL_STMT_CLOSE
Definition plpgsql.h:127
@ PLPGSQL_STMT_WHILE
Definition plpgsql.h:110
@ PLPGSQL_STMT_BLOCK
Definition plpgsql.h:105
@ PLPGSQL_STMT_FORS
Definition plpgsql.h:112
@ PLPGSQL_STMT_FORC
Definition plpgsql.h:113
@ PLPGSQL_STMT_IF
Definition plpgsql.h:107
@ PLPGSQL_STMT_PERFORM
Definition plpgsql.h:128
@ PLPGSQL_STMT_LOOP
Definition plpgsql.h:109
@ PLPGSQL_STMT_ASSERT
Definition plpgsql.h:120
@ PLPGSQL_STMT_FOREACH_A
Definition plpgsql.h:114
@ PLPGSQL_STMT_GETDIAG
Definition plpgsql.h:124
@ PLPGSQL_STMT_RETURN_NEXT
Definition plpgsql.h:117
@ PLPGSQL_STMT_ASSIGN
Definition plpgsql.h:106
@ PLPGSQL_STMT_EXIT
Definition plpgsql.h:115
@ PLPGSQL_STMT_EXECSQL
Definition plpgsql.h:121
@ PLPGSQL_STMT_RAISE
Definition plpgsql.h:119
@ PLPGSQL_STMT_CALL
Definition plpgsql.h:129
@ PLPGSQL_STMT_DYNEXECUTE
Definition plpgsql.h:122
@ PLPGSQL_RAISEOPTION_COLUMN
Definition plpgsql.h:174
@ PLPGSQL_RAISEOPTION_TABLE
Definition plpgsql.h:177
@ PLPGSQL_RAISEOPTION_SCHEMA
Definition plpgsql.h:178
@ PLPGSQL_RAISEOPTION_CONSTRAINT
Definition plpgsql.h:175
@ PLPGSQL_RAISEOPTION_DETAIL
Definition plpgsql.h:172
@ PLPGSQL_RAISEOPTION_MESSAGE
Definition plpgsql.h:171
@ PLPGSQL_RAISEOPTION_HINT
Definition plpgsql.h:173
@ PLPGSQL_RAISEOPTION_ERRCODE
Definition plpgsql.h:170
@ PLPGSQL_RAISEOPTION_DATATYPE
Definition plpgsql.h:176
@ PLPGSQL_PROMISE_NONE
Definition plpgsql.h:76
@ PLPGSQL_DTYPE_ROW
Definition plpgsql.h:65
@ PLPGSQL_DTYPE_PROMISE
Definition plpgsql.h:68
@ PLPGSQL_DTYPE_RECFIELD
Definition plpgsql.h:67
@ PLPGSQL_DTYPE_REC
Definition plpgsql.h:66
@ PLPGSQL_DTYPE_VAR
Definition plpgsql.h:64
#define printf(...)
Definition port.h:266
e
int SPI_freeplan(SPIPlanPtr plan)
Definition spi.c:1025
uint64 use_count
Definition funccache.h:117
Definition pg_list.h:54
struct PLpgSQL_condition * next
Definition plpgsql.h:496
PLpgSQL_datum_type dtype
Definition plpgsql.h:300
PLpgSQL_condition * conditions
Definition plpgsql.h:518
int target_param
Definition plpgsql.h:244
SPIPlanPtr plan
Definition plpgsql.h:251
bool target_is_local
Definition plpgsql.h:245
char * query
Definition plpgsql.h:232
CachedFunction cfunc
Definition plpgsql.h:960
MemoryContext fn_cxt
Definition plpgsql.h:966
int fn_argvarnos[FUNC_MAX_ARGS]
Definition plpgsql.h:978
PLpgSQL_stmt_block * action
Definition plpgsql.h:998
PLpgSQL_datum ** datums
Definition plpgsql.h:994
char * fn_signature
Definition plpgsql.h:962
PLpgSQL_raise_option_type opt_type
Definition plpgsql.h:898
PLpgSQL_expr * expr
Definition plpgsql.h:899
PLpgSQL_expr * default_val
Definition plpgsql.h:420
PLpgSQL_datum_type dtype
Definition plpgsql.h:445
int * varnos
Definition plpgsql.h:406
char * refname
Definition plpgsql.h:390
char ** fieldnames
Definition plpgsql.h:405
int nfields
Definition plpgsql.h:404
PLpgSQL_exception_block * exceptions
Definition plpgsql.h:534
PLpgSQL_expr * expr
Definition plpgsql.h:557
char * typname
Definition plpgsql.h:212
int32 atttypmod
Definition plpgsql.h:220
PLpgSQL_promise_type promise
Definition plpgsql.h:365
int cursor_explicit_argrow
Definition plpgsql.h:351
bool notnull
Definition plpgsql.h:339
bool isconst
Definition plpgsql.h:338
PLpgSQL_expr * cursor_explicit_expr
Definition plpgsql.h:350
PLpgSQL_type * datatype
Definition plpgsql.h:343
PLpgSQL_expr * default_val
Definition plpgsql.h:340
char * refname
Definition plpgsql.h:336
const char * name

◆ S_LIST_WALK

#define S_LIST_WALK (   lst)    foreach_ptr(PLpgSQL_stmt, st, lst) S_WALK(st)

◆ S_WALK

#define S_WALK (   st)    stmt_callback(st, context)

Typedef Documentation

◆ plpgsql_expr_walker_callback

typedef void(* plpgsql_expr_walker_callback) (PLpgSQL_expr *expr, void *context)

Definition at line 351 of file pl_funcs.c.

◆ plpgsql_stmt_walker_callback

typedef void(* plpgsql_stmt_walker_callback) (PLpgSQL_stmt *stmt, void *context)

Definition at line 349 of file pl_funcs.c.

Function Documentation

◆ dump_assert()

static void dump_assert ( PLpgSQL_stmt_assert stmt)
static

Definition at line 1466 of file pl_funcs.c.

1467{
1468 dump_ind();
1469 printf("ASSERT ");
1470 dump_expr(stmt->cond);
1471 printf("\n");
1472
1473 dump_indent += 2;
1474 if (stmt->message != NULL)
1475 {
1476 dump_ind();
1477 printf(" MESSAGE = ");
1478 dump_expr(stmt->message);
1479 printf("\n");
1480 }
1481 dump_indent -= 2;
1482}

References dump_expr(), dump_ind(), dump_indent, fb(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_assign()

static void dump_assign ( PLpgSQL_stmt_assign stmt)
static

Definition at line 974 of file pl_funcs.c.

975{
976 dump_ind();
977 printf("ASSIGN var %d := ", stmt->varno);
978 dump_expr(stmt->expr);
979 printf("\n");
980}

References dump_expr(), dump_ind(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_block()

static void dump_block ( PLpgSQL_stmt_block block)
static

Definition at line 933 of file pl_funcs.c.

934{
935 char *name;
936
937 if (block->label == NULL)
938 name = "*unnamed*";
939 else
940 name = block->label;
941
942 dump_ind();
943 printf("BLOCK <<%s>>\n", name);
944
945 dump_stmts(block->body);
946
947 if (block->exceptions)
948 {
949 ListCell *e;
950
951 foreach(e, block->exceptions->exc_list)
952 {
954 PLpgSQL_condition *cond;
955
956 dump_ind();
957 printf(" EXCEPTION WHEN ");
958 for (cond = exc->conditions; cond; cond = cond->next)
959 {
960 if (cond != exc->conditions)
961 printf(" OR ");
962 printf("%s", cond->condname);
963 }
964 printf(" THEN\n");
965 dump_stmts(exc->action);
966 }
967 }
968
969 dump_ind();
970 printf(" END -- %s\n", name);
971}

References PLpgSQL_exception::action, PLpgSQL_stmt_block::body, PLpgSQL_exception::conditions, PLpgSQL_condition::condname, dump_ind(), dump_stmts(), PLpgSQL_exception_block::exc_list, PLpgSQL_stmt_block::exceptions, fb(), PLpgSQL_stmt_block::label, lfirst, name, PLpgSQL_condition::next, and printf.

Referenced by dump_stmt(), and plpgsql_dumptree().

◆ dump_call()

static void dump_call ( PLpgSQL_stmt_call stmt)
static

Definition at line 1288 of file pl_funcs.c.

1289{
1290 dump_ind();
1291 printf("%s expr = ", stmt->is_call ? "CALL" : "DO");
1292 dump_expr(stmt->expr);
1293 printf("\n");
1294}

References dump_expr(), dump_ind(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_case()

static void dump_case ( PLpgSQL_stmt_case stmt)
static

Definition at line 1013 of file pl_funcs.c.

1014{
1015 ListCell *l;
1016
1017 dump_ind();
1018 printf("CASE %d ", stmt->t_varno);
1019 if (stmt->t_expr)
1020 dump_expr(stmt->t_expr);
1021 printf("\n");
1022 dump_indent += 6;
1023 foreach(l, stmt->case_when_list)
1024 {
1026
1027 dump_ind();
1028 printf("WHEN ");
1029 dump_expr(cwt->expr);
1030 printf("\n");
1031 dump_ind();
1032 printf("THEN\n");
1033 dump_indent += 2;
1034 dump_stmts(cwt->stmts);
1035 dump_indent -= 2;
1036 }
1037 if (stmt->have_else)
1038 {
1039 dump_ind();
1040 printf("ELSE\n");
1041 dump_indent += 2;
1042 dump_stmts(stmt->else_stmts);
1043 dump_indent -= 2;
1044 }
1045 dump_indent -= 6;
1046 dump_ind();
1047 printf(" ENDCASE\n");
1048}

References dump_expr(), dump_ind(), dump_indent, dump_stmts(), fb(), lfirst, printf, and stmt.

Referenced by dump_stmt().

◆ dump_close()

static void dump_close ( PLpgSQL_stmt_close stmt)
static

Definition at line 1272 of file pl_funcs.c.

1273{
1274 dump_ind();
1275 printf("CLOSE curvar=%d\n", stmt->curvar);
1276}

References dump_ind(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_commit()

static void dump_commit ( PLpgSQL_stmt_commit stmt)
static

Definition at line 1297 of file pl_funcs.c.

1298{
1299 dump_ind();
1300 if (stmt->chain)
1301 printf("COMMIT AND CHAIN\n");
1302 else
1303 printf("COMMIT\n");
1304}

References dump_ind(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_cursor_direction()

static void dump_cursor_direction ( PLpgSQL_stmt_fetch stmt)
static

Definition at line 1238 of file pl_funcs.c.

1239{
1240 dump_indent += 2;
1241 dump_ind();
1242 switch (stmt->direction)
1243 {
1244 case FETCH_FORWARD:
1245 printf(" FORWARD ");
1246 break;
1247 case FETCH_BACKWARD:
1248 printf(" BACKWARD ");
1249 break;
1250 case FETCH_ABSOLUTE:
1251 printf(" ABSOLUTE ");
1252 break;
1253 case FETCH_RELATIVE:
1254 printf(" RELATIVE ");
1255 break;
1256 default:
1257 printf("??? unknown cursor direction %d", stmt->direction);
1258 }
1259
1260 if (stmt->expr)
1261 {
1262 dump_expr(stmt->expr);
1263 printf("\n");
1264 }
1265 else
1266 printf("%ld\n", stmt->how_many);
1267
1268 dump_indent -= 2;
1269}

References dump_expr(), dump_ind(), dump_indent, FETCH_ABSOLUTE, FETCH_BACKWARD, FETCH_FORWARD, FETCH_RELATIVE, printf, and stmt.

Referenced by dump_fetch().

◆ dump_dynexecute()

static void dump_dynexecute ( PLpgSQL_stmt_dynexecute stmt)
static

Definition at line 1504 of file pl_funcs.c.

1505{
1506 dump_ind();
1507 printf("EXECUTE ");
1508 dump_expr(stmt->query);
1509 printf("\n");
1510
1511 dump_indent += 2;
1512 if (stmt->target != NULL)
1513 {
1514 dump_ind();
1515 printf(" INTO%s target = %d %s\n",
1516 stmt->strict ? " STRICT" : "",
1517 stmt->target->dno, stmt->target->refname);
1518 }
1519 if (stmt->params != NIL)
1520 {
1521 ListCell *lc;
1522 int i;
1523
1524 dump_ind();
1525 printf(" USING\n");
1526 dump_indent += 2;
1527 i = 1;
1528 foreach(lc, stmt->params)
1529 {
1530 dump_ind();
1531 printf(" parameter %d: ", i++);
1533 printf("\n");
1534 }
1535 dump_indent -= 2;
1536 }
1537 dump_indent -= 2;
1538}

References dump_expr(), dump_ind(), dump_indent, fb(), i, lfirst, NIL, printf, and stmt.

Referenced by dump_stmt().

◆ dump_dynfors()

static void dump_dynfors ( PLpgSQL_stmt_dynfors stmt)
static

Definition at line 1541 of file pl_funcs.c.

1542{
1543 dump_ind();
1544 printf("FORS %s EXECUTE ", stmt->var->refname);
1545 dump_expr(stmt->query);
1546 printf("\n");
1547 if (stmt->params != NIL)
1548 {
1549 ListCell *lc;
1550 int i;
1551
1552 dump_indent += 2;
1553 dump_ind();
1554 printf(" USING\n");
1555 dump_indent += 2;
1556 i = 1;
1557 foreach(lc, stmt->params)
1558 {
1559 dump_ind();
1560 printf(" parameter $%d: ", i++);
1562 printf("\n");
1563 }
1564 dump_indent -= 4;
1565 }
1566 dump_stmts(stmt->body);
1567 dump_ind();
1568 printf(" ENDFORS\n");
1569}

References dump_expr(), dump_ind(), dump_indent, dump_stmts(), fb(), i, lfirst, NIL, printf, and stmt.

Referenced by dump_stmt().

◆ dump_execsql()

static void dump_execsql ( PLpgSQL_stmt_execsql stmt)
static

Definition at line 1485 of file pl_funcs.c.

1486{
1487 dump_ind();
1488 printf("EXECSQL ");
1489 dump_expr(stmt->sqlstmt);
1490 printf("\n");
1491
1492 dump_indent += 2;
1493 if (stmt->target != NULL)
1494 {
1495 dump_ind();
1496 printf(" INTO%s target = %d %s\n",
1497 stmt->strict ? " STRICT" : "",
1498 stmt->target->dno, stmt->target->refname);
1499 }
1500 dump_indent -= 2;
1501}

References dump_expr(), dump_ind(), dump_indent, fb(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_exit()

static void dump_exit ( PLpgSQL_stmt_exit stmt)
static

Definition at line 1317 of file pl_funcs.c.

1318{
1319 dump_ind();
1320 printf("%s", stmt->is_exit ? "EXIT" : "CONTINUE");
1321 if (stmt->label != NULL)
1322 printf(" label='%s'", stmt->label);
1323 if (stmt->cond != NULL)
1324 {
1325 printf(" WHEN ");
1326 dump_expr(stmt->cond);
1327 }
1328 printf("\n");
1329}

References dump_expr(), dump_ind(), fb(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_expr()

◆ dump_fetch()

static void dump_fetch ( PLpgSQL_stmt_fetch stmt)
static

Definition at line 1212 of file pl_funcs.c.

1213{
1214 dump_ind();
1215
1216 if (!stmt->is_move)
1217 {
1218 printf("FETCH curvar=%d\n", stmt->curvar);
1220
1221 dump_indent += 2;
1222 if (stmt->target != NULL)
1223 {
1224 dump_ind();
1225 printf(" target = %d %s\n",
1226 stmt->target->dno, stmt->target->refname);
1227 }
1228 dump_indent -= 2;
1229 }
1230 else
1231 {
1232 printf("MOVE curvar=%d\n", stmt->curvar);
1234 }
1235}

References dump_cursor_direction(), dump_ind(), dump_indent, fb(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_forc()

static void dump_forc ( PLpgSQL_stmt_forc stmt)
static

Definition at line 1121 of file pl_funcs.c.

1122{
1123 dump_ind();
1124 printf("FORC %s ", stmt->var->refname);
1125 printf("curvar=%d\n", stmt->curvar);
1126
1127 dump_indent += 2;
1128 if (stmt->argquery != NULL)
1129 {
1130 dump_ind();
1131 printf(" arguments = ");
1132 dump_expr(stmt->argquery);
1133 printf("\n");
1134 }
1135 dump_indent -= 2;
1136
1137 dump_stmts(stmt->body);
1138
1139 dump_ind();
1140 printf(" ENDFORC\n");
1141}

References dump_expr(), dump_ind(), dump_indent, dump_stmts(), fb(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_foreach_a()

static void dump_foreach_a ( PLpgSQL_stmt_foreach_a stmt)
static

Definition at line 1144 of file pl_funcs.c.

1145{
1146 dump_ind();
1147 printf("FOREACHA var %d ", stmt->varno);
1148 if (stmt->slice != 0)
1149 printf("SLICE %d ", stmt->slice);
1150 printf("IN ");
1151 dump_expr(stmt->expr);
1152 printf("\n");
1153
1154 dump_stmts(stmt->body);
1155
1156 dump_ind();
1157 printf(" ENDFOREACHA");
1158}

References dump_expr(), dump_ind(), dump_stmts(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_fori()

static void dump_fori ( PLpgSQL_stmt_fori stmt)
static

Definition at line 1077 of file pl_funcs.c.

1078{
1079 dump_ind();
1080 printf("FORI %s %s\n", stmt->var->refname, (stmt->reverse) ? "REVERSE" : "NORMAL");
1081
1082 dump_indent += 2;
1083 dump_ind();
1084 printf(" lower = ");
1085 dump_expr(stmt->lower);
1086 printf("\n");
1087 dump_ind();
1088 printf(" upper = ");
1089 dump_expr(stmt->upper);
1090 printf("\n");
1091 if (stmt->step)
1092 {
1093 dump_ind();
1094 printf(" step = ");
1095 dump_expr(stmt->step);
1096 printf("\n");
1097 }
1098 dump_indent -= 2;
1099
1100 dump_stmts(stmt->body);
1101
1102 dump_ind();
1103 printf(" ENDFORI\n");
1104}

References dump_expr(), dump_ind(), dump_indent, dump_stmts(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_fors()

static void dump_fors ( PLpgSQL_stmt_fors stmt)
static

Definition at line 1107 of file pl_funcs.c.

1108{
1109 dump_ind();
1110 printf("FORS %s ", stmt->var->refname);
1111 dump_expr(stmt->query);
1112 printf("\n");
1113
1114 dump_stmts(stmt->body);
1115
1116 dump_ind();
1117 printf(" ENDFORS\n");
1118}

References dump_expr(), dump_ind(), dump_stmts(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_getdiag()

static void dump_getdiag ( PLpgSQL_stmt_getdiag stmt)
static

Definition at line 1572 of file pl_funcs.c.

1573{
1574 ListCell *lc;
1575
1576 dump_ind();
1577 printf("GET %s DIAGNOSTICS ", stmt->is_stacked ? "STACKED" : "CURRENT");
1578 foreach(lc, stmt->diag_items)
1579 {
1581
1582 if (lc != list_head(stmt->diag_items))
1583 printf(", ");
1584
1585 printf("{var %d} = %s", diag_item->target,
1587 }
1588 printf("\n");
1589}

References dump_ind(), fb(), lfirst, list_head(), plpgsql_getdiag_kindname(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_if()

static void dump_if ( PLpgSQL_stmt_if stmt)
static

Definition at line 983 of file pl_funcs.c.

984{
985 ListCell *l;
986
987 dump_ind();
988 printf("IF ");
989 dump_expr(stmt->cond);
990 printf(" THEN\n");
991 dump_stmts(stmt->then_body);
992 foreach(l, stmt->elsif_list)
993 {
995
996 dump_ind();
997 printf(" ELSIF ");
998 dump_expr(elif->cond);
999 printf(" THEN\n");
1000 dump_stmts(elif->stmts);
1001 }
1002 if (stmt->else_body != NIL)
1003 {
1004 dump_ind();
1005 printf(" ELSE\n");
1006 dump_stmts(stmt->else_body);
1007 }
1008 dump_ind();
1009 printf(" ENDIF\n");
1010}

References dump_expr(), dump_ind(), dump_stmts(), fb(), lfirst, NIL, printf, and stmt.

Referenced by dump_stmt().

◆ dump_ind()

◆ dump_loop()

static void dump_loop ( PLpgSQL_stmt_loop stmt)
static

Definition at line 1051 of file pl_funcs.c.

1052{
1053 dump_ind();
1054 printf("LOOP\n");
1055
1056 dump_stmts(stmt->body);
1057
1058 dump_ind();
1059 printf(" ENDLOOP\n");
1060}

References dump_ind(), dump_stmts(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_open()

static void dump_open ( PLpgSQL_stmt_open stmt)
static

Definition at line 1161 of file pl_funcs.c.

1162{
1163 dump_ind();
1164 printf("OPEN curvar=%d\n", stmt->curvar);
1165
1166 dump_indent += 2;
1167 if (stmt->argquery != NULL)
1168 {
1169 dump_ind();
1170 printf(" arguments = '");
1171 dump_expr(stmt->argquery);
1172 printf("'\n");
1173 }
1174 if (stmt->query != NULL)
1175 {
1176 dump_ind();
1177 printf(" query = '");
1178 dump_expr(stmt->query);
1179 printf("'\n");
1180 }
1181 if (stmt->dynquery != NULL)
1182 {
1183 dump_ind();
1184 printf(" execute = '");
1185 dump_expr(stmt->dynquery);
1186 printf("'\n");
1187
1188 if (stmt->params != NIL)
1189 {
1190 ListCell *lc;
1191 int i;
1192
1193 dump_indent += 2;
1194 dump_ind();
1195 printf(" USING\n");
1196 dump_indent += 2;
1197 i = 1;
1198 foreach(lc, stmt->params)
1199 {
1200 dump_ind();
1201 printf(" parameter $%d: ", i++);
1203 printf("\n");
1204 }
1205 dump_indent -= 4;
1206 }
1207 }
1208 dump_indent -= 2;
1209}

References dump_expr(), dump_ind(), dump_indent, fb(), i, lfirst, NIL, printf, and stmt.

Referenced by dump_stmt().

◆ dump_perform()

static void dump_perform ( PLpgSQL_stmt_perform stmt)
static

Definition at line 1279 of file pl_funcs.c.

1280{
1281 dump_ind();
1282 printf("PERFORM expr = ");
1283 dump_expr(stmt->expr);
1284 printf("\n");
1285}

References dump_expr(), dump_ind(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_raise()

static void dump_raise ( PLpgSQL_stmt_raise stmt)
static

Definition at line 1397 of file pl_funcs.c.

1398{
1399 ListCell *lc;
1400 int i = 0;
1401
1402 dump_ind();
1403 printf("RAISE level=%d", stmt->elog_level);
1404 if (stmt->condname)
1405 printf(" condname='%s'", stmt->condname);
1406 if (stmt->message)
1407 printf(" message='%s'", stmt->message);
1408 printf("\n");
1409 dump_indent += 2;
1410 foreach(lc, stmt->params)
1411 {
1412 dump_ind();
1413 printf(" parameter %d: ", i++);
1415 printf("\n");
1416 }
1417 if (stmt->options)
1418 {
1419 dump_ind();
1420 printf(" USING\n");
1421 dump_indent += 2;
1422 foreach(lc, stmt->options)
1423 {
1425
1426 dump_ind();
1427 switch (opt->opt_type)
1428 {
1430 printf(" ERRCODE = ");
1431 break;
1433 printf(" MESSAGE = ");
1434 break;
1436 printf(" DETAIL = ");
1437 break;
1439 printf(" HINT = ");
1440 break;
1442 printf(" COLUMN = ");
1443 break;
1445 printf(" CONSTRAINT = ");
1446 break;
1448 printf(" DATATYPE = ");
1449 break;
1451 printf(" TABLE = ");
1452 break;
1454 printf(" SCHEMA = ");
1455 break;
1456 }
1457 dump_expr(opt->expr);
1458 printf("\n");
1459 }
1460 dump_indent -= 2;
1461 }
1462 dump_indent -= 2;
1463}

References dump_expr(), dump_ind(), dump_indent, PLpgSQL_raise_option::expr, fb(), i, lfirst, PLpgSQL_raise_option::opt_type, PLPGSQL_RAISEOPTION_COLUMN, PLPGSQL_RAISEOPTION_CONSTRAINT, PLPGSQL_RAISEOPTION_DATATYPE, PLPGSQL_RAISEOPTION_DETAIL, PLPGSQL_RAISEOPTION_ERRCODE, PLPGSQL_RAISEOPTION_HINT, PLPGSQL_RAISEOPTION_MESSAGE, PLPGSQL_RAISEOPTION_SCHEMA, PLPGSQL_RAISEOPTION_TABLE, printf, and stmt.

Referenced by dump_stmt().

◆ dump_return()

static void dump_return ( PLpgSQL_stmt_return stmt)
static

Definition at line 1332 of file pl_funcs.c.

1333{
1334 dump_ind();
1335 printf("RETURN ");
1336 if (stmt->retvarno >= 0)
1337 printf("variable %d", stmt->retvarno);
1338 else if (stmt->expr != NULL)
1339 dump_expr(stmt->expr);
1340 else
1341 printf("NULL");
1342 printf("\n");
1343}

References dump_expr(), dump_ind(), fb(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_return_next()

static void dump_return_next ( PLpgSQL_stmt_return_next stmt)
static

Definition at line 1346 of file pl_funcs.c.

1347{
1348 dump_ind();
1349 printf("RETURN NEXT ");
1350 if (stmt->retvarno >= 0)
1351 printf("variable %d", stmt->retvarno);
1352 else if (stmt->expr != NULL)
1353 dump_expr(stmt->expr);
1354 else
1355 printf("NULL");
1356 printf("\n");
1357}

References dump_expr(), dump_ind(), fb(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_return_query()

static void dump_return_query ( PLpgSQL_stmt_return_query stmt)
static

Definition at line 1360 of file pl_funcs.c.

1361{
1362 dump_ind();
1363 if (stmt->query)
1364 {
1365 printf("RETURN QUERY ");
1366 dump_expr(stmt->query);
1367 printf("\n");
1368 }
1369 else
1370 {
1371 printf("RETURN QUERY EXECUTE ");
1372 dump_expr(stmt->dynquery);
1373 printf("\n");
1374 if (stmt->params != NIL)
1375 {
1376 ListCell *lc;
1377 int i;
1378
1379 dump_indent += 2;
1380 dump_ind();
1381 printf(" USING\n");
1382 dump_indent += 2;
1383 i = 1;
1384 foreach(lc, stmt->params)
1385 {
1386 dump_ind();
1387 printf(" parameter $%d: ", i++);
1389 printf("\n");
1390 }
1391 dump_indent -= 4;
1392 }
1393 }
1394}

References dump_expr(), dump_ind(), dump_indent, fb(), i, lfirst, NIL, printf, and stmt.

Referenced by dump_stmt().

◆ dump_rollback()

static void dump_rollback ( PLpgSQL_stmt_rollback stmt)
static

Definition at line 1307 of file pl_funcs.c.

1308{
1309 dump_ind();
1310 if (stmt->chain)
1311 printf("ROLLBACK AND CHAIN\n");
1312 else
1313 printf("ROLLBACK\n");
1314}

References dump_ind(), printf, and stmt.

Referenced by dump_stmt().

◆ dump_stmt()

static void dump_stmt ( PLpgSQL_stmt stmt)
static

Definition at line 829 of file pl_funcs.c.

830{
831 printf("%3d:", stmt->lineno);
832 switch (stmt->cmd_type)
833 {
836 break;
839 break;
840 case PLPGSQL_STMT_IF:
842 break;
845 break;
848 break;
851 break;
854 break;
857 break;
860 break;
863 break;
866 break;
869 break;
872 break;
875 break;
878 break;
881 break;
884 break;
887 break;
890 break;
893 break;
896 break;
899 break;
902 break;
905 break;
908 break;
911 break;
914 break;
915 default:
916 elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
917 break;
918 }
919}

References dump_assert(), dump_assign(), dump_block(), dump_call(), dump_case(), dump_close(), dump_commit(), dump_dynexecute(), dump_dynfors(), dump_execsql(), dump_exit(), dump_fetch(), dump_forc(), dump_foreach_a(), dump_fori(), dump_fors(), dump_getdiag(), dump_if(), dump_loop(), dump_open(), dump_perform(), dump_raise(), dump_return(), dump_return_next(), dump_return_query(), dump_rollback(), dump_while(), elog, ERROR, PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CALL, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, PLPGSQL_STMT_COMMIT, PLPGSQL_STMT_DYNEXECUTE, PLPGSQL_STMT_DYNFORS, PLPGSQL_STMT_EXECSQL, PLPGSQL_STMT_EXIT, PLPGSQL_STMT_FETCH, PLPGSQL_STMT_FORC, PLPGSQL_STMT_FOREACH_A, PLPGSQL_STMT_FORI, PLPGSQL_STMT_FORS, PLPGSQL_STMT_GETDIAG, PLPGSQL_STMT_IF, PLPGSQL_STMT_LOOP, PLPGSQL_STMT_OPEN, PLPGSQL_STMT_PERFORM, PLPGSQL_STMT_RAISE, PLPGSQL_STMT_RETURN, PLPGSQL_STMT_RETURN_NEXT, PLPGSQL_STMT_RETURN_QUERY, PLPGSQL_STMT_ROLLBACK, PLPGSQL_STMT_WHILE, printf, and stmt.

Referenced by dump_stmts().

◆ dump_stmts()

static void dump_stmts ( List stmts)
static

Definition at line 922 of file pl_funcs.c.

923{
924 ListCell *s;
925
926 dump_indent += 2;
927 foreach(s, stmts)
929 dump_indent -= 2;
930}

References dump_indent, dump_stmt(), and lfirst.

Referenced by dump_block(), dump_case(), dump_dynfors(), dump_forc(), dump_foreach_a(), dump_fori(), dump_fors(), dump_if(), dump_loop(), and dump_while().

◆ dump_while()

static void dump_while ( PLpgSQL_stmt_while stmt)
static

Definition at line 1063 of file pl_funcs.c.

1064{
1065 dump_ind();
1066 printf("WHILE ");
1067 dump_expr(stmt->cond);
1068 printf("\n");
1069
1070 dump_stmts(stmt->body);
1071
1072 dump_ind();
1073 printf(" ENDWHILE\n");
1074}

References dump_expr(), dump_ind(), dump_stmts(), printf, and stmt.

Referenced by dump_stmt().

◆ free_expr()

static void free_expr ( PLpgSQL_expr expr,
void context 
)
static

Definition at line 706 of file pl_funcs.c.

707{
708 if (expr && expr->plan)
709 {
710 SPI_freeplan(expr->plan);
711 expr->plan = NULL;
712 }
713}

References fb(), PLpgSQL_expr::plan, and SPI_freeplan().

Referenced by free_stmt(), and plpgsql_free_function_memory().

◆ free_stmt()

static void free_stmt ( PLpgSQL_stmt stmt,
void context 
)
static

Definition at line 698 of file pl_funcs.c.

699{
700 if (stmt == NULL)
701 return;
703}

References fb(), free_expr(), free_stmt(), plpgsql_statement_tree_walker, and stmt.

Referenced by free_stmt(), and plpgsql_free_function_memory().

◆ mark_expr()

static void mark_expr ( PLpgSQL_expr expr,
Bitmapset local_dnos 
)
static

Definition at line 662 of file pl_funcs.c.

663{
664 /*
665 * If this expression has an assignment target, check whether the target
666 * is local, and mark the expression accordingly.
667 */
668 if (expr && expr->target_param >= 0)
670}

References bms_is_member(), fb(), PLpgSQL_expr::target_is_local, and PLpgSQL_expr::target_param.

Referenced by mark_stmt().

◆ mark_stmt()

static void mark_stmt ( PLpgSQL_stmt stmt,
Bitmapset local_dnos 
)
static

Definition at line 623 of file pl_funcs.c.

624{
625 if (stmt == NULL)
626 return;
627 if (stmt->cmd_type == PLPGSQL_STMT_BLOCK)
628 {
630
631 if (block->exceptions)
632 {
633 /*
634 * The block creates a new exception scope, so variables declared
635 * at outer levels are nonlocal. For that matter, so are any
636 * variables declared in the block's DECLARE section. Hence, we
637 * must pass down empty local_dnos.
638 */
640 }
641 else
642 {
643 /*
644 * Otherwise, the block does not create a new exception scope, and
645 * any variables it declares can also be considered local within
646 * it. Note that only initializable datum types (VAR, REC) are
647 * included in initvarnos; but that's sufficient for our purposes.
648 */
650 for (int i = 0; i < block->n_initvars; i++)
653 local_dnos);
655 }
656 }
657 else
659}

References bms_add_member(), bms_copy(), bms_free(), PLpgSQL_stmt_block::exceptions, fb(), i, PLpgSQL_stmt_block::initvarnos, mark_expr(), mark_stmt(), PLpgSQL_stmt_block::n_initvars, plpgsql_statement_tree_walker, PLPGSQL_STMT_BLOCK, and stmt.

Referenced by mark_stmt(), and plpgsql_mark_local_assignment_targets().

◆ plpgsql_delete_callback()

void plpgsql_delete_callback ( CachedFunction cfunc)

Definition at line 772 of file pl_funcs.c.

References plpgsql_free_function_memory().

Referenced by plpgsql_compile().

◆ plpgsql_dumptree()

void plpgsql_dumptree ( PLpgSQL_function func)

Definition at line 1601 of file pl_funcs.c.

1602{
1603 int i;
1604 PLpgSQL_datum *d;
1605
1606 printf("\nExecution tree of successfully compiled PL/pgSQL function %s:\n",
1607 func->fn_signature);
1608
1609 printf("\nFunction's data area:\n");
1610 for (i = 0; i < func->ndatums; i++)
1611 {
1612 d = func->datums[i];
1613
1614 printf(" entry %d: ", i);
1615 switch (d->dtype)
1616 {
1617 case PLPGSQL_DTYPE_VAR:
1619 {
1620 PLpgSQL_var *var = (PLpgSQL_var *) d;
1621
1622 printf("VAR %-16s type %s (typoid %u) atttypmod %d\n",
1623 var->refname, var->datatype->typname,
1624 var->datatype->typoid,
1625 var->datatype->atttypmod);
1626 if (var->isconst)
1627 printf(" CONSTANT\n");
1628 if (var->notnull)
1629 printf(" NOT NULL\n");
1630 if (var->default_val != NULL)
1631 {
1632 printf(" DEFAULT ");
1633 dump_expr(var->default_val);
1634 printf("\n");
1635 }
1636 if (var->cursor_explicit_expr != NULL)
1637 {
1638 if (var->cursor_explicit_argrow >= 0)
1639 printf(" CURSOR argument row %d\n", var->cursor_explicit_argrow);
1640
1641 printf(" CURSOR IS ");
1643 printf("\n");
1644 }
1645 if (var->promise != PLPGSQL_PROMISE_NONE)
1646 printf(" PROMISE %d\n",
1647 (int) var->promise);
1648 }
1649 break;
1650 case PLPGSQL_DTYPE_ROW:
1651 {
1652 PLpgSQL_row *row = (PLpgSQL_row *) d;
1653
1654 printf("ROW %-16s fields", row->refname);
1655 for (int j = 0; j < row->nfields; j++)
1656 {
1657 printf(" %s=var %d", row->fieldnames[j],
1658 row->varnos[j]);
1659 }
1660 printf("\n");
1661 }
1662 break;
1663 case PLPGSQL_DTYPE_REC:
1664 printf("REC %-16s typoid %u\n",
1665 ((PLpgSQL_rec *) d)->refname,
1666 ((PLpgSQL_rec *) d)->rectypeid);
1667 if (((PLpgSQL_rec *) d)->isconst)
1668 printf(" CONSTANT\n");
1669 if (((PLpgSQL_rec *) d)->notnull)
1670 printf(" NOT NULL\n");
1671 if (((PLpgSQL_rec *) d)->default_val != NULL)
1672 {
1673 printf(" DEFAULT ");
1674 dump_expr(((PLpgSQL_rec *) d)->default_val);
1675 printf("\n");
1676 }
1677 break;
1679 printf("RECFIELD %-16s of REC %d\n",
1680 ((PLpgSQL_recfield *) d)->fieldname,
1681 ((PLpgSQL_recfield *) d)->recparentno);
1682 break;
1683 default:
1684 printf("??? unknown data type %d\n", d->dtype);
1685 }
1686 }
1687 printf("\nFunction's statements:\n");
1688
1689 dump_indent = 0;
1690 printf("%3d:", func->action->lineno);
1691 dump_block(func->action);
1692 printf("\nEnd of execution tree of function %s\n\n", func->fn_signature);
1693 fflush(stdout);
1694}

References PLpgSQL_function::action, PLpgSQL_type::atttypmod, PLpgSQL_var::cursor_explicit_argrow, PLpgSQL_var::cursor_explicit_expr, PLpgSQL_var::datatype, PLpgSQL_function::datums, PLpgSQL_var::default_val, PLpgSQL_datum::dtype, PLpgSQL_rec::dtype, dump_block(), dump_expr(), dump_indent, fb(), PLpgSQL_row::fieldnames, PLpgSQL_function::fn_signature, i, PLpgSQL_var::isconst, j, PLpgSQL_stmt_block::lineno, PLpgSQL_function::ndatums, PLpgSQL_row::nfields, PLpgSQL_var::notnull, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, PLPGSQL_PROMISE_NONE, printf, PLpgSQL_var::promise, PLpgSQL_var::refname, PLpgSQL_row::refname, PLpgSQL_type::typname, PLpgSQL_type::typoid, and PLpgSQL_row::varnos.

Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().

◆ plpgsql_free_function_memory()

void plpgsql_free_function_memory ( PLpgSQL_function func)

Definition at line 716 of file pl_funcs.c.

717{
718 int i;
719
720 /* Better not call this on an in-use function */
721 Assert(func->cfunc.use_count == 0);
722
723 /* Release plans associated with variable declarations */
724 for (i = 0; i < func->ndatums; i++)
725 {
726 PLpgSQL_datum *d = func->datums[i];
727
728 switch (d->dtype)
729 {
732 {
733 PLpgSQL_var *var = (PLpgSQL_var *) d;
734
737 }
738 break;
740 break;
742 {
743 PLpgSQL_rec *rec = (PLpgSQL_rec *) d;
744
746 }
747 break;
749 break;
750 default:
751 elog(ERROR, "unrecognized data type: %d", d->dtype);
752 }
753 }
754 func->ndatums = 0;
755
756 /* Release plans in statement tree */
757 free_stmt((PLpgSQL_stmt *) func->action, NULL);
758 func->action = NULL;
759
760 /*
761 * And finally, release all memory except the PLpgSQL_function struct
762 * itself (which has to be kept around because there may be multiple
763 * fn_extra pointers to it).
764 */
765 if (func->fn_cxt)
767 func->fn_cxt = NULL;
768}

References PLpgSQL_function::action, Assert, PLpgSQL_function::cfunc, PLpgSQL_var::cursor_explicit_expr, PLpgSQL_function::datums, PLpgSQL_var::default_val, PLpgSQL_rec::default_val, PLpgSQL_datum::dtype, elog, ERROR, fb(), PLpgSQL_function::fn_cxt, free_expr(), free_stmt(), i, MemoryContextDelete(), PLpgSQL_function::ndatums, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, and CachedFunction::use_count.

Referenced by plpgsql_delete_callback(), and plpgsql_inline_handler().

◆ plpgsql_getdiag_kindname()

const char * plpgsql_getdiag_kindname ( PLpgSQL_getdiag_kind  kind)

Definition at line 300 of file pl_funcs.c.

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}
@ PLPGSQL_GETDIAG_ERROR_DETAIL
Definition plpgsql.h:154
@ PLPGSQL_GETDIAG_SCHEMA_NAME
Definition plpgsql.h:162
@ PLPGSQL_GETDIAG_MESSAGE_TEXT
Definition plpgsql.h:160
@ PLPGSQL_GETDIAG_DATATYPE_NAME
Definition plpgsql.h:159
@ PLPGSQL_GETDIAG_TABLE_NAME
Definition plpgsql.h:161
@ PLPGSQL_GETDIAG_CONSTRAINT_NAME
Definition plpgsql.h:158
@ PLPGSQL_GETDIAG_COLUMN_NAME
Definition plpgsql.h:157
@ PLPGSQL_GETDIAG_ROW_COUNT
Definition plpgsql.h:150
@ PLPGSQL_GETDIAG_RETURNED_SQLSTATE
Definition plpgsql.h:156
@ PLPGSQL_GETDIAG_CONTEXT
Definition plpgsql.h:152
@ PLPGSQL_GETDIAG_ERROR_HINT
Definition plpgsql.h:155
@ PLPGSQL_GETDIAG_ERROR_CONTEXT
Definition plpgsql.h:153
@ PLPGSQL_GETDIAG_ROUTINE_OID
Definition plpgsql.h:151

References PLPGSQL_GETDIAG_COLUMN_NAME, PLPGSQL_GETDIAG_CONSTRAINT_NAME, PLPGSQL_GETDIAG_CONTEXT, PLPGSQL_GETDIAG_DATATYPE_NAME, PLPGSQL_GETDIAG_ERROR_CONTEXT, PLPGSQL_GETDIAG_ERROR_DETAIL, PLPGSQL_GETDIAG_ERROR_HINT, PLPGSQL_GETDIAG_MESSAGE_TEXT, PLPGSQL_GETDIAG_RETURNED_SQLSTATE, PLPGSQL_GETDIAG_ROUTINE_OID, PLPGSQL_GETDIAG_ROW_COUNT, PLPGSQL_GETDIAG_SCHEMA_NAME, and PLPGSQL_GETDIAG_TABLE_NAME.

Referenced by dump_getdiag().

◆ plpgsql_mark_local_assignment_targets()

void plpgsql_mark_local_assignment_targets ( PLpgSQL_function func)

Definition at line 673 of file pl_funcs.c.

674{
676
677 /* Function parameters can be treated as local targets at outer level */
679 for (int i = 0; i < func->fn_nargs; i++)
683}

References PLpgSQL_function::action, bms_add_member(), bms_free(), fb(), PLpgSQL_function::fn_argvarnos, PLpgSQL_function::fn_nargs, i, and mark_stmt().

Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().

◆ plpgsql_ns_additem()

void plpgsql_ns_additem ( PLpgSQL_nsitem_type  itemtype,
int  itemno,
const char name 
)

Definition at line 92 of file pl_funcs.c.

93{
95
96 Assert(name != NULL);
97 /* first item added must be a label */
98 Assert(ns_top != NULL || itemtype == PLPGSQL_NSTYPE_LABEL);
99
101 nse->itemtype = itemtype;
102 nse->itemno = itemno;
103 nse->prev = ns_top;
104 strcpy(nse->name, name);
105 ns_top = nse;
106}
void * palloc(Size size)
Definition mcxt.c:1387
static PLpgSQL_nsitem * ns_top
Definition pl_funcs.c:35
@ PLPGSQL_NSTYPE_LABEL
Definition plpgsql.h:44

References Assert, fb(), name, ns_top, palloc(), and PLPGSQL_NSTYPE_LABEL.

Referenced by add_parameter_name(), plpgsql_build_record(), plpgsql_build_variable(), and plpgsql_ns_push().

◆ plpgsql_ns_find_nearest_loop()

PLpgSQL_nsitem * plpgsql_ns_find_nearest_loop ( PLpgSQL_nsitem ns_cur)

Definition at line 214 of file pl_funcs.c.

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}
@ PLPGSQL_LABEL_LOOP
Definition plpgsql.h:55

References fb(), PLPGSQL_LABEL_LOOP, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

◆ plpgsql_ns_init()

void plpgsql_ns_init ( void  )

Definition at line 43 of file pl_funcs.c.

44{
45 ns_top = NULL;
46}

References fb(), and ns_top.

Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().

◆ plpgsql_ns_lookup()

PLpgSQL_nsitem * plpgsql_ns_lookup ( PLpgSQL_nsitem ns_cur,
bool  localmode,
const char name1,
const char name2,
const char name3,
int names_used 
)

Definition at line 130 of file pl_funcs.c.

133{
134 /* Outer loop iterates once per block level in the namespace chain */
135 while (ns_cur != NULL)
136 {
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}
@ PLPGSQL_NSTYPE_VAR
Definition plpgsql.h:45
struct PLpgSQL_nsitem * prev
Definition plpgsql.h:469

References fb(), PLPGSQL_NSTYPE_LABEL, PLPGSQL_NSTYPE_VAR, and PLpgSQL_nsitem::prev.

Referenced by add_parameter_name(), plpgsql_param_ref(), plpgsql_parse_cwordtype(), plpgsql_parse_dblword(), plpgsql_parse_tripword(), plpgsql_parse_word(), plpgsql_parse_wordtype(), and resolve_column_ref().

◆ plpgsql_ns_lookup_label()

PLpgSQL_nsitem * plpgsql_ns_lookup_label ( PLpgSQL_nsitem ns_cur,
const char name 
)

Definition at line 195 of file pl_funcs.c.

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}

References fb(), name, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

◆ plpgsql_ns_pop()

void plpgsql_ns_pop ( void  )

Definition at line 67 of file pl_funcs.c.

68{
69 Assert(ns_top != NULL);
73}
PLpgSQL_nsitem_type itemtype
Definition plpgsql.h:462

References Assert, fb(), PLpgSQL_nsitem::itemtype, ns_top, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

◆ plpgsql_ns_push()

void plpgsql_ns_push ( const char label,
PLpgSQL_label_type  label_type 
)

Definition at line 54 of file pl_funcs.c.

55{
56 if (label == NULL)
57 label = "";
59}
static char * label
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition pl_funcs.c:92

References fb(), label, plpgsql_ns_additem(), and PLPGSQL_NSTYPE_LABEL.

Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().

◆ plpgsql_ns_top()

PLpgSQL_nsitem * plpgsql_ns_top ( void  )

◆ plpgsql_statement_tree_walker_impl()

static void plpgsql_statement_tree_walker_impl ( PLpgSQL_stmt stmt,
plpgsql_stmt_walker_callback  stmt_callback,
plpgsql_expr_walker_callback  expr_callback,
void context 
)
static

Definition at line 364 of file pl_funcs.c.

368{
369#define S_WALK(st) stmt_callback(st, context)
370#define E_WALK(ex) expr_callback(ex, context)
371#define S_LIST_WALK(lst) foreach_ptr(PLpgSQL_stmt, st, lst) S_WALK(st)
372#define E_LIST_WALK(lst) foreach_ptr(PLpgSQL_expr, ex, lst) E_WALK(ex)
373
374 switch (stmt->cmd_type)
375 {
377 {
379
380 S_LIST_WALK(bstmt->body);
381 if (bstmt->exceptions)
382 {
383 foreach_ptr(PLpgSQL_exception, exc, bstmt->exceptions->exc_list)
384 {
385 /* conditions list has no interesting sub-structure */
386 S_LIST_WALK(exc->action);
387 }
388 }
389 break;
390 }
392 {
394
395 E_WALK(astmt->expr);
396 break;
397 }
398 case PLPGSQL_STMT_IF:
399 {
401
402 E_WALK(ifstmt->cond);
403 S_LIST_WALK(ifstmt->then_body);
405 {
406 E_WALK(elif->cond);
407 S_LIST_WALK(elif->stmts);
408 }
409 S_LIST_WALK(ifstmt->else_body);
410 break;
411 }
413 {
415
416 E_WALK(cstmt->t_expr);
417 foreach_ptr(PLpgSQL_case_when, cwt, cstmt->case_when_list)
418 {
419 E_WALK(cwt->expr);
420 S_LIST_WALK(cwt->stmts);
421 }
422 S_LIST_WALK(cstmt->else_stmts);
423 break;
424 }
426 {
428
429 S_LIST_WALK(lstmt->body);
430 break;
431 }
433 {
435
436 E_WALK(wstmt->cond);
437 S_LIST_WALK(wstmt->body);
438 break;
439 }
441 {
443
444 E_WALK(fori->lower);
445 E_WALK(fori->upper);
446 E_WALK(fori->step);
447 S_LIST_WALK(fori->body);
448 break;
449 }
451 {
453
454 S_LIST_WALK(fors->body);
455 E_WALK(fors->query);
456 break;
457 }
459 {
461
462 S_LIST_WALK(forc->body);
463 E_WALK(forc->argquery);
464 break;
465 }
467 {
469
470 E_WALK(fstmt->expr);
471 S_LIST_WALK(fstmt->body);
472 break;
473 }
475 {
477
478 E_WALK(estmt->cond);
479 break;
480 }
482 {
484
485 E_WALK(rstmt->expr);
486 break;
487 }
489 {
491
492 E_WALK(rstmt->expr);
493 break;
494 }
496 {
498
499 E_WALK(rstmt->query);
500 E_WALK(rstmt->dynquery);
501 E_LIST_WALK(rstmt->params);
502 break;
503 }
505 {
507
508 E_LIST_WALK(rstmt->params);
510 {
511 E_WALK(opt->expr);
512 }
513 break;
514 }
516 {
518
519 E_WALK(astmt->cond);
520 E_WALK(astmt->message);
521 break;
522 }
524 {
526
527 E_WALK(xstmt->sqlstmt);
528 break;
529 }
531 {
533
534 E_WALK(dstmt->query);
535 E_LIST_WALK(dstmt->params);
536 break;
537 }
539 {
541
542 S_LIST_WALK(dstmt->body);
543 E_WALK(dstmt->query);
544 E_LIST_WALK(dstmt->params);
545 break;
546 }
548 {
549 /* no interesting sub-structure */
550 break;
551 }
553 {
555
556 E_WALK(ostmt->argquery);
557 E_WALK(ostmt->query);
558 E_WALK(ostmt->dynquery);
559 E_LIST_WALK(ostmt->params);
560 break;
561 }
563 {
565
566 E_WALK(fstmt->expr);
567 break;
568 }
570 {
571 /* no interesting sub-structure */
572 break;
573 }
575 {
577
578 E_WALK(pstmt->expr);
579 break;
580 }
582 {
584
585 E_WALK(cstmt->expr);
586 break;
587 }
590 {
591 /* no interesting sub-structure */
592 break;
593 }
594 default:
595 elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
596 break;
597 }
598}

References E_LIST_WALK, E_WALK, elog, ERROR, PLpgSQL_stmt_perform::expr, fb(), foreach_ptr, ifstmt, PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CALL, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, PLPGSQL_STMT_COMMIT, PLPGSQL_STMT_DYNEXECUTE, PLPGSQL_STMT_DYNFORS, PLPGSQL_STMT_EXECSQL, PLPGSQL_STMT_EXIT, PLPGSQL_STMT_FETCH, PLPGSQL_STMT_FORC, PLPGSQL_STMT_FOREACH_A, PLPGSQL_STMT_FORI, PLPGSQL_STMT_FORS, PLPGSQL_STMT_GETDIAG, PLPGSQL_STMT_IF, PLPGSQL_STMT_LOOP, PLPGSQL_STMT_OPEN, PLPGSQL_STMT_PERFORM, PLPGSQL_STMT_RAISE, PLPGSQL_STMT_RETURN, PLPGSQL_STMT_RETURN_NEXT, PLPGSQL_STMT_RETURN_QUERY, PLPGSQL_STMT_ROLLBACK, PLPGSQL_STMT_WHILE, S_LIST_WALK, and stmt.

◆ plpgsql_stmt_typename()

const char * plpgsql_stmt_typename ( PLpgSQL_stmt stmt)

Definition at line 232 of file pl_funcs.c.

233{
234 switch (stmt->cmd_type)
235 {
237 return _("statement block");
239 return _("assignment");
240 case PLPGSQL_STMT_IF:
241 return "IF";
243 return "CASE";
245 return "LOOP";
247 return "WHILE";
249 return _("FOR with integer loop variable");
251 return _("FOR over SELECT rows");
253 return _("FOR over cursor");
255 return _("FOREACH over array");
257 return ((PLpgSQL_stmt_exit *) stmt)->is_exit ? "EXIT" : "CONTINUE";
259 return "RETURN";
261 return "RETURN NEXT";
263 return "RETURN QUERY";
265 return "RAISE";
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";
278 return "OPEN";
280 return ((PLpgSQL_stmt_fetch *) stmt)->is_move ? "MOVE" : "FETCH";
282 return "CLOSE";
284 return "PERFORM";
286 return ((PLpgSQL_stmt_call *) stmt)->is_call ? "CALL" : "DO";
288 return "COMMIT";
290 return "ROLLBACK";
291 }
292
293 return "unknown";
294}
#define _(x)
Definition elog.c:91

References _, PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CALL, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, PLPGSQL_STMT_COMMIT, PLPGSQL_STMT_DYNEXECUTE, PLPGSQL_STMT_DYNFORS, PLPGSQL_STMT_EXECSQL, PLPGSQL_STMT_EXIT, PLPGSQL_STMT_FETCH, PLPGSQL_STMT_FORC, PLPGSQL_STMT_FOREACH_A, PLPGSQL_STMT_FORI, PLPGSQL_STMT_FORS, PLPGSQL_STMT_GETDIAG, PLPGSQL_STMT_IF, PLPGSQL_STMT_LOOP, PLPGSQL_STMT_OPEN, PLPGSQL_STMT_PERFORM, PLPGSQL_STMT_RAISE, PLPGSQL_STMT_RETURN, PLPGSQL_STMT_RETURN_NEXT, PLPGSQL_STMT_RETURN_QUERY, PLPGSQL_STMT_ROLLBACK, PLPGSQL_STMT_WHILE, and stmt.

Referenced by plpgsql_exec_error_callback().

Variable Documentation

◆ dump_indent

◆ ns_top

PLpgSQL_nsitem* ns_top = NULL
static

Definition at line 35 of file pl_funcs.c.

Referenced by plpgsql_ns_additem(), plpgsql_ns_init(), plpgsql_ns_pop(), and plpgsql_ns_top().