LCOV - code coverage report
Current view: top level - src/pl/plpgsql/src - pl_gram.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 78.6 % 468 368
Test Date: 2026-05-11 23:16:49 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* A Bison parser, made by GNU Bison 3.8.2.  */
       2              : 
       3              : /* Bison implementation for Yacc-like parsers in C
       4              : 
       5              :    Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
       6              :    Inc.
       7              : 
       8              :    This program is free software: you can redistribute it and/or modify
       9              :    it under the terms of the GNU General Public License as published by
      10              :    the Free Software Foundation, either version 3 of the License, or
      11              :    (at your option) any later version.
      12              : 
      13              :    This program is distributed in the hope that it will be useful,
      14              :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15              :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16              :    GNU General Public License for more details.
      17              : 
      18              :    You should have received a copy of the GNU General Public License
      19              :    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      20              : 
      21              : /* As a special exception, you may create a larger work that contains
      22              :    part or all of the Bison parser skeleton and distribute that work
      23              :    under terms of your choice, so long as that work isn't itself a
      24              :    parser generator using the skeleton or a modified version thereof
      25              :    as a parser skeleton.  Alternatively, if you modify or redistribute
      26              :    the parser skeleton itself, you may (at your option) remove this
      27              :    special exception, which will cause the skeleton and the resulting
      28              :    Bison output files to be licensed under the GNU General Public
      29              :    License without this special exception.
      30              : 
      31              :    This special exception was added by the Free Software Foundation in
      32              :    version 2.2 of Bison.  */
      33              : 
      34              : /* C LALR(1) parser skeleton written by Richard Stallman, by
      35              :    simplifying the original so-called "semantic" parser.  */
      36              : 
      37              : /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
      38              :    especially those whose name start with YY_ or yy_.  They are
      39              :    private implementation details that can be changed or removed.  */
      40              : 
      41              : /* All symbols defined below should begin with yy or YY, to avoid
      42              :    infringing on user name space.  This should be done even for local
      43              :    variables, as they might otherwise be expanded by user macros.
      44              :    There are some unavoidable exceptions within include files to
      45              :    define necessary library symbols; they are noted "INFRINGES ON
      46              :    USER NAME SPACE" below.  */
      47              : 
      48              : /* Identify Bison output, and Bison version.  */
      49              : #define YYBISON 30802
      50              : 
      51              : /* Bison version string.  */
      52              : #define YYBISON_VERSION "3.8.2"
      53              : 
      54              : /* Skeleton name.  */
      55              : #define YYSKELETON_NAME "yacc.c"
      56              : 
      57              : /* Pure parsers.  */
      58              : #define YYPURE 1
      59              : 
      60              : /* Push parsers.  */
      61              : #define YYPUSH 0
      62              : 
      63              : /* Pull parsers.  */
      64              : #define YYPULL 1
      65              : 
      66              : 
      67              : /* Substitute the variable and function names.  */
      68              : #define yyparse         plpgsql_yyparse
      69              : #define yylex           plpgsql_yylex
      70              : #define yyerror         plpgsql_yyerror
      71              : #define yydebug         plpgsql_yydebug
      72              : #define yynerrs         plpgsql_yynerrs
      73              : 
      74              : /* First part of user prologue.  */
      75              : #line 1 "pl_gram.y"
      76              : 
      77              : /*-------------------------------------------------------------------------
      78              :  *
      79              :  * pl_gram.y            - Parser for the PL/pgSQL procedural language
      80              :  *
      81              :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
      82              :  * Portions Copyright (c) 1994, Regents of the University of California
      83              :  *
      84              :  *
      85              :  * IDENTIFICATION
      86              :  *    src/pl/plpgsql/src/pl_gram.y
      87              :  *
      88              :  *-------------------------------------------------------------------------
      89              :  */
      90              : 
      91              : #include "postgres.h"
      92              : 
      93              : #include "catalog/namespace.h"
      94              : #include "catalog/pg_proc.h"
      95              : #include "catalog/pg_type.h"
      96              : #include "parser/parser.h"
      97              : #include "parser/parse_type.h"
      98              : #include "parser/scanner.h"
      99              : #include "parser/scansup.h"
     100              : #include "utils/builtins.h"
     101              : 
     102              : #include "plpgsql.h"
     103              : 
     104              : #include "pl_gram.h"
     105              : 
     106              : /* Location tracking support --- simpler than bison's default */
     107              : #define YYLLOC_DEFAULT(Current, Rhs, N) \
     108              :     do { \
     109              :         if (N) \
     110              :             (Current) = (Rhs)[1]; \
     111              :         else \
     112              :             (Current) = (Rhs)[0]; \
     113              :     } while (0)
     114              : 
     115              : /*
     116              :  * Bison doesn't allocate anything that needs to live across parser calls,
     117              :  * so we can easily have it use palloc instead of malloc.  This prevents
     118              :  * memory leaks if we error out during parsing.
     119              :  */
     120              : #define YYMALLOC palloc
     121              : #define YYFREE   pfree
     122              : 
     123              : 
     124              : typedef struct
     125              : {
     126              :     int         location;
     127              :     yyscan_t    yyscanner;
     128              : } sql_error_callback_arg;
     129              : 
     130              : #define parser_errposition(pos)  plpgsql_scanner_errposition(pos, yyscanner)
     131              : 
     132              : union YYSTYPE;                  /* need forward reference for tok_is_keyword */
     133              : 
     134              : static  bool            tok_is_keyword(int token, union YYSTYPE *lval,
     135              :                                        int kw_token, const char *kw_str);
     136              : static  void            word_is_not_variable(PLword *word, int location, yyscan_t yyscanner);
     137              : static  void            cword_is_not_variable(PLcword *cword, int location, yyscan_t yyscanner);
     138              : static  void            current_token_is_not_variable(int tok, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     139              : static  PLpgSQL_expr    *make_plpgsql_expr(const char *query,
     140              :                                            RawParseMode parsemode);
     141              : static  void            mark_expr_as_assignment_source(PLpgSQL_expr *expr,
     142              :                                                        PLpgSQL_datum *target);
     143              : static  PLpgSQL_expr    *read_sql_construct(int until,
     144              :                                             int until2,
     145              :                                             int until3,
     146              :                                             const char *expected,
     147              :                                             RawParseMode parsemode,
     148              :                                             bool isexpression,
     149              :                                             bool valid_sql,
     150              :                                             int *startloc,
     151              :                                             int *endtoken,
     152              :                                             YYSTYPE *yylvalp, YYLTYPE *yyllocp,
     153              :                                             yyscan_t yyscanner);
     154              : static  PLpgSQL_expr    *read_sql_expression(int until, const char *expected,
     155              :                                              YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     156              : static  PLpgSQL_expr    *read_sql_expression2(int until, int until2,
     157              :                                               const char *expected, int *endtoken,
     158              :                                               YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     159              : static  PLpgSQL_expr    *read_sql_stmt(YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     160              : static  PLpgSQL_type    *read_datatype(int tok, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     161              : static  PLpgSQL_stmt    *make_execsql_stmt(int firsttoken, int location,
     162              :                                            PLword *word, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     163              : static  PLpgSQL_stmt_fetch *read_fetch_direction(YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     164              : static  void             complete_direction(PLpgSQL_stmt_fetch *fetch,
     165              :                                             bool *check_FROM, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     166              : static  PLpgSQL_stmt    *make_return_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     167              : static  PLpgSQL_stmt    *make_return_next_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     168              : static  PLpgSQL_stmt    *make_return_query_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     169              : static  PLpgSQL_stmt    *make_case(int location, PLpgSQL_expr *t_expr,
     170              :                                    List *case_when_list, List *else_stmts, yyscan_t yyscanner);
     171              : static  char            *NameOfDatum(PLwdatum *wdatum);
     172              : static  void             check_assignable(PLpgSQL_datum *datum, int location, yyscan_t yyscanner);
     173              : static  void             read_into_target(PLpgSQL_variable **target, bool *strict,
     174              :                                           YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     175              : static  PLpgSQL_row     *read_into_scalar_list(char *initial_name,
     176              :                                                PLpgSQL_datum *initial_datum,
     177              :                                                int initial_location,
     178              :                                                YYSTYPE *yylvalp, YYLTYPE *yyllocp,
     179              :                                                yyscan_t yyscanner);
     180              : static  PLpgSQL_row     *make_scalar_list1(char *initial_name,
     181              :                                            PLpgSQL_datum *initial_datum,
     182              :                                            int lineno, int location, yyscan_t yyscanner);
     183              : static  void             check_sql_expr(const char *stmt,
     184              :                                         RawParseMode parseMode, int location, yyscan_t yyscanner);
     185              : static  void             plpgsql_sql_error_callback(void *arg);
     186              : static  PLpgSQL_type    *parse_datatype(const char *string, int location, yyscan_t yyscanner);
     187              : static  void             check_labels(const char *start_label,
     188              :                                       const char *end_label,
     189              :                                       int end_location,
     190              :                                       yyscan_t yyscanner);
     191              : static  PLpgSQL_expr    *read_cursor_args(PLpgSQL_var *cursor, int until,
     192              :                                           YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     193              : static  List            *read_raise_options(YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner);
     194              : static  void            check_raise_parameters(PLpgSQL_stmt_raise *stmt);
     195              : 
     196              : 
     197              : #line 198 "pl_gram.c"
     198              : 
     199              : # ifndef YY_CAST
     200              : #  ifdef __cplusplus
     201              : #   define YY_CAST(Type, Val) static_cast<Type> (Val)
     202              : #   define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
     203              : #  else
     204              : #   define YY_CAST(Type, Val) ((Type) (Val))
     205              : #   define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
     206              : #  endif
     207              : # endif
     208              : # ifndef YY_NULLPTR
     209              : #  if defined __cplusplus
     210              : #   if 201103L <= __cplusplus
     211              : #    define YY_NULLPTR nullptr
     212              : #   else
     213              : #    define YY_NULLPTR 0
     214              : #   endif
     215              : #  else
     216              : #   define YY_NULLPTR ((void*)0)
     217              : #  endif
     218              : # endif
     219              : 
     220              : #include "pl_gram.h"
     221              : /* Symbol kind.  */
     222              : enum yysymbol_kind_t
     223              : {
     224              :   YYSYMBOL_YYEMPTY = -2,
     225              :   YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
     226              :   YYSYMBOL_YYerror = 1,                    /* error  */
     227              :   YYSYMBOL_YYUNDEF = 2,                    /* "invalid token"  */
     228              :   YYSYMBOL_IDENT = 3,                      /* IDENT  */
     229              :   YYSYMBOL_UIDENT = 4,                     /* UIDENT  */
     230              :   YYSYMBOL_FCONST = 5,                     /* FCONST  */
     231              :   YYSYMBOL_SCONST = 6,                     /* SCONST  */
     232              :   YYSYMBOL_USCONST = 7,                    /* USCONST  */
     233              :   YYSYMBOL_BCONST = 8,                     /* BCONST  */
     234              :   YYSYMBOL_XCONST = 9,                     /* XCONST  */
     235              :   YYSYMBOL_Op = 10,                        /* Op  */
     236              :   YYSYMBOL_ICONST = 11,                    /* ICONST  */
     237              :   YYSYMBOL_PARAM = 12,                     /* PARAM  */
     238              :   YYSYMBOL_TYPECAST = 13,                  /* TYPECAST  */
     239              :   YYSYMBOL_DOT_DOT = 14,                   /* DOT_DOT  */
     240              :   YYSYMBOL_COLON_EQUALS = 15,              /* COLON_EQUALS  */
     241              :   YYSYMBOL_EQUALS_GREATER = 16,            /* EQUALS_GREATER  */
     242              :   YYSYMBOL_LESS_EQUALS = 17,               /* LESS_EQUALS  */
     243              :   YYSYMBOL_GREATER_EQUALS = 18,            /* GREATER_EQUALS  */
     244              :   YYSYMBOL_NOT_EQUALS = 19,                /* NOT_EQUALS  */
     245              :   YYSYMBOL_T_WORD = 20,                    /* T_WORD  */
     246              :   YYSYMBOL_T_CWORD = 21,                   /* T_CWORD  */
     247              :   YYSYMBOL_T_DATUM = 22,                   /* T_DATUM  */
     248              :   YYSYMBOL_LESS_LESS = 23,                 /* LESS_LESS  */
     249              :   YYSYMBOL_GREATER_GREATER = 24,           /* GREATER_GREATER  */
     250              :   YYSYMBOL_K_ABSOLUTE = 25,                /* K_ABSOLUTE  */
     251              :   YYSYMBOL_K_ALIAS = 26,                   /* K_ALIAS  */
     252              :   YYSYMBOL_K_ALL = 27,                     /* K_ALL  */
     253              :   YYSYMBOL_K_AND = 28,                     /* K_AND  */
     254              :   YYSYMBOL_K_ARRAY = 29,                   /* K_ARRAY  */
     255              :   YYSYMBOL_K_ASSERT = 30,                  /* K_ASSERT  */
     256              :   YYSYMBOL_K_BACKWARD = 31,                /* K_BACKWARD  */
     257              :   YYSYMBOL_K_BEGIN = 32,                   /* K_BEGIN  */
     258              :   YYSYMBOL_K_BY = 33,                      /* K_BY  */
     259              :   YYSYMBOL_K_CALL = 34,                    /* K_CALL  */
     260              :   YYSYMBOL_K_CASE = 35,                    /* K_CASE  */
     261              :   YYSYMBOL_K_CHAIN = 36,                   /* K_CHAIN  */
     262              :   YYSYMBOL_K_CLOSE = 37,                   /* K_CLOSE  */
     263              :   YYSYMBOL_K_COLLATE = 38,                 /* K_COLLATE  */
     264              :   YYSYMBOL_K_COLUMN = 39,                  /* K_COLUMN  */
     265              :   YYSYMBOL_K_COLUMN_NAME = 40,             /* K_COLUMN_NAME  */
     266              :   YYSYMBOL_K_COMMIT = 41,                  /* K_COMMIT  */
     267              :   YYSYMBOL_K_CONSTANT = 42,                /* K_CONSTANT  */
     268              :   YYSYMBOL_K_CONSTRAINT = 43,              /* K_CONSTRAINT  */
     269              :   YYSYMBOL_K_CONSTRAINT_NAME = 44,         /* K_CONSTRAINT_NAME  */
     270              :   YYSYMBOL_K_CONTINUE = 45,                /* K_CONTINUE  */
     271              :   YYSYMBOL_K_CURRENT = 46,                 /* K_CURRENT  */
     272              :   YYSYMBOL_K_CURSOR = 47,                  /* K_CURSOR  */
     273              :   YYSYMBOL_K_DATATYPE = 48,                /* K_DATATYPE  */
     274              :   YYSYMBOL_K_DEBUG = 49,                   /* K_DEBUG  */
     275              :   YYSYMBOL_K_DECLARE = 50,                 /* K_DECLARE  */
     276              :   YYSYMBOL_K_DEFAULT = 51,                 /* K_DEFAULT  */
     277              :   YYSYMBOL_K_DETAIL = 52,                  /* K_DETAIL  */
     278              :   YYSYMBOL_K_DIAGNOSTICS = 53,             /* K_DIAGNOSTICS  */
     279              :   YYSYMBOL_K_DO = 54,                      /* K_DO  */
     280              :   YYSYMBOL_K_DUMP = 55,                    /* K_DUMP  */
     281              :   YYSYMBOL_K_ELSE = 56,                    /* K_ELSE  */
     282              :   YYSYMBOL_K_ELSIF = 57,                   /* K_ELSIF  */
     283              :   YYSYMBOL_K_END = 58,                     /* K_END  */
     284              :   YYSYMBOL_K_ERRCODE = 59,                 /* K_ERRCODE  */
     285              :   YYSYMBOL_K_ERROR = 60,                   /* K_ERROR  */
     286              :   YYSYMBOL_K_EXCEPTION = 61,               /* K_EXCEPTION  */
     287              :   YYSYMBOL_K_EXECUTE = 62,                 /* K_EXECUTE  */
     288              :   YYSYMBOL_K_EXIT = 63,                    /* K_EXIT  */
     289              :   YYSYMBOL_K_FETCH = 64,                   /* K_FETCH  */
     290              :   YYSYMBOL_K_FIRST = 65,                   /* K_FIRST  */
     291              :   YYSYMBOL_K_FOR = 66,                     /* K_FOR  */
     292              :   YYSYMBOL_K_FOREACH = 67,                 /* K_FOREACH  */
     293              :   YYSYMBOL_K_FORWARD = 68,                 /* K_FORWARD  */
     294              :   YYSYMBOL_K_FROM = 69,                    /* K_FROM  */
     295              :   YYSYMBOL_K_GET = 70,                     /* K_GET  */
     296              :   YYSYMBOL_K_HINT = 71,                    /* K_HINT  */
     297              :   YYSYMBOL_K_IF = 72,                      /* K_IF  */
     298              :   YYSYMBOL_K_IMPORT = 73,                  /* K_IMPORT  */
     299              :   YYSYMBOL_K_IN = 74,                      /* K_IN  */
     300              :   YYSYMBOL_K_INFO = 75,                    /* K_INFO  */
     301              :   YYSYMBOL_K_INSERT = 76,                  /* K_INSERT  */
     302              :   YYSYMBOL_K_INTO = 77,                    /* K_INTO  */
     303              :   YYSYMBOL_K_IS = 78,                      /* K_IS  */
     304              :   YYSYMBOL_K_LAST = 79,                    /* K_LAST  */
     305              :   YYSYMBOL_K_LOG = 80,                     /* K_LOG  */
     306              :   YYSYMBOL_K_LOOP = 81,                    /* K_LOOP  */
     307              :   YYSYMBOL_K_MERGE = 82,                   /* K_MERGE  */
     308              :   YYSYMBOL_K_MESSAGE = 83,                 /* K_MESSAGE  */
     309              :   YYSYMBOL_K_MESSAGE_TEXT = 84,            /* K_MESSAGE_TEXT  */
     310              :   YYSYMBOL_K_MOVE = 85,                    /* K_MOVE  */
     311              :   YYSYMBOL_K_NEXT = 86,                    /* K_NEXT  */
     312              :   YYSYMBOL_K_NO = 87,                      /* K_NO  */
     313              :   YYSYMBOL_K_NOT = 88,                     /* K_NOT  */
     314              :   YYSYMBOL_K_NOTICE = 89,                  /* K_NOTICE  */
     315              :   YYSYMBOL_K_NULL = 90,                    /* K_NULL  */
     316              :   YYSYMBOL_K_OPEN = 91,                    /* K_OPEN  */
     317              :   YYSYMBOL_K_OPTION = 92,                  /* K_OPTION  */
     318              :   YYSYMBOL_K_OR = 93,                      /* K_OR  */
     319              :   YYSYMBOL_K_PERFORM = 94,                 /* K_PERFORM  */
     320              :   YYSYMBOL_K_PG_CONTEXT = 95,              /* K_PG_CONTEXT  */
     321              :   YYSYMBOL_K_PG_DATATYPE_NAME = 96,        /* K_PG_DATATYPE_NAME  */
     322              :   YYSYMBOL_K_PG_EXCEPTION_CONTEXT = 97,    /* K_PG_EXCEPTION_CONTEXT  */
     323              :   YYSYMBOL_K_PG_EXCEPTION_DETAIL = 98,     /* K_PG_EXCEPTION_DETAIL  */
     324              :   YYSYMBOL_K_PG_EXCEPTION_HINT = 99,       /* K_PG_EXCEPTION_HINT  */
     325              :   YYSYMBOL_K_PG_ROUTINE_OID = 100,         /* K_PG_ROUTINE_OID  */
     326              :   YYSYMBOL_K_PRINT_STRICT_PARAMS = 101,    /* K_PRINT_STRICT_PARAMS  */
     327              :   YYSYMBOL_K_PRIOR = 102,                  /* K_PRIOR  */
     328              :   YYSYMBOL_K_QUERY = 103,                  /* K_QUERY  */
     329              :   YYSYMBOL_K_RAISE = 104,                  /* K_RAISE  */
     330              :   YYSYMBOL_K_RELATIVE = 105,               /* K_RELATIVE  */
     331              :   YYSYMBOL_K_RETURN = 106,                 /* K_RETURN  */
     332              :   YYSYMBOL_K_RETURNED_SQLSTATE = 107,      /* K_RETURNED_SQLSTATE  */
     333              :   YYSYMBOL_K_REVERSE = 108,                /* K_REVERSE  */
     334              :   YYSYMBOL_K_ROLLBACK = 109,               /* K_ROLLBACK  */
     335              :   YYSYMBOL_K_ROW_COUNT = 110,              /* K_ROW_COUNT  */
     336              :   YYSYMBOL_K_ROWTYPE = 111,                /* K_ROWTYPE  */
     337              :   YYSYMBOL_K_SCHEMA = 112,                 /* K_SCHEMA  */
     338              :   YYSYMBOL_K_SCHEMA_NAME = 113,            /* K_SCHEMA_NAME  */
     339              :   YYSYMBOL_K_SCROLL = 114,                 /* K_SCROLL  */
     340              :   YYSYMBOL_K_SLICE = 115,                  /* K_SLICE  */
     341              :   YYSYMBOL_K_SQLSTATE = 116,               /* K_SQLSTATE  */
     342              :   YYSYMBOL_K_STACKED = 117,                /* K_STACKED  */
     343              :   YYSYMBOL_K_STRICT = 118,                 /* K_STRICT  */
     344              :   YYSYMBOL_K_TABLE = 119,                  /* K_TABLE  */
     345              :   YYSYMBOL_K_TABLE_NAME = 120,             /* K_TABLE_NAME  */
     346              :   YYSYMBOL_K_THEN = 121,                   /* K_THEN  */
     347              :   YYSYMBOL_K_TO = 122,                     /* K_TO  */
     348              :   YYSYMBOL_K_TYPE = 123,                   /* K_TYPE  */
     349              :   YYSYMBOL_K_USE_COLUMN = 124,             /* K_USE_COLUMN  */
     350              :   YYSYMBOL_K_USE_VARIABLE = 125,           /* K_USE_VARIABLE  */
     351              :   YYSYMBOL_K_USING = 126,                  /* K_USING  */
     352              :   YYSYMBOL_K_VARIABLE_CONFLICT = 127,      /* K_VARIABLE_CONFLICT  */
     353              :   YYSYMBOL_K_WARNING = 128,                /* K_WARNING  */
     354              :   YYSYMBOL_K_WHEN = 129,                   /* K_WHEN  */
     355              :   YYSYMBOL_K_WHILE = 130,                  /* K_WHILE  */
     356              :   YYSYMBOL_131_ = 131,                     /* '#'  */
     357              :   YYSYMBOL_132_ = 132,                     /* ';'  */
     358              :   YYSYMBOL_133_ = 133,                     /* '('  */
     359              :   YYSYMBOL_134_ = 134,                     /* ')'  */
     360              :   YYSYMBOL_135_ = 135,                     /* ','  */
     361              :   YYSYMBOL_136_ = 136,                     /* '='  */
     362              :   YYSYMBOL_YYACCEPT = 137,                 /* $accept  */
     363              :   YYSYMBOL_pl_function = 138,              /* pl_function  */
     364              :   YYSYMBOL_comp_options = 139,             /* comp_options  */
     365              :   YYSYMBOL_comp_option = 140,              /* comp_option  */
     366              :   YYSYMBOL_option_value = 141,             /* option_value  */
     367              :   YYSYMBOL_opt_semi = 142,                 /* opt_semi  */
     368              :   YYSYMBOL_pl_block = 143,                 /* pl_block  */
     369              :   YYSYMBOL_decl_sect = 144,                /* decl_sect  */
     370              :   YYSYMBOL_decl_start = 145,               /* decl_start  */
     371              :   YYSYMBOL_decl_stmts = 146,               /* decl_stmts  */
     372              :   YYSYMBOL_decl_stmt = 147,                /* decl_stmt  */
     373              :   YYSYMBOL_decl_statement = 148,           /* decl_statement  */
     374              :   YYSYMBOL_149_1 = 149,                    /* $@1  */
     375              :   YYSYMBOL_opt_scrollable = 150,           /* opt_scrollable  */
     376              :   YYSYMBOL_decl_cursor_query = 151,        /* decl_cursor_query  */
     377              :   YYSYMBOL_decl_cursor_args = 152,         /* decl_cursor_args  */
     378              :   YYSYMBOL_decl_cursor_arglist = 153,      /* decl_cursor_arglist  */
     379              :   YYSYMBOL_decl_cursor_arg = 154,          /* decl_cursor_arg  */
     380              :   YYSYMBOL_decl_is_for = 155,              /* decl_is_for  */
     381              :   YYSYMBOL_decl_aliasitem = 156,           /* decl_aliasitem  */
     382              :   YYSYMBOL_decl_varname = 157,             /* decl_varname  */
     383              :   YYSYMBOL_decl_const = 158,               /* decl_const  */
     384              :   YYSYMBOL_decl_datatype = 159,            /* decl_datatype  */
     385              :   YYSYMBOL_decl_collate = 160,             /* decl_collate  */
     386              :   YYSYMBOL_decl_notnull = 161,             /* decl_notnull  */
     387              :   YYSYMBOL_decl_defval = 162,              /* decl_defval  */
     388              :   YYSYMBOL_decl_defkey = 163,              /* decl_defkey  */
     389              :   YYSYMBOL_assign_operator = 164,          /* assign_operator  */
     390              :   YYSYMBOL_proc_sect = 165,                /* proc_sect  */
     391              :   YYSYMBOL_proc_stmt = 166,                /* proc_stmt  */
     392              :   YYSYMBOL_stmt_perform = 167,             /* stmt_perform  */
     393              :   YYSYMBOL_stmt_call = 168,                /* stmt_call  */
     394              :   YYSYMBOL_stmt_assign = 169,              /* stmt_assign  */
     395              :   YYSYMBOL_stmt_getdiag = 170,             /* stmt_getdiag  */
     396              :   YYSYMBOL_getdiag_area_opt = 171,         /* getdiag_area_opt  */
     397              :   YYSYMBOL_getdiag_list = 172,             /* getdiag_list  */
     398              :   YYSYMBOL_getdiag_list_item = 173,        /* getdiag_list_item  */
     399              :   YYSYMBOL_getdiag_item = 174,             /* getdiag_item  */
     400              :   YYSYMBOL_getdiag_target = 175,           /* getdiag_target  */
     401              :   YYSYMBOL_stmt_if = 176,                  /* stmt_if  */
     402              :   YYSYMBOL_stmt_elsifs = 177,              /* stmt_elsifs  */
     403              :   YYSYMBOL_stmt_else = 178,                /* stmt_else  */
     404              :   YYSYMBOL_stmt_case = 179,                /* stmt_case  */
     405              :   YYSYMBOL_opt_expr_until_when = 180,      /* opt_expr_until_when  */
     406              :   YYSYMBOL_case_when_list = 181,           /* case_when_list  */
     407              :   YYSYMBOL_case_when = 182,                /* case_when  */
     408              :   YYSYMBOL_opt_case_else = 183,            /* opt_case_else  */
     409              :   YYSYMBOL_stmt_loop = 184,                /* stmt_loop  */
     410              :   YYSYMBOL_stmt_while = 185,               /* stmt_while  */
     411              :   YYSYMBOL_stmt_for = 186,                 /* stmt_for  */
     412              :   YYSYMBOL_for_control = 187,              /* for_control  */
     413              :   YYSYMBOL_for_variable = 188,             /* for_variable  */
     414              :   YYSYMBOL_stmt_foreach_a = 189,           /* stmt_foreach_a  */
     415              :   YYSYMBOL_foreach_slice = 190,            /* foreach_slice  */
     416              :   YYSYMBOL_stmt_exit = 191,                /* stmt_exit  */
     417              :   YYSYMBOL_exit_type = 192,                /* exit_type  */
     418              :   YYSYMBOL_stmt_return = 193,              /* stmt_return  */
     419              :   YYSYMBOL_stmt_raise = 194,               /* stmt_raise  */
     420              :   YYSYMBOL_stmt_assert = 195,              /* stmt_assert  */
     421              :   YYSYMBOL_loop_body = 196,                /* loop_body  */
     422              :   YYSYMBOL_stmt_execsql = 197,             /* stmt_execsql  */
     423              :   YYSYMBOL_stmt_dynexecute = 198,          /* stmt_dynexecute  */
     424              :   YYSYMBOL_stmt_open = 199,                /* stmt_open  */
     425              :   YYSYMBOL_stmt_fetch = 200,               /* stmt_fetch  */
     426              :   YYSYMBOL_stmt_move = 201,                /* stmt_move  */
     427              :   YYSYMBOL_opt_fetch_direction = 202,      /* opt_fetch_direction  */
     428              :   YYSYMBOL_stmt_close = 203,               /* stmt_close  */
     429              :   YYSYMBOL_stmt_null = 204,                /* stmt_null  */
     430              :   YYSYMBOL_stmt_commit = 205,              /* stmt_commit  */
     431              :   YYSYMBOL_stmt_rollback = 206,            /* stmt_rollback  */
     432              :   YYSYMBOL_opt_transaction_chain = 207,    /* opt_transaction_chain  */
     433              :   YYSYMBOL_cursor_variable = 208,          /* cursor_variable  */
     434              :   YYSYMBOL_exception_sect = 209,           /* exception_sect  */
     435              :   YYSYMBOL_210_2 = 210,                    /* @2  */
     436              :   YYSYMBOL_proc_exceptions = 211,          /* proc_exceptions  */
     437              :   YYSYMBOL_proc_exception = 212,           /* proc_exception  */
     438              :   YYSYMBOL_proc_conditions = 213,          /* proc_conditions  */
     439              :   YYSYMBOL_proc_condition = 214,           /* proc_condition  */
     440              :   YYSYMBOL_expr_until_semi = 215,          /* expr_until_semi  */
     441              :   YYSYMBOL_expr_until_then = 216,          /* expr_until_then  */
     442              :   YYSYMBOL_expr_until_loop = 217,          /* expr_until_loop  */
     443              :   YYSYMBOL_opt_block_label = 218,          /* opt_block_label  */
     444              :   YYSYMBOL_opt_loop_label = 219,           /* opt_loop_label  */
     445              :   YYSYMBOL_opt_label = 220,                /* opt_label  */
     446              :   YYSYMBOL_opt_exitcond = 221,             /* opt_exitcond  */
     447              :   YYSYMBOL_any_identifier = 222,           /* any_identifier  */
     448              :   YYSYMBOL_unreserved_keyword = 223        /* unreserved_keyword  */
     449              : };
     450              : typedef enum yysymbol_kind_t yysymbol_kind_t;
     451              : 
     452              : 
     453              : 
     454              : 
     455              : #ifdef short
     456              : # undef short
     457              : #endif
     458              : 
     459              : /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
     460              :    <limits.h> and (if available) <stdint.h> are included
     461              :    so that the code can choose integer types of a good width.  */
     462              : 
     463              : #ifndef __PTRDIFF_MAX__
     464              : # include <limits.h> /* INFRINGES ON USER NAME SPACE */
     465              : # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
     466              : #  include <stdint.h> /* INFRINGES ON USER NAME SPACE */
     467              : #  define YY_STDINT_H
     468              : # endif
     469              : #endif
     470              : 
     471              : /* Narrow types that promote to a signed type and that can represent a
     472              :    signed or unsigned integer of at least N bits.  In tables they can
     473              :    save space and decrease cache pressure.  Promoting to a signed type
     474              :    helps avoid bugs in integer arithmetic.  */
     475              : 
     476              : #ifdef __INT_LEAST8_MAX__
     477              : typedef __INT_LEAST8_TYPE__ yytype_int8;
     478              : #elif defined YY_STDINT_H
     479              : typedef int_least8_t yytype_int8;
     480              : #else
     481              : typedef signed char yytype_int8;
     482              : #endif
     483              : 
     484              : #ifdef __INT_LEAST16_MAX__
     485              : typedef __INT_LEAST16_TYPE__ yytype_int16;
     486              : #elif defined YY_STDINT_H
     487              : typedef int_least16_t yytype_int16;
     488              : #else
     489              : typedef short yytype_int16;
     490              : #endif
     491              : 
     492              : /* Work around bug in HP-UX 11.23, which defines these macros
     493              :    incorrectly for preprocessor constants.  This workaround can likely
     494              :    be removed in 2023, as HPE has promised support for HP-UX 11.23
     495              :    (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
     496              :    <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>.  */
     497              : #ifdef __hpux
     498              : # undef UINT_LEAST8_MAX
     499              : # undef UINT_LEAST16_MAX
     500              : # define UINT_LEAST8_MAX 255
     501              : # define UINT_LEAST16_MAX 65535
     502              : #endif
     503              : 
     504              : #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
     505              : typedef __UINT_LEAST8_TYPE__ yytype_uint8;
     506              : #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
     507              :        && UINT_LEAST8_MAX <= INT_MAX)
     508              : typedef uint_least8_t yytype_uint8;
     509              : #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
     510              : typedef unsigned char yytype_uint8;
     511              : #else
     512              : typedef short yytype_uint8;
     513              : #endif
     514              : 
     515              : #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
     516              : typedef __UINT_LEAST16_TYPE__ yytype_uint16;
     517              : #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
     518              :        && UINT_LEAST16_MAX <= INT_MAX)
     519              : typedef uint_least16_t yytype_uint16;
     520              : #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
     521              : typedef unsigned short yytype_uint16;
     522              : #else
     523              : typedef int yytype_uint16;
     524              : #endif
     525              : 
     526              : #ifndef YYPTRDIFF_T
     527              : # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
     528              : #  define YYPTRDIFF_T __PTRDIFF_TYPE__
     529              : #  define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
     530              : # elif defined PTRDIFF_MAX
     531              : #  ifndef ptrdiff_t
     532              : #   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
     533              : #  endif
     534              : #  define YYPTRDIFF_T ptrdiff_t
     535              : #  define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
     536              : # else
     537              : #  define YYPTRDIFF_T long
     538              : #  define YYPTRDIFF_MAXIMUM LONG_MAX
     539              : # endif
     540              : #endif
     541              : 
     542              : #ifndef YYSIZE_T
     543              : # ifdef __SIZE_TYPE__
     544              : #  define YYSIZE_T __SIZE_TYPE__
     545              : # elif defined size_t
     546              : #  define YYSIZE_T size_t
     547              : # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
     548              : #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
     549              : #  define YYSIZE_T size_t
     550              : # else
     551              : #  define YYSIZE_T unsigned
     552              : # endif
     553              : #endif
     554              : 
     555              : #define YYSIZE_MAXIMUM                                  \
     556              :   YY_CAST (YYPTRDIFF_T,                                 \
     557              :            (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1)  \
     558              :             ? YYPTRDIFF_MAXIMUM                         \
     559              :             : YY_CAST (YYSIZE_T, -1)))
     560              : 
     561              : #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
     562              : 
     563              : 
     564              : /* Stored state numbers (used for stacks). */
     565              : typedef yytype_int16 yy_state_t;
     566              : 
     567              : /* State numbers in computations.  */
     568              : typedef int yy_state_fast_t;
     569              : 
     570              : #ifndef YY_
     571              : # if defined YYENABLE_NLS && YYENABLE_NLS
     572              : #  if ENABLE_NLS
     573              : #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
     574              : #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
     575              : #  endif
     576              : # endif
     577              : # ifndef YY_
     578              : #  define YY_(Msgid) Msgid
     579              : # endif
     580              : #endif
     581              : 
     582              : 
     583              : #ifndef YY_ATTRIBUTE_PURE
     584              : # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
     585              : #  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
     586              : # else
     587              : #  define YY_ATTRIBUTE_PURE
     588              : # endif
     589              : #endif
     590              : 
     591              : #ifndef YY_ATTRIBUTE_UNUSED
     592              : # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
     593              : #  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
     594              : # else
     595              : #  define YY_ATTRIBUTE_UNUSED
     596              : # endif
     597              : #endif
     598              : 
     599              : /* Suppress unused-variable warnings by "using" E.  */
     600              : #if ! defined lint || defined __GNUC__
     601              : # define YY_USE(E) ((void) (E))
     602              : #else
     603              : # define YY_USE(E) /* empty */
     604              : #endif
     605              : 
     606              : /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
     607              : #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
     608              : # if __GNUC__ * 100 + __GNUC_MINOR__ < 407
     609              : #  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
     610              :     _Pragma ("GCC diagnostic push")                                     \
     611              :     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
     612              : # else
     613              : #  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
     614              :     _Pragma ("GCC diagnostic push")                                     \
     615              :     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")              \
     616              :     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
     617              : # endif
     618              : # define YY_IGNORE_MAYBE_UNINITIALIZED_END      \
     619              :     _Pragma ("GCC diagnostic pop")
     620              : #else
     621              : # define YY_INITIAL_VALUE(Value) Value
     622              : #endif
     623              : #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
     624              : # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
     625              : # define YY_IGNORE_MAYBE_UNINITIALIZED_END
     626              : #endif
     627              : #ifndef YY_INITIAL_VALUE
     628              : # define YY_INITIAL_VALUE(Value) /* Nothing. */
     629              : #endif
     630              : 
     631              : #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
     632              : # define YY_IGNORE_USELESS_CAST_BEGIN                          \
     633              :     _Pragma ("GCC diagnostic push")                            \
     634              :     _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
     635              : # define YY_IGNORE_USELESS_CAST_END            \
     636              :     _Pragma ("GCC diagnostic pop")
     637              : #endif
     638              : #ifndef YY_IGNORE_USELESS_CAST_BEGIN
     639              : # define YY_IGNORE_USELESS_CAST_BEGIN
     640              : # define YY_IGNORE_USELESS_CAST_END
     641              : #endif
     642              : 
     643              : 
     644              : #define YY_ASSERT(E) ((void) (0 && (E)))
     645              : 
     646              : #if !defined yyoverflow
     647              : 
     648              : /* The parser invokes alloca or malloc; define the necessary symbols.  */
     649              : 
     650              : # ifdef YYSTACK_USE_ALLOCA
     651              : #  if YYSTACK_USE_ALLOCA
     652              : #   ifdef __GNUC__
     653              : #    define YYSTACK_ALLOC __builtin_alloca
     654              : #   elif defined __BUILTIN_VA_ARG_INCR
     655              : #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
     656              : #   elif defined _AIX
     657              : #    define YYSTACK_ALLOC __alloca
     658              : #   elif defined _MSC_VER
     659              : #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
     660              : #    define alloca _alloca
     661              : #   else
     662              : #    define YYSTACK_ALLOC alloca
     663              : #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
     664              : #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
     665              :       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
     666              : #     ifndef EXIT_SUCCESS
     667              : #      define EXIT_SUCCESS 0
     668              : #     endif
     669              : #    endif
     670              : #   endif
     671              : #  endif
     672              : # endif
     673              : 
     674              : # ifdef YYSTACK_ALLOC
     675              :    /* Pacify GCC's 'empty if-body' warning.  */
     676              : #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
     677              : #  ifndef YYSTACK_ALLOC_MAXIMUM
     678              :     /* The OS might guarantee only one guard page at the bottom of the stack,
     679              :        and a page size can be as small as 4096 bytes.  So we cannot safely
     680              :        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
     681              :        to allow for a few compiler-allocated temporary stack slots.  */
     682              : #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
     683              : #  endif
     684              : # else
     685              : #  define YYSTACK_ALLOC YYMALLOC
     686              : #  define YYSTACK_FREE YYFREE
     687              : #  ifndef YYSTACK_ALLOC_MAXIMUM
     688              : #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
     689              : #  endif
     690              : #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
     691              :        && ! ((defined YYMALLOC || defined malloc) \
     692              :              && (defined YYFREE || defined free)))
     693              : #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
     694              : #   ifndef EXIT_SUCCESS
     695              : #    define EXIT_SUCCESS 0
     696              : #   endif
     697              : #  endif
     698              : #  ifndef YYMALLOC
     699              : #   define YYMALLOC malloc
     700              : #   if ! defined malloc && ! defined EXIT_SUCCESS
     701              : void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
     702              : #   endif
     703              : #  endif
     704              : #  ifndef YYFREE
     705              : #   define YYFREE free
     706              : #   if ! defined free && ! defined EXIT_SUCCESS
     707              : void free (void *); /* INFRINGES ON USER NAME SPACE */
     708              : #   endif
     709              : #  endif
     710              : # endif
     711              : #endif /* !defined yyoverflow */
     712              : 
     713              : #if (! defined yyoverflow \
     714              :      && (! defined __cplusplus \
     715              :          || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
     716              :              && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
     717              : 
     718              : /* A type that is properly aligned for any stack member.  */
     719              : union yyalloc
     720              : {
     721              :   yy_state_t yyss_alloc;
     722              :   YYSTYPE yyvs_alloc;
     723              :   YYLTYPE yyls_alloc;
     724              : };
     725              : 
     726              : /* The size of the maximum gap between one aligned stack and the next.  */
     727              : # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
     728              : 
     729              : /* The size of an array large to enough to hold all stacks, each with
     730              :    N elements.  */
     731              : # define YYSTACK_BYTES(N) \
     732              :      ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \
     733              :              + YYSIZEOF (YYLTYPE)) \
     734              :       + 2 * YYSTACK_GAP_MAXIMUM)
     735              : 
     736              : # define YYCOPY_NEEDED 1
     737              : 
     738              : /* Relocate STACK from its old location to the new one.  The
     739              :    local variables YYSIZE and YYSTACKSIZE give the old and new number of
     740              :    elements in the stack, and YYPTR gives the new location of the
     741              :    stack.  Advance YYPTR to a properly aligned location for the next
     742              :    stack.  */
     743              : # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
     744              :     do                                                                  \
     745              :       {                                                                 \
     746              :         YYPTRDIFF_T yynewbytes;                                         \
     747              :         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
     748              :         Stack = &yyptr->Stack_alloc;                                    \
     749              :         yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
     750              :         yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
     751              :       }                                                                 \
     752              :     while (0)
     753              : 
     754              : #endif
     755              : 
     756              : #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
     757              : /* Copy COUNT objects from SRC to DST.  The source and destination do
     758              :    not overlap.  */
     759              : # ifndef YYCOPY
     760              : #  if defined __GNUC__ && 1 < __GNUC__
     761              : #   define YYCOPY(Dst, Src, Count) \
     762              :       __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
     763              : #  else
     764              : #   define YYCOPY(Dst, Src, Count)              \
     765              :       do                                        \
     766              :         {                                       \
     767              :           YYPTRDIFF_T yyi;                      \
     768              :           for (yyi = 0; yyi < (Count); yyi++)   \
     769              :             (Dst)[yyi] = (Src)[yyi];            \
     770              :         }                                       \
     771              :       while (0)
     772              : #  endif
     773              : # endif
     774              : #endif /* !YYCOPY_NEEDED */
     775              : 
     776              : /* YYFINAL -- State number of the termination state.  */
     777              : #define YYFINAL  3
     778              : /* YYLAST -- Last index in YYTABLE.  */
     779              : #define YYLAST   1305
     780              : 
     781              : /* YYNTOKENS -- Number of terminals.  */
     782              : #define YYNTOKENS  137
     783              : /* YYNNTS -- Number of nonterminals.  */
     784              : #define YYNNTS  87
     785              : /* YYNRULES -- Number of rules.  */
     786              : #define YYNRULES  255
     787              : /* YYNSTATES -- Number of states.  */
     788              : #define YYNSTATES  336
     789              : 
     790              : /* YYMAXUTOK -- Last valid token kind.  */
     791              : #define YYMAXUTOK   385
     792              : 
     793              : 
     794              : /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
     795              :    as returned by yylex, with out-of-bounds checking.  */
     796              : #define YYTRANSLATE(YYX)                                \
     797              :   (0 <= (YYX) && (YYX) <= YYMAXUTOK                     \
     798              :    ? YY_CAST (yysymbol_kind_t, yytranslate[YYX])        \
     799              :    : YYSYMBOL_YYUNDEF)
     800              : 
     801              : /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
     802              :    as returned by yylex.  */
     803              : static const yytype_uint8 yytranslate[] =
     804              : {
     805              :        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     806              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     807              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     808              :        2,     2,     2,     2,     2,   131,     2,     2,     2,     2,
     809              :      133,   134,     2,     2,   135,     2,     2,     2,     2,     2,
     810              :        2,     2,     2,     2,     2,     2,     2,     2,     2,   132,
     811              :        2,   136,     2,     2,     2,     2,     2,     2,     2,     2,
     812              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     813              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     814              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     815              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     816              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     817              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     818              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     819              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     820              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     821              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     822              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     823              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     824              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     825              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     826              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     827              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     828              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     829              :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     830              :        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
     831              :        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
     832              :       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
     833              :       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
     834              :       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
     835              :       45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
     836              :       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
     837              :       65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
     838              :       75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
     839              :       85,    86,    87,    88,    89,    90,    91,    92,    93,    94,
     840              :       95,    96,    97,    98,    99,   100,   101,   102,   103,   104,
     841              :      105,   106,   107,   108,   109,   110,   111,   112,   113,   114,
     842              :      115,   116,   117,   118,   119,   120,   121,   122,   123,   124,
     843              :      125,   126,   127,   128,   129,   130
     844              : };
     845              : 
     846              : #if YYDEBUG
     847              : /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
     848              : static const yytype_int16 yyrline[] =
     849              : {
     850              :        0,   374,   374,   381,   382,   385,   389,   398,   402,   406,
     851              :      412,   416,   421,   422,   425,   448,   456,   463,   472,   484,
     852              :      485,   488,   489,   493,   506,   548,   554,   553,   580,   583,
     853              :      587,   594,   600,   603,   634,   638,   644,   652,   653,   655,
     854              :      670,   685,   713,   741,   772,   773,   778,   790,   791,   796,
     855              :      801,   808,   809,   813,   815,   821,   822,   830,   831,   835,
     856              :      836,   846,   848,   850,   852,   854,   856,   858,   860,   862,
     857              :      864,   866,   868,   870,   872,   874,   876,   878,   880,   882,
     858              :      884,   886,   888,   890,   892,   896,   933,   951,   972,  1013,
     859              :     1077,  1080,  1084,  1090,  1094,  1100,  1113,  1160,  1178,  1183,
     860              :     1190,  1208,  1211,  1225,  1228,  1234,  1241,  1255,  1259,  1265,
     861              :     1277,  1280,  1295,  1313,  1332,  1366,  1625,  1653,  1667,  1674,
     862              :     1713,  1716,  1722,  1775,  1779,  1785,  1811,  1957,  1981,  1999,
     863              :     2003,  2007,  2011,  2022,  2035,  2101,  2180,  2210,  2223,  2228,
     864              :     2242,  2249,  2263,  2278,  2279,  2280,  2284,  2306,  2311,  2319,
     865              :     2321,  2320,  2364,  2368,  2374,  2387,  2396,  2402,  2439,  2443,
     866              :     2447,  2451,  2455,  2463,  2467,  2475,  2478,  2485,  2487,  2494,
     867              :     2498,  2502,  2511,  2512,  2513,  2514,  2515,  2516,  2517,  2518,
     868              :     2519,  2520,  2521,  2522,  2523,  2524,  2525,  2526,  2527,  2528,
     869              :     2529,  2530,  2531,  2532,  2533,  2534,  2535,  2536,  2537,  2538,
     870              :     2539,  2540,  2541,  2542,  2543,  2544,  2545,  2546,  2547,  2548,
     871              :     2549,  2550,  2551,  2552,  2553,  2554,  2555,  2556,  2557,  2558,
     872              :     2559,  2560,  2561,  2562,  2563,  2564,  2565,  2566,  2567,  2568,
     873              :     2569,  2570,  2571,  2572,  2573,  2574,  2575,  2576,  2577,  2578,
     874              :     2579,  2580,  2581,  2582,  2583,  2584,  2585,  2586,  2587,  2588,
     875              :     2589,  2590,  2591,  2592,  2593,  2594
     876              : };
     877              : #endif
     878              : 
     879              : /** Accessing symbol of state STATE.  */
     880              : #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
     881              : 
     882              : #if YYDEBUG || 0
     883              : /* The user-facing name of the symbol whose (internal) number is
     884              :    YYSYMBOL.  No bounds checking.  */
     885              : static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
     886              : 
     887              : /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
     888              :    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
     889              : static const char *const yytname[] =
     890              : {
     891              :   "\"end of file\"", "error", "\"invalid token\"", "IDENT", "UIDENT",
     892              :   "FCONST", "SCONST", "USCONST", "BCONST", "XCONST", "Op", "ICONST",
     893              :   "PARAM", "TYPECAST", "DOT_DOT", "COLON_EQUALS", "EQUALS_GREATER",
     894              :   "LESS_EQUALS", "GREATER_EQUALS", "NOT_EQUALS", "T_WORD", "T_CWORD",
     895              :   "T_DATUM", "LESS_LESS", "GREATER_GREATER", "K_ABSOLUTE", "K_ALIAS",
     896              :   "K_ALL", "K_AND", "K_ARRAY", "K_ASSERT", "K_BACKWARD", "K_BEGIN", "K_BY",
     897              :   "K_CALL", "K_CASE", "K_CHAIN", "K_CLOSE", "K_COLLATE", "K_COLUMN",
     898              :   "K_COLUMN_NAME", "K_COMMIT", "K_CONSTANT", "K_CONSTRAINT",
     899              :   "K_CONSTRAINT_NAME", "K_CONTINUE", "K_CURRENT", "K_CURSOR", "K_DATATYPE",
     900              :   "K_DEBUG", "K_DECLARE", "K_DEFAULT", "K_DETAIL", "K_DIAGNOSTICS", "K_DO",
     901              :   "K_DUMP", "K_ELSE", "K_ELSIF", "K_END", "K_ERRCODE", "K_ERROR",
     902              :   "K_EXCEPTION", "K_EXECUTE", "K_EXIT", "K_FETCH", "K_FIRST", "K_FOR",
     903              :   "K_FOREACH", "K_FORWARD", "K_FROM", "K_GET", "K_HINT", "K_IF",
     904              :   "K_IMPORT", "K_IN", "K_INFO", "K_INSERT", "K_INTO", "K_IS", "K_LAST",
     905              :   "K_LOG", "K_LOOP", "K_MERGE", "K_MESSAGE", "K_MESSAGE_TEXT", "K_MOVE",
     906              :   "K_NEXT", "K_NO", "K_NOT", "K_NOTICE", "K_NULL", "K_OPEN", "K_OPTION",
     907              :   "K_OR", "K_PERFORM", "K_PG_CONTEXT", "K_PG_DATATYPE_NAME",
     908              :   "K_PG_EXCEPTION_CONTEXT", "K_PG_EXCEPTION_DETAIL", "K_PG_EXCEPTION_HINT",
     909              :   "K_PG_ROUTINE_OID", "K_PRINT_STRICT_PARAMS", "K_PRIOR", "K_QUERY",
     910              :   "K_RAISE", "K_RELATIVE", "K_RETURN", "K_RETURNED_SQLSTATE", "K_REVERSE",
     911              :   "K_ROLLBACK", "K_ROW_COUNT", "K_ROWTYPE", "K_SCHEMA", "K_SCHEMA_NAME",
     912              :   "K_SCROLL", "K_SLICE", "K_SQLSTATE", "K_STACKED", "K_STRICT", "K_TABLE",
     913              :   "K_TABLE_NAME", "K_THEN", "K_TO", "K_TYPE", "K_USE_COLUMN",
     914              :   "K_USE_VARIABLE", "K_USING", "K_VARIABLE_CONFLICT", "K_WARNING",
     915              :   "K_WHEN", "K_WHILE", "'#'", "';'", "'('", "')'", "','", "'='", "$accept",
     916              :   "pl_function", "comp_options", "comp_option", "option_value", "opt_semi",
     917              :   "pl_block", "decl_sect", "decl_start", "decl_stmts", "decl_stmt",
     918              :   "decl_statement", "$@1", "opt_scrollable", "decl_cursor_query",
     919              :   "decl_cursor_args", "decl_cursor_arglist", "decl_cursor_arg",
     920              :   "decl_is_for", "decl_aliasitem", "decl_varname", "decl_const",
     921              :   "decl_datatype", "decl_collate", "decl_notnull", "decl_defval",
     922              :   "decl_defkey", "assign_operator", "proc_sect", "proc_stmt",
     923              :   "stmt_perform", "stmt_call", "stmt_assign", "stmt_getdiag",
     924              :   "getdiag_area_opt", "getdiag_list", "getdiag_list_item", "getdiag_item",
     925              :   "getdiag_target", "stmt_if", "stmt_elsifs", "stmt_else", "stmt_case",
     926              :   "opt_expr_until_when", "case_when_list", "case_when", "opt_case_else",
     927              :   "stmt_loop", "stmt_while", "stmt_for", "for_control", "for_variable",
     928              :   "stmt_foreach_a", "foreach_slice", "stmt_exit", "exit_type",
     929              :   "stmt_return", "stmt_raise", "stmt_assert", "loop_body", "stmt_execsql",
     930              :   "stmt_dynexecute", "stmt_open", "stmt_fetch", "stmt_move",
     931              :   "opt_fetch_direction", "stmt_close", "stmt_null", "stmt_commit",
     932              :   "stmt_rollback", "opt_transaction_chain", "cursor_variable",
     933              :   "exception_sect", "@2", "proc_exceptions", "proc_exception",
     934              :   "proc_conditions", "proc_condition", "expr_until_semi",
     935              :   "expr_until_then", "expr_until_loop", "opt_block_label",
     936              :   "opt_loop_label", "opt_label", "opt_exitcond", "any_identifier",
     937              :   "unreserved_keyword", YY_NULLPTR
     938              : };
     939              : 
     940              : static const char *
     941              : yysymbol_name (yysymbol_kind_t yysymbol)
     942              : {
     943              :   return yytname[yysymbol];
     944              : }
     945              : #endif
     946              : 
     947              : #define YYPACT_NINF (-245)
     948              : 
     949              : #define yypact_value_is_default(Yyn) \
     950              :   ((Yyn) == YYPACT_NINF)
     951              : 
     952              : #define YYTABLE_NINF (-163)
     953              : 
     954              : #define yytable_value_is_error(Yyn) \
     955              :   0
     956              : 
     957              : /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
     958              :    STATE-NUM.  */
     959              : static const yytype_int16 yypact[] =
     960              : {
     961              :     -245,    29,   -18,  -245,   327,   -51,  -245,   -99,     8,     7,
     962              :     -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     963              :     -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     964              :     -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     965              :     -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     966              :     -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     967              :     -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     968              :     -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     969              :     -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     970              :     -245,  -245,  -245,  -245,  -245,  -245,    54,  -245,    15,   651,
     971              :      -35,  -245,  -245,  -245,  -245,   218,  -245,  -245,  -245,  -245,
     972              :     -245,  -245,  -245,  -245,   998,  -245,   327,  -245,   218,  -245,
     973              :     -245,   -10,  -245,  -245,  -245,  -245,   327,  -245,  -245,  -245,
     974              :       46,    66,  -245,  -245,  -245,  -245,  -245,  -245,   -42,  -245,
     975              :     -245,  -245,  -245,  -245,   -40,    46,  -245,  -245,  -245,    66,
     976              :      -36,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     977              :     -245,  -245,  -245,   327,  -245,  -245,  -245,  -245,  -245,  -245,
     978              :     -245,  -245,  -245,  -245,  -245,  -245,    39,   -39,    81,  -245,
     979              :       37,  -245,    -3,  -245,    59,  -245,    85,   -19,  -245,  -245,
     980              :     -245,   -16,    -5,   -15,    -9,    46,  -245,  -245,    61,  -245,
     981              :       46,  -245,  -245,    -7,  -245,   -74,  -245,   327,    64,    64,
     982              :     -245,  -245,  -245,   436,  -245,  -245,    83,     4,  -245,   -41,
     983              :     -245,  -245,  -245,    90,  -245,   327,    -9,  -245,    50,    79,
     984              :      866,     2,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     985              :     -245,    55,    13,  1064,  -245,  -245,  -245,  -245,     3,  -245,
     986              :        5,   545,    48,  -245,  -245,  -245,    88,  -245,   -75,  -245,
     987              :     -245,  -245,  -245,  -245,  -245,  -245,   -72,  -245,   -12,    -8,
     988              :     -245,  -245,  -245,  -245,   126,    65,    60,  -245,  -245,   757,
     989              :      -22,  -245,  -245,  -245,    53,   -13,   -11,  1130,   113,   327,
     990              :     -245,  -245,    79,  -245,  -245,  -245,  -245,  -245,    91,  -245,
     991              :      121,   327,   -62,  -245,  -245,  -245,  -245,  -245,  -245,  -245,
     992              :     -245,  -245,  -245,  -245,    20,  -245,   110,  -245,  -245,  1196,
     993              :     -245,    82,  -245,    26,  -245,   757,  -245,  -245,  -245,   932,
     994              :       27,  -245,  -245,  -245,  -245,  -245
     995              : };
     996              : 
     997              : /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
     998              :    Performed when YYTABLE does not specify something else to do.  Zero
     999              :    means the default is an error.  */
    1000              : static const yytype_uint8 yydefact[] =
    1001              : {
    1002              :        3,     0,   161,     1,     0,     0,     4,    12,     0,    15,
    1003              :      169,   171,   172,   173,   174,   175,   176,   177,   178,   179,
    1004              :      180,   181,   182,   183,   184,   185,   186,   187,   188,   189,
    1005              :      190,   191,   192,   193,   194,   195,   196,   197,   198,   199,
    1006              :      200,   201,   202,   203,   204,   205,   206,   207,   208,   209,
    1007              :      210,   211,   212,   213,   214,   215,   216,   217,   218,   219,
    1008              :      220,   221,   222,   223,   224,   225,   226,   227,   228,   229,
    1009              :      230,   231,   232,   233,   234,   235,   236,   237,   238,   239,
    1010              :      240,   241,   242,   243,   244,   245,   246,   247,   248,   249,
    1011              :      250,   251,   252,   253,   254,   255,     0,   170,     0,     0,
    1012              :        0,    13,     2,    59,    18,    16,   162,     5,    10,     6,
    1013              :       11,     7,     9,     8,   163,    42,     0,    22,    17,    20,
    1014              :       21,    44,    43,   132,   133,    88,     0,   127,    86,   106,
    1015              :        0,   145,   124,    87,   150,   134,   123,   138,    90,   159,
    1016              :      129,   130,   131,   138,     0,     0,    85,   126,   125,   145,
    1017              :        0,    60,    75,    76,    62,    77,    63,    64,    65,    66,
    1018              :       67,    68,    69,   165,    70,    71,    72,    73,    74,    78,
    1019              :       79,    80,    81,    82,    83,    84,     0,     0,     0,    19,
    1020              :        0,    45,     0,    30,     0,    46,     0,     0,   147,   148,
    1021              :      146,     0,     0,     0,     0,     0,    91,    92,     0,    59,
    1022              :        0,   140,   135,     0,    61,     0,   166,   165,     0,     0,
    1023              :       59,   160,    23,     0,    29,    26,    47,   164,   159,   110,
    1024              :      108,   139,   143,     0,   141,     0,   151,   153,     0,     0,
    1025              :      163,     0,   142,   158,   167,   122,    14,   117,   118,   116,
    1026              :       59,     0,   120,   163,   112,    59,    39,    41,     0,    40,
    1027              :       32,     0,    51,    59,    59,   107,     0,   144,     0,   156,
    1028              :      157,   152,   136,    98,    99,    97,     0,    94,     0,   103,
    1029              :      137,   168,   114,   115,     0,     0,     0,   113,    25,     0,
    1030              :        0,    48,    50,    49,     0,     0,   163,   163,     0,     0,
    1031              :       59,    89,     0,    58,    57,    96,    59,   159,     0,   121,
    1032              :        0,   165,     0,    34,    46,    38,    37,    31,    52,    56,
    1033              :       53,    24,    54,    55,     0,   155,   163,    93,    95,   163,
    1034              :       59,     0,   160,     0,    33,     0,    36,    27,   105,   163,
    1035              :        0,    59,   128,    35,   100,   119
    1036              : };
    1037              : 
    1038              : /* YYPGOTO[NTERM-NUM].  */
    1039              : static const yytype_int16 yypgoto[] =
    1040              : {
    1041              :     -245,  -245,  -245,  -245,  -245,  -245,   159,  -245,  -245,  -245,
    1042              :       44,  -245,  -245,  -245,  -245,  -245,  -245,  -162,  -245,  -245,
    1043              :     -244,  -245,  -139,  -245,  -245,  -245,  -245,  -119,   -97,  -245,
    1044              :     -245,  -245,  -245,  -245,  -245,  -245,  -125,  -245,  -245,  -245,
    1045              :     -245,  -245,  -245,  -245,  -245,   -50,  -245,  -245,  -245,  -245,
    1046              :     -245,   -38,  -245,  -245,  -245,  -245,  -245,  -245,  -245,  -223,
    1047              :     -245,  -245,  -245,  -245,  -245,    32,  -245,  -245,  -245,  -245,
    1048              :       21,  -131,  -245,  -245,  -245,   -49,  -245,  -113,  -245,  -210,
    1049              :     -144,  -245,  -245,  -194,  -245,    -4,   -98
    1050              : };
    1051              : 
    1052              : /* YYDEFGOTO[NTERM-NUM].  */
    1053              : static const yytype_int16 yydefgoto[] =
    1054              : {
    1055              :        0,     1,     2,     6,   109,   102,   150,     8,   105,   118,
    1056              :      119,   120,   250,   184,   327,   280,   302,   303,   307,   248,
    1057              :      121,   185,   216,   252,   285,   311,   312,   295,   243,   151,
    1058              :      152,   153,   154,   155,   198,   266,   267,   318,   268,   156,
    1059              :      269,   298,   157,   187,   219,   220,   256,   158,   159,   160,
    1060              :      240,   241,   161,   275,   162,   163,   164,   165,   166,   244,
    1061              :      167,   168,   169,   170,   171,   195,   172,   173,   174,   175,
    1062              :      193,   191,   176,   194,   226,   227,   258,   259,   271,   199,
    1063              :      245,     9,   177,   205,   235,   206,    97
    1064              : };
    1065              : 
    1066              : /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
    1067              :    positive, shift that token.  If negative, reduce the rule whose
    1068              :    number is the opposite.  If YYTABLE_NINF, syntax error.  */
    1069              : static const yytype_int16 yytable[] =
    1070              : {
    1071              :       96,   110,   293,   293,   196,     4,   114,   122,   253,   123,
    1072              :      124,   125,   126,   236,   202,   254,   180,   272,   289,   127,
    1073              :      122,  -161,   277,   128,   129,   111,   130,   208,   209,     3,
    1074              :      131,   222,   181,   101,   132,   304,  -162,   -28,   309,  -161,
    1075              :      103,    98,   210,   133,   305,  -109,   290,  -109,   296,   297,
    1076              :       99,   135,   136,   137,  -162,   233,   306,   104,   234,   138,
    1077              :      291,   139,   140,   292,   228,   141,   188,   189,   190,   231,
    1078              :      107,   142,   324,   325,   143,   197,   100,   182,   106,   144,
    1079              :      145,   304,   223,   146,   237,   238,   239,   320,   218,   112,
    1080              :      113,   211,   201,   147,   192,   148,   204,   207,   149,   263,
    1081              :      264,   265,   230,   213,   183,   212,   215,   323,   335,   217,
    1082              :      218,   214,   178,     5,   229,   249,   221,   224,  -109,   310,
    1083              :      225,   251,   186,   294,   294,   232,   257,   262,   274,   273,
    1084              :      123,   124,   125,   126,   270,   278,   284,   299,   279,   300,
    1085              :      127,   301,  -161,   308,   128,   129,   288,   130,   314,   321,
    1086              :      322,   131,   328,   283,   330,   132,   286,   287,   332,   334,
    1087              :     -161,     7,   179,   333,   133,   326,   313,   317,  -154,   255,
    1088              :      203,   242,   135,   136,   137,   200,   315,   261,   331,     0,
    1089              :      138,   122,   139,   140,     0,     0,   141,     0,     0,     0,
    1090              :        0,     0,   142,   316,     0,   143,     0,     0,     0,   319,
    1091              :      144,   145,     0,     0,   146,     0,     0,     0,     0,     0,
    1092              :        0,     0,     0,     0,   147,     0,   148,     0,     0,   149,
    1093              :        0,   260,     0,   329,     0,     0,     0,   122,     0,     0,
    1094              :        0,     0,     0,     0,     0,     0,     0,     0,   115,  -154,
    1095              :        0,   116,     0,    12,    13,     0,    14,    15,    16,    17,
    1096              :        0,     0,    18,     0,    19,    20,    21,    22,    23,    24,
    1097              :       25,    26,    27,    28,    29,    30,    31,    32,   117,    33,
    1098              :       34,    35,    36,    37,     0,    38,     0,    39,    40,    41,
    1099              :       42,    43,    44,    45,     0,   260,    46,     0,    47,    48,
    1100              :        0,    49,     0,    50,    51,     0,    52,    53,    54,     0,
    1101              :       55,    56,    57,    58,    59,    60,     0,    61,     0,    62,
    1102              :       63,     0,    64,    65,    66,    67,    68,    69,    70,    71,
    1103              :       72,    73,    74,    75,    76,    77,    78,    79,    80,    81,
    1104              :       82,    83,    84,    85,    86,    87,    88,    89,    90,     0,
    1105              :        0,    91,    92,    93,     0,    94,    95,    10,     0,    11,
    1106              :        0,     0,    12,    13,     0,    14,    15,    16,    17,     0,
    1107              :        0,    18,     0,    19,    20,    21,    22,    23,    24,    25,
    1108              :       26,    27,    28,    29,    30,    31,    32,     0,    33,    34,
    1109              :       35,    36,    37,     0,    38,     0,    39,    40,    41,    42,
    1110              :       43,    44,    45,     0,     0,    46,     0,    47,    48,     0,
    1111              :       49,     0,    50,    51,     0,    52,    53,    54,     0,    55,
    1112              :       56,    57,    58,    59,    60,     0,    61,     0,    62,    63,
    1113              :        0,    64,    65,    66,    67,    68,    69,    70,    71,    72,
    1114              :       73,    74,    75,    76,    77,    78,    79,    80,    81,    82,
    1115              :       83,    84,    85,    86,    87,    88,    89,    90,     0,     0,
    1116              :       91,    92,    93,     0,    94,    95,   246,   247,     0,     0,
    1117              :        0,    12,    13,     0,    14,    15,    16,    17,     0,     0,
    1118              :       18,     0,    19,    20,    21,    22,    23,    24,    25,    26,
    1119              :       27,    28,    29,    30,    31,    32,     0,    33,    34,    35,
    1120              :       36,    37,     0,    38,     0,    39,    40,    41,    42,    43,
    1121              :       44,    45,     0,     0,    46,     0,    47,    48,     0,    49,
    1122              :        0,    50,    51,     0,    52,    53,    54,     0,    55,    56,
    1123              :       57,    58,    59,    60,     0,    61,     0,    62,    63,     0,
    1124              :       64,    65,    66,    67,    68,    69,    70,    71,    72,    73,
    1125              :       74,    75,    76,    77,    78,    79,    80,    81,    82,    83,
    1126              :       84,    85,    86,    87,    88,    89,    90,     0,     0,    91,
    1127              :       92,    93,     0,    94,    95,   281,   282,     0,     0,     0,
    1128              :       12,    13,     0,    14,    15,    16,    17,     0,     0,    18,
    1129              :        0,    19,    20,    21,    22,    23,    24,    25,    26,    27,
    1130              :       28,    29,    30,    31,    32,     0,    33,    34,    35,    36,
    1131              :       37,     0,    38,     0,    39,    40,    41,    42,    43,    44,
    1132              :       45,     0,     0,    46,     0,    47,    48,     0,    49,     0,
    1133              :       50,    51,     0,    52,    53,    54,     0,    55,    56,    57,
    1134              :       58,    59,    60,     0,    61,     0,    62,    63,     0,    64,
    1135              :       65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
    1136              :       75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
    1137              :       85,    86,    87,    88,    89,    90,     0,     0,    91,    92,
    1138              :       93,   108,    94,    95,     0,     0,    12,    13,     0,    14,
    1139              :       15,    16,    17,     0,     0,    18,     0,    19,    20,    21,
    1140              :       22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
    1141              :       32,     0,    33,    34,    35,    36,    37,     0,    38,     0,
    1142              :       39,    40,    41,    42,    43,    44,    45,     0,     0,    46,
    1143              :        0,    47,    48,     0,    49,     0,    50,    51,     0,    52,
    1144              :       53,    54,     0,    55,    56,    57,    58,    59,    60,     0,
    1145              :       61,     0,    62,    63,     0,    64,    65,    66,    67,    68,
    1146              :       69,    70,    71,    72,    73,    74,    75,    76,    77,    78,
    1147              :       79,    80,    81,    82,    83,    84,    85,    86,    87,    88,
    1148              :       89,    90,     0,     0,    91,    92,    93,   115,    94,    95,
    1149              :        0,     0,    12,    13,     0,    14,    15,    16,    17,     0,
    1150              :        0,    18,     0,    19,    20,    21,    22,    23,    24,    25,
    1151              :       26,    27,    28,    29,    30,    31,    32,     0,    33,    34,
    1152              :       35,    36,    37,     0,    38,     0,    39,    40,    41,    42,
    1153              :       43,    44,    45,     0,     0,    46,     0,    47,    48,     0,
    1154              :       49,     0,    50,    51,     0,    52,    53,    54,     0,    55,
    1155              :       56,    57,    58,    59,    60,     0,    61,     0,    62,    63,
    1156              :        0,    64,    65,    66,    67,    68,    69,    70,    71,    72,
    1157              :       73,    74,    75,    76,    77,    78,    79,    80,    81,    82,
    1158              :       83,    84,    85,    86,    87,    88,    89,    90,     0,     0,
    1159              :       91,    92,    93,     0,    94,    95,   123,   124,   125,   126,
    1160              :        0,     0,     0,     0,     0,     0,   127,     0,  -161,     0,
    1161              :      128,   129,     0,   130,     0,     0,     0,   131,     0,     0,
    1162              :        0,   132,     0,     0,     0,     0,  -161,     0,     0,     0,
    1163              :      133,     0,  -101,  -101,  -101,     0,     0,     0,   135,   136,
    1164              :      137,     0,     0,     0,     0,     0,   138,     0,   139,   140,
    1165              :        0,     0,   141,     0,     0,     0,     0,     0,   142,     0,
    1166              :        0,   143,   123,   124,   125,   126,   144,   145,     0,     0,
    1167              :      146,     0,   127,     0,  -161,     0,   128,   129,     0,   130,
    1168              :      147,     0,   148,   131,     0,   149,     0,   132,     0,     0,
    1169              :        0,     0,  -161,     0,     0,     0,   133,     0,  -102,  -102,
    1170              :     -102,     0,     0,     0,   135,   136,   137,     0,     0,     0,
    1171              :        0,     0,   138,     0,   139,   140,     0,     0,   141,     0,
    1172              :        0,     0,     0,     0,   142,     0,     0,   143,   123,   124,
    1173              :      125,   126,   144,   145,     0,     0,   146,     0,   127,     0,
    1174              :     -161,     0,   128,   129,     0,   130,   147,     0,   148,   131,
    1175              :        0,   149,     0,   132,     0,     0,     0,     0,  -161,     0,
    1176              :        0,     0,   133,     0,     0,     0,  -149,     0,     0,   134,
    1177              :      135,   136,   137,     0,     0,     0,     0,     0,   138,     0,
    1178              :      139,   140,     0,     0,   141,     0,     0,     0,     0,     0,
    1179              :      142,     0,     0,   143,   123,   124,   125,   126,   144,   145,
    1180              :        0,     0,   146,     0,   127,     0,  -161,     0,   128,   129,
    1181              :        0,   130,   147,     0,   148,   131,     0,   149,     0,   132,
    1182              :        0,     0,     0,     0,  -161,     0,     0,     0,   133,     0,
    1183              :        0,     0,   276,     0,     0,     0,   135,   136,   137,     0,
    1184              :        0,     0,     0,     0,   138,     0,   139,   140,     0,     0,
    1185              :      141,     0,     0,     0,     0,     0,   142,     0,     0,   143,
    1186              :      123,   124,   125,   126,   144,   145,     0,     0,   146,     0,
    1187              :      127,     0,  -161,     0,   128,   129,     0,   130,   147,     0,
    1188              :      148,   131,     0,   149,     0,   132,     0,     0,     0,     0,
    1189              :     -161,     0,     0,     0,   133,     0,     0,     0,  -111,     0,
    1190              :        0,     0,   135,   136,   137,     0,     0,     0,     0,     0,
    1191              :      138,     0,   139,   140,     0,     0,   141,     0,     0,     0,
    1192              :        0,     0,   142,     0,     0,   143,   123,   124,   125,   126,
    1193              :      144,   145,     0,     0,   146,     0,   127,     0,  -161,     0,
    1194              :      128,   129,     0,   130,   147,     0,   148,   131,     0,   149,
    1195              :        0,   132,     0,     0,     0,     0,  -161,     0,     0,     0,
    1196              :      133,     0,     0,     0,  -104,     0,     0,     0,   135,   136,
    1197              :      137,     0,     0,     0,     0,     0,   138,     0,   139,   140,
    1198              :        0,     0,   141,     0,     0,     0,     0,     0,   142,     0,
    1199              :        0,   143,     0,     0,     0,     0,   144,   145,     0,     0,
    1200              :      146,     0,     0,     0,     0,     0,     0,     0,     0,     0,
    1201              :      147,     0,   148,     0,     0,   149
    1202              : };
    1203              : 
    1204              : static const yytype_int16 yycheck[] =
    1205              : {
    1206              :        4,    99,    15,    15,    46,    23,   103,   105,   218,    20,
    1207              :       21,    22,    23,   207,   145,    56,    26,   240,    93,    30,
    1208              :      118,    32,   245,    34,    35,    60,    37,    66,    67,     0,
    1209              :       41,    36,    42,   132,    45,   279,    32,    47,    51,    50,
    1210              :       32,    92,    81,    54,    66,    56,   121,    58,    56,    57,
    1211              :      101,    62,    63,    64,    50,   129,    78,    50,   132,    70,
    1212              :      132,    72,    73,   135,   195,    76,    20,    21,    22,   200,
    1213              :       55,    82,   134,   135,    85,   117,   127,    87,    24,    90,
    1214              :       91,   325,    87,    94,    20,    21,    22,   297,   129,   124,
    1215              :      125,   130,   132,   104,    28,   106,   132,    58,   109,    20,
    1216              :       21,    22,   199,    66,   114,    24,    47,   301,   331,    24,
    1217              :      129,   114,   116,   131,    53,   213,   132,   132,   129,   132,
    1218              :      129,    38,   126,   136,   136,   132,    36,    77,   115,    74,
    1219              :       20,    21,    22,    23,   132,   132,    88,    11,   133,    74,
    1220              :       30,    81,    32,    90,    34,    35,    58,    37,    35,    58,
    1221              :       29,    41,   132,   251,    72,    45,   253,   254,   132,   132,
    1222              :       50,     2,   118,   325,    54,   304,   285,   292,    58,   219,
    1223              :      149,   209,    62,    63,    64,   143,   289,   226,   322,    -1,
    1224              :       70,   279,    72,    73,    -1,    -1,    76,    -1,    -1,    -1,
    1225              :       -1,    -1,    82,   290,    -1,    85,    -1,    -1,    -1,   296,
    1226              :       90,    91,    -1,    -1,    94,    -1,    -1,    -1,    -1,    -1,
    1227              :       -1,    -1,    -1,    -1,   104,    -1,   106,    -1,    -1,   109,
    1228              :       -1,   225,    -1,   320,    -1,    -1,    -1,   325,    -1,    -1,
    1229              :       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    20,   129,
    1230              :       -1,    23,    -1,    25,    26,    -1,    28,    29,    30,    31,
    1231              :       -1,    -1,    34,    -1,    36,    37,    38,    39,    40,    41,
    1232              :       42,    43,    44,    45,    46,    47,    48,    49,    50,    51,
    1233              :       52,    53,    54,    55,    -1,    57,    -1,    59,    60,    61,
    1234              :       62,    63,    64,    65,    -1,   289,    68,    -1,    70,    71,
    1235              :       -1,    73,    -1,    75,    76,    -1,    78,    79,    80,    -1,
    1236              :       82,    83,    84,    85,    86,    87,    -1,    89,    -1,    91,
    1237              :       92,    -1,    94,    95,    96,    97,    98,    99,   100,   101,
    1238              :      102,   103,   104,   105,   106,   107,   108,   109,   110,   111,
    1239              :      112,   113,   114,   115,   116,   117,   118,   119,   120,    -1,
    1240              :       -1,   123,   124,   125,    -1,   127,   128,    20,    -1,    22,
    1241              :       -1,    -1,    25,    26,    -1,    28,    29,    30,    31,    -1,
    1242              :       -1,    34,    -1,    36,    37,    38,    39,    40,    41,    42,
    1243              :       43,    44,    45,    46,    47,    48,    49,    -1,    51,    52,
    1244              :       53,    54,    55,    -1,    57,    -1,    59,    60,    61,    62,
    1245              :       63,    64,    65,    -1,    -1,    68,    -1,    70,    71,    -1,
    1246              :       73,    -1,    75,    76,    -1,    78,    79,    80,    -1,    82,
    1247              :       83,    84,    85,    86,    87,    -1,    89,    -1,    91,    92,
    1248              :       -1,    94,    95,    96,    97,    98,    99,   100,   101,   102,
    1249              :      103,   104,   105,   106,   107,   108,   109,   110,   111,   112,
    1250              :      113,   114,   115,   116,   117,   118,   119,   120,    -1,    -1,
    1251              :      123,   124,   125,    -1,   127,   128,    20,    21,    -1,    -1,
    1252              :       -1,    25,    26,    -1,    28,    29,    30,    31,    -1,    -1,
    1253              :       34,    -1,    36,    37,    38,    39,    40,    41,    42,    43,
    1254              :       44,    45,    46,    47,    48,    49,    -1,    51,    52,    53,
    1255              :       54,    55,    -1,    57,    -1,    59,    60,    61,    62,    63,
    1256              :       64,    65,    -1,    -1,    68,    -1,    70,    71,    -1,    73,
    1257              :       -1,    75,    76,    -1,    78,    79,    80,    -1,    82,    83,
    1258              :       84,    85,    86,    87,    -1,    89,    -1,    91,    92,    -1,
    1259              :       94,    95,    96,    97,    98,    99,   100,   101,   102,   103,
    1260              :      104,   105,   106,   107,   108,   109,   110,   111,   112,   113,
    1261              :      114,   115,   116,   117,   118,   119,   120,    -1,    -1,   123,
    1262              :      124,   125,    -1,   127,   128,    20,    21,    -1,    -1,    -1,
    1263              :       25,    26,    -1,    28,    29,    30,    31,    -1,    -1,    34,
    1264              :       -1,    36,    37,    38,    39,    40,    41,    42,    43,    44,
    1265              :       45,    46,    47,    48,    49,    -1,    51,    52,    53,    54,
    1266              :       55,    -1,    57,    -1,    59,    60,    61,    62,    63,    64,
    1267              :       65,    -1,    -1,    68,    -1,    70,    71,    -1,    73,    -1,
    1268              :       75,    76,    -1,    78,    79,    80,    -1,    82,    83,    84,
    1269              :       85,    86,    87,    -1,    89,    -1,    91,    92,    -1,    94,
    1270              :       95,    96,    97,    98,    99,   100,   101,   102,   103,   104,
    1271              :      105,   106,   107,   108,   109,   110,   111,   112,   113,   114,
    1272              :      115,   116,   117,   118,   119,   120,    -1,    -1,   123,   124,
    1273              :      125,    20,   127,   128,    -1,    -1,    25,    26,    -1,    28,
    1274              :       29,    30,    31,    -1,    -1,    34,    -1,    36,    37,    38,
    1275              :       39,    40,    41,    42,    43,    44,    45,    46,    47,    48,
    1276              :       49,    -1,    51,    52,    53,    54,    55,    -1,    57,    -1,
    1277              :       59,    60,    61,    62,    63,    64,    65,    -1,    -1,    68,
    1278              :       -1,    70,    71,    -1,    73,    -1,    75,    76,    -1,    78,
    1279              :       79,    80,    -1,    82,    83,    84,    85,    86,    87,    -1,
    1280              :       89,    -1,    91,    92,    -1,    94,    95,    96,    97,    98,
    1281              :       99,   100,   101,   102,   103,   104,   105,   106,   107,   108,
    1282              :      109,   110,   111,   112,   113,   114,   115,   116,   117,   118,
    1283              :      119,   120,    -1,    -1,   123,   124,   125,    20,   127,   128,
    1284              :       -1,    -1,    25,    26,    -1,    28,    29,    30,    31,    -1,
    1285              :       -1,    34,    -1,    36,    37,    38,    39,    40,    41,    42,
    1286              :       43,    44,    45,    46,    47,    48,    49,    -1,    51,    52,
    1287              :       53,    54,    55,    -1,    57,    -1,    59,    60,    61,    62,
    1288              :       63,    64,    65,    -1,    -1,    68,    -1,    70,    71,    -1,
    1289              :       73,    -1,    75,    76,    -1,    78,    79,    80,    -1,    82,
    1290              :       83,    84,    85,    86,    87,    -1,    89,    -1,    91,    92,
    1291              :       -1,    94,    95,    96,    97,    98,    99,   100,   101,   102,
    1292              :      103,   104,   105,   106,   107,   108,   109,   110,   111,   112,
    1293              :      113,   114,   115,   116,   117,   118,   119,   120,    -1,    -1,
    1294              :      123,   124,   125,    -1,   127,   128,    20,    21,    22,    23,
    1295              :       -1,    -1,    -1,    -1,    -1,    -1,    30,    -1,    32,    -1,
    1296              :       34,    35,    -1,    37,    -1,    -1,    -1,    41,    -1,    -1,
    1297              :       -1,    45,    -1,    -1,    -1,    -1,    50,    -1,    -1,    -1,
    1298              :       54,    -1,    56,    57,    58,    -1,    -1,    -1,    62,    63,
    1299              :       64,    -1,    -1,    -1,    -1,    -1,    70,    -1,    72,    73,
    1300              :       -1,    -1,    76,    -1,    -1,    -1,    -1,    -1,    82,    -1,
    1301              :       -1,    85,    20,    21,    22,    23,    90,    91,    -1,    -1,
    1302              :       94,    -1,    30,    -1,    32,    -1,    34,    35,    -1,    37,
    1303              :      104,    -1,   106,    41,    -1,   109,    -1,    45,    -1,    -1,
    1304              :       -1,    -1,    50,    -1,    -1,    -1,    54,    -1,    56,    57,
    1305              :       58,    -1,    -1,    -1,    62,    63,    64,    -1,    -1,    -1,
    1306              :       -1,    -1,    70,    -1,    72,    73,    -1,    -1,    76,    -1,
    1307              :       -1,    -1,    -1,    -1,    82,    -1,    -1,    85,    20,    21,
    1308              :       22,    23,    90,    91,    -1,    -1,    94,    -1,    30,    -1,
    1309              :       32,    -1,    34,    35,    -1,    37,   104,    -1,   106,    41,
    1310              :       -1,   109,    -1,    45,    -1,    -1,    -1,    -1,    50,    -1,
    1311              :       -1,    -1,    54,    -1,    -1,    -1,    58,    -1,    -1,    61,
    1312              :       62,    63,    64,    -1,    -1,    -1,    -1,    -1,    70,    -1,
    1313              :       72,    73,    -1,    -1,    76,    -1,    -1,    -1,    -1,    -1,
    1314              :       82,    -1,    -1,    85,    20,    21,    22,    23,    90,    91,
    1315              :       -1,    -1,    94,    -1,    30,    -1,    32,    -1,    34,    35,
    1316              :       -1,    37,   104,    -1,   106,    41,    -1,   109,    -1,    45,
    1317              :       -1,    -1,    -1,    -1,    50,    -1,    -1,    -1,    54,    -1,
    1318              :       -1,    -1,    58,    -1,    -1,    -1,    62,    63,    64,    -1,
    1319              :       -1,    -1,    -1,    -1,    70,    -1,    72,    73,    -1,    -1,
    1320              :       76,    -1,    -1,    -1,    -1,    -1,    82,    -1,    -1,    85,
    1321              :       20,    21,    22,    23,    90,    91,    -1,    -1,    94,    -1,
    1322              :       30,    -1,    32,    -1,    34,    35,    -1,    37,   104,    -1,
    1323              :      106,    41,    -1,   109,    -1,    45,    -1,    -1,    -1,    -1,
    1324              :       50,    -1,    -1,    -1,    54,    -1,    -1,    -1,    58,    -1,
    1325              :       -1,    -1,    62,    63,    64,    -1,    -1,    -1,    -1,    -1,
    1326              :       70,    -1,    72,    73,    -1,    -1,    76,    -1,    -1,    -1,
    1327              :       -1,    -1,    82,    -1,    -1,    85,    20,    21,    22,    23,
    1328              :       90,    91,    -1,    -1,    94,    -1,    30,    -1,    32,    -1,
    1329              :       34,    35,    -1,    37,   104,    -1,   106,    41,    -1,   109,
    1330              :       -1,    45,    -1,    -1,    -1,    -1,    50,    -1,    -1,    -1,
    1331              :       54,    -1,    -1,    -1,    58,    -1,    -1,    -1,    62,    63,
    1332              :       64,    -1,    -1,    -1,    -1,    -1,    70,    -1,    72,    73,
    1333              :       -1,    -1,    76,    -1,    -1,    -1,    -1,    -1,    82,    -1,
    1334              :       -1,    85,    -1,    -1,    -1,    -1,    90,    91,    -1,    -1,
    1335              :       94,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
    1336              :      104,    -1,   106,    -1,    -1,   109
    1337              : };
    1338              : 
    1339              : /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
    1340              :    state STATE-NUM.  */
    1341              : static const yytype_uint8 yystos[] =
    1342              : {
    1343              :        0,   138,   139,     0,    23,   131,   140,   143,   144,   218,
    1344              :       20,    22,    25,    26,    28,    29,    30,    31,    34,    36,
    1345              :       37,    38,    39,    40,    41,    42,    43,    44,    45,    46,
    1346              :       47,    48,    49,    51,    52,    53,    54,    55,    57,    59,
    1347              :       60,    61,    62,    63,    64,    65,    68,    70,    71,    73,
    1348              :       75,    76,    78,    79,    80,    82,    83,    84,    85,    86,
    1349              :       87,    89,    91,    92,    94,    95,    96,    97,    98,    99,
    1350              :      100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
    1351              :      110,   111,   112,   113,   114,   115,   116,   117,   118,   119,
    1352              :      120,   123,   124,   125,   127,   128,   222,   223,    92,   101,
    1353              :      127,   132,   142,    32,    50,   145,    24,    55,    20,   141,
    1354              :      223,    60,   124,   125,   165,    20,    23,    50,   146,   147,
    1355              :      148,   157,   223,    20,    21,    22,    23,    30,    34,    35,
    1356              :       37,    41,    45,    54,    61,    62,    63,    64,    70,    72,
    1357              :       73,    76,    82,    85,    90,    91,    94,   104,   106,   109,
    1358              :      143,   166,   167,   168,   169,   170,   176,   179,   184,   185,
    1359              :      186,   189,   191,   192,   193,   194,   195,   197,   198,   199,
    1360              :      200,   201,   203,   204,   205,   206,   209,   219,   222,   147,
    1361              :       26,    42,    87,   114,   150,   158,   222,   180,    20,    21,
    1362              :       22,   208,    28,   207,   210,   202,    46,   117,   171,   216,
    1363              :      202,   132,   208,   207,   132,   220,   222,    58,    66,    67,
    1364              :       81,   130,    24,    66,   114,    47,   159,    24,   129,   181,
    1365              :      182,   132,    36,    87,   132,   129,   211,   212,   208,    53,
    1366              :      165,   208,   132,   129,   132,   221,   220,    20,    21,    22,
    1367              :      187,   188,   188,   165,   196,   217,    20,    21,   156,   223,
    1368              :      149,    38,   160,   216,    56,   182,   183,    36,   213,   214,
    1369              :      222,   212,    77,    20,    21,    22,   172,   173,   175,   177,
    1370              :      132,   215,   196,    74,   115,   190,    58,   196,   132,   133,
    1371              :      152,    20,    21,   223,    88,   161,   165,   165,    58,    93,
    1372              :      121,   132,   135,    15,   136,   164,    56,    57,   178,    11,
    1373              :       74,    81,   153,   154,   157,    66,    78,   155,    90,    51,
    1374              :      132,   162,   163,   164,    35,   214,   165,   173,   174,   165,
    1375              :      216,    58,    29,   220,   134,   135,   159,   151,   132,   165,
    1376              :       72,   217,   132,   154,   132,   196
    1377              : };
    1378              : 
    1379              : /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.  */
    1380              : static const yytype_uint8 yyr1[] =
    1381              : {
    1382              :        0,   137,   138,   139,   139,   140,   140,   140,   140,   140,
    1383              :      141,   141,   142,   142,   143,   144,   144,   144,   145,   146,
    1384              :      146,   147,   147,   147,   148,   148,   149,   148,   150,   150,
    1385              :      150,   151,   152,   152,   153,   153,   154,   155,   155,   156,
    1386              :      156,   156,   157,   157,   158,   158,   159,   160,   160,   160,
    1387              :      160,   161,   161,   162,   162,   163,   163,   164,   164,   165,
    1388              :      165,   166,   166,   166,   166,   166,   166,   166,   166,   166,
    1389              :      166,   166,   166,   166,   166,   166,   166,   166,   166,   166,
    1390              :      166,   166,   166,   166,   166,   167,   168,   168,   169,   170,
    1391              :      171,   171,   171,   172,   172,   173,   174,   175,   175,   175,
    1392              :      176,   177,   177,   178,   178,   179,   180,   181,   181,   182,
    1393              :      183,   183,   184,   185,   186,   187,   188,   188,   188,   189,
    1394              :      190,   190,   191,   192,   192,   193,   194,   195,   196,   197,
    1395              :      197,   197,   197,   197,   198,   199,   200,   201,   202,   203,
    1396              :      204,   205,   206,   207,   207,   207,   208,   208,   208,   209,
    1397              :      210,   209,   211,   211,   212,   213,   213,   214,   215,   216,
    1398              :      217,   218,   218,   219,   219,   220,   220,   221,   221,   222,
    1399              :      222,   222,   223,   223,   223,   223,   223,   223,   223,   223,
    1400              :      223,   223,   223,   223,   223,   223,   223,   223,   223,   223,
    1401              :      223,   223,   223,   223,   223,   223,   223,   223,   223,   223,
    1402              :      223,   223,   223,   223,   223,   223,   223,   223,   223,   223,
    1403              :      223,   223,   223,   223,   223,   223,   223,   223,   223,   223,
    1404              :      223,   223,   223,   223,   223,   223,   223,   223,   223,   223,
    1405              :      223,   223,   223,   223,   223,   223,   223,   223,   223,   223,
    1406              :      223,   223,   223,   223,   223,   223,   223,   223,   223,   223,
    1407              :      223,   223,   223,   223,   223,   223
    1408              : };
    1409              : 
    1410              : /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.  */
    1411              : static const yytype_int8 yyr2[] =
    1412              : {
    1413              :        0,     2,     3,     0,     2,     3,     3,     3,     3,     3,
    1414              :        1,     1,     0,     1,     6,     1,     2,     3,     1,     2,
    1415              :        1,     1,     1,     3,     6,     5,     0,     7,     0,     2,
    1416              :        1,     0,     0,     3,     1,     3,     2,     1,     1,     1,
    1417              :        1,     1,     1,     1,     0,     1,     0,     0,     2,     2,
    1418              :        2,     0,     2,     1,     1,     1,     1,     1,     1,     0,
    1419              :        2,     2,     1,     1,     1,     1,     1,     1,     1,     1,
    1420              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1421              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     5,
    1422              :        0,     1,     1,     3,     1,     3,     0,     1,     1,     1,
    1423              :        8,     0,     4,     0,     2,     7,     0,     2,     1,     3,
    1424              :        0,     2,     3,     4,     4,     2,     1,     1,     1,     8,
    1425              :        0,     2,     3,     1,     1,     1,     1,     1,     5,     1,
    1426              :        1,     1,     1,     1,     1,     2,     4,     4,     0,     3,
    1427              :        2,     3,     3,     2,     3,     0,     1,     1,     1,     0,
    1428              :        0,     3,     2,     1,     4,     3,     1,     1,     0,     0,
    1429              :        0,     0,     3,     0,     3,     0,     1,     1,     2,     1,
    1430              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1431              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1432              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1433              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1434              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1435              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1436              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1437              :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1438              :        1,     1,     1,     1,     1,     1
    1439              : };
    1440              : 
    1441              : 
    1442              : enum { YYENOMEM = -2 };
    1443              : 
    1444              : #define yyerrok         (yyerrstatus = 0)
    1445              : #define yyclearin       (yychar = YYEMPTY)
    1446              : 
    1447              : #define YYACCEPT        goto yyacceptlab
    1448              : #define YYABORT         goto yyabortlab
    1449              : #define YYERROR         goto yyerrorlab
    1450              : #define YYNOMEM         goto yyexhaustedlab
    1451              : 
    1452              : 
    1453              : #define YYRECOVERING()  (!!yyerrstatus)
    1454              : 
    1455              : #define YYBACKUP(Token, Value)                                    \
    1456              :   do                                                              \
    1457              :     if (yychar == YYEMPTY)                                        \
    1458              :       {                                                           \
    1459              :         yychar = (Token);                                         \
    1460              :         yylval = (Value);                                         \
    1461              :         YYPOPSTACK (yylen);                                       \
    1462              :         yystate = *yyssp;                                         \
    1463              :         goto yybackup;                                            \
    1464              :       }                                                           \
    1465              :     else                                                          \
    1466              :       {                                                           \
    1467              :         yyerror (&yylloc, plpgsql_parse_result_p, yyscanner, YY_("syntax error: cannot back up")); \
    1468              :         YYERROR;                                                  \
    1469              :       }                                                           \
    1470              :   while (0)
    1471              : 
    1472              : /* Backward compatibility with an undocumented macro.
    1473              :    Use YYerror or YYUNDEF. */
    1474              : #define YYERRCODE YYUNDEF
    1475              : 
    1476              : /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
    1477              :    If N is 0, then set CURRENT to the empty location which ends
    1478              :    the previous symbol: RHS[0] (always defined).  */
    1479              : 
    1480              : #ifndef YYLLOC_DEFAULT
    1481              : # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
    1482              :     do                                                                  \
    1483              :       if (N)                                                            \
    1484              :         {                                                               \
    1485              :           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
    1486              :           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
    1487              :           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
    1488              :           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
    1489              :         }                                                               \
    1490              :       else                                                              \
    1491              :         {                                                               \
    1492              :           (Current).first_line   = (Current).last_line   =              \
    1493              :             YYRHSLOC (Rhs, 0).last_line;                                \
    1494              :           (Current).first_column = (Current).last_column =              \
    1495              :             YYRHSLOC (Rhs, 0).last_column;                              \
    1496              :         }                                                               \
    1497              :     while (0)
    1498              : #endif
    1499              : 
    1500              : #define YYRHSLOC(Rhs, K) ((Rhs)[K])
    1501              : 
    1502              : 
    1503              : /* Enable debugging if requested.  */
    1504              : #if YYDEBUG
    1505              : 
    1506              : # ifndef YYFPRINTF
    1507              : #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
    1508              : #  define YYFPRINTF fprintf
    1509              : # endif
    1510              : 
    1511              : # define YYDPRINTF(Args)                        \
    1512              : do {                                            \
    1513              :   if (yydebug)                                  \
    1514              :     YYFPRINTF Args;                             \
    1515              : } while (0)
    1516              : 
    1517              : 
    1518              : /* YYLOCATION_PRINT -- Print the location on the stream.
    1519              :    This macro was not mandated originally: define only if we know
    1520              :    we won't break user code: when these are the locations we know.  */
    1521              : 
    1522              : # ifndef YYLOCATION_PRINT
    1523              : 
    1524              : #  if defined YY_LOCATION_PRINT
    1525              : 
    1526              :    /* Temporary convenience wrapper in case some people defined the
    1527              :       undocumented and private YY_LOCATION_PRINT macros.  */
    1528              : #   define YYLOCATION_PRINT(File, Loc)  YY_LOCATION_PRINT(File, *(Loc))
    1529              : 
    1530              : #  elif defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
    1531              : 
    1532              : /* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
    1533              : 
    1534              : YY_ATTRIBUTE_UNUSED
    1535              : static int
    1536              : yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
    1537              : {
    1538              :   int res = 0;
    1539              :   int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
    1540              :   if (0 <= yylocp->first_line)
    1541              :     {
    1542              :       res += YYFPRINTF (yyo, "%d", yylocp->first_line);
    1543              :       if (0 <= yylocp->first_column)
    1544              :         res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
    1545              :     }
    1546              :   if (0 <= yylocp->last_line)
    1547              :     {
    1548              :       if (yylocp->first_line < yylocp->last_line)
    1549              :         {
    1550              :           res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
    1551              :           if (0 <= end_col)
    1552              :             res += YYFPRINTF (yyo, ".%d", end_col);
    1553              :         }
    1554              :       else if (0 <= end_col && yylocp->first_column < end_col)
    1555              :         res += YYFPRINTF (yyo, "-%d", end_col);
    1556              :     }
    1557              :   return res;
    1558              : }
    1559              : 
    1560              : #   define YYLOCATION_PRINT  yy_location_print_
    1561              : 
    1562              :     /* Temporary convenience wrapper in case some people defined the
    1563              :        undocumented and private YY_LOCATION_PRINT macros.  */
    1564              : #   define YY_LOCATION_PRINT(File, Loc)  YYLOCATION_PRINT(File, &(Loc))
    1565              : 
    1566              : #  else
    1567              : 
    1568              : #   define YYLOCATION_PRINT(File, Loc) ((void) 0)
    1569              :     /* Temporary convenience wrapper in case some people defined the
    1570              :        undocumented and private YY_LOCATION_PRINT macros.  */
    1571              : #   define YY_LOCATION_PRINT  YYLOCATION_PRINT
    1572              : 
    1573              : #  endif
    1574              : # endif /* !defined YYLOCATION_PRINT */
    1575              : 
    1576              : 
    1577              : # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                    \
    1578              : do {                                                                      \
    1579              :   if (yydebug)                                                            \
    1580              :     {                                                                     \
    1581              :       YYFPRINTF (stderr, "%s ", Title);                                   \
    1582              :       yy_symbol_print (stderr,                                            \
    1583              :                   Kind, Value, Location, plpgsql_parse_result_p, yyscanner); \
    1584              :       YYFPRINTF (stderr, "\n");                                           \
    1585              :     }                                                                     \
    1586              : } while (0)
    1587              : 
    1588              : 
    1589              : /*-----------------------------------.
    1590              : | Print this symbol's value on YYO.  |
    1591              : `-----------------------------------*/
    1592              : 
    1593              : static void
    1594              : yy_symbol_value_print (FILE *yyo,
    1595              :                        yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, PLpgSQL_stmt_block **plpgsql_parse_result_p, yyscan_t yyscanner)
    1596              : {
    1597              :   FILE *yyoutput = yyo;
    1598              :   YY_USE (yyoutput);
    1599              :   YY_USE (yylocationp);
    1600              :   YY_USE (plpgsql_parse_result_p);
    1601              :   YY_USE (yyscanner);
    1602              :   if (!yyvaluep)
    1603              :     return;
    1604              :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    1605              :   YY_USE (yykind);
    1606              :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    1607              : }
    1608              : 
    1609              : 
    1610              : /*---------------------------.
    1611              : | Print this symbol on YYO.  |
    1612              : `---------------------------*/
    1613              : 
    1614              : static void
    1615              : yy_symbol_print (FILE *yyo,
    1616              :                  yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, PLpgSQL_stmt_block **plpgsql_parse_result_p, yyscan_t yyscanner)
    1617              : {
    1618              :   YYFPRINTF (yyo, "%s %s (",
    1619              :              yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
    1620              : 
    1621              :   YYLOCATION_PRINT (yyo, yylocationp);
    1622              :   YYFPRINTF (yyo, ": ");
    1623              :   yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, plpgsql_parse_result_p, yyscanner);
    1624              :   YYFPRINTF (yyo, ")");
    1625              : }
    1626              : 
    1627              : /*------------------------------------------------------------------.
    1628              : | yy_stack_print -- Print the state stack from its BOTTOM up to its |
    1629              : | TOP (included).                                                   |
    1630              : `------------------------------------------------------------------*/
    1631              : 
    1632              : static void
    1633              : yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
    1634              : {
    1635              :   YYFPRINTF (stderr, "Stack now");
    1636              :   for (; yybottom <= yytop; yybottom++)
    1637              :     {
    1638              :       int yybot = *yybottom;
    1639              :       YYFPRINTF (stderr, " %d", yybot);
    1640              :     }
    1641              :   YYFPRINTF (stderr, "\n");
    1642              : }
    1643              : 
    1644              : # define YY_STACK_PRINT(Bottom, Top)                            \
    1645              : do {                                                            \
    1646              :   if (yydebug)                                                  \
    1647              :     yy_stack_print ((Bottom), (Top));                           \
    1648              : } while (0)
    1649              : 
    1650              : 
    1651              : /*------------------------------------------------.
    1652              : | Report that the YYRULE is going to be reduced.  |
    1653              : `------------------------------------------------*/
    1654              : 
    1655              : static void
    1656              : yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp,
    1657              :                  int yyrule, PLpgSQL_stmt_block **plpgsql_parse_result_p, yyscan_t yyscanner)
    1658              : {
    1659              :   int yylno = yyrline[yyrule];
    1660              :   int yynrhs = yyr2[yyrule];
    1661              :   int yyi;
    1662              :   YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
    1663              :              yyrule - 1, yylno);
    1664              :   /* The symbols being reduced.  */
    1665              :   for (yyi = 0; yyi < yynrhs; yyi++)
    1666              :     {
    1667              :       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
    1668              :       yy_symbol_print (stderr,
    1669              :                        YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
    1670              :                        &yyvsp[(yyi + 1) - (yynrhs)],
    1671              :                        &(yylsp[(yyi + 1) - (yynrhs)]), plpgsql_parse_result_p, yyscanner);
    1672              :       YYFPRINTF (stderr, "\n");
    1673              :     }
    1674              : }
    1675              : 
    1676              : # define YY_REDUCE_PRINT(Rule)          \
    1677              : do {                                    \
    1678              :   if (yydebug)                          \
    1679              :     yy_reduce_print (yyssp, yyvsp, yylsp, Rule, plpgsql_parse_result_p, yyscanner); \
    1680              : } while (0)
    1681              : 
    1682              : /* Nonzero means print parse trace.  It is left uninitialized so that
    1683              :    multiple parsers can coexist.  */
    1684              : int yydebug;
    1685              : #else /* !YYDEBUG */
    1686              : # define YYDPRINTF(Args) ((void) 0)
    1687              : # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
    1688              : # define YY_STACK_PRINT(Bottom, Top)
    1689              : # define YY_REDUCE_PRINT(Rule)
    1690              : #endif /* !YYDEBUG */
    1691              : 
    1692              : 
    1693              : /* YYINITDEPTH -- initial size of the parser's stacks.  */
    1694              : #ifndef YYINITDEPTH
    1695              : # define YYINITDEPTH 200
    1696              : #endif
    1697              : 
    1698              : /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
    1699              :    if the built-in stack extension method is used).
    1700              : 
    1701              :    Do not make this value too large; the results are undefined if
    1702              :    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
    1703              :    evaluated with infinite-precision integer arithmetic.  */
    1704              : 
    1705              : #ifndef YYMAXDEPTH
    1706              : # define YYMAXDEPTH 10000
    1707              : #endif
    1708              : 
    1709              : 
    1710              : 
    1711              : 
    1712              : 
    1713              : 
    1714              : /*-----------------------------------------------.
    1715              : | Release the memory associated to this symbol.  |
    1716              : `-----------------------------------------------*/
    1717              : 
    1718              : static void
    1719        11920 : yydestruct (const char *yymsg,
    1720              :             yysymbol_kind_t yykind, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, PLpgSQL_stmt_block **plpgsql_parse_result_p, yyscan_t yyscanner)
    1721              : {
    1722              :   YY_USE (yyvaluep);
    1723              :   YY_USE (yylocationp);
    1724              :   YY_USE (plpgsql_parse_result_p);
    1725              :   YY_USE (yyscanner);
    1726        11920 :   if (!yymsg)
    1727            0 :     yymsg = "Deleting";
    1728              :   YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
    1729              : 
    1730              :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    1731              :   YY_USE (yykind);
    1732              :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    1733        11920 : }
    1734              : 
    1735              : 
    1736              : 
    1737              : 
    1738              : 
    1739              : 
    1740              : /*----------.
    1741              : | yyparse.  |
    1742              : `----------*/
    1743              : 
    1744              : int
    1745         6055 : yyparse (PLpgSQL_stmt_block **plpgsql_parse_result_p, yyscan_t yyscanner)
    1746              : {
    1747              : /* Lookahead token kind.  */
    1748              : int yychar;
    1749              : 
    1750              : 
    1751              : /* The semantic value of the lookahead symbol.  */
    1752              : /* Default value used for initialization, for pacifying older GCCs
    1753              :    or non-GCC compilers.  */
    1754              : YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
    1755              : YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
    1756              : 
    1757              : /* Location data for the lookahead symbol.  */
    1758              : static YYLTYPE yyloc_default
    1759              : # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
    1760              :   = { 1, 1, 1, 1 }
    1761              : # endif
    1762              : ;
    1763         6055 : YYLTYPE yylloc = yyloc_default;
    1764              : 
    1765              :     /* Number of syntax errors so far.  */
    1766         6055 :     int yynerrs = 0;
    1767              : 
    1768         6055 :     yy_state_fast_t yystate = 0;
    1769              :     /* Number of tokens to shift before error messages enabled.  */
    1770         6055 :     int yyerrstatus = 0;
    1771              : 
    1772              :     /* Refer to the stacks through separate pointers, to allow yyoverflow
    1773              :        to reallocate them elsewhere.  */
    1774              : 
    1775              :     /* Their size.  */
    1776         6055 :     YYPTRDIFF_T yystacksize = YYINITDEPTH;
    1777              : 
    1778              :     /* The state stack: array, bottom, top.  */
    1779              :     yy_state_t yyssa[YYINITDEPTH];
    1780         6055 :     yy_state_t *yyss = yyssa;
    1781         6055 :     yy_state_t *yyssp = yyss;
    1782              : 
    1783              :     /* The semantic value stack: array, bottom, top.  */
    1784              :     YYSTYPE yyvsa[YYINITDEPTH];
    1785         6055 :     YYSTYPE *yyvs = yyvsa;
    1786         6055 :     YYSTYPE *yyvsp = yyvs;
    1787              : 
    1788              :     /* The location stack: array, bottom, top.  */
    1789              :     YYLTYPE yylsa[YYINITDEPTH];
    1790         6055 :     YYLTYPE *yyls = yylsa;
    1791         6055 :     YYLTYPE *yylsp = yyls;
    1792              : 
    1793              :   int yyn;
    1794              :   /* The return value of yyparse.  */
    1795              :   int yyresult;
    1796              :   /* Lookahead symbol kind.  */
    1797         6055 :   yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
    1798              :   /* The variables used to return semantic value and location from the
    1799              :      action routines.  */
    1800              :   YYSTYPE yyval;
    1801              :   YYLTYPE yyloc;
    1802              : 
    1803              :   /* The locations where the error started and ended.  */
    1804              :   YYLTYPE yyerror_range[3];
    1805              : 
    1806              : 
    1807              : 
    1808              : #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
    1809              : 
    1810              :   /* The number of symbols on the RHS of the reduced rule.
    1811              :      Keep to zero when no symbol should be popped.  */
    1812         6055 :   int yylen = 0;
    1813              : 
    1814              :   YYDPRINTF ((stderr, "Starting parse\n"));
    1815              : 
    1816         6055 :   yychar = YYEMPTY; /* Cause a token to be read.  */
    1817              : 
    1818         6055 :   yylsp[0] = yylloc;
    1819         6055 :   goto yysetstate;
    1820              : 
    1821              : 
    1822              : /*------------------------------------------------------------.
    1823              : | yynewstate -- push a new state, which is found in yystate.  |
    1824              : `------------------------------------------------------------*/
    1825       273045 : yynewstate:
    1826              :   /* In all cases, when you get here, the value and location stacks
    1827              :      have just been pushed.  So pushing a state here evens the stacks.  */
    1828       273045 :   yyssp++;
    1829              : 
    1830              : 
    1831              : /*--------------------------------------------------------------------.
    1832              : | yysetstate -- set current state (the top of the stack) to yystate.  |
    1833              : `--------------------------------------------------------------------*/
    1834       279100 : yysetstate:
    1835              :   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
    1836              :   YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
    1837              :   YY_IGNORE_USELESS_CAST_BEGIN
    1838       279100 :   *yyssp = YY_CAST (yy_state_t, yystate);
    1839              :   YY_IGNORE_USELESS_CAST_END
    1840              :   YY_STACK_PRINT (yyss, yyssp);
    1841              : 
    1842       279100 :   if (yyss + yystacksize - 1 <= yyssp)
    1843              : #if !defined yyoverflow && !defined YYSTACK_RELOCATE
    1844              :     YYNOMEM;
    1845              : #else
    1846              :     {
    1847              :       /* Get the current used size of the three stacks, in elements.  */
    1848            0 :       YYPTRDIFF_T yysize = yyssp - yyss + 1;
    1849              : 
    1850              : # if defined yyoverflow
    1851              :       {
    1852              :         /* Give user a chance to reallocate the stack.  Use copies of
    1853              :            these so that the &'s don't force the real ones into
    1854              :            memory.  */
    1855              :         yy_state_t *yyss1 = yyss;
    1856              :         YYSTYPE *yyvs1 = yyvs;
    1857              :         YYLTYPE *yyls1 = yyls;
    1858              : 
    1859              :         /* Each stack pointer address is followed by the size of the
    1860              :            data in use in that stack, in bytes.  This used to be a
    1861              :            conditional around just the two extra args, but that might
    1862              :            be undefined if yyoverflow is a macro.  */
    1863              :         yyoverflow (YY_("memory exhausted"),
    1864              :                     &yyss1, yysize * YYSIZEOF (*yyssp),
    1865              :                     &yyvs1, yysize * YYSIZEOF (*yyvsp),
    1866              :                     &yyls1, yysize * YYSIZEOF (*yylsp),
    1867              :                     &yystacksize);
    1868              :         yyss = yyss1;
    1869              :         yyvs = yyvs1;
    1870              :         yyls = yyls1;
    1871              :       }
    1872              : # else /* defined YYSTACK_RELOCATE */
    1873              :       /* Extend the stack our own way.  */
    1874            0 :       if (YYMAXDEPTH <= yystacksize)
    1875            0 :         YYNOMEM;
    1876            0 :       yystacksize *= 2;
    1877            0 :       if (YYMAXDEPTH < yystacksize)
    1878            0 :         yystacksize = YYMAXDEPTH;
    1879              : 
    1880              :       {
    1881            0 :         yy_state_t *yyss1 = yyss;
    1882              :         union yyalloc *yyptr =
    1883            0 :           YY_CAST (union yyalloc *,
    1884              :                    YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
    1885            0 :         if (! yyptr)
    1886            0 :           YYNOMEM;
    1887            0 :         YYSTACK_RELOCATE (yyss_alloc, yyss);
    1888            0 :         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
    1889            0 :         YYSTACK_RELOCATE (yyls_alloc, yyls);
    1890              : #  undef YYSTACK_RELOCATE
    1891            0 :         if (yyss1 != yyssa)
    1892            0 :           YYSTACK_FREE (yyss1);
    1893              :       }
    1894              : # endif
    1895              : 
    1896            0 :       yyssp = yyss + yysize - 1;
    1897            0 :       yyvsp = yyvs + yysize - 1;
    1898            0 :       yylsp = yyls + yysize - 1;
    1899              : 
    1900              :       YY_IGNORE_USELESS_CAST_BEGIN
    1901              :       YYDPRINTF ((stderr, "Stack size increased to %ld\n",
    1902              :                   YY_CAST (long, yystacksize)));
    1903              :       YY_IGNORE_USELESS_CAST_END
    1904              : 
    1905            0 :       if (yyss + yystacksize - 1 <= yyssp)
    1906            0 :         YYABORT;
    1907              :     }
    1908              : #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
    1909              : 
    1910              : 
    1911       279100 :   if (yystate == YYFINAL)
    1912         5960 :     YYACCEPT;
    1913              : 
    1914       273140 :   goto yybackup;
    1915              : 
    1916              : 
    1917              : /*-----------.
    1918              : | yybackup.  |
    1919              : `-----------*/
    1920       273140 : yybackup:
    1921              :   /* Do appropriate processing given the current state.  Read a
    1922              :      lookahead token if we need one and don't already have one.  */
    1923              : 
    1924              :   /* First try to decide what to do without reference to lookahead token.  */
    1925       273140 :   yyn = yypact[yystate];
    1926       273140 :   if (yypact_value_is_default (yyn))
    1927       146085 :     goto yydefault;
    1928              : 
    1929              :   /* Not known => get a lookahead token if don't already have one.  */
    1930              : 
    1931              :   /* YYCHAR is either empty, or end-of-input, or a valid lookahead.  */
    1932       127055 :   if (yychar == YYEMPTY)
    1933              :     {
    1934              :       YYDPRINTF ((stderr, "Reading a token\n"));
    1935        82009 :       yychar = yylex (&yylval, &yylloc, yyscanner);
    1936              :     }
    1937              : 
    1938       127055 :   if (yychar <= YYEOF)
    1939              :     {
    1940         9822 :       yychar = YYEOF;
    1941         9822 :       yytoken = YYSYMBOL_YYEOF;
    1942              :       YYDPRINTF ((stderr, "Now at end of input.\n"));
    1943              :     }
    1944       117233 :   else if (yychar == YYerror)
    1945              :     {
    1946              :       /* The scanner already issued an error message, process directly
    1947              :          to error recovery.  But do not keep the error token as
    1948              :          lookahead, it is too special and may lead us to an endless
    1949              :          loop in error recovery. */
    1950            0 :       yychar = YYUNDEF;
    1951            0 :       yytoken = YYSYMBOL_YYerror;
    1952            0 :       yyerror_range[1] = yylloc;
    1953            0 :       goto yyerrlab1;
    1954              :     }
    1955              :   else
    1956              :     {
    1957       117233 :       yytoken = YYTRANSLATE (yychar);
    1958              :       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    1959              :     }
    1960              : 
    1961              :   /* If the proper action on seeing token YYTOKEN is to reduce or to
    1962              :      detect an error, take that action.  */
    1963       127055 :   yyn += yytoken;
    1964       127055 :   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    1965        36789 :     goto yydefault;
    1966        90266 :   yyn = yytable[yyn];
    1967        90266 :   if (yyn <= 0)
    1968              :     {
    1969              :       if (yytable_value_is_error (yyn))
    1970              :         goto yyerrlab;
    1971        11819 :       yyn = -yyn;
    1972        11819 :       goto yyreduce;
    1973              :     }
    1974              : 
    1975              :   /* Count tokens shifted since error; after three, turn off error
    1976              :      status.  */
    1977        78447 :   if (yyerrstatus)
    1978            0 :     yyerrstatus--;
    1979              : 
    1980              :   /* Shift the lookahead token.  */
    1981              :   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
    1982        78447 :   yystate = yyn;
    1983              :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    1984        78447 :   *++yyvsp = yylval;
    1985              :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    1986        78447 :   *++yylsp = yylloc;
    1987              : 
    1988              :   /* Discard the shifted token.  */
    1989        78447 :   yychar = YYEMPTY;
    1990        78447 :   goto yynewstate;
    1991              : 
    1992              : 
    1993              : /*-----------------------------------------------------------.
    1994              : | yydefault -- do the default action for the current state.  |
    1995              : `-----------------------------------------------------------*/
    1996       182874 : yydefault:
    1997       182874 :   yyn = yydefact[yystate];
    1998       182874 :   if (yyn == 0)
    1999            1 :     goto yyerrlab;
    2000       182873 :   goto yyreduce;
    2001              : 
    2002              : 
    2003              : /*-----------------------------.
    2004              : | yyreduce -- do a reduction.  |
    2005              : `-----------------------------*/
    2006       194692 : yyreduce:
    2007              :   /* yyn is the number of a rule to reduce with.  */
    2008       194692 :   yylen = yyr2[yyn];
    2009              : 
    2010              :   /* If YYLEN is nonzero, implement the default value of the action:
    2011              :      '$$ = $1'.
    2012              : 
    2013              :      Otherwise, the following line sets YYVAL to garbage.
    2014              :      This behavior is undocumented and Bison
    2015              :      users should not rely upon it.  Assigning to YYVAL
    2016              :      unconditionally makes the parser a bit smaller, and it avoids a
    2017              :      GCC warning that YYVAL may be used uninitialized.  */
    2018       194692 :   yyval = yyvsp[1-yylen];
    2019              : 
    2020              :   /* Default location. */
    2021       194692 :   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
    2022       194692 :   yyerror_range[1] = yyloc;
    2023              :   YY_REDUCE_PRINT (yyn);
    2024       194692 :   switch (yyn)
    2025              :     {
    2026         5960 :   case 2: /* pl_function: comp_options pl_block opt_semi  */
    2027              : #line 375 "pl_gram.y"
    2028              :                                         {
    2029              :                         *plpgsql_parse_result_p = (PLpgSQL_stmt_block *) (yyvsp[-1].stmt);
    2030              :                         (void) yynerrs;     /* suppress compiler warning */
    2031              :                     }
    2032              : #line 2033 "pl_gram.c"
    2033         5960 :     break;
    2034              : 
    2035            0 :   case 5: /* comp_option: '#' K_OPTION K_DUMP  */
    2036              : #line 386 "pl_gram.y"
    2037              :                                         {
    2038              :                         plpgsql_DumpExecTree = true;
    2039              :                     }
    2040              : #line 2041 "pl_gram.c"
    2041            0 :     break;
    2042              : 
    2043            8 :   case 6: /* comp_option: '#' K_PRINT_STRICT_PARAMS option_value  */
    2044              : #line 390 "pl_gram.y"
    2045              :                                         {
    2046              :                         if (strcmp((yyvsp[0].str), "on") == 0)
    2047              :                             plpgsql_curr_compile->print_strict_params = true;
    2048              :                         else if (strcmp((yyvsp[0].str), "off") == 0)
    2049              :                             plpgsql_curr_compile->print_strict_params = false;
    2050              :                         else
    2051              :                             elog(ERROR, "unrecognized print_strict_params option %s", (yyvsp[0].str));
    2052              :                     }
    2053              : #line 2054 "pl_gram.c"
    2054            8 :     break;
    2055              : 
    2056            0 :   case 7: /* comp_option: '#' K_VARIABLE_CONFLICT K_ERROR  */
    2057              : #line 399 "pl_gram.y"
    2058              :                                         {
    2059              :                         plpgsql_curr_compile->resolve_option = PLPGSQL_RESOLVE_ERROR;
    2060              :                     }
    2061              : #line 2062 "pl_gram.c"
    2062            0 :     break;
    2063              : 
    2064            4 :   case 8: /* comp_option: '#' K_VARIABLE_CONFLICT K_USE_VARIABLE  */
    2065              : #line 403 "pl_gram.y"
    2066              :                                         {
    2067              :                         plpgsql_curr_compile->resolve_option = PLPGSQL_RESOLVE_VARIABLE;
    2068              :                     }
    2069              : #line 2070 "pl_gram.c"
    2070            4 :     break;
    2071              : 
    2072            4 :   case 9: /* comp_option: '#' K_VARIABLE_CONFLICT K_USE_COLUMN  */
    2073              : #line 407 "pl_gram.y"
    2074              :                                         {
    2075              :                         plpgsql_curr_compile->resolve_option = PLPGSQL_RESOLVE_COLUMN;
    2076              :                     }
    2077              : #line 2078 "pl_gram.c"
    2078            4 :     break;
    2079              : 
    2080            8 :   case 10: /* option_value: T_WORD  */
    2081              : #line 413 "pl_gram.y"
    2082              :                                 {
    2083              :                     (yyval.str) = (yyvsp[0].word).ident;
    2084              :                 }
    2085              : #line 2086 "pl_gram.c"
    2086            8 :     break;
    2087              : 
    2088            0 :   case 11: /* option_value: unreserved_keyword  */
    2089              : #line 417 "pl_gram.y"
    2090              :                                 {
    2091              :                     (yyval.str) = pstrdup((yyvsp[0].keyword));
    2092              :                 }
    2093              : #line 2094 "pl_gram.c"
    2094            0 :     break;
    2095              : 
    2096         6102 :   case 14: /* pl_block: decl_sect K_BEGIN proc_sect exception_sect K_END opt_label  */
    2097              : #line 426 "pl_gram.y"
    2098              :                                         {
    2099              :                         PLpgSQL_stmt_block *new;
    2100              : 
    2101              :                         new = palloc0_object(PLpgSQL_stmt_block);
    2102              : 
    2103              :                         new->cmd_type    = PLPGSQL_STMT_BLOCK;
    2104              :                         new->lineno      = plpgsql_location_to_lineno((yylsp[-4]), yyscanner);
    2105              :                         new->stmtid      = ++plpgsql_curr_compile->nstatements;
    2106              :                         new->label       = (yyvsp[-5].declhdr).label;
    2107              :                         new->n_initvars = (yyvsp[-5].declhdr).n_initvars;
    2108              :                         new->initvarnos = (yyvsp[-5].declhdr).initvarnos;
    2109              :                         new->body        = (yyvsp[-3].list);
    2110              :                         new->exceptions  = (yyvsp[-2].exception_block);
    2111              : 
    2112              :                         check_labels((yyvsp[-5].declhdr).label, (yyvsp[0].str), (yylsp[0]), yyscanner);
    2113              :                         plpgsql_ns_pop();
    2114              : 
    2115              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    2116              :                     }
    2117              : #line 2118 "pl_gram.c"
    2118         6102 :     break;
    2119              : 
    2120         3971 :   case 15: /* decl_sect: opt_block_label  */
    2121              : #line 449 "pl_gram.y"
    2122              :                                         {
    2123              :                         /* done with decls, so resume identifier lookup */
    2124              :                         plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
    2125              :                         (yyval.declhdr).label     = (yyvsp[0].str);
    2126              :                         (yyval.declhdr).n_initvars = 0;
    2127              :                         (yyval.declhdr).initvarnos = NULL;
    2128              :                     }
    2129              : #line 2130 "pl_gram.c"
    2130         3971 :     break;
    2131              : 
    2132            6 :   case 16: /* decl_sect: opt_block_label decl_start  */
    2133              : #line 457 "pl_gram.y"
    2134              :                                         {
    2135              :                         plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
    2136              :                         (yyval.declhdr).label     = (yyvsp[-1].str);
    2137              :                         (yyval.declhdr).n_initvars = 0;
    2138              :                         (yyval.declhdr).initvarnos = NULL;
    2139              :                     }
    2140              : #line 2141 "pl_gram.c"
    2141            6 :     break;
    2142              : 
    2143         2203 :   case 17: /* decl_sect: opt_block_label decl_start decl_stmts  */
    2144              : #line 464 "pl_gram.y"
    2145              :                                         {
    2146              :                         plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
    2147              :                         (yyval.declhdr).label     = (yyvsp[-2].str);
    2148              :                         /* Remember variables declared in decl_stmts */
    2149              :                         (yyval.declhdr).n_initvars = plpgsql_add_initdatums(&((yyval.declhdr).initvarnos));
    2150              :                     }
    2151              : #line 2152 "pl_gram.c"
    2152         2203 :     break;
    2153              : 
    2154         2231 :   case 18: /* decl_start: K_DECLARE  */
    2155              : #line 473 "pl_gram.y"
    2156              :                                         {
    2157              :                         /* Forget any variables created before block */
    2158              :                         plpgsql_add_initdatums(NULL);
    2159              :                         /*
    2160              :                          * Disable scanner lookup of identifiers while
    2161              :                          * we process the decl_stmts
    2162              :                          */
    2163              :                         plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_DECLARE;
    2164              :                     }
    2165              : #line 2166 "pl_gram.c"
    2166         2231 :     break;
    2167              : 
    2168            0 :   case 22: /* decl_stmt: K_DECLARE  */
    2169              : #line 490 "pl_gram.y"
    2170              :                                         {
    2171              :                         /* We allow useless extra DECLAREs */
    2172              :                     }
    2173              : #line 2174 "pl_gram.c"
    2174            0 :     break;
    2175              : 
    2176            0 :   case 23: /* decl_stmt: LESS_LESS any_identifier GREATER_GREATER  */
    2177              : #line 494 "pl_gram.y"
    2178              :                                         {
    2179              :                         /*
    2180              :                          * Throw a helpful error if user tries to put block
    2181              :                          * label just before BEGIN, instead of before DECLARE.
    2182              :                          */
    2183              :                         ereport(ERROR,
    2184              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2185              :                                  errmsg("block label must be placed before DECLARE, not after"),
    2186              :                                  parser_errposition((yylsp[-2]))));
    2187              :                     }
    2188              : #line 2189 "pl_gram.c"
    2189              :     break;
    2190              : 
    2191         3564 :   case 24: /* decl_statement: decl_varname decl_const decl_datatype decl_collate decl_notnull decl_defval  */
    2192              : #line 507 "pl_gram.y"
    2193              :                                         {
    2194              :                         PLpgSQL_variable    *var;
    2195              : 
    2196              :                         /*
    2197              :                          * If a collation is supplied, insert it into the
    2198              :                          * datatype.  We assume decl_datatype always returns
    2199              :                          * a freshly built struct not shared with other
    2200              :                          * variables.
    2201              :                          */
    2202              :                         if (OidIsValid((yyvsp[-2].oid)))
    2203              :                         {
    2204              :                             if (!OidIsValid((yyvsp[-3].dtype)->collation))
    2205              :                                 ereport(ERROR,
    2206              :                                         (errcode(ERRCODE_DATATYPE_MISMATCH),
    2207              :                                          errmsg("collations are not supported by type %s",
    2208              :                                                 format_type_be((yyvsp[-3].dtype)->typoid)),
    2209              :                                          parser_errposition((yylsp[-2]))));
    2210              :                             (yyvsp[-3].dtype)->collation = (yyvsp[-2].oid);
    2211              :                         }
    2212              : 
    2213              :                         var = plpgsql_build_variable((yyvsp[-5].varname).name, (yyvsp[-5].varname).lineno,
    2214              :                                                      (yyvsp[-3].dtype), true);
    2215              :                         var->isconst = (yyvsp[-4].boolean);
    2216              :                         var->notnull = (yyvsp[-1].boolean);
    2217              :                         var->default_val = (yyvsp[0].expr);
    2218              : 
    2219              :                         /*
    2220              :                          * The combination of NOT NULL without an initializer
    2221              :                          * can't work, so let's reject it at compile time.
    2222              :                          */
    2223              :                         if (var->notnull && var->default_val == NULL)
    2224              :                             ereport(ERROR,
    2225              :                                     (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
    2226              :                                      errmsg("variable \"%s\" must have a default value, since it's declared NOT NULL",
    2227              :                                             var->refname),
    2228              :                                      parser_errposition((yylsp[-1]))));
    2229              : 
    2230              :                         if (var->default_val != NULL)
    2231              :                             mark_expr_as_assignment_source(var->default_val,
    2232              :                                                            (PLpgSQL_datum *) var);
    2233              :                     }
    2234              : #line 2235 "pl_gram.c"
    2235         3559 :     break;
    2236              : 
    2237           56 :   case 25: /* decl_statement: decl_varname K_ALIAS K_FOR decl_aliasitem ';'  */
    2238              : #line 549 "pl_gram.y"
    2239              :                                         {
    2240              :                         plpgsql_ns_additem((yyvsp[-1].nsitem)->itemtype,
    2241              :                                            (yyvsp[-1].nsitem)->itemno, (yyvsp[-4].varname).name);
    2242              :                     }
    2243              : #line 2244 "pl_gram.c"
    2244           56 :     break;
    2245              : 
    2246           81 :   case 26: /* $@1: %empty  */
    2247              : #line 554 "pl_gram.y"
    2248              :                                         { plpgsql_ns_push((yyvsp[-2].varname).name, PLPGSQL_LABEL_OTHER); }
    2249              : #line 2250 "pl_gram.c"
    2250           81 :     break;
    2251              : 
    2252           81 :   case 27: /* decl_statement: decl_varname opt_scrollable K_CURSOR $@1 decl_cursor_args decl_is_for decl_cursor_query  */
    2253              : #line 556 "pl_gram.y"
    2254              :                                         {
    2255              :                         PLpgSQL_var *new;
    2256              : 
    2257              :                         /* pop local namespace for cursor args */
    2258              :                         plpgsql_ns_pop();
    2259              : 
    2260              :                         new = (PLpgSQL_var *)
    2261              :                             plpgsql_build_variable((yyvsp[-6].varname).name, (yyvsp[-6].varname).lineno,
    2262              :                                                    plpgsql_build_datatype(REFCURSOROID,
    2263              :                                                                           -1,
    2264              :                                                                           InvalidOid,
    2265              :                                                                           NULL),
    2266              :                                                    true);
    2267              : 
    2268              :                         new->cursor_explicit_expr = (yyvsp[0].expr);
    2269              :                         if ((yyvsp[-2].datum) == NULL)
    2270              :                             new->cursor_explicit_argrow = -1;
    2271              :                         else
    2272              :                             new->cursor_explicit_argrow = (yyvsp[-2].datum)->dno;
    2273              :                         new->cursor_options = CURSOR_OPT_FAST_PLAN | (yyvsp[-5].ival);
    2274              :                     }
    2275              : #line 2276 "pl_gram.c"
    2276           81 :     break;
    2277              : 
    2278           73 :   case 28: /* opt_scrollable: %empty  */
    2279              : #line 580 "pl_gram.y"
    2280              :                                         {
    2281              :                         (yyval.ival) = 0;
    2282              :                     }
    2283              : #line 2284 "pl_gram.c"
    2284           73 :     break;
    2285              : 
    2286            4 :   case 29: /* opt_scrollable: K_NO K_SCROLL  */
    2287              : #line 584 "pl_gram.y"
    2288              :                                         {
    2289              :                         (yyval.ival) = CURSOR_OPT_NO_SCROLL;
    2290              :                     }
    2291              : #line 2292 "pl_gram.c"
    2292            4 :     break;
    2293              : 
    2294            4 :   case 30: /* opt_scrollable: K_SCROLL  */
    2295              : #line 588 "pl_gram.y"
    2296              :                                         {
    2297              :                         (yyval.ival) = CURSOR_OPT_SCROLL;
    2298              :                     }
    2299              : #line 2300 "pl_gram.c"
    2300            4 :     break;
    2301              : 
    2302           81 :   case 31: /* decl_cursor_query: %empty  */
    2303              : #line 594 "pl_gram.y"
    2304              :                                         {
    2305              :                         (yyval.expr) = read_sql_stmt(&yylval, &yylloc, yyscanner);
    2306              :                     }
    2307              : #line 2308 "pl_gram.c"
    2308           81 :     break;
    2309              : 
    2310           33 :   case 32: /* decl_cursor_args: %empty  */
    2311              : #line 600 "pl_gram.y"
    2312              :                                         {
    2313              :                         (yyval.datum) = NULL;
    2314              :                     }
    2315              : #line 2316 "pl_gram.c"
    2316           33 :     break;
    2317              : 
    2318           48 :   case 33: /* decl_cursor_args: '(' decl_cursor_arglist ')'  */
    2319              : #line 604 "pl_gram.y"
    2320              :                                         {
    2321              :                         PLpgSQL_row *new;
    2322              :                         int         i;
    2323              :                         ListCell   *l;
    2324              : 
    2325              :                         new = palloc0_object(PLpgSQL_row);
    2326              :                         new->dtype = PLPGSQL_DTYPE_ROW;
    2327              :                         new->refname = "(unnamed row)";
    2328              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    2329              :                         new->rowtupdesc = NULL;
    2330              :                         new->nfields = list_length((yyvsp[-1].list));
    2331              :                         new->fieldnames = palloc_array(char *, new->nfields);
    2332              :                         new->varnos = palloc_array(int, new->nfields);
    2333              : 
    2334              :                         i = 0;
    2335              :                         foreach (l, (yyvsp[-1].list))
    2336              :                         {
    2337              :                             PLpgSQL_variable *arg = (PLpgSQL_variable *) lfirst(l);
    2338              :                             Assert(!arg->isconst);
    2339              :                             new->fieldnames[i] = arg->refname;
    2340              :                             new->varnos[i] = arg->dno;
    2341              :                             i++;
    2342              :                         }
    2343              :                         list_free((yyvsp[-1].list));
    2344              : 
    2345              :                         plpgsql_adddatum((PLpgSQL_datum *) new);
    2346              :                         (yyval.datum) = (PLpgSQL_datum *) new;
    2347              :                     }
    2348              : #line 2349 "pl_gram.c"
    2349           48 :     break;
    2350              : 
    2351           48 :   case 34: /* decl_cursor_arglist: decl_cursor_arg  */
    2352              : #line 635 "pl_gram.y"
    2353              :                                         {
    2354              :                         (yyval.list) = list_make1((yyvsp[0].datum));
    2355              :                     }
    2356              : #line 2357 "pl_gram.c"
    2357           48 :     break;
    2358              : 
    2359           48 :   case 35: /* decl_cursor_arglist: decl_cursor_arglist ',' decl_cursor_arg  */
    2360              : #line 639 "pl_gram.y"
    2361              :                                         {
    2362              :                         (yyval.list) = lappend((yyvsp[-2].list), (yyvsp[0].datum));
    2363              :                     }
    2364              : #line 2365 "pl_gram.c"
    2365           48 :     break;
    2366              : 
    2367           96 :   case 36: /* decl_cursor_arg: decl_varname decl_datatype  */
    2368              : #line 645 "pl_gram.y"
    2369              :                                         {
    2370              :                         (yyval.datum) = (PLpgSQL_datum *)
    2371              :                             plpgsql_build_variable((yyvsp[-1].varname).name, (yyvsp[-1].varname).lineno,
    2372              :                                                    (yyvsp[0].dtype), true);
    2373              :                     }
    2374              : #line 2375 "pl_gram.c"
    2375           96 :     break;
    2376              : 
    2377           56 :   case 39: /* decl_aliasitem: T_WORD  */
    2378              : #line 656 "pl_gram.y"
    2379              :                                         {
    2380              :                         PLpgSQL_nsitem *nsi;
    2381              : 
    2382              :                         nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2383              :                                                 (yyvsp[0].word).ident, NULL, NULL,
    2384              :                                                 NULL);
    2385              :                         if (nsi == NULL)
    2386              :                             ereport(ERROR,
    2387              :                                     (errcode(ERRCODE_UNDEFINED_OBJECT),
    2388              :                                      errmsg("variable \"%s\" does not exist",
    2389              :                                             (yyvsp[0].word).ident),
    2390              :                                      parser_errposition((yylsp[0]))));
    2391              :                         (yyval.nsitem) = nsi;
    2392              :                     }
    2393              : #line 2394 "pl_gram.c"
    2394           56 :     break;
    2395              : 
    2396            0 :   case 40: /* decl_aliasitem: unreserved_keyword  */
    2397              : #line 671 "pl_gram.y"
    2398              :                                         {
    2399              :                         PLpgSQL_nsitem *nsi;
    2400              : 
    2401              :                         nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2402              :                                                 (yyvsp[0].keyword), NULL, NULL,
    2403              :                                                 NULL);
    2404              :                         if (nsi == NULL)
    2405              :                             ereport(ERROR,
    2406              :                                     (errcode(ERRCODE_UNDEFINED_OBJECT),
    2407              :                                      errmsg("variable \"%s\" does not exist",
    2408              :                                             (yyvsp[0].keyword)),
    2409              :                                      parser_errposition((yylsp[0]))));
    2410              :                         (yyval.nsitem) = nsi;
    2411              :                     }
    2412              : #line 2413 "pl_gram.c"
    2413            0 :     break;
    2414              : 
    2415            0 :   case 41: /* decl_aliasitem: T_CWORD  */
    2416              : #line 686 "pl_gram.y"
    2417              :                                         {
    2418              :                         PLpgSQL_nsitem *nsi;
    2419              : 
    2420              :                         if (list_length((yyvsp[0].cword).idents) == 2)
    2421              :                             nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2422              :                                                     strVal(linitial((yyvsp[0].cword).idents)),
    2423              :                                                     strVal(lsecond((yyvsp[0].cword).idents)),
    2424              :                                                     NULL,
    2425              :                                                     NULL);
    2426              :                         else if (list_length((yyvsp[0].cword).idents) == 3)
    2427              :                             nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2428              :                                                     strVal(linitial((yyvsp[0].cword).idents)),
    2429              :                                                     strVal(lsecond((yyvsp[0].cword).idents)),
    2430              :                                                     strVal(lthird((yyvsp[0].cword).idents)),
    2431              :                                                     NULL);
    2432              :                         else
    2433              :                             nsi = NULL;
    2434              :                         if (nsi == NULL)
    2435              :                             ereport(ERROR,
    2436              :                                     (errcode(ERRCODE_UNDEFINED_OBJECT),
    2437              :                                      errmsg("variable \"%s\" does not exist",
    2438              :                                             NameListToString((yyvsp[0].cword).idents)),
    2439              :                                      parser_errposition((yylsp[0]))));
    2440              :                         (yyval.nsitem) = nsi;
    2441              :                     }
    2442              : #line 2443 "pl_gram.c"
    2443            0 :     break;
    2444              : 
    2445         3794 :   case 42: /* decl_varname: T_WORD  */
    2446              : #line 714 "pl_gram.y"
    2447              :                                         {
    2448              :                         (yyval.varname).name = (yyvsp[0].word).ident;
    2449              :                         (yyval.varname).lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    2450              :                         /*
    2451              :                          * Check to make sure name isn't already declared
    2452              :                          * in the current block.
    2453              :                          */
    2454              :                         if (plpgsql_ns_lookup(plpgsql_ns_top(), true,
    2455              :                                               (yyvsp[0].word).ident, NULL, NULL,
    2456              :                                               NULL) != NULL)
    2457              :                             yyerror(&yylloc, NULL, yyscanner, "duplicate declaration");
    2458              : 
    2459              :                         if (plpgsql_curr_compile->extra_warnings & PLPGSQL_XCHECK_SHADOWVAR ||
    2460              :                             plpgsql_curr_compile->extra_errors & PLPGSQL_XCHECK_SHADOWVAR)
    2461              :                         {
    2462              :                             PLpgSQL_nsitem *nsi;
    2463              :                             nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2464              :                                                     (yyvsp[0].word).ident, NULL, NULL, NULL);
    2465              :                             if (nsi != NULL)
    2466              :                                 ereport(plpgsql_curr_compile->extra_errors & PLPGSQL_XCHECK_SHADOWVAR ? ERROR : WARNING,
    2467              :                                         (errcode(ERRCODE_DUPLICATE_ALIAS),
    2468              :                                          errmsg("variable \"%s\" shadows a previously defined variable",
    2469              :                                                 (yyvsp[0].word).ident),
    2470              :                                          parser_errposition((yylsp[0]))));
    2471              :                         }
    2472              : 
    2473              :                     }
    2474              : #line 2475 "pl_gram.c"
    2475         3790 :     break;
    2476              : 
    2477           20 :   case 43: /* decl_varname: unreserved_keyword  */
    2478              : #line 742 "pl_gram.y"
    2479              :                                         {
    2480              :                         (yyval.varname).name = pstrdup((yyvsp[0].keyword));
    2481              :                         (yyval.varname).lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    2482              :                         /*
    2483              :                          * Check to make sure name isn't already declared
    2484              :                          * in the current block.
    2485              :                          */
    2486              :                         if (plpgsql_ns_lookup(plpgsql_ns_top(), true,
    2487              :                                               (yyvsp[0].keyword), NULL, NULL,
    2488              :                                               NULL) != NULL)
    2489              :                             yyerror(&yylloc, NULL, yyscanner, "duplicate declaration");
    2490              : 
    2491              :                         if (plpgsql_curr_compile->extra_warnings & PLPGSQL_XCHECK_SHADOWVAR ||
    2492              :                             plpgsql_curr_compile->extra_errors & PLPGSQL_XCHECK_SHADOWVAR)
    2493              :                         {
    2494              :                             PLpgSQL_nsitem *nsi;
    2495              :                             nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2496              :                                                     (yyvsp[0].keyword), NULL, NULL, NULL);
    2497              :                             if (nsi != NULL)
    2498              :                                 ereport(plpgsql_curr_compile->extra_errors & PLPGSQL_XCHECK_SHADOWVAR ? ERROR : WARNING,
    2499              :                                         (errcode(ERRCODE_DUPLICATE_ALIAS),
    2500              :                                          errmsg("variable \"%s\" shadows a previously defined variable",
    2501              :                                                 (yyvsp[0].keyword)),
    2502              :                                          parser_errposition((yylsp[0]))));
    2503              :                         }
    2504              : 
    2505              :                     }
    2506              : #line 2507 "pl_gram.c"
    2507           20 :     break;
    2508              : 
    2509         3561 :   case 44: /* decl_const: %empty  */
    2510              : #line 772 "pl_gram.y"
    2511              :                                         { (yyval.boolean) = false; }
    2512              : #line 2513 "pl_gram.c"
    2513         3561 :     break;
    2514              : 
    2515           16 :   case 45: /* decl_const: K_CONSTANT  */
    2516              : #line 774 "pl_gram.y"
    2517              :                                         { (yyval.boolean) = true; }
    2518              : #line 2519 "pl_gram.c"
    2519           16 :     break;
    2520              : 
    2521         3673 :   case 46: /* decl_datatype: %empty  */
    2522              : #line 778 "pl_gram.y"
    2523              :                                         {
    2524              :                         /*
    2525              :                          * If there's a lookahead token, read_datatype() will
    2526              :                          * consume it, and then we must tell bison to forget
    2527              :                          * it.
    2528              :                          */
    2529              :                         (yyval.dtype) = read_datatype(yychar, &yylval, &yylloc, yyscanner);
    2530              :                         yyclearin;
    2531              :                     }
    2532              : #line 2533 "pl_gram.c"
    2533         3660 :     break;
    2534              : 
    2535         3548 :   case 47: /* decl_collate: %empty  */
    2536              : #line 790 "pl_gram.y"
    2537              :                                         { (yyval.oid) = InvalidOid; }
    2538              : #line 2539 "pl_gram.c"
    2539         3548 :     break;
    2540              : 
    2541           16 :   case 48: /* decl_collate: K_COLLATE T_WORD  */
    2542              : #line 792 "pl_gram.y"
    2543              :                                         {
    2544              :                         (yyval.oid) = get_collation_oid(list_make1(makeString((yyvsp[0].word).ident)),
    2545              :                                                false);
    2546              :                     }
    2547              : #line 2548 "pl_gram.c"
    2548           16 :     break;
    2549              : 
    2550            0 :   case 49: /* decl_collate: K_COLLATE unreserved_keyword  */
    2551              : #line 797 "pl_gram.y"
    2552              :                                         {
    2553              :                         (yyval.oid) = get_collation_oid(list_make1(makeString(pstrdup((yyvsp[0].keyword)))),
    2554              :                                                false);
    2555              :                     }
    2556              : #line 2557 "pl_gram.c"
    2557            0 :     break;
    2558              : 
    2559            0 :   case 50: /* decl_collate: K_COLLATE T_CWORD  */
    2560              : #line 802 "pl_gram.y"
    2561              :                                         {
    2562              :                         (yyval.oid) = get_collation_oid((yyvsp[0].cword).idents, false);
    2563              :                     }
    2564              : #line 2565 "pl_gram.c"
    2565            0 :     break;
    2566              : 
    2567         3551 :   case 51: /* decl_notnull: %empty  */
    2568              : #line 808 "pl_gram.y"
    2569              :                                         { (yyval.boolean) = false; }
    2570              : #line 2571 "pl_gram.c"
    2571         3551 :     break;
    2572              : 
    2573           13 :   case 52: /* decl_notnull: K_NOT K_NULL  */
    2574              : #line 810 "pl_gram.y"
    2575              :                                         { (yyval.boolean) = true; }
    2576              : #line 2577 "pl_gram.c"
    2577           13 :     break;
    2578              : 
    2579         3041 :   case 53: /* decl_defval: ';'  */
    2580              : #line 814 "pl_gram.y"
    2581              :                                         { (yyval.expr) = NULL; }
    2582              : #line 2583 "pl_gram.c"
    2583         3041 :     break;
    2584              : 
    2585          523 :   case 54: /* decl_defval: decl_defkey  */
    2586              : #line 816 "pl_gram.y"
    2587              :                                         {
    2588              :                         (yyval.expr) = read_sql_expression(';', ";", &yylval, &yylloc, yyscanner);
    2589              :                     }
    2590              : #line 2591 "pl_gram.c"
    2591          523 :     break;
    2592              : 
    2593        13015 :   case 59: /* proc_sect: %empty  */
    2594              : #line 835 "pl_gram.y"
    2595              :                                         { (yyval.list) = NIL; }
    2596              : #line 2597 "pl_gram.c"
    2597        13015 :     break;
    2598              : 
    2599        24740 :   case 60: /* proc_sect: proc_sect proc_stmt  */
    2600              : #line 837 "pl_gram.y"
    2601              :                                         {
    2602              :                         /* don't bother linking null statements into list */
    2603              :                         if ((yyvsp[0].stmt) == NULL)
    2604              :                             (yyval.list) = (yyvsp[-1].list);
    2605              :                         else
    2606              :                             (yyval.list) = lappend((yyvsp[-1].list), (yyvsp[0].stmt));
    2607              :                     }
    2608              : #line 2609 "pl_gram.c"
    2609        24740 :     break;
    2610              : 
    2611          142 :   case 61: /* proc_stmt: pl_block ';'  */
    2612              : #line 847 "pl_gram.y"
    2613              :                                                 { (yyval.stmt) = (yyvsp[-1].stmt); }
    2614              : #line 2615 "pl_gram.c"
    2615          142 :     break;
    2616              : 
    2617         4462 :   case 62: /* proc_stmt: stmt_assign  */
    2618              : #line 849 "pl_gram.y"
    2619              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2620              : #line 2621 "pl_gram.c"
    2621         4462 :     break;
    2622              : 
    2623         3968 :   case 63: /* proc_stmt: stmt_if  */
    2624              : #line 851 "pl_gram.y"
    2625              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2626              : #line 2627 "pl_gram.c"
    2627         3968 :     break;
    2628              : 
    2629           11 :   case 64: /* proc_stmt: stmt_case  */
    2630              : #line 853 "pl_gram.y"
    2631              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2632              : #line 2633 "pl_gram.c"
    2633           11 :     break;
    2634              : 
    2635           45 :   case 65: /* proc_stmt: stmt_loop  */
    2636              : #line 855 "pl_gram.y"
    2637              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2638              : #line 2639 "pl_gram.c"
    2639           45 :     break;
    2640              : 
    2641           51 :   case 66: /* proc_stmt: stmt_while  */
    2642              : #line 857 "pl_gram.y"
    2643              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2644              : #line 2645 "pl_gram.c"
    2645           51 :     break;
    2646              : 
    2647          921 :   case 67: /* proc_stmt: stmt_for  */
    2648              : #line 859 "pl_gram.y"
    2649              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2650              : #line 2651 "pl_gram.c"
    2651          921 :     break;
    2652              : 
    2653           41 :   case 68: /* proc_stmt: stmt_foreach_a  */
    2654              : #line 861 "pl_gram.y"
    2655              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2656              : #line 2657 "pl_gram.c"
    2657           41 :     break;
    2658              : 
    2659          127 :   case 69: /* proc_stmt: stmt_exit  */
    2660              : #line 863 "pl_gram.y"
    2661              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2662              : #line 2663 "pl_gram.c"
    2663          127 :     break;
    2664              : 
    2665         5943 :   case 70: /* proc_stmt: stmt_return  */
    2666              : #line 865 "pl_gram.y"
    2667              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2668              : #line 2669 "pl_gram.c"
    2669         5943 :     break;
    2670              : 
    2671         4623 :   case 71: /* proc_stmt: stmt_raise  */
    2672              : #line 867 "pl_gram.y"
    2673              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2674              : #line 2675 "pl_gram.c"
    2675         4623 :     break;
    2676              : 
    2677           34 :   case 72: /* proc_stmt: stmt_assert  */
    2678              : #line 869 "pl_gram.y"
    2679              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2680              : #line 2681 "pl_gram.c"
    2681           34 :     break;
    2682              : 
    2683         2539 :   case 73: /* proc_stmt: stmt_execsql  */
    2684              : #line 871 "pl_gram.y"
    2685              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2686              : #line 2687 "pl_gram.c"
    2687         2539 :     break;
    2688              : 
    2689          633 :   case 74: /* proc_stmt: stmt_dynexecute  */
    2690              : #line 873 "pl_gram.y"
    2691              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2692              : #line 2693 "pl_gram.c"
    2693          633 :     break;
    2694              : 
    2695          758 :   case 75: /* proc_stmt: stmt_perform  */
    2696              : #line 875 "pl_gram.y"
    2697              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2698              : #line 2699 "pl_gram.c"
    2699          758 :     break;
    2700              : 
    2701           54 :   case 76: /* proc_stmt: stmt_call  */
    2702              : #line 877 "pl_gram.y"
    2703              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2704              : #line 2705 "pl_gram.c"
    2705           54 :     break;
    2706              : 
    2707           90 :   case 77: /* proc_stmt: stmt_getdiag  */
    2708              : #line 879 "pl_gram.y"
    2709              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2710              : #line 2711 "pl_gram.c"
    2711           90 :     break;
    2712              : 
    2713           77 :   case 78: /* proc_stmt: stmt_open  */
    2714              : #line 881 "pl_gram.y"
    2715              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2716              : #line 2717 "pl_gram.c"
    2717           77 :     break;
    2718              : 
    2719           81 :   case 79: /* proc_stmt: stmt_fetch  */
    2720              : #line 883 "pl_gram.y"
    2721              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2722              : #line 2723 "pl_gram.c"
    2723           81 :     break;
    2724              : 
    2725           12 :   case 80: /* proc_stmt: stmt_move  */
    2726              : #line 885 "pl_gram.y"
    2727              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2728              : #line 2729 "pl_gram.c"
    2729           12 :     break;
    2730              : 
    2731           44 :   case 81: /* proc_stmt: stmt_close  */
    2732              : #line 887 "pl_gram.y"
    2733              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2734              : #line 2735 "pl_gram.c"
    2735           44 :     break;
    2736              : 
    2737           20 :   case 82: /* proc_stmt: stmt_null  */
    2738              : #line 889 "pl_gram.y"
    2739              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2740              : #line 2741 "pl_gram.c"
    2741           20 :     break;
    2742              : 
    2743           39 :   case 83: /* proc_stmt: stmt_commit  */
    2744              : #line 891 "pl_gram.y"
    2745              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2746              : #line 2747 "pl_gram.c"
    2747           39 :     break;
    2748              : 
    2749           25 :   case 84: /* proc_stmt: stmt_rollback  */
    2750              : #line 893 "pl_gram.y"
    2751              :                                                 { (yyval.stmt) = (yyvsp[0].stmt); }
    2752              : #line 2753 "pl_gram.c"
    2753           25 :     break;
    2754              : 
    2755          758 :   case 85: /* stmt_perform: K_PERFORM  */
    2756              : #line 897 "pl_gram.y"
    2757              :                                         {
    2758              :                         PLpgSQL_stmt_perform *new;
    2759              :                         int         startloc;
    2760              : 
    2761              :                         new = palloc0_object(PLpgSQL_stmt_perform);
    2762              :                         new->cmd_type = PLPGSQL_STMT_PERFORM;
    2763              :                         new->lineno   = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    2764              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2765              :                         plpgsql_push_back_token(K_PERFORM, &yylval, &yylloc, yyscanner);
    2766              : 
    2767              :                         /*
    2768              :                          * Since PERFORM isn't legal SQL, we have to cheat to
    2769              :                          * the extent of substituting "SELECT" for "PERFORM"
    2770              :                          * in the parsed text.  It does not seem worth
    2771              :                          * inventing a separate parse mode for this one case.
    2772              :                          * We can't do syntax-checking until after we make the
    2773              :                          * substitution.
    2774              :                          */
    2775              :                         new->expr = read_sql_construct(';', 0, 0, ";",
    2776              :                                                        RAW_PARSE_DEFAULT,
    2777              :                                                        false, false,
    2778              :                                                        &startloc, NULL,
    2779              :                                                        &yylval, &yylloc, yyscanner);
    2780              :                         /* overwrite "perform" ... */
    2781              :                         memcpy(new->expr->query, " SELECT", 7);
    2782              :                         /* left-justify to get rid of the leading space */
    2783              :                         memmove(new->expr->query, new->expr->query + 1,
    2784              :                                 strlen(new->expr->query));
    2785              :                         /* offset syntax error position to account for that */
    2786              :                         check_sql_expr(new->expr->query, new->expr->parseMode,
    2787              :                                        startloc + 1, yyscanner);
    2788              : 
    2789              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    2790              :                     }
    2791              : #line 2792 "pl_gram.c"
    2792          758 :     break;
    2793              : 
    2794           53 :   case 86: /* stmt_call: K_CALL  */
    2795              : #line 934 "pl_gram.y"
    2796              :                                         {
    2797              :                         PLpgSQL_stmt_call *new;
    2798              : 
    2799              :                         new = palloc0_object(PLpgSQL_stmt_call);
    2800              :                         new->cmd_type = PLPGSQL_STMT_CALL;
    2801              :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    2802              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2803              :                         plpgsql_push_back_token(K_CALL, &yylval, &yylloc, yyscanner);
    2804              :                         new->expr = read_sql_stmt(&yylval, &yylloc, yyscanner);
    2805              :                         new->is_call = true;
    2806              : 
    2807              :                         /* Remember we may need a procedure resource owner */
    2808              :                         plpgsql_curr_compile->requires_procedure_resowner = true;
    2809              : 
    2810              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    2811              : 
    2812              :                     }
    2813              : #line 2814 "pl_gram.c"
    2814           53 :     break;
    2815              : 
    2816            1 :   case 87: /* stmt_call: K_DO  */
    2817              : #line 952 "pl_gram.y"
    2818              :                                         {
    2819              :                         /* use the same structures as for CALL, for simplicity */
    2820              :                         PLpgSQL_stmt_call *new;
    2821              : 
    2822              :                         new = palloc0_object(PLpgSQL_stmt_call);
    2823              :                         new->cmd_type = PLPGSQL_STMT_CALL;
    2824              :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    2825              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2826              :                         plpgsql_push_back_token(K_DO, &yylval, &yylloc, yyscanner);
    2827              :                         new->expr = read_sql_stmt(&yylval, &yylloc, yyscanner);
    2828              :                         new->is_call = false;
    2829              : 
    2830              :                         /* Remember we may need a procedure resource owner */
    2831              :                         plpgsql_curr_compile->requires_procedure_resowner = true;
    2832              : 
    2833              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    2834              : 
    2835              :                     }
    2836              : #line 2837 "pl_gram.c"
    2837            1 :     break;
    2838              : 
    2839         4465 :   case 88: /* stmt_assign: T_DATUM  */
    2840              : #line 973 "pl_gram.y"
    2841              :                                         {
    2842              :                         PLpgSQL_stmt_assign *new;
    2843              :                         RawParseMode pmode;
    2844              : 
    2845              :                         /* see how many names identify the datum */
    2846              :                         switch ((yyvsp[0].wdatum).ident ? 1 : list_length((yyvsp[0].wdatum).idents))
    2847              :                         {
    2848              :                             case 1:
    2849              :                                 pmode = RAW_PARSE_PLPGSQL_ASSIGN1;
    2850              :                                 break;
    2851              :                             case 2:
    2852              :                                 pmode = RAW_PARSE_PLPGSQL_ASSIGN2;
    2853              :                                 break;
    2854              :                             case 3:
    2855              :                                 pmode = RAW_PARSE_PLPGSQL_ASSIGN3;
    2856              :                                 break;
    2857              :                             default:
    2858              :                                 elog(ERROR, "unexpected number of names");
    2859              :                                 pmode = 0; /* keep compiler quiet */
    2860              :                         }
    2861              : 
    2862              :                         check_assignable((yyvsp[0].wdatum).datum, (yylsp[0]), yyscanner);
    2863              :                         new = palloc0_object(PLpgSQL_stmt_assign);
    2864              :                         new->cmd_type = PLPGSQL_STMT_ASSIGN;
    2865              :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    2866              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2867              :                         new->varno = (yyvsp[0].wdatum).datum->dno;
    2868              :                         /* Push back the head name to include it in the stmt */
    2869              :                         plpgsql_push_back_token(T_DATUM, &yylval, &yylloc, yyscanner);
    2870              :                         new->expr = read_sql_construct(';', 0, 0, ";",
    2871              :                                                        pmode,
    2872              :                                                        false, true,
    2873              :                                                        NULL, NULL,
    2874              :                                                        &yylval, &yylloc, yyscanner);
    2875              :                         mark_expr_as_assignment_source(new->expr, (yyvsp[0].wdatum).datum);
    2876              : 
    2877              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    2878              :                     }
    2879              : #line 2880 "pl_gram.c"
    2880         4462 :     break;
    2881              : 
    2882           90 :   case 89: /* stmt_getdiag: K_GET getdiag_area_opt K_DIAGNOSTICS getdiag_list ';'  */
    2883              : #line 1014 "pl_gram.y"
    2884              :                                         {
    2885              :                         PLpgSQL_stmt_getdiag *new;
    2886              :                         ListCell       *lc;
    2887              : 
    2888              :                         new = palloc0_object(PLpgSQL_stmt_getdiag);
    2889              :                         new->cmd_type = PLPGSQL_STMT_GETDIAG;
    2890              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-4]), yyscanner);
    2891              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2892              :                         new->is_stacked = (yyvsp[-3].boolean);
    2893              :                         new->diag_items = (yyvsp[-1].list);
    2894              : 
    2895              :                         /*
    2896              :                          * Check information items are valid for area option.
    2897              :                          */
    2898              :                         foreach(lc, new->diag_items)
    2899              :                         {
    2900              :                             PLpgSQL_diag_item *ditem = (PLpgSQL_diag_item *) lfirst(lc);
    2901              : 
    2902              :                             switch (ditem->kind)
    2903              :                             {
    2904              :                                 /* these fields are disallowed in stacked case */
    2905              :                                 case PLPGSQL_GETDIAG_ROW_COUNT:
    2906              :                                 case PLPGSQL_GETDIAG_ROUTINE_OID:
    2907              :                                     if (new->is_stacked)
    2908              :                                         ereport(ERROR,
    2909              :                                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2910              :                                                  errmsg("diagnostics item %s is not allowed in GET STACKED DIAGNOSTICS",
    2911              :                                                         plpgsql_getdiag_kindname(ditem->kind)),
    2912              :                                                  parser_errposition((yylsp[-4]))));
    2913              :                                     break;
    2914              :                                 /* these fields are disallowed in current case */
    2915              :                                 case PLPGSQL_GETDIAG_ERROR_CONTEXT:
    2916              :                                 case PLPGSQL_GETDIAG_ERROR_DETAIL:
    2917              :                                 case PLPGSQL_GETDIAG_ERROR_HINT:
    2918              :                                 case PLPGSQL_GETDIAG_RETURNED_SQLSTATE:
    2919              :                                 case PLPGSQL_GETDIAG_COLUMN_NAME:
    2920              :                                 case PLPGSQL_GETDIAG_CONSTRAINT_NAME:
    2921              :                                 case PLPGSQL_GETDIAG_DATATYPE_NAME:
    2922              :                                 case PLPGSQL_GETDIAG_MESSAGE_TEXT:
    2923              :                                 case PLPGSQL_GETDIAG_TABLE_NAME:
    2924              :                                 case PLPGSQL_GETDIAG_SCHEMA_NAME:
    2925              :                                     if (!new->is_stacked)
    2926              :                                         ereport(ERROR,
    2927              :                                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2928              :                                                  errmsg("diagnostics item %s is not allowed in GET CURRENT DIAGNOSTICS",
    2929              :                                                         plpgsql_getdiag_kindname(ditem->kind)),
    2930              :                                                  parser_errposition((yylsp[-4]))));
    2931              :                                     break;
    2932              :                                 /* these fields are allowed in either case */
    2933              :                                 case PLPGSQL_GETDIAG_CONTEXT:
    2934              :                                     break;
    2935              :                                 default:
    2936              :                                     elog(ERROR, "unrecognized diagnostic item kind: %d",
    2937              :                                          ditem->kind);
    2938              :                                     break;
    2939              :                             }
    2940              :                         }
    2941              : 
    2942              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    2943              :                     }
    2944              : #line 2945 "pl_gram.c"
    2945           90 :     break;
    2946              : 
    2947           76 :   case 90: /* getdiag_area_opt: %empty  */
    2948              : #line 1077 "pl_gram.y"
    2949              :                                         {
    2950              :                         (yyval.boolean) = false;
    2951              :                     }
    2952              : #line 2953 "pl_gram.c"
    2953           76 :     break;
    2954              : 
    2955            0 :   case 91: /* getdiag_area_opt: K_CURRENT  */
    2956              : #line 1081 "pl_gram.y"
    2957              :                                         {
    2958              :                         (yyval.boolean) = false;
    2959              :                     }
    2960              : #line 2961 "pl_gram.c"
    2961            0 :     break;
    2962              : 
    2963           18 :   case 92: /* getdiag_area_opt: K_STACKED  */
    2964              : #line 1085 "pl_gram.y"
    2965              :                                         {
    2966              :                         (yyval.boolean) = true;
    2967              :                     }
    2968              : #line 2969 "pl_gram.c"
    2969           18 :     break;
    2970              : 
    2971           48 :   case 93: /* getdiag_list: getdiag_list ',' getdiag_list_item  */
    2972              : #line 1091 "pl_gram.y"
    2973              :                                         {
    2974              :                         (yyval.list) = lappend((yyvsp[-2].list), (yyvsp[0].diagitem));
    2975              :                     }
    2976              : #line 2977 "pl_gram.c"
    2977           48 :     break;
    2978              : 
    2979           90 :   case 94: /* getdiag_list: getdiag_list_item  */
    2980              : #line 1095 "pl_gram.y"
    2981              :                                         {
    2982              :                         (yyval.list) = list_make1((yyvsp[0].diagitem));
    2983              :                     }
    2984              : #line 2985 "pl_gram.c"
    2985           90 :     break;
    2986              : 
    2987          138 :   case 95: /* getdiag_list_item: getdiag_target assign_operator getdiag_item  */
    2988              : #line 1101 "pl_gram.y"
    2989              :                                         {
    2990              :                         PLpgSQL_diag_item *new;
    2991              : 
    2992              :                         new = palloc_object(PLpgSQL_diag_item);
    2993              :                         new->target = (yyvsp[-2].datum)->dno;
    2994              :                         new->kind = (yyvsp[0].ival);
    2995              : 
    2996              :                         (yyval.diagitem) = new;
    2997              :                     }
    2998              : #line 2999 "pl_gram.c"
    2999          138 :     break;
    3000              : 
    3001          138 :   case 96: /* getdiag_item: %empty  */
    3002              : #line 1113 "pl_gram.y"
    3003              :                                         {
    3004              :                         int         tok = yylex(&yylval, &yylloc, yyscanner);
    3005              : 
    3006              :                         if (tok_is_keyword(tok, &yylval,
    3007              :                                            K_ROW_COUNT, "row_count"))
    3008              :                             (yyval.ival) = PLPGSQL_GETDIAG_ROW_COUNT;
    3009              :                         else if (tok_is_keyword(tok, &yylval,
    3010              :                                                 K_PG_ROUTINE_OID, "pg_routine_oid"))
    3011              :                             (yyval.ival) = PLPGSQL_GETDIAG_ROUTINE_OID;
    3012              :                         else if (tok_is_keyword(tok, &yylval,
    3013              :                                                 K_PG_CONTEXT, "pg_context"))
    3014              :                             (yyval.ival) = PLPGSQL_GETDIAG_CONTEXT;
    3015              :                         else if (tok_is_keyword(tok, &yylval,
    3016              :                                                 K_PG_EXCEPTION_DETAIL, "pg_exception_detail"))
    3017              :                             (yyval.ival) = PLPGSQL_GETDIAG_ERROR_DETAIL;
    3018              :                         else if (tok_is_keyword(tok, &yylval,
    3019              :                                                 K_PG_EXCEPTION_HINT, "pg_exception_hint"))
    3020              :                             (yyval.ival) = PLPGSQL_GETDIAG_ERROR_HINT;
    3021              :                         else if (tok_is_keyword(tok, &yylval,
    3022              :                                                 K_PG_EXCEPTION_CONTEXT, "pg_exception_context"))
    3023              :                             (yyval.ival) = PLPGSQL_GETDIAG_ERROR_CONTEXT;
    3024              :                         else if (tok_is_keyword(tok, &yylval,
    3025              :                                                 K_COLUMN_NAME, "column_name"))
    3026              :                             (yyval.ival) = PLPGSQL_GETDIAG_COLUMN_NAME;
    3027              :                         else if (tok_is_keyword(tok, &yylval,
    3028              :                                                 K_CONSTRAINT_NAME, "constraint_name"))
    3029              :                             (yyval.ival) = PLPGSQL_GETDIAG_CONSTRAINT_NAME;
    3030              :                         else if (tok_is_keyword(tok, &yylval,
    3031              :                                                 K_PG_DATATYPE_NAME, "pg_datatype_name"))
    3032              :                             (yyval.ival) = PLPGSQL_GETDIAG_DATATYPE_NAME;
    3033              :                         else if (tok_is_keyword(tok, &yylval,
    3034              :                                                 K_MESSAGE_TEXT, "message_text"))
    3035              :                             (yyval.ival) = PLPGSQL_GETDIAG_MESSAGE_TEXT;
    3036              :                         else if (tok_is_keyword(tok, &yylval,
    3037              :                                                 K_TABLE_NAME, "table_name"))
    3038              :                             (yyval.ival) = PLPGSQL_GETDIAG_TABLE_NAME;
    3039              :                         else if (tok_is_keyword(tok, &yylval,
    3040              :                                                 K_SCHEMA_NAME, "schema_name"))
    3041              :                             (yyval.ival) = PLPGSQL_GETDIAG_SCHEMA_NAME;
    3042              :                         else if (tok_is_keyword(tok, &yylval,
    3043              :                                                 K_RETURNED_SQLSTATE, "returned_sqlstate"))
    3044              :                             (yyval.ival) = PLPGSQL_GETDIAG_RETURNED_SQLSTATE;
    3045              :                         else
    3046              :                             yyerror(&yylloc, NULL, yyscanner, "unrecognized GET DIAGNOSTICS item");
    3047              :                     }
    3048              : #line 3049 "pl_gram.c"
    3049          138 :     break;
    3050              : 
    3051          142 :   case 97: /* getdiag_target: T_DATUM  */
    3052              : #line 1161 "pl_gram.y"
    3053              :                                         {
    3054              :                         /*
    3055              :                          * In principle we should support a getdiag_target
    3056              :                          * that is an array element, but for now we don't, so
    3057              :                          * just throw an error if next token is '['.
    3058              :                          */
    3059              :                         if ((yyvsp[0].wdatum).datum->dtype == PLPGSQL_DTYPE_ROW ||
    3060              :                             (yyvsp[0].wdatum).datum->dtype == PLPGSQL_DTYPE_REC ||
    3061              :                             plpgsql_peek(yyscanner) == '[')
    3062              :                             ereport(ERROR,
    3063              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3064              :                                      errmsg("\"%s\" is not a scalar variable",
    3065              :                                             NameOfDatum(&((yyvsp[0].wdatum)))),
    3066              :                                      parser_errposition((yylsp[0]))));
    3067              :                         check_assignable((yyvsp[0].wdatum).datum, (yylsp[0]), yyscanner);
    3068              :                         (yyval.datum) = (yyvsp[0].wdatum).datum;
    3069              :                     }
    3070              : #line 3071 "pl_gram.c"
    3071          138 :     break;
    3072              : 
    3073            0 :   case 98: /* getdiag_target: T_WORD  */
    3074              : #line 1179 "pl_gram.y"
    3075              :                                         {
    3076              :                         /* just to give a better message than "syntax error" */
    3077              :                         word_is_not_variable(&((yyvsp[0].word)), (yylsp[0]), yyscanner);
    3078              :                     }
    3079              : #line 3080 "pl_gram.c"
    3080            0 :     break;
    3081              : 
    3082            0 :   case 99: /* getdiag_target: T_CWORD  */
    3083              : #line 1184 "pl_gram.y"
    3084              :                                         {
    3085              :                         /* just to give a better message than "syntax error" */
    3086              :                         cword_is_not_variable(&((yyvsp[0].cword)), (yylsp[0]), yyscanner);
    3087              :                     }
    3088              : #line 3089 "pl_gram.c"
    3089            0 :     break;
    3090              : 
    3091         3968 :   case 100: /* stmt_if: K_IF expr_until_then proc_sect stmt_elsifs stmt_else K_END K_IF ';'  */
    3092              : #line 1191 "pl_gram.y"
    3093              :                                         {
    3094              :                         PLpgSQL_stmt_if *new;
    3095              : 
    3096              :                         new = palloc0_object(PLpgSQL_stmt_if);
    3097              :                         new->cmd_type = PLPGSQL_STMT_IF;
    3098              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-7]), yyscanner);
    3099              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    3100              :                         new->cond = (yyvsp[-6].expr);
    3101              :                         new->then_body = (yyvsp[-5].list);
    3102              :                         new->elsif_list = (yyvsp[-4].list);
    3103              :                         new->else_body = (yyvsp[-3].list);
    3104              : 
    3105              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    3106              :                     }
    3107              : #line 3108 "pl_gram.c"
    3108         3968 :     break;
    3109              : 
    3110         3968 :   case 101: /* stmt_elsifs: %empty  */
    3111              : #line 1208 "pl_gram.y"
    3112              :                                         {
    3113              :                         (yyval.list) = NIL;
    3114              :                     }
    3115              : #line 3116 "pl_gram.c"
    3116         3968 :     break;
    3117              : 
    3118          691 :   case 102: /* stmt_elsifs: stmt_elsifs K_ELSIF expr_until_then proc_sect  */
    3119              : #line 1212 "pl_gram.y"
    3120              :                                         {
    3121              :                         PLpgSQL_if_elsif *new;
    3122              : 
    3123              :                         new = palloc0_object(PLpgSQL_if_elsif);
    3124              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    3125              :                         new->cond = (yyvsp[-1].expr);
    3126              :                         new->stmts = (yyvsp[0].list);
    3127              : 
    3128              :                         (yyval.list) = lappend((yyvsp[-3].list), new);
    3129              :                     }
    3130              : #line 3131 "pl_gram.c"
    3131          691 :     break;
    3132              : 
    3133         3163 :   case 103: /* stmt_else: %empty  */
    3134              : #line 1225 "pl_gram.y"
    3135              :                                         {
    3136              :                         (yyval.list) = NIL;
    3137              :                     }
    3138              : #line 3139 "pl_gram.c"
    3139         3163 :     break;
    3140              : 
    3141          805 :   case 104: /* stmt_else: K_ELSE proc_sect  */
    3142              : #line 1229 "pl_gram.y"
    3143              :                                         {
    3144              :                         (yyval.list) = (yyvsp[0].list);
    3145              :                     }
    3146              : #line 3147 "pl_gram.c"
    3147          805 :     break;
    3148              : 
    3149           11 :   case 105: /* stmt_case: K_CASE opt_expr_until_when case_when_list opt_case_else K_END K_CASE ';'  */
    3150              : #line 1235 "pl_gram.y"
    3151              :                                         {
    3152              :                         (yyval.stmt) = make_case((yylsp[-6]), (yyvsp[-5].expr), (yyvsp[-4].list), (yyvsp[-3].list), yyscanner);
    3153              :                     }
    3154              : #line 3155 "pl_gram.c"
    3155           11 :     break;
    3156              : 
    3157           11 :   case 106: /* opt_expr_until_when: %empty  */
    3158              : #line 1241 "pl_gram.y"
    3159              :                                         {
    3160              :                         PLpgSQL_expr *expr = NULL;
    3161              :                         int         tok = yylex(&yylval, &yylloc, yyscanner);
    3162              : 
    3163              :                         if (tok != K_WHEN)
    3164              :                         {
    3165              :                             plpgsql_push_back_token(tok, &yylval, &yylloc, yyscanner);
    3166              :                             expr = read_sql_expression(K_WHEN, "WHEN", &yylval, &yylloc, yyscanner);
    3167              :                         }
    3168              :                         plpgsql_push_back_token(K_WHEN, &yylval, &yylloc, yyscanner);
    3169              :                         (yyval.expr) = expr;
    3170              :                     }
    3171              : #line 3172 "pl_gram.c"
    3172           11 :     break;
    3173              : 
    3174           13 :   case 107: /* case_when_list: case_when_list case_when  */
    3175              : #line 1256 "pl_gram.y"
    3176              :                                         {
    3177              :                         (yyval.list) = lappend((yyvsp[-1].list), (yyvsp[0].casewhen));
    3178              :                     }
    3179              : #line 3180 "pl_gram.c"
    3180           13 :     break;
    3181              : 
    3182           11 :   case 108: /* case_when_list: case_when  */
    3183              : #line 1260 "pl_gram.y"
    3184              :                                         {
    3185              :                         (yyval.list) = list_make1((yyvsp[0].casewhen));
    3186              :                     }
    3187              : #line 3188 "pl_gram.c"
    3188           11 :     break;
    3189              : 
    3190           24 :   case 109: /* case_when: K_WHEN expr_until_then proc_sect  */
    3191              : #line 1266 "pl_gram.y"
    3192              :                                         {
    3193              :                         PLpgSQL_case_when *new = palloc_object(PLpgSQL_case_when);
    3194              : 
    3195              :                         new->lineno  = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    3196              :                         new->expr = (yyvsp[-1].expr);
    3197              :                         new->stmts = (yyvsp[0].list);
    3198              :                         (yyval.casewhen) = new;
    3199              :                     }
    3200              : #line 3201 "pl_gram.c"
    3201           24 :     break;
    3202              : 
    3203            9 :   case 110: /* opt_case_else: %empty  */
    3204              : #line 1277 "pl_gram.y"
    3205              :                                         {
    3206              :                         (yyval.list) = NIL;
    3207              :                     }
    3208              : #line 3209 "pl_gram.c"
    3209            9 :     break;
    3210              : 
    3211            2 :   case 111: /* opt_case_else: K_ELSE proc_sect  */
    3212              : #line 1281 "pl_gram.y"
    3213              :                                         {
    3214              :                         /*
    3215              :                          * proc_sect could return an empty list, but we
    3216              :                          * must distinguish that from not having ELSE at all.
    3217              :                          * Simplest fix is to return a list with one NULL
    3218              :                          * pointer, which make_case() must take care of.
    3219              :                          */
    3220              :                         if ((yyvsp[0].list) != NIL)
    3221              :                             (yyval.list) = (yyvsp[0].list);
    3222              :                         else
    3223              :                             (yyval.list) = list_make1(NULL);
    3224              :                     }
    3225              : #line 3226 "pl_gram.c"
    3226            2 :     break;
    3227              : 
    3228           45 :   case 112: /* stmt_loop: opt_loop_label K_LOOP loop_body  */
    3229              : #line 1296 "pl_gram.y"
    3230              :                                         {
    3231              :                         PLpgSQL_stmt_loop *new;
    3232              : 
    3233              :                         new = palloc0_object(PLpgSQL_stmt_loop);
    3234              :                         new->cmd_type = PLPGSQL_STMT_LOOP;
    3235              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-1]), yyscanner);
    3236              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    3237              :                         new->label = (yyvsp[-2].str);
    3238              :                         new->body = (yyvsp[0].loop_body).stmts;
    3239              : 
    3240              :                         check_labels((yyvsp[-2].str), (yyvsp[0].loop_body).end_label, (yyvsp[0].loop_body).end_label_location, yyscanner);
    3241              :                         plpgsql_ns_pop();
    3242              : 
    3243              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    3244              :                     }
    3245              : #line 3246 "pl_gram.c"
    3246           45 :     break;
    3247              : 
    3248           51 :   case 113: /* stmt_while: opt_loop_label K_WHILE expr_until_loop loop_body  */
    3249              : #line 1314 "pl_gram.y"
    3250              :                                         {
    3251              :                         PLpgSQL_stmt_while *new;
    3252              : 
    3253              :                         new = palloc0_object(PLpgSQL_stmt_while);
    3254              :                         new->cmd_type = PLPGSQL_STMT_WHILE;
    3255              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    3256              :                         new->stmtid  = ++plpgsql_curr_compile->nstatements;
    3257              :                         new->label = (yyvsp[-3].str);
    3258              :                         new->cond = (yyvsp[-1].expr);
    3259              :                         new->body = (yyvsp[0].loop_body).stmts;
    3260              : 
    3261              :                         check_labels((yyvsp[-3].str), (yyvsp[0].loop_body).end_label, (yyvsp[0].loop_body).end_label_location, yyscanner);
    3262              :                         plpgsql_ns_pop();
    3263              : 
    3264              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    3265              :                     }
    3266              : #line 3267 "pl_gram.c"
    3267           51 :     break;
    3268              : 
    3269          924 :   case 114: /* stmt_for: opt_loop_label K_FOR for_control loop_body  */
    3270              : #line 1333 "pl_gram.y"
    3271              :                                         {
    3272              :                         /* This runs after we've scanned the loop body */
    3273              :                         if ((yyvsp[-1].stmt)->cmd_type == PLPGSQL_STMT_FORI)
    3274              :                         {
    3275              :                             PLpgSQL_stmt_fori *new;
    3276              : 
    3277              :                             new = (PLpgSQL_stmt_fori *) (yyvsp[-1].stmt);
    3278              :                             new->lineno = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    3279              :                             new->label = (yyvsp[-3].str);
    3280              :                             new->body = (yyvsp[0].loop_body).stmts;
    3281              :                             (yyval.stmt) = (PLpgSQL_stmt *) new;
    3282              :                         }
    3283              :                         else
    3284              :                         {
    3285              :                             PLpgSQL_stmt_forq *new;
    3286              : 
    3287              :                             Assert((yyvsp[-1].stmt)->cmd_type == PLPGSQL_STMT_FORS ||
    3288              :                                    (yyvsp[-1].stmt)->cmd_type == PLPGSQL_STMT_FORC ||
    3289              :                                    (yyvsp[-1].stmt)->cmd_type == PLPGSQL_STMT_DYNFORS);
    3290              :                             /* forq is the common supertype of all three */
    3291              :                             new = (PLpgSQL_stmt_forq *) (yyvsp[-1].stmt);
    3292              :                             new->lineno = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    3293              :                             new->label = (yyvsp[-3].str);
    3294              :                             new->body = (yyvsp[0].loop_body).stmts;
    3295              :                             (yyval.stmt) = (PLpgSQL_stmt *) new;
    3296              :                         }
    3297              : 
    3298              :                         check_labels((yyvsp[-3].str), (yyvsp[0].loop_body).end_label, (yyvsp[0].loop_body).end_label_location, yyscanner);
    3299              :                         /* close namespace started in opt_loop_label */
    3300              :                         plpgsql_ns_pop();
    3301              :                     }
    3302              : #line 3303 "pl_gram.c"
    3303          921 :     break;
    3304              : 
    3305          932 :   case 115: /* for_control: for_variable K_IN  */
    3306              : #line 1367 "pl_gram.y"
    3307              :                                         {
    3308              :                         int         tok = yylex(&yylval, &yylloc, yyscanner);
    3309              :                         int         tokloc = yylloc;
    3310              : 
    3311              :                         if (tok_is_keyword(tok, &yylval,
    3312              :                                            K_EXECUTE, "execute"))
    3313              :                         {
    3314              :                             /* EXECUTE means it's a dynamic FOR loop */
    3315              :                             PLpgSQL_stmt_dynfors *new;
    3316              :                             PLpgSQL_expr *expr;
    3317              :                             int         term;
    3318              : 
    3319              :                             expr = read_sql_expression2(K_LOOP, K_USING,
    3320              :                                                         "LOOP or USING",
    3321              :                                                         &term, &yylval, &yylloc, yyscanner);
    3322              : 
    3323              :                             new = palloc0_object(PLpgSQL_stmt_dynfors);
    3324              :                             new->cmd_type = PLPGSQL_STMT_DYNFORS;
    3325              :                             new->stmtid = ++plpgsql_curr_compile->nstatements;
    3326              :                             if ((yyvsp[-1].forvariable).row)
    3327              :                             {
    3328              :                                 new->var = (PLpgSQL_variable *) (yyvsp[-1].forvariable).row;
    3329              :                                 check_assignable((yyvsp[-1].forvariable).row, (yylsp[-1]), yyscanner);
    3330              :                             }
    3331              :                             else if ((yyvsp[-1].forvariable).scalar)
    3332              :                             {
    3333              :                                 /* convert single scalar to list */
    3334              :                                 new->var = (PLpgSQL_variable *)
    3335              :                                     make_scalar_list1((yyvsp[-1].forvariable).name, (yyvsp[-1].forvariable).scalar,
    3336              :                                                       (yyvsp[-1].forvariable).lineno, (yylsp[-1]), yyscanner);
    3337              :                                 /* make_scalar_list1 did check_assignable */
    3338              :                             }
    3339              :                             else
    3340              :                             {
    3341              :                                 ereport(ERROR,
    3342              :                                         (errcode(ERRCODE_DATATYPE_MISMATCH),
    3343              :                                          errmsg("loop variable of loop over rows must be a record variable or list of scalar variables"),
    3344              :                                          parser_errposition((yylsp[-1]))));
    3345              :                             }
    3346              :                             new->query = expr;
    3347              : 
    3348              :                             if (term == K_USING)
    3349              :                             {
    3350              :                                 do
    3351              :                                 {
    3352              :                                     expr = read_sql_expression2(',', K_LOOP,
    3353              :                                                                 ", or LOOP",
    3354              :                                                                 &term, &yylval, &yylloc, yyscanner);
    3355              :                                     new->params = lappend(new->params, expr);
    3356              :                                 } while (term == ',');
    3357              :                             }
    3358              : 
    3359              :                             (yyval.stmt) = (PLpgSQL_stmt *) new;
    3360              :                         }
    3361              :                         else if (tok == T_DATUM &&
    3362              :                                  yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_VAR &&
    3363              :                                  ((PLpgSQL_var *) yylval.wdatum.datum)->datatype->typoid == REFCURSOROID)
    3364              :                         {
    3365              :                             /* It's FOR var IN cursor */
    3366              :                             PLpgSQL_stmt_forc *new;
    3367              :                             PLpgSQL_var *cursor = (PLpgSQL_var *) yylval.wdatum.datum;
    3368              : 
    3369              :                             new = palloc0_object(PLpgSQL_stmt_forc);
    3370              :                             new->cmd_type = PLPGSQL_STMT_FORC;
    3371              :                             new->stmtid = ++plpgsql_curr_compile->nstatements;
    3372              :                             new->curvar = cursor->dno;
    3373              : 
    3374              :                             /* Should have had a single variable name */
    3375              :                             if ((yyvsp[-1].forvariable).scalar && (yyvsp[-1].forvariable).row)
    3376              :                                 ereport(ERROR,
    3377              :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3378              :                                          errmsg("cursor FOR loop must have only one target variable"),
    3379              :                                          parser_errposition((yylsp[-1]))));
    3380              : 
    3381              :                             /* can't use an unbound cursor this way */
    3382              :                             if (cursor->cursor_explicit_expr == NULL)
    3383              :                                 ereport(ERROR,
    3384              :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3385              :                                          errmsg("cursor FOR loop must use a bound cursor variable"),
    3386              :                                          parser_errposition(tokloc)));
    3387              : 
    3388              :                             /* collect cursor's parameters if any */
    3389              :                             new->argquery = read_cursor_args(cursor, K_LOOP, &yylval, &yylloc, yyscanner);
    3390              : 
    3391              :                             /* create loop's private RECORD variable */
    3392              :                             new->var = (PLpgSQL_variable *)
    3393              :                                 plpgsql_build_record((yyvsp[-1].forvariable).name,
    3394              :                                                      (yyvsp[-1].forvariable).lineno,
    3395              :                                                      NULL,
    3396              :                                                      RECORDOID,
    3397              :                                                      true);
    3398              : 
    3399              :                             (yyval.stmt) = (PLpgSQL_stmt *) new;
    3400              :                         }
    3401              :                         else
    3402              :                         {
    3403              :                             PLpgSQL_expr *expr1;
    3404              :                             int         expr1loc;
    3405              :                             bool        reverse = false;
    3406              : 
    3407              :                             /*
    3408              :                              * We have to distinguish between two
    3409              :                              * alternatives: FOR var IN a .. b and FOR
    3410              :                              * var IN query. Unfortunately this is
    3411              :                              * tricky, since the query in the second
    3412              :                              * form needn't start with a SELECT
    3413              :                              * keyword.  We use the ugly hack of
    3414              :                              * looking for two periods after the first
    3415              :                              * token. We also check for the REVERSE
    3416              :                              * keyword, which means it must be an
    3417              :                              * integer loop.
    3418              :                              */
    3419              :                             if (tok_is_keyword(tok, &yylval,
    3420              :                                                K_REVERSE, "reverse"))
    3421              :                                 reverse = true;
    3422              :                             else
    3423              :                                 plpgsql_push_back_token(tok, &yylval, &yylloc, yyscanner);
    3424              : 
    3425              :                             /*
    3426              :                              * Read tokens until we see either a ".."
    3427              :                              * or a LOOP.  The text we read may be either
    3428              :                              * an expression or a whole SQL statement, so
    3429              :                              * we need to invoke read_sql_construct directly,
    3430              :                              * and tell it not to check syntax yet.
    3431              :                              */
    3432              :                             expr1 = read_sql_construct(DOT_DOT,
    3433              :                                                        K_LOOP,
    3434              :                                                        0,
    3435              :                                                        "LOOP",
    3436              :                                                        RAW_PARSE_DEFAULT,
    3437              :                                                        true,
    3438              :                                                        false,
    3439              :                                                        &expr1loc,
    3440              :                                                        &tok,
    3441              :                                                        &yylval, &yylloc, yyscanner);
    3442              : 
    3443              :                             if (tok == DOT_DOT)
    3444              :                             {
    3445              :                                 /* Saw "..", so it must be an integer loop */
    3446              :                                 PLpgSQL_expr *expr2;
    3447              :                                 PLpgSQL_expr *expr_by;
    3448              :                                 PLpgSQL_var *fvar;
    3449              :                                 PLpgSQL_stmt_fori *new;
    3450              : 
    3451              :                                 /*
    3452              :                                  * Relabel first expression as an expression;
    3453              :                                  * then we can check its syntax.
    3454              :                                  */
    3455              :                                 expr1->parseMode = RAW_PARSE_PLPGSQL_EXPR;
    3456              :                                 check_sql_expr(expr1->query, expr1->parseMode,
    3457              :                                                expr1loc, yyscanner);
    3458              : 
    3459              :                                 /* Read and check the second one */
    3460              :                                 expr2 = read_sql_expression2(K_LOOP, K_BY,
    3461              :                                                              "LOOP",
    3462              :                                                              &tok, &yylval, &yylloc, yyscanner);
    3463              : 
    3464              :                                 /* Get the BY clause if any */
    3465              :                                 if (tok == K_BY)
    3466              :                                     expr_by = read_sql_expression(K_LOOP,
    3467              :                                                                   "LOOP", &yylval, &yylloc, yyscanner);
    3468              :                                 else
    3469              :                                     expr_by = NULL;
    3470              : 
    3471              :                                 /* Should have had a single variable name */
    3472              :                                 if ((yyvsp[-1].forvariable).scalar && (yyvsp[-1].forvariable).row)
    3473              :                                     ereport(ERROR,
    3474              :                                             (errcode(ERRCODE_SYNTAX_ERROR),
    3475              :                                              errmsg("integer FOR loop must have only one target variable"),
    3476              :                                              parser_errposition((yylsp[-1]))));
    3477              : 
    3478              :                                 /* create loop's private variable */
    3479              :                                 fvar = (PLpgSQL_var *)
    3480              :                                     plpgsql_build_variable((yyvsp[-1].forvariable).name,
    3481              :                                                            (yyvsp[-1].forvariable).lineno,
    3482              :                                                            plpgsql_build_datatype(INT4OID,
    3483              :                                                                                   -1,
    3484              :                                                                                   InvalidOid,
    3485              :                                                                                   NULL),
    3486              :                                                            true);
    3487              : 
    3488              :                                 new = palloc0_object(PLpgSQL_stmt_fori);
    3489              :                                 new->cmd_type = PLPGSQL_STMT_FORI;
    3490              :                                 new->stmtid  = ++plpgsql_curr_compile->nstatements;
    3491              :                                 new->var = fvar;
    3492              :                                 new->reverse = reverse;
    3493              :                                 new->lower = expr1;
    3494              :                                 new->upper = expr2;
    3495              :                                 new->step = expr_by;
    3496              : 
    3497              :                                 (yyval.stmt) = (PLpgSQL_stmt *) new;
    3498              :                             }
    3499              :                             else
    3500              :                             {
    3501              :                                 /*
    3502              :                                  * No "..", so it must be a query loop.
    3503              :                                  */
    3504              :                                 PLpgSQL_stmt_fors *new;
    3505              : 
    3506              :                                 if (reverse)
    3507              :                                     ereport(ERROR,
    3508              :                                             (errcode(ERRCODE_SYNTAX_ERROR),
    3509              :                                              errmsg("cannot specify REVERSE in query FOR loop"),
    3510              :                                              parser_errposition(tokloc)));
    3511              : 
    3512              :                                 /* Check syntax as a regular query */
    3513              :                                 check_sql_expr(expr1->query, expr1->parseMode,
    3514              :                                                expr1loc, yyscanner);
    3515              : 
    3516              :                                 new = palloc0_object(PLpgSQL_stmt_fors);
    3517              :                                 new->cmd_type = PLPGSQL_STMT_FORS;
    3518              :                                 new->stmtid = ++plpgsql_curr_compile->nstatements;
    3519              :                                 if ((yyvsp[-1].forvariable).row)
    3520              :                                 {
    3521              :                                     new->var = (PLpgSQL_variable *) (yyvsp[-1].forvariable).row;
    3522              :                                     check_assignable((yyvsp[-1].forvariable).row, (yylsp[-1]), yyscanner);
    3523              :                                 }
    3524              :                                 else if ((yyvsp[-1].forvariable).scalar)
    3525              :                                 {
    3526              :                                     /* convert single scalar to list */
    3527              :                                     new->var = (PLpgSQL_variable *)
    3528              :                                         make_scalar_list1((yyvsp[-1].forvariable).name, (yyvsp[-1].forvariable).scalar,
    3529              :                                                           (yyvsp[-1].forvariable).lineno, (yylsp[-1]), yyscanner);
    3530              :                                     /* make_scalar_list1 did check_assignable */
    3531              :                                 }
    3532              :                                 else
    3533              :                                 {
    3534              :                                     ereport(ERROR,
    3535              :                                             (errcode(ERRCODE_SYNTAX_ERROR),
    3536              :                                              errmsg("loop variable of loop over rows must be a record variable or list of scalar variables"),
    3537              :                                              parser_errposition((yylsp[-1]))));
    3538              :                                 }
    3539              : 
    3540              :                                 new->query = expr1;
    3541              :                                 (yyval.stmt) = (PLpgSQL_stmt *) new;
    3542              :                             }
    3543              :                         }
    3544              :                     }
    3545              : #line 3546 "pl_gram.c"
    3546          924 :     break;
    3547              : 
    3548          501 :   case 116: /* for_variable: T_DATUM  */
    3549              : #line 1626 "pl_gram.y"
    3550              :                                         {
    3551              :                         (yyval.forvariable).name = NameOfDatum(&((yyvsp[0].wdatum)));
    3552              :                         (yyval.forvariable).lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    3553              :                         if ((yyvsp[0].wdatum).datum->dtype == PLPGSQL_DTYPE_ROW ||
    3554              :                             (yyvsp[0].wdatum).datum->dtype == PLPGSQL_DTYPE_REC)
    3555              :                         {
    3556              :                             (yyval.forvariable).scalar = NULL;
    3557              :                             (yyval.forvariable).row = (yyvsp[0].wdatum).datum;
    3558              :                         }
    3559              :                         else
    3560              :                         {
    3561              :                             int         tok;
    3562              : 
    3563              :                             (yyval.forvariable).scalar = (yyvsp[0].wdatum).datum;
    3564              :                             (yyval.forvariable).row = NULL;
    3565              :                             /* check for comma-separated list */
    3566              :                             tok = yylex(&yylval, &yylloc, yyscanner);
    3567              :                             plpgsql_push_back_token(tok, &yylval, &yylloc, yyscanner);
    3568              :                             if (tok == ',')
    3569              :                                 (yyval.forvariable).row = (PLpgSQL_datum *)
    3570              :                                     read_into_scalar_list((yyval.forvariable).name,
    3571              :                                                           (yyval.forvariable).scalar,
    3572              :                                                           (yylsp[0]),
    3573              :                                                           &yylval, &yylloc,
    3574              :                                                           yyscanner);
    3575              :                         }
    3576              :                     }
    3577              : #line 3578 "pl_gram.c"
    3578          499 :     break;
    3579              : 
    3580          475 :   case 117: /* for_variable: T_WORD  */
    3581              : #line 1654 "pl_gram.y"
    3582              :                                         {
    3583              :                         int         tok;
    3584              : 
    3585              :                         (yyval.forvariable).name = (yyvsp[0].word).ident;
    3586              :                         (yyval.forvariable).lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    3587              :                         (yyval.forvariable).scalar = NULL;
    3588              :                         (yyval.forvariable).row = NULL;
    3589              :                         /* check for comma-separated list */
    3590              :                         tok = yylex(&yylval, &yylloc, yyscanner);
    3591              :                         plpgsql_push_back_token(tok, &yylval, &yylloc, yyscanner);
    3592              :                         if (tok == ',')
    3593              :                             word_is_not_variable(&((yyvsp[0].word)), (yylsp[0]), yyscanner);
    3594              :                     }
    3595              : #line 3596 "pl_gram.c"
    3596          475 :     break;
    3597              : 
    3598            0 :   case 118: /* for_variable: T_CWORD  */
    3599              : #line 1668 "pl_gram.y"
    3600              :                                         {
    3601              :                         /* just to give a better message than "syntax error" */
    3602              :                         cword_is_not_variable(&((yyvsp[0].cword)), (yylsp[0]), yyscanner);
    3603              :                     }
    3604              : #line 3605 "pl_gram.c"
    3605            0 :     break;
    3606              : 
    3607           41 :   case 119: /* stmt_foreach_a: opt_loop_label K_FOREACH for_variable foreach_slice K_IN K_ARRAY expr_until_loop loop_body  */
    3608              : #line 1675 "pl_gram.y"
    3609              :                                         {
    3610              :                         PLpgSQL_stmt_foreach_a *new;
    3611              : 
    3612              :                         new = palloc0_object(PLpgSQL_stmt_foreach_a);
    3613              :                         new->cmd_type = PLPGSQL_STMT_FOREACH_A;
    3614              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-6]), yyscanner);
    3615              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    3616              :                         new->label = (yyvsp[-7].str);
    3617              :                         new->slice = (yyvsp[-4].ival);
    3618              :                         new->expr = (yyvsp[-1].expr);
    3619              :                         new->body = (yyvsp[0].loop_body).stmts;
    3620              : 
    3621              :                         if ((yyvsp[-5].forvariable).row)
    3622              :                         {
    3623              :                             new->varno = (yyvsp[-5].forvariable).row->dno;
    3624              :                             check_assignable((yyvsp[-5].forvariable).row, (yylsp[-5]), yyscanner);
    3625              :                         }
    3626              :                         else if ((yyvsp[-5].forvariable).scalar)
    3627              :                         {
    3628              :                             new->varno = (yyvsp[-5].forvariable).scalar->dno;
    3629              :                             check_assignable((yyvsp[-5].forvariable).scalar, (yylsp[-5]), yyscanner);
    3630              :                         }
    3631              :                         else
    3632              :                         {
    3633              :                             ereport(ERROR,
    3634              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3635              :                                      errmsg("loop variable of FOREACH must be a known variable or list of variables"),
    3636              :                                              parser_errposition((yylsp[-5]))));
    3637              :                         }
    3638              : 
    3639              :                         check_labels((yyvsp[-7].str), (yyvsp[0].loop_body).end_label, (yyvsp[0].loop_body).end_label_location, yyscanner);
    3640              :                         plpgsql_ns_pop();
    3641              : 
    3642              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    3643              :                     }
    3644              : #line 3645 "pl_gram.c"
    3645           41 :     break;
    3646              : 
    3647           21 :   case 120: /* foreach_slice: %empty  */
    3648              : #line 1713 "pl_gram.y"
    3649              :                                         {
    3650              :                         (yyval.ival) = 0;
    3651              :                     }
    3652              : #line 3653 "pl_gram.c"
    3653           21 :     break;
    3654              : 
    3655           20 :   case 121: /* foreach_slice: K_SLICE ICONST  */
    3656              : #line 1717 "pl_gram.y"
    3657              :                                         {
    3658              :                         (yyval.ival) = (yyvsp[0].ival);
    3659              :                     }
    3660              : #line 3661 "pl_gram.c"
    3661           20 :     break;
    3662              : 
    3663          132 :   case 122: /* stmt_exit: exit_type opt_label opt_exitcond  */
    3664              : #line 1723 "pl_gram.y"
    3665              :                                         {
    3666              :                         PLpgSQL_stmt_exit *new;
    3667              : 
    3668              :                         new = palloc0_object(PLpgSQL_stmt_exit);
    3669              :                         new->cmd_type = PLPGSQL_STMT_EXIT;
    3670              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    3671              :                         new->is_exit = (yyvsp[-2].boolean);
    3672              :                         new->lineno  = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    3673              :                         new->label = (yyvsp[-1].str);
    3674              :                         new->cond = (yyvsp[0].expr);
    3675              : 
    3676              :                         if ((yyvsp[-1].str))
    3677              :                         {
    3678              :                             /* We have a label, so verify it exists */
    3679              :                             PLpgSQL_nsitem *label;
    3680              : 
    3681              :                             label = plpgsql_ns_lookup_label(plpgsql_ns_top(), (yyvsp[-1].str));
    3682              :                             if (label == NULL)
    3683              :                                 ereport(ERROR,
    3684              :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3685              :                                          errmsg("there is no label \"%s\" "
    3686              :                                                 "attached to any block or loop enclosing this statement",
    3687              :                                                 (yyvsp[-1].str)),
    3688              :                                          parser_errposition((yylsp[-1]))));
    3689              :                             /* CONTINUE only allows loop labels */
    3690              :                             if (label->itemno != PLPGSQL_LABEL_LOOP && !new->is_exit)
    3691              :                                 ereport(ERROR,
    3692              :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3693              :                                          errmsg("block label \"%s\" cannot be used in CONTINUE",
    3694              :                                                 (yyvsp[-1].str)),
    3695              :                                          parser_errposition((yylsp[-1]))));
    3696              :                         }
    3697              :                         else
    3698              :                         {
    3699              :                             /*
    3700              :                              * No label, so make sure there is some loop (an
    3701              :                              * unlabeled EXIT does not match a block, so this
    3702              :                              * is the same test for both EXIT and CONTINUE)
    3703              :                              */
    3704              :                             if (plpgsql_ns_find_nearest_loop(plpgsql_ns_top()) == NULL)
    3705              :                                 ereport(ERROR,
    3706              :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3707              :                                          new->is_exit ?
    3708              :                                          errmsg("EXIT cannot be used outside a loop, unless it has a label") :
    3709              :                                          errmsg("CONTINUE cannot be used outside a loop"),
    3710              :                                          parser_errposition((yylsp[-2]))));
    3711              :                         }
    3712              : 
    3713              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    3714              :                     }
    3715              : #line 3716 "pl_gram.c"
    3716          127 :     break;
    3717              : 
    3718           69 :   case 123: /* exit_type: K_EXIT  */
    3719              : #line 1776 "pl_gram.y"
    3720              :                                         {
    3721              :                         (yyval.boolean) = true;
    3722              :                     }
    3723              : #line 3724 "pl_gram.c"
    3724           69 :     break;
    3725              : 
    3726           63 :   case 124: /* exit_type: K_CONTINUE  */
    3727              : #line 1780 "pl_gram.y"
    3728              :                                         {
    3729              :                         (yyval.boolean) = false;
    3730              :                     }
    3731              : #line 3732 "pl_gram.c"
    3732           63 :     break;
    3733              : 
    3734         5960 :   case 125: /* stmt_return: K_RETURN  */
    3735              : #line 1786 "pl_gram.y"
    3736              :                                         {
    3737              :                         int         tok;
    3738              : 
    3739              :                         tok = yylex(&yylval, &yylloc, yyscanner);
    3740              :                         if (tok == 0)
    3741              :                             yyerror(&yylloc, NULL, yyscanner, "unexpected end of function definition");
    3742              : 
    3743              :                         if (tok_is_keyword(tok, &yylval,
    3744              :                                            K_NEXT, "next"))
    3745              :                         {
    3746              :                             (yyval.stmt) = make_return_next_stmt((yylsp[0]), &yylval, &yylloc, yyscanner);
    3747              :                         }
    3748              :                         else if (tok_is_keyword(tok, &yylval,
    3749              :                                                 K_QUERY, "query"))
    3750              :                         {
    3751              :                             (yyval.stmt) = make_return_query_stmt((yylsp[0]), &yylval, &yylloc, yyscanner);
    3752              :                         }
    3753              :                         else
    3754              :                         {
    3755              :                             plpgsql_push_back_token(tok, &yylval, &yylloc, yyscanner);
    3756              :                             (yyval.stmt) = make_return_stmt((yylsp[0]), &yylval, &yylloc, yyscanner);
    3757              :                         }
    3758              :                     }
    3759              : #line 3760 "pl_gram.c"
    3760         5943 :     break;
    3761              : 
    3762         4631 :   case 126: /* stmt_raise: K_RAISE  */
    3763              : #line 1812 "pl_gram.y"
    3764              :                                         {
    3765              :                         PLpgSQL_stmt_raise *new;
    3766              :                         int         tok;
    3767              : 
    3768              :                         new = palloc_object(PLpgSQL_stmt_raise);
    3769              : 
    3770              :                         new->cmd_type = PLPGSQL_STMT_RAISE;
    3771              :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    3772              :                         new->stmtid  = ++plpgsql_curr_compile->nstatements;
    3773              :                         new->elog_level = ERROR; /* default */
    3774              :                         new->condname = NULL;
    3775              :                         new->message = NULL;
    3776              :                         new->params = NIL;
    3777              :                         new->options = NIL;
    3778              : 
    3779              :                         tok = yylex(&yylval, &yylloc, yyscanner);
    3780              :                         if (tok == 0)
    3781              :                             yyerror(&yylloc, NULL, yyscanner, "unexpected end of function definition");
    3782              : 
    3783              :                         /*
    3784              :                          * We could have just RAISE, meaning to re-throw
    3785              :                          * the current error.
    3786              :                          */
    3787              :                         if (tok != ';')
    3788              :                         {
    3789              :                             /*
    3790              :                              * First is an optional elog severity level.
    3791              :                              */
    3792              :                             if (tok_is_keyword(tok, &yylval,
    3793              :                                                K_EXCEPTION, "exception"))
    3794              :                             {
    3795              :                                 new->elog_level = ERROR;
    3796              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    3797              :                             }
    3798              :                             else if (tok_is_keyword(tok, &yylval,
    3799              :                                                     K_WARNING, "warning"))
    3800              :                             {
    3801              :                                 new->elog_level = WARNING;
    3802              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    3803              :                             }
    3804              :                             else if (tok_is_keyword(tok, &yylval,
    3805              :                                                     K_NOTICE, "notice"))
    3806              :                             {
    3807              :                                 new->elog_level = NOTICE;
    3808              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    3809              :                             }
    3810              :                             else if (tok_is_keyword(tok, &yylval,
    3811              :                                                     K_INFO, "info"))
    3812              :                             {
    3813              :                                 new->elog_level = INFO;
    3814              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    3815              :                             }
    3816              :                             else if (tok_is_keyword(tok, &yylval,
    3817              :                                                     K_LOG, "log"))
    3818              :                             {
    3819              :                                 new->elog_level = LOG;
    3820              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    3821              :                             }
    3822              :                             else if (tok_is_keyword(tok, &yylval,
    3823              :                                                     K_DEBUG, "debug"))
    3824              :                             {
    3825              :                                 new->elog_level = DEBUG1;
    3826              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    3827              :                             }
    3828              :                             if (tok == 0)
    3829              :                                 yyerror(&yylloc, NULL, yyscanner, "unexpected end of function definition");
    3830              : 
    3831              :                             /*
    3832              :                              * Next we can have a condition name, or
    3833              :                              * equivalently SQLSTATE 'xxxxx', or a string
    3834              :                              * literal that is the old-style message format,
    3835              :                              * or USING to start the option list immediately.
    3836              :                              */
    3837              :                             if (tok == SCONST)
    3838              :                             {
    3839              :                                 /* old style message and parameters */
    3840              :                                 new->message = yylval.str;
    3841              :                                 /*
    3842              :                                  * We expect either a semi-colon, which
    3843              :                                  * indicates no parameters, or a comma that
    3844              :                                  * begins the list of parameter expressions,
    3845              :                                  * or USING to begin the options list.
    3846              :                                  */
    3847              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    3848              :                                 if (tok != ',' && tok != ';' && tok != K_USING)
    3849              :                                     yyerror(&yylloc, NULL, yyscanner, "syntax error");
    3850              : 
    3851              :                                 while (tok == ',')
    3852              :                                 {
    3853              :                                     PLpgSQL_expr *expr;
    3854              : 
    3855              :                                     expr = read_sql_construct(',', ';', K_USING,
    3856              :                                                               ", or ; or USING",
    3857              :                                                               RAW_PARSE_PLPGSQL_EXPR,
    3858              :                                                               true, true,
    3859              :                                                               NULL, &tok,
    3860              :                                                               &yylval, &yylloc, yyscanner);
    3861              :                                     new->params = lappend(new->params, expr);
    3862              :                                 }
    3863              :                             }
    3864              :                             else if (tok != K_USING)
    3865              :                             {
    3866              :                                 /* must be condition name or SQLSTATE */
    3867              :                                 if (tok_is_keyword(tok, &yylval,
    3868              :                                                    K_SQLSTATE, "sqlstate"))
    3869              :                                 {
    3870              :                                     /* next token should be a string literal */
    3871              :                                     char       *sqlstatestr;
    3872              : 
    3873              :                                     if (yylex(&yylval, &yylloc, yyscanner) != SCONST)
    3874              :                                         yyerror(&yylloc, NULL, yyscanner, "syntax error");
    3875              :                                     sqlstatestr = yylval.str;
    3876              : 
    3877              :                                     if (strlen(sqlstatestr) != 5)
    3878              :                                         yyerror(&yylloc, NULL, yyscanner, "invalid SQLSTATE code");
    3879              :                                     if (strspn(sqlstatestr, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
    3880              :                                         yyerror(&yylloc, NULL, yyscanner, "invalid SQLSTATE code");
    3881              :                                     new->condname = sqlstatestr;
    3882              :                                 }
    3883              :                                 else
    3884              :                                 {
    3885              :                                     if (tok == T_WORD)
    3886              :                                         new->condname = yylval.word.ident;
    3887              :                                     else if (plpgsql_token_is_unreserved_keyword(tok))
    3888              :                                         new->condname = pstrdup(yylval.keyword);
    3889              :                                     else
    3890              :                                         yyerror(&yylloc, NULL, yyscanner, "syntax error");
    3891              :                                     plpgsql_recognize_err_condition(new->condname,
    3892              :                                                                     false);
    3893              :                                 }
    3894              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    3895              :                                 if (tok != ';' && tok != K_USING)
    3896              :                                     yyerror(&yylloc, NULL, yyscanner, "syntax error");
    3897              :                             }
    3898              : 
    3899              :                             if (tok == K_USING)
    3900              :                                 new->options = read_raise_options(&yylval, &yylloc, yyscanner);
    3901              :                         }
    3902              : 
    3903              :                         check_raise_parameters(new);
    3904              : 
    3905              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    3906              :                     }
    3907              : #line 3908 "pl_gram.c"
    3908         4623 :     break;
    3909              : 
    3910           34 :   case 127: /* stmt_assert: K_ASSERT  */
    3911              : #line 1958 "pl_gram.y"
    3912              :                                         {
    3913              :                         PLpgSQL_stmt_assert *new;
    3914              :                         int         tok;
    3915              : 
    3916              :                         new = palloc_object(PLpgSQL_stmt_assert);
    3917              : 
    3918              :                         new->cmd_type = PLPGSQL_STMT_ASSERT;
    3919              :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    3920              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    3921              : 
    3922              :                         new->cond = read_sql_expression2(',', ';',
    3923              :                                                          ", or ;",
    3924              :                                                          &tok, &yylval, &yylloc, yyscanner);
    3925              : 
    3926              :                         if (tok == ',')
    3927              :                             new->message = read_sql_expression(';', ";", &yylval, &yylloc, yyscanner);
    3928              :                         else
    3929              :                             new->message = NULL;
    3930              : 
    3931              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    3932              :                     }
    3933              : #line 3934 "pl_gram.c"
    3934           34 :     break;
    3935              : 
    3936         1061 :   case 128: /* loop_body: proc_sect K_END K_LOOP opt_label ';'  */
    3937              : #line 1982 "pl_gram.y"
    3938              :                                         {
    3939              :                         (yyval.loop_body).stmts = (yyvsp[-4].list);
    3940              :                         (yyval.loop_body).end_label = (yyvsp[-1].str);
    3941              :                         (yyval.loop_body).end_label_location = (yylsp[-1]);
    3942              :                     }
    3943              : #line 3944 "pl_gram.c"
    3944         1061 :     break;
    3945              : 
    3946            0 :   case 129: /* stmt_execsql: K_IMPORT  */
    3947              : #line 2000 "pl_gram.y"
    3948              :                                         {
    3949              :                         (yyval.stmt) = make_execsql_stmt(K_IMPORT, (yylsp[0]), NULL, &yylval, &yylloc, yyscanner);
    3950              :                     }
    3951              : #line 3952 "pl_gram.c"
    3952            0 :     break;
    3953              : 
    3954          561 :   case 130: /* stmt_execsql: K_INSERT  */
    3955              : #line 2004 "pl_gram.y"
    3956              :                                         {
    3957              :                         (yyval.stmt) = make_execsql_stmt(K_INSERT, (yylsp[0]), NULL, &yylval, &yylloc, yyscanner);
    3958              :                     }
    3959              : #line 3960 "pl_gram.c"
    3960          561 :     break;
    3961              : 
    3962           36 :   case 131: /* stmt_execsql: K_MERGE  */
    3963              : #line 2008 "pl_gram.y"
    3964              :                                         {
    3965              :                         (yyval.stmt) = make_execsql_stmt(K_MERGE, (yylsp[0]), NULL, &yylval, &yylloc, yyscanner);
    3966              :                     }
    3967              : #line 3968 "pl_gram.c"
    3968           36 :     break;
    3969              : 
    3970         1946 :   case 132: /* stmt_execsql: T_WORD  */
    3971              : #line 2012 "pl_gram.y"
    3972              :                                         {
    3973              :                         int         tok;
    3974              : 
    3975              :                         tok = yylex(&yylval, &yylloc, yyscanner);
    3976              :                         plpgsql_push_back_token(tok, &yylval, &yylloc, yyscanner);
    3977              :                         if (tok == '=' || tok == COLON_EQUALS ||
    3978              :                             tok == '[' || tok == '.')
    3979              :                             word_is_not_variable(&((yyvsp[0].word)), (yylsp[0]), yyscanner);
    3980              :                         (yyval.stmt) = make_execsql_stmt(T_WORD, (yylsp[0]), &((yyvsp[0].word)), &yylval, &yylloc, yyscanner);
    3981              :                     }
    3982              : #line 3983 "pl_gram.c"
    3983         1942 :     break;
    3984              : 
    3985            2 :   case 133: /* stmt_execsql: T_CWORD  */
    3986              : #line 2023 "pl_gram.y"
    3987              :                                         {
    3988              :                         int         tok;
    3989              : 
    3990              :                         tok = yylex(&yylval, &yylloc, yyscanner);
    3991              :                         plpgsql_push_back_token(tok, &yylval, &yylloc, yyscanner);
    3992              :                         if (tok == '=' || tok == COLON_EQUALS ||
    3993              :                             tok == '[' || tok == '.')
    3994              :                             cword_is_not_variable(&((yyvsp[0].cword)), (yylsp[0]), yyscanner);
    3995              :                         (yyval.stmt) = make_execsql_stmt(T_CWORD, (yylsp[0]), NULL, &yylval, &yylloc, yyscanner);
    3996              :                     }
    3997              : #line 3998 "pl_gram.c"
    3998            0 :     break;
    3999              : 
    4000          633 :   case 134: /* stmt_dynexecute: K_EXECUTE  */
    4001              : #line 2036 "pl_gram.y"
    4002              :                                         {
    4003              :                         PLpgSQL_stmt_dynexecute *new;
    4004              :                         PLpgSQL_expr *expr;
    4005              :                         int         endtoken;
    4006              : 
    4007              :                         expr = read_sql_construct(K_INTO, K_USING, ';',
    4008              :                                                   "INTO or USING or ;",
    4009              :                                                   RAW_PARSE_PLPGSQL_EXPR,
    4010              :                                                   true, true,
    4011              :                                                   NULL, &endtoken,
    4012              :                                                   &yylval, &yylloc, yyscanner);
    4013              : 
    4014              :                         new = palloc_object(PLpgSQL_stmt_dynexecute);
    4015              :                         new->cmd_type = PLPGSQL_STMT_DYNEXECUTE;
    4016              :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    4017              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4018              :                         new->query = expr;
    4019              :                         new->into = false;
    4020              :                         new->strict = false;
    4021              :                         new->target = NULL;
    4022              :                         new->params = NIL;
    4023              : 
    4024              :                         /*
    4025              :                          * We loop to allow the INTO and USING clauses to
    4026              :                          * appear in either order, since people easily get
    4027              :                          * that wrong.  This coding also prevents "INTO foo"
    4028              :                          * from getting absorbed into a USING expression,
    4029              :                          * which is *really* confusing.
    4030              :                          */
    4031              :                         for (;;)
    4032              :                         {
    4033              :                             if (endtoken == K_INTO)
    4034              :                             {
    4035              :                                 if (new->into)           /* multiple INTO */
    4036              :                                     yyerror(&yylloc, NULL, yyscanner, "syntax error");
    4037              :                                 new->into = true;
    4038              :                                 read_into_target(&new->target, &new->strict, &yylval, &yylloc, yyscanner);
    4039              :                                 endtoken = yylex(&yylval, &yylloc, yyscanner);
    4040              :                             }
    4041              :                             else if (endtoken == K_USING)
    4042              :                             {
    4043              :                                 if (new->params)     /* multiple USING */
    4044              :                                     yyerror(&yylloc, NULL, yyscanner, "syntax error");
    4045              :                                 do
    4046              :                                 {
    4047              :                                     expr = read_sql_construct(',', ';', K_INTO,
    4048              :                                                               ", or ; or INTO",
    4049              :                                                               RAW_PARSE_PLPGSQL_EXPR,
    4050              :                                                               true, true,
    4051              :                                                               NULL, &endtoken,
    4052              :                                                               &yylval, &yylloc, yyscanner);
    4053              :                                     new->params = lappend(new->params, expr);
    4054              :                                 } while (endtoken == ',');
    4055              :                             }
    4056              :                             else if (endtoken == ';')
    4057              :                                 break;
    4058              :                             else
    4059              :                                 yyerror(&yylloc, NULL, yyscanner, "syntax error");
    4060              :                         }
    4061              : 
    4062              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    4063              :                     }
    4064              : #line 4065 "pl_gram.c"
    4065          633 :     break;
    4066              : 
    4067           93 :   case 135: /* stmt_open: K_OPEN cursor_variable  */
    4068              : #line 2102 "pl_gram.y"
    4069              :                                         {
    4070              :                         PLpgSQL_stmt_open *new;
    4071              :                         int         tok;
    4072              : 
    4073              :                         new = palloc0_object(PLpgSQL_stmt_open);
    4074              :                         new->cmd_type = PLPGSQL_STMT_OPEN;
    4075              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-1]), yyscanner);
    4076              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4077              :                         new->curvar = (yyvsp[0].var)->dno;
    4078              :                         new->cursor_options = CURSOR_OPT_FAST_PLAN;
    4079              : 
    4080              :                         if ((yyvsp[0].var)->cursor_explicit_expr == NULL)
    4081              :                         {
    4082              :                             /* be nice if we could use opt_scrollable here */
    4083              :                             tok = yylex(&yylval, &yylloc, yyscanner);
    4084              :                             if (tok_is_keyword(tok, &yylval,
    4085              :                                                K_NO, "no"))
    4086              :                             {
    4087              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    4088              :                                 if (tok_is_keyword(tok, &yylval,
    4089              :                                                    K_SCROLL, "scroll"))
    4090              :                                 {
    4091              :                                     new->cursor_options |= CURSOR_OPT_NO_SCROLL;
    4092              :                                     tok = yylex(&yylval, &yylloc, yyscanner);
    4093              :                                 }
    4094              :                             }
    4095              :                             else if (tok_is_keyword(tok, &yylval,
    4096              :                                                     K_SCROLL, "scroll"))
    4097              :                             {
    4098              :                                 new->cursor_options |= CURSOR_OPT_SCROLL;
    4099              :                                 tok = yylex(&yylval, &yylloc, yyscanner);
    4100              :                             }
    4101              : 
    4102              :                             if (tok != K_FOR)
    4103              :                                 yyerror(&yylloc, NULL, yyscanner, "syntax error, expected \"FOR\"");
    4104              : 
    4105              :                             tok = yylex(&yylval, &yylloc, yyscanner);
    4106              :                             if (tok_is_keyword(tok, &yylval,
    4107              :                                                K_EXECUTE, "execute"))
    4108              :                             {
    4109              :                                 int         endtoken;
    4110              : 
    4111              :                                 new->dynquery =
    4112              :                                     read_sql_expression2(K_USING, ';',
    4113              :                                                          "USING or ;",
    4114              :                                                          &endtoken, &yylval, &yylloc, yyscanner);
    4115              : 
    4116              :                                 /* If we found "USING", collect argument(s) */
    4117              :                                 if (endtoken == K_USING)
    4118              :                                 {
    4119              :                                     PLpgSQL_expr *expr;
    4120              : 
    4121              :                                     do
    4122              :                                     {
    4123              :                                         expr = read_sql_expression2(',', ';',
    4124              :                                                                     ", or ;",
    4125              :                                                                     &endtoken, &yylval, &yylloc, yyscanner);
    4126              :                                         new->params = lappend(new->params,
    4127              :                                                               expr);
    4128              :                                     } while (endtoken == ',');
    4129              :                                 }
    4130              :                             }
    4131              :                             else
    4132              :                             {
    4133              :                                 plpgsql_push_back_token(tok, &yylval, &yylloc, yyscanner);
    4134              :                                 new->query = read_sql_stmt(&yylval, &yylloc, yyscanner);
    4135              :                             }
    4136              :                         }
    4137              :                         else
    4138              :                         {
    4139              :                             /* predefined cursor query, so read args */
    4140              :                             new->argquery = read_cursor_args((yyvsp[0].var), ';', &yylval, &yylloc, yyscanner);
    4141              :                         }
    4142              : 
    4143              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    4144              :                     }
    4145              : #line 4146 "pl_gram.c"
    4146           77 :     break;
    4147              : 
    4148           81 :   case 136: /* stmt_fetch: K_FETCH opt_fetch_direction cursor_variable K_INTO  */
    4149              : #line 2181 "pl_gram.y"
    4150              :                                         {
    4151              :                         PLpgSQL_stmt_fetch *fetch = (yyvsp[-2].fetch);
    4152              :                         PLpgSQL_variable *target;
    4153              : 
    4154              :                         /* We have already parsed everything through the INTO keyword */
    4155              :                         read_into_target(&target, NULL, &yylval, &yylloc, yyscanner);
    4156              : 
    4157              :                         if (yylex(&yylval, &yylloc, yyscanner) != ';')
    4158              :                             yyerror(&yylloc, NULL, yyscanner, "syntax error");
    4159              : 
    4160              :                         /*
    4161              :                          * We don't allow multiple rows in PL/pgSQL's FETCH
    4162              :                          * statement, only in MOVE.
    4163              :                          */
    4164              :                         if (fetch->returns_multiple_rows)
    4165              :                             ereport(ERROR,
    4166              :                                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4167              :                                      errmsg("FETCH statement cannot return multiple rows"),
    4168              :                                      parser_errposition((yylsp[-3]))));
    4169              : 
    4170              :                         fetch->lineno = plpgsql_location_to_lineno((yylsp[-3]), yyscanner);
    4171              :                         fetch->target    = target;
    4172              :                         fetch->curvar    = (yyvsp[-1].var)->dno;
    4173              :                         fetch->is_move   = false;
    4174              : 
    4175              :                         (yyval.stmt) = (PLpgSQL_stmt *) fetch;
    4176              :                     }
    4177              : #line 4178 "pl_gram.c"
    4178           81 :     break;
    4179              : 
    4180           12 :   case 137: /* stmt_move: K_MOVE opt_fetch_direction cursor_variable ';'  */
    4181              : #line 2211 "pl_gram.y"
    4182              :                                         {
    4183              :                         PLpgSQL_stmt_fetch *fetch = (yyvsp[-2].fetch);
    4184              : 
    4185              :                         fetch->lineno = plpgsql_location_to_lineno((yylsp[-3]), yyscanner);
    4186              :                         fetch->curvar = (yyvsp[-1].var)->dno;
    4187              :                         fetch->is_move = true;
    4188              : 
    4189              :                         (yyval.stmt) = (PLpgSQL_stmt *) fetch;
    4190              :                     }
    4191              : #line 4192 "pl_gram.c"
    4192           12 :     break;
    4193              : 
    4194           93 :   case 138: /* opt_fetch_direction: %empty  */
    4195              : #line 2223 "pl_gram.y"
    4196              :                                         {
    4197              :                         (yyval.fetch) = read_fetch_direction(&yylval, &yylloc, yyscanner);
    4198              :                     }
    4199              : #line 4200 "pl_gram.c"
    4200           93 :     break;
    4201              : 
    4202           44 :   case 139: /* stmt_close: K_CLOSE cursor_variable ';'  */
    4203              : #line 2229 "pl_gram.y"
    4204              :                                         {
    4205              :                         PLpgSQL_stmt_close *new;
    4206              : 
    4207              :                         new = palloc_object(PLpgSQL_stmt_close);
    4208              :                         new->cmd_type = PLPGSQL_STMT_CLOSE;
    4209              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    4210              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4211              :                         new->curvar = (yyvsp[-1].var)->dno;
    4212              : 
    4213              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    4214              :                     }
    4215              : #line 4216 "pl_gram.c"
    4216           44 :     break;
    4217              : 
    4218           20 :   case 140: /* stmt_null: K_NULL ';'  */
    4219              : #line 2243 "pl_gram.y"
    4220              :                                         {
    4221              :                         /* We do not bother building a node for NULL */
    4222              :                         (yyval.stmt) = NULL;
    4223              :                     }
    4224              : #line 4225 "pl_gram.c"
    4225           20 :     break;
    4226              : 
    4227           39 :   case 141: /* stmt_commit: K_COMMIT opt_transaction_chain ';'  */
    4228              : #line 2250 "pl_gram.y"
    4229              :                                         {
    4230              :                         PLpgSQL_stmt_commit *new;
    4231              : 
    4232              :                         new = palloc_object(PLpgSQL_stmt_commit);
    4233              :                         new->cmd_type = PLPGSQL_STMT_COMMIT;
    4234              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    4235              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4236              :                         new->chain = (yyvsp[-1].ival);
    4237              : 
    4238              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    4239              :                     }
    4240              : #line 4241 "pl_gram.c"
    4241           39 :     break;
    4242              : 
    4243           25 :   case 142: /* stmt_rollback: K_ROLLBACK opt_transaction_chain ';'  */
    4244              : #line 2264 "pl_gram.y"
    4245              :                                         {
    4246              :                         PLpgSQL_stmt_rollback *new;
    4247              : 
    4248              :                         new = palloc_object(PLpgSQL_stmt_rollback);
    4249              :                         new->cmd_type = PLPGSQL_STMT_ROLLBACK;
    4250              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]), yyscanner);
    4251              :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4252              :                         new->chain = (yyvsp[-1].ival);
    4253              : 
    4254              :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    4255              :                     }
    4256              : #line 4257 "pl_gram.c"
    4257           25 :     break;
    4258              : 
    4259            2 :   case 143: /* opt_transaction_chain: K_AND K_CHAIN  */
    4260              : #line 2278 "pl_gram.y"
    4261              :                                                         { (yyval.ival) = true; }
    4262              : #line 4263 "pl_gram.c"
    4263            2 :     break;
    4264              : 
    4265            0 :   case 144: /* opt_transaction_chain: K_AND K_NO K_CHAIN  */
    4266              : #line 2279 "pl_gram.y"
    4267              :                                                 { (yyval.ival) = false; }
    4268              : #line 4269 "pl_gram.c"
    4269            0 :     break;
    4270              : 
    4271           62 :   case 145: /* opt_transaction_chain: %empty  */
    4272              : #line 2280 "pl_gram.y"
    4273              :                                                         { (yyval.ival) = false; }
    4274              : #line 4275 "pl_gram.c"
    4275           62 :     break;
    4276              : 
    4277          230 :   case 146: /* cursor_variable: T_DATUM  */
    4278              : #line 2285 "pl_gram.y"
    4279              :                                         {
    4280              :                         /*
    4281              :                          * In principle we should support a cursor_variable
    4282              :                          * that is an array element, but for now we don't, so
    4283              :                          * just throw an error if next token is '['.
    4284              :                          */
    4285              :                         if ((yyvsp[0].wdatum).datum->dtype != PLPGSQL_DTYPE_VAR ||
    4286              :                             plpgsql_peek(yyscanner) == '[')
    4287              :                             ereport(ERROR,
    4288              :                                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    4289              :                                      errmsg("cursor variable must be a simple variable"),
    4290              :                                      parser_errposition((yylsp[0]))));
    4291              : 
    4292              :                         if (((PLpgSQL_var *) (yyvsp[0].wdatum).datum)->datatype->typoid != REFCURSOROID)
    4293              :                             ereport(ERROR,
    4294              :                                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    4295              :                                      errmsg("variable \"%s\" must be of type cursor or refcursor",
    4296              :                                             ((PLpgSQL_var *) (yyvsp[0].wdatum).datum)->refname),
    4297              :                                      parser_errposition((yylsp[0]))));
    4298              :                         (yyval.var) = (PLpgSQL_var *) (yyvsp[0].wdatum).datum;
    4299              :                     }
    4300              : #line 4301 "pl_gram.c"
    4301          230 :     break;
    4302              : 
    4303            0 :   case 147: /* cursor_variable: T_WORD  */
    4304              : #line 2307 "pl_gram.y"
    4305              :                                         {
    4306              :                         /* just to give a better message than "syntax error" */
    4307              :                         word_is_not_variable(&((yyvsp[0].word)), (yylsp[0]), yyscanner);
    4308              :                     }
    4309              : #line 4310 "pl_gram.c"
    4310            0 :     break;
    4311              : 
    4312            0 :   case 148: /* cursor_variable: T_CWORD  */
    4313              : #line 2312 "pl_gram.y"
    4314              :                                         {
    4315              :                         /* just to give a better message than "syntax error" */
    4316              :                         cword_is_not_variable(&((yyvsp[0].cword)), (yylsp[0]), yyscanner);
    4317              :                     }
    4318              : #line 4319 "pl_gram.c"
    4319            0 :     break;
    4320              : 
    4321         5828 :   case 149: /* exception_sect: %empty  */
    4322              : #line 2319 "pl_gram.y"
    4323              :                                         { (yyval.exception_block) = NULL; }
    4324              : #line 4325 "pl_gram.c"
    4325         5828 :     break;
    4326              : 
    4327          274 :   case 150: /* @2: %empty  */
    4328              : #line 2321 "pl_gram.y"
    4329              :                                         {
    4330              :                         /*
    4331              :                          * We use a mid-rule action to add these
    4332              :                          * special variables to the namespace before
    4333              :                          * parsing the WHEN clauses themselves.  The
    4334              :                          * scope of the names extends to the end of the
    4335              :                          * current block.
    4336              :                          */
    4337              :                         int         lineno = plpgsql_location_to_lineno((yylsp[0]), yyscanner);
    4338              :                         PLpgSQL_exception_block *new = palloc_object(PLpgSQL_exception_block);
    4339              :                         PLpgSQL_variable *var;
    4340              : 
    4341              :                         plpgsql_curr_compile->has_exception_block = true;
    4342              : 
    4343              :                         var = plpgsql_build_variable("sqlstate", lineno,
    4344              :                                                      plpgsql_build_datatype(TEXTOID,
    4345              :                                                                             -1,
    4346              :                                                                             plpgsql_curr_compile->fn_input_collation,
    4347              :                                                                             NULL),
    4348              :                                                      true);
    4349              :                         var->isconst = true;
    4350              :                         new->sqlstate_varno = var->dno;
    4351              : 
    4352              :                         var = plpgsql_build_variable("sqlerrm", lineno,
    4353              :                                                      plpgsql_build_datatype(TEXTOID,
    4354              :                                                                             -1,
    4355              :                                                                             plpgsql_curr_compile->fn_input_collation,
    4356              :                                                                             NULL),
    4357              :                                                      true);
    4358              :                         var->isconst = true;
    4359              :                         new->sqlerrm_varno = var->dno;
    4360              : 
    4361              :                         (yyval.exception_block) = new;
    4362              :                     }
    4363              : #line 4364 "pl_gram.c"
    4364          274 :     break;
    4365              : 
    4366          274 :   case 151: /* exception_sect: K_EXCEPTION @2 proc_exceptions  */
    4367              : #line 2356 "pl_gram.y"
    4368              :                                         {
    4369              :                         PLpgSQL_exception_block *new = (yyvsp[-1].exception_block);
    4370              :                         new->exc_list = (yyvsp[0].list);
    4371              : 
    4372              :                         (yyval.exception_block) = new;
    4373              :                     }
    4374              : #line 4375 "pl_gram.c"
    4375          274 :     break;
    4376              : 
    4377            7 :   case 152: /* proc_exceptions: proc_exceptions proc_exception  */
    4378              : #line 2365 "pl_gram.y"
    4379              :                                                 {
    4380              :                             (yyval.list) = lappend((yyvsp[-1].list), (yyvsp[0].exception));
    4381              :                         }
    4382              : #line 4383 "pl_gram.c"
    4383            7 :     break;
    4384              : 
    4385          274 :   case 153: /* proc_exceptions: proc_exception  */
    4386              : #line 2369 "pl_gram.y"
    4387              :                                                 {
    4388              :                             (yyval.list) = list_make1((yyvsp[0].exception));
    4389              :                         }
    4390              : #line 4391 "pl_gram.c"
    4391          274 :     break;
    4392              : 
    4393          281 :   case 154: /* proc_exception: K_WHEN proc_conditions K_THEN proc_sect  */
    4394              : #line 2375 "pl_gram.y"
    4395              :                                         {
    4396              :                         PLpgSQL_exception *new;
    4397              : 
    4398              :                         new = palloc0_object(PLpgSQL_exception);
    4399              :                         new->lineno = plpgsql_location_to_lineno((yylsp[-3]), yyscanner);
    4400              :                         new->conditions = (yyvsp[-2].condition);
    4401              :                         new->action = (yyvsp[0].list);
    4402              : 
    4403              :                         (yyval.exception) = new;
    4404              :                     }
    4405              : #line 4406 "pl_gram.c"
    4406          281 :     break;
    4407              : 
    4408            5 :   case 155: /* proc_conditions: proc_conditions K_OR proc_condition  */
    4409              : #line 2388 "pl_gram.y"
    4410              :                                                 {
    4411              :                             PLpgSQL_condition   *old;
    4412              : 
    4413              :                             for (old = (yyvsp[-2].condition); old->next != NULL; old = old->next)
    4414              :                                 /* skip */ ;
    4415              :                             old->next = (yyvsp[0].condition);
    4416              :                             (yyval.condition) = (yyvsp[-2].condition);
    4417              :                         }
    4418              : #line 4419 "pl_gram.c"
    4419            5 :     break;
    4420              : 
    4421          281 :   case 156: /* proc_conditions: proc_condition  */
    4422              : #line 2397 "pl_gram.y"
    4423              :                                                 {
    4424              :                             (yyval.condition) = (yyvsp[0].condition);
    4425              :                         }
    4426              : #line 4427 "pl_gram.c"
    4427          281 :     break;
    4428              : 
    4429          286 :   case 157: /* proc_condition: any_identifier  */
    4430              : #line 2403 "pl_gram.y"
    4431              :                                                 {
    4432              :                             if (strcmp((yyvsp[0].str), "sqlstate") != 0)
    4433              :                             {
    4434              :                                 (yyval.condition) = plpgsql_parse_err_condition((yyvsp[0].str));
    4435              :                             }
    4436              :                             else
    4437              :                             {
    4438              :                                 PLpgSQL_condition *new;
    4439              :                                 char   *sqlstatestr;
    4440              : 
    4441              :                                 /* next token should be a string literal */
    4442              :                                 if (yylex(&yylval, &yylloc, yyscanner) != SCONST)
    4443              :                                     yyerror(&yylloc, NULL, yyscanner, "syntax error");
    4444              :                                 sqlstatestr = yylval.str;
    4445              : 
    4446              :                                 if (strlen(sqlstatestr) != 5)
    4447              :                                     yyerror(&yylloc, NULL, yyscanner, "invalid SQLSTATE code");
    4448              :                                 if (strspn(sqlstatestr, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
    4449              :                                     yyerror(&yylloc, NULL, yyscanner, "invalid SQLSTATE code");
    4450              : 
    4451              :                                 new = palloc_object(PLpgSQL_condition);
    4452              :                                 new->sqlerrstate =
    4453              :                                     MAKE_SQLSTATE(sqlstatestr[0],
    4454              :                                                   sqlstatestr[1],
    4455              :                                                   sqlstatestr[2],
    4456              :                                                   sqlstatestr[3],
    4457              :                                                   sqlstatestr[4]);
    4458              :                                 new->condname = sqlstatestr;
    4459              :                                 new->next = NULL;
    4460              : 
    4461              :                                 (yyval.condition) = new;
    4462              :                             }
    4463              :                         }
    4464              : #line 4465 "pl_gram.c"
    4465          286 :     break;
    4466              : 
    4467           85 :   case 158: /* expr_until_semi: %empty  */
    4468              : #line 2439 "pl_gram.y"
    4469              :                                         { (yyval.expr) = read_sql_expression(';', ";", &yylval, &yylloc, yyscanner); }
    4470              : #line 4471 "pl_gram.c"
    4471           85 :     break;
    4472              : 
    4473         4683 :   case 159: /* expr_until_then: %empty  */
    4474              : #line 2443 "pl_gram.y"
    4475              :                                         { (yyval.expr) = read_sql_expression(K_THEN, "THEN", &yylval, &yylloc, yyscanner); }
    4476              : #line 4477 "pl_gram.c"
    4477         4683 :     break;
    4478              : 
    4479           92 :   case 160: /* expr_until_loop: %empty  */
    4480              : #line 2447 "pl_gram.y"
    4481              :                                         { (yyval.expr) = read_sql_expression(K_LOOP, "LOOP", &yylval, &yylloc, yyscanner); }
    4482              : #line 4483 "pl_gram.c"
    4483           92 :     break;
    4484              : 
    4485         6167 :   case 161: /* opt_block_label: %empty  */
    4486              : #line 2451 "pl_gram.y"
    4487              :                                         {
    4488              :                         plpgsql_ns_push(NULL, PLPGSQL_LABEL_BLOCK);
    4489              :                         (yyval.str) = NULL;
    4490              :                     }
    4491              : #line 4492 "pl_gram.c"
    4492         6167 :     break;
    4493              : 
    4494           35 :   case 162: /* opt_block_label: LESS_LESS any_identifier GREATER_GREATER  */
    4495              : #line 2456 "pl_gram.y"
    4496              :                                         {
    4497              :                         plpgsql_ns_push((yyvsp[-1].str), PLPGSQL_LABEL_BLOCK);
    4498              :                         (yyval.str) = (yyvsp[-1].str);
    4499              :                     }
    4500              : #line 4501 "pl_gram.c"
    4501           35 :     break;
    4502              : 
    4503         1060 :   case 163: /* opt_loop_label: %empty  */
    4504              : #line 2463 "pl_gram.y"
    4505              :                                         {
    4506              :                         plpgsql_ns_push(NULL, PLPGSQL_LABEL_LOOP);
    4507              :                         (yyval.str) = NULL;
    4508              :                     }
    4509              : #line 4510 "pl_gram.c"
    4510         1060 :     break;
    4511              : 
    4512           15 :   case 164: /* opt_loop_label: LESS_LESS any_identifier GREATER_GREATER  */
    4513              : #line 2468 "pl_gram.y"
    4514              :                                         {
    4515              :                         plpgsql_ns_push((yyvsp[-1].str), PLPGSQL_LABEL_LOOP);
    4516              :                         (yyval.str) = (yyvsp[-1].str);
    4517              :                     }
    4518              : #line 4519 "pl_gram.c"
    4519           15 :     break;
    4520              : 
    4521         7274 :   case 165: /* opt_label: %empty  */
    4522              : #line 2475 "pl_gram.y"
    4523              :                                         {
    4524              :                         (yyval.str) = NULL;
    4525              :                     }
    4526              : #line 4527 "pl_gram.c"
    4527         7274 :     break;
    4528              : 
    4529           21 :   case 166: /* opt_label: any_identifier  */
    4530              : #line 2479 "pl_gram.y"
    4531              :                                         {
    4532              :                         /* label validity will be checked by outer production */
    4533              :                         (yyval.str) = (yyvsp[0].str);
    4534              :                     }
    4535              : #line 4536 "pl_gram.c"
    4536           21 :     break;
    4537              : 
    4538           47 :   case 167: /* opt_exitcond: ';'  */
    4539              : #line 2486 "pl_gram.y"
    4540              :                                         { (yyval.expr) = NULL; }
    4541              : #line 4542 "pl_gram.c"
    4542           47 :     break;
    4543              : 
    4544           85 :   case 168: /* opt_exitcond: K_WHEN expr_until_semi  */
    4545              : #line 2488 "pl_gram.y"
    4546              :                                         { (yyval.expr) = (yyvsp[0].expr); }
    4547              : #line 4548 "pl_gram.c"
    4548           85 :     break;
    4549              : 
    4550          339 :   case 169: /* any_identifier: T_WORD  */
    4551              : #line 2495 "pl_gram.y"
    4552              :                                         {
    4553              :                         (yyval.str) = (yyvsp[0].word).ident;
    4554              :                     }
    4555              : #line 4556 "pl_gram.c"
    4556          339 :     break;
    4557              : 
    4558            0 :   case 170: /* any_identifier: unreserved_keyword  */
    4559              : #line 2499 "pl_gram.y"
    4560              :                                         {
    4561              :                         (yyval.str) = pstrdup((yyvsp[0].keyword));
    4562              :                     }
    4563              : #line 4564 "pl_gram.c"
    4564            0 :     break;
    4565              : 
    4566           18 :   case 171: /* any_identifier: T_DATUM  */
    4567              : #line 2503 "pl_gram.y"
    4568              :                                         {
    4569              :                         if ((yyvsp[0].wdatum).ident == NULL) /* composite name not OK */
    4570              :                             yyerror(&yylloc, NULL, yyscanner, "syntax error");
    4571              :                         (yyval.str) = (yyvsp[0].wdatum).ident;
    4572              :                     }
    4573              : #line 4574 "pl_gram.c"
    4574           18 :     break;
    4575              : 
    4576              : 
    4577              : #line 4578 "pl_gram.c"
    4578              : 
    4579        20708 :       default: break;
    4580              :     }
    4581              :   /* User semantic actions sometimes alter yychar, and that requires
    4582              :      that yytoken be updated with the new translation.  We take the
    4583              :      approach of translating immediately before every use of yytoken.
    4584              :      One alternative is translating here after every semantic action,
    4585              :      but that translation would be missed if the semantic action invokes
    4586              :      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
    4587              :      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
    4588              :      incorrect destructor might then be invoked immediately.  In the
    4589              :      case of YYERROR or YYBACKUP, subsequent parser actions might lead
    4590              :      to an incorrect destructor call or verbose syntax error message
    4591              :      before the lookahead is translated.  */
    4592              :   YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
    4593              : 
    4594       194598 :   YYPOPSTACK (yylen);
    4595       194598 :   yylen = 0;
    4596              : 
    4597       194598 :   *++yyvsp = yyval;
    4598       194598 :   *++yylsp = yyloc;
    4599              : 
    4600              :   /* Now 'shift' the result of the reduction.  Determine what state
    4601              :      that goes to, based on the state we popped back to and the rule
    4602              :      number reduced by.  */
    4603              :   {
    4604       194598 :     const int yylhs = yyr1[yyn] - YYNTOKENS;
    4605       194598 :     const int yyi = yypgoto[yylhs] + *yyssp;
    4606        81404 :     yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
    4607        52253 :                ? yytable[yyi]
    4608       276002 :                : yydefgoto[yylhs]);
    4609              :   }
    4610              : 
    4611       194598 :   goto yynewstate;
    4612              : 
    4613              : 
    4614              : /*--------------------------------------.
    4615              : | yyerrlab -- here on detecting error.  |
    4616              : `--------------------------------------*/
    4617            1 : yyerrlab:
    4618              :   /* Make sure we have latest lookahead translation.  See comments at
    4619              :      user semantic actions for why this is necessary.  */
    4620            1 :   yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
    4621              :   /* If not already recovering from an error, report this error.  */
    4622            1 :   if (!yyerrstatus)
    4623              :     {
    4624            1 :       ++yynerrs;
    4625            1 :       yyerror (&yylloc, plpgsql_parse_result_p, yyscanner, YY_("syntax error"));
    4626              :     }
    4627              : 
    4628            0 :   yyerror_range[1] = yylloc;
    4629            0 :   if (yyerrstatus == 3)
    4630              :     {
    4631              :       /* If just tried and failed to reuse lookahead token after an
    4632              :          error, discard it.  */
    4633              : 
    4634            0 :       if (yychar <= YYEOF)
    4635              :         {
    4636              :           /* Return failure if at end of input.  */
    4637            0 :           if (yychar == YYEOF)
    4638            0 :             YYABORT;
    4639              :         }
    4640              :       else
    4641              :         {
    4642            0 :           yydestruct ("Error: discarding",
    4643              :                       yytoken, &yylval, &yylloc, plpgsql_parse_result_p, yyscanner);
    4644            0 :           yychar = YYEMPTY;
    4645              :         }
    4646              :     }
    4647              : 
    4648              :   /* Else will try to reuse lookahead token after shifting the error
    4649              :      token.  */
    4650            0 :   goto yyerrlab1;
    4651              : 
    4652              : 
    4653              : /*---------------------------------------------------.
    4654              : | yyerrorlab -- error raised explicitly by YYERROR.  |
    4655              : `---------------------------------------------------*/
    4656              : yyerrorlab:
    4657              :   /* Pacify compilers when the user code never invokes YYERROR and the
    4658              :      label yyerrorlab therefore never appears in user code.  */
    4659              :   if (0)
    4660              :     YYERROR;
    4661              :   ++yynerrs;
    4662              : 
    4663              :   /* Do not reclaim the symbols of the rule whose action triggered
    4664              :      this YYERROR.  */
    4665              :   YYPOPSTACK (yylen);
    4666              :   yylen = 0;
    4667              :   YY_STACK_PRINT (yyss, yyssp);
    4668              :   yystate = *yyssp;
    4669              :   goto yyerrlab1;
    4670              : 
    4671              : 
    4672              : /*-------------------------------------------------------------.
    4673              : | yyerrlab1 -- common code for both syntax error and YYERROR.  |
    4674              : `-------------------------------------------------------------*/
    4675            0 : yyerrlab1:
    4676            0 :   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
    4677              : 
    4678              :   /* Pop stack until we find a state that shifts the error token.  */
    4679              :   for (;;)
    4680              :     {
    4681            0 :       yyn = yypact[yystate];
    4682            0 :       if (!yypact_value_is_default (yyn))
    4683              :         {
    4684            0 :           yyn += YYSYMBOL_YYerror;
    4685            0 :           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
    4686              :             {
    4687            0 :               yyn = yytable[yyn];
    4688            0 :               if (0 < yyn)
    4689            0 :                 break;
    4690              :             }
    4691              :         }
    4692              : 
    4693              :       /* Pop the current state because it cannot handle the error token.  */
    4694            0 :       if (yyssp == yyss)
    4695            0 :         YYABORT;
    4696              : 
    4697            0 :       yyerror_range[1] = *yylsp;
    4698            0 :       yydestruct ("Error: popping",
    4699            0 :                   YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp, plpgsql_parse_result_p, yyscanner);
    4700            0 :       YYPOPSTACK (1);
    4701            0 :       yystate = *yyssp;
    4702              :       YY_STACK_PRINT (yyss, yyssp);
    4703              :     }
    4704              : 
    4705              :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    4706            0 :   *++yyvsp = yylval;
    4707              :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    4708              : 
    4709            0 :   yyerror_range[2] = yylloc;
    4710            0 :   ++yylsp;
    4711            0 :   YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);
    4712              : 
    4713              :   /* Shift the error token.  */
    4714              :   YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
    4715              : 
    4716            0 :   yystate = yyn;
    4717            0 :   goto yynewstate;
    4718              : 
    4719              : 
    4720              : /*-------------------------------------.
    4721              : | yyacceptlab -- YYACCEPT comes here.  |
    4722              : `-------------------------------------*/
    4723         5960 : yyacceptlab:
    4724         5960 :   yyresult = 0;
    4725         5960 :   goto yyreturnlab;
    4726              : 
    4727              : 
    4728              : /*-----------------------------------.
    4729              : | yyabortlab -- YYABORT comes here.  |
    4730              : `-----------------------------------*/
    4731            0 : yyabortlab:
    4732            0 :   yyresult = 1;
    4733            0 :   goto yyreturnlab;
    4734              : 
    4735              : 
    4736              : /*-----------------------------------------------------------.
    4737              : | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here.  |
    4738              : `-----------------------------------------------------------*/
    4739            0 : yyexhaustedlab:
    4740            0 :   yyerror (&yylloc, plpgsql_parse_result_p, yyscanner, YY_("memory exhausted"));
    4741              :   yyresult = 2;
    4742              :   goto yyreturnlab;
    4743              : 
    4744              : 
    4745              : /*----------------------------------------------------------.
    4746              : | yyreturnlab -- parsing is finished, clean up and return.  |
    4747              : `----------------------------------------------------------*/
    4748         5960 : yyreturnlab:
    4749         5960 :   if (yychar != YYEMPTY)
    4750              :     {
    4751              :       /* Make sure we have latest lookahead translation.  See comments at
    4752              :          user semantic actions for why this is necessary.  */
    4753            0 :       yytoken = YYTRANSLATE (yychar);
    4754            0 :       yydestruct ("Cleanup: discarding lookahead",
    4755              :                   yytoken, &yylval, &yylloc, plpgsql_parse_result_p, yyscanner);
    4756              :     }
    4757              :   /* Do not reclaim the symbols of the rule whose action triggered
    4758              :      this YYABORT or YYACCEPT.  */
    4759         5960 :   YYPOPSTACK (yylen);
    4760              :   YY_STACK_PRINT (yyss, yyssp);
    4761        17880 :   while (yyssp != yyss)
    4762              :     {
    4763        11920 :       yydestruct ("Cleanup: popping",
    4764        11920 :                   YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yylsp, plpgsql_parse_result_p, yyscanner);
    4765        11920 :       YYPOPSTACK (1);
    4766              :     }
    4767              : #ifndef yyoverflow
    4768         5960 :   if (yyss != yyssa)
    4769            0 :     YYSTACK_FREE (yyss);
    4770              : #endif
    4771              : 
    4772         5960 :   return yyresult;
    4773              : }
    4774              : 
    4775              : #line 2597 "pl_gram.y"
    4776              : 
    4777              : 
    4778              : /*
    4779              :  * Check whether a token represents an "unreserved keyword".
    4780              :  * We have various places where we want to recognize a keyword in preference
    4781              :  * to a variable name, but not reserve that keyword in other contexts.
    4782              :  * Hence, this kluge.
    4783              :  */
    4784              : static bool
    4785              : tok_is_keyword(int token, union YYSTYPE *lval,
    4786              :                int kw_token, const char *kw_str)
    4787              : {
    4788              :     if (token == kw_token)
    4789              :     {
    4790              :         /* Normal case, was recognized by scanner (no conflicting variable) */
    4791              :         return true;
    4792              :     }
    4793              :     else if (token == T_DATUM)
    4794              :     {
    4795              :         /*
    4796              :          * It's a variable, so recheck the string name.  Note we will not
    4797              :          * match composite names (hence an unreserved word followed by "."
    4798              :          * will not be recognized).
    4799              :          */
    4800              :         if (!lval->wdatum.quoted && lval->wdatum.ident != NULL &&
    4801              :             strcmp(lval->wdatum.ident, kw_str) == 0)
    4802              :             return true;
    4803              :     }
    4804              :     return false;               /* not the keyword */
    4805              : }
    4806              : 
    4807              : /*
    4808              :  * Convenience routine to complain when we expected T_DATUM and got T_WORD,
    4809              :  * ie, unrecognized variable.
    4810              :  */
    4811              : static void
    4812              : word_is_not_variable(PLword *word, int location, yyscan_t yyscanner)
    4813              : {
    4814              :     ereport(ERROR,
    4815              :             (errcode(ERRCODE_SYNTAX_ERROR),
    4816              :              errmsg("\"%s\" is not a known variable",
    4817              :                     word->ident),
    4818              :              parser_errposition(location)));
    4819              : }
    4820              : 
    4821              : /* Same, for a CWORD */
    4822              : static void
    4823              : cword_is_not_variable(PLcword *cword, int location, yyscan_t yyscanner)
    4824              : {
    4825              :     ereport(ERROR,
    4826              :             (errcode(ERRCODE_SYNTAX_ERROR),
    4827              :              errmsg("\"%s\" is not a known variable",
    4828              :                     NameListToString(cword->idents)),
    4829              :              parser_errposition(location)));
    4830              : }
    4831              : 
    4832              : /*
    4833              :  * Convenience routine to complain when we expected T_DATUM and got
    4834              :  * something else.  "tok" must be the current token, since we also
    4835              :  * look at yylval and yylloc.
    4836              :  */
    4837              : static void
    4838              : current_token_is_not_variable(int tok, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    4839              : {
    4840              :     if (tok == T_WORD)
    4841              :         word_is_not_variable(&(yylvalp->word), *yyllocp, yyscanner);
    4842              :     else if (tok == T_CWORD)
    4843              :         cword_is_not_variable(&(yylvalp->cword), *yyllocp, yyscanner);
    4844              :     else
    4845              :         yyerror(yyllocp, NULL, yyscanner, "syntax error");
    4846              : }
    4847              : 
    4848              : /* Convenience routine to construct a PLpgSQL_expr struct */
    4849              : static PLpgSQL_expr *
    4850              : make_plpgsql_expr(const char *query,
    4851              :                   RawParseMode parsemode)
    4852              : {
    4853              :     PLpgSQL_expr *expr = palloc0_object(PLpgSQL_expr);
    4854              : 
    4855              :     expr->query = pstrdup(query);
    4856              :     expr->parseMode = parsemode;
    4857              :     expr->func = plpgsql_curr_compile;
    4858              :     expr->ns = plpgsql_ns_top();
    4859              :     /* might get changed later during parsing: */
    4860              :     expr->target_param = -1;
    4861              :     expr->target_is_local = false;
    4862              :     /* other fields are left as zeroes until first execution */
    4863              :     return expr;
    4864              : }
    4865              : 
    4866              : /* Mark a PLpgSQL_expr as being the source of an assignment to target */
    4867              : static void
    4868              : mark_expr_as_assignment_source(PLpgSQL_expr *expr, PLpgSQL_datum *target)
    4869              : {
    4870              :     /*
    4871              :      * Mark the expression as being an assignment source, if target is a
    4872              :      * simple variable.  We don't currently support optimized assignments to
    4873              :      * other DTYPEs, so no need to mark in other cases.
    4874              :      */
    4875              :     if (target->dtype == PLPGSQL_DTYPE_VAR)
    4876              :     {
    4877              :         expr->target_param = target->dno;
    4878              : 
    4879              :         /*
    4880              :          * For now, assume the target is local to the nearest enclosing
    4881              :          * exception block.  That's correct if the function contains no
    4882              :          * exception blocks; otherwise we'll update this later.
    4883              :          */
    4884              :         expr->target_is_local = true;
    4885              :     }
    4886              :     else
    4887              :     {
    4888              :         expr->target_param = -1; /* should be that already */
    4889              :         expr->target_is_local = false; /* ditto */
    4890              :     }
    4891              : }
    4892              : 
    4893              : /* Convenience routine to read an expression with one possible terminator */
    4894              : static PLpgSQL_expr *
    4895              : read_sql_expression(int until, const char *expected, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    4896              : {
    4897              :     return read_sql_construct(until, 0, 0, expected,
    4898              :                               RAW_PARSE_PLPGSQL_EXPR,
    4899              :                               true, true, NULL, NULL,
    4900              :                               yylvalp, yyllocp, yyscanner);
    4901              : }
    4902              : 
    4903              : /* Convenience routine to read an expression with two possible terminators */
    4904              : static PLpgSQL_expr *
    4905              : read_sql_expression2(int until, int until2, const char *expected,
    4906              :                      int *endtoken, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    4907              : {
    4908              :     return read_sql_construct(until, until2, 0, expected,
    4909              :                               RAW_PARSE_PLPGSQL_EXPR,
    4910              :                               true, true, NULL, endtoken,
    4911              :                               yylvalp, yyllocp, yyscanner);
    4912              : }
    4913              : 
    4914              : /* Convenience routine to read a SQL statement that must end with ';' */
    4915              : static PLpgSQL_expr *
    4916              : read_sql_stmt(YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    4917              : {
    4918              :     return read_sql_construct(';', 0, 0, ";",
    4919              :                               RAW_PARSE_DEFAULT,
    4920              :                               false, true, NULL, NULL,
    4921              :                               yylvalp, yyllocp, yyscanner);
    4922              : }
    4923              : 
    4924              : /*
    4925              :  * Read a SQL construct and build a PLpgSQL_expr for it.
    4926              :  *
    4927              :  * until:       token code for expected terminator
    4928              :  * until2:      token code for alternate terminator (pass 0 if none)
    4929              :  * until3:      token code for another alternate terminator (pass 0 if none)
    4930              :  * expected:    text to use in complaining that terminator was not found
    4931              :  * parsemode:   raw_parser() mode to use
    4932              :  * isexpression: whether to say we're reading an "expression" or a "statement"
    4933              :  * valid_sql:   whether to check the syntax of the expr
    4934              :  * startloc:    if not NULL, location of first token is stored at *startloc
    4935              :  * endtoken:    if not NULL, ending token is stored at *endtoken
    4936              :  *              (this is only interesting if until2 or until3 isn't zero)
    4937              :  */
    4938              : static PLpgSQL_expr *
    4939              : read_sql_construct(int until,
    4940              :                    int until2,
    4941              :                    int until3,
    4942              :                    const char *expected,
    4943              :                    RawParseMode parsemode,
    4944              :                    bool isexpression,
    4945              :                    bool valid_sql,
    4946              :                    int *startloc,
    4947              :                    int *endtoken,
    4948              :                    YYSTYPE *yylvalp, YYLTYPE *yyllocp,
    4949              :                    yyscan_t yyscanner)
    4950              : {
    4951              :     int         tok;
    4952              :     StringInfoData ds;
    4953              :     IdentifierLookup save_IdentifierLookup;
    4954              :     int         startlocation = -1;
    4955              :     int         endlocation = -1;
    4956              :     int         parenlevel = 0;
    4957              :     PLpgSQL_expr *expr;
    4958              : 
    4959              :     initStringInfo(&ds);
    4960              : 
    4961              :     /* special lookup mode for identifiers within the SQL text */
    4962              :     save_IdentifierLookup = plpgsql_IdentifierLookup;
    4963              :     plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_EXPR;
    4964              : 
    4965              :     for (;;)
    4966              :     {
    4967              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    4968              :         if (startlocation < 0)   /* remember loc of first token */
    4969              :             startlocation = *yyllocp;
    4970              :         if (tok == until && parenlevel == 0)
    4971              :             break;
    4972              :         if (tok == until2 && parenlevel == 0)
    4973              :             break;
    4974              :         if (tok == until3 && parenlevel == 0)
    4975              :             break;
    4976              :         if (tok == '(' || tok == '[')
    4977              :             parenlevel++;
    4978              :         else if (tok == ')' || tok == ']')
    4979              :         {
    4980              :             parenlevel--;
    4981              :             if (parenlevel < 0)
    4982              :                 yyerror(yyllocp, NULL, yyscanner, "mismatched parentheses");
    4983              :         }
    4984              : 
    4985              :         /*
    4986              :          * End of function definition is an error, and we don't expect to hit
    4987              :          * a semicolon either (unless it's the until symbol, in which case we
    4988              :          * should have fallen out above).
    4989              :          */
    4990              :         if (tok == 0 || tok == ';')
    4991              :         {
    4992              :             if (parenlevel != 0)
    4993              :                 yyerror(yyllocp, NULL, yyscanner, "mismatched parentheses");
    4994              :             if (isexpression)
    4995              :                 ereport(ERROR,
    4996              :                         (errcode(ERRCODE_SYNTAX_ERROR),
    4997              :                          errmsg("missing \"%s\" at end of SQL expression",
    4998              :                                 expected),
    4999              :                          parser_errposition(*yyllocp)));
    5000              :             else
    5001              :                 ereport(ERROR,
    5002              :                         (errcode(ERRCODE_SYNTAX_ERROR),
    5003              :                          errmsg("missing \"%s\" at end of SQL statement",
    5004              :                                 expected),
    5005              :                          parser_errposition(*yyllocp)));
    5006              :         }
    5007              :         /* Remember end+1 location of last accepted token */
    5008              :         endlocation = *yyllocp + plpgsql_token_length(yyscanner);
    5009              :     }
    5010              : 
    5011              :     plpgsql_IdentifierLookup = save_IdentifierLookup;
    5012              : 
    5013              :     if (startloc)
    5014              :         *startloc = startlocation;
    5015              :     if (endtoken)
    5016              :         *endtoken = tok;
    5017              : 
    5018              :     /* give helpful complaint about empty input */
    5019              :     if (startlocation >= endlocation)
    5020              :     {
    5021              :         if (isexpression)
    5022              :             yyerror(yyllocp, NULL, yyscanner, "missing expression");
    5023              :         else
    5024              :             yyerror(yyllocp, NULL, yyscanner, "missing SQL statement");
    5025              :     }
    5026              : 
    5027              :     /*
    5028              :      * We save only the text from startlocation to endlocation-1.  This
    5029              :      * suppresses the "until" token as well as any whitespace or comments
    5030              :      * following the last accepted token.  (We used to strip such trailing
    5031              :      * whitespace by hand, but that causes problems if there's a "-- comment"
    5032              :      * in front of said whitespace.)
    5033              :      */
    5034              :     plpgsql_append_source_text(&ds, startlocation, endlocation, yyscanner);
    5035              : 
    5036              :     expr = make_plpgsql_expr(ds.data, parsemode);
    5037              :     pfree(ds.data);
    5038              : 
    5039              :     if (valid_sql)
    5040              :         check_sql_expr(expr->query, expr->parseMode, startlocation, yyscanner);
    5041              : 
    5042              :     return expr;
    5043              : }
    5044              : 
    5045              : /*
    5046              :  * Read a datatype declaration, consuming the current lookahead token if any.
    5047              :  * Returns a PLpgSQL_type struct.
    5048              :  */
    5049              : static PLpgSQL_type *
    5050              : read_datatype(int tok, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    5051              : {
    5052              :     StringInfoData ds;
    5053              :     char       *type_name;
    5054              :     int         startlocation;
    5055              :     PLpgSQL_type *result = NULL;
    5056              :     int         parenlevel = 0;
    5057              : 
    5058              :     /* Should only be called while parsing DECLARE sections */
    5059              :     Assert(plpgsql_IdentifierLookup == IDENTIFIER_LOOKUP_DECLARE);
    5060              : 
    5061              :     /* Often there will be a lookahead token, but if not, get one */
    5062              :     if (tok == YYEMPTY)
    5063              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5064              : 
    5065              :     /* The current token is the start of what we'll pass to parse_datatype */
    5066              :     startlocation = *yyllocp;
    5067              : 
    5068              :     /*
    5069              :      * If we have a simple or composite identifier, check for %TYPE and
    5070              :      * %ROWTYPE constructs.
    5071              :      */
    5072              :     if (tok == T_WORD)
    5073              :     {
    5074              :         char       *dtname = yylvalp->word.ident;
    5075              : 
    5076              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5077              :         if (tok == '%')
    5078              :         {
    5079              :             tok = yylex(yylvalp, yyllocp, yyscanner);
    5080              :             if (tok_is_keyword(tok, yylvalp,
    5081              :                                K_TYPE, "type"))
    5082              :                 result = plpgsql_parse_wordtype(dtname);
    5083              :             else if (tok_is_keyword(tok, yylvalp,
    5084              :                                     K_ROWTYPE, "rowtype"))
    5085              :                 result = plpgsql_parse_wordrowtype(dtname);
    5086              :         }
    5087              :     }
    5088              :     else if (plpgsql_token_is_unreserved_keyword(tok))
    5089              :     {
    5090              :         char       *dtname = pstrdup(yylvalp->keyword);
    5091              : 
    5092              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5093              :         if (tok == '%')
    5094              :         {
    5095              :             tok = yylex(yylvalp, yyllocp, yyscanner);
    5096              :             if (tok_is_keyword(tok, yylvalp,
    5097              :                                K_TYPE, "type"))
    5098              :                 result = plpgsql_parse_wordtype(dtname);
    5099              :             else if (tok_is_keyword(tok, yylvalp,
    5100              :                                     K_ROWTYPE, "rowtype"))
    5101              :                 result = plpgsql_parse_wordrowtype(dtname);
    5102              :         }
    5103              :     }
    5104              :     else if (tok == T_CWORD)
    5105              :     {
    5106              :         List       *dtnames = yylvalp->cword.idents;
    5107              : 
    5108              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5109              :         if (tok == '%')
    5110              :         {
    5111              :             tok = yylex(yylvalp, yyllocp, yyscanner);
    5112              :             if (tok_is_keyword(tok, yylvalp,
    5113              :                                K_TYPE, "type"))
    5114              :                 result = plpgsql_parse_cwordtype(dtnames);
    5115              :             else if (tok_is_keyword(tok, yylvalp,
    5116              :                                     K_ROWTYPE, "rowtype"))
    5117              :                 result = plpgsql_parse_cwordrowtype(dtnames);
    5118              :         }
    5119              :     }
    5120              : 
    5121              :     /*
    5122              :      * If we recognized a %TYPE or %ROWTYPE construct, see if it is followed
    5123              :      * by array decoration: [ ARRAY ] [ '[' [ iconst ] ']' [ ... ] ]
    5124              :      *
    5125              :      * Like the core parser, we ignore the specific numbers and sizes of
    5126              :      * dimensions; arrays of different dimensionality are still the same type
    5127              :      * in Postgres.
    5128              :      */
    5129              :     if (result)
    5130              :     {
    5131              :         bool        is_array = false;
    5132              : 
    5133              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5134              :         if (tok_is_keyword(tok, yylvalp,
    5135              :                            K_ARRAY, "array"))
    5136              :         {
    5137              :             is_array = true;
    5138              :             tok = yylex(yylvalp, yyllocp, yyscanner);
    5139              :         }
    5140              :         while (tok == '[')
    5141              :         {
    5142              :             is_array = true;
    5143              :             tok = yylex(yylvalp, yyllocp, yyscanner);
    5144              :             if (tok == ICONST)
    5145              :                 tok = yylex(yylvalp, yyllocp, yyscanner);
    5146              :             if (tok != ']')
    5147              :                 yyerror(yyllocp, NULL, yyscanner, "syntax error, expected \"]\"");
    5148              :             tok = yylex(yylvalp, yyllocp, yyscanner);
    5149              :         }
    5150              :         plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5151              : 
    5152              :         if (is_array)
    5153              :             result = plpgsql_build_datatype_arrayof(result);
    5154              : 
    5155              :         return result;
    5156              :     }
    5157              : 
    5158              :     /*
    5159              :      * Not %TYPE or %ROWTYPE, so scan to the end of the datatype declaration,
    5160              :      * which could include typmod or array decoration.  We are not very picky
    5161              :      * here, instead relying on parse_datatype to complain about garbage.  But
    5162              :      * we must count parens to handle typmods within cursor_arg correctly.
    5163              :      */
    5164              :     while (tok != ';')
    5165              :     {
    5166              :         if (tok == 0)
    5167              :         {
    5168              :             if (parenlevel != 0)
    5169              :                 yyerror(yyllocp, NULL, yyscanner, "mismatched parentheses");
    5170              :             else
    5171              :                 yyerror(yyllocp, NULL, yyscanner, "incomplete data type declaration");
    5172              :         }
    5173              :         /* Possible followers for datatype in a declaration */
    5174              :         if (tok == K_COLLATE || tok == K_NOT ||
    5175              :             tok == '=' || tok == COLON_EQUALS || tok == K_DEFAULT)
    5176              :             break;
    5177              :         /* Possible followers for datatype in a cursor_arg list */
    5178              :         if ((tok == ',' || tok == ')') && parenlevel == 0)
    5179              :             break;
    5180              :         if (tok == '(')
    5181              :             parenlevel++;
    5182              :         else if (tok == ')')
    5183              :             parenlevel--;
    5184              : 
    5185              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5186              :     }
    5187              : 
    5188              :     /* set up ds to contain complete typename text */
    5189              :     initStringInfo(&ds);
    5190              :     plpgsql_append_source_text(&ds, startlocation, *yyllocp, yyscanner);
    5191              :     type_name = ds.data;
    5192              : 
    5193              :     if (type_name[0] == '\0')
    5194              :         yyerror(yyllocp, NULL, yyscanner, "missing data type declaration");
    5195              : 
    5196              :     result = parse_datatype(type_name, startlocation, yyscanner);
    5197              : 
    5198              :     pfree(ds.data);
    5199              : 
    5200              :     plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5201              : 
    5202              :     return result;
    5203              : }
    5204              : 
    5205              : /*
    5206              :  * Read a generic SQL statement.  We have already read its first token;
    5207              :  * firsttoken is that token's code and location its starting location.
    5208              :  * If firsttoken == T_WORD, pass its yylval value as "word", else pass NULL.
    5209              :  */
    5210              : static PLpgSQL_stmt *
    5211              : make_execsql_stmt(int firsttoken, int location, PLword *word, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    5212              : {
    5213              :     StringInfoData ds;
    5214              :     IdentifierLookup save_IdentifierLookup;
    5215              :     PLpgSQL_stmt_execsql *execsql;
    5216              :     PLpgSQL_expr *expr;
    5217              :     PLpgSQL_variable *target = NULL;
    5218              :     int         tok;
    5219              :     int         prev_tok;
    5220              :     bool        have_into = false;
    5221              :     bool        have_strict = false;
    5222              :     int         into_start_loc = -1;
    5223              :     int         into_end_loc = -1;
    5224              :     int         paren_depth = 0;
    5225              :     int         begin_depth = 0;
    5226              :     bool        in_routine_definition = false;
    5227              :     int         token_count = 0;
    5228              :     char        tokens[4];      /* records the first few tokens */
    5229              : 
    5230              :     initStringInfo(&ds);
    5231              : 
    5232              :     memset(tokens, 0, sizeof(tokens));
    5233              : 
    5234              :     /* special lookup mode for identifiers within the SQL text */
    5235              :     save_IdentifierLookup = plpgsql_IdentifierLookup;
    5236              :     plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_EXPR;
    5237              : 
    5238              :     /*
    5239              :      * Scan to the end of the SQL command.  Identify any INTO-variables clause
    5240              :      * lurking within it, and parse that via read_into_target().
    5241              :      *
    5242              :      * The end of the statement is defined by a semicolon ... except that
    5243              :      * semicolons within parentheses or BEGIN/END blocks don't terminate a
    5244              :      * statement.  We follow psql's lead in not recognizing BEGIN/END except
    5245              :      * after CREATE [OR REPLACE] {FUNCTION|PROCEDURE}.  END can also appear
    5246              :      * within a CASE construct, so we treat CASE/END like BEGIN/END.
    5247              :      *
    5248              :      * Because INTO is sometimes used in the main SQL grammar, we have to be
    5249              :      * careful not to take any such usage of INTO as a PL/pgSQL INTO clause.
    5250              :      * There are currently three such cases:
    5251              :      *
    5252              :      * 1. SELECT ... INTO.  We don't care, we just override that with the
    5253              :      * PL/pgSQL definition.
    5254              :      *
    5255              :      * 2. INSERT INTO.  This is relatively easy to recognize since the words
    5256              :      * must appear adjacently; but we can't assume INSERT starts the command,
    5257              :      * because it can appear in CREATE RULE or WITH.  Unfortunately, INSERT is
    5258              :      * *not* fully reserved, so that means there is a chance of a false match;
    5259              :      * but it's not very likely.
    5260              :      *
    5261              :      * 3. IMPORT FOREIGN SCHEMA ... INTO.  This is not allowed in CREATE RULE
    5262              :      * or WITH, so we just check for IMPORT as the command's first token. (If
    5263              :      * IMPORT FOREIGN SCHEMA returned data someone might wish to capture with
    5264              :      * an INTO-variables clause, we'd have to work much harder here.)
    5265              :      *
    5266              :      * Fortunately, INTO is a fully reserved word in the main grammar, so at
    5267              :      * least we need not worry about it appearing as an identifier.
    5268              :      *
    5269              :      * Any future additional uses of INTO in the main grammar will doubtless
    5270              :      * break this logic again ... beware!
    5271              :      */
    5272              :     tok = firsttoken;
    5273              :     if (tok == T_WORD && strcmp(word->ident, "create") == 0)
    5274              :         tokens[token_count] = 'c';
    5275              :     token_count++;
    5276              : 
    5277              :     for (;;)
    5278              :     {
    5279              :         prev_tok = tok;
    5280              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5281              :         if (have_into && into_end_loc < 0)
    5282              :             into_end_loc = *yyllocp;    /* token after the INTO part */
    5283              :         /* Detect CREATE [OR REPLACE] {FUNCTION|PROCEDURE} */
    5284              :         if (tokens[0] == 'c' && token_count < sizeof(tokens))
    5285              :         {
    5286              :             if (tok == K_OR)
    5287              :                 tokens[token_count] = 'o';
    5288              :             else if (tok == T_WORD &&
    5289              :                      strcmp(yylvalp->word.ident, "replace") == 0)
    5290              :                 tokens[token_count] = 'r';
    5291              :             else if (tok == T_WORD &&
    5292              :                      strcmp(yylvalp->word.ident, "function") == 0)
    5293              :                 tokens[token_count] = 'f';
    5294              :             else if (tok == T_WORD &&
    5295              :                      strcmp(yylvalp->word.ident, "procedure") == 0)
    5296              :                 tokens[token_count] = 'f';  /* treat same as "function" */
    5297              :             if (tokens[1] == 'f' ||
    5298              :                 (tokens[1] == 'o' && tokens[2] == 'r' && tokens[3] == 'f'))
    5299              :                 in_routine_definition = true;
    5300              :             token_count++;
    5301              :         }
    5302              :         /* Track paren nesting (needed for CREATE RULE syntax) */
    5303              :         if (tok == '(')
    5304              :             paren_depth++;
    5305              :         else if (tok == ')' && paren_depth > 0)
    5306              :             paren_depth--;
    5307              :         /* We need track BEGIN/END nesting only in a routine definition */
    5308              :         if (in_routine_definition && paren_depth == 0)
    5309              :         {
    5310              :             if (tok == K_BEGIN || tok == K_CASE)
    5311              :                 begin_depth++;
    5312              :             else if (tok == K_END && begin_depth > 0)
    5313              :                 begin_depth--;
    5314              :         }
    5315              :         /* Command-ending semicolon? */
    5316              :         if (tok == ';' && paren_depth == 0 && begin_depth == 0)
    5317              :             break;
    5318              :         if (tok == 0)
    5319              :             yyerror(yyllocp, NULL, yyscanner, "unexpected end of function definition");
    5320              :         if (tok == K_INTO)
    5321              :         {
    5322              :             if (prev_tok == K_INSERT)
    5323              :                 continue;       /* INSERT INTO is not an INTO-target */
    5324              :             if (prev_tok == K_MERGE)
    5325              :                 continue;       /* MERGE INTO is not an INTO-target */
    5326              :             if (firsttoken == K_IMPORT)
    5327              :                 continue;       /* IMPORT ... INTO is not an INTO-target */
    5328              :             if (have_into)
    5329              :                 yyerror(yyllocp, NULL, yyscanner, "INTO specified more than once");
    5330              :             have_into = true;
    5331              :             into_start_loc = *yyllocp;
    5332              :             plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
    5333              :             read_into_target(&target, &have_strict, yylvalp, yyllocp, yyscanner);
    5334              :             plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_EXPR;
    5335              :         }
    5336              :     }
    5337              : 
    5338              :     plpgsql_IdentifierLookup = save_IdentifierLookup;
    5339              : 
    5340              :     if (have_into)
    5341              :     {
    5342              :         /*
    5343              :          * Insert an appropriate number of spaces corresponding to the INTO
    5344              :          * text, so that locations within the redacted SQL statement still
    5345              :          * line up with those in the original source text.
    5346              :          */
    5347              :         plpgsql_append_source_text(&ds, location, into_start_loc, yyscanner);
    5348              :         appendStringInfoSpaces(&ds, into_end_loc - into_start_loc);
    5349              :         plpgsql_append_source_text(&ds, into_end_loc, *yyllocp, yyscanner);
    5350              :     }
    5351              :     else
    5352              :         plpgsql_append_source_text(&ds, location, *yyllocp, yyscanner);
    5353              : 
    5354              :     /* trim any trailing whitespace, for neatness */
    5355              :     while (ds.len > 0 && scanner_isspace(ds.data[ds.len - 1]))
    5356              :         ds.data[--ds.len] = '\0';
    5357              : 
    5358              :     expr = make_plpgsql_expr(ds.data, RAW_PARSE_DEFAULT);
    5359              :     pfree(ds.data);
    5360              : 
    5361              :     check_sql_expr(expr->query, expr->parseMode, location, yyscanner);
    5362              : 
    5363              :     execsql = palloc0_object(PLpgSQL_stmt_execsql);
    5364              :     execsql->cmd_type = PLPGSQL_STMT_EXECSQL;
    5365              :     execsql->lineno = plpgsql_location_to_lineno(location, yyscanner);
    5366              :     execsql->stmtid = ++plpgsql_curr_compile->nstatements;
    5367              :     execsql->sqlstmt = expr;
    5368              :     execsql->into = have_into;
    5369              :     execsql->strict = have_strict;
    5370              :     execsql->target = target;
    5371              : 
    5372              :     return (PLpgSQL_stmt *) execsql;
    5373              : }
    5374              : 
    5375              : 
    5376              : /*
    5377              :  * Read FETCH or MOVE direction clause (everything through FROM/IN).
    5378              :  */
    5379              : static PLpgSQL_stmt_fetch *
    5380              : read_fetch_direction(YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    5381              : {
    5382              :     PLpgSQL_stmt_fetch *fetch;
    5383              :     int         tok;
    5384              :     bool        check_FROM = true;
    5385              : 
    5386              :     /*
    5387              :      * We create the PLpgSQL_stmt_fetch struct here, but only fill in the
    5388              :      * fields arising from the optional direction clause
    5389              :      */
    5390              :     fetch = (PLpgSQL_stmt_fetch *) palloc0_object(PLpgSQL_stmt_fetch);
    5391              :     fetch->cmd_type = PLPGSQL_STMT_FETCH;
    5392              :     fetch->stmtid = ++plpgsql_curr_compile->nstatements;
    5393              :     /* set direction defaults: */
    5394              :     fetch->direction = FETCH_FORWARD;
    5395              :     fetch->how_many = 1;
    5396              :     fetch->expr = NULL;
    5397              :     fetch->returns_multiple_rows = false;
    5398              : 
    5399              :     tok = yylex(yylvalp, yyllocp, yyscanner);
    5400              :     if (tok == 0)
    5401              :         yyerror(yyllocp, NULL, yyscanner, "unexpected end of function definition");
    5402              : 
    5403              :     if (tok_is_keyword(tok, yylvalp,
    5404              :                        K_NEXT, "next"))
    5405              :     {
    5406              :         /* use defaults */
    5407              :     }
    5408              :     else if (tok_is_keyword(tok, yylvalp,
    5409              :                             K_PRIOR, "prior"))
    5410              :     {
    5411              :         fetch->direction = FETCH_BACKWARD;
    5412              :     }
    5413              :     else if (tok_is_keyword(tok, yylvalp,
    5414              :                             K_FIRST, "first"))
    5415              :     {
    5416              :         fetch->direction = FETCH_ABSOLUTE;
    5417              :     }
    5418              :     else if (tok_is_keyword(tok, yylvalp,
    5419              :                             K_LAST, "last"))
    5420              :     {
    5421              :         fetch->direction = FETCH_ABSOLUTE;
    5422              :         fetch->how_many = -1;
    5423              :     }
    5424              :     else if (tok_is_keyword(tok, yylvalp,
    5425              :                             K_ABSOLUTE, "absolute"))
    5426              :     {
    5427              :         fetch->direction = FETCH_ABSOLUTE;
    5428              :         fetch->expr = read_sql_expression2(K_FROM, K_IN,
    5429              :                                            "FROM or IN",
    5430              :                                            NULL, yylvalp, yyllocp, yyscanner);
    5431              :         check_FROM = false;
    5432              :     }
    5433              :     else if (tok_is_keyword(tok, yylvalp,
    5434              :                             K_RELATIVE, "relative"))
    5435              :     {
    5436              :         fetch->direction = FETCH_RELATIVE;
    5437              :         fetch->expr = read_sql_expression2(K_FROM, K_IN,
    5438              :                                            "FROM or IN",
    5439              :                                            NULL, yylvalp, yyllocp, yyscanner);
    5440              :         check_FROM = false;
    5441              :     }
    5442              :     else if (tok_is_keyword(tok, yylvalp,
    5443              :                             K_ALL, "all"))
    5444              :     {
    5445              :         fetch->how_many = FETCH_ALL;
    5446              :         fetch->returns_multiple_rows = true;
    5447              :     }
    5448              :     else if (tok_is_keyword(tok, yylvalp,
    5449              :                             K_FORWARD, "forward"))
    5450              :     {
    5451              :         complete_direction(fetch, &check_FROM, yylvalp, yyllocp, yyscanner);
    5452              :     }
    5453              :     else if (tok_is_keyword(tok, yylvalp,
    5454              :                             K_BACKWARD, "backward"))
    5455              :     {
    5456              :         fetch->direction = FETCH_BACKWARD;
    5457              :         complete_direction(fetch, &check_FROM, yylvalp, yyllocp, yyscanner);
    5458              :     }
    5459              :     else if (tok == K_FROM || tok == K_IN)
    5460              :     {
    5461              :         /* empty direction */
    5462              :         check_FROM = false;
    5463              :     }
    5464              :     else if (tok == T_DATUM)
    5465              :     {
    5466              :         /* Assume there's no direction clause and tok is a cursor name */
    5467              :         plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5468              :         check_FROM = false;
    5469              :     }
    5470              :     else
    5471              :     {
    5472              :         /*
    5473              :          * Assume it's a count expression with no preceding keyword. Note: we
    5474              :          * allow this syntax because core SQL does, but it's ambiguous with
    5475              :          * the case of an omitted direction clause; for instance, "MOVE n IN
    5476              :          * c" will fail if n is a variable, because the preceding else-arm
    5477              :          * will trigger.  Perhaps this can be improved someday, but it hardly
    5478              :          * seems worth a lot of work.
    5479              :          */
    5480              :         plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5481              :         fetch->expr = read_sql_expression2(K_FROM, K_IN,
    5482              :                                            "FROM or IN",
    5483              :                                            NULL, yylvalp, yyllocp, yyscanner);
    5484              :         fetch->returns_multiple_rows = true;
    5485              :         check_FROM = false;
    5486              :     }
    5487              : 
    5488              :     /* check FROM or IN keyword after direction's specification */
    5489              :     if (check_FROM)
    5490              :     {
    5491              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5492              :         if (tok != K_FROM && tok != K_IN)
    5493              :             yyerror(yyllocp, NULL, yyscanner, "expected FROM or IN");
    5494              :     }
    5495              : 
    5496              :     return fetch;
    5497              : }
    5498              : 
    5499              : /*
    5500              :  * Process remainder of FETCH/MOVE direction after FORWARD or BACKWARD.
    5501              :  * Allows these cases:
    5502              :  *   FORWARD expr,  FORWARD ALL,  FORWARD
    5503              :  *   BACKWARD expr, BACKWARD ALL, BACKWARD
    5504              :  */
    5505              : static void
    5506              : complete_direction(PLpgSQL_stmt_fetch *fetch, bool *check_FROM, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    5507              : {
    5508              :     int         tok;
    5509              : 
    5510              :     tok = yylex(yylvalp, yyllocp, yyscanner);
    5511              :     if (tok == 0)
    5512              :         yyerror(yyllocp, NULL, yyscanner, "unexpected end of function definition");
    5513              : 
    5514              :     if (tok == K_FROM || tok == K_IN)
    5515              :     {
    5516              :         *check_FROM = false;
    5517              :         return;
    5518              :     }
    5519              : 
    5520              :     if (tok == K_ALL)
    5521              :     {
    5522              :         fetch->how_many = FETCH_ALL;
    5523              :         fetch->returns_multiple_rows = true;
    5524              :         *check_FROM = true;
    5525              :         return;
    5526              :     }
    5527              : 
    5528              :     plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5529              :     fetch->expr = read_sql_expression2(K_FROM, K_IN,
    5530              :                                        "FROM or IN",
    5531              :                                        NULL, yylvalp, yyllocp, yyscanner);
    5532              :     fetch->returns_multiple_rows = true;
    5533              :     *check_FROM = false;
    5534              : }
    5535              : 
    5536              : 
    5537              : static PLpgSQL_stmt *
    5538              : make_return_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    5539              : {
    5540              :     PLpgSQL_stmt_return *new;
    5541              : 
    5542              :     new = palloc0_object(PLpgSQL_stmt_return);
    5543              :     new->cmd_type = PLPGSQL_STMT_RETURN;
    5544              :     new->lineno = plpgsql_location_to_lineno(location, yyscanner);
    5545              :     new->stmtid = ++plpgsql_curr_compile->nstatements;
    5546              :     new->expr = NULL;
    5547              :     new->retvarno = -1;
    5548              : 
    5549              :     if (plpgsql_curr_compile->fn_retset)
    5550              :     {
    5551              :         if (yylex(yylvalp, yyllocp, yyscanner) != ';')
    5552              :             ereport(ERROR,
    5553              :                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    5554              :                      errmsg("RETURN cannot have a parameter in function returning set"),
    5555              :                      errhint("Use RETURN NEXT or RETURN QUERY."),
    5556              :                      parser_errposition(*yyllocp)));
    5557              :     }
    5558              :     else if (plpgsql_curr_compile->fn_rettype == VOIDOID)
    5559              :     {
    5560              :         if (yylex(yylvalp, yyllocp, yyscanner) != ';')
    5561              :         {
    5562              :             if (plpgsql_curr_compile->fn_prokind == PROKIND_PROCEDURE)
    5563              :                 ereport(ERROR,
    5564              :                         (errcode(ERRCODE_SYNTAX_ERROR),
    5565              :                          errmsg("RETURN cannot have a parameter in a procedure"),
    5566              :                          parser_errposition(*yyllocp)));
    5567              :             else
    5568              :                 ereport(ERROR,
    5569              :                         (errcode(ERRCODE_DATATYPE_MISMATCH),
    5570              :                          errmsg("RETURN cannot have a parameter in function returning void"),
    5571              :                          parser_errposition(*yyllocp)));
    5572              :         }
    5573              :     }
    5574              :     else if (plpgsql_curr_compile->out_param_varno >= 0)
    5575              :     {
    5576              :         if (yylex(yylvalp, yyllocp, yyscanner) != ';')
    5577              :             ereport(ERROR,
    5578              :                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    5579              :                      errmsg("RETURN cannot have a parameter in function with OUT parameters"),
    5580              :                      parser_errposition(*yyllocp)));
    5581              :         new->retvarno = plpgsql_curr_compile->out_param_varno;
    5582              :     }
    5583              :     else
    5584              :     {
    5585              :         /*
    5586              :          * We want to special-case simple variable references for efficiency.
    5587              :          * So peek ahead to see if that's what we have.
    5588              :          */
    5589              :         int         tok = yylex(yylvalp, yyllocp, yyscanner);
    5590              : 
    5591              :         if (tok == T_DATUM && plpgsql_peek(yyscanner) == ';' &&
    5592              :             (yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_VAR ||
    5593              :              yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_PROMISE ||
    5594              :              yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_ROW ||
    5595              :              yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_REC))
    5596              :         {
    5597              :             new->retvarno = yylvalp->wdatum.datum->dno;
    5598              :             /* eat the semicolon token that we only peeked at above */
    5599              :             tok = yylex(yylvalp, yyllocp, yyscanner);
    5600              :             Assert(tok == ';');
    5601              :         }
    5602              :         else
    5603              :         {
    5604              :             /*
    5605              :              * Not (just) a variable name, so treat as expression.
    5606              :              *
    5607              :              * Note that a well-formed expression is _required_ here; anything
    5608              :              * else is a compile-time error.
    5609              :              */
    5610              :             plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5611              :             new->expr = read_sql_expression(';', ";", yylvalp, yyllocp, yyscanner);
    5612              :         }
    5613              :     }
    5614              : 
    5615              :     return (PLpgSQL_stmt *) new;
    5616              : }
    5617              : 
    5618              : 
    5619              : static PLpgSQL_stmt *
    5620              : make_return_next_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    5621              : {
    5622              :     PLpgSQL_stmt_return_next *new;
    5623              : 
    5624              :     if (!plpgsql_curr_compile->fn_retset)
    5625              :         ereport(ERROR,
    5626              :                 (errcode(ERRCODE_DATATYPE_MISMATCH),
    5627              :                  errmsg("cannot use RETURN NEXT in a non-SETOF function"),
    5628              :                  parser_errposition(location)));
    5629              : 
    5630              :     new = palloc0_object(PLpgSQL_stmt_return_next);
    5631              :     new->cmd_type = PLPGSQL_STMT_RETURN_NEXT;
    5632              :     new->lineno = plpgsql_location_to_lineno(location, yyscanner);
    5633              :     new->stmtid = ++plpgsql_curr_compile->nstatements;
    5634              :     new->expr = NULL;
    5635              :     new->retvarno = -1;
    5636              : 
    5637              :     if (plpgsql_curr_compile->out_param_varno >= 0)
    5638              :     {
    5639              :         if (yylex(yylvalp, yyllocp, yyscanner) != ';')
    5640              :             ereport(ERROR,
    5641              :                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    5642              :                      errmsg("RETURN NEXT cannot have a parameter in function with OUT parameters"),
    5643              :                      parser_errposition(*yyllocp)));
    5644              :         new->retvarno = plpgsql_curr_compile->out_param_varno;
    5645              :     }
    5646              :     else
    5647              :     {
    5648              :         /*
    5649              :          * We want to special-case simple variable references for efficiency.
    5650              :          * So peek ahead to see if that's what we have.
    5651              :          */
    5652              :         int         tok = yylex(yylvalp, yyllocp, yyscanner);
    5653              : 
    5654              :         if (tok == T_DATUM && plpgsql_peek(yyscanner) == ';' &&
    5655              :             (yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_VAR ||
    5656              :              yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_PROMISE ||
    5657              :              yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_ROW ||
    5658              :              yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_REC))
    5659              :         {
    5660              :             new->retvarno = yylvalp->wdatum.datum->dno;
    5661              :             /* eat the semicolon token that we only peeked at above */
    5662              :             tok = yylex(yylvalp, yyllocp, yyscanner);
    5663              :             Assert(tok == ';');
    5664              :         }
    5665              :         else
    5666              :         {
    5667              :             /*
    5668              :              * Not (just) a variable name, so treat as expression.
    5669              :              *
    5670              :              * Note that a well-formed expression is _required_ here; anything
    5671              :              * else is a compile-time error.
    5672              :              */
    5673              :             plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5674              :             new->expr = read_sql_expression(';', ";", yylvalp, yyllocp, yyscanner);
    5675              :         }
    5676              :     }
    5677              : 
    5678              :     return (PLpgSQL_stmt *) new;
    5679              : }
    5680              : 
    5681              : 
    5682              : static PLpgSQL_stmt *
    5683              : make_return_query_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    5684              : {
    5685              :     PLpgSQL_stmt_return_query *new;
    5686              :     int         tok;
    5687              : 
    5688              :     if (!plpgsql_curr_compile->fn_retset)
    5689              :         ereport(ERROR,
    5690              :                 (errcode(ERRCODE_DATATYPE_MISMATCH),
    5691              :                  errmsg("cannot use RETURN QUERY in a non-SETOF function"),
    5692              :                  parser_errposition(location)));
    5693              : 
    5694              :     new = palloc0_object(PLpgSQL_stmt_return_query);
    5695              :     new->cmd_type = PLPGSQL_STMT_RETURN_QUERY;
    5696              :     new->lineno = plpgsql_location_to_lineno(location, yyscanner);
    5697              :     new->stmtid = ++plpgsql_curr_compile->nstatements;
    5698              : 
    5699              :     /* check for RETURN QUERY EXECUTE */
    5700              :     tok = yylex(yylvalp, yyllocp, yyscanner);
    5701              :     if (!tok_is_keyword(tok, yylvalp, K_EXECUTE, "execute"))
    5702              :     {
    5703              :         /* ordinary static query */
    5704              :         plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5705              :         new->query = read_sql_stmt(yylvalp, yyllocp, yyscanner);
    5706              :     }
    5707              :     else
    5708              :     {
    5709              :         /* dynamic SQL */
    5710              :         int         term;
    5711              : 
    5712              :         new->dynquery = read_sql_expression2(';', K_USING, "; or USING",
    5713              :                                              &term, yylvalp, yyllocp, yyscanner);
    5714              :         if (term == K_USING)
    5715              :         {
    5716              :             do
    5717              :             {
    5718              :                 PLpgSQL_expr *expr;
    5719              : 
    5720              :                 expr = read_sql_expression2(',', ';', ", or ;", &term, yylvalp, yyllocp, yyscanner);
    5721              :                 new->params = lappend(new->params, expr);
    5722              :             } while (term == ',');
    5723              :         }
    5724              :     }
    5725              : 
    5726              :     return (PLpgSQL_stmt *) new;
    5727              : }
    5728              : 
    5729              : 
    5730              : /* convenience routine to fetch the name of a T_DATUM */
    5731              : static char *
    5732              : NameOfDatum(PLwdatum *wdatum)
    5733              : {
    5734              :     if (wdatum->ident)
    5735              :         return wdatum->ident;
    5736              :     Assert(wdatum->idents != NIL);
    5737              :     return NameListToString(wdatum->idents);
    5738              : }
    5739              : 
    5740              : static void
    5741              : check_assignable(PLpgSQL_datum *datum, int location, yyscan_t yyscanner)
    5742              : {
    5743              :     switch (datum->dtype)
    5744              :     {
    5745              :         case PLPGSQL_DTYPE_VAR:
    5746              :         case PLPGSQL_DTYPE_PROMISE:
    5747              :         case PLPGSQL_DTYPE_REC:
    5748              :             if (((PLpgSQL_variable *) datum)->isconst)
    5749              :                 ereport(ERROR,
    5750              :                         (errcode(ERRCODE_ERROR_IN_ASSIGNMENT),
    5751              :                          errmsg("variable \"%s\" is declared CONSTANT",
    5752              :                                 ((PLpgSQL_variable *) datum)->refname),
    5753              :                          parser_errposition(location)));
    5754              :             break;
    5755              :         case PLPGSQL_DTYPE_ROW:
    5756              :             /* always assignable; member vars were checked at compile time */
    5757              :             break;
    5758              :         case PLPGSQL_DTYPE_RECFIELD:
    5759              :             /* assignable if parent record is */
    5760              :             check_assignable(plpgsql_Datums[((PLpgSQL_recfield *) datum)->recparentno],
    5761              :                              location, yyscanner);
    5762              :             break;
    5763              :         default:
    5764              :             elog(ERROR, "unrecognized dtype: %d", datum->dtype);
    5765              :             break;
    5766              :     }
    5767              : }
    5768              : 
    5769              : /*
    5770              :  * Read the argument of an INTO clause.  On entry, we have just read the
    5771              :  * INTO keyword.
    5772              :  */
    5773              : static void
    5774              : read_into_target(PLpgSQL_variable **target, bool *strict, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    5775              : {
    5776              :     int         tok;
    5777              : 
    5778              :     /* Set default results */
    5779              :     *target = NULL;
    5780              :     if (strict)
    5781              :         *strict = false;
    5782              : 
    5783              :     tok = yylex(yylvalp, yyllocp, yyscanner);
    5784              :     if (strict && tok_is_keyword(tok, yylvalp, K_STRICT, "strict"))
    5785              :     {
    5786              :         *strict = true;
    5787              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5788              :     }
    5789              : 
    5790              :     /*
    5791              :      * Currently, a row or record variable can be the single INTO target, but
    5792              :      * not a member of a multi-target list.  So we throw error if there is a
    5793              :      * comma after it, because that probably means the user tried to write a
    5794              :      * multi-target list.  If this ever gets generalized, we should probably
    5795              :      * refactor read_into_scalar_list so it handles all cases.
    5796              :      */
    5797              :     switch (tok)
    5798              :     {
    5799              :         case T_DATUM:
    5800              :             if (yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_ROW ||
    5801              :                 yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_REC)
    5802              :             {
    5803              :                 check_assignable(yylvalp->wdatum.datum, *yyllocp, yyscanner);
    5804              :                 *target = (PLpgSQL_variable *) yylvalp->wdatum.datum;
    5805              : 
    5806              :                 if ((tok = yylex(yylvalp, yyllocp, yyscanner)) == ',')
    5807              :                     ereport(ERROR,
    5808              :                             (errcode(ERRCODE_SYNTAX_ERROR),
    5809              :                              errmsg("record variable cannot be part of multiple-item INTO list"),
    5810              :                              parser_errposition(*yyllocp)));
    5811              :                 plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5812              :             }
    5813              :             else
    5814              :             {
    5815              :                 *target = (PLpgSQL_variable *)
    5816              :                     read_into_scalar_list(NameOfDatum(&(yylvalp->wdatum)),
    5817              :                                           yylvalp->wdatum.datum, *yyllocp, yylvalp, yyllocp, yyscanner);
    5818              :             }
    5819              :             break;
    5820              : 
    5821              :         default:
    5822              :             /* just to give a better message than "syntax error" */
    5823              :             current_token_is_not_variable(tok, yylvalp, yyllocp, yyscanner);
    5824              :     }
    5825              : }
    5826              : 
    5827              : /*
    5828              :  * Given the first datum and name in the INTO list, continue to read
    5829              :  * comma-separated scalar variables until we run out. Then construct
    5830              :  * and return a fake "row" variable that represents the list of
    5831              :  * scalars.
    5832              :  */
    5833              : static PLpgSQL_row *
    5834              : read_into_scalar_list(char *initial_name,
    5835              :                       PLpgSQL_datum *initial_datum,
    5836              :                       int initial_location,
    5837              :                       YYSTYPE *yylvalp, YYLTYPE *yyllocp,
    5838              :                       yyscan_t yyscanner)
    5839              : {
    5840              :     int         nfields;
    5841              :     char       *fieldnames[1024];
    5842              :     int         varnos[1024];
    5843              :     PLpgSQL_row *row;
    5844              :     int         tok;
    5845              : 
    5846              :     check_assignable(initial_datum, initial_location, yyscanner);
    5847              :     fieldnames[0] = initial_name;
    5848              :     varnos[0] = initial_datum->dno;
    5849              :     nfields = 1;
    5850              : 
    5851              :     while ((tok = yylex(yylvalp, yyllocp, yyscanner)) == ',')
    5852              :     {
    5853              :         /* Check for array overflow */
    5854              :         if (nfields >= 1024)
    5855              :             ereport(ERROR,
    5856              :                     (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
    5857              :                      errmsg("too many INTO variables specified"),
    5858              :                      parser_errposition(*yyllocp)));
    5859              : 
    5860              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    5861              :         switch (tok)
    5862              :         {
    5863              :             case T_DATUM:
    5864              :                 check_assignable(yylvalp->wdatum.datum, *yyllocp, yyscanner);
    5865              :                 if (yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_ROW ||
    5866              :                     yylvalp->wdatum.datum->dtype == PLPGSQL_DTYPE_REC)
    5867              :                     ereport(ERROR,
    5868              :                             (errcode(ERRCODE_SYNTAX_ERROR),
    5869              :                              errmsg("\"%s\" is not a scalar variable",
    5870              :                                     NameOfDatum(&(yylvalp->wdatum))),
    5871              :                              parser_errposition(*yyllocp)));
    5872              :                 fieldnames[nfields] = NameOfDatum(&(yylvalp->wdatum));
    5873              :                 varnos[nfields++] = yylvalp->wdatum.datum->dno;
    5874              :                 break;
    5875              : 
    5876              :             default:
    5877              :                 /* just to give a better message than "syntax error" */
    5878              :                 current_token_is_not_variable(tok, yylvalp, yyllocp, yyscanner);
    5879              :         }
    5880              :     }
    5881              : 
    5882              :     /*
    5883              :      * We read an extra, non-comma token from yylex(), so push it back onto
    5884              :      * the input stream
    5885              :      */
    5886              :     plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
    5887              : 
    5888              :     row = palloc0_object(PLpgSQL_row);
    5889              :     row->dtype = PLPGSQL_DTYPE_ROW;
    5890              :     row->refname = "(unnamed row)";
    5891              :     row->lineno = plpgsql_location_to_lineno(initial_location, yyscanner);
    5892              :     row->rowtupdesc = NULL;
    5893              :     row->nfields = nfields;
    5894              :     row->fieldnames = palloc_array(char *, nfields);
    5895              :     row->varnos = palloc_array(int, nfields);
    5896              :     while (--nfields >= 0)
    5897              :     {
    5898              :         row->fieldnames[nfields] = fieldnames[nfields];
    5899              :         row->varnos[nfields] = varnos[nfields];
    5900              :     }
    5901              : 
    5902              :     plpgsql_adddatum((PLpgSQL_datum *) row);
    5903              : 
    5904              :     return row;
    5905              : }
    5906              : 
    5907              : /*
    5908              :  * Convert a single scalar into a "row" list.  This is exactly
    5909              :  * like read_into_scalar_list except we never consume any input.
    5910              :  *
    5911              :  * Note: lineno could be computed from location, but since callers
    5912              :  * have it at hand already, we may as well pass it in.
    5913              :  */
    5914              : static PLpgSQL_row *
    5915              : make_scalar_list1(char *initial_name,
    5916              :                   PLpgSQL_datum *initial_datum,
    5917              :                   int lineno, int location, yyscan_t yyscanner)
    5918              : {
    5919              :     PLpgSQL_row *row;
    5920              : 
    5921              :     check_assignable(initial_datum, location, yyscanner);
    5922              : 
    5923              :     row = palloc0_object(PLpgSQL_row);
    5924              :     row->dtype = PLPGSQL_DTYPE_ROW;
    5925              :     row->refname = "(unnamed row)";
    5926              :     row->lineno = lineno;
    5927              :     row->rowtupdesc = NULL;
    5928              :     row->nfields = 1;
    5929              :     row->fieldnames = palloc_object(char *);
    5930              :     row->varnos = palloc_object(int);
    5931              :     row->fieldnames[0] = initial_name;
    5932              :     row->varnos[0] = initial_datum->dno;
    5933              : 
    5934              :     plpgsql_adddatum((PLpgSQL_datum *) row);
    5935              : 
    5936              :     return row;
    5937              : }
    5938              : 
    5939              : /*
    5940              :  * When the PL/pgSQL parser expects to see a SQL statement, it is very
    5941              :  * liberal in what it accepts; for example, we often assume an
    5942              :  * unrecognized keyword is the beginning of a SQL statement. This
    5943              :  * avoids the need to duplicate parts of the SQL grammar in the
    5944              :  * PL/pgSQL grammar, but it means we can accept wildly malformed
    5945              :  * input. To try and catch some of the more obviously invalid input,
    5946              :  * we run the strings we expect to be SQL statements through the main
    5947              :  * SQL parser.
    5948              :  *
    5949              :  * We only invoke the raw parser (not the analyzer); this doesn't do
    5950              :  * any database access and does not check any semantic rules, it just
    5951              :  * checks for basic syntactic correctness. We do this here, rather
    5952              :  * than after parsing has finished, because a malformed SQL statement
    5953              :  * may cause the PL/pgSQL parser to become confused about statement
    5954              :  * borders. So it is best to bail out as early as we can.
    5955              :  *
    5956              :  * It is assumed that "stmt" represents a copy of the function source text
    5957              :  * beginning at offset "location".  We use this assumption to transpose
    5958              :  * any error cursor position back to the function source text.
    5959              :  * If no error cursor is provided, we'll just point at "location".
    5960              :  */
    5961              : static void
    5962              : check_sql_expr(const char *stmt, RawParseMode parseMode, int location, yyscan_t yyscanner)
    5963              : {
    5964              :     sql_error_callback_arg cbarg;
    5965              :     ErrorContextCallback syntax_errcontext;
    5966              :     MemoryContext oldCxt;
    5967              : 
    5968              :     if (!plpgsql_check_syntax)
    5969              :         return;
    5970              : 
    5971              :     cbarg.location = location;
    5972              :     cbarg.yyscanner = yyscanner;
    5973              : 
    5974              :     syntax_errcontext.callback = plpgsql_sql_error_callback;
    5975              :     syntax_errcontext.arg = &cbarg;
    5976              :     syntax_errcontext.previous = error_context_stack;
    5977              :     error_context_stack = &syntax_errcontext;
    5978              : 
    5979              :     oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
    5980              :     (void) raw_parser(stmt, parseMode);
    5981              :     MemoryContextSwitchTo(oldCxt);
    5982              : 
    5983              :     /* Restore former ereport callback */
    5984              :     error_context_stack = syntax_errcontext.previous;
    5985              : }
    5986              : 
    5987              : static void
    5988              : plpgsql_sql_error_callback(void *arg)
    5989              : {
    5990              :     sql_error_callback_arg *cbarg = (sql_error_callback_arg *) arg;
    5991              :     yyscan_t    yyscanner = cbarg->yyscanner;
    5992              :     int         errpos;
    5993              : 
    5994              :     /*
    5995              :      * First, set up internalerrposition to point to the start of the
    5996              :      * statement text within the function text.  Note this converts location
    5997              :      * (a byte offset) to a character number.
    5998              :      */
    5999              :     parser_errposition(cbarg->location);
    6000              : 
    6001              :     /*
    6002              :      * If the core parser provided an error position, transpose it. Note we
    6003              :      * are dealing with 1-based character numbers at this point.
    6004              :      */
    6005              :     errpos = geterrposition();
    6006              :     if (errpos > 0)
    6007              :     {
    6008              :         int         myerrpos = getinternalerrposition();
    6009              : 
    6010              :         if (myerrpos > 0)        /* safety check */
    6011              :             internalerrposition(myerrpos + errpos - 1);
    6012              :     }
    6013              : 
    6014              :     /* In any case, flush errposition --- we want internalerrposition only */
    6015              :     errposition(0);
    6016              : }
    6017              : 
    6018              : /*
    6019              :  * Parse a SQL datatype name and produce a PLpgSQL_type structure.
    6020              :  *
    6021              :  * The heavy lifting is done elsewhere.  Here we are only concerned
    6022              :  * with setting up an errcontext link that will let us give an error
    6023              :  * cursor pointing into the plpgsql function source, if necessary.
    6024              :  * This is handled the same as in check_sql_expr(), and we likewise
    6025              :  * expect that the given string is a copy from the source text.
    6026              :  */
    6027              : static PLpgSQL_type *
    6028              : parse_datatype(const char *string, int location, yyscan_t yyscanner)
    6029              : {
    6030              :     TypeName   *typeName;
    6031              :     Oid         type_id;
    6032              :     int32       typmod;
    6033              :     sql_error_callback_arg cbarg;
    6034              :     ErrorContextCallback syntax_errcontext;
    6035              :     MemoryContext oldCxt;
    6036              : 
    6037              :     cbarg.location = location;
    6038              :     cbarg.yyscanner = yyscanner;
    6039              : 
    6040              :     syntax_errcontext.callback = plpgsql_sql_error_callback;
    6041              :     syntax_errcontext.arg = &cbarg;
    6042              :     syntax_errcontext.previous = error_context_stack;
    6043              :     error_context_stack = &syntax_errcontext;
    6044              : 
    6045              :     /*
    6046              :      * Let the main parser try to parse it under standard SQL rules.  The
    6047              :      * parser leaks memory, so run it in temp context.
    6048              :      */
    6049              :     oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
    6050              :     typeName = typeStringToTypeName(string, NULL);
    6051              :     typenameTypeIdAndMod(NULL, typeName, &type_id, &typmod);
    6052              :     MemoryContextSwitchTo(oldCxt);
    6053              : 
    6054              :     /* Restore former ereport callback */
    6055              :     error_context_stack = syntax_errcontext.previous;
    6056              : 
    6057              :     /* Okay, build a PLpgSQL_type data structure for it */
    6058              :     return plpgsql_build_datatype(type_id, typmod,
    6059              :                                   plpgsql_curr_compile->fn_input_collation,
    6060              :                                   typeName);
    6061              : }
    6062              : 
    6063              : /*
    6064              :  * Check block starting and ending labels match.
    6065              :  */
    6066              : static void
    6067              : check_labels(const char *start_label, const char *end_label, int end_location, yyscan_t yyscanner)
    6068              : {
    6069              :     if (end_label)
    6070              :     {
    6071              :         if (!start_label)
    6072              :             ereport(ERROR,
    6073              :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6074              :                      errmsg("end label \"%s\" specified for unlabeled block",
    6075              :                             end_label),
    6076              :                      parser_errposition(end_location)));
    6077              : 
    6078              :         if (strcmp(start_label, end_label) != 0)
    6079              :             ereport(ERROR,
    6080              :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6081              :                      errmsg("end label \"%s\" differs from block's label \"%s\"",
    6082              :                             end_label, start_label),
    6083              :                      parser_errposition(end_location)));
    6084              :     }
    6085              : }
    6086              : 
    6087              : /*
    6088              :  * Read the arguments (if any) for a cursor, followed by the until token
    6089              :  *
    6090              :  * If cursor has no args, just swallow the until token and return NULL.
    6091              :  * If it does have args, we expect to see "( arg [, arg ...] )" followed
    6092              :  * by the until token, where arg may be a plain expression, or a named
    6093              :  * parameter assignment of the form argname := expr. Consume all that and
    6094              :  * return a SELECT query that evaluates the expression(s) (without the outer
    6095              :  * parens).
    6096              :  */
    6097              : static PLpgSQL_expr *
    6098              : read_cursor_args(PLpgSQL_var *cursor, int until, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    6099              : {
    6100              :     PLpgSQL_expr *expr;
    6101              :     PLpgSQL_row *row;
    6102              :     int         tok;
    6103              :     int         argc;
    6104              :     char      **argv;
    6105              :     StringInfoData ds;
    6106              :     bool        any_named = false;
    6107              : 
    6108              :     tok = yylex(yylvalp, yyllocp, yyscanner);
    6109              :     if (cursor->cursor_explicit_argrow < 0)
    6110              :     {
    6111              :         /* No arguments expected */
    6112              :         if (tok == '(')
    6113              :             ereport(ERROR,
    6114              :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6115              :                      errmsg("cursor \"%s\" has no arguments",
    6116              :                             cursor->refname),
    6117              :                      parser_errposition(*yyllocp)));
    6118              : 
    6119              :         if (tok != until)
    6120              :             yyerror(yyllocp, NULL, yyscanner, "syntax error");
    6121              : 
    6122              :         return NULL;
    6123              :     }
    6124              : 
    6125              :     /* Else better provide arguments */
    6126              :     if (tok != '(')
    6127              :         ereport(ERROR,
    6128              :                 (errcode(ERRCODE_SYNTAX_ERROR),
    6129              :                  errmsg("cursor \"%s\" has arguments",
    6130              :                         cursor->refname),
    6131              :                  parser_errposition(*yyllocp)));
    6132              : 
    6133              :     /*
    6134              :      * Read the arguments, one by one.
    6135              :      */
    6136              :     row = (PLpgSQL_row *) plpgsql_Datums[cursor->cursor_explicit_argrow];
    6137              :     argv = (char **) palloc0_array(char *, row->nfields);
    6138              : 
    6139              :     for (argc = 0; argc < row->nfields; argc++)
    6140              :     {
    6141              :         PLpgSQL_expr *item;
    6142              :         int         endtoken;
    6143              :         int         argpos;
    6144              :         int         tok1,
    6145              :                     tok2;
    6146              :         int         arglocation;
    6147              : 
    6148              :         /*
    6149              :          * Check if it's a named parameter: "param := value"
    6150              :          * or "param => value"
    6151              :          */
    6152              :         plpgsql_peek2(&tok1, &tok2, &arglocation, NULL, yyscanner);
    6153              :         if (tok1 == IDENT && (tok2 == COLON_EQUALS || tok2 == EQUALS_GREATER))
    6154              :         {
    6155              :             char       *argname;
    6156              :             IdentifierLookup save_IdentifierLookup;
    6157              : 
    6158              :             /* Read the argument name, ignoring any matching variable */
    6159              :             save_IdentifierLookup = plpgsql_IdentifierLookup;
    6160              :             plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_DECLARE;
    6161              :             yylex(yylvalp, yyllocp, yyscanner);
    6162              :             argname = yylvalp->str;
    6163              :             plpgsql_IdentifierLookup = save_IdentifierLookup;
    6164              : 
    6165              :             /* Match argument name to cursor arguments */
    6166              :             for (argpos = 0; argpos < row->nfields; argpos++)
    6167              :             {
    6168              :                 if (strcmp(row->fieldnames[argpos], argname) == 0)
    6169              :                     break;
    6170              :             }
    6171              :             if (argpos == row->nfields)
    6172              :                 ereport(ERROR,
    6173              :                         (errcode(ERRCODE_SYNTAX_ERROR),
    6174              :                          errmsg("cursor \"%s\" has no argument named \"%s\"",
    6175              :                                 cursor->refname, argname),
    6176              :                          parser_errposition(*yyllocp)));
    6177              : 
    6178              :             /*
    6179              :              * Eat the ":=" or "=>".  We already peeked, so the error should
    6180              :              * never happen.
    6181              :              */
    6182              :             tok2 = yylex(yylvalp, yyllocp, yyscanner);
    6183              :             if (tok2 != COLON_EQUALS && tok2 != EQUALS_GREATER)
    6184              :                 yyerror(yyllocp, NULL, yyscanner, "syntax error");
    6185              : 
    6186              :             any_named = true;
    6187              :         }
    6188              :         else
    6189              :             argpos = argc;
    6190              : 
    6191              :         if (argv[argpos] != NULL)
    6192              :             ereport(ERROR,
    6193              :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6194              :                      errmsg("value for parameter \"%s\" of cursor \"%s\" specified more than once",
    6195              :                             row->fieldnames[argpos], cursor->refname),
    6196              :                      parser_errposition(arglocation)));
    6197              : 
    6198              :         /*
    6199              :          * Read the value expression. To provide the user with meaningful
    6200              :          * parse error positions, we check the syntax immediately, instead of
    6201              :          * checking the final expression that may have the arguments
    6202              :          * reordered.
    6203              :          */
    6204              :         item = read_sql_construct(',', ')', 0,
    6205              :                                   ",\" or \")",
    6206              :                                   RAW_PARSE_PLPGSQL_EXPR,
    6207              :                                   true, true,
    6208              :                                   NULL, &endtoken,
    6209              :                                   yylvalp, yyllocp, yyscanner);
    6210              : 
    6211              :         argv[argpos] = item->query;
    6212              : 
    6213              :         if (endtoken == ')' && !(argc == row->nfields - 1))
    6214              :             ereport(ERROR,
    6215              :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6216              :                      errmsg("not enough arguments for cursor \"%s\"",
    6217              :                             cursor->refname),
    6218              :                      parser_errposition(*yyllocp)));
    6219              : 
    6220              :         if (endtoken == ',' && (argc == row->nfields - 1))
    6221              :             ereport(ERROR,
    6222              :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6223              :                      errmsg("too many arguments for cursor \"%s\"",
    6224              :                             cursor->refname),
    6225              :                      parser_errposition(*yyllocp)));
    6226              :     }
    6227              : 
    6228              :     /* Make positional argument list */
    6229              :     initStringInfo(&ds);
    6230              :     for (argc = 0; argc < row->nfields; argc++)
    6231              :     {
    6232              :         Assert(argv[argc] != NULL);
    6233              : 
    6234              :         /*
    6235              :          * Because named notation allows permutated argument lists, include
    6236              :          * the parameter name for meaningful runtime errors.
    6237              :          */
    6238              :         appendStringInfoString(&ds, argv[argc]);
    6239              :         if (any_named)
    6240              :             appendStringInfo(&ds, " AS %s",
    6241              :                              quote_identifier(row->fieldnames[argc]));
    6242              :         if (argc < row->nfields - 1)
    6243              :             appendStringInfoString(&ds, ", ");
    6244              :     }
    6245              : 
    6246              :     expr = make_plpgsql_expr(ds.data, RAW_PARSE_PLPGSQL_EXPR);
    6247              :     pfree(ds.data);
    6248              : 
    6249              :     /* Next we'd better find the until token */
    6250              :     tok = yylex(yylvalp, yyllocp, yyscanner);
    6251              :     if (tok != until)
    6252              :         yyerror(yyllocp, NULL, yyscanner, "syntax error");
    6253              : 
    6254              :     return expr;
    6255              : }
    6256              : 
    6257              : /*
    6258              :  * Parse RAISE ... USING options
    6259              :  */
    6260              : static List *
    6261              : read_raise_options(YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
    6262              : {
    6263              :     List       *result = NIL;
    6264              : 
    6265              :     for (;;)
    6266              :     {
    6267              :         PLpgSQL_raise_option *opt;
    6268              :         int         tok;
    6269              : 
    6270              :         if ((tok = yylex(yylvalp, yyllocp, yyscanner)) == 0)
    6271              :             yyerror(yyllocp, NULL, yyscanner, "unexpected end of function definition");
    6272              : 
    6273              :         opt = palloc_object(PLpgSQL_raise_option);
    6274              : 
    6275              :         if (tok_is_keyword(tok, yylvalp,
    6276              :                            K_ERRCODE, "errcode"))
    6277              :             opt->opt_type = PLPGSQL_RAISEOPTION_ERRCODE;
    6278              :         else if (tok_is_keyword(tok, yylvalp,
    6279              :                                 K_MESSAGE, "message"))
    6280              :             opt->opt_type = PLPGSQL_RAISEOPTION_MESSAGE;
    6281              :         else if (tok_is_keyword(tok, yylvalp,
    6282              :                                 K_DETAIL, "detail"))
    6283              :             opt->opt_type = PLPGSQL_RAISEOPTION_DETAIL;
    6284              :         else if (tok_is_keyword(tok, yylvalp,
    6285              :                                 K_HINT, "hint"))
    6286              :             opt->opt_type = PLPGSQL_RAISEOPTION_HINT;
    6287              :         else if (tok_is_keyword(tok, yylvalp,
    6288              :                                 K_COLUMN, "column"))
    6289              :             opt->opt_type = PLPGSQL_RAISEOPTION_COLUMN;
    6290              :         else if (tok_is_keyword(tok, yylvalp,
    6291              :                                 K_CONSTRAINT, "constraint"))
    6292              :             opt->opt_type = PLPGSQL_RAISEOPTION_CONSTRAINT;
    6293              :         else if (tok_is_keyword(tok, yylvalp,
    6294              :                                 K_DATATYPE, "datatype"))
    6295              :             opt->opt_type = PLPGSQL_RAISEOPTION_DATATYPE;
    6296              :         else if (tok_is_keyword(tok, yylvalp,
    6297              :                                 K_TABLE, "table"))
    6298              :             opt->opt_type = PLPGSQL_RAISEOPTION_TABLE;
    6299              :         else if (tok_is_keyword(tok, yylvalp,
    6300              :                                 K_SCHEMA, "schema"))
    6301              :             opt->opt_type = PLPGSQL_RAISEOPTION_SCHEMA;
    6302              :         else
    6303              :             yyerror(yyllocp, NULL, yyscanner, "unrecognized RAISE statement option");
    6304              : 
    6305              :         tok = yylex(yylvalp, yyllocp, yyscanner);
    6306              :         if (tok != '=' && tok != COLON_EQUALS)
    6307              :             yyerror(yyllocp, NULL, yyscanner, "syntax error, expected \"=\"");
    6308              : 
    6309              :         opt->expr = read_sql_expression2(',', ';', ", or ;", &tok, yylvalp, yyllocp, yyscanner);
    6310              : 
    6311              :         result = lappend(result, opt);
    6312              : 
    6313              :         if (tok == ';')
    6314              :             break;
    6315              :     }
    6316              : 
    6317              :     return result;
    6318              : }
    6319              : 
    6320              : /*
    6321              :  * Check that the number of parameter placeholders in the message matches the
    6322              :  * number of parameters passed to it, if a message was given.
    6323              :  */
    6324              : static void
    6325              : check_raise_parameters(PLpgSQL_stmt_raise *stmt)
    6326              : {
    6327              :     char       *cp;
    6328              :     int         expected_nparams = 0;
    6329              : 
    6330              :     if (stmt->message == NULL)
    6331              :         return;
    6332              : 
    6333              :     for (cp = stmt->message; *cp; cp++)
    6334              :     {
    6335              :         if (cp[0] == '%')
    6336              :         {
    6337              :             /* ignore literal % characters */
    6338              :             if (cp[1] == '%')
    6339              :                 cp++;
    6340              :             else
    6341              :                 expected_nparams++;
    6342              :         }
    6343              :     }
    6344              : 
    6345              :     if (expected_nparams < list_length(stmt->params))
    6346              :         ereport(ERROR,
    6347              :                 (errcode(ERRCODE_SYNTAX_ERROR),
    6348              :                  errmsg("too many parameters specified for RAISE")));
    6349              :     if (expected_nparams > list_length(stmt->params))
    6350              :         ereport(ERROR,
    6351              :                 (errcode(ERRCODE_SYNTAX_ERROR),
    6352              :                  errmsg("too few parameters specified for RAISE")));
    6353              : }
    6354              : 
    6355              : /*
    6356              :  * Fix up CASE statement
    6357              :  */
    6358              : static PLpgSQL_stmt *
    6359              : make_case(int location, PLpgSQL_expr *t_expr,
    6360              :           List *case_when_list, List *else_stmts, yyscan_t yyscanner)
    6361              : {
    6362              :     PLpgSQL_stmt_case *new;
    6363              : 
    6364              :     new = palloc_object(PLpgSQL_stmt_case);
    6365              :     new->cmd_type = PLPGSQL_STMT_CASE;
    6366              :     new->lineno = plpgsql_location_to_lineno(location, yyscanner);
    6367              :     new->stmtid = ++plpgsql_curr_compile->nstatements;
    6368              :     new->t_expr = t_expr;
    6369              :     new->t_varno = 0;
    6370              :     new->case_when_list = case_when_list;
    6371              :     new->have_else = (else_stmts != NIL);
    6372              :     /* Get rid of list-with-NULL hack */
    6373              :     if (list_length(else_stmts) == 1 && linitial(else_stmts) == NULL)
    6374              :         new->else_stmts = NIL;
    6375              :     else
    6376              :         new->else_stmts = else_stmts;
    6377              : 
    6378              :     /*
    6379              :      * When test expression is present, we create a var for it and then
    6380              :      * convert all the WHEN expressions to "VAR IN (original_expression)".
    6381              :      * This is a bit klugy, but okay since we haven't yet done more than read
    6382              :      * the expressions as text.  (Note that previous parsing won't have
    6383              :      * complained if the WHEN ... THEN expression contained multiple
    6384              :      * comma-separated values.)
    6385              :      */
    6386              :     if (t_expr)
    6387              :     {
    6388              :         char        varname[32];
    6389              :         PLpgSQL_var *t_var;
    6390              :         ListCell   *l;
    6391              : 
    6392              :         /* use a name unlikely to collide with any user names */
    6393              :         snprintf(varname, sizeof(varname), "__Case__Variable_%d__",
    6394              :                  plpgsql_nDatums);
    6395              : 
    6396              :         /*
    6397              :          * We don't yet know the result datatype of t_expr.  Build the
    6398              :          * variable as if it were INT4; we'll fix this at runtime if needed.
    6399              :          */
    6400              :         t_var = (PLpgSQL_var *)
    6401              :             plpgsql_build_variable(varname, new->lineno,
    6402              :                                    plpgsql_build_datatype(INT4OID,
    6403              :                                                           -1,
    6404              :                                                           InvalidOid,
    6405              :                                                           NULL),
    6406              :                                    true);
    6407              :         new->t_varno = t_var->dno;
    6408              : 
    6409              :         foreach(l, case_when_list)
    6410              :         {
    6411              :             PLpgSQL_case_when *cwt = (PLpgSQL_case_when *) lfirst(l);
    6412              :             PLpgSQL_expr *expr = cwt->expr;
    6413              :             StringInfoData ds;
    6414              : 
    6415              :             /* We expect to have expressions not statements */
    6416              :             Assert(expr->parseMode == RAW_PARSE_PLPGSQL_EXPR);
    6417              : 
    6418              :             /* Do the string hacking */
    6419              :             initStringInfo(&ds);
    6420              : 
    6421              :             appendStringInfo(&ds, "\"%s\" IN (%s)",
    6422              :                              varname, expr->query);
    6423              : 
    6424              :             pfree(expr->query);
    6425              :             expr->query = pstrdup(ds.data);
    6426              :             /* Adjust expr's namespace to include the case variable */
    6427              :             expr->ns = plpgsql_ns_top();
    6428              : 
    6429              :             pfree(ds.data);
    6430              :         }
    6431              :     }
    6432              : 
    6433              :     return (PLpgSQL_stmt *) new;
    6434              : }
        

Generated by: LCOV version 2.0-1