LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 90.8 % 7591 6894
Test Date: 2026-03-02 14:15:04 Functions: 100.0 % 42 42
Legend: Lines:     hit not hit

            Line data    Source code
       1              : %{
       2              : 
       3              : /*#define YYDEBUG 1*/
       4              : /*-------------------------------------------------------------------------
       5              :  *
       6              :  * gram.y
       7              :  *    POSTGRESQL BISON rules/actions
       8              :  *
       9              :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
      10              :  * Portions Copyright (c) 1994, Regents of the University of California
      11              :  *
      12              :  *
      13              :  * IDENTIFICATION
      14              :  *    src/backend/parser/gram.y
      15              :  *
      16              :  * HISTORY
      17              :  *    AUTHOR            DATE            MAJOR EVENT
      18              :  *    Andrew Yu         Sept, 1994      POSTQUEL to SQL conversion
      19              :  *    Andrew Yu         Oct, 1994       lispy code conversion
      20              :  *
      21              :  * NOTES
      22              :  *    CAPITALS are used to represent terminal symbols.
      23              :  *    non-capitals are used to represent non-terminals.
      24              :  *
      25              :  *    In general, nothing in this file should initiate database accesses
      26              :  *    nor depend on changeable state (such as SET variables).  If you do
      27              :  *    database accesses, your code will fail when we have aborted the
      28              :  *    current transaction and are just parsing commands to find the next
      29              :  *    ROLLBACK or COMMIT.  If you make use of SET variables, then you
      30              :  *    will do the wrong thing in multi-query strings like this:
      31              :  *          SET constraint_exclusion TO off; SELECT * FROM foo;
      32              :  *    because the entire string is parsed by gram.y before the SET gets
      33              :  *    executed.  Anything that depends on the database or changeable state
      34              :  *    should be handled during parse analysis so that it happens at the
      35              :  *    right time not the wrong time.
      36              :  *
      37              :  * WARNINGS
      38              :  *    If you use a list, make sure the datum is a node so that the printing
      39              :  *    routines work.
      40              :  *
      41              :  *    Sometimes we assign constants to makeStrings. Make sure we don't free
      42              :  *    those.
      43              :  *
      44              :  *-------------------------------------------------------------------------
      45              :  */
      46              : #include "postgres.h"
      47              : 
      48              : #include <ctype.h>
      49              : #include <limits.h>
      50              : 
      51              : #include "catalog/index.h"
      52              : #include "catalog/namespace.h"
      53              : #include "catalog/pg_am.h"
      54              : #include "catalog/pg_trigger.h"
      55              : #include "commands/defrem.h"
      56              : #include "commands/trigger.h"
      57              : #include "gramparse.h"
      58              : #include "nodes/makefuncs.h"
      59              : #include "nodes/nodeFuncs.h"
      60              : #include "parser/parser.h"
      61              : #include "utils/datetime.h"
      62              : #include "utils/xml.h"
      63              : 
      64              : 
      65              : /*
      66              :  * Location tracking support.  Unlike bison's default, we only want
      67              :  * to track the start position not the end position of each nonterminal.
      68              :  * Nonterminals that reduce to empty receive position "-1".  Since a
      69              :  * production's leading RHS nonterminal(s) may have reduced to empty,
      70              :  * we have to scan to find the first one that's not -1.
      71              :  */
      72              : #define YYLLOC_DEFAULT(Current, Rhs, N) \
      73              :     do { \
      74              :         (Current) = (-1); \
      75              :         for (int _i = 1; _i <= (N); _i++) \
      76              :         { \
      77              :             if ((Rhs)[_i] >= 0) \
      78              :             { \
      79              :                 (Current) = (Rhs)[_i]; \
      80              :                 break; \
      81              :             } \
      82              :         } \
      83              :     } while (0)
      84              : 
      85              : /*
      86              :  * Bison doesn't allocate anything that needs to live across parser calls,
      87              :  * so we can easily have it use palloc instead of malloc.  This prevents
      88              :  * memory leaks if we error out during parsing.
      89              :  */
      90              : #define YYMALLOC palloc
      91              : #define YYFREE   pfree
      92              : 
      93              : /* Private struct for the result of privilege_target production */
      94              : typedef struct PrivTarget
      95              : {
      96              :     GrantTargetType targtype;
      97              :     ObjectType  objtype;
      98              :     List       *objs;
      99              : } PrivTarget;
     100              : 
     101              : /* Private struct for the result of import_qualification production */
     102              : typedef struct ImportQual
     103              : {
     104              :     ImportForeignSchemaType type;
     105              :     List       *table_names;
     106              : } ImportQual;
     107              : 
     108              : /* Private struct for the result of select_limit & limit_clause productions */
     109              : typedef struct SelectLimit
     110              : {
     111              :     Node       *limitOffset;
     112              :     Node       *limitCount;
     113              :     LimitOption limitOption;    /* indicates presence of WITH TIES */
     114              :     ParseLoc    offsetLoc;      /* location of OFFSET token, if present */
     115              :     ParseLoc    countLoc;       /* location of LIMIT/FETCH token, if present */
     116              :     ParseLoc    optionLoc;      /* location of WITH TIES, if present */
     117              : } SelectLimit;
     118              : 
     119              : /* Private struct for the result of group_clause production */
     120              : typedef struct GroupClause
     121              : {
     122              :     bool        distinct;
     123              :     bool        all;
     124              :     List       *list;
     125              : } GroupClause;
     126              : 
     127              : /* Private structs for the result of key_actions and key_action productions */
     128              : typedef struct KeyAction
     129              : {
     130              :     char        action;
     131              :     List       *cols;
     132              : } KeyAction;
     133              : 
     134              : typedef struct KeyActions
     135              : {
     136              :     KeyAction *updateAction;
     137              :     KeyAction *deleteAction;
     138              : } KeyActions;
     139              : 
     140              : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
     141              : #define CAS_NOT_DEFERRABLE          0x01
     142              : #define CAS_DEFERRABLE              0x02
     143              : #define CAS_INITIALLY_IMMEDIATE     0x04
     144              : #define CAS_INITIALLY_DEFERRED      0x08
     145              : #define CAS_NOT_VALID               0x10
     146              : #define CAS_NO_INHERIT              0x20
     147              : #define CAS_NOT_ENFORCED            0x40
     148              : #define CAS_ENFORCED                0x80
     149              : 
     150              : 
     151              : #define parser_yyerror(msg)  scanner_yyerror(msg, yyscanner)
     152              : #define parser_errposition(pos)  scanner_errposition(pos, yyscanner)
     153              : 
     154              : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
     155              :                          const char *msg);
     156              : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
     157              : static void updateRawStmtEnd(RawStmt *rs, int end_location);
     158              : static Node *makeColumnRef(char *colname, List *indirection,
     159              :                            int location, core_yyscan_t yyscanner);
     160              : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     161              : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     162              : static Node *makeIntConst(int val, int location);
     163              : static Node *makeFloatConst(char *str, int location);
     164              : static Node *makeBoolAConst(bool state, int location);
     165              : static Node *makeBitStringConst(char *str, int location);
     166              : static Node *makeNullAConst(int location);
     167              : static Node *makeAConst(Node *v, int location);
     168              : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     169              : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     170              : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     171              : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     172              : static List *extractArgTypes(List *parameters);
     173              : static List *extractAggrArgTypes(List *aggrargs);
     174              : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     175              :                                 core_yyscan_t yyscanner);
     176              : static void insertSelectOptions(SelectStmt *stmt,
     177              :                                 List *sortClause, List *lockingClause,
     178              :                                 SelectLimit *limitClause,
     179              :                                 WithClause *withClause,
     180              :                                 core_yyscan_t yyscanner);
     181              : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     182              : static Node *doNegate(Node *n, int location);
     183              : static void doNegateFloat(Float *v);
     184              : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     185              : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     186              : static Node *makeNotExpr(Node *expr, int location);
     187              : static Node *makeAArrayExpr(List *elements, int location, int end_location);
     188              : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     189              :                                   int location);
     190              : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     191              :                          List *args, int location);
     192              : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
     193              : static TypeName *TableFuncTypeName(List *columns);
     194              : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     195              : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     196              :                                                core_yyscan_t yyscanner);
     197              : static void SplitColQualList(List *qualList,
     198              :                              List **constraintList, CollateClause **collClause,
     199              :                              core_yyscan_t yyscanner);
     200              : static void processCASbits(int cas_bits, int location, const char *constrType,
     201              :                bool *deferrable, bool *initdeferred, bool *is_enforced,
     202              :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
     203              : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
     204              :                                                 core_yyscan_t yyscanner);
     205              : static void preprocess_pub_all_objtype_list(List *all_objects_list,
     206              :                                             bool *all_tables,
     207              :                                             bool *all_sequences,
     208              :                                             core_yyscan_t yyscanner);
     209              : static void preprocess_pubobj_list(List *pubobjspec_list,
     210              :                                    core_yyscan_t yyscanner);
     211              : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     212              : 
     213              : %}
     214              : 
     215              : %pure-parser
     216              : %expect 0
     217              : %name-prefix="base_yy"
     218              : %locations
     219              : 
     220              : %parse-param {core_yyscan_t yyscanner}
     221              : %lex-param   {core_yyscan_t yyscanner}
     222              : 
     223              : %union
     224              : {
     225              :     core_YYSTYPE core_yystype;
     226              :     /* these fields must match core_YYSTYPE: */
     227              :     int         ival;
     228              :     char       *str;
     229              :     const char *keyword;
     230              : 
     231              :     char        chr;
     232              :     bool        boolean;
     233              :     JoinType    jtype;
     234              :     DropBehavior dbehavior;
     235              :     OnCommitAction oncommit;
     236              :     List       *list;
     237              :     Node       *node;
     238              :     ObjectType  objtype;
     239              :     TypeName   *typnam;
     240              :     FunctionParameter *fun_param;
     241              :     FunctionParameterMode fun_param_mode;
     242              :     ObjectWithArgs *objwithargs;
     243              :     DefElem    *defelt;
     244              :     SortBy     *sortby;
     245              :     WindowDef  *windef;
     246              :     JoinExpr   *jexpr;
     247              :     IndexElem  *ielem;
     248              :     StatsElem  *selem;
     249              :     Alias      *alias;
     250              :     RangeVar   *range;
     251              :     IntoClause *into;
     252              :     WithClause *with;
     253              :     InferClause *infer;
     254              :     OnConflictClause *onconflict;
     255              :     A_Indices  *aind;
     256              :     ResTarget  *target;
     257              :     struct PrivTarget *privtarget;
     258              :     AccessPriv *accesspriv;
     259              :     struct ImportQual *importqual;
     260              :     InsertStmt *istmt;
     261              :     VariableSetStmt *vsetstmt;
     262              :     PartitionElem *partelem;
     263              :     PartitionSpec *partspec;
     264              :     PartitionBoundSpec *partboundspec;
     265              :     SinglePartitionSpec *singlepartspec;
     266              :     RoleSpec   *rolespec;
     267              :     PublicationObjSpec *publicationobjectspec;
     268              :     PublicationAllObjSpec *publicationallobjectspec;
     269              :     struct SelectLimit *selectlimit;
     270              :     SetQuantifier setquantifier;
     271              :     struct GroupClause *groupclause;
     272              :     MergeMatchKind mergematch;
     273              :     MergeWhenClause *mergewhen;
     274              :     struct KeyActions *keyactions;
     275              :     struct KeyAction *keyaction;
     276              :     ReturningClause *retclause;
     277              :     ReturningOptionKind retoptionkind;
     278              : }
     279              : 
     280              : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     281              :         AlterEventTrigStmt AlterCollationStmt
     282              :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     283              :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     284              :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     285              :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     286              :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     287              :         AlterCompositeTypeStmt AlterUserMappingStmt
     288              :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     289              :         AlterDefaultPrivilegesStmt DefACLAction
     290              :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     291              :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     292              :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     293              :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     294              :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     295              :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     296              :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     297              :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     298              :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     299              :         DropOpClassStmt DropOpFamilyStmt DropStmt
     300              :         DropCastStmt DropRoleStmt
     301              :         DropdbStmt DropTableSpaceStmt
     302              :         DropTransformStmt
     303              :         DropUserMappingStmt ExplainStmt FetchStmt
     304              :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     305              :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     306              :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     307              :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     308              :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     309              :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     310              :         UnlistenStmt UpdateStmt VacuumStmt
     311              :         VariableResetStmt VariableSetStmt VariableShowStmt
     312              :         ViewStmt WaitStmt CheckPointStmt CreateConversionStmt
     313              :         DeallocateStmt PrepareStmt ExecuteStmt
     314              :         DropOwnedStmt ReassignOwnedStmt
     315              :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     316              :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     317              :         CreatePublicationStmt AlterPublicationStmt
     318              :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     319              : 
     320              : %type <node>  select_no_parens select_with_parens select_clause
     321              :                 simple_select values_clause
     322              :                 PLpgSQL_Expr PLAssignStmt
     323              : 
     324              : %type <str>           opt_single_name
     325              : %type <list>      opt_qualified_name
     326              : %type <boolean>       opt_concurrently
     327              : %type <dbehavior> opt_drop_behavior
     328              : %type <list>      opt_utility_option_list
     329              : %type <list>      opt_wait_with_clause
     330              : %type <list>      utility_option_list
     331              : %type <defelt>        utility_option_elem
     332              : %type <str>           utility_option_name
     333              : %type <node>      utility_option_arg
     334              : 
     335              : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     336              : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     337              : 
     338              : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     339              :        replica_identity partition_cmd index_partition_cmd
     340              : %type <list>  alter_table_cmds alter_type_cmds
     341              : %type <list>    alter_identity_column_option_list
     342              : %type <defelt>  alter_identity_column_option
     343              : %type <node>  set_statistics_value
     344              : %type <str>       set_access_method_name
     345              : 
     346              : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     347              :                 transaction_mode_list
     348              :                 create_extension_opt_list alter_extension_opt_list
     349              : %type <defelt>    createdb_opt_item copy_opt_item
     350              :                 transaction_mode_item
     351              :                 create_extension_opt_item alter_extension_opt_item
     352              : 
     353              : %type <ival>  opt_lock lock_type cast_context
     354              : %type <defelt>    drop_option
     355              : %type <boolean>   opt_or_replace opt_no
     356              :                 opt_grant_grant_option
     357              :                 opt_nowait opt_if_exists opt_with_data
     358              :                 opt_transaction_chain
     359              : %type <list>  grant_role_opt_list
     360              : %type <defelt>    grant_role_opt
     361              : %type <node>  grant_role_opt_value
     362              : %type <ival>  opt_nowait_or_skip
     363              : 
     364              : %type <list>  OptRoleList AlterOptRoleList
     365              : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     366              : 
     367              : %type <str>       opt_type
     368              : %type <str>       foreign_server_version opt_foreign_server_version
     369              : %type <str>       opt_in_database
     370              : 
     371              : %type <str>       parameter_name
     372              : %type <list>  OptSchemaEltList parameter_name_list
     373              : 
     374              : %type <chr>       am_type
     375              : 
     376              : %type <boolean> TriggerForSpec TriggerForType
     377              : %type <ival>  TriggerActionTime
     378              : %type <list>  TriggerEvents TriggerOneEvent
     379              : %type <node>  TriggerFuncArg
     380              : %type <node>  TriggerWhen
     381              : %type <str>       TransitionRelName
     382              : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     383              : %type <node>  TriggerTransition
     384              : 
     385              : %type <list>  event_trigger_when_list event_trigger_value_list
     386              : %type <defelt>    event_trigger_when_item
     387              : %type <chr>       enable_trigger
     388              : 
     389              : %type <str>       copy_file_name
     390              :                 access_method_clause attr_name
     391              :                 table_access_method_clause name cursor_name file_name
     392              :                 cluster_index_specification
     393              : 
     394              : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     395              :                 opt_inline_handler opt_validator validator_clause
     396              :                 opt_collate
     397              : 
     398              : %type <range> qualified_name insert_target OptConstrFromTable
     399              : 
     400              : %type <str>       all_Op MathOp
     401              : 
     402              : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     403              : %type <boolean> RowSecurityDefaultPermissive
     404              : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     405              : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     406              : 
     407              : %type <str>       iso_level opt_encoding
     408              : %type <rolespec> grantee
     409              : %type <list>  grantee_list
     410              : %type <accesspriv> privilege
     411              : %type <list>  privileges privilege_list
     412              : %type <privtarget> privilege_target
     413              : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     414              : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     415              : %type <ival>  defacl_privilege_target
     416              : %type <defelt>    DefACLOption
     417              : %type <list>  DefACLOptionList
     418              : %type <ival>  import_qualification_type
     419              : %type <importqual> import_qualification
     420              : %type <node>  vacuum_relation
     421              : %type <selectlimit> opt_select_limit select_limit limit_clause
     422              : 
     423              : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     424              :                 OptTableElementList TableElementList OptInherit definition
     425              :                 OptTypedTableElementList TypedTableElementList
     426              :                 reloptions opt_reloptions
     427              :                 OptWith opt_definition func_args func_args_list
     428              :                 func_args_with_defaults func_args_with_defaults_list
     429              :                 aggr_args aggr_args_list
     430              :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     431              :                 old_aggr_definition old_aggr_list
     432              :                 oper_argtypes RuleActionList RuleActionMulti
     433              :                 opt_column_list columnList opt_name_list
     434              :                 sort_clause opt_sort_clause sortby_list index_params
     435              :                 stats_params
     436              :                 opt_include opt_c_include index_including_params
     437              :                 name_list role_list from_clause from_list opt_array_bounds
     438              :                 qualified_name_list any_name any_name_list type_name_list
     439              :                 any_operator expr_list attrs
     440              :                 distinct_clause opt_distinct_clause
     441              :                 target_list opt_target_list insert_column_list set_target_list
     442              :                 merge_values_clause
     443              :                 set_clause_list set_clause
     444              :                 def_list operator_def_list indirection opt_indirection
     445              :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     446              :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     447              :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     448              :                 prep_type_clause
     449              :                 execute_param_clause using_clause
     450              :                 returning_with_clause returning_options
     451              :                 opt_enum_val_list enum_val_list table_func_column_list
     452              :                 create_generic_options alter_generic_options
     453              :                 relation_expr_list dostmt_opt_list
     454              :                 transform_element_list transform_type_list
     455              :                 TriggerTransitions TriggerReferencing
     456              :                 vacuum_relation_list opt_vacuum_relation_list
     457              :                 drop_option_list pub_obj_list pub_all_obj_type_list
     458              : 
     459              : %type <retclause> returning_clause
     460              : %type <node>  returning_option
     461              : %type <retoptionkind> returning_option_kind
     462              : %type <node>  opt_routine_body
     463              : %type <groupclause> group_clause
     464              : %type <list>  group_by_list
     465              : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     466              : %type <node>  grouping_sets_clause
     467              : 
     468              : %type <list>  opt_fdw_options fdw_options
     469              : %type <defelt>    fdw_option
     470              : 
     471              : %type <range> OptTempTableName
     472              : %type <into>  into_clause create_as_target create_mv_target
     473              : 
     474              : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     475              : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     476              : %type <fun_param_mode> arg_class
     477              : %type <typnam>    func_return func_type
     478              : 
     479              : %type <boolean>  opt_trusted opt_restart_seqs
     480              : %type <ival>   OptTemp
     481              : %type <ival>   OptNoLog
     482              : %type <oncommit> OnCommitOption
     483              : 
     484              : %type <ival>  for_locking_strength opt_for_locking_strength
     485              : %type <node>  for_locking_item
     486              : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     487              : %type <list>  locked_rels_list
     488              : %type <setquantifier> set_quantifier
     489              : 
     490              : %type <node>  join_qual
     491              : %type <jtype> join_type
     492              : 
     493              : %type <list>  extract_list overlay_list position_list
     494              : %type <list>  substr_list trim_list
     495              : %type <list>  opt_interval interval_second
     496              : %type <str>       unicode_normal_form
     497              : 
     498              : %type <boolean> opt_instead
     499              : %type <boolean> opt_unique opt_verbose opt_full
     500              : %type <boolean> opt_freeze opt_analyze opt_default
     501              : %type <defelt>    opt_binary copy_delimiter
     502              : 
     503              : %type <boolean> copy_from opt_program
     504              : 
     505              : %type <ival>  event cursor_options opt_hold opt_set_data
     506              : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     507              :                 drop_type_name
     508              : 
     509              : %type <node>  fetch_args select_limit_value
     510              :                 offset_clause select_offset_value
     511              :                 select_fetch_first_value I_or_F_const
     512              : %type <ival>  row_or_rows first_or_next
     513              : 
     514              : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     515              : %type <defelt>    SeqOptElem
     516              : 
     517              : %type <istmt> insert_rest
     518              : %type <infer> opt_conf_expr
     519              : %type <onconflict> opt_on_conflict
     520              : %type <mergewhen> merge_insert merge_update merge_delete
     521              : 
     522              : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
     523              : %type <node>  merge_when_clause opt_merge_when_condition
     524              : %type <list>  merge_when_list
     525              : 
     526              : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     527              :                  SetResetClause FunctionSetResetClause
     528              : 
     529              : %type <node>  TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
     530              : %type <node>  columnDef columnOptions optionalPeriodName
     531              : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     532              : %type <node>  def_arg columnElem where_clause where_or_current_clause
     533              :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     534              :                 columnref having_clause func_table xmltable array_expr
     535              :                 OptWhereClause operator_def_arg
     536              : %type <list>  opt_column_and_period_list
     537              : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     538              : %type <boolean> opt_ordinality opt_without_overlaps
     539              : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     540              : %type <list>  func_arg_list func_arg_list_opt
     541              : %type <node>  func_arg_expr
     542              : %type <list>  row explicit_row implicit_row type_list array_expr_list
     543              : %type <node>  case_expr case_arg when_clause case_default
     544              : %type <list>  when_clause_list
     545              : %type <node>  opt_search_clause opt_cycle_clause
     546              : %type <ival>  sub_type opt_materialized
     547              : %type <node>  NumericOnly
     548              : %type <list>  NumericOnly_list
     549              : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     550              : %type <list>  func_alias_clause
     551              : %type <sortby>    sortby
     552              : %type <ielem> index_elem index_elem_options
     553              : %type <selem> stats_param
     554              : %type <node>  table_ref
     555              : %type <jexpr> joined_table
     556              : %type <range> relation_expr
     557              : %type <range> extended_relation_expr
     558              : %type <range> relation_expr_opt_alias
     559              : %type <node>  tablesample_clause opt_repeatable_clause
     560              : %type <target>    target_el set_target insert_column_item
     561              : 
     562              : %type <str>       generic_option_name
     563              : %type <node>  generic_option_arg
     564              : %type <defelt>    generic_option_elem alter_generic_option_elem
     565              : %type <list>  generic_option_list alter_generic_option_list
     566              : 
     567              : %type <ival>  reindex_target_relation reindex_target_all
     568              : 
     569              : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     570              : %type <defelt>    copy_generic_opt_elem
     571              : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     572              : %type <list>  copy_options
     573              : 
     574              : %type <typnam>    Typename SimpleTypename ConstTypename
     575              :                 GenericType Numeric opt_float JsonType
     576              :                 Character ConstCharacter
     577              :                 CharacterWithLength CharacterWithoutLength
     578              :                 ConstDatetime ConstInterval
     579              :                 Bit ConstBit BitWithLength BitWithoutLength
     580              : %type <str>       character
     581              : %type <str>       extract_arg
     582              : %type <boolean> opt_varying opt_timezone opt_no_inherit
     583              : 
     584              : %type <ival>  Iconst SignedIconst
     585              : %type <str>       Sconst comment_text notify_payload
     586              : %type <str>       RoleId opt_boolean_or_string
     587              : %type <list>  var_list
     588              : %type <str>       ColId ColLabel BareColLabel
     589              : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     590              : %type <str>       var_name type_function_name param_name
     591              : %type <str>       createdb_opt_name plassign_target
     592              : %type <node>  var_value zone_value
     593              : %type <rolespec> auth_ident RoleSpec opt_granted_by
     594              : %type <publicationobjectspec> PublicationObjSpec
     595              : %type <publicationallobjectspec> PublicationAllObjSpec
     596              : 
     597              : %type <keyword> unreserved_keyword type_func_name_keyword
     598              : %type <keyword> col_name_keyword reserved_keyword
     599              : %type <keyword> bare_label_keyword
     600              : 
     601              : %type <node>  DomainConstraint TableConstraint TableLikeClause
     602              : %type <ival>  TableLikeOptionList TableLikeOption
     603              : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     604              : %type <list>  ColQualList
     605              : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     606              : %type <ival>  key_match
     607              : %type <keyaction> key_delete key_update key_action
     608              : %type <keyactions> key_actions
     609              : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     610              : %type <str>       ExistingIndex
     611              : 
     612              : %type <list>  constraints_set_list
     613              : %type <boolean> constraints_set_mode
     614              : %type <str>       OptTableSpace OptConsTableSpace
     615              : %type <rolespec> OptTableSpaceOwner
     616              : %type <ival>  opt_check_option
     617              : 
     618              : %type <str>       opt_provider security_label
     619              : 
     620              : %type <target>    xml_attribute_el
     621              : %type <list>  xml_attribute_list xml_attributes
     622              : %type <node>  xml_root_version opt_xml_root_standalone
     623              : %type <node>  xmlexists_argument
     624              : %type <ival>  document_or_content
     625              : %type <boolean>   xml_indent_option xml_whitespace_option
     626              : %type <list>  xmltable_column_list xmltable_column_option_list
     627              : %type <node>  xmltable_column_el
     628              : %type <defelt>    xmltable_column_option_el
     629              : %type <list>  xml_namespace_list
     630              : %type <target>    xml_namespace_el
     631              : 
     632              : %type <node>  func_application func_expr_common_subexpr
     633              : %type <node>  func_expr func_expr_windowless
     634              : %type <node>  common_table_expr
     635              : %type <with>  with_clause opt_with_clause
     636              : %type <list>  cte_list
     637              : 
     638              : %type <list>  within_group_clause
     639              : %type <node>  filter_clause
     640              : %type <list>  window_clause window_definition_list opt_partition_clause
     641              : %type <windef>    window_definition over_clause window_specification
     642              :                 opt_frame_clause frame_extent frame_bound
     643              : %type <ival>  null_treatment opt_window_exclusion_clause
     644              : %type <str>       opt_existing_window_name
     645              : %type <boolean> opt_if_not_exists
     646              : %type <boolean> opt_unique_null_treatment
     647              : %type <ival>  generated_when override_kind opt_virtual_or_stored
     648              : %type <partspec>  PartitionSpec OptPartitionSpec
     649              : %type <partelem>  part_elem
     650              : %type <list>      part_params
     651              : %type <partboundspec> PartitionBoundSpec
     652              : %type <singlepartspec>    SinglePartitionSpec
     653              : %type <list>      partitions_list
     654              : %type <list>      hash_partbound
     655              : %type <defelt>        hash_partbound_elem
     656              : 
     657              : %type <node>  json_format_clause
     658              :                 json_format_clause_opt
     659              :                 json_value_expr
     660              :                 json_returning_clause_opt
     661              :                 json_name_and_value
     662              :                 json_aggregate_func
     663              :                 json_argument
     664              :                 json_behavior
     665              :                 json_on_error_clause_opt
     666              :                 json_table
     667              :                 json_table_column_definition
     668              :                 json_table_column_path_clause_opt
     669              : %type <list>  json_name_and_value_list
     670              :                 json_value_expr_list
     671              :                 json_array_aggregate_order_by_clause_opt
     672              :                 json_arguments
     673              :                 json_behavior_clause_opt
     674              :                 json_passing_clause_opt
     675              :                 json_table_column_definition_list
     676              : %type <str>       json_table_path_name_opt
     677              : %type <ival>  json_behavior_type
     678              :                 json_predicate_type_constraint
     679              :                 json_quotes_clause_opt
     680              :                 json_wrapper_behavior
     681              : %type <boolean>   json_key_uniqueness_constraint_opt
     682              :                 json_object_constructor_null_clause_opt
     683              :                 json_array_constructor_null_clause_opt
     684              : 
     685              : /*
     686              :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     687              :  * They must be listed first so that their numeric codes do not depend on
     688              :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     689              :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     690              :  *
     691              :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     692              :  * they need no productions here; but we must assign token codes to them.
     693              :  *
     694              :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     695              :  * parse errors.  It is needed by PL/pgSQL.
     696              :  */
     697              : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     698              : %token <ival> ICONST PARAM
     699              : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     700              : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     701              : 
     702              : /*
     703              :  * If you want to make any keyword changes, update the keyword table in
     704              :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     705              :  * of the reserved-or-not-so-reserved keyword lists, below; search
     706              :  * this file for "Keyword category lists".
     707              :  */
     708              : 
     709              : /* ordinary key words in alphabetical order */
     710              : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     711              :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     712              :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     713              : 
     714              :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     715              :     BOOLEAN_P BOTH BREADTH BY
     716              : 
     717              :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     718              :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     719              :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     720              :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     721              :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     722              :     COST CREATE CROSS CSV CUBE CURRENT_P
     723              :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     724              :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     725              : 
     726              :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     727              :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     728              :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     729              :     DOUBLE_P DROP
     730              : 
     731              :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
     732              :     ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
     733              :     EXPRESSION EXTENSION EXTERNAL EXTRACT
     734              : 
     735              :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     736              :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     737              : 
     738              :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     739              : 
     740              :     HANDLER HAVING HEADER_P HOLD HOUR_P
     741              : 
     742              :     IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     743              :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     744              :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     745              :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     746              : 
     747              :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     748              :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
     749              : 
     750              :     KEEP KEY KEYS
     751              : 
     752              :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     753              :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     754              :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED LSN_P
     755              : 
     756              :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     757              :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     758              : 
     759              :     NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
     760              :     NONE NORMALIZE NORMALIZED
     761              :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     762              :     NULLS_P NUMERIC
     763              : 
     764              :     OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     765              :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     766              :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     767              : 
     768              :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PARTITIONS PASSING PASSWORD PATH
     769              :     PERIOD PLACING PLAN PLANS POLICY
     770              :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     771              :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     772              : 
     773              :     QUOTE QUOTES
     774              : 
     775              :     RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
     776              :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     777              :     RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     778              :     ROUTINE ROUTINES ROW ROWS RULE
     779              : 
     780              :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     781              :     SEQUENCE SEQUENCES
     782              :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     783              :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SPLIT SOURCE SQL_P STABLE STANDALONE_P
     784              :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     785              :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     786              : 
     787              :     TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
     788              :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     789              :     TREAT TRIGGER TRIM TRUE_P
     790              :     TRUNCATE TRUSTED TYPE_P TYPES_P
     791              : 
     792              :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     793              :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     794              : 
     795              :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     796              :     VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
     797              : 
     798              :     WAIT WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     799              : 
     800              :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     801              :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     802              : 
     803              :     YEAR_P YES_P
     804              : 
     805              :     ZONE
     806              : 
     807              : /*
     808              :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     809              :  * list and so can never be entered directly.  The filter in parser.c
     810              :  * creates these tokens when required (based on looking one token ahead).
     811              :  *
     812              :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     813              :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     814              :  * as NOT, at least with respect to their left-hand subexpression.
     815              :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     816              :  * LALR(1).
     817              :  */
     818              : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     819              : 
     820              : /*
     821              :  * The grammar likewise thinks these tokens are keywords, but they are never
     822              :  * generated by the scanner.  Rather, they can be injected by parser.c as
     823              :  * the initial token of the string (using the lookahead-token mechanism
     824              :  * implemented there).  This provides a way to tell the grammar to parse
     825              :  * something other than the usual list of SQL commands.
     826              :  */
     827              : %token      MODE_TYPE_NAME
     828              : %token      MODE_PLPGSQL_EXPR
     829              : %token      MODE_PLPGSQL_ASSIGN1
     830              : %token      MODE_PLPGSQL_ASSIGN2
     831              : %token      MODE_PLPGSQL_ASSIGN3
     832              : 
     833              : 
     834              : /* Precedence: lowest to highest */
     835              : %left       UNION EXCEPT
     836              : %left       INTERSECT
     837              : %left       OR
     838              : %left       AND
     839              : %right      NOT
     840              : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     841              : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     842              : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     843              : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     844              : 
     845              : /*
     846              :  * Sometimes it is necessary to assign precedence to keywords that are not
     847              :  * really part of the operator hierarchy, in order to resolve grammar
     848              :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     849              :  * assignments have global effect and may hide ambiguities besides the one
     850              :  * you intended to solve.  (Attaching a precedence to a single rule with
     851              :  * %prec is far safer and should be preferred.)  If you must give precedence
     852              :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     853              :  * If the keyword has IDENT's precedence then it clearly acts the same as
     854              :  * non-keywords and other similar keywords, thus reducing the risk of
     855              :  * unexpected precedence effects.
     856              :  *
     857              :  * We used to need to assign IDENT an explicit precedence just less than Op,
     858              :  * to support target_el without AS.  While that's not really necessary since
     859              :  * we removed postfix operators, we continue to do so because it provides a
     860              :  * reference point for a precedence level that we can assign to other
     861              :  * keywords that lack a natural precedence level.
     862              :  *
     863              :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     864              :  * opt_existing_window_name (see comment there).
     865              :  *
     866              :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     867              :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     868              :  * there is no principled way to distinguish these from the productions
     869              :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     870              :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     871              :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     872              :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     873              :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     874              :  *
     875              :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     876              :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     877              :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     878              :  * Using the same precedence as IDENT seems right for the reasons given above.
     879              :  *
     880              :  * SET is likewise assigned the same precedence as IDENT, to support the
     881              :  * relation_expr_opt_alias production (see comment there).
     882              :  *
     883              :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     884              :  * the same precedence as IDENT.  This allows resolving conflicts in the
     885              :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     886              :  * productions (see comments there).
     887              :  *
     888              :  * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
     889              :  * precedence than PATH to fix ambiguity in the json_table production.
     890              :  */
     891              : %nonassoc   UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
     892              : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     893              :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
     894              : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     895              : %left       '+' '-'
     896              : %left       '*' '/' '%'
     897              : %left       '^'
     898              : /* Unary Operators */
     899              : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     900              : %left       COLLATE
     901              : %right      UMINUS
     902              : %left       '[' ']'
     903              : %left       '(' ')'
     904              : %left       TYPECAST
     905              : %left       '.'
     906              : /*
     907              :  * These might seem to be low-precedence, but actually they are not part
     908              :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     909              :  * We make them high-precedence to support their use as function names.
     910              :  * They wouldn't be given a precedence at all, were it not that we need
     911              :  * left-associativity among the JOIN rules themselves.
     912              :  */
     913              : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     914              : 
     915              : %%
     916              : 
     917              : /*
     918              :  *  The target production for the whole parse.
     919              :  *
     920              :  * Ordinarily we parse a list of statements, but if we see one of the
     921              :  * special MODE_XXX symbols as first token, we parse something else.
     922              :  * The options here correspond to enum RawParseMode, which see for details.
     923              :  */
     924              : parse_toplevel:
     925              :             stmtmulti
     926              :             {
     927       382419 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     928              :                 (void) yynerrs;     /* suppress compiler warning */
     929              :             }
     930              :             | MODE_TYPE_NAME Typename
     931              :             {
     932         5163 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     933              :             }
     934              :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     935              :             {
     936        17273 :                 pg_yyget_extra(yyscanner)->parsetree =
     937        17273 :                     list_make1(makeRawStmt($2, @2));
     938              :             }
     939              :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     940              :             {
     941         3227 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     942              : 
     943         3227 :                 n->nnames = 1;
     944         3227 :                 pg_yyget_extra(yyscanner)->parsetree =
     945         3227 :                     list_make1(makeRawStmt((Node *) n, @2));
     946              :             }
     947              :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     948              :             {
     949          343 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     950              : 
     951          343 :                 n->nnames = 2;
     952          343 :                 pg_yyget_extra(yyscanner)->parsetree =
     953          343 :                     list_make1(makeRawStmt((Node *) n, @2));
     954              :             }
     955              :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     956              :             {
     957           14 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     958              : 
     959           14 :                 n->nnames = 3;
     960           14 :                 pg_yyget_extra(yyscanner)->parsetree =
     961           14 :                     list_make1(makeRawStmt((Node *) n, @2));
     962              :             }
     963              :         ;
     964              : 
     965              : /*
     966              :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     967              :  * and length of the stmt's text.
     968              :  * We also take care to discard empty statements entirely (which among other
     969              :  * things dodges the problem of assigning them a location).
     970              :  */
     971              : stmtmulti:  stmtmulti ';' toplevel_stmt
     972              :                 {
     973       310473 :                     if ($1 != NIL)
     974              :                     {
     975              :                         /* update length of previous stmt */
     976       309920 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     977              :                     }
     978       310473 :                     if ($3 != NULL)
     979        29605 :                         $$ = lappend($1, makeRawStmt($3, @3));
     980              :                     else
     981       280868 :                         $$ = $1;
     982              :                 }
     983              :             | toplevel_stmt
     984              :                 {
     985       382423 :                     if ($1 != NULL)
     986       381473 :                         $$ = list_make1(makeRawStmt($1, @1));
     987              :                     else
     988          950 :                         $$ = NIL;
     989              :                 }
     990              :         ;
     991              : 
     992              : /*
     993              :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     994              :  * those words have different meanings in function bodies.
     995              :  */
     996              : toplevel_stmt:
     997              :             stmt
     998              :             | TransactionStmtLegacy
     999              :         ;
    1000              : 
    1001              : stmt:
    1002              :             AlterEventTrigStmt
    1003              :             | AlterCollationStmt
    1004              :             | AlterDatabaseStmt
    1005              :             | AlterDatabaseSetStmt
    1006              :             | AlterDefaultPrivilegesStmt
    1007              :             | AlterDomainStmt
    1008              :             | AlterEnumStmt
    1009              :             | AlterExtensionStmt
    1010              :             | AlterExtensionContentsStmt
    1011              :             | AlterFdwStmt
    1012              :             | AlterForeignServerStmt
    1013              :             | AlterFunctionStmt
    1014              :             | AlterGroupStmt
    1015              :             | AlterObjectDependsStmt
    1016              :             | AlterObjectSchemaStmt
    1017              :             | AlterOwnerStmt
    1018              :             | AlterOperatorStmt
    1019              :             | AlterTypeStmt
    1020              :             | AlterPolicyStmt
    1021              :             | AlterSeqStmt
    1022              :             | AlterSystemStmt
    1023              :             | AlterTableStmt
    1024              :             | AlterTblSpcStmt
    1025              :             | AlterCompositeTypeStmt
    1026              :             | AlterPublicationStmt
    1027              :             | AlterRoleSetStmt
    1028              :             | AlterRoleStmt
    1029              :             | AlterSubscriptionStmt
    1030              :             | AlterStatsStmt
    1031              :             | AlterTSConfigurationStmt
    1032              :             | AlterTSDictionaryStmt
    1033              :             | AlterUserMappingStmt
    1034              :             | AnalyzeStmt
    1035              :             | CallStmt
    1036              :             | CheckPointStmt
    1037              :             | ClosePortalStmt
    1038              :             | ClusterStmt
    1039              :             | CommentStmt
    1040              :             | ConstraintsSetStmt
    1041              :             | CopyStmt
    1042              :             | CreateAmStmt
    1043              :             | CreateAsStmt
    1044              :             | CreateAssertionStmt
    1045              :             | CreateCastStmt
    1046              :             | CreateConversionStmt
    1047              :             | CreateDomainStmt
    1048              :             | CreateExtensionStmt
    1049              :             | CreateFdwStmt
    1050              :             | CreateForeignServerStmt
    1051              :             | CreateForeignTableStmt
    1052              :             | CreateFunctionStmt
    1053              :             | CreateGroupStmt
    1054              :             | CreateMatViewStmt
    1055              :             | CreateOpClassStmt
    1056              :             | CreateOpFamilyStmt
    1057              :             | CreatePublicationStmt
    1058              :             | AlterOpFamilyStmt
    1059              :             | CreatePolicyStmt
    1060              :             | CreatePLangStmt
    1061              :             | CreateSchemaStmt
    1062              :             | CreateSeqStmt
    1063              :             | CreateStmt
    1064              :             | CreateSubscriptionStmt
    1065              :             | CreateStatsStmt
    1066              :             | CreateTableSpaceStmt
    1067              :             | CreateTransformStmt
    1068              :             | CreateTrigStmt
    1069              :             | CreateEventTrigStmt
    1070              :             | CreateRoleStmt
    1071              :             | CreateUserStmt
    1072              :             | CreateUserMappingStmt
    1073              :             | CreatedbStmt
    1074              :             | DeallocateStmt
    1075              :             | DeclareCursorStmt
    1076              :             | DefineStmt
    1077              :             | DeleteStmt
    1078              :             | DiscardStmt
    1079              :             | DoStmt
    1080              :             | DropCastStmt
    1081              :             | DropOpClassStmt
    1082              :             | DropOpFamilyStmt
    1083              :             | DropOwnedStmt
    1084              :             | DropStmt
    1085              :             | DropSubscriptionStmt
    1086              :             | DropTableSpaceStmt
    1087              :             | DropTransformStmt
    1088              :             | DropRoleStmt
    1089              :             | DropUserMappingStmt
    1090              :             | DropdbStmt
    1091              :             | ExecuteStmt
    1092              :             | ExplainStmt
    1093              :             | FetchStmt
    1094              :             | GrantStmt
    1095              :             | GrantRoleStmt
    1096              :             | ImportForeignSchemaStmt
    1097              :             | IndexStmt
    1098              :             | InsertStmt
    1099              :             | ListenStmt
    1100              :             | RefreshMatViewStmt
    1101              :             | LoadStmt
    1102              :             | LockStmt
    1103              :             | MergeStmt
    1104              :             | NotifyStmt
    1105              :             | PrepareStmt
    1106              :             | ReassignOwnedStmt
    1107              :             | ReindexStmt
    1108              :             | RemoveAggrStmt
    1109              :             | RemoveFuncStmt
    1110              :             | RemoveOperStmt
    1111              :             | RenameStmt
    1112              :             | RevokeStmt
    1113              :             | RevokeRoleStmt
    1114              :             | RuleStmt
    1115              :             | SecLabelStmt
    1116              :             | SelectStmt
    1117              :             | TransactionStmt
    1118              :             | TruncateStmt
    1119              :             | UnlistenStmt
    1120              :             | UpdateStmt
    1121              :             | VacuumStmt
    1122              :             | VariableResetStmt
    1123              :             | VariableSetStmt
    1124              :             | VariableShowStmt
    1125              :             | ViewStmt
    1126              :             | WaitStmt
    1127              :             | /*EMPTY*/
    1128       281827 :                 { $$ = NULL; }
    1129              :         ;
    1130              : 
    1131              : /*
    1132              :  * Generic supporting productions for DDL
    1133              :  */
    1134              : opt_single_name:
    1135         2736 :             ColId                           { $$ = $1; }
    1136          797 :             | /* EMPTY */                   { $$ = NULL; }
    1137              :         ;
    1138              : 
    1139              : opt_qualified_name:
    1140         1039 :             any_name                        { $$ = $1; }
    1141         8238 :             | /*EMPTY*/                     { $$ = NIL; }
    1142              :         ;
    1143              : 
    1144              : opt_concurrently:
    1145          525 :             CONCURRENTLY                    { $$ = true; }
    1146         3899 :             | /*EMPTY*/                     { $$ = false; }
    1147              :         ;
    1148              : 
    1149              : opt_drop_behavior:
    1150         1038 :             CASCADE                         { $$ = DROP_CASCADE; }
    1151           85 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1152        20372 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1153              :         ;
    1154              : 
    1155              : opt_utility_option_list:
    1156          183 :             '(' utility_option_list ')'     { $$ = $2; }
    1157         2940 :             | /* EMPTY */                   { $$ = NULL; }
    1158              :         ;
    1159              : 
    1160              : utility_option_list:
    1161              :             utility_option_elem
    1162              :                 {
    1163        11969 :                     $$ = list_make1($1);
    1164              :                 }
    1165              :             | utility_option_list ',' utility_option_elem
    1166              :                 {
    1167         6946 :                     $$ = lappend($1, $3);
    1168              :                 }
    1169              :         ;
    1170              : 
    1171              : utility_option_elem:
    1172              :             utility_option_name utility_option_arg
    1173              :                 {
    1174        18915 :                     $$ = makeDefElem($1, $2, @1);
    1175              :                 }
    1176              :         ;
    1177              : 
    1178              : utility_option_name:
    1179        16879 :             NonReservedWord                 { $$ = $1; }
    1180         1965 :             | analyze_keyword               { $$ = "analyze"; }
    1181           74 :             | FORMAT_LA                     { $$ = "format"; }
    1182              :         ;
    1183              : 
    1184              : utility_option_arg:
    1185         9344 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    1186          192 :             | NumericOnly                   { $$ = (Node *) $1; }
    1187         9379 :             | /* EMPTY */                   { $$ = NULL; }
    1188              :         ;
    1189              : 
    1190              : /*****************************************************************************
    1191              :  *
    1192              :  * CALL statement
    1193              :  *
    1194              :  *****************************************************************************/
    1195              : 
    1196              : CallStmt:   CALL func_application
    1197              :                 {
    1198          314 :                     CallStmt   *n = makeNode(CallStmt);
    1199              : 
    1200          314 :                     n->funccall = castNode(FuncCall, $2);
    1201          314 :                     $$ = (Node *) n;
    1202              :                 }
    1203              :         ;
    1204              : 
    1205              : /*****************************************************************************
    1206              :  *
    1207              :  * Create a new Postgres DBMS role
    1208              :  *
    1209              :  *****************************************************************************/
    1210              : 
    1211              : CreateRoleStmt:
    1212              :             CREATE ROLE RoleId opt_with OptRoleList
    1213              :                 {
    1214          732 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1215              : 
    1216          732 :                     n->stmt_type = ROLESTMT_ROLE;
    1217          732 :                     n->role = $3;
    1218          732 :                     n->options = $5;
    1219          732 :                     $$ = (Node *) n;
    1220              :                 }
    1221              :         ;
    1222              : 
    1223              : 
    1224              : opt_with:   WITH
    1225              :             | WITH_LA
    1226              :             | /*EMPTY*/
    1227              :         ;
    1228              : 
    1229              : /*
    1230              :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1231              :  * for backwards compatibility).  Note: the only option required by SQL99
    1232              :  * is "WITH ADMIN name".
    1233              :  */
    1234              : OptRoleList:
    1235          603 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1236          973 :             | /* EMPTY */                           { $$ = NIL; }
    1237              :         ;
    1238              : 
    1239              : AlterOptRoleList:
    1240          392 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1241          218 :             | /* EMPTY */                           { $$ = NIL; }
    1242              :         ;
    1243              : 
    1244              : AlterOptRoleElem:
    1245              :             PASSWORD Sconst
    1246              :                 {
    1247           97 :                     $$ = makeDefElem("password",
    1248           97 :                                      (Node *) makeString($2), @1);
    1249              :                 }
    1250              :             | PASSWORD NULL_P
    1251              :                 {
    1252            6 :                     $$ = makeDefElem("password", NULL, @1);
    1253              :                 }
    1254              :             | ENCRYPTED PASSWORD Sconst
    1255              :                 {
    1256              :                     /*
    1257              :                      * These days, passwords are always stored in encrypted
    1258              :                      * form, so there is no difference between PASSWORD and
    1259              :                      * ENCRYPTED PASSWORD.
    1260              :                      */
    1261            9 :                     $$ = makeDefElem("password",
    1262            9 :                                      (Node *) makeString($3), @1);
    1263              :                 }
    1264              :             | UNENCRYPTED PASSWORD Sconst
    1265              :                 {
    1266            0 :                     ereport(ERROR,
    1267              :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1268              :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1269              :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1270              :                              parser_errposition(@1)));
    1271              :                 }
    1272              :             | INHERIT
    1273              :                 {
    1274           56 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1275              :                 }
    1276              :             | CONNECTION LIMIT SignedIconst
    1277              :                 {
    1278           13 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1279              :                 }
    1280              :             | VALID UNTIL Sconst
    1281              :                 {
    1282            4 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1283              :                 }
    1284              :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1285              :             | USER role_list
    1286              :                 {
    1287            3 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1288              :                 }
    1289              :             | IDENT
    1290              :                 {
    1291              :                     /*
    1292              :                      * We handle identifiers that aren't parser keywords with
    1293              :                      * the following special-case codes, to avoid bloating the
    1294              :                      * size of the main parser.
    1295              :                      */
    1296          732 :                     if (strcmp($1, "superuser") == 0)
    1297           98 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1298          634 :                     else if (strcmp($1, "nosuperuser") == 0)
    1299           57 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1300          577 :                     else if (strcmp($1, "createrole") == 0)
    1301           52 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1302          525 :                     else if (strcmp($1, "nocreaterole") == 0)
    1303           26 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1304          499 :                     else if (strcmp($1, "replication") == 0)
    1305           67 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1306          432 :                     else if (strcmp($1, "noreplication") == 0)
    1307           55 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1308          377 :                     else if (strcmp($1, "createdb") == 0)
    1309           47 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1310          330 :                     else if (strcmp($1, "nocreatedb") == 0)
    1311           30 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1312          300 :                     else if (strcmp($1, "login") == 0)
    1313          148 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1314          152 :                     else if (strcmp($1, "nologin") == 0)
    1315           51 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1316          101 :                     else if (strcmp($1, "bypassrls") == 0)
    1317           42 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1318           59 :                     else if (strcmp($1, "nobypassrls") == 0)
    1319           41 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1320           18 :                     else if (strcmp($1, "noinherit") == 0)
    1321              :                     {
    1322              :                         /*
    1323              :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1324              :                          * NOINHERIT is handled here.
    1325              :                          */
    1326           18 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1327              :                     }
    1328              :                     else
    1329            0 :                         ereport(ERROR,
    1330              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1331              :                                  errmsg("unrecognized role option \"%s\"", $1),
    1332              :                                      parser_errposition(@1)));
    1333              :                 }
    1334              :         ;
    1335              : 
    1336              : CreateOptRoleElem:
    1337          528 :             AlterOptRoleElem            { $$ = $1; }
    1338              :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1339              :             | SYSID Iconst
    1340              :                 {
    1341            3 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1342              :                 }
    1343              :             | ADMIN role_list
    1344              :                 {
    1345           11 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1346              :                 }
    1347              :             | ROLE role_list
    1348              :                 {
    1349           11 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1350              :                 }
    1351              :             | IN_P ROLE role_list
    1352              :                 {
    1353           50 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1354              :                 }
    1355              :             | IN_P GROUP_P role_list
    1356              :                 {
    1357            0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1358              :                 }
    1359              :         ;
    1360              : 
    1361              : 
    1362              : /*****************************************************************************
    1363              :  *
    1364              :  * Create a new Postgres DBMS user (role with implied login ability)
    1365              :  *
    1366              :  *****************************************************************************/
    1367              : 
    1368              : CreateUserStmt:
    1369              :             CREATE USER RoleId opt_with OptRoleList
    1370              :                 {
    1371          229 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1372              : 
    1373          229 :                     n->stmt_type = ROLESTMT_USER;
    1374          229 :                     n->role = $3;
    1375          229 :                     n->options = $5;
    1376          229 :                     $$ = (Node *) n;
    1377              :                 }
    1378              :         ;
    1379              : 
    1380              : 
    1381              : /*****************************************************************************
    1382              :  *
    1383              :  * Alter a postgresql DBMS role
    1384              :  *
    1385              :  *****************************************************************************/
    1386              : 
    1387              : AlterRoleStmt:
    1388              :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1389              :                  {
    1390          172 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1391              : 
    1392          172 :                     n->role = $3;
    1393          172 :                     n->action = +1;  /* add, if there are members */
    1394          172 :                     n->options = $5;
    1395          172 :                     $$ = (Node *) n;
    1396              :                  }
    1397              :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1398              :                  {
    1399           46 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1400              : 
    1401           46 :                     n->role = $3;
    1402           46 :                     n->action = +1;  /* add, if there are members */
    1403           46 :                     n->options = $5;
    1404           46 :                     $$ = (Node *) n;
    1405              :                  }
    1406              :         ;
    1407              : 
    1408              : opt_in_database:
    1409           46 :                /* EMPTY */                  { $$ = NULL; }
    1410            2 :             | IN_P DATABASE name    { $$ = $3; }
    1411              :         ;
    1412              : 
    1413              : AlterRoleSetStmt:
    1414              :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1415              :                 {
    1416           28 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1417              : 
    1418           28 :                     n->role = $3;
    1419           28 :                     n->database = $4;
    1420           28 :                     n->setstmt = $5;
    1421           28 :                     $$ = (Node *) n;
    1422              :                 }
    1423              :             | ALTER ROLE ALL opt_in_database SetResetClause
    1424              :                 {
    1425            2 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1426              : 
    1427            2 :                     n->role = NULL;
    1428            2 :                     n->database = $4;
    1429            2 :                     n->setstmt = $5;
    1430            2 :                     $$ = (Node *) n;
    1431              :                 }
    1432              :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1433              :                 {
    1434           14 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1435              : 
    1436           14 :                     n->role = $3;
    1437           14 :                     n->database = $4;
    1438           14 :                     n->setstmt = $5;
    1439           14 :                     $$ = (Node *) n;
    1440              :                 }
    1441              :             | ALTER USER ALL opt_in_database SetResetClause
    1442              :                 {
    1443            2 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1444              : 
    1445            2 :                     n->role = NULL;
    1446            2 :                     n->database = $4;
    1447            2 :                     n->setstmt = $5;
    1448            2 :                     $$ = (Node *) n;
    1449              :                 }
    1450              :         ;
    1451              : 
    1452              : 
    1453              : /*****************************************************************************
    1454              :  *
    1455              :  * Drop a postgresql DBMS role
    1456              :  *
    1457              :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1458              :  * might own objects in multiple databases, and there is presently no way to
    1459              :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1460              :  *****************************************************************************/
    1461              : 
    1462              : DropRoleStmt:
    1463              :             DROP ROLE role_list
    1464              :                 {
    1465          574 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1466              : 
    1467          574 :                     n->missing_ok = false;
    1468          574 :                     n->roles = $3;
    1469          574 :                     $$ = (Node *) n;
    1470              :                 }
    1471              :             | DROP ROLE IF_P EXISTS role_list
    1472              :                 {
    1473           67 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1474              : 
    1475           67 :                     n->missing_ok = true;
    1476           67 :                     n->roles = $5;
    1477           67 :                     $$ = (Node *) n;
    1478              :                 }
    1479              :             | DROP USER role_list
    1480              :                 {
    1481          203 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1482              : 
    1483          203 :                     n->missing_ok = false;
    1484          203 :                     n->roles = $3;
    1485          203 :                     $$ = (Node *) n;
    1486              :                 }
    1487              :             | DROP USER IF_P EXISTS role_list
    1488              :                 {
    1489           18 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1490              : 
    1491           18 :                     n->roles = $5;
    1492           18 :                     n->missing_ok = true;
    1493           18 :                     $$ = (Node *) n;
    1494              :                 }
    1495              :             | DROP GROUP_P role_list
    1496              :                 {
    1497           18 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1498              : 
    1499           18 :                     n->missing_ok = false;
    1500           18 :                     n->roles = $3;
    1501           18 :                     $$ = (Node *) n;
    1502              :                 }
    1503              :             | DROP GROUP_P IF_P EXISTS role_list
    1504              :                 {
    1505            3 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1506              : 
    1507            3 :                     n->missing_ok = true;
    1508            3 :                     n->roles = $5;
    1509            3 :                     $$ = (Node *) n;
    1510              :                 }
    1511              :             ;
    1512              : 
    1513              : 
    1514              : /*****************************************************************************
    1515              :  *
    1516              :  * Create a postgresql group (role without login ability)
    1517              :  *
    1518              :  *****************************************************************************/
    1519              : 
    1520              : CreateGroupStmt:
    1521              :             CREATE GROUP_P RoleId opt_with OptRoleList
    1522              :                 {
    1523           12 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1524              : 
    1525           12 :                     n->stmt_type = ROLESTMT_GROUP;
    1526           12 :                     n->role = $3;
    1527           12 :                     n->options = $5;
    1528           12 :                     $$ = (Node *) n;
    1529              :                 }
    1530              :         ;
    1531              : 
    1532              : 
    1533              : /*****************************************************************************
    1534              :  *
    1535              :  * Alter a postgresql group
    1536              :  *
    1537              :  *****************************************************************************/
    1538              : 
    1539              : AlterGroupStmt:
    1540              :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1541              :                 {
    1542           21 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1543              : 
    1544           21 :                     n->role = $3;
    1545           21 :                     n->action = $4;
    1546           21 :                     n->options = list_make1(makeDefElem("rolemembers",
    1547              :                                                         (Node *) $6, @6));
    1548           21 :                     $$ = (Node *) n;
    1549              :                 }
    1550              :         ;
    1551              : 
    1552           47 : add_drop:   ADD_P                                   { $$ = +1; }
    1553          101 :             | DROP                                  { $$ = -1; }
    1554              :         ;
    1555              : 
    1556              : 
    1557              : /*****************************************************************************
    1558              :  *
    1559              :  * Manipulate a schema
    1560              :  *
    1561              :  *****************************************************************************/
    1562              : 
    1563              : CreateSchemaStmt:
    1564              :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1565              :                 {
    1566           79 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1567              : 
    1568              :                     /* One can omit the schema name or the authorization id. */
    1569           79 :                     n->schemaname = $3;
    1570           79 :                     n->authrole = $5;
    1571           79 :                     n->schemaElts = $6;
    1572           79 :                     n->if_not_exists = false;
    1573           79 :                     $$ = (Node *) n;
    1574              :                 }
    1575              :             | CREATE SCHEMA ColId OptSchemaEltList
    1576              :                 {
    1577          466 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1578              : 
    1579              :                     /* ...but not both */
    1580          466 :                     n->schemaname = $3;
    1581          466 :                     n->authrole = NULL;
    1582          466 :                     n->schemaElts = $4;
    1583          466 :                     n->if_not_exists = false;
    1584          466 :                     $$ = (Node *) n;
    1585              :                 }
    1586              :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1587              :                 {
    1588            9 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1589              : 
    1590              :                     /* schema name can be omitted here, too */
    1591            9 :                     n->schemaname = $6;
    1592            9 :                     n->authrole = $8;
    1593            9 :                     if ($9 != NIL)
    1594            0 :                         ereport(ERROR,
    1595              :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1596              :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1597              :                                  parser_errposition(@9)));
    1598            9 :                     n->schemaElts = $9;
    1599            9 :                     n->if_not_exists = true;
    1600            9 :                     $$ = (Node *) n;
    1601              :                 }
    1602              :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1603              :                 {
    1604           17 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1605              : 
    1606              :                     /* ...but not here */
    1607           17 :                     n->schemaname = $6;
    1608           17 :                     n->authrole = NULL;
    1609           17 :                     if ($7 != NIL)
    1610            3 :                         ereport(ERROR,
    1611              :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1612              :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1613              :                                  parser_errposition(@7)));
    1614           14 :                     n->schemaElts = $7;
    1615           14 :                     n->if_not_exists = true;
    1616           14 :                     $$ = (Node *) n;
    1617              :                 }
    1618              :         ;
    1619              : 
    1620              : OptSchemaEltList:
    1621              :             OptSchemaEltList schema_stmt
    1622              :                 {
    1623          295 :                     $$ = lappend($1, $2);
    1624              :                 }
    1625              :             | /* EMPTY */
    1626          571 :                 { $$ = NIL; }
    1627              :         ;
    1628              : 
    1629              : /*
    1630              :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1631              :  *  statement (in addition to by themselves).
    1632              :  */
    1633              : schema_stmt:
    1634              :             CreateStmt
    1635              :             | IndexStmt
    1636              :             | CreateSeqStmt
    1637              :             | CreateTrigStmt
    1638              :             | GrantStmt
    1639              :             | ViewStmt
    1640              :         ;
    1641              : 
    1642              : 
    1643              : /*****************************************************************************
    1644              :  *
    1645              :  * Set PG internal variable
    1646              :  *    SET name TO 'var_value'
    1647              :  * Include SQL syntax (thomas 1997-10-22):
    1648              :  *    SET TIME ZONE 'var_value'
    1649              :  *
    1650              :  *****************************************************************************/
    1651              : 
    1652              : VariableSetStmt:
    1653              :             SET set_rest
    1654              :                 {
    1655        12196 :                     VariableSetStmt *n = $2;
    1656              : 
    1657        12196 :                     n->is_local = false;
    1658        12196 :                     $$ = (Node *) n;
    1659              :                 }
    1660              :             | SET LOCAL set_rest
    1661              :                 {
    1662          648 :                     VariableSetStmt *n = $3;
    1663              : 
    1664          648 :                     n->is_local = true;
    1665          648 :                     $$ = (Node *) n;
    1666              :                 }
    1667              :             | SET SESSION set_rest
    1668              :                 {
    1669           42 :                     VariableSetStmt *n = $3;
    1670              : 
    1671           42 :                     n->is_local = false;
    1672           42 :                     $$ = (Node *) n;
    1673              :                 }
    1674              :         ;
    1675              : 
    1676              : set_rest:
    1677              :             TRANSACTION transaction_mode_list
    1678              :                 {
    1679          356 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1680              : 
    1681          356 :                     n->kind = VAR_SET_MULTI;
    1682          356 :                     n->name = "TRANSACTION";
    1683          356 :                     n->args = $2;
    1684          356 :                     n->jumble_args = true;
    1685          356 :                     n->location = -1;
    1686          356 :                     $$ = n;
    1687              :                 }
    1688              :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1689              :                 {
    1690            9 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1691              : 
    1692            9 :                     n->kind = VAR_SET_MULTI;
    1693            9 :                     n->name = "SESSION CHARACTERISTICS";
    1694            9 :                     n->args = $5;
    1695            9 :                     n->jumble_args = true;
    1696            9 :                     n->location = -1;
    1697            9 :                     $$ = n;
    1698              :                 }
    1699              :             | set_rest_more
    1700              :             ;
    1701              : 
    1702              : generic_set:
    1703              :             var_name TO var_list
    1704              :                 {
    1705         2803 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1706              : 
    1707         2803 :                     n->kind = VAR_SET_VALUE;
    1708         2803 :                     n->name = $1;
    1709         2803 :                     n->args = $3;
    1710         2803 :                     n->location = @3;
    1711         2803 :                     $$ = n;
    1712              :                 }
    1713              :             | var_name '=' var_list
    1714              :                 {
    1715         8480 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1716              : 
    1717         8480 :                     n->kind = VAR_SET_VALUE;
    1718         8480 :                     n->name = $1;
    1719         8480 :                     n->args = $3;
    1720         8480 :                     n->location = @3;
    1721         8480 :                     $$ = n;
    1722              :                 }
    1723              :             | var_name TO NULL_P
    1724              :                 {
    1725            4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1726              : 
    1727            4 :                     n->kind = VAR_SET_VALUE;
    1728            4 :                     n->name = $1;
    1729            4 :                     n->args = list_make1(makeNullAConst(@3));
    1730            4 :                     n->location = @3;
    1731            4 :                     $$ = n;
    1732              :                 }
    1733              :             | var_name '=' NULL_P
    1734              :                 {
    1735            9 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1736              : 
    1737            9 :                     n->kind = VAR_SET_VALUE;
    1738            9 :                     n->name = $1;
    1739            9 :                     n->args = list_make1(makeNullAConst(@3));
    1740            9 :                     n->location = @3;
    1741            9 :                     $$ = n;
    1742              :                 }
    1743              :             | var_name TO DEFAULT
    1744              :                 {
    1745           68 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1746              : 
    1747           68 :                     n->kind = VAR_SET_DEFAULT;
    1748           68 :                     n->name = $1;
    1749           68 :                     n->location = -1;
    1750           68 :                     $$ = n;
    1751              :                 }
    1752              :             | var_name '=' DEFAULT
    1753              :                 {
    1754            5 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1755              : 
    1756            5 :                     n->kind = VAR_SET_DEFAULT;
    1757            5 :                     n->name = $1;
    1758            5 :                     n->location = -1;
    1759            5 :                     $$ = n;
    1760              :                 }
    1761              :         ;
    1762              : 
    1763              : set_rest_more:  /* Generic SET syntaxes: */
    1764        11295 :             generic_set                         {$$ = $1;}
    1765              :             | var_name FROM CURRENT_P
    1766              :                 {
    1767            2 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1768              : 
    1769            2 :                     n->kind = VAR_SET_CURRENT;
    1770            2 :                     n->name = $1;
    1771            2 :                     n->location = -1;
    1772            2 :                     $$ = n;
    1773              :                 }
    1774              :             /* Special syntaxes mandated by SQL standard: */
    1775              :             | TIME ZONE zone_value
    1776              :                 {
    1777           52 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1778              : 
    1779           52 :                     n->kind = VAR_SET_VALUE;
    1780           52 :                     n->name = "timezone";
    1781           52 :                     n->location = -1;
    1782           52 :                     n->jumble_args = true;
    1783           52 :                     if ($3 != NULL)
    1784           44 :                         n->args = list_make1($3);
    1785              :                     else
    1786            8 :                         n->kind = VAR_SET_DEFAULT;
    1787           52 :                     $$ = n;
    1788              :                 }
    1789              :             | CATALOG_P Sconst
    1790              :                 {
    1791            0 :                     ereport(ERROR,
    1792              :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1793              :                              errmsg("current database cannot be changed"),
    1794              :                              parser_errposition(@2)));
    1795              :                     $$ = NULL; /*not reached*/
    1796              :                 }
    1797              :             | SCHEMA Sconst
    1798              :                 {
    1799            2 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1800              : 
    1801            2 :                     n->kind = VAR_SET_VALUE;
    1802            2 :                     n->name = "search_path";
    1803            2 :                     n->args = list_make1(makeStringConst($2, @2));
    1804            2 :                     n->location = @2;
    1805            2 :                     $$ = n;
    1806              :                 }
    1807              :             | NAMES opt_encoding
    1808              :                 {
    1809            0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1810              : 
    1811            0 :                     n->kind = VAR_SET_VALUE;
    1812            0 :                     n->name = "client_encoding";
    1813            0 :                     n->location = @2;
    1814            0 :                     if ($2 != NULL)
    1815            0 :                         n->args = list_make1(makeStringConst($2, @2));
    1816              :                     else
    1817            0 :                         n->kind = VAR_SET_DEFAULT;
    1818            0 :                     $$ = n;
    1819              :                 }
    1820              :             | ROLE NonReservedWord_or_Sconst
    1821              :                 {
    1822          499 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1823              : 
    1824          499 :                     n->kind = VAR_SET_VALUE;
    1825          499 :                     n->name = "role";
    1826          499 :                     n->args = list_make1(makeStringConst($2, @2));
    1827          499 :                     n->location = @2;
    1828          499 :                     $$ = n;
    1829              :                 }
    1830              :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1831              :                 {
    1832         1374 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1833              : 
    1834         1374 :                     n->kind = VAR_SET_VALUE;
    1835         1374 :                     n->name = "session_authorization";
    1836         1374 :                     n->args = list_make1(makeStringConst($3, @3));
    1837         1374 :                     n->location = @3;
    1838         1374 :                     $$ = n;
    1839              :                 }
    1840              :             | SESSION AUTHORIZATION DEFAULT
    1841              :                 {
    1842            2 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1843              : 
    1844            2 :                     n->kind = VAR_SET_DEFAULT;
    1845            2 :                     n->name = "session_authorization";
    1846            2 :                     n->location = -1;
    1847            2 :                     $$ = n;
    1848              :                 }
    1849              :             | XML_P OPTION document_or_content
    1850              :                 {
    1851            8 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1852              : 
    1853            8 :                     n->kind = VAR_SET_VALUE;
    1854            8 :                     n->name = "xmloption";
    1855            8 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1856            8 :                     n->jumble_args = true;
    1857            8 :                     n->location = -1;
    1858            8 :                     $$ = n;
    1859              :                 }
    1860              :             /* Special syntaxes invented by PostgreSQL: */
    1861              :             | TRANSACTION SNAPSHOT Sconst
    1862              :                 {
    1863           22 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1864              : 
    1865           22 :                     n->kind = VAR_SET_MULTI;
    1866           22 :                     n->name = "TRANSACTION SNAPSHOT";
    1867           22 :                     n->args = list_make1(makeStringConst($3, @3));
    1868           22 :                     n->location = @3;
    1869           22 :                     $$ = n;
    1870              :                 }
    1871              :         ;
    1872              : 
    1873        13869 : var_name:   ColId                               { $$ = $1; }
    1874              :             | var_name '.' ColId
    1875          251 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1876              :         ;
    1877              : 
    1878        11283 : var_list:   var_value                               { $$ = list_make1($1); }
    1879          151 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1880              :         ;
    1881              : 
    1882              : var_value:  opt_boolean_or_string
    1883         8392 :                 { $$ = makeStringConst($1, @1); }
    1884              :             | NumericOnly
    1885         3042 :                 { $$ = makeAConst($1, @1); }
    1886              :         ;
    1887              : 
    1888            0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1889          541 :             | READ COMMITTED                        { $$ = "read committed"; }
    1890         1416 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1891         1632 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1892              :         ;
    1893              : 
    1894              : opt_boolean_or_string:
    1895          359 :             TRUE_P                                  { $$ = "true"; }
    1896          755 :             | FALSE_P                               { $$ = "false"; }
    1897         1447 :             | ON                                    { $$ = "on"; }
    1898              :             /*
    1899              :              * OFF is also accepted as a boolean value, but is handled by
    1900              :              * the NonReservedWord rule.  The action for booleans and strings
    1901              :              * is the same, so we don't need to distinguish them here.
    1902              :              */
    1903        16439 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1904              :         ;
    1905              : 
    1906              : /* Timezone values can be:
    1907              :  * - a string such as 'pst8pdt'
    1908              :  * - an identifier such as "pst8pdt"
    1909              :  * - an integer or floating point number
    1910              :  * - a time interval per SQL99
    1911              :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1912              :  * so use IDENT (meaning we reject anything that is a key word).
    1913              :  */
    1914              : zone_value:
    1915              :             Sconst
    1916              :                 {
    1917           30 :                     $$ = makeStringConst($1, @1);
    1918              :                 }
    1919              :             | IDENT
    1920              :                 {
    1921            2 :                     $$ = makeStringConst($1, @1);
    1922              :                 }
    1923              :             | ConstInterval Sconst opt_interval
    1924              :                 {
    1925            0 :                     TypeName   *t = $1;
    1926              : 
    1927            0 :                     if ($3 != NIL)
    1928              :                     {
    1929            0 :                         A_Const    *n = (A_Const *) linitial($3);
    1930              : 
    1931            0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1932            0 :                             ereport(ERROR,
    1933              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1934              :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1935              :                                      parser_errposition(@3)));
    1936              :                     }
    1937            0 :                     t->typmods = $3;
    1938            0 :                     $$ = makeStringConstCast($2, @2, t);
    1939              :                 }
    1940              :             | ConstInterval '(' Iconst ')' Sconst
    1941              :                 {
    1942            0 :                     TypeName   *t = $1;
    1943              : 
    1944            0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1945              :                                             makeIntConst($3, @3));
    1946            0 :                     $$ = makeStringConstCast($5, @5, t);
    1947              :                 }
    1948           12 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1949            7 :             | DEFAULT                               { $$ = NULL; }
    1950            1 :             | LOCAL                                 { $$ = NULL; }
    1951              :         ;
    1952              : 
    1953              : opt_encoding:
    1954            0 :             Sconst                                  { $$ = $1; }
    1955            0 :             | DEFAULT                               { $$ = NULL; }
    1956            0 :             | /*EMPTY*/                             { $$ = NULL; }
    1957              :         ;
    1958              : 
    1959              : NonReservedWord_or_Sconst:
    1960        26624 :             NonReservedWord                         { $$ = $1; }
    1961         3038 :             | Sconst                                { $$ = $1; }
    1962              :         ;
    1963              : 
    1964              : VariableResetStmt:
    1965         2487 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1966              :         ;
    1967              : 
    1968              : reset_rest:
    1969         2040 :             generic_reset                           { $$ = $1; }
    1970              :             | TIME ZONE
    1971              :                 {
    1972            7 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1973              : 
    1974            7 :                     n->kind = VAR_RESET;
    1975            7 :                     n->name = "timezone";
    1976            7 :                     n->location = -1;
    1977            7 :                     $$ = n;
    1978              :                 }
    1979              :             | TRANSACTION ISOLATION LEVEL
    1980              :                 {
    1981            0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1982              : 
    1983            0 :                     n->kind = VAR_RESET;
    1984            0 :                     n->name = "transaction_isolation";
    1985            0 :                     n->location = -1;
    1986            0 :                     $$ = n;
    1987              :                 }
    1988              :             | SESSION AUTHORIZATION
    1989              :                 {
    1990          440 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1991              : 
    1992          440 :                     n->kind = VAR_RESET;
    1993          440 :                     n->name = "session_authorization";
    1994          440 :                     n->location = -1;
    1995          440 :                     $$ = n;
    1996              :                 }
    1997              :         ;
    1998              : 
    1999              : generic_reset:
    2000              :             var_name
    2001              :                 {
    2002         2055 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    2003              : 
    2004         2055 :                     n->kind = VAR_RESET;
    2005         2055 :                     n->name = $1;
    2006         2055 :                     n->location = -1;
    2007         2055 :                     $$ = n;
    2008              :                 }
    2009              :             | ALL
    2010              :                 {
    2011           14 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    2012              : 
    2013           14 :                     n->kind = VAR_RESET_ALL;
    2014           14 :                     n->location = -1;
    2015           14 :                     $$ = n;
    2016              :                 }
    2017              :         ;
    2018              : 
    2019              : /* SetResetClause allows SET or RESET without LOCAL */
    2020              : SetResetClause:
    2021          664 :             SET set_rest                    { $$ = $2; }
    2022           21 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    2023              :         ;
    2024              : 
    2025              : /* SetResetClause allows SET or RESET without LOCAL */
    2026              : FunctionSetResetClause:
    2027           71 :             SET set_rest_more               { $$ = $2; }
    2028            6 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    2029              :         ;
    2030              : 
    2031              : 
    2032              : VariableShowStmt:
    2033              :             SHOW var_name
    2034              :                 {
    2035          443 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2036              : 
    2037          443 :                     n->name = $2;
    2038          443 :                     $$ = (Node *) n;
    2039              :                 }
    2040              :             | SHOW TIME ZONE
    2041              :                 {
    2042            5 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2043              : 
    2044            5 :                     n->name = "timezone";
    2045            5 :                     $$ = (Node *) n;
    2046              :                 }
    2047              :             | SHOW TRANSACTION ISOLATION LEVEL
    2048              :                 {
    2049            2 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2050              : 
    2051            2 :                     n->name = "transaction_isolation";
    2052            2 :                     $$ = (Node *) n;
    2053              :                 }
    2054              :             | SHOW SESSION AUTHORIZATION
    2055              :                 {
    2056            0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2057              : 
    2058            0 :                     n->name = "session_authorization";
    2059            0 :                     $$ = (Node *) n;
    2060              :                 }
    2061              :             | SHOW ALL
    2062              :                 {
    2063            0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2064              : 
    2065            0 :                     n->name = "all";
    2066            0 :                     $$ = (Node *) n;
    2067              :                 }
    2068              :         ;
    2069              : 
    2070              : 
    2071              : ConstraintsSetStmt:
    2072              :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    2073              :                 {
    2074           52 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2075              : 
    2076           52 :                     n->constraints = $3;
    2077           52 :                     n->deferred = $4;
    2078           52 :                     $$ = (Node *) n;
    2079              :                 }
    2080              :         ;
    2081              : 
    2082              : constraints_set_list:
    2083           28 :             ALL                                     { $$ = NIL; }
    2084           24 :             | qualified_name_list                   { $$ = $1; }
    2085              :         ;
    2086              : 
    2087              : constraints_set_mode:
    2088           34 :             DEFERRED                                { $$ = true; }
    2089           18 :             | IMMEDIATE                             { $$ = false; }
    2090              :         ;
    2091              : 
    2092              : 
    2093              : /*
    2094              :  * Checkpoint statement
    2095              :  */
    2096              : CheckPointStmt:
    2097              :             CHECKPOINT opt_utility_option_list
    2098              :                 {
    2099          130 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2100              : 
    2101          130 :                     $$ = (Node *) n;
    2102          130 :                     n->options = $2;
    2103              :                 }
    2104              :         ;
    2105              : 
    2106              : 
    2107              : /*****************************************************************************
    2108              :  *
    2109              :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2110              :  *
    2111              :  *****************************************************************************/
    2112              : 
    2113              : DiscardStmt:
    2114              :             DISCARD ALL
    2115              :                 {
    2116            3 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2117              : 
    2118            3 :                     n->target = DISCARD_ALL;
    2119            3 :                     $$ = (Node *) n;
    2120              :                 }
    2121              :             | DISCARD TEMP
    2122              :                 {
    2123            7 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2124              : 
    2125            7 :                     n->target = DISCARD_TEMP;
    2126            7 :                     $$ = (Node *) n;
    2127              :                 }
    2128              :             | DISCARD TEMPORARY
    2129              :                 {
    2130            0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2131              : 
    2132            0 :                     n->target = DISCARD_TEMP;
    2133            0 :                     $$ = (Node *) n;
    2134              :                 }
    2135              :             | DISCARD PLANS
    2136              :                 {
    2137            3 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2138              : 
    2139            3 :                     n->target = DISCARD_PLANS;
    2140            3 :                     $$ = (Node *) n;
    2141              :                 }
    2142              :             | DISCARD SEQUENCES
    2143              :                 {
    2144            6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2145              : 
    2146            6 :                     n->target = DISCARD_SEQUENCES;
    2147            6 :                     $$ = (Node *) n;
    2148              :                 }
    2149              : 
    2150              :         ;
    2151              : 
    2152              : 
    2153              : /*****************************************************************************
    2154              :  *
    2155              :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2156              :  *
    2157              :  * Note: we accept all subcommands for each of the variants, and sort
    2158              :  * out what's really legal at execution time.
    2159              :  *****************************************************************************/
    2160              : 
    2161              : AlterTableStmt:
    2162              :             ALTER TABLE relation_expr alter_table_cmds
    2163              :                 {
    2164        13543 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2165              : 
    2166        13543 :                     n->relation = $3;
    2167        13543 :                     n->cmds = $4;
    2168        13543 :                     n->objtype = OBJECT_TABLE;
    2169        13543 :                     n->missing_ok = false;
    2170        13543 :                     $$ = (Node *) n;
    2171              :                 }
    2172              :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2173              :                 {
    2174           27 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2175              : 
    2176           27 :                     n->relation = $5;
    2177           27 :                     n->cmds = $6;
    2178           27 :                     n->objtype = OBJECT_TABLE;
    2179           27 :                     n->missing_ok = true;
    2180           27 :                     $$ = (Node *) n;
    2181              :                 }
    2182              :         |   ALTER TABLE relation_expr partition_cmd
    2183              :                 {
    2184         1924 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2185              : 
    2186         1924 :                     n->relation = $3;
    2187         1924 :                     n->cmds = list_make1($4);
    2188         1924 :                     n->objtype = OBJECT_TABLE;
    2189         1924 :                     n->missing_ok = false;
    2190         1924 :                     $$ = (Node *) n;
    2191              :                 }
    2192              :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2193              :                 {
    2194            0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2195              : 
    2196            0 :                     n->relation = $5;
    2197            0 :                     n->cmds = list_make1($6);
    2198            0 :                     n->objtype = OBJECT_TABLE;
    2199            0 :                     n->missing_ok = true;
    2200            0 :                     $$ = (Node *) n;
    2201              :                 }
    2202              :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2203              :                 {
    2204              :                     AlterTableMoveAllStmt *n =
    2205            6 :                         makeNode(AlterTableMoveAllStmt);
    2206              : 
    2207            6 :                     n->orig_tablespacename = $6;
    2208            6 :                     n->objtype = OBJECT_TABLE;
    2209            6 :                     n->roles = NIL;
    2210            6 :                     n->new_tablespacename = $9;
    2211            6 :                     n->nowait = $10;
    2212            6 :                     $$ = (Node *) n;
    2213              :                 }
    2214              :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2215              :                 {
    2216              :                     AlterTableMoveAllStmt *n =
    2217            0 :                         makeNode(AlterTableMoveAllStmt);
    2218              : 
    2219            0 :                     n->orig_tablespacename = $6;
    2220            0 :                     n->objtype = OBJECT_TABLE;
    2221            0 :                     n->roles = $9;
    2222            0 :                     n->new_tablespacename = $12;
    2223            0 :                     n->nowait = $13;
    2224            0 :                     $$ = (Node *) n;
    2225              :                 }
    2226              :         |   ALTER INDEX qualified_name alter_table_cmds
    2227              :                 {
    2228          121 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2229              : 
    2230          121 :                     n->relation = $3;
    2231          121 :                     n->cmds = $4;
    2232          121 :                     n->objtype = OBJECT_INDEX;
    2233          121 :                     n->missing_ok = false;
    2234          121 :                     $$ = (Node *) n;
    2235              :                 }
    2236              :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2237              :                 {
    2238            0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2239              : 
    2240            0 :                     n->relation = $5;
    2241            0 :                     n->cmds = $6;
    2242            0 :                     n->objtype = OBJECT_INDEX;
    2243            0 :                     n->missing_ok = true;
    2244            0 :                     $$ = (Node *) n;
    2245              :                 }
    2246              :         |   ALTER INDEX qualified_name index_partition_cmd
    2247              :                 {
    2248          201 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2249              : 
    2250          201 :                     n->relation = $3;
    2251          201 :                     n->cmds = list_make1($4);
    2252          201 :                     n->objtype = OBJECT_INDEX;
    2253          201 :                     n->missing_ok = false;
    2254          201 :                     $$ = (Node *) n;
    2255              :                 }
    2256              :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2257              :                 {
    2258              :                     AlterTableMoveAllStmt *n =
    2259            3 :                         makeNode(AlterTableMoveAllStmt);
    2260              : 
    2261            3 :                     n->orig_tablespacename = $6;
    2262            3 :                     n->objtype = OBJECT_INDEX;
    2263            3 :                     n->roles = NIL;
    2264            3 :                     n->new_tablespacename = $9;
    2265            3 :                     n->nowait = $10;
    2266            3 :                     $$ = (Node *) n;
    2267              :                 }
    2268              :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2269              :                 {
    2270              :                     AlterTableMoveAllStmt *n =
    2271            0 :                         makeNode(AlterTableMoveAllStmt);
    2272              : 
    2273            0 :                     n->orig_tablespacename = $6;
    2274            0 :                     n->objtype = OBJECT_INDEX;
    2275            0 :                     n->roles = $9;
    2276            0 :                     n->new_tablespacename = $12;
    2277            0 :                     n->nowait = $13;
    2278            0 :                     $$ = (Node *) n;
    2279              :                 }
    2280              :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2281              :                 {
    2282           47 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2283              : 
    2284           47 :                     n->relation = $3;
    2285           47 :                     n->cmds = $4;
    2286           47 :                     n->objtype = OBJECT_SEQUENCE;
    2287           47 :                     n->missing_ok = false;
    2288           47 :                     $$ = (Node *) n;
    2289              :                 }
    2290              :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2291              :                 {
    2292            0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2293              : 
    2294            0 :                     n->relation = $5;
    2295            0 :                     n->cmds = $6;
    2296            0 :                     n->objtype = OBJECT_SEQUENCE;
    2297            0 :                     n->missing_ok = true;
    2298            0 :                     $$ = (Node *) n;
    2299              :                 }
    2300              :         |   ALTER VIEW qualified_name alter_table_cmds
    2301              :                 {
    2302          127 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2303              : 
    2304          127 :                     n->relation = $3;
    2305          127 :                     n->cmds = $4;
    2306          127 :                     n->objtype = OBJECT_VIEW;
    2307          127 :                     n->missing_ok = false;
    2308          127 :                     $$ = (Node *) n;
    2309              :                 }
    2310              :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2311              :                 {
    2312            0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2313              : 
    2314            0 :                     n->relation = $5;
    2315            0 :                     n->cmds = $6;
    2316            0 :                     n->objtype = OBJECT_VIEW;
    2317            0 :                     n->missing_ok = true;
    2318            0 :                     $$ = (Node *) n;
    2319              :                 }
    2320              :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2321              :                 {
    2322           24 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2323              : 
    2324           24 :                     n->relation = $4;
    2325           24 :                     n->cmds = $5;
    2326           24 :                     n->objtype = OBJECT_MATVIEW;
    2327           24 :                     n->missing_ok = false;
    2328           24 :                     $$ = (Node *) n;
    2329              :                 }
    2330              :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2331              :                 {
    2332            0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2333              : 
    2334            0 :                     n->relation = $6;
    2335            0 :                     n->cmds = $7;
    2336            0 :                     n->objtype = OBJECT_MATVIEW;
    2337            0 :                     n->missing_ok = true;
    2338            0 :                     $$ = (Node *) n;
    2339              :                 }
    2340              :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2341              :                 {
    2342              :                     AlterTableMoveAllStmt *n =
    2343            6 :                         makeNode(AlterTableMoveAllStmt);
    2344              : 
    2345            6 :                     n->orig_tablespacename = $7;
    2346            6 :                     n->objtype = OBJECT_MATVIEW;
    2347            6 :                     n->roles = NIL;
    2348            6 :                     n->new_tablespacename = $10;
    2349            6 :                     n->nowait = $11;
    2350            6 :                     $$ = (Node *) n;
    2351              :                 }
    2352              :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2353              :                 {
    2354              :                     AlterTableMoveAllStmt *n =
    2355            0 :                         makeNode(AlterTableMoveAllStmt);
    2356              : 
    2357            0 :                     n->orig_tablespacename = $7;
    2358            0 :                     n->objtype = OBJECT_MATVIEW;
    2359            0 :                     n->roles = $10;
    2360            0 :                     n->new_tablespacename = $13;
    2361            0 :                     n->nowait = $14;
    2362            0 :                     $$ = (Node *) n;
    2363              :                 }
    2364              :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2365              :                 {
    2366          189 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2367              : 
    2368          189 :                     n->relation = $4;
    2369          189 :                     n->cmds = $5;
    2370          189 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2371          189 :                     n->missing_ok = false;
    2372          189 :                     $$ = (Node *) n;
    2373              :                 }
    2374              :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2375              :                 {
    2376           54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2377              : 
    2378           54 :                     n->relation = $6;
    2379           54 :                     n->cmds = $7;
    2380           54 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2381           54 :                     n->missing_ok = true;
    2382           54 :                     $$ = (Node *) n;
    2383              :                 }
    2384              :         ;
    2385              : 
    2386              : alter_table_cmds:
    2387        14132 :             alter_table_cmd                         { $$ = list_make1($1); }
    2388          513 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2389              :         ;
    2390              : 
    2391              : partitions_list:
    2392          195 :             SinglePartitionSpec                         { $$ = list_make1($1); }
    2393          357 :             | partitions_list ',' SinglePartitionSpec   { $$ = lappend($1, $3); }
    2394              :         ;
    2395              : 
    2396              : SinglePartitionSpec:
    2397              :             PARTITION qualified_name PartitionBoundSpec
    2398              :                 {
    2399          552 :                     SinglePartitionSpec *n = makeNode(SinglePartitionSpec);
    2400              : 
    2401          552 :                     n->name = $2;
    2402          552 :                     n->bound = $3;
    2403              : 
    2404          552 :                     $$ = n;
    2405              :                 }
    2406              :         ;
    2407              : 
    2408              : partition_cmd:
    2409              :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2410              :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2411              :                 {
    2412         1280 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2413         1280 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2414              : 
    2415         1280 :                     n->subtype = AT_AttachPartition;
    2416         1280 :                     cmd->name = $3;
    2417         1280 :                     cmd->bound = $4;
    2418         1280 :                     cmd->partlist = NIL;
    2419         1280 :                     cmd->concurrent = false;
    2420         1280 :                     n->def = (Node *) cmd;
    2421              : 
    2422         1280 :                     $$ = (Node *) n;
    2423              :                 }
    2424              :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2425              :             | DETACH PARTITION qualified_name opt_concurrently
    2426              :                 {
    2427          304 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2428          304 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2429              : 
    2430          304 :                     n->subtype = AT_DetachPartition;
    2431          304 :                     cmd->name = $3;
    2432          304 :                     cmd->bound = NULL;
    2433          304 :                     cmd->partlist = NIL;
    2434          304 :                     cmd->concurrent = $4;
    2435          304 :                     n->def = (Node *) cmd;
    2436              : 
    2437          304 :                     $$ = (Node *) n;
    2438              :                 }
    2439              :             | DETACH PARTITION qualified_name FINALIZE
    2440              :                 {
    2441           10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2442           10 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2443              : 
    2444           10 :                     n->subtype = AT_DetachPartitionFinalize;
    2445           10 :                     cmd->name = $3;
    2446           10 :                     cmd->bound = NULL;
    2447           10 :                     cmd->partlist = NIL;
    2448           10 :                     cmd->concurrent = false;
    2449           10 :                     n->def = (Node *) cmd;
    2450           10 :                     $$ = (Node *) n;
    2451              :                 }
    2452              :             /* ALTER TABLE <name> SPLIT PARTITION <partition_name> INTO () */
    2453              :             | SPLIT PARTITION qualified_name INTO '(' partitions_list ')'
    2454              :                 {
    2455          195 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2456          195 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2457              : 
    2458          195 :                     n->subtype = AT_SplitPartition;
    2459          195 :                     cmd->name = $3;
    2460          195 :                     cmd->bound = NULL;
    2461          195 :                     cmd->partlist = $6;
    2462          195 :                     cmd->concurrent = false;
    2463          195 :                     n->def = (Node *) cmd;
    2464          195 :                     $$ = (Node *) n;
    2465              :                 }
    2466              :             /* ALTER TABLE <name> MERGE PARTITIONS () INTO <partition_name> */
    2467              :             | MERGE PARTITIONS '(' qualified_name_list ')' INTO qualified_name
    2468              :                 {
    2469          135 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2470          135 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2471              : 
    2472          135 :                     n->subtype = AT_MergePartitions;
    2473          135 :                     cmd->name = $7;
    2474          135 :                     cmd->bound = NULL;
    2475          135 :                     cmd->partlist = $4;
    2476          135 :                     cmd->concurrent = false;
    2477          135 :                     n->def = (Node *) cmd;
    2478          135 :                     $$ = (Node *) n;
    2479              :                 }
    2480              :         ;
    2481              : 
    2482              : index_partition_cmd:
    2483              :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2484              :             ATTACH PARTITION qualified_name
    2485              :                 {
    2486          201 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2487          201 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2488              : 
    2489          201 :                     n->subtype = AT_AttachPartition;
    2490          201 :                     cmd->name = $3;
    2491          201 :                     cmd->bound = NULL;
    2492          201 :                     cmd->partlist = NIL;
    2493          201 :                     cmd->concurrent = false;
    2494          201 :                     n->def = (Node *) cmd;
    2495              : 
    2496          201 :                     $$ = (Node *) n;
    2497              :                 }
    2498              :         ;
    2499              : 
    2500              : alter_table_cmd:
    2501              :             /* ALTER TABLE <name> ADD <coldef> */
    2502              :             ADD_P columnDef
    2503              :                 {
    2504           96 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2505              : 
    2506           96 :                     n->subtype = AT_AddColumn;
    2507           96 :                     n->def = $2;
    2508           96 :                     n->missing_ok = false;
    2509           96 :                     $$ = (Node *) n;
    2510              :                 }
    2511              :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2512              :             | ADD_P IF_P NOT EXISTS columnDef
    2513              :                 {
    2514            0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2515              : 
    2516            0 :                     n->subtype = AT_AddColumn;
    2517            0 :                     n->def = $5;
    2518            0 :                     n->missing_ok = true;
    2519            0 :                     $$ = (Node *) n;
    2520              :                 }
    2521              :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2522              :             | ADD_P COLUMN columnDef
    2523              :                 {
    2524          966 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2525              : 
    2526          966 :                     n->subtype = AT_AddColumn;
    2527          966 :                     n->def = $3;
    2528          966 :                     n->missing_ok = false;
    2529          966 :                     $$ = (Node *) n;
    2530              :                 }
    2531              :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2532              :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2533              :                 {
    2534           30 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2535              : 
    2536           30 :                     n->subtype = AT_AddColumn;
    2537           30 :                     n->def = $6;
    2538           30 :                     n->missing_ok = true;
    2539           30 :                     $$ = (Node *) n;
    2540              :                 }
    2541              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2542              :             | ALTER opt_column ColId alter_column_default
    2543              :                 {
    2544          275 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2545              : 
    2546          275 :                     n->subtype = AT_ColumnDefault;
    2547          275 :                     n->name = $3;
    2548          275 :                     n->def = $4;
    2549          275 :                     $$ = (Node *) n;
    2550              :                 }
    2551              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2552              :             | ALTER opt_column ColId DROP NOT NULL_P
    2553              :                 {
    2554          147 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2555              : 
    2556          147 :                     n->subtype = AT_DropNotNull;
    2557          147 :                     n->name = $3;
    2558          147 :                     $$ = (Node *) n;
    2559              :                 }
    2560              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2561              :             | ALTER opt_column ColId SET NOT NULL_P
    2562              :                 {
    2563          220 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2564              : 
    2565          220 :                     n->subtype = AT_SetNotNull;
    2566          220 :                     n->name = $3;
    2567          220 :                     $$ = (Node *) n;
    2568              :                 }
    2569              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2570              :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2571              :                 {
    2572           91 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2573              : 
    2574           91 :                     n->subtype = AT_SetExpression;
    2575           91 :                     n->name = $3;
    2576           91 :                     n->def = $8;
    2577           91 :                     $$ = (Node *) n;
    2578              :                 }
    2579              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2580              :             | ALTER opt_column ColId DROP EXPRESSION
    2581              :                 {
    2582           31 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2583              : 
    2584           31 :                     n->subtype = AT_DropExpression;
    2585           31 :                     n->name = $3;
    2586           31 :                     $$ = (Node *) n;
    2587              :                 }
    2588              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2589              :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2590              :                 {
    2591            6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2592              : 
    2593            6 :                     n->subtype = AT_DropExpression;
    2594            6 :                     n->name = $3;
    2595            6 :                     n->missing_ok = true;
    2596            6 :                     $$ = (Node *) n;
    2597              :                 }
    2598              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2599              :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2600              :                 {
    2601           31 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2602              : 
    2603           31 :                     n->subtype = AT_SetStatistics;
    2604           31 :                     n->name = $3;
    2605           31 :                     n->def = $6;
    2606           31 :                     $$ = (Node *) n;
    2607              :                 }
    2608              :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2609              :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2610              :                 {
    2611           35 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2612              : 
    2613           35 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2614            3 :                         ereport(ERROR,
    2615              :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2616              :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2617              :                                  parser_errposition(@3)));
    2618              : 
    2619           32 :                     n->subtype = AT_SetStatistics;
    2620           32 :                     n->num = (int16) $3;
    2621           32 :                     n->def = $6;
    2622           32 :                     $$ = (Node *) n;
    2623              :                 }
    2624              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2625              :             | ALTER opt_column ColId SET reloptions
    2626              :                 {
    2627           19 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2628              : 
    2629           19 :                     n->subtype = AT_SetOptions;
    2630           19 :                     n->name = $3;
    2631           19 :                     n->def = (Node *) $5;
    2632           19 :                     $$ = (Node *) n;
    2633              :                 }
    2634              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2635              :             | ALTER opt_column ColId RESET reloptions
    2636              :                 {
    2637            3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2638              : 
    2639            3 :                     n->subtype = AT_ResetOptions;
    2640            3 :                     n->name = $3;
    2641            3 :                     n->def = (Node *) $5;
    2642            3 :                     $$ = (Node *) n;
    2643              :                 }
    2644              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2645              :             | ALTER opt_column ColId SET column_storage
    2646              :                 {
    2647          131 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2648              : 
    2649          131 :                     n->subtype = AT_SetStorage;
    2650          131 :                     n->name = $3;
    2651          131 :                     n->def = (Node *) makeString($5);
    2652          131 :                     $$ = (Node *) n;
    2653              :                 }
    2654              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2655              :             | ALTER opt_column ColId SET column_compression
    2656              :                 {
    2657           39 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2658              : 
    2659           39 :                     n->subtype = AT_SetCompression;
    2660           39 :                     n->name = $3;
    2661           39 :                     n->def = (Node *) makeString($5);
    2662           39 :                     $$ = (Node *) n;
    2663              :                 }
    2664              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2665              :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2666              :                 {
    2667           86 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2668           86 :                     Constraint *c = makeNode(Constraint);
    2669              : 
    2670           86 :                     c->contype = CONSTR_IDENTITY;
    2671           86 :                     c->generated_when = $6;
    2672           86 :                     c->options = $9;
    2673           86 :                     c->location = @5;
    2674              : 
    2675           86 :                     n->subtype = AT_AddIdentity;
    2676           86 :                     n->name = $3;
    2677           86 :                     n->def = (Node *) c;
    2678              : 
    2679           86 :                     $$ = (Node *) n;
    2680              :                 }
    2681              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2682              :             | ALTER opt_column ColId alter_identity_column_option_list
    2683              :                 {
    2684           31 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2685              : 
    2686           31 :                     n->subtype = AT_SetIdentity;
    2687           31 :                     n->name = $3;
    2688           31 :                     n->def = (Node *) $4;
    2689           31 :                     $$ = (Node *) n;
    2690              :                 }
    2691              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2692              :             | ALTER opt_column ColId DROP IDENTITY_P
    2693              :                 {
    2694           25 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2695              : 
    2696           25 :                     n->subtype = AT_DropIdentity;
    2697           25 :                     n->name = $3;
    2698           25 :                     n->missing_ok = false;
    2699           25 :                     $$ = (Node *) n;
    2700              :                 }
    2701              :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2702              :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2703              :                 {
    2704            3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2705              : 
    2706            3 :                     n->subtype = AT_DropIdentity;
    2707            3 :                     n->name = $3;
    2708            3 :                     n->missing_ok = true;
    2709            3 :                     $$ = (Node *) n;
    2710              :                 }
    2711              :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2712              :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2713              :                 {
    2714            9 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2715              : 
    2716            9 :                     n->subtype = AT_DropColumn;
    2717            9 :                     n->name = $5;
    2718            9 :                     n->behavior = $6;
    2719            9 :                     n->missing_ok = true;
    2720            9 :                     $$ = (Node *) n;
    2721              :                 }
    2722              :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2723              :             | DROP opt_column ColId opt_drop_behavior
    2724              :                 {
    2725          808 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2726              : 
    2727          808 :                     n->subtype = AT_DropColumn;
    2728          808 :                     n->name = $3;
    2729          808 :                     n->behavior = $4;
    2730          808 :                     n->missing_ok = false;
    2731          808 :                     $$ = (Node *) n;
    2732              :                 }
    2733              :             /*
    2734              :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2735              :              *      [ USING <expression> ]
    2736              :              */
    2737              :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2738              :                 {
    2739          569 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2740          569 :                     ColumnDef *def = makeNode(ColumnDef);
    2741              : 
    2742          569 :                     n->subtype = AT_AlterColumnType;
    2743          569 :                     n->name = $3;
    2744          569 :                     n->def = (Node *) def;
    2745              :                     /* We only use these fields of the ColumnDef node */
    2746          569 :                     def->typeName = $6;
    2747          569 :                     def->collClause = (CollateClause *) $7;
    2748          569 :                     def->raw_default = $8;
    2749          569 :                     def->location = @3;
    2750          569 :                     $$ = (Node *) n;
    2751              :                 }
    2752              :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2753              :             | ALTER opt_column ColId alter_generic_options
    2754              :                 {
    2755           25 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2756              : 
    2757           25 :                     n->subtype = AT_AlterColumnGenericOptions;
    2758           25 :                     n->name = $3;
    2759           25 :                     n->def = (Node *) $4;
    2760           25 :                     $$ = (Node *) n;
    2761              :                 }
    2762              :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2763              :             | ADD_P TableConstraint
    2764              :                 {
    2765         7478 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2766              : 
    2767         7478 :                     n->subtype = AT_AddConstraint;
    2768         7478 :                     n->def = $2;
    2769         7478 :                     $$ = (Node *) n;
    2770              :                 }
    2771              :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2772              :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2773              :                 {
    2774          123 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2775          123 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2776              : 
    2777          123 :                     n->subtype = AT_AlterConstraint;
    2778          123 :                     n->def = (Node *) c;
    2779          123 :                     c->conname = $3;
    2780          123 :                     if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
    2781           45 :                         c->alterEnforceability = true;
    2782          123 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2783              :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2784           60 :                         c->alterDeferrability = true;
    2785          123 :                     if ($4 & CAS_NO_INHERIT)
    2786           15 :                         c->alterInheritability = true;
    2787              :                     /* handle unsupported case with specific error message */
    2788          123 :                     if ($4 & CAS_NOT_VALID)
    2789            6 :                         ereport(ERROR,
    2790              :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    2791              :                                 errmsg("constraints cannot be altered to be NOT VALID"),
    2792              :                                 parser_errposition(@4));
    2793          117 :                     processCASbits($4, @4, "FOREIGN KEY",
    2794              :                                     &c->deferrable,
    2795              :                                     &c->initdeferred,
    2796              :                                     &c->is_enforced,
    2797              :                                     NULL,
    2798              :                                     &c->noinherit,
    2799              :                                     yyscanner);
    2800          117 :                     $$ = (Node *) n;
    2801              :                 }
    2802              :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2803              :             | ALTER CONSTRAINT name INHERIT
    2804              :                 {
    2805           33 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2806           33 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2807              : 
    2808           33 :                     n->subtype = AT_AlterConstraint;
    2809           33 :                     n->def = (Node *) c;
    2810           33 :                     c->conname = $3;
    2811           33 :                     c->alterInheritability = true;
    2812           33 :                     c->noinherit = false;
    2813              : 
    2814           33 :                     $$ = (Node *) n;
    2815              :                 }
    2816              :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2817              :             | VALIDATE CONSTRAINT name
    2818              :                 {
    2819          241 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2820              : 
    2821          241 :                     n->subtype = AT_ValidateConstraint;
    2822          241 :                     n->name = $3;
    2823          241 :                     $$ = (Node *) n;
    2824              :                 }
    2825              :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2826              :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2827              :                 {
    2828            9 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2829              : 
    2830            9 :                     n->subtype = AT_DropConstraint;
    2831            9 :                     n->name = $5;
    2832            9 :                     n->behavior = $6;
    2833            9 :                     n->missing_ok = true;
    2834            9 :                     $$ = (Node *) n;
    2835              :                 }
    2836              :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2837              :             | DROP CONSTRAINT name opt_drop_behavior
    2838              :                 {
    2839          412 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2840              : 
    2841          412 :                     n->subtype = AT_DropConstraint;
    2842          412 :                     n->name = $3;
    2843          412 :                     n->behavior = $4;
    2844          412 :                     n->missing_ok = false;
    2845          412 :                     $$ = (Node *) n;
    2846              :                 }
    2847              :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2848              :             | SET WITHOUT OIDS
    2849              :                 {
    2850            3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2851              : 
    2852            3 :                     n->subtype = AT_DropOids;
    2853            3 :                     $$ = (Node *) n;
    2854              :                 }
    2855              :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2856              :             | CLUSTER ON name
    2857              :                 {
    2858           23 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2859              : 
    2860           23 :                     n->subtype = AT_ClusterOn;
    2861           23 :                     n->name = $3;
    2862           23 :                     $$ = (Node *) n;
    2863              :                 }
    2864              :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2865              :             | SET WITHOUT CLUSTER
    2866              :                 {
    2867            9 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2868              : 
    2869            9 :                     n->subtype = AT_DropCluster;
    2870            9 :                     n->name = NULL;
    2871            9 :                     $$ = (Node *) n;
    2872              :                 }
    2873              :             /* ALTER TABLE <name> SET LOGGED */
    2874              :             | SET LOGGED
    2875              :                 {
    2876           25 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2877              : 
    2878           25 :                     n->subtype = AT_SetLogged;
    2879           25 :                     $$ = (Node *) n;
    2880              :                 }
    2881              :             /* ALTER TABLE <name> SET UNLOGGED */
    2882              :             | SET UNLOGGED
    2883              :                 {
    2884           31 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2885              : 
    2886           31 :                     n->subtype = AT_SetUnLogged;
    2887           31 :                     $$ = (Node *) n;
    2888              :                 }
    2889              :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2890              :             | ENABLE_P TRIGGER name
    2891              :                 {
    2892           61 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2893              : 
    2894           61 :                     n->subtype = AT_EnableTrig;
    2895           61 :                     n->name = $3;
    2896           61 :                     $$ = (Node *) n;
    2897              :                 }
    2898              :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2899              :             | ENABLE_P ALWAYS TRIGGER name
    2900              :                 {
    2901           21 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2902              : 
    2903           21 :                     n->subtype = AT_EnableAlwaysTrig;
    2904           21 :                     n->name = $4;
    2905           21 :                     $$ = (Node *) n;
    2906              :                 }
    2907              :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2908              :             | ENABLE_P REPLICA TRIGGER name
    2909              :                 {
    2910            8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2911              : 
    2912            8 :                     n->subtype = AT_EnableReplicaTrig;
    2913            8 :                     n->name = $4;
    2914            8 :                     $$ = (Node *) n;
    2915              :                 }
    2916              :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2917              :             | ENABLE_P TRIGGER ALL
    2918              :                 {
    2919            0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2920              : 
    2921            0 :                     n->subtype = AT_EnableTrigAll;
    2922            0 :                     $$ = (Node *) n;
    2923              :                 }
    2924              :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2925              :             | ENABLE_P TRIGGER USER
    2926              :                 {
    2927            0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2928              : 
    2929            0 :                     n->subtype = AT_EnableTrigUser;
    2930            0 :                     $$ = (Node *) n;
    2931              :                 }
    2932              :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2933              :             | DISABLE_P TRIGGER name
    2934              :                 {
    2935           69 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2936              : 
    2937           69 :                     n->subtype = AT_DisableTrig;
    2938           69 :                     n->name = $3;
    2939           69 :                     $$ = (Node *) n;
    2940              :                 }
    2941              :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2942              :             | DISABLE_P TRIGGER ALL
    2943              :                 {
    2944            6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2945              : 
    2946            6 :                     n->subtype = AT_DisableTrigAll;
    2947            6 :                     $$ = (Node *) n;
    2948              :                 }
    2949              :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2950              :             | DISABLE_P TRIGGER USER
    2951              :                 {
    2952            6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2953              : 
    2954            6 :                     n->subtype = AT_DisableTrigUser;
    2955            6 :                     $$ = (Node *) n;
    2956              :                 }
    2957              :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2958              :             | ENABLE_P RULE name
    2959              :                 {
    2960            4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2961              : 
    2962            4 :                     n->subtype = AT_EnableRule;
    2963            4 :                     n->name = $3;
    2964            4 :                     $$ = (Node *) n;
    2965              :                 }
    2966              :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2967              :             | ENABLE_P ALWAYS RULE name
    2968              :                 {
    2969            0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2970              : 
    2971            0 :                     n->subtype = AT_EnableAlwaysRule;
    2972            0 :                     n->name = $4;
    2973            0 :                     $$ = (Node *) n;
    2974              :                 }
    2975              :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2976              :             | ENABLE_P REPLICA RULE name
    2977              :                 {
    2978            3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2979              : 
    2980            3 :                     n->subtype = AT_EnableReplicaRule;
    2981            3 :                     n->name = $4;
    2982            3 :                     $$ = (Node *) n;
    2983              :                 }
    2984              :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2985              :             | DISABLE_P RULE name
    2986              :                 {
    2987           16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2988              : 
    2989           16 :                     n->subtype = AT_DisableRule;
    2990           16 :                     n->name = $3;
    2991           16 :                     $$ = (Node *) n;
    2992              :                 }
    2993              :             /* ALTER TABLE <name> INHERIT <parent> */
    2994              :             | INHERIT qualified_name
    2995              :                 {
    2996          232 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2997              : 
    2998          232 :                     n->subtype = AT_AddInherit;
    2999          232 :                     n->def = (Node *) $2;
    3000          232 :                     $$ = (Node *) n;
    3001              :                 }
    3002              :             /* ALTER TABLE <name> NO INHERIT <parent> */
    3003              :             | NO INHERIT qualified_name
    3004              :                 {
    3005           47 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3006              : 
    3007           47 :                     n->subtype = AT_DropInherit;
    3008           47 :                     n->def = (Node *) $3;
    3009           47 :                     $$ = (Node *) n;
    3010              :                 }
    3011              :             /* ALTER TABLE <name> OF <type_name> */
    3012              :             | OF any_name
    3013              :                 {
    3014           33 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3015           33 :                     TypeName   *def = makeTypeNameFromNameList($2);
    3016              : 
    3017           33 :                     def->location = @2;
    3018           33 :                     n->subtype = AT_AddOf;
    3019           33 :                     n->def = (Node *) def;
    3020           33 :                     $$ = (Node *) n;
    3021              :                 }
    3022              :             /* ALTER TABLE <name> NOT OF */
    3023              :             | NOT OF
    3024              :                 {
    3025            3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3026              : 
    3027            3 :                     n->subtype = AT_DropOf;
    3028            3 :                     $$ = (Node *) n;
    3029              :                 }
    3030              :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    3031              :             | OWNER TO RoleSpec
    3032              :                 {
    3033         1041 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3034              : 
    3035         1041 :                     n->subtype = AT_ChangeOwner;
    3036         1041 :                     n->newowner = $3;
    3037         1041 :                     $$ = (Node *) n;
    3038              :                 }
    3039              :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    3040              :             | SET ACCESS METHOD set_access_method_name
    3041              :                 {
    3042           64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3043              : 
    3044           64 :                     n->subtype = AT_SetAccessMethod;
    3045           64 :                     n->name = $4;
    3046           64 :                     $$ = (Node *) n;
    3047              :                 }
    3048              :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    3049              :             | SET TABLESPACE name
    3050              :                 {
    3051           58 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3052              : 
    3053           58 :                     n->subtype = AT_SetTableSpace;
    3054           58 :                     n->name = $3;
    3055           58 :                     $$ = (Node *) n;
    3056              :                 }
    3057              :             /* ALTER TABLE <name> SET (...) */
    3058              :             | SET reloptions
    3059              :                 {
    3060          313 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3061              : 
    3062          313 :                     n->subtype = AT_SetRelOptions;
    3063          313 :                     n->def = (Node *) $2;
    3064          313 :                     $$ = (Node *) n;
    3065              :                 }
    3066              :             /* ALTER TABLE <name> RESET (...) */
    3067              :             | RESET reloptions
    3068              :                 {
    3069           87 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3070              : 
    3071           87 :                     n->subtype = AT_ResetRelOptions;
    3072           87 :                     n->def = (Node *) $2;
    3073           87 :                     $$ = (Node *) n;
    3074              :                 }
    3075              :             /* ALTER TABLE <name> REPLICA IDENTITY */
    3076              :             | REPLICA IDENTITY_P replica_identity
    3077              :                 {
    3078          247 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3079              : 
    3080          247 :                     n->subtype = AT_ReplicaIdentity;
    3081          247 :                     n->def = $3;
    3082          247 :                     $$ = (Node *) n;
    3083              :                 }
    3084              :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    3085              :             | ENABLE_P ROW LEVEL SECURITY
    3086              :                 {
    3087          169 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3088              : 
    3089          169 :                     n->subtype = AT_EnableRowSecurity;
    3090          169 :                     $$ = (Node *) n;
    3091              :                 }
    3092              :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    3093              :             | DISABLE_P ROW LEVEL SECURITY
    3094              :                 {
    3095            5 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3096              : 
    3097            5 :                     n->subtype = AT_DisableRowSecurity;
    3098            5 :                     $$ = (Node *) n;
    3099              :                 }
    3100              :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    3101              :             | FORCE ROW LEVEL SECURITY
    3102              :                 {
    3103           50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3104              : 
    3105           50 :                     n->subtype = AT_ForceRowSecurity;
    3106           50 :                     $$ = (Node *) n;
    3107              :                 }
    3108              :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    3109              :             | NO FORCE ROW LEVEL SECURITY
    3110              :                 {
    3111           16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3112              : 
    3113           16 :                     n->subtype = AT_NoForceRowSecurity;
    3114           16 :                     $$ = (Node *) n;
    3115              :                 }
    3116              :             | alter_generic_options
    3117              :                 {
    3118           32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3119              : 
    3120           32 :                     n->subtype = AT_GenericOptions;
    3121           32 :                     n->def = (Node *) $1;
    3122           32 :                     $$ = (Node *) n;
    3123              :                 }
    3124              :         ;
    3125              : 
    3126              : alter_column_default:
    3127          189 :             SET DEFAULT a_expr          { $$ = $3; }
    3128           93 :             | DROP DEFAULT              { $$ = NULL; }
    3129              :         ;
    3130              : 
    3131              : opt_collate_clause:
    3132              :             COLLATE any_name
    3133              :                 {
    3134            9 :                     CollateClause *n = makeNode(CollateClause);
    3135              : 
    3136            9 :                     n->arg = NULL;
    3137            9 :                     n->collname = $2;
    3138            9 :                     n->location = @1;
    3139            9 :                     $$ = (Node *) n;
    3140              :                 }
    3141         2432 :             | /* EMPTY */               { $$ = NULL; }
    3142              :         ;
    3143              : 
    3144              : alter_using:
    3145           90 :             USING a_expr                { $$ = $2; }
    3146          479 :             | /* EMPTY */               { $$ = NULL; }
    3147              :         ;
    3148              : 
    3149              : replica_identity:
    3150              :             NOTHING
    3151              :                 {
    3152           24 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3153              : 
    3154           24 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3155           24 :                     n->name = NULL;
    3156           24 :                     $$ = (Node *) n;
    3157              :                 }
    3158              :             | FULL
    3159              :                 {
    3160           85 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3161              : 
    3162           85 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3163           85 :                     n->name = NULL;
    3164           85 :                     $$ = (Node *) n;
    3165              :                 }
    3166              :             | DEFAULT
    3167              :                 {
    3168            3 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3169              : 
    3170            3 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3171            3 :                     n->name = NULL;
    3172            3 :                     $$ = (Node *) n;
    3173              :                 }
    3174              :             | USING INDEX name
    3175              :                 {
    3176          135 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3177              : 
    3178          135 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3179          135 :                     n->name = $3;
    3180          135 :                     $$ = (Node *) n;
    3181              :                 }
    3182              : ;
    3183              : 
    3184              : reloptions:
    3185         1435 :             '(' reloption_list ')'                  { $$ = $2; }
    3186              :         ;
    3187              : 
    3188          487 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3189        11984 :              |      /* EMPTY */                     { $$ = NIL; }
    3190              :         ;
    3191              : 
    3192              : reloption_list:
    3193         1435 :             reloption_elem                          { $$ = list_make1($1); }
    3194          127 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3195              :         ;
    3196              : 
    3197              : /* This should match def_elem and also allow qualified names */
    3198              : reloption_elem:
    3199              :             ColLabel '=' def_arg
    3200              :                 {
    3201         1222 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3202              :                 }
    3203              :             | ColLabel
    3204              :                 {
    3205          301 :                     $$ = makeDefElem($1, NULL, @1);
    3206              :                 }
    3207              :             | ColLabel '.' ColLabel '=' def_arg
    3208              :                 {
    3209           36 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3210           36 :                                              DEFELEM_UNSPEC, @1);
    3211              :                 }
    3212              :             | ColLabel '.' ColLabel
    3213              :                 {
    3214            3 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3215              :                 }
    3216              :         ;
    3217              : 
    3218              : alter_identity_column_option_list:
    3219              :             alter_identity_column_option
    3220           31 :                 { $$ = list_make1($1); }
    3221              :             | alter_identity_column_option_list alter_identity_column_option
    3222           30 :                 { $$ = lappend($1, $2); }
    3223              :         ;
    3224              : 
    3225              : alter_identity_column_option:
    3226              :             RESTART
    3227              :                 {
    3228           12 :                     $$ = makeDefElem("restart", NULL, @1);
    3229              :                 }
    3230              :             | RESTART opt_with NumericOnly
    3231              :                 {
    3232            0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3233              :                 }
    3234              :             | SET SeqOptElem
    3235              :                 {
    3236           27 :                     if (strcmp($2->defname, "as") == 0 ||
    3237           27 :                         strcmp($2->defname, "restart") == 0 ||
    3238           27 :                         strcmp($2->defname, "owned_by") == 0)
    3239            0 :                         ereport(ERROR,
    3240              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3241              :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3242              :                                  parser_errposition(@2)));
    3243           27 :                     $$ = $2;
    3244              :                 }
    3245              :             | SET GENERATED generated_when
    3246              :                 {
    3247           22 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3248              :                 }
    3249              :         ;
    3250              : 
    3251              : set_statistics_value:
    3252           79 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3253            0 :             | DEFAULT                       { $$ = NULL; }
    3254              :         ;
    3255              : 
    3256              : set_access_method_name:
    3257           46 :             ColId                           { $$ = $1; }
    3258           18 :             | DEFAULT                       { $$ = NULL; }
    3259              :         ;
    3260              : 
    3261              : PartitionBoundSpec:
    3262              :             /* a HASH partition */
    3263              :             FOR VALUES WITH '(' hash_partbound ')'
    3264              :                 {
    3265              :                     ListCell   *lc;
    3266          387 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3267              : 
    3268          387 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3269          387 :                     n->modulus = n->remainder = -1;
    3270              : 
    3271         1161 :                     foreach (lc, $5)
    3272              :                     {
    3273          774 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3274              : 
    3275          774 :                         if (strcmp(opt->defname, "modulus") == 0)
    3276              :                         {
    3277          387 :                             if (n->modulus != -1)
    3278            0 :                                 ereport(ERROR,
    3279              :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3280              :                                          errmsg("modulus for hash partition provided more than once"),
    3281              :                                          parser_errposition(opt->location)));
    3282          387 :                             n->modulus = defGetInt32(opt);
    3283              :                         }
    3284          387 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3285              :                         {
    3286          387 :                             if (n->remainder != -1)
    3287            0 :                                 ereport(ERROR,
    3288              :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3289              :                                          errmsg("remainder for hash partition provided more than once"),
    3290              :                                          parser_errposition(opt->location)));
    3291          387 :                             n->remainder = defGetInt32(opt);
    3292              :                         }
    3293              :                         else
    3294            0 :                             ereport(ERROR,
    3295              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3296              :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3297              :                                             opt->defname),
    3298              :                                      parser_errposition(opt->location)));
    3299              :                     }
    3300              : 
    3301          387 :                     if (n->modulus == -1)
    3302            0 :                         ereport(ERROR,
    3303              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3304              :                                  errmsg("modulus for hash partition must be specified"),
    3305              :                                  parser_errposition(@3)));
    3306          387 :                     if (n->remainder == -1)
    3307            0 :                         ereport(ERROR,
    3308              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3309              :                                  errmsg("remainder for hash partition must be specified"),
    3310              :                                  parser_errposition(@3)));
    3311              : 
    3312          387 :                     n->location = @3;
    3313              : 
    3314          387 :                     $$ = n;
    3315              :                 }
    3316              : 
    3317              :             /* a LIST partition */
    3318              :             | FOR VALUES IN_P '(' expr_list ')'
    3319              :                 {
    3320         2654 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3321              : 
    3322         2654 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3323         2654 :                     n->is_default = false;
    3324         2654 :                     n->listdatums = $5;
    3325         2654 :                     n->location = @3;
    3326              : 
    3327         2654 :                     $$ = n;
    3328              :                 }
    3329              : 
    3330              :             /* a RANGE partition */
    3331              :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3332              :                 {
    3333         2963 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3334              : 
    3335         2963 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3336         2963 :                     n->is_default = false;
    3337         2963 :                     n->lowerdatums = $5;
    3338         2963 :                     n->upperdatums = $9;
    3339         2963 :                     n->location = @3;
    3340              : 
    3341         2963 :                     $$ = n;
    3342              :                 }
    3343              : 
    3344              :             /* a DEFAULT partition */
    3345              :             | DEFAULT
    3346              :                 {
    3347          423 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3348              : 
    3349          423 :                     n->is_default = true;
    3350          423 :                     n->location = @1;
    3351              : 
    3352          423 :                     $$ = n;
    3353              :                 }
    3354              :         ;
    3355              : 
    3356              : hash_partbound_elem:
    3357              :         NonReservedWord Iconst
    3358              :             {
    3359          774 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3360              :             }
    3361              :         ;
    3362              : 
    3363              : hash_partbound:
    3364              :         hash_partbound_elem
    3365              :             {
    3366          387 :                 $$ = list_make1($1);
    3367              :             }
    3368              :         | hash_partbound ',' hash_partbound_elem
    3369              :             {
    3370          387 :                 $$ = lappend($1, $3);
    3371              :             }
    3372              :         ;
    3373              : 
    3374              : /*****************************************************************************
    3375              :  *
    3376              :  *  ALTER TYPE
    3377              :  *
    3378              :  * really variants of the ALTER TABLE subcommands with different spellings
    3379              :  *****************************************************************************/
    3380              : 
    3381              : AlterCompositeTypeStmt:
    3382              :             ALTER TYPE_P any_name alter_type_cmds
    3383              :                 {
    3384          105 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3385              : 
    3386              :                     /* can't use qualified_name, sigh */
    3387          105 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3388          105 :                     n->cmds = $4;
    3389          105 :                     n->objtype = OBJECT_TYPE;
    3390          105 :                     $$ = (Node *) n;
    3391              :                 }
    3392              :             ;
    3393              : 
    3394              : alter_type_cmds:
    3395          105 :             alter_type_cmd                          { $$ = list_make1($1); }
    3396            6 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3397              :         ;
    3398              : 
    3399              : alter_type_cmd:
    3400              :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3401              :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3402              :                 {
    3403           32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3404              : 
    3405           32 :                     n->subtype = AT_AddColumn;
    3406           32 :                     n->def = $3;
    3407           32 :                     n->behavior = $4;
    3408           32 :                     $$ = (Node *) n;
    3409              :                 }
    3410              :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3411              :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3412              :                 {
    3413            3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3414              : 
    3415            3 :                     n->subtype = AT_DropColumn;
    3416            3 :                     n->name = $5;
    3417            3 :                     n->behavior = $6;
    3418            3 :                     n->missing_ok = true;
    3419            3 :                     $$ = (Node *) n;
    3420              :                 }
    3421              :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3422              :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3423              :                 {
    3424           39 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3425              : 
    3426           39 :                     n->subtype = AT_DropColumn;
    3427           39 :                     n->name = $3;
    3428           39 :                     n->behavior = $4;
    3429           39 :                     n->missing_ok = false;
    3430           39 :                     $$ = (Node *) n;
    3431              :                 }
    3432              :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3433              :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3434              :                 {
    3435           37 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3436           37 :                     ColumnDef *def = makeNode(ColumnDef);
    3437              : 
    3438           37 :                     n->subtype = AT_AlterColumnType;
    3439           37 :                     n->name = $3;
    3440           37 :                     n->def = (Node *) def;
    3441           37 :                     n->behavior = $8;
    3442              :                     /* We only use these fields of the ColumnDef node */
    3443           37 :                     def->typeName = $6;
    3444           37 :                     def->collClause = (CollateClause *) $7;
    3445           37 :                     def->raw_default = NULL;
    3446           37 :                     def->location = @3;
    3447           37 :                     $$ = (Node *) n;
    3448              :                 }
    3449              :         ;
    3450              : 
    3451              : 
    3452              : /*****************************************************************************
    3453              :  *
    3454              :  *      QUERY :
    3455              :  *              close <portalname>
    3456              :  *
    3457              :  *****************************************************************************/
    3458              : 
    3459              : ClosePortalStmt:
    3460              :             CLOSE cursor_name
    3461              :                 {
    3462         1124 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3463              : 
    3464         1124 :                     n->portalname = $2;
    3465         1124 :                     $$ = (Node *) n;
    3466              :                 }
    3467              :             | CLOSE ALL
    3468              :                 {
    3469            6 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3470              : 
    3471            6 :                     n->portalname = NULL;
    3472            6 :                     $$ = (Node *) n;
    3473              :                 }
    3474              :         ;
    3475              : 
    3476              : 
    3477              : /*****************************************************************************
    3478              :  *
    3479              :  *      QUERY :
    3480              :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3481              :  *              COPY ( query ) TO file  [WITH] [(options)]
    3482              :  *
    3483              :  *              where 'query' can be one of:
    3484              :  *              { SELECT | UPDATE | INSERT | DELETE | MERGE }
    3485              :  *
    3486              :  *              and 'file' can be one of:
    3487              :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3488              :  *
    3489              :  *              In the preferred syntax the options are comma-separated
    3490              :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3491              :  *              syntax had a hard-wired, space-separated set of options.
    3492              :  *
    3493              :  *              Really old syntax, from versions 7.2 and prior:
    3494              :  *              COPY [ BINARY ] table FROM/TO file
    3495              :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3496              :  *                  [ WITH NULL AS 'null string' ]
    3497              :  *              This option placement is not supported with COPY (query...).
    3498              :  *
    3499              :  *****************************************************************************/
    3500              : 
    3501              : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3502              :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3503              :             copy_options where_clause
    3504              :                 {
    3505         5602 :                     CopyStmt *n = makeNode(CopyStmt);
    3506              : 
    3507         5602 :                     n->relation = $3;
    3508         5602 :                     n->query = NULL;
    3509         5602 :                     n->attlist = $4;
    3510         5602 :                     n->is_from = $5;
    3511         5602 :                     n->is_program = $6;
    3512         5602 :                     n->filename = $7;
    3513         5602 :                     n->whereClause = $11;
    3514              : 
    3515         5602 :                     if (n->is_program && n->filename == NULL)
    3516            0 :                         ereport(ERROR,
    3517              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3518              :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3519              :                                  parser_errposition(@8)));
    3520              : 
    3521         5602 :                     if (!n->is_from && n->whereClause != NULL)
    3522            3 :                         ereport(ERROR,
    3523              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3524              :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3525              :                                  errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
    3526              :                                  parser_errposition(@11)));
    3527              : 
    3528         5599 :                     n->options = NIL;
    3529              :                     /* Concatenate user-supplied flags */
    3530         5599 :                     if ($2)
    3531            6 :                         n->options = lappend(n->options, $2);
    3532         5599 :                     if ($8)
    3533            0 :                         n->options = lappend(n->options, $8);
    3534         5599 :                     if ($10)
    3535          521 :                         n->options = list_concat(n->options, $10);
    3536         5599 :                     $$ = (Node *) n;
    3537              :                 }
    3538              :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3539              :                 {
    3540          262 :                     CopyStmt *n = makeNode(CopyStmt);
    3541              : 
    3542          262 :                     n->relation = NULL;
    3543          262 :                     n->query = $3;
    3544          262 :                     n->attlist = NIL;
    3545          262 :                     n->is_from = false;
    3546          262 :                     n->is_program = $6;
    3547          262 :                     n->filename = $7;
    3548          262 :                     n->options = $9;
    3549              : 
    3550          262 :                     if (n->is_program && n->filename == NULL)
    3551            0 :                         ereport(ERROR,
    3552              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3553              :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3554              :                                  parser_errposition(@5)));
    3555              : 
    3556          262 :                     $$ = (Node *) n;
    3557              :                 }
    3558              :         ;
    3559              : 
    3560              : copy_from:
    3561          936 :             FROM                                    { $$ = true; }
    3562         4666 :             | TO                                    { $$ = false; }
    3563              :         ;
    3564              : 
    3565              : opt_program:
    3566            0 :             PROGRAM                                 { $$ = true; }
    3567         5864 :             | /* EMPTY */                           { $$ = false; }
    3568              :         ;
    3569              : 
    3570              : /*
    3571              :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3572              :  * used depends on the direction. (It really doesn't make sense to copy from
    3573              :  * stdout. We silently correct the "typo".)        - AY 9/94
    3574              :  */
    3575              : copy_file_name:
    3576          243 :             Sconst                                  { $$ = $1; }
    3577          731 :             | STDIN                                 { $$ = NULL; }
    3578         4890 :             | STDOUT                                { $$ = NULL; }
    3579              :         ;
    3580              : 
    3581         5476 : copy_options: copy_opt_list                         { $$ = $1; }
    3582          388 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3583              :         ;
    3584              : 
    3585              : /* old COPY option syntax */
    3586              : copy_opt_list:
    3587          256 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3588         5476 :             | /* EMPTY */                           { $$ = NIL; }
    3589              :         ;
    3590              : 
    3591              : copy_opt_item:
    3592              :             BINARY
    3593              :                 {
    3594            0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3595              :                 }
    3596              :             | FREEZE
    3597              :                 {
    3598           25 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3599              :                 }
    3600              :             | DELIMITER opt_as Sconst
    3601              :                 {
    3602           90 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3603              :                 }
    3604              :             | NULL_P opt_as Sconst
    3605              :                 {
    3606           24 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3607              :                 }
    3608              :             | CSV
    3609              :                 {
    3610           75 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3611              :                 }
    3612              :             | HEADER_P
    3613              :                 {
    3614            9 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3615              :                 }
    3616              :             | QUOTE opt_as Sconst
    3617              :                 {
    3618            9 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3619              :                 }
    3620              :             | ESCAPE opt_as Sconst
    3621              :                 {
    3622            9 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3623              :                 }
    3624              :             | FORCE QUOTE columnList
    3625              :                 {
    3626            6 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3627              :                 }
    3628              :             | FORCE QUOTE '*'
    3629              :                 {
    3630            3 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3631              :                 }
    3632              :             | FORCE NOT NULL_P columnList
    3633              :                 {
    3634            0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3635              :                 }
    3636              :             | FORCE NOT NULL_P '*'
    3637              :                 {
    3638            0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3639              :                 }
    3640              :             | FORCE NULL_P columnList
    3641              :                 {
    3642            0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3643              :                 }
    3644              :             | FORCE NULL_P '*'
    3645              :                 {
    3646            0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3647              :                 }
    3648              :             | ENCODING Sconst
    3649              :                 {
    3650            6 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3651              :                 }
    3652              :         ;
    3653              : 
    3654              : /* The following exist for backward compatibility with very old versions */
    3655              : 
    3656              : opt_binary:
    3657              :             BINARY
    3658              :                 {
    3659            6 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3660              :                 }
    3661         5596 :             | /*EMPTY*/                             { $$ = NULL; }
    3662              :         ;
    3663              : 
    3664              : copy_delimiter:
    3665              :             opt_using DELIMITERS Sconst
    3666              :                 {
    3667            0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3668              :                 }
    3669         5602 :             | /*EMPTY*/                             { $$ = NULL; }
    3670              :         ;
    3671              : 
    3672              : opt_using:
    3673              :             USING
    3674              :             | /*EMPTY*/
    3675              :         ;
    3676              : 
    3677              : /* new COPY option syntax */
    3678              : copy_generic_opt_list:
    3679              :             copy_generic_opt_elem
    3680              :                 {
    3681          388 :                     $$ = list_make1($1);
    3682              :                 }
    3683              :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3684              :                 {
    3685          252 :                     $$ = lappend($1, $3);
    3686              :                 }
    3687              :         ;
    3688              : 
    3689              : copy_generic_opt_elem:
    3690              :             ColLabel copy_generic_opt_arg
    3691              :                 {
    3692          640 :                     $$ = makeDefElem($1, $2, @1);
    3693              :                 }
    3694              :         ;
    3695              : 
    3696              : copy_generic_opt_arg:
    3697          463 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3698           30 :             | NumericOnly                   { $$ = (Node *) $1; }
    3699           45 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3700            3 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3701           75 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3702           24 :             | /* EMPTY */                   { $$ = NULL; }
    3703              :         ;
    3704              : 
    3705              : copy_generic_opt_arg_list:
    3706              :               copy_generic_opt_arg_list_item
    3707              :                 {
    3708           75 :                     $$ = list_make1($1);
    3709              :                 }
    3710              :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3711              :                 {
    3712            6 :                     $$ = lappend($1, $3);
    3713              :                 }
    3714              :         ;
    3715              : 
    3716              : /* beware of emitting non-string list elements here; see commands/define.c */
    3717              : copy_generic_opt_arg_list_item:
    3718           81 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3719              :         ;
    3720              : 
    3721              : 
    3722              : /*****************************************************************************
    3723              :  *
    3724              :  *      QUERY :
    3725              :  *              CREATE TABLE relname
    3726              :  *
    3727              :  *****************************************************************************/
    3728              : 
    3729              : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3730              :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3731              :             OnCommitOption OptTableSpace
    3732              :                 {
    3733        15511 :                     CreateStmt *n = makeNode(CreateStmt);
    3734              : 
    3735        15511 :                     $4->relpersistence = $2;
    3736        15511 :                     n->relation = $4;
    3737        15511 :                     n->tableElts = $6;
    3738        15511 :                     n->inhRelations = $8;
    3739        15511 :                     n->partspec = $9;
    3740        15511 :                     n->ofTypename = NULL;
    3741        15511 :                     n->constraints = NIL;
    3742        15511 :                     n->accessMethod = $10;
    3743        15511 :                     n->options = $11;
    3744        15511 :                     n->oncommit = $12;
    3745        15511 :                     n->tablespacename = $13;
    3746        15511 :                     n->if_not_exists = false;
    3747        15511 :                     $$ = (Node *) n;
    3748              :                 }
    3749              :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3750              :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3751              :             OptWith OnCommitOption OptTableSpace
    3752              :                 {
    3753           15 :                     CreateStmt *n = makeNode(CreateStmt);
    3754              : 
    3755           15 :                     $7->relpersistence = $2;
    3756           15 :                     n->relation = $7;
    3757           15 :                     n->tableElts = $9;
    3758           15 :                     n->inhRelations = $11;
    3759           15 :                     n->partspec = $12;
    3760           15 :                     n->ofTypename = NULL;
    3761           15 :                     n->constraints = NIL;
    3762           15 :                     n->accessMethod = $13;
    3763           15 :                     n->options = $14;
    3764           15 :                     n->oncommit = $15;
    3765           15 :                     n->tablespacename = $16;
    3766           15 :                     n->if_not_exists = true;
    3767           15 :                     $$ = (Node *) n;
    3768              :                 }
    3769              :         | CREATE OptTemp TABLE qualified_name OF any_name
    3770              :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3771              :             OptWith OnCommitOption OptTableSpace
    3772              :                 {
    3773           61 :                     CreateStmt *n = makeNode(CreateStmt);
    3774              : 
    3775           61 :                     $4->relpersistence = $2;
    3776           61 :                     n->relation = $4;
    3777           61 :                     n->tableElts = $7;
    3778           61 :                     n->inhRelations = NIL;
    3779           61 :                     n->partspec = $8;
    3780           61 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3781           61 :                     n->ofTypename->location = @6;
    3782           61 :                     n->constraints = NIL;
    3783           61 :                     n->accessMethod = $9;
    3784           61 :                     n->options = $10;
    3785           61 :                     n->oncommit = $11;
    3786           61 :                     n->tablespacename = $12;
    3787           61 :                     n->if_not_exists = false;
    3788           61 :                     $$ = (Node *) n;
    3789              :                 }
    3790              :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3791              :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3792              :             OptWith OnCommitOption OptTableSpace
    3793              :                 {
    3794            3 :                     CreateStmt *n = makeNode(CreateStmt);
    3795              : 
    3796            3 :                     $7->relpersistence = $2;
    3797            3 :                     n->relation = $7;
    3798            3 :                     n->tableElts = $10;
    3799            3 :                     n->inhRelations = NIL;
    3800            3 :                     n->partspec = $11;
    3801            3 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3802            3 :                     n->ofTypename->location = @9;
    3803            3 :                     n->constraints = NIL;
    3804            3 :                     n->accessMethod = $12;
    3805            3 :                     n->options = $13;
    3806            3 :                     n->oncommit = $14;
    3807            3 :                     n->tablespacename = $15;
    3808            3 :                     n->if_not_exists = true;
    3809            3 :                     $$ = (Node *) n;
    3810              :                 }
    3811              :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3812              :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3813              :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3814              :                 {
    3815         4550 :                     CreateStmt *n = makeNode(CreateStmt);
    3816              : 
    3817         4550 :                     $4->relpersistence = $2;
    3818         4550 :                     n->relation = $4;
    3819         4550 :                     n->tableElts = $8;
    3820         4550 :                     n->inhRelations = list_make1($7);
    3821         4550 :                     n->partbound = $9;
    3822         4550 :                     n->partspec = $10;
    3823         4550 :                     n->ofTypename = NULL;
    3824         4550 :                     n->constraints = NIL;
    3825         4550 :                     n->accessMethod = $11;
    3826         4550 :                     n->options = $12;
    3827         4550 :                     n->oncommit = $13;
    3828         4550 :                     n->tablespacename = $14;
    3829         4550 :                     n->if_not_exists = false;
    3830         4550 :                     $$ = (Node *) n;
    3831              :                 }
    3832              :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3833              :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3834              :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3835              :                 {
    3836            0 :                     CreateStmt *n = makeNode(CreateStmt);
    3837              : 
    3838            0 :                     $7->relpersistence = $2;
    3839            0 :                     n->relation = $7;
    3840            0 :                     n->tableElts = $11;
    3841            0 :                     n->inhRelations = list_make1($10);
    3842            0 :                     n->partbound = $12;
    3843            0 :                     n->partspec = $13;
    3844            0 :                     n->ofTypename = NULL;
    3845            0 :                     n->constraints = NIL;
    3846            0 :                     n->accessMethod = $14;
    3847            0 :                     n->options = $15;
    3848            0 :                     n->oncommit = $16;
    3849            0 :                     n->tablespacename = $17;
    3850            0 :                     n->if_not_exists = true;
    3851            0 :                     $$ = (Node *) n;
    3852              :                 }
    3853              :         ;
    3854              : 
    3855              : /*
    3856              :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3857              :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3858              :  *
    3859              :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3860              :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3861              :  * temp table behavior, so warn about that.  Since we have no modules the
    3862              :  * LOCAL keyword is really meaningless; furthermore, some other products
    3863              :  * implement LOCAL as meaning the same as our default temp table behavior,
    3864              :  * so we'll probably continue to treat LOCAL as a noise word.
    3865              :  */
    3866          176 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3867         1461 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3868            0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3869            0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3870              :             | GLOBAL TEMPORARY
    3871              :                 {
    3872            0 :                     ereport(WARNING,
    3873              :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3874              :                              parser_errposition(@1)));
    3875            0 :                     $$ = RELPERSISTENCE_TEMP;
    3876              :                 }
    3877              :             | GLOBAL TEMP
    3878              :                 {
    3879            0 :                     ereport(WARNING,
    3880              :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3881              :                              parser_errposition(@1)));
    3882            0 :                     $$ = RELPERSISTENCE_TEMP;
    3883              :                 }
    3884           85 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3885        28224 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3886              :         ;
    3887              : 
    3888              : OptTableElementList:
    3889        14922 :             TableElementList                    { $$ = $1; }
    3890          840 :             | /*EMPTY*/                         { $$ = NIL; }
    3891              :         ;
    3892              : 
    3893              : OptTypedTableElementList:
    3894          178 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3895         4484 :             | /*EMPTY*/                         { $$ = NIL; }
    3896              :         ;
    3897              : 
    3898              : TableElementList:
    3899              :             TableElement
    3900              :                 {
    3901        14949 :                     $$ = list_make1($1);
    3902              :                 }
    3903              :             | TableElementList ',' TableElement
    3904              :                 {
    3905        21051 :                     $$ = lappend($1, $3);
    3906              :                 }
    3907              :         ;
    3908              : 
    3909              : TypedTableElementList:
    3910              :             TypedTableElement
    3911              :                 {
    3912          178 :                     $$ = list_make1($1);
    3913              :                 }
    3914              :             | TypedTableElementList ',' TypedTableElement
    3915              :                 {
    3916           34 :                     $$ = lappend($1, $3);
    3917              :                 }
    3918              :         ;
    3919              : 
    3920              : TableElement:
    3921        34215 :             columnDef                           { $$ = $1; }
    3922          393 :             | TableLikeClause                   { $$ = $1; }
    3923         1392 :             | TableConstraint                   { $$ = $1; }
    3924              :         ;
    3925              : 
    3926              : TypedTableElement:
    3927          180 :             columnOptions                       { $$ = $1; }
    3928           32 :             | TableConstraint                   { $$ = $1; }
    3929              :         ;
    3930              : 
    3931              : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3932              :                 {
    3933        35307 :                     ColumnDef *n = makeNode(ColumnDef);
    3934              : 
    3935        35307 :                     n->colname = $1;
    3936        35307 :                     n->typeName = $2;
    3937        35307 :                     n->storage_name = $3;
    3938        35307 :                     n->compression = $4;
    3939        35307 :                     n->inhcount = 0;
    3940        35307 :                     n->is_local = true;
    3941        35307 :                     n->is_not_null = false;
    3942        35307 :                     n->is_from_type = false;
    3943        35307 :                     n->storage = 0;
    3944        35307 :                     n->raw_default = NULL;
    3945        35307 :                     n->cooked_default = NULL;
    3946        35307 :                     n->collOid = InvalidOid;
    3947        35307 :                     n->fdwoptions = $5;
    3948        35307 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3949              :                                      yyscanner);
    3950        35307 :                     n->location = @1;
    3951        35307 :                     $$ = (Node *) n;
    3952              :                 }
    3953              :         ;
    3954              : 
    3955              : columnOptions:  ColId ColQualList
    3956              :                 {
    3957           69 :                     ColumnDef *n = makeNode(ColumnDef);
    3958              : 
    3959           69 :                     n->colname = $1;
    3960           69 :                     n->typeName = NULL;
    3961           69 :                     n->inhcount = 0;
    3962           69 :                     n->is_local = true;
    3963           69 :                     n->is_not_null = false;
    3964           69 :                     n->is_from_type = false;
    3965           69 :                     n->storage = 0;
    3966           69 :                     n->raw_default = NULL;
    3967           69 :                     n->cooked_default = NULL;
    3968           69 :                     n->collOid = InvalidOid;
    3969           69 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3970              :                                      yyscanner);
    3971           69 :                     n->location = @1;
    3972           69 :                     $$ = (Node *) n;
    3973              :                 }
    3974              :                 | ColId WITH OPTIONS ColQualList
    3975              :                 {
    3976          111 :                     ColumnDef *n = makeNode(ColumnDef);
    3977              : 
    3978          111 :                     n->colname = $1;
    3979          111 :                     n->typeName = NULL;
    3980          111 :                     n->inhcount = 0;
    3981          111 :                     n->is_local = true;
    3982          111 :                     n->is_not_null = false;
    3983          111 :                     n->is_from_type = false;
    3984          111 :                     n->storage = 0;
    3985          111 :                     n->raw_default = NULL;
    3986          111 :                     n->cooked_default = NULL;
    3987          111 :                     n->collOid = InvalidOid;
    3988          111 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3989              :                                      yyscanner);
    3990          111 :                     n->location = @1;
    3991          111 :                     $$ = (Node *) n;
    3992              :                 }
    3993              :         ;
    3994              : 
    3995              : column_compression:
    3996           89 :             COMPRESSION ColId                       { $$ = $2; }
    3997            3 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3998              :         ;
    3999              : 
    4000              : opt_column_compression:
    4001           53 :             column_compression                      { $$ = $1; }
    4002        35287 :             | /*EMPTY*/                             { $$ = NULL; }
    4003              :         ;
    4004              : 
    4005              : column_storage:
    4006          157 :             STORAGE ColId                           { $$ = $2; }
    4007            3 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    4008              :         ;
    4009              : 
    4010              : opt_column_storage:
    4011           29 :             column_storage                          { $$ = $1; }
    4012        35311 :             | /*EMPTY*/                             { $$ = NULL; }
    4013              :         ;
    4014              : 
    4015              : ColQualList:
    4016        10395 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    4017        36257 :             | /*EMPTY*/                             { $$ = NIL; }
    4018              :         ;
    4019              : 
    4020              : ColConstraint:
    4021              :             CONSTRAINT name ColConstraintElem
    4022              :                 {
    4023          405 :                     Constraint *n = castNode(Constraint, $3);
    4024              : 
    4025          405 :                     n->conname = $2;
    4026          405 :                     n->location = @1;
    4027          405 :                     $$ = (Node *) n;
    4028              :                 }
    4029         9454 :             | ColConstraintElem                     { $$ = $1; }
    4030          147 :             | ConstraintAttr                        { $$ = $1; }
    4031              :             | COLLATE any_name
    4032              :                 {
    4033              :                     /*
    4034              :                      * Note: the CollateClause is momentarily included in
    4035              :                      * the list built by ColQualList, but we split it out
    4036              :                      * again in SplitColQualList.
    4037              :                      */
    4038          389 :                     CollateClause *n = makeNode(CollateClause);
    4039              : 
    4040          389 :                     n->arg = NULL;
    4041          389 :                     n->collname = $2;
    4042          389 :                     n->location = @1;
    4043          389 :                     $$ = (Node *) n;
    4044              :                 }
    4045              :         ;
    4046              : 
    4047              : /* DEFAULT NULL is already the default for Postgres.
    4048              :  * But define it here and carry it forward into the system
    4049              :  * to make it explicit.
    4050              :  * - thomas 1998-09-13
    4051              :  *
    4052              :  * WITH NULL and NULL are not SQL-standard syntax elements,
    4053              :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    4054              :  * that a column may have that value. WITH NULL leads to
    4055              :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    4056              :  * - thomas 1999-01-08
    4057              :  *
    4058              :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    4059              :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    4060              :  * or be part of a_expr NOT LIKE or similar constructs).
    4061              :  */
    4062              : ColConstraintElem:
    4063              :             NOT NULL_P opt_no_inherit
    4064              :                 {
    4065         3530 :                     Constraint *n = makeNode(Constraint);
    4066              : 
    4067         3530 :                     n->contype = CONSTR_NOTNULL;
    4068         3530 :                     n->location = @1;
    4069         3530 :                     n->is_no_inherit = $3;
    4070         3530 :                     n->is_enforced = true;
    4071         3530 :                     n->skip_validation = false;
    4072         3530 :                     n->initially_valid = true;
    4073         3530 :                     $$ = (Node *) n;
    4074              :                 }
    4075              :             | NULL_P
    4076              :                 {
    4077           15 :                     Constraint *n = makeNode(Constraint);
    4078              : 
    4079           15 :                     n->contype = CONSTR_NULL;
    4080           15 :                     n->location = @1;
    4081           15 :                     $$ = (Node *) n;
    4082              :                 }
    4083              :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    4084              :                 {
    4085          233 :                     Constraint *n = makeNode(Constraint);
    4086              : 
    4087          233 :                     n->contype = CONSTR_UNIQUE;
    4088          233 :                     n->location = @1;
    4089          233 :                     n->nulls_not_distinct = !$2;
    4090          233 :                     n->keys = NULL;
    4091          233 :                     n->options = $3;
    4092          233 :                     n->indexname = NULL;
    4093          233 :                     n->indexspace = $4;
    4094          233 :                     $$ = (Node *) n;
    4095              :                 }
    4096              :             | PRIMARY KEY opt_definition OptConsTableSpace
    4097              :                 {
    4098         3023 :                     Constraint *n = makeNode(Constraint);
    4099              : 
    4100         3023 :                     n->contype = CONSTR_PRIMARY;
    4101         3023 :                     n->location = @1;
    4102         3023 :                     n->keys = NULL;
    4103         3023 :                     n->options = $3;
    4104         3023 :                     n->indexname = NULL;
    4105         3023 :                     n->indexspace = $4;
    4106         3023 :                     $$ = (Node *) n;
    4107              :                 }
    4108              :             | CHECK '(' a_expr ')' opt_no_inherit
    4109              :                 {
    4110          553 :                     Constraint *n = makeNode(Constraint);
    4111              : 
    4112          553 :                     n->contype = CONSTR_CHECK;
    4113          553 :                     n->location = @1;
    4114          553 :                     n->is_no_inherit = $5;
    4115          553 :                     n->raw_expr = $3;
    4116          553 :                     n->cooked_expr = NULL;
    4117          553 :                     n->is_enforced = true;
    4118          553 :                     n->skip_validation = false;
    4119          553 :                     n->initially_valid = true;
    4120          553 :                     $$ = (Node *) n;
    4121              :                 }
    4122              :             | DEFAULT b_expr
    4123              :                 {
    4124          959 :                     Constraint *n = makeNode(Constraint);
    4125              : 
    4126          959 :                     n->contype = CONSTR_DEFAULT;
    4127          959 :                     n->location = @1;
    4128          959 :                     n->raw_expr = $2;
    4129          959 :                     n->cooked_expr = NULL;
    4130          959 :                     $$ = (Node *) n;
    4131              :                 }
    4132              :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4133              :                 {
    4134          187 :                     Constraint *n = makeNode(Constraint);
    4135              : 
    4136          187 :                     n->contype = CONSTR_IDENTITY;
    4137          187 :                     n->generated_when = $2;
    4138          187 :                     n->options = $5;
    4139          187 :                     n->location = @1;
    4140          187 :                     $$ = (Node *) n;
    4141              :                 }
    4142              :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4143              :                 {
    4144          939 :                     Constraint *n = makeNode(Constraint);
    4145              : 
    4146          939 :                     n->contype = CONSTR_GENERATED;
    4147          939 :                     n->generated_when = $2;
    4148          939 :                     n->raw_expr = $5;
    4149          939 :                     n->cooked_expr = NULL;
    4150          939 :                     n->generated_kind = $7;
    4151          939 :                     n->location = @1;
    4152              : 
    4153              :                     /*
    4154              :                      * Can't do this in the grammar because of shift/reduce
    4155              :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4156              :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4157              :                      * can also give a more useful error message and location.
    4158              :                      */
    4159          939 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4160            6 :                         ereport(ERROR,
    4161              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4162              :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4163              :                                  parser_errposition(@2)));
    4164              : 
    4165          933 :                     $$ = (Node *) n;
    4166              :                 }
    4167              :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4168              :                 {
    4169          426 :                     Constraint *n = makeNode(Constraint);
    4170              : 
    4171          426 :                     n->contype = CONSTR_FOREIGN;
    4172          426 :                     n->location = @1;
    4173          426 :                     n->pktable = $2;
    4174          426 :                     n->fk_attrs = NIL;
    4175          426 :                     n->pk_attrs = $3;
    4176          426 :                     n->fk_matchtype = $4;
    4177          426 :                     n->fk_upd_action = ($5)->updateAction->action;
    4178          426 :                     n->fk_del_action = ($5)->deleteAction->action;
    4179          426 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4180          426 :                     n->is_enforced = true;
    4181          426 :                     n->skip_validation = false;
    4182          426 :                     n->initially_valid = true;
    4183          426 :                     $$ = (Node *) n;
    4184              :                 }
    4185              :         ;
    4186              : 
    4187              : opt_unique_null_treatment:
    4188            6 :             NULLS_P DISTINCT        { $$ = true; }
    4189           18 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4190         3935 :             | /*EMPTY*/             { $$ = true; }
    4191              :         ;
    4192              : 
    4193              : generated_when:
    4194         1143 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4195           91 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4196              :         ;
    4197              : 
    4198              : opt_virtual_or_stored:
    4199          547 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4200          329 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4201           63 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4202              :         ;
    4203              : 
    4204              : /*
    4205              :  * ConstraintAttr represents constraint attributes, which we parse as if
    4206              :  * they were independent constraint clauses, in order to avoid shift/reduce
    4207              :  * conflicts (since NOT might start either an independent NOT NULL clause
    4208              :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4209              :  * attribute information to the preceding "real" constraint node, and for
    4210              :  * complaining if attribute clauses appear in the wrong place or wrong
    4211              :  * combinations.
    4212              :  *
    4213              :  * See also ConstraintAttributeSpec, which can be used in places where
    4214              :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4215              :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4216              :  * might need to allow them here too, but for the moment it doesn't seem
    4217              :  * useful in the statements that use ConstraintAttr.)
    4218              :  */
    4219              : ConstraintAttr:
    4220              :             DEFERRABLE
    4221              :                 {
    4222           51 :                     Constraint *n = makeNode(Constraint);
    4223              : 
    4224           51 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4225           51 :                     n->location = @1;
    4226           51 :                     $$ = (Node *) n;
    4227              :                 }
    4228              :             | NOT DEFERRABLE
    4229              :                 {
    4230            0 :                     Constraint *n = makeNode(Constraint);
    4231              : 
    4232            0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4233            0 :                     n->location = @1;
    4234            0 :                     $$ = (Node *) n;
    4235              :                 }
    4236              :             | INITIALLY DEFERRED
    4237              :                 {
    4238           39 :                     Constraint *n = makeNode(Constraint);
    4239              : 
    4240           39 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4241           39 :                     n->location = @1;
    4242           39 :                     $$ = (Node *) n;
    4243              :                 }
    4244              :             | INITIALLY IMMEDIATE
    4245              :                 {
    4246            3 :                     Constraint *n = makeNode(Constraint);
    4247              : 
    4248            3 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4249            3 :                     n->location = @1;
    4250            3 :                     $$ = (Node *) n;
    4251              :                 }
    4252              :             | ENFORCED
    4253              :                 {
    4254           21 :                     Constraint *n = makeNode(Constraint);
    4255              : 
    4256           21 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4257           21 :                     n->location = @1;
    4258           21 :                     $$ = (Node *) n;
    4259              :                 }
    4260              :             | NOT ENFORCED
    4261              :                 {
    4262           33 :                     Constraint *n = makeNode(Constraint);
    4263              : 
    4264           33 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4265           33 :                     n->location = @1;
    4266           33 :                     $$ = (Node *) n;
    4267              :                 }
    4268              :         ;
    4269              : 
    4270              : 
    4271              : TableLikeClause:
    4272              :             LIKE qualified_name TableLikeOptionList
    4273              :                 {
    4274          393 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4275              : 
    4276          393 :                     n->relation = $2;
    4277          393 :                     n->options = $3;
    4278          393 :                     n->relationOid = InvalidOid;
    4279          393 :                     $$ = (Node *) n;
    4280              :                 }
    4281              :         ;
    4282              : 
    4283              : TableLikeOptionList:
    4284          144 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4285            4 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4286          393 :                 | /* EMPTY */                       { $$ = 0; }
    4287              :         ;
    4288              : 
    4289              : TableLikeOption:
    4290           15 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4291            3 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4292           27 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4293           10 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4294            6 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4295           15 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4296           25 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4297            0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4298           13 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4299           34 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4300              :         ;
    4301              : 
    4302              : 
    4303              : /* ConstraintElem specifies constraint syntax which is not embedded into
    4304              :  *  a column definition. ColConstraintElem specifies the embedded form.
    4305              :  * - thomas 1997-12-03
    4306              :  */
    4307              : TableConstraint:
    4308              :             CONSTRAINT name ConstraintElem
    4309              :                 {
    4310         2138 :                     Constraint *n = castNode(Constraint, $3);
    4311              : 
    4312         2138 :                     n->conname = $2;
    4313         2138 :                     n->location = @1;
    4314         2138 :                     $$ = (Node *) n;
    4315              :                 }
    4316         6764 :             | ConstraintElem                        { $$ = $1; }
    4317              :         ;
    4318              : 
    4319              : ConstraintElem:
    4320              :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4321              :                 {
    4322          691 :                     Constraint *n = makeNode(Constraint);
    4323              : 
    4324          691 :                     n->contype = CONSTR_CHECK;
    4325          691 :                     n->location = @1;
    4326          691 :                     n->raw_expr = $3;
    4327          691 :                     n->cooked_expr = NULL;
    4328          691 :                     processCASbits($5, @5, "CHECK",
    4329              :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4330              :                                    &n->is_no_inherit, yyscanner);
    4331          691 :                     n->initially_valid = !n->skip_validation;
    4332          691 :                     $$ = (Node *) n;
    4333              :                 }
    4334              :             | NOT NULL_P ColId ConstraintAttributeSpec
    4335              :                 {
    4336          315 :                     Constraint *n = makeNode(Constraint);
    4337              : 
    4338          315 :                     n->contype = CONSTR_NOTNULL;
    4339          315 :                     n->location = @1;
    4340          315 :                     n->keys = list_make1(makeString($3));
    4341          315 :                     processCASbits($4, @4, "NOT NULL",
    4342              :                                    NULL, NULL, NULL, &n->skip_validation,
    4343              :                                    &n->is_no_inherit, yyscanner);
    4344          315 :                     n->initially_valid = !n->skip_validation;
    4345          315 :                     $$ = (Node *) n;
    4346              :                 }
    4347              :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4348              :                 ConstraintAttributeSpec
    4349              :                 {
    4350          308 :                     Constraint *n = makeNode(Constraint);
    4351              : 
    4352          308 :                     n->contype = CONSTR_UNIQUE;
    4353          308 :                     n->location = @1;
    4354          308 :                     n->nulls_not_distinct = !$2;
    4355          308 :                     n->keys = $4;
    4356          308 :                     n->without_overlaps = $5;
    4357          308 :                     n->including = $7;
    4358          308 :                     n->options = $8;
    4359          308 :                     n->indexname = NULL;
    4360          308 :                     n->indexspace = $9;
    4361          308 :                     processCASbits($10, @10, "UNIQUE",
    4362              :                                    &n->deferrable, &n->initdeferred, NULL,
    4363              :                                    NULL, NULL, yyscanner);
    4364          308 :                     $$ = (Node *) n;
    4365              :                 }
    4366              :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4367              :                 {
    4368         2372 :                     Constraint *n = makeNode(Constraint);
    4369              : 
    4370         2372 :                     n->contype = CONSTR_UNIQUE;
    4371         2372 :                     n->location = @1;
    4372         2372 :                     n->keys = NIL;
    4373         2372 :                     n->including = NIL;
    4374         2372 :                     n->options = NIL;
    4375         2372 :                     n->indexname = $2;
    4376         2372 :                     n->indexspace = NULL;
    4377         2372 :                     processCASbits($3, @3, "UNIQUE",
    4378              :                                    &n->deferrable, &n->initdeferred, NULL,
    4379              :                                    NULL, NULL, yyscanner);
    4380         2372 :                     $$ = (Node *) n;
    4381              :                 }
    4382              :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4383              :                 ConstraintAttributeSpec
    4384              :                 {
    4385         1094 :                     Constraint *n = makeNode(Constraint);
    4386              : 
    4387         1094 :                     n->contype = CONSTR_PRIMARY;
    4388         1094 :                     n->location = @1;
    4389         1094 :                     n->keys = $4;
    4390         1094 :                     n->without_overlaps = $5;
    4391         1094 :                     n->including = $7;
    4392         1094 :                     n->options = $8;
    4393         1094 :                     n->indexname = NULL;
    4394         1094 :                     n->indexspace = $9;
    4395         1094 :                     processCASbits($10, @10, "PRIMARY KEY",
    4396              :                                    &n->deferrable, &n->initdeferred, NULL,
    4397              :                                    NULL, NULL, yyscanner);
    4398         1094 :                     $$ = (Node *) n;
    4399              :                 }
    4400              :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4401              :                 {
    4402         3071 :                     Constraint *n = makeNode(Constraint);
    4403              : 
    4404         3071 :                     n->contype = CONSTR_PRIMARY;
    4405         3071 :                     n->location = @1;
    4406         3071 :                     n->keys = NIL;
    4407         3071 :                     n->including = NIL;
    4408         3071 :                     n->options = NIL;
    4409         3071 :                     n->indexname = $3;
    4410         3071 :                     n->indexspace = NULL;
    4411         3071 :                     processCASbits($4, @4, "PRIMARY KEY",
    4412              :                                    &n->deferrable, &n->initdeferred, NULL,
    4413              :                                    NULL, NULL, yyscanner);
    4414         3071 :                     $$ = (Node *) n;
    4415              :                 }
    4416              :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4417              :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4418              :                 ConstraintAttributeSpec
    4419              :                 {
    4420          117 :                     Constraint *n = makeNode(Constraint);
    4421              : 
    4422          117 :                     n->contype = CONSTR_EXCLUSION;
    4423          117 :                     n->location = @1;
    4424          117 :                     n->access_method = $2;
    4425          117 :                     n->exclusions = $4;
    4426          117 :                     n->including = $6;
    4427          117 :                     n->options = $7;
    4428          117 :                     n->indexname = NULL;
    4429          117 :                     n->indexspace = $8;
    4430          117 :                     n->where_clause = $9;
    4431          117 :                     processCASbits($10, @10, "EXCLUDE",
    4432              :                                    &n->deferrable, &n->initdeferred, NULL,
    4433              :                                    NULL, NULL, yyscanner);
    4434          117 :                     $$ = (Node *) n;
    4435              :                 }
    4436              :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4437              :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4438              :                 {
    4439          934 :                     Constraint *n = makeNode(Constraint);
    4440              : 
    4441          934 :                     n->contype = CONSTR_FOREIGN;
    4442          934 :                     n->location = @1;
    4443          934 :                     n->pktable = $8;
    4444          934 :                     n->fk_attrs = $4;
    4445          934 :                     if ($5)
    4446              :                     {
    4447          163 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4448          163 :                         n->fk_with_period = true;
    4449              :                     }
    4450          934 :                     n->pk_attrs = linitial($9);
    4451          934 :                     if (lsecond($9))
    4452              :                     {
    4453           85 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4454           85 :                         n->pk_with_period = true;
    4455              :                     }
    4456          934 :                     n->fk_matchtype = $10;
    4457          934 :                     n->fk_upd_action = ($11)->updateAction->action;
    4458          934 :                     n->fk_del_action = ($11)->deleteAction->action;
    4459          934 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4460          934 :                     processCASbits($12, @12, "FOREIGN KEY",
    4461              :                                    &n->deferrable, &n->initdeferred,
    4462              :                                    &n->is_enforced, &n->skip_validation, NULL,
    4463              :                                    yyscanner);
    4464          934 :                     n->initially_valid = !n->skip_validation;
    4465          934 :                     $$ = (Node *) n;
    4466              :                 }
    4467              :         ;
    4468              : 
    4469              : /*
    4470              :  * DomainConstraint is separate from TableConstraint because the syntax for
    4471              :  * NOT NULL constraints is different.  For table constraints, we need to
    4472              :  * accept a column name, but for domain constraints, we don't.  (We could
    4473              :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4474              :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4475              :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4476              :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4477              :  * standard; we are just living with the bits of inconsistency that have built
    4478              :  * up over time.
    4479              :  */
    4480              : DomainConstraint:
    4481              :             CONSTRAINT name DomainConstraintElem
    4482              :                 {
    4483           82 :                     Constraint *n = castNode(Constraint, $3);
    4484              : 
    4485           82 :                     n->conname = $2;
    4486           82 :                     n->location = @1;
    4487           82 :                     $$ = (Node *) n;
    4488              :                 }
    4489            9 :             | DomainConstraintElem                  { $$ = $1; }
    4490              :         ;
    4491              : 
    4492              : DomainConstraintElem:
    4493              :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4494              :                 {
    4495           82 :                     Constraint *n = makeNode(Constraint);
    4496              : 
    4497           82 :                     n->contype = CONSTR_CHECK;
    4498           82 :                     n->location = @1;
    4499           82 :                     n->raw_expr = $3;
    4500           82 :                     n->cooked_expr = NULL;
    4501           82 :                     processCASbits($5, @5, "CHECK",
    4502              :                                    NULL, NULL, NULL, &n->skip_validation,
    4503              :                                    &n->is_no_inherit, yyscanner);
    4504           76 :                     n->is_enforced = true;
    4505           76 :                     n->initially_valid = !n->skip_validation;
    4506           76 :                     $$ = (Node *) n;
    4507              :                 }
    4508              :             | NOT NULL_P ConstraintAttributeSpec
    4509              :                 {
    4510           15 :                     Constraint *n = makeNode(Constraint);
    4511              : 
    4512           15 :                     n->contype = CONSTR_NOTNULL;
    4513           15 :                     n->location = @1;
    4514           15 :                     n->keys = list_make1(makeString("value"));
    4515              :                     /* no NOT VALID, NO INHERIT support */
    4516           15 :                     processCASbits($3, @3, "NOT NULL",
    4517              :                                    NULL, NULL, NULL,
    4518              :                                    NULL, NULL, yyscanner);
    4519           15 :                     n->initially_valid = true;
    4520           15 :                     $$ = (Node *) n;
    4521              :                 }
    4522              :         ;
    4523              : 
    4524           70 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4525         4013 :             | /* EMPTY */                           {  $$ = false; }
    4526              :         ;
    4527              : 
    4528              : opt_without_overlaps:
    4529          295 :             WITHOUT OVERLAPS                        { $$ = true; }
    4530         1107 :             | /*EMPTY*/                             { $$ = false; }
    4531              :     ;
    4532              : 
    4533              : opt_column_list:
    4534         5344 :             '(' columnList ')'                      { $$ = $2; }
    4535        22018 :             | /*EMPTY*/                             { $$ = NIL; }
    4536              :         ;
    4537              : 
    4538              : columnList:
    4539         8527 :             columnElem                              { $$ = list_make1($1); }
    4540        14451 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4541              :         ;
    4542              : 
    4543              : optionalPeriodName:
    4544          248 :             ',' PERIOD columnElem { $$ = $3; }
    4545         1251 :             | /*EMPTY*/               { $$ = NULL; }
    4546              :     ;
    4547              : 
    4548              : opt_column_and_period_list:
    4549          562 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4550          375 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4551              :         ;
    4552              : 
    4553              : columnElem: ColId
    4554              :                 {
    4555        23226 :                     $$ = (Node *) makeString($1);
    4556              :                 }
    4557              :         ;
    4558              : 
    4559           84 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4560         1435 :              |      /* EMPTY */                     { $$ = NIL; }
    4561              :         ;
    4562              : 
    4563              : key_match:  MATCH FULL
    4564              :             {
    4565           49 :                 $$ = FKCONSTR_MATCH_FULL;
    4566              :             }
    4567              :         | MATCH PARTIAL
    4568              :             {
    4569            0 :                 ereport(ERROR,
    4570              :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4571              :                          errmsg("MATCH PARTIAL not yet implemented"),
    4572              :                          parser_errposition(@1)));
    4573              :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4574              :             }
    4575              :         | MATCH SIMPLE
    4576              :             {
    4577            3 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4578              :             }
    4579              :         | /*EMPTY*/
    4580              :             {
    4581         1311 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4582              :             }
    4583              :         ;
    4584              : 
    4585              : ExclusionConstraintList:
    4586          117 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4587              :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4588           53 :                                                     { $$ = lappend($1, $3); }
    4589              :         ;
    4590              : 
    4591              : ExclusionConstraintElem: index_elem WITH any_operator
    4592              :             {
    4593          170 :                 $$ = list_make2($1, $3);
    4594              :             }
    4595              :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4596              :             | index_elem WITH OPERATOR '(' any_operator ')'
    4597              :             {
    4598            0 :                 $$ = list_make2($1, $5);
    4599              :             }
    4600              :         ;
    4601              : 
    4602              : OptWhereClause:
    4603          232 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4604          634 :             | /*EMPTY*/                             { $$ = NULL; }
    4605              :         ;
    4606              : 
    4607              : key_actions:
    4608              :             key_update
    4609              :                 {
    4610           37 :                     KeyActions *n = palloc_object(KeyActions);
    4611              : 
    4612           37 :                     n->updateAction = $1;
    4613           37 :                     n->deleteAction = palloc_object(KeyAction);
    4614           37 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4615           37 :                     n->deleteAction->cols = NIL;
    4616           37 :                     $$ = n;
    4617              :                 }
    4618              :             | key_delete
    4619              :                 {
    4620           75 :                     KeyActions *n = palloc_object(KeyActions);
    4621              : 
    4622           75 :                     n->updateAction = palloc_object(KeyAction);
    4623           75 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4624           75 :                     n->updateAction->cols = NIL;
    4625           75 :                     n->deleteAction = $1;
    4626           75 :                     $$ = n;
    4627              :                 }
    4628              :             | key_update key_delete
    4629              :                 {
    4630           84 :                     KeyActions *n = palloc_object(KeyActions);
    4631              : 
    4632           84 :                     n->updateAction = $1;
    4633           84 :                     n->deleteAction = $2;
    4634           84 :                     $$ = n;
    4635              :                 }
    4636              :             | key_delete key_update
    4637              :                 {
    4638           75 :                     KeyActions *n = palloc_object(KeyActions);
    4639              : 
    4640           75 :                     n->updateAction = $2;
    4641           75 :                     n->deleteAction = $1;
    4642           75 :                     $$ = n;
    4643              :                 }
    4644              :             | /*EMPTY*/
    4645              :                 {
    4646         1089 :                     KeyActions *n = palloc_object(KeyActions);
    4647              : 
    4648         1089 :                     n->updateAction = palloc_object(KeyAction);
    4649         1089 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4650         1089 :                     n->updateAction->cols = NIL;
    4651         1089 :                     n->deleteAction = palloc_object(KeyAction);
    4652         1089 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4653         1089 :                     n->deleteAction->cols = NIL;
    4654         1089 :                     $$ = n;
    4655              :                 }
    4656              :         ;
    4657              : 
    4658              : key_update: ON UPDATE key_action
    4659              :                 {
    4660          199 :                     if (($3)->cols)
    4661            3 :                         ereport(ERROR,
    4662              :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4663              :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4664              :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4665              :                                  parser_errposition(@1)));
    4666          196 :                     $$ = $3;
    4667              :                 }
    4668              :         ;
    4669              : 
    4670              : key_delete: ON DELETE_P key_action
    4671              :                 {
    4672          234 :                     $$ = $3;
    4673              :                 }
    4674              :         ;
    4675              : 
    4676              : key_action:
    4677              :             NO ACTION
    4678              :                 {
    4679           40 :                     KeyAction *n = palloc_object(KeyAction);
    4680              : 
    4681           40 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4682           40 :                     n->cols = NIL;
    4683           40 :                     $$ = n;
    4684              :                 }
    4685              :             | RESTRICT
    4686              :                 {
    4687           24 :                     KeyAction *n = palloc_object(KeyAction);
    4688              : 
    4689           24 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4690           24 :                     n->cols = NIL;
    4691           24 :                     $$ = n;
    4692              :                 }
    4693              :             | CASCADE
    4694              :                 {
    4695          223 :                     KeyAction *n = palloc_object(KeyAction);
    4696              : 
    4697          223 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4698          223 :                     n->cols = NIL;
    4699          223 :                     $$ = n;
    4700              :                 }
    4701              :             | SET NULL_P opt_column_list
    4702              :                 {
    4703           95 :                     KeyAction *n = palloc_object(KeyAction);
    4704              : 
    4705           95 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4706           95 :                     n->cols = $3;
    4707           95 :                     $$ = n;
    4708              :                 }
    4709              :             | SET DEFAULT opt_column_list
    4710              :                 {
    4711           51 :                     KeyAction *n = palloc_object(KeyAction);
    4712              : 
    4713           51 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4714           51 :                     n->cols = $3;
    4715           51 :                     $$ = n;
    4716              :                 }
    4717              :         ;
    4718              : 
    4719         1070 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4720        14683 :             | /*EMPTY*/                             { $$ = NIL; }
    4721              :         ;
    4722              : 
    4723              : /* Optional partition key specification */
    4724         2802 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4725        17344 :             | /*EMPTY*/         { $$ = NULL; }
    4726              :         ;
    4727              : 
    4728              : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4729              :                 {
    4730         2805 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4731              : 
    4732         2805 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4733         2802 :                     n->partParams = $5;
    4734         2802 :                     n->location = @1;
    4735              : 
    4736         2802 :                     $$ = n;
    4737              :                 }
    4738              :         ;
    4739              : 
    4740         2805 : part_params:    part_elem                       { $$ = list_make1($1); }
    4741          243 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4742              :         ;
    4743              : 
    4744              : part_elem: ColId opt_collate opt_qualified_name
    4745              :                 {
    4746         2872 :                     PartitionElem *n = makeNode(PartitionElem);
    4747              : 
    4748         2872 :                     n->name = $1;
    4749         2872 :                     n->expr = NULL;
    4750         2872 :                     n->collation = $2;
    4751         2872 :                     n->opclass = $3;
    4752         2872 :                     n->location = @1;
    4753         2872 :                     $$ = n;
    4754              :                 }
    4755              :             | func_expr_windowless opt_collate opt_qualified_name
    4756              :                 {
    4757           71 :                     PartitionElem *n = makeNode(PartitionElem);
    4758              : 
    4759           71 :                     n->name = NULL;
    4760           71 :                     n->expr = $1;
    4761           71 :                     n->collation = $2;
    4762           71 :                     n->opclass = $3;
    4763           71 :                     n->location = @1;
    4764           71 :                     $$ = n;
    4765              :                 }
    4766              :             | '(' a_expr ')' opt_collate opt_qualified_name
    4767              :                 {
    4768          105 :                     PartitionElem *n = makeNode(PartitionElem);
    4769              : 
    4770          105 :                     n->name = NULL;
    4771          105 :                     n->expr = $2;
    4772          105 :                     n->collation = $4;
    4773          105 :                     n->opclass = $5;
    4774          105 :                     n->location = @1;
    4775          105 :                     $$ = n;
    4776              :                 }
    4777              :         ;
    4778              : 
    4779              : table_access_method_clause:
    4780           67 :             USING name                          { $$ = $2; }
    4781        21059 :             | /*EMPTY*/                         { $$ = NULL; }
    4782              :         ;
    4783              : 
    4784              : /* WITHOUT OIDS is legacy only */
    4785              : OptWith:
    4786          440 :             WITH reloptions             { $$ = $2; }
    4787           12 :             | WITHOUT OIDS              { $$ = NIL; }
    4788        20377 :             | /*EMPTY*/                 { $$ = NIL; }
    4789              :         ;
    4790              : 
    4791           33 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4792           52 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4793           12 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4794        20732 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4795              :         ;
    4796              : 
    4797          114 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4798        24427 :             | /*EMPTY*/                             { $$ = NULL; }
    4799              :         ;
    4800              : 
    4801           39 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4802         4736 :             | /*EMPTY*/                             { $$ = NULL; }
    4803              :         ;
    4804              : 
    4805         5443 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4806              :         ;
    4807              : 
    4808              : /*****************************************************************************
    4809              :  *
    4810              :  *      QUERY :
    4811              :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4812              :  *                  ON expression-list FROM from_list
    4813              :  *
    4814              :  * Note: the expectation here is that the clauses after ON are a subset of
    4815              :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4816              :  * someday a WHERE clause.  Much less than that is currently implemented,
    4817              :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4818              :  * errors as necessary at execution.
    4819              :  *
    4820              :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4821              :  *
    4822              :  *****************************************************************************/
    4823              : 
    4824              : CreateStatsStmt:
    4825              :             CREATE STATISTICS opt_qualified_name
    4826              :             opt_name_list ON stats_params FROM from_list
    4827              :                 {
    4828          472 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4829              : 
    4830          472 :                     n->defnames = $3;
    4831          472 :                     n->stat_types = $4;
    4832          472 :                     n->exprs = $6;
    4833          472 :                     n->relations = $8;
    4834          472 :                     n->stxcomment = NULL;
    4835          472 :                     n->if_not_exists = false;
    4836          472 :                     $$ = (Node *) n;
    4837              :                 }
    4838              :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4839              :             opt_name_list ON stats_params FROM from_list
    4840              :                 {
    4841            6 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4842              : 
    4843            6 :                     n->defnames = $6;
    4844            6 :                     n->stat_types = $7;
    4845            6 :                     n->exprs = $9;
    4846            6 :                     n->relations = $11;
    4847            6 :                     n->stxcomment = NULL;
    4848            6 :                     n->if_not_exists = true;
    4849            6 :                     $$ = (Node *) n;
    4850              :                 }
    4851              :             ;
    4852              : 
    4853              : /*
    4854              :  * Statistics attributes can be either simple column references, or arbitrary
    4855              :  * expressions in parens.  For compatibility with index attributes permitted
    4856              :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4857              :  * written without parens.
    4858              :  */
    4859              : 
    4860          484 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4861          653 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4862              :         ;
    4863              : 
    4864              : stats_param:    ColId
    4865              :                 {
    4866          835 :                     $$ = makeNode(StatsElem);
    4867          835 :                     $$->name = $1;
    4868          835 :                     $$->expr = NULL;
    4869              :                 }
    4870              :             | func_expr_windowless
    4871              :                 {
    4872           51 :                     $$ = makeNode(StatsElem);
    4873           51 :                     $$->name = NULL;
    4874           51 :                     $$->expr = $1;
    4875              :                 }
    4876              :             | '(' a_expr ')'
    4877              :                 {
    4878          251 :                     $$ = makeNode(StatsElem);
    4879          251 :                     $$->name = NULL;
    4880          251 :                     $$->expr = $2;
    4881              :                 }
    4882              :         ;
    4883              : 
    4884              : /*****************************************************************************
    4885              :  *
    4886              :  *      QUERY :
    4887              :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4888              :  *                  SET STATISTICS  <SignedIconst>
    4889              :  *
    4890              :  *****************************************************************************/
    4891              : 
    4892              : AlterStatsStmt:
    4893              :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4894              :                 {
    4895           10 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4896              : 
    4897           10 :                     n->defnames = $3;
    4898           10 :                     n->missing_ok = false;
    4899           10 :                     n->stxstattarget = $6;
    4900           10 :                     $$ = (Node *) n;
    4901              :                 }
    4902              :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4903              :                 {
    4904            3 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4905              : 
    4906            3 :                     n->defnames = $5;
    4907            3 :                     n->missing_ok = true;
    4908            3 :                     n->stxstattarget = $8;
    4909            3 :                     $$ = (Node *) n;
    4910              :                 }
    4911              :             ;
    4912              : 
    4913              : /*****************************************************************************
    4914              :  *
    4915              :  *      QUERY :
    4916              :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4917              :  *
    4918              :  *
    4919              :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4920              :  *
    4921              :  *****************************************************************************/
    4922              : 
    4923              : CreateAsStmt:
    4924              :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4925              :                 {
    4926          619 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4927              : 
    4928          619 :                     ctas->query = $6;
    4929          619 :                     ctas->into = $4;
    4930          619 :                     ctas->objtype = OBJECT_TABLE;
    4931          619 :                     ctas->is_select_into = false;
    4932          619 :                     ctas->if_not_exists = false;
    4933              :                     /* cram additional flags into the IntoClause */
    4934          619 :                     $4->rel->relpersistence = $2;
    4935          619 :                     $4->skipData = !($7);
    4936          619 :                     $$ = (Node *) ctas;
    4937              :                 }
    4938              :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4939              :                 {
    4940           26 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4941              : 
    4942           26 :                     ctas->query = $9;
    4943           26 :                     ctas->into = $7;
    4944           26 :                     ctas->objtype = OBJECT_TABLE;
    4945           26 :                     ctas->is_select_into = false;
    4946           26 :                     ctas->if_not_exists = true;
    4947              :                     /* cram additional flags into the IntoClause */
    4948           26 :                     $7->rel->relpersistence = $2;
    4949           26 :                     $7->skipData = !($10);
    4950           26 :                     $$ = (Node *) ctas;
    4951              :                 }
    4952              :         ;
    4953              : 
    4954              : create_as_target:
    4955              :             qualified_name opt_column_list table_access_method_clause
    4956              :             OptWith OnCommitOption OptTableSpace
    4957              :                 {
    4958          689 :                     $$ = makeNode(IntoClause);
    4959          689 :                     $$->rel = $1;
    4960          689 :                     $$->colNames = $2;
    4961          689 :                     $$->accessMethod = $3;
    4962          689 :                     $$->options = $4;
    4963          689 :                     $$->onCommit = $5;
    4964          689 :                     $$->tableSpaceName = $6;
    4965          689 :                     $$->viewQuery = NULL;
    4966          689 :                     $$->skipData = false;        /* might get changed later */
    4967              :                 }
    4968              :         ;
    4969              : 
    4970              : opt_with_data:
    4971           18 :             WITH DATA_P                             { $$ = true; }
    4972          109 :             | WITH NO DATA_P                        { $$ = false; }
    4973          990 :             | /*EMPTY*/                             { $$ = true; }
    4974              :         ;
    4975              : 
    4976              : 
    4977              : /*****************************************************************************
    4978              :  *
    4979              :  *      QUERY :
    4980              :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4981              :  *
    4982              :  *****************************************************************************/
    4983              : 
    4984              : CreateMatViewStmt:
    4985              :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4986              :                 {
    4987          270 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4988              : 
    4989          270 :                     ctas->query = $7;
    4990          270 :                     ctas->into = $5;
    4991          270 :                     ctas->objtype = OBJECT_MATVIEW;
    4992          270 :                     ctas->is_select_into = false;
    4993          270 :                     ctas->if_not_exists = false;
    4994              :                     /* cram additional flags into the IntoClause */
    4995          270 :                     $5->rel->relpersistence = $2;
    4996          270 :                     $5->skipData = !($8);
    4997          270 :                     $$ = (Node *) ctas;
    4998              :                 }
    4999              :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    5000              :                 {
    5001           24 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    5002              : 
    5003           24 :                     ctas->query = $10;
    5004           24 :                     ctas->into = $8;
    5005           24 :                     ctas->objtype = OBJECT_MATVIEW;
    5006           24 :                     ctas->is_select_into = false;
    5007           24 :                     ctas->if_not_exists = true;
    5008              :                     /* cram additional flags into the IntoClause */
    5009           24 :                     $8->rel->relpersistence = $2;
    5010           24 :                     $8->skipData = !($11);
    5011           24 :                     $$ = (Node *) ctas;
    5012              :                 }
    5013              :         ;
    5014              : 
    5015              : create_mv_target:
    5016              :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    5017              :                 {
    5018          294 :                     $$ = makeNode(IntoClause);
    5019          294 :                     $$->rel = $1;
    5020          294 :                     $$->colNames = $2;
    5021          294 :                     $$->accessMethod = $3;
    5022          294 :                     $$->options = $4;
    5023          294 :                     $$->onCommit = ONCOMMIT_NOOP;
    5024          294 :                     $$->tableSpaceName = $5;
    5025          294 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    5026          294 :                     $$->skipData = false;        /* might get changed later */
    5027              :                 }
    5028              :         ;
    5029              : 
    5030            0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    5031          294 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    5032              :         ;
    5033              : 
    5034              : 
    5035              : /*****************************************************************************
    5036              :  *
    5037              :  *      QUERY :
    5038              :  *              REFRESH MATERIALIZED VIEW qualified_name
    5039              :  *
    5040              :  *****************************************************************************/
    5041              : 
    5042              : RefreshMatViewStmt:
    5043              :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    5044              :                 {
    5045          134 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    5046              : 
    5047          134 :                     n->concurrent = $4;
    5048          134 :                     n->relation = $5;
    5049          134 :                     n->skipData = !($6);
    5050          134 :                     $$ = (Node *) n;
    5051              :                 }
    5052              :         ;
    5053              : 
    5054              : 
    5055              : /*****************************************************************************
    5056              :  *
    5057              :  *      QUERY :
    5058              :  *              CREATE SEQUENCE seqname
    5059              :  *              ALTER SEQUENCE seqname
    5060              :  *
    5061              :  *****************************************************************************/
    5062              : 
    5063              : CreateSeqStmt:
    5064              :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    5065              :                 {
    5066          352 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    5067              : 
    5068          352 :                     $4->relpersistence = $2;
    5069          352 :                     n->sequence = $4;
    5070          352 :                     n->options = $5;
    5071          352 :                     n->ownerId = InvalidOid;
    5072          352 :                     n->if_not_exists = false;
    5073          352 :                     $$ = (Node *) n;
    5074              :                 }
    5075              :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    5076              :                 {
    5077           12 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    5078              : 
    5079           12 :                     $7->relpersistence = $2;
    5080           12 :                     n->sequence = $7;
    5081           12 :                     n->options = $8;
    5082           12 :                     n->ownerId = InvalidOid;
    5083           12 :                     n->if_not_exists = true;
    5084           12 :                     $$ = (Node *) n;
    5085              :                 }
    5086              :         ;
    5087              : 
    5088              : AlterSeqStmt:
    5089              :             ALTER SEQUENCE qualified_name SeqOptList
    5090              :                 {
    5091           94 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5092              : 
    5093           94 :                     n->sequence = $3;
    5094           94 :                     n->options = $4;
    5095           94 :                     n->missing_ok = false;
    5096           94 :                     $$ = (Node *) n;
    5097              :                 }
    5098              :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    5099              :                 {
    5100            6 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5101              : 
    5102            6 :                     n->sequence = $5;
    5103            6 :                     n->options = $6;
    5104            6 :                     n->missing_ok = true;
    5105            6 :                     $$ = (Node *) n;
    5106              :                 }
    5107              : 
    5108              :         ;
    5109              : 
    5110          136 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    5111          228 :             | /*EMPTY*/                             { $$ = NIL; }
    5112              :         ;
    5113              : 
    5114           37 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    5115          236 :             | /*EMPTY*/                             { $$ = NIL; }
    5116              :         ;
    5117              : 
    5118          273 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    5119          403 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    5120              :         ;
    5121              : 
    5122              : SeqOptElem: AS SimpleTypename
    5123              :                 {
    5124           95 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5125              :                 }
    5126              :             | CACHE NumericOnly
    5127              :                 {
    5128           65 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5129              :                 }
    5130              :             | CYCLE
    5131              :                 {
    5132           17 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5133              :                 }
    5134              :             | NO CYCLE
    5135              :                 {
    5136            7 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5137              :                 }
    5138              :             | INCREMENT opt_by NumericOnly
    5139              :                 {
    5140          129 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5141              :                 }
    5142              :             | LOGGED
    5143              :                 {
    5144            1 :                     $$ = makeDefElem("logged", NULL, @1);
    5145              :                 }
    5146              :             | MAXVALUE NumericOnly
    5147              :                 {
    5148           34 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5149              :                 }
    5150              :             | MINVALUE NumericOnly
    5151              :                 {
    5152           34 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5153              :                 }
    5154              :             | NO MAXVALUE
    5155              :                 {
    5156           54 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5157              :                 }
    5158              :             | NO MINVALUE
    5159              :                 {
    5160           54 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5161              :                 }
    5162              :             | OWNED BY any_name
    5163              :                 {
    5164           36 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5165              :                 }
    5166              :             | SEQUENCE NAME_P any_name
    5167              :                 {
    5168           22 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5169              :                 }
    5170              :             | START opt_with NumericOnly
    5171              :                 {
    5172          121 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5173              :                 }
    5174              :             | RESTART
    5175              :                 {
    5176            3 :                     $$ = makeDefElem("restart", NULL, @1);
    5177              :                 }
    5178              :             | RESTART opt_with NumericOnly
    5179              :                 {
    5180           30 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5181              :                 }
    5182              :             | UNLOGGED
    5183              :                 {
    5184            1 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5185              :                 }
    5186              :         ;
    5187              : 
    5188              : opt_by:     BY
    5189              :             | /* EMPTY */
    5190              :       ;
    5191              : 
    5192              : NumericOnly:
    5193          164 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5194            0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5195              :             | '-' FCONST
    5196              :                 {
    5197           10 :                     Float      *f = makeFloat($2);
    5198              : 
    5199           10 :                     doNegateFloat(f);
    5200           10 :                     $$ = (Node *) f;
    5201              :                 }
    5202         6470 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5203              :         ;
    5204              : 
    5205           48 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5206            3 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5207              :         ;
    5208              : 
    5209              : /*****************************************************************************
    5210              :  *
    5211              :  *      QUERIES :
    5212              :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5213              :  *              DROP [PROCEDURAL] LANGUAGE ...
    5214              :  *
    5215              :  *****************************************************************************/
    5216              : 
    5217              : CreatePLangStmt:
    5218              :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5219              :             {
    5220              :                 /*
    5221              :                  * We now interpret parameterless CREATE LANGUAGE as
    5222              :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5223              :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5224              :                  * seems more useful than throwing an error.  We just
    5225              :                  * ignore TRUSTED, as the previous code would have too.
    5226              :                  */
    5227            0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5228              : 
    5229            0 :                 n->if_not_exists = $2;
    5230            0 :                 n->extname = $6;
    5231            0 :                 n->options = NIL;
    5232            0 :                 $$ = (Node *) n;
    5233              :             }
    5234              :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5235              :               HANDLER handler_name opt_inline_handler opt_validator
    5236              :             {
    5237           72 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5238              : 
    5239           72 :                 n->replace = $2;
    5240           72 :                 n->plname = $6;
    5241           72 :                 n->plhandler = $8;
    5242           72 :                 n->plinline = $9;
    5243           72 :                 n->plvalidator = $10;
    5244           72 :                 n->pltrusted = $3;
    5245           72 :                 $$ = (Node *) n;
    5246              :             }
    5247              :         ;
    5248              : 
    5249              : opt_trusted:
    5250           57 :             TRUSTED                                 { $$ = true; }
    5251           19 :             | /*EMPTY*/                             { $$ = false; }
    5252              :         ;
    5253              : 
    5254              : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5255              :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5256              :  * Work around by using simple names, instead.
    5257              :  */
    5258              : handler_name:
    5259          288 :             name                        { $$ = list_make1(makeString($1)); }
    5260            1 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5261              :         ;
    5262              : 
    5263              : opt_inline_handler:
    5264           63 :             INLINE_P handler_name                   { $$ = $2; }
    5265            9 :             | /*EMPTY*/                             { $$ = NIL; }
    5266              :         ;
    5267              : 
    5268              : validator_clause:
    5269           63 :             VALIDATOR handler_name                  { $$ = $2; }
    5270            0 :             | NO VALIDATOR                          { $$ = NIL; }
    5271              :         ;
    5272              : 
    5273              : opt_validator:
    5274           63 :             validator_clause                        { $$ = $1; }
    5275            9 :             | /*EMPTY*/                             { $$ = NIL; }
    5276              :         ;
    5277              : 
    5278              : opt_procedural:
    5279              :             PROCEDURAL
    5280              :             | /*EMPTY*/
    5281              :         ;
    5282              : 
    5283              : /*****************************************************************************
    5284              :  *
    5285              :  *      QUERY:
    5286              :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5287              :  *
    5288              :  *****************************************************************************/
    5289              : 
    5290              : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5291              :                 {
    5292           69 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5293              : 
    5294           69 :                     n->tablespacename = $3;
    5295           69 :                     n->owner = $4;
    5296           69 :                     n->location = $6;
    5297           69 :                     n->options = $7;
    5298           69 :                     $$ = (Node *) n;
    5299              :                 }
    5300              :         ;
    5301              : 
    5302            7 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5303           62 :             | /*EMPTY */                { $$ = NULL; }
    5304              :         ;
    5305              : 
    5306              : /*****************************************************************************
    5307              :  *
    5308              :  *      QUERY :
    5309              :  *              DROP TABLESPACE <tablespace>
    5310              :  *
    5311              :  *      No need for drop behaviour as we cannot implement dependencies for
    5312              :  *      objects in other databases; we can only support RESTRICT.
    5313              :  *
    5314              :  ****************************************************************************/
    5315              : 
    5316              : DropTableSpaceStmt: DROP TABLESPACE name
    5317              :                 {
    5318           32 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5319              : 
    5320           32 :                     n->tablespacename = $3;
    5321           32 :                     n->missing_ok = false;
    5322           32 :                     $$ = (Node *) n;
    5323              :                 }
    5324              :                 |  DROP TABLESPACE IF_P EXISTS name
    5325              :                 {
    5326            0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5327              : 
    5328            0 :                     n->tablespacename = $5;
    5329            0 :                     n->missing_ok = true;
    5330            0 :                     $$ = (Node *) n;
    5331              :                 }
    5332              :         ;
    5333              : 
    5334              : /*****************************************************************************
    5335              :  *
    5336              :  *      QUERY:
    5337              :  *             CREATE EXTENSION extension
    5338              :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5339              :  *
    5340              :  *****************************************************************************/
    5341              : 
    5342              : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5343              :                 {
    5344          283 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5345              : 
    5346          283 :                     n->extname = $3;
    5347          283 :                     n->if_not_exists = false;
    5348          283 :                     n->options = $5;
    5349          283 :                     $$ = (Node *) n;
    5350              :                 }
    5351              :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5352              :                 {
    5353           10 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5354              : 
    5355           10 :                     n->extname = $6;
    5356           10 :                     n->if_not_exists = true;
    5357           10 :                     n->options = $8;
    5358           10 :                     $$ = (Node *) n;
    5359              :                 }
    5360              :         ;
    5361              : 
    5362              : create_extension_opt_list:
    5363              :             create_extension_opt_list create_extension_opt_item
    5364           49 :                 { $$ = lappend($1, $2); }
    5365              :             | /* EMPTY */
    5366          293 :                 { $$ = NIL; }
    5367              :         ;
    5368              : 
    5369              : create_extension_opt_item:
    5370              :             SCHEMA name
    5371              :                 {
    5372           23 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5373              :                 }
    5374              :             | VERSION_P NonReservedWord_or_Sconst
    5375              :                 {
    5376            6 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5377              :                 }
    5378              :             | FROM NonReservedWord_or_Sconst
    5379              :                 {
    5380            0 :                     ereport(ERROR,
    5381              :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5382              :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5383              :                              parser_errposition(@1)));
    5384              :                 }
    5385              :             | CASCADE
    5386              :                 {
    5387           20 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5388              :                 }
    5389              :         ;
    5390              : 
    5391              : /*****************************************************************************
    5392              :  *
    5393              :  * ALTER EXTENSION name UPDATE [ TO version ]
    5394              :  *
    5395              :  *****************************************************************************/
    5396              : 
    5397              : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5398              :                 {
    5399           20 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5400              : 
    5401           20 :                     n->extname = $3;
    5402           20 :                     n->options = $5;
    5403           20 :                     $$ = (Node *) n;
    5404              :                 }
    5405              :         ;
    5406              : 
    5407              : alter_extension_opt_list:
    5408              :             alter_extension_opt_list alter_extension_opt_item
    5409           20 :                 { $$ = lappend($1, $2); }
    5410              :             | /* EMPTY */
    5411           20 :                 { $$ = NIL; }
    5412              :         ;
    5413              : 
    5414              : alter_extension_opt_item:
    5415              :             TO NonReservedWord_or_Sconst
    5416              :                 {
    5417           20 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5418              :                 }
    5419              :         ;
    5420              : 
    5421              : /*****************************************************************************
    5422              :  *
    5423              :  * ALTER EXTENSION name ADD/DROP object-identifier
    5424              :  *
    5425              :  *****************************************************************************/
    5426              : 
    5427              : AlterExtensionContentsStmt:
    5428              :             ALTER EXTENSION name add_drop object_type_name name
    5429              :                 {
    5430            9 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5431              : 
    5432            9 :                     n->extname = $3;
    5433            9 :                     n->action = $4;
    5434            9 :                     n->objtype = $5;
    5435            9 :                     n->object = (Node *) makeString($6);
    5436            9 :                     $$ = (Node *) n;
    5437              :                 }
    5438              :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5439              :                 {
    5440           39 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5441              : 
    5442           39 :                     n->extname = $3;
    5443           39 :                     n->action = $4;
    5444           39 :                     n->objtype = $5;
    5445           39 :                     n->object = (Node *) $6;
    5446           39 :                     $$ = (Node *) n;
    5447              :                 }
    5448              :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5449              :                 {
    5450            4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5451              : 
    5452            4 :                     n->extname = $3;
    5453            4 :                     n->action = $4;
    5454            4 :                     n->objtype = OBJECT_AGGREGATE;
    5455            4 :                     n->object = (Node *) $6;
    5456            4 :                     $$ = (Node *) n;
    5457              :                 }
    5458              :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5459              :                 {
    5460            2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5461              : 
    5462            2 :                     n->extname = $3;
    5463            2 :                     n->action = $4;
    5464            2 :                     n->objtype = OBJECT_CAST;
    5465            2 :                     n->object = (Node *) list_make2($7, $9);
    5466            2 :                     $$ = (Node *) n;
    5467              :                 }
    5468              :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5469              :                 {
    5470            0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5471              : 
    5472            0 :                     n->extname = $3;
    5473            0 :                     n->action = $4;
    5474            0 :                     n->objtype = OBJECT_DOMAIN;
    5475            0 :                     n->object = (Node *) $6;
    5476            0 :                     $$ = (Node *) n;
    5477              :                 }
    5478              :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5479              :                 {
    5480           54 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5481              : 
    5482           54 :                     n->extname = $3;
    5483           54 :                     n->action = $4;
    5484           54 :                     n->objtype = OBJECT_FUNCTION;
    5485           54 :                     n->object = (Node *) $6;
    5486           54 :                     $$ = (Node *) n;
    5487              :                 }
    5488              :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5489              :                 {
    5490            9 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5491              : 
    5492            9 :                     n->extname = $3;
    5493            9 :                     n->action = $4;
    5494            9 :                     n->objtype = OBJECT_OPERATOR;
    5495            9 :                     n->object = (Node *) $6;
    5496            9 :                     $$ = (Node *) n;
    5497              :                 }
    5498              :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5499              :                 {
    5500            2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5501              : 
    5502            2 :                     n->extname = $3;
    5503            2 :                     n->action = $4;
    5504            2 :                     n->objtype = OBJECT_OPCLASS;
    5505            2 :                     n->object = (Node *) lcons(makeString($9), $7);
    5506            2 :                     $$ = (Node *) n;
    5507              :                 }
    5508              :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5509              :                 {
    5510            2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5511              : 
    5512            2 :                     n->extname = $3;
    5513            2 :                     n->action = $4;
    5514            2 :                     n->objtype = OBJECT_OPFAMILY;
    5515            2 :                     n->object = (Node *) lcons(makeString($9), $7);
    5516            2 :                     $$ = (Node *) n;
    5517              :                 }
    5518              :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5519              :                 {
    5520            0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5521              : 
    5522            0 :                     n->extname = $3;
    5523            0 :                     n->action = $4;
    5524            0 :                     n->objtype = OBJECT_PROCEDURE;
    5525            0 :                     n->object = (Node *) $6;
    5526            0 :                     $$ = (Node *) n;
    5527              :                 }
    5528              :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5529              :                 {
    5530            0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5531              : 
    5532            0 :                     n->extname = $3;
    5533            0 :                     n->action = $4;
    5534            0 :                     n->objtype = OBJECT_ROUTINE;
    5535            0 :                     n->object = (Node *) $6;
    5536            0 :                     $$ = (Node *) n;
    5537              :                 }
    5538              :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5539              :                 {
    5540            2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5541              : 
    5542            2 :                     n->extname = $3;
    5543            2 :                     n->action = $4;
    5544            2 :                     n->objtype = OBJECT_TRANSFORM;
    5545            2 :                     n->object = (Node *) list_make2($7, makeString($9));
    5546            2 :                     $$ = (Node *) n;
    5547              :                 }
    5548              :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5549              :                 {
    5550            4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5551              : 
    5552            4 :                     n->extname = $3;
    5553            4 :                     n->action = $4;
    5554            4 :                     n->objtype = OBJECT_TYPE;
    5555            4 :                     n->object = (Node *) $6;
    5556            4 :                     $$ = (Node *) n;
    5557              :                 }
    5558              :         ;
    5559              : 
    5560              : /*****************************************************************************
    5561              :  *
    5562              :  *      QUERY:
    5563              :  *             CREATE FOREIGN DATA WRAPPER name options
    5564              :  *
    5565              :  *****************************************************************************/
    5566              : 
    5567              : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5568              :                 {
    5569          104 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5570              : 
    5571          104 :                     n->fdwname = $5;
    5572          104 :                     n->func_options = $6;
    5573          104 :                     n->options = $7;
    5574          104 :                     $$ = (Node *) n;
    5575              :                 }
    5576              :         ;
    5577              : 
    5578              : fdw_option:
    5579           29 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5580            0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5581           25 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5582            3 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5583              :         ;
    5584              : 
    5585              : fdw_options:
    5586           46 :             fdw_option                          { $$ = list_make1($1); }
    5587           11 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5588              :         ;
    5589              : 
    5590              : opt_fdw_options:
    5591           28 :             fdw_options                         { $$ = $1; }
    5592          122 :             | /*EMPTY*/                         { $$ = NIL; }
    5593              :         ;
    5594              : 
    5595              : /*****************************************************************************
    5596              :  *
    5597              :  *      QUERY :
    5598              :  *              ALTER FOREIGN DATA WRAPPER name options
    5599              :  *
    5600              :  ****************************************************************************/
    5601              : 
    5602              : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5603              :                 {
    5604           43 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5605              : 
    5606           43 :                     n->fdwname = $5;
    5607           43 :                     n->func_options = $6;
    5608           43 :                     n->options = $7;
    5609           43 :                     $$ = (Node *) n;
    5610              :                 }
    5611              :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5612              :                 {
    5613           18 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5614              : 
    5615           18 :                     n->fdwname = $5;
    5616           18 :                     n->func_options = $6;
    5617           18 :                     n->options = NIL;
    5618           18 :                     $$ = (Node *) n;
    5619              :                 }
    5620              :         ;
    5621              : 
    5622              : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5623              : create_generic_options:
    5624          391 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5625        35619 :             | /*EMPTY*/                                 { $$ = NIL; }
    5626              :         ;
    5627              : 
    5628              : generic_option_list:
    5629              :             generic_option_elem
    5630              :                 {
    5631          391 :                     $$ = list_make1($1);
    5632              :                 }
    5633              :             | generic_option_list ',' generic_option_elem
    5634              :                 {
    5635          252 :                     $$ = lappend($1, $3);
    5636              :                 }
    5637              :         ;
    5638              : 
    5639              : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5640              : alter_generic_options:
    5641          254 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5642              :         ;
    5643              : 
    5644              : alter_generic_option_list:
    5645              :             alter_generic_option_elem
    5646              :                 {
    5647          254 :                     $$ = list_make1($1);
    5648              :                 }
    5649              :             | alter_generic_option_list ',' alter_generic_option_elem
    5650              :                 {
    5651           84 :                     $$ = lappend($1, $3);
    5652              :                 }
    5653              :         ;
    5654              : 
    5655              : alter_generic_option_elem:
    5656              :             generic_option_elem
    5657              :                 {
    5658          100 :                     $$ = $1;
    5659              :                 }
    5660              :             | SET generic_option_elem
    5661              :                 {
    5662           64 :                     $$ = $2;
    5663           64 :                     $$->defaction = DEFELEM_SET;
    5664              :                 }
    5665              :             | ADD_P generic_option_elem
    5666              :                 {
    5667          110 :                     $$ = $2;
    5668          110 :                     $$->defaction = DEFELEM_ADD;
    5669              :                 }
    5670              :             | DROP generic_option_name
    5671              :                 {
    5672           64 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5673              :                 }
    5674              :         ;
    5675              : 
    5676              : generic_option_elem:
    5677              :             generic_option_name generic_option_arg
    5678              :                 {
    5679          917 :                     $$ = makeDefElem($1, $2, @1);
    5680              :                 }
    5681              :         ;
    5682              : 
    5683              : generic_option_name:
    5684          981 :                 ColLabel            { $$ = $1; }
    5685              :         ;
    5686              : 
    5687              : /* We could use def_arg here, but the spec only requires string literals */
    5688              : generic_option_arg:
    5689          917 :                 Sconst              { $$ = (Node *) makeString($1); }
    5690              :         ;
    5691              : 
    5692              : /*****************************************************************************
    5693              :  *
    5694              :  *      QUERY:
    5695              :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5696              :  *
    5697              :  *****************************************************************************/
    5698              : 
    5699              : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5700              :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5701              :                 {
    5702          140 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5703              : 
    5704          140 :                     n->servername = $3;
    5705          140 :                     n->servertype = $4;
    5706          140 :                     n->version = $5;
    5707          140 :                     n->fdwname = $9;
    5708          140 :                     n->options = $10;
    5709          140 :                     n->if_not_exists = false;
    5710          140 :                     $$ = (Node *) n;
    5711              :                 }
    5712              :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5713              :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5714              :                 {
    5715           12 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5716              : 
    5717           12 :                     n->servername = $6;
    5718           12 :                     n->servertype = $7;
    5719           12 :                     n->version = $8;
    5720           12 :                     n->fdwname = $12;
    5721           12 :                     n->options = $13;
    5722           12 :                     n->if_not_exists = true;
    5723           12 :                     $$ = (Node *) n;
    5724              :                 }
    5725              :         ;
    5726              : 
    5727              : opt_type:
    5728            9 :             TYPE_P Sconst           { $$ = $2; }
    5729          143 :             | /*EMPTY*/             { $$ = NULL; }
    5730              :         ;
    5731              : 
    5732              : 
    5733              : foreign_server_version:
    5734           33 :             VERSION_P Sconst        { $$ = $2; }
    5735            0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5736              :         ;
    5737              : 
    5738              : opt_foreign_server_version:
    5739            9 :             foreign_server_version  { $$ = $1; }
    5740          143 :             | /*EMPTY*/             { $$ = NULL; }
    5741              :         ;
    5742              : 
    5743              : /*****************************************************************************
    5744              :  *
    5745              :  *      QUERY :
    5746              :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5747              :  *
    5748              :  ****************************************************************************/
    5749              : 
    5750              : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5751              :                 {
    5752            3 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5753              : 
    5754            3 :                     n->servername = $3;
    5755            3 :                     n->version = $4;
    5756            3 :                     n->options = $5;
    5757            3 :                     n->has_version = true;
    5758            3 :                     $$ = (Node *) n;
    5759              :                 }
    5760              :             | ALTER SERVER name foreign_server_version
    5761              :                 {
    5762           21 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5763              : 
    5764           21 :                     n->servername = $3;
    5765           21 :                     n->version = $4;
    5766           21 :                     n->has_version = true;
    5767           21 :                     $$ = (Node *) n;
    5768              :                 }
    5769              :             | ALTER SERVER name alter_generic_options
    5770              :                 {
    5771           92 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5772              : 
    5773           92 :                     n->servername = $3;
    5774           92 :                     n->options = $4;
    5775           92 :                     $$ = (Node *) n;
    5776              :                 }
    5777              :         ;
    5778              : 
    5779              : /*****************************************************************************
    5780              :  *
    5781              :  *      QUERY:
    5782              :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5783              :  *
    5784              :  *****************************************************************************/
    5785              : 
    5786              : CreateForeignTableStmt:
    5787              :         CREATE FOREIGN TABLE qualified_name
    5788              :             '(' OptTableElementList ')'
    5789              :             OptInherit SERVER name create_generic_options
    5790              :                 {
    5791          215 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5792              : 
    5793          215 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5794          215 :                     n->base.relation = $4;
    5795          215 :                     n->base.tableElts = $6;
    5796          215 :                     n->base.inhRelations = $8;
    5797          215 :                     n->base.ofTypename = NULL;
    5798          215 :                     n->base.constraints = NIL;
    5799          215 :                     n->base.options = NIL;
    5800          215 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5801          215 :                     n->base.tablespacename = NULL;
    5802          215 :                     n->base.if_not_exists = false;
    5803              :                     /* FDW-specific data */
    5804          215 :                     n->servername = $10;
    5805          215 :                     n->options = $11;
    5806          215 :                     $$ = (Node *) n;
    5807              :                 }
    5808              :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5809              :             '(' OptTableElementList ')'
    5810              :             OptInherit SERVER name create_generic_options
    5811              :                 {
    5812            0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5813              : 
    5814            0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5815            0 :                     n->base.relation = $7;
    5816            0 :                     n->base.tableElts = $9;
    5817            0 :                     n->base.inhRelations = $11;
    5818            0 :                     n->base.ofTypename = NULL;
    5819            0 :                     n->base.constraints = NIL;
    5820            0 :                     n->base.options = NIL;
    5821            0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5822            0 :                     n->base.tablespacename = NULL;
    5823            0 :                     n->base.if_not_exists = true;
    5824              :                     /* FDW-specific data */
    5825            0 :                     n->servername = $13;
    5826            0 :                     n->options = $14;
    5827            0 :                     $$ = (Node *) n;
    5828              :                 }
    5829              :         | CREATE FOREIGN TABLE qualified_name
    5830              :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5831              :             SERVER name create_generic_options
    5832              :                 {
    5833           45 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5834              : 
    5835           45 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5836           45 :                     n->base.relation = $4;
    5837           45 :                     n->base.inhRelations = list_make1($7);
    5838           45 :                     n->base.tableElts = $8;
    5839           45 :                     n->base.partbound = $9;
    5840           45 :                     n->base.ofTypename = NULL;
    5841           45 :                     n->base.constraints = NIL;
    5842           45 :                     n->base.options = NIL;
    5843           45 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5844           45 :                     n->base.tablespacename = NULL;
    5845           45 :                     n->base.if_not_exists = false;
    5846              :                     /* FDW-specific data */
    5847           45 :                     n->servername = $11;
    5848           45 :                     n->options = $12;
    5849           45 :                     $$ = (Node *) n;
    5850              :                 }
    5851              :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5852              :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5853              :             SERVER name create_generic_options
    5854              :                 {
    5855            0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5856              : 
    5857            0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5858            0 :                     n->base.relation = $7;
    5859            0 :                     n->base.inhRelations = list_make1($10);
    5860            0 :                     n->base.tableElts = $11;
    5861            0 :                     n->base.partbound = $12;
    5862            0 :                     n->base.ofTypename = NULL;
    5863            0 :                     n->base.constraints = NIL;
    5864            0 :                     n->base.options = NIL;
    5865            0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5866            0 :                     n->base.tablespacename = NULL;
    5867            0 :                     n->base.if_not_exists = true;
    5868              :                     /* FDW-specific data */
    5869            0 :                     n->servername = $14;
    5870            0 :                     n->options = $15;
    5871            0 :                     $$ = (Node *) n;
    5872              :                 }
    5873              :         ;
    5874              : 
    5875              : /*****************************************************************************
    5876              :  *
    5877              :  *      QUERY:
    5878              :  *              IMPORT FOREIGN SCHEMA remote_schema
    5879              :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5880              :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5881              :  *
    5882              :  ****************************************************************************/
    5883              : 
    5884              : ImportForeignSchemaStmt:
    5885              :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5886              :           FROM SERVER name INTO name create_generic_options
    5887              :             {
    5888           24 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5889              : 
    5890           24 :                 n->server_name = $8;
    5891           24 :                 n->remote_schema = $4;
    5892           24 :                 n->local_schema = $10;
    5893           24 :                 n->list_type = $5->type;
    5894           24 :                 n->table_list = $5->table_names;
    5895           24 :                 n->options = $11;
    5896           24 :                 $$ = (Node *) n;
    5897              :             }
    5898              :         ;
    5899              : 
    5900              : import_qualification_type:
    5901            7 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5902            7 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5903              :         ;
    5904              : 
    5905              : import_qualification:
    5906              :         import_qualification_type '(' relation_expr_list ')'
    5907              :             {
    5908           14 :                 ImportQual *n = palloc_object(ImportQual);
    5909              : 
    5910           14 :                 n->type = $1;
    5911           14 :                 n->table_names = $3;
    5912           14 :                 $$ = n;
    5913              :             }
    5914              :         | /*EMPTY*/
    5915              :             {
    5916           10 :                 ImportQual *n = palloc_object(ImportQual);
    5917           10 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5918           10 :                 n->table_names = NIL;
    5919           10 :                 $$ = n;
    5920              :             }
    5921              :         ;
    5922              : 
    5923              : /*****************************************************************************
    5924              :  *
    5925              :  *      QUERY:
    5926              :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5927              :  *
    5928              :  *****************************************************************************/
    5929              : 
    5930              : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5931              :                 {
    5932          127 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5933              : 
    5934          127 :                     n->user = $5;
    5935          127 :                     n->servername = $7;
    5936          127 :                     n->options = $8;
    5937          127 :                     n->if_not_exists = false;
    5938          127 :                     $$ = (Node *) n;
    5939              :                 }
    5940              :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5941              :                 {
    5942            3 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5943              : 
    5944            3 :                     n->user = $8;
    5945            3 :                     n->servername = $10;
    5946            3 :                     n->options = $11;
    5947            3 :                     n->if_not_exists = true;
    5948            3 :                     $$ = (Node *) n;
    5949              :                 }
    5950              :         ;
    5951              : 
    5952              : /* User mapping authorization identifier */
    5953          229 : auth_ident: RoleSpec            { $$ = $1; }
    5954           23 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5955              :         ;
    5956              : 
    5957              : /*****************************************************************************
    5958              :  *
    5959              :  *      QUERY :
    5960              :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5961              :  *
    5962              :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5963              :  * only pro forma; but the SQL standard doesn't show one.
    5964              :  ****************************************************************************/
    5965              : 
    5966              : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5967              :                 {
    5968           44 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5969              : 
    5970           44 :                     n->user = $5;
    5971           44 :                     n->servername = $7;
    5972           44 :                     n->missing_ok = false;
    5973           44 :                     $$ = (Node *) n;
    5974              :                 }
    5975              :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5976              :                 {
    5977           19 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5978              : 
    5979           19 :                     n->user = $7;
    5980           19 :                     n->servername = $9;
    5981           19 :                     n->missing_ok = true;
    5982           19 :                     $$ = (Node *) n;
    5983              :                 }
    5984              :         ;
    5985              : 
    5986              : /*****************************************************************************
    5987              :  *
    5988              :  *      QUERY :
    5989              :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5990              :  *
    5991              :  ****************************************************************************/
    5992              : 
    5993              : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5994              :                 {
    5995           59 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5996              : 
    5997           59 :                     n->user = $5;
    5998           59 :                     n->servername = $7;
    5999           59 :                     n->options = $8;
    6000           59 :                     $$ = (Node *) n;
    6001              :                 }
    6002              :         ;
    6003              : 
    6004              : /*****************************************************************************
    6005              :  *
    6006              :  *      QUERIES:
    6007              :  *              CREATE POLICY name ON table
    6008              :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    6009              :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    6010              :  *                  [TO role, ...]
    6011              :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    6012              :  *              ALTER POLICY name ON table [TO role, ...]
    6013              :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    6014              :  *
    6015              :  *****************************************************************************/
    6016              : 
    6017              : CreatePolicyStmt:
    6018              :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    6019              :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    6020              :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    6021              :                 {
    6022          395 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    6023              : 
    6024          395 :                     n->policy_name = $3;
    6025          395 :                     n->table = $5;
    6026          395 :                     n->permissive = $6;
    6027          395 :                     n->cmd_name = $7;
    6028          395 :                     n->roles = $8;
    6029          395 :                     n->qual = $9;
    6030          395 :                     n->with_check = $10;
    6031          395 :                     $$ = (Node *) n;
    6032              :                 }
    6033              :         ;
    6034              : 
    6035              : AlterPolicyStmt:
    6036              :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    6037              :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    6038              :                 {
    6039           42 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    6040              : 
    6041           42 :                     n->policy_name = $3;
    6042           42 :                     n->table = $5;
    6043           42 :                     n->roles = $6;
    6044           42 :                     n->qual = $7;
    6045           42 :                     n->with_check = $8;
    6046           42 :                     $$ = (Node *) n;
    6047              :                 }
    6048              :         ;
    6049              : 
    6050              : RowSecurityOptionalExpr:
    6051          402 :             USING '(' a_expr ')'    { $$ = $3; }
    6052           35 :             | /* EMPTY */           { $$ = NULL; }
    6053              :         ;
    6054              : 
    6055              : RowSecurityOptionalWithCheck:
    6056           76 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    6057          361 :             | /* EMPTY */                   { $$ = NULL; }
    6058              :         ;
    6059              : 
    6060              : RowSecurityDefaultToRole:
    6061           65 :             TO role_list            { $$ = $2; }
    6062          330 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    6063              :         ;
    6064              : 
    6065              : RowSecurityOptionalToRole:
    6066            6 :             TO role_list            { $$ = $2; }
    6067           36 :             | /* EMPTY */           { $$ = NULL; }
    6068              :         ;
    6069              : 
    6070              : RowSecurityDefaultPermissive:
    6071              :             AS IDENT
    6072              :                 {
    6073           49 :                     if (strcmp($2, "permissive") == 0)
    6074           12 :                         $$ = true;
    6075           37 :                     else if (strcmp($2, "restrictive") == 0)
    6076           34 :                         $$ = false;
    6077              :                     else
    6078            3 :                         ereport(ERROR,
    6079              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6080              :                                  errmsg("unrecognized row security option \"%s\"", $2),
    6081              :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    6082              :                                  parser_errposition(@2)));
    6083              : 
    6084              :                 }
    6085          349 :             | /* EMPTY */           { $$ = true; }
    6086              :         ;
    6087              : 
    6088              : RowSecurityDefaultForCmd:
    6089          187 :             FOR row_security_cmd    { $$ = $2; }
    6090          208 :             | /* EMPTY */           { $$ = "all"; }
    6091              :         ;
    6092              : 
    6093              : row_security_cmd:
    6094           22 :             ALL             { $$ = "all"; }
    6095           65 :         |   SELECT          { $$ = "select"; }
    6096           28 :         |   INSERT          { $$ = "insert"; }
    6097           48 :         |   UPDATE          { $$ = "update"; }
    6098           24 :         |   DELETE_P        { $$ = "delete"; }
    6099              :         ;
    6100              : 
    6101              : /*****************************************************************************
    6102              :  *
    6103              :  *      QUERY:
    6104              :  *             CREATE ACCESS METHOD name HANDLER handler_name
    6105              :  *
    6106              :  *****************************************************************************/
    6107              : 
    6108              : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    6109              :                 {
    6110           37 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    6111              : 
    6112           37 :                     n->amname = $4;
    6113           37 :                     n->handler_name = $8;
    6114           37 :                     n->amtype = $6;
    6115           37 :                     $$ = (Node *) n;
    6116              :                 }
    6117              :         ;
    6118              : 
    6119              : am_type:
    6120           17 :             INDEX           { $$ = AMTYPE_INDEX; }
    6121           20 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    6122              :         ;
    6123              : 
    6124              : /*****************************************************************************
    6125              :  *
    6126              :  *      QUERIES :
    6127              :  *              CREATE TRIGGER ...
    6128              :  *
    6129              :  *****************************************************************************/
    6130              : 
    6131              : CreateTrigStmt:
    6132              :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    6133              :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    6134              :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6135              :                 {
    6136         1617 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6137              : 
    6138         1617 :                     n->replace = $2;
    6139         1617 :                     n->isconstraint = false;
    6140         1617 :                     n->trigname = $4;
    6141         1617 :                     n->relation = $8;
    6142         1617 :                     n->funcname = $14;
    6143         1617 :                     n->args = $16;
    6144         1617 :                     n->row = $10;
    6145         1617 :                     n->timing = $5;
    6146         1617 :                     n->events = intVal(linitial($6));
    6147         1617 :                     n->columns = (List *) lsecond($6);
    6148         1617 :                     n->whenClause = $11;
    6149         1617 :                     n->transitionRels = $9;
    6150         1617 :                     n->deferrable = false;
    6151         1617 :                     n->initdeferred = false;
    6152         1617 :                     n->constrrel = NULL;
    6153         1617 :                     $$ = (Node *) n;
    6154              :                 }
    6155              :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6156              :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6157              :             FOR EACH ROW TriggerWhen
    6158              :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6159              :                 {
    6160           40 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6161              :                     bool        dummy;
    6162              : 
    6163           40 :                     if (($11 & CAS_NOT_VALID) != 0)
    6164            3 :                         ereport(ERROR,
    6165              :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6166              :                                 errmsg("constraint triggers cannot be marked %s",
    6167              :                                        "NOT VALID"),
    6168              :                                 parser_errposition(@11));
    6169           37 :                     if (($11 & CAS_NO_INHERIT) != 0)
    6170            3 :                         ereport(ERROR,
    6171              :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6172              :                                 errmsg("constraint triggers cannot be marked %s",
    6173              :                                        "NO INHERIT"),
    6174              :                                 parser_errposition(@11));
    6175           34 :                     if (($11 & CAS_NOT_ENFORCED) != 0)
    6176            3 :                         ereport(ERROR,
    6177              :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6178              :                                 errmsg("constraint triggers cannot be marked %s",
    6179              :                                        "NOT ENFORCED"),
    6180              :                                 parser_errposition(@11));
    6181              : 
    6182           31 :                     n->replace = $2;
    6183           31 :                     if (n->replace) /* not supported, see CreateTrigger */
    6184            0 :                         ereport(ERROR,
    6185              :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6186              :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6187              :                                  parser_errposition(@1)));
    6188           31 :                     n->isconstraint = true;
    6189           31 :                     n->trigname = $5;
    6190           31 :                     n->relation = $9;
    6191           31 :                     n->funcname = $18;
    6192           31 :                     n->args = $20;
    6193           31 :                     n->row = true;
    6194           31 :                     n->timing = TRIGGER_TYPE_AFTER;
    6195           31 :                     n->events = intVal(linitial($7));
    6196           31 :                     n->columns = (List *) lsecond($7);
    6197           31 :                     n->whenClause = $15;
    6198           31 :                     n->transitionRels = NIL;
    6199           31 :                     processCASbits($11, @11, "TRIGGER",
    6200              :                                    &n->deferrable, &n->initdeferred, &dummy,
    6201              :                                    NULL, NULL, yyscanner);
    6202           31 :                     n->constrrel = $10;
    6203           31 :                     $$ = (Node *) n;
    6204              :                 }
    6205              :         ;
    6206              : 
    6207              : TriggerActionTime:
    6208          737 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6209          814 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6210           72 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6211              :         ;
    6212              : 
    6213              : TriggerEvents:
    6214              :             TriggerOneEvent
    6215         1663 :                 { $$ = $1; }
    6216              :             | TriggerEvents OR TriggerOneEvent
    6217              :                 {
    6218          581 :                     int         events1 = intVal(linitial($1));
    6219          581 :                     int         events2 = intVal(linitial($3));
    6220          581 :                     List       *columns1 = (List *) lsecond($1);
    6221          581 :                     List       *columns2 = (List *) lsecond($3);
    6222              : 
    6223          581 :                     if (events1 & events2)
    6224            3 :                         parser_yyerror("duplicate trigger events specified");
    6225              :                     /*
    6226              :                      * concat'ing the columns lists loses information about
    6227              :                      * which columns went with which event, but so long as
    6228              :                      * only UPDATE carries columns and we disallow multiple
    6229              :                      * UPDATE items, it doesn't matter.  Command execution
    6230              :                      * should just ignore the columns for non-UPDATE events.
    6231              :                      */
    6232          578 :                     $$ = list_make2(makeInteger(events1 | events2),
    6233              :                                     list_concat(columns1, columns2));
    6234              :                 }
    6235              :         ;
    6236              : 
    6237              : TriggerOneEvent:
    6238              :             INSERT
    6239          868 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6240              :             | DELETE_P
    6241          443 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6242              :             | UPDATE
    6243          862 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6244              :             | UPDATE OF columnList
    6245           50 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6246              :             | TRUNCATE
    6247           21 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6248              :         ;
    6249              : 
    6250              : TriggerReferencing:
    6251          232 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6252         1385 :             | /*EMPTY*/                             { $$ = NIL; }
    6253              :         ;
    6254              : 
    6255              : TriggerTransitions:
    6256          232 :             TriggerTransition                       { $$ = list_make1($1); }
    6257           71 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6258              :         ;
    6259              : 
    6260              : TriggerTransition:
    6261              :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6262              :                 {
    6263          303 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6264              : 
    6265          303 :                     n->name = $4;
    6266          303 :                     n->isNew = $1;
    6267          303 :                     n->isTable = $2;
    6268          303 :                     $$ = (Node *) n;
    6269              :                 }
    6270              :         ;
    6271              : 
    6272              : TransitionOldOrNew:
    6273          165 :             NEW                                     { $$ = true; }
    6274          138 :             | OLD                                   { $$ = false; }
    6275              :         ;
    6276              : 
    6277              : TransitionRowOrTable:
    6278          303 :             TABLE                                   { $$ = true; }
    6279              :             /*
    6280              :              * According to the standard, lack of a keyword here implies ROW.
    6281              :              * Support for that would require prohibiting ROW entirely here,
    6282              :              * reserving the keyword ROW, and/or requiring AS (instead of
    6283              :              * allowing it to be optional, as the standard specifies) as the
    6284              :              * next token.  Requiring ROW seems cleanest and easiest to
    6285              :              * explain.
    6286              :              */
    6287            0 :             | ROW                                   { $$ = false; }
    6288              :         ;
    6289              : 
    6290              : TransitionRelName:
    6291          303 :             ColId                                   { $$ = $1; }
    6292              :         ;
    6293              : 
    6294              : TriggerForSpec:
    6295              :             FOR TriggerForOptEach TriggerForType
    6296              :                 {
    6297         1497 :                     $$ = $3;
    6298              :                 }
    6299              :             | /* EMPTY */
    6300              :                 {
    6301              :                     /*
    6302              :                      * If ROW/STATEMENT not specified, default to
    6303              :                      * STATEMENT, per SQL
    6304              :                      */
    6305          120 :                     $$ = false;
    6306              :                 }
    6307              :         ;
    6308              : 
    6309              : TriggerForOptEach:
    6310              :             EACH
    6311              :             | /*EMPTY*/
    6312              :         ;
    6313              : 
    6314              : TriggerForType:
    6315         1079 :             ROW                                     { $$ = true; }
    6316          418 :             | STATEMENT                             { $$ = false; }
    6317              :         ;
    6318              : 
    6319              : TriggerWhen:
    6320           95 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6321         1562 :             | /*EMPTY*/                             { $$ = NULL; }
    6322              :         ;
    6323              : 
    6324              : FUNCTION_or_PROCEDURE:
    6325              :             FUNCTION
    6326              :         |   PROCEDURE
    6327              :         ;
    6328              : 
    6329              : TriggerFuncArgs:
    6330          300 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6331           81 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6332         1357 :             | /*EMPTY*/                             { $$ = NIL; }
    6333              :         ;
    6334              : 
    6335              : TriggerFuncArg:
    6336              :             Iconst
    6337              :                 {
    6338           47 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6339              :                 }
    6340            0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6341          323 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6342           11 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6343              :         ;
    6344              : 
    6345              : OptConstrFromTable:
    6346            6 :             FROM qualified_name                     { $$ = $2; }
    6347           34 :             | /*EMPTY*/                             { $$ = NULL; }
    6348              :         ;
    6349              : 
    6350              : ConstraintAttributeSpec:
    6351              :             /*EMPTY*/
    6352         9168 :                 { $$ = 0; }
    6353              :             | ConstraintAttributeSpec ConstraintAttributeElem
    6354              :                 {
    6355              :                     /*
    6356              :                      * We must complain about conflicting options.
    6357              :                      * We could, but choose not to, complain about redundant
    6358              :                      * options (ie, where $2's bit is already set in $1).
    6359              :                      */
    6360          869 :                     int     newspec = $1 | $2;
    6361              : 
    6362              :                     /* special message for this case */
    6363          869 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6364            3 :                         ereport(ERROR,
    6365              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6366              :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6367              :                                  parser_errposition(@2)));
    6368              :                     /* generic message for other conflicts */
    6369          866 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6370          866 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6371          866 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6372            3 :                         ereport(ERROR,
    6373              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6374              :                                  errmsg("conflicting constraint properties"),
    6375              :                                  parser_errposition(@2)));
    6376          863 :                     $$ = newspec;
    6377              :                 }
    6378              :         ;
    6379              : 
    6380              : ConstraintAttributeElem:
    6381           21 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6382          100 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6383           15 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6384           76 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6385          381 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6386          126 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6387           93 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6388           57 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6389              :         ;
    6390              : 
    6391              : 
    6392              : /*****************************************************************************
    6393              :  *
    6394              :  *      QUERIES :
    6395              :  *              CREATE EVENT TRIGGER ...
    6396              :  *              ALTER EVENT TRIGGER ...
    6397              :  *
    6398              :  *****************************************************************************/
    6399              : 
    6400              : CreateEventTrigStmt:
    6401              :             CREATE EVENT TRIGGER name ON ColLabel
    6402              :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6403              :                 {
    6404           51 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6405              : 
    6406           51 :                     n->trigname = $4;
    6407           51 :                     n->eventname = $6;
    6408           51 :                     n->whenclause = NULL;
    6409           51 :                     n->funcname = $9;
    6410           51 :                     $$ = (Node *) n;
    6411              :                 }
    6412              :           | CREATE EVENT TRIGGER name ON ColLabel
    6413              :             WHEN event_trigger_when_list
    6414              :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6415              :                 {
    6416           49 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6417              : 
    6418           49 :                     n->trigname = $4;
    6419           49 :                     n->eventname = $6;
    6420           49 :                     n->whenclause = $8;
    6421           49 :                     n->funcname = $11;
    6422           49 :                     $$ = (Node *) n;
    6423              :                 }
    6424              :         ;
    6425              : 
    6426              : event_trigger_when_list:
    6427              :           event_trigger_when_item
    6428           49 :             { $$ = list_make1($1); }
    6429              :         | event_trigger_when_list AND event_trigger_when_item
    6430            3 :             { $$ = lappend($1, $3); }
    6431              :         ;
    6432              : 
    6433              : event_trigger_when_item:
    6434              :         ColId IN_P '(' event_trigger_value_list ')'
    6435           52 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6436              :         ;
    6437              : 
    6438              : event_trigger_value_list:
    6439              :           SCONST
    6440           52 :             { $$ = list_make1(makeString($1)); }
    6441              :         | event_trigger_value_list ',' SCONST
    6442           33 :             { $$ = lappend($1, makeString($3)); }
    6443              :         ;
    6444              : 
    6445              : AlterEventTrigStmt:
    6446              :             ALTER EVENT TRIGGER name enable_trigger
    6447              :                 {
    6448           24 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6449              : 
    6450           24 :                     n->trigname = $4;
    6451           24 :                     n->tgenabled = $5;
    6452           24 :                     $$ = (Node *) n;
    6453              :                 }
    6454              :         ;
    6455              : 
    6456              : enable_trigger:
    6457            3 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6458            3 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6459            8 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6460           10 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6461              :         ;
    6462              : 
    6463              : /*****************************************************************************
    6464              :  *
    6465              :  *      QUERY :
    6466              :  *              CREATE ASSERTION ...
    6467              :  *
    6468              :  *****************************************************************************/
    6469              : 
    6470              : CreateAssertionStmt:
    6471              :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6472              :                 {
    6473            0 :                     ereport(ERROR,
    6474              :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6475              :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6476              :                              parser_errposition(@1)));
    6477              : 
    6478              :                     $$ = NULL;
    6479              :                 }
    6480              :         ;
    6481              : 
    6482              : 
    6483              : /*****************************************************************************
    6484              :  *
    6485              :  *      QUERY :
    6486              :  *              define (aggregate,operator,type)
    6487              :  *
    6488              :  *****************************************************************************/
    6489              : 
    6490              : DefineStmt:
    6491              :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6492              :                 {
    6493          272 :                     DefineStmt *n = makeNode(DefineStmt);
    6494              : 
    6495          272 :                     n->kind = OBJECT_AGGREGATE;
    6496          272 :                     n->oldstyle = false;
    6497          272 :                     n->replace = $2;
    6498          272 :                     n->defnames = $4;
    6499          272 :                     n->args = $5;
    6500          272 :                     n->definition = $6;
    6501          272 :                     $$ = (Node *) n;
    6502              :                 }
    6503              :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6504              :                 {
    6505              :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6506          181 :                     DefineStmt *n = makeNode(DefineStmt);
    6507              : 
    6508          181 :                     n->kind = OBJECT_AGGREGATE;
    6509          181 :                     n->oldstyle = true;
    6510          181 :                     n->replace = $2;
    6511          181 :                     n->defnames = $4;
    6512          181 :                     n->args = NIL;
    6513          181 :                     n->definition = $5;
    6514          181 :                     $$ = (Node *) n;
    6515              :                 }
    6516              :             | CREATE OPERATOR any_operator definition
    6517              :                 {
    6518          827 :                     DefineStmt *n = makeNode(DefineStmt);
    6519              : 
    6520          827 :                     n->kind = OBJECT_OPERATOR;
    6521          827 :                     n->oldstyle = false;
    6522          827 :                     n->defnames = $3;
    6523          827 :                     n->args = NIL;
    6524          827 :                     n->definition = $4;
    6525          827 :                     $$ = (Node *) n;
    6526              :                 }
    6527              :             | CREATE TYPE_P any_name definition
    6528              :                 {
    6529          121 :                     DefineStmt *n = makeNode(DefineStmt);
    6530              : 
    6531          121 :                     n->kind = OBJECT_TYPE;
    6532          121 :                     n->oldstyle = false;
    6533          121 :                     n->defnames = $3;
    6534          121 :                     n->args = NIL;
    6535          121 :                     n->definition = $4;
    6536          121 :                     $$ = (Node *) n;
    6537              :                 }
    6538              :             | CREATE TYPE_P any_name
    6539              :                 {
    6540              :                     /* Shell type (identified by lack of definition) */
    6541           78 :                     DefineStmt *n = makeNode(DefineStmt);
    6542              : 
    6543           78 :                     n->kind = OBJECT_TYPE;
    6544           78 :                     n->oldstyle = false;
    6545           78 :                     n->defnames = $3;
    6546           78 :                     n->args = NIL;
    6547           78 :                     n->definition = NIL;
    6548           78 :                     $$ = (Node *) n;
    6549              :                 }
    6550              :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6551              :                 {
    6552         2254 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6553              : 
    6554              :                     /* can't use qualified_name, sigh */
    6555         2254 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6556         2254 :                     n->coldeflist = $6;
    6557         2254 :                     $$ = (Node *) n;
    6558              :                 }
    6559              :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6560              :                 {
    6561          104 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6562              : 
    6563          104 :                     n->typeName = $3;
    6564          104 :                     n->vals = $7;
    6565          104 :                     $$ = (Node *) n;
    6566              :                 }
    6567              :             | CREATE TYPE_P any_name AS RANGE definition
    6568              :                 {
    6569           92 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6570              : 
    6571           92 :                     n->typeName = $3;
    6572           92 :                     n->params = $6;
    6573           92 :                     $$ = (Node *) n;
    6574              :                 }
    6575              :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6576              :                 {
    6577           20 :                     DefineStmt *n = makeNode(DefineStmt);
    6578              : 
    6579           20 :                     n->kind = OBJECT_TSPARSER;
    6580           20 :                     n->args = NIL;
    6581           20 :                     n->defnames = $5;
    6582           20 :                     n->definition = $6;
    6583           20 :                     $$ = (Node *) n;
    6584              :                 }
    6585              :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6586              :                 {
    6587         1592 :                     DefineStmt *n = makeNode(DefineStmt);
    6588              : 
    6589         1592 :                     n->kind = OBJECT_TSDICTIONARY;
    6590         1592 :                     n->args = NIL;
    6591         1592 :                     n->defnames = $5;
    6592         1592 :                     n->definition = $6;
    6593         1592 :                     $$ = (Node *) n;
    6594              :                 }
    6595              :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6596              :                 {
    6597           71 :                     DefineStmt *n = makeNode(DefineStmt);
    6598              : 
    6599           71 :                     n->kind = OBJECT_TSTEMPLATE;
    6600           71 :                     n->args = NIL;
    6601           71 :                     n->defnames = $5;
    6602           71 :                     n->definition = $6;
    6603           71 :                     $$ = (Node *) n;
    6604              :                 }
    6605              :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6606              :                 {
    6607         1563 :                     DefineStmt *n = makeNode(DefineStmt);
    6608              : 
    6609         1563 :                     n->kind = OBJECT_TSCONFIGURATION;
    6610         1563 :                     n->args = NIL;
    6611         1563 :                     n->defnames = $5;
    6612         1563 :                     n->definition = $6;
    6613         1563 :                     $$ = (Node *) n;
    6614              :                 }
    6615              :             | CREATE COLLATION any_name definition
    6616              :                 {
    6617          146 :                     DefineStmt *n = makeNode(DefineStmt);
    6618              : 
    6619          146 :                     n->kind = OBJECT_COLLATION;
    6620          146 :                     n->args = NIL;
    6621          146 :                     n->defnames = $3;
    6622          146 :                     n->definition = $4;
    6623          146 :                     $$ = (Node *) n;
    6624              :                 }
    6625              :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6626              :                 {
    6627            9 :                     DefineStmt *n = makeNode(DefineStmt);
    6628              : 
    6629            9 :                     n->kind = OBJECT_COLLATION;
    6630            9 :                     n->args = NIL;
    6631            9 :                     n->defnames = $6;
    6632            9 :                     n->definition = $7;
    6633            9 :                     n->if_not_exists = true;
    6634            9 :                     $$ = (Node *) n;
    6635              :                 }
    6636              :             | CREATE COLLATION any_name FROM any_name
    6637              :                 {
    6638           27 :                     DefineStmt *n = makeNode(DefineStmt);
    6639              : 
    6640           27 :                     n->kind = OBJECT_COLLATION;
    6641           27 :                     n->args = NIL;
    6642           27 :                     n->defnames = $3;
    6643           27 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6644           27 :                     $$ = (Node *) n;
    6645              :                 }
    6646              :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6647              :                 {
    6648            0 :                     DefineStmt *n = makeNode(DefineStmt);
    6649              : 
    6650            0 :                     n->kind = OBJECT_COLLATION;
    6651            0 :                     n->args = NIL;
    6652            0 :                     n->defnames = $6;
    6653            0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6654            0 :                     n->if_not_exists = true;
    6655            0 :                     $$ = (Node *) n;
    6656              :                 }
    6657              :         ;
    6658              : 
    6659         5258 : definition: '(' def_list ')'                        { $$ = $2; }
    6660              :         ;
    6661              : 
    6662         5258 : def_list:   def_elem                                { $$ = list_make1($1); }
    6663         7592 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6664              :         ;
    6665              : 
    6666              : def_elem:   ColLabel '=' def_arg
    6667              :                 {
    6668        12679 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6669              :                 }
    6670              :             | ColLabel
    6671              :                 {
    6672          171 :                     $$ = makeDefElem($1, NULL, @1);
    6673              :                 }
    6674              :         ;
    6675              : 
    6676              : /* Note: any simple identifier will be returned as a type name! */
    6677        10174 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6678         2245 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6679          600 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6680          688 :             | NumericOnly                   { $$ = (Node *) $1; }
    6681          966 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6682           91 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6683              :         ;
    6684              : 
    6685          181 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6686              :         ;
    6687              : 
    6688          181 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6689          646 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6690              :         ;
    6691              : 
    6692              : /*
    6693              :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6694              :  * the item names needed in old aggregate definitions are likely to become
    6695              :  * SQL keywords.
    6696              :  */
    6697              : old_aggr_elem:  IDENT '=' def_arg
    6698              :                 {
    6699          827 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6700              :                 }
    6701              :         ;
    6702              : 
    6703              : opt_enum_val_list:
    6704          100 :         enum_val_list                           { $$ = $1; }
    6705            4 :         | /*EMPTY*/                             { $$ = NIL; }
    6706              :         ;
    6707              : 
    6708              : enum_val_list:  Sconst
    6709          100 :                 { $$ = list_make1(makeString($1)); }
    6710              :             | enum_val_list ',' Sconst
    6711         5210 :                 { $$ = lappend($1, makeString($3)); }
    6712              :         ;
    6713              : 
    6714              : /*****************************************************************************
    6715              :  *
    6716              :  *  ALTER TYPE enumtype ADD ...
    6717              :  *
    6718              :  *****************************************************************************/
    6719              : 
    6720              : AlterEnumStmt:
    6721              :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6722              :             {
    6723           77 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6724              : 
    6725           77 :                 n->typeName = $3;
    6726           77 :                 n->oldVal = NULL;
    6727           77 :                 n->newVal = $7;
    6728           77 :                 n->newValNeighbor = NULL;
    6729           77 :                 n->newValIsAfter = true;
    6730           77 :                 n->skipIfNewValExists = $6;
    6731           77 :                 $$ = (Node *) n;
    6732              :             }
    6733              :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6734              :             {
    6735           98 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6736              : 
    6737           98 :                 n->typeName = $3;
    6738           98 :                 n->oldVal = NULL;
    6739           98 :                 n->newVal = $7;
    6740           98 :                 n->newValNeighbor = $9;
    6741           98 :                 n->newValIsAfter = false;
    6742           98 :                 n->skipIfNewValExists = $6;
    6743           98 :                 $$ = (Node *) n;
    6744              :             }
    6745              :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6746              :             {
    6747           11 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6748              : 
    6749           11 :                 n->typeName = $3;
    6750           11 :                 n->oldVal = NULL;
    6751           11 :                 n->newVal = $7;
    6752           11 :                 n->newValNeighbor = $9;
    6753           11 :                 n->newValIsAfter = true;
    6754           11 :                 n->skipIfNewValExists = $6;
    6755           11 :                 $$ = (Node *) n;
    6756              :             }
    6757              :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6758              :             {
    6759           12 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6760              : 
    6761           12 :                 n->typeName = $3;
    6762           12 :                 n->oldVal = $6;
    6763           12 :                 n->newVal = $8;
    6764           12 :                 n->newValNeighbor = NULL;
    6765           12 :                 n->newValIsAfter = false;
    6766           12 :                 n->skipIfNewValExists = false;
    6767           12 :                 $$ = (Node *) n;
    6768              :             }
    6769              :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6770              :             {
    6771              :                 /*
    6772              :                  * The following problems must be solved before this can be
    6773              :                  * implemented:
    6774              :                  *
    6775              :                  * - There must be no instance of the target value in
    6776              :                  *   any table.
    6777              :                  *
    6778              :                  * - The value must not appear in any catalog metadata,
    6779              :                  *   such as stored view expressions or column defaults.
    6780              :                  *
    6781              :                  * - The value must not appear in any non-leaf page of a
    6782              :                  *   btree (and similar issues with other index types).
    6783              :                  *   This is problematic because a value could persist
    6784              :                  *   there long after it's gone from user-visible data.
    6785              :                  *
    6786              :                  * - Concurrent sessions must not be able to insert the
    6787              :                  *   value while the preceding conditions are being checked.
    6788              :                  *
    6789              :                  * - Possibly more...
    6790              :                  */
    6791            0 :                 ereport(ERROR,
    6792              :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6793              :                          errmsg("dropping an enum value is not implemented"),
    6794              :                          parser_errposition(@4)));
    6795              :             }
    6796              :          ;
    6797              : 
    6798            6 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6799          180 :         | /* EMPTY */                          { $$ = false; }
    6800              :         ;
    6801              : 
    6802              : 
    6803              : /*****************************************************************************
    6804              :  *
    6805              :  *      QUERIES :
    6806              :  *              CREATE OPERATOR CLASS ...
    6807              :  *              CREATE OPERATOR FAMILY ...
    6808              :  *              ALTER OPERATOR FAMILY ...
    6809              :  *              DROP OPERATOR CLASS ...
    6810              :  *              DROP OPERATOR FAMILY ...
    6811              :  *
    6812              :  *****************************************************************************/
    6813              : 
    6814              : CreateOpClassStmt:
    6815              :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6816              :             USING name opt_opfamily AS opclass_item_list
    6817              :                 {
    6818          279 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6819              : 
    6820          279 :                     n->opclassname = $4;
    6821          279 :                     n->isDefault = $5;
    6822          279 :                     n->datatype = $8;
    6823          279 :                     n->amname = $10;
    6824          279 :                     n->opfamilyname = $11;
    6825          279 :                     n->items = $13;
    6826          279 :                     $$ = (Node *) n;
    6827              :                 }
    6828              :         ;
    6829              : 
    6830              : opclass_item_list:
    6831          476 :             opclass_item                            { $$ = list_make1($1); }
    6832         2930 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6833              :         ;
    6834              : 
    6835              : opclass_item:
    6836              :             OPERATOR Iconst any_operator opclass_purpose
    6837              :                 {
    6838         1046 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6839         1046 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6840              : 
    6841         1046 :                     owa->objname = $3;
    6842         1046 :                     owa->objargs = NIL;
    6843         1046 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6844         1046 :                     n->name = owa;
    6845         1046 :                     n->number = $2;
    6846         1046 :                     n->order_family = $4;
    6847         1046 :                     $$ = (Node *) n;
    6848              :                 }
    6849              :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6850              :                 {
    6851          677 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6852              : 
    6853          677 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6854          677 :                     n->name = $3;
    6855          677 :                     n->number = $2;
    6856          677 :                     n->order_family = $4;
    6857          677 :                     $$ = (Node *) n;
    6858              :                 }
    6859              :             | FUNCTION Iconst function_with_argtypes
    6860              :                 {
    6861         1388 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6862              : 
    6863         1388 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6864         1388 :                     n->name = $3;
    6865         1388 :                     n->number = $2;
    6866         1388 :                     $$ = (Node *) n;
    6867              :                 }
    6868              :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6869              :                 {
    6870          115 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6871              : 
    6872          115 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6873          115 :                     n->name = $6;
    6874          115 :                     n->number = $2;
    6875          115 :                     n->class_args = $4;
    6876          115 :                     $$ = (Node *) n;
    6877              :                 }
    6878              :             | STORAGE Typename
    6879              :                 {
    6880          180 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6881              : 
    6882          180 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6883          180 :                     n->storedtype = $2;
    6884          180 :                     $$ = (Node *) n;
    6885              :                 }
    6886              :         ;
    6887              : 
    6888          221 : opt_default:    DEFAULT                     { $$ = true; }
    6889           90 :             | /*EMPTY*/                     { $$ = false; }
    6890              :         ;
    6891              : 
    6892           22 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6893          257 :             | /*EMPTY*/                     { $$ = NIL; }
    6894              :         ;
    6895              : 
    6896            0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6897           60 :             | FOR ORDER BY any_name         { $$ = $4; }
    6898         1663 :             | /*EMPTY*/                     { $$ = NIL; }
    6899              :         ;
    6900              : 
    6901              : 
    6902              : CreateOpFamilyStmt:
    6903              :             CREATE OPERATOR FAMILY any_name USING name
    6904              :                 {
    6905           74 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6906              : 
    6907           74 :                     n->opfamilyname = $4;
    6908           74 :                     n->amname = $6;
    6909           74 :                     $$ = (Node *) n;
    6910              :                 }
    6911              :         ;
    6912              : 
    6913              : AlterOpFamilyStmt:
    6914              :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6915              :                 {
    6916          197 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6917              : 
    6918          197 :                     n->opfamilyname = $4;
    6919          197 :                     n->amname = $6;
    6920          197 :                     n->isDrop = false;
    6921          197 :                     n->items = $8;
    6922          197 :                     $$ = (Node *) n;
    6923              :                 }
    6924              :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6925              :                 {
    6926           32 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6927              : 
    6928           32 :                     n->opfamilyname = $4;
    6929           32 :                     n->amname = $6;
    6930           32 :                     n->isDrop = true;
    6931           32 :                     n->items = $8;
    6932           32 :                     $$ = (Node *) n;
    6933              :                 }
    6934              :         ;
    6935              : 
    6936              : opclass_drop_list:
    6937           32 :             opclass_drop                            { $$ = list_make1($1); }
    6938           15 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6939              :         ;
    6940              : 
    6941              : opclass_drop:
    6942              :             OPERATOR Iconst '(' type_list ')'
    6943              :                 {
    6944           28 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6945              : 
    6946           28 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6947           28 :                     n->number = $2;
    6948           28 :                     n->class_args = $4;
    6949           28 :                     $$ = (Node *) n;
    6950              :                 }
    6951              :             | FUNCTION Iconst '(' type_list ')'
    6952              :                 {
    6953           19 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6954              : 
    6955           19 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6956           19 :                     n->number = $2;
    6957           19 :                     n->class_args = $4;
    6958           19 :                     $$ = (Node *) n;
    6959              :                 }
    6960              :         ;
    6961              : 
    6962              : 
    6963              : DropOpClassStmt:
    6964              :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6965              :                 {
    6966           19 :                     DropStmt *n = makeNode(DropStmt);
    6967              : 
    6968           19 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6969           19 :                     n->removeType = OBJECT_OPCLASS;
    6970           19 :                     n->behavior = $7;
    6971           19 :                     n->missing_ok = false;
    6972           19 :                     n->concurrent = false;
    6973           19 :                     $$ = (Node *) n;
    6974              :                 }
    6975              :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6976              :                 {
    6977            9 :                     DropStmt *n = makeNode(DropStmt);
    6978              : 
    6979            9 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6980            9 :                     n->removeType = OBJECT_OPCLASS;
    6981            9 :                     n->behavior = $9;
    6982            9 :                     n->missing_ok = true;
    6983            9 :                     n->concurrent = false;
    6984            9 :                     $$ = (Node *) n;
    6985              :                 }
    6986              :         ;
    6987              : 
    6988              : DropOpFamilyStmt:
    6989              :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6990              :                 {
    6991           55 :                     DropStmt *n = makeNode(DropStmt);
    6992              : 
    6993           55 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6994           55 :                     n->removeType = OBJECT_OPFAMILY;
    6995           55 :                     n->behavior = $7;
    6996           55 :                     n->missing_ok = false;
    6997           55 :                     n->concurrent = false;
    6998           55 :                     $$ = (Node *) n;
    6999              :                 }
    7000              :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    7001              :                 {
    7002            9 :                     DropStmt *n = makeNode(DropStmt);
    7003              : 
    7004            9 :                     n->objects = list_make1(lcons(makeString($8), $6));
    7005            9 :                     n->removeType = OBJECT_OPFAMILY;
    7006            9 :                     n->behavior = $9;
    7007            9 :                     n->missing_ok = true;
    7008            9 :                     n->concurrent = false;
    7009            9 :                     $$ = (Node *) n;
    7010              :                 }
    7011              :         ;
    7012              : 
    7013              : 
    7014              : /*****************************************************************************
    7015              :  *
    7016              :  *      QUERY:
    7017              :  *
    7018              :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    7019              :  *      REASSIGN OWNED BY username [, username ...] TO username
    7020              :  *
    7021              :  *****************************************************************************/
    7022              : DropOwnedStmt:
    7023              :             DROP OWNED BY role_list opt_drop_behavior
    7024              :                 {
    7025           74 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    7026              : 
    7027           74 :                     n->roles = $4;
    7028           74 :                     n->behavior = $5;
    7029           74 :                     $$ = (Node *) n;
    7030              :                 }
    7031              :         ;
    7032              : 
    7033              : ReassignOwnedStmt:
    7034              :             REASSIGN OWNED BY role_list TO RoleSpec
    7035              :                 {
    7036           23 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    7037              : 
    7038           23 :                     n->roles = $4;
    7039           23 :                     n->newrole = $6;
    7040           23 :                     $$ = (Node *) n;
    7041              :                 }
    7042              :         ;
    7043              : 
    7044              : /*****************************************************************************
    7045              :  *
    7046              :  *      QUERY:
    7047              :  *
    7048              :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    7049              :  *           [ RESTRICT | CASCADE ]
    7050              :  *
    7051              :  *****************************************************************************/
    7052              : 
    7053              : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    7054              :                 {
    7055          698 :                     DropStmt *n = makeNode(DropStmt);
    7056              : 
    7057          698 :                     n->removeType = $2;
    7058          698 :                     n->missing_ok = true;
    7059          698 :                     n->objects = $5;
    7060          698 :                     n->behavior = $6;
    7061          698 :                     n->concurrent = false;
    7062          698 :                     $$ = (Node *) n;
    7063              :                 }
    7064              :             | DROP object_type_any_name any_name_list opt_drop_behavior
    7065              :                 {
    7066         8553 :                     DropStmt *n = makeNode(DropStmt);
    7067              : 
    7068         8553 :                     n->removeType = $2;
    7069         8553 :                     n->missing_ok = false;
    7070         8553 :                     n->objects = $3;
    7071         8553 :                     n->behavior = $4;
    7072         8553 :                     n->concurrent = false;
    7073         8553 :                     $$ = (Node *) n;
    7074              :                 }
    7075              :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    7076              :                 {
    7077           43 :                     DropStmt *n = makeNode(DropStmt);
    7078              : 
    7079           43 :                     n->removeType = $2;
    7080           43 :                     n->missing_ok = true;
    7081           43 :                     n->objects = $5;
    7082           43 :                     n->behavior = $6;
    7083           43 :                     n->concurrent = false;
    7084           43 :                     $$ = (Node *) n;
    7085              :                 }
    7086              :             | DROP drop_type_name name_list opt_drop_behavior
    7087              :                 {
    7088          759 :                     DropStmt *n = makeNode(DropStmt);
    7089              : 
    7090          759 :                     n->removeType = $2;
    7091          759 :                     n->missing_ok = false;
    7092          759 :                     n->objects = $3;
    7093          759 :                     n->behavior = $4;
    7094          759 :                     n->concurrent = false;
    7095          759 :                     $$ = (Node *) n;
    7096              :                 }
    7097              :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    7098              :                 {
    7099          578 :                     DropStmt *n = makeNode(DropStmt);
    7100              : 
    7101          578 :                     n->removeType = $2;
    7102          578 :                     n->objects = list_make1(lappend($5, makeString($3)));
    7103          578 :                     n->behavior = $6;
    7104          578 :                     n->missing_ok = false;
    7105          578 :                     n->concurrent = false;
    7106          578 :                     $$ = (Node *) n;
    7107              :                 }
    7108              :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    7109              :                 {
    7110           24 :                     DropStmt *n = makeNode(DropStmt);
    7111              : 
    7112           24 :                     n->removeType = $2;
    7113           24 :                     n->objects = list_make1(lappend($7, makeString($5)));
    7114           24 :                     n->behavior = $8;
    7115           24 :                     n->missing_ok = true;
    7116           24 :                     n->concurrent = false;
    7117           24 :                     $$ = (Node *) n;
    7118              :                 }
    7119              :             | DROP TYPE_P type_name_list opt_drop_behavior
    7120              :                 {
    7121          283 :                     DropStmt *n = makeNode(DropStmt);
    7122              : 
    7123          283 :                     n->removeType = OBJECT_TYPE;
    7124          283 :                     n->missing_ok = false;
    7125          283 :                     n->objects = $3;
    7126          283 :                     n->behavior = $4;
    7127          283 :                     n->concurrent = false;
    7128          283 :                     $$ = (Node *) n;
    7129              :                 }
    7130              :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    7131              :                 {
    7132           13 :                     DropStmt *n = makeNode(DropStmt);
    7133              : 
    7134           13 :                     n->removeType = OBJECT_TYPE;
    7135           13 :                     n->missing_ok = true;
    7136           13 :                     n->objects = $5;
    7137           13 :                     n->behavior = $6;
    7138           13 :                     n->concurrent = false;
    7139           13 :                     $$ = (Node *) n;
    7140              :                 }
    7141              :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    7142              :                 {
    7143          235 :                     DropStmt *n = makeNode(DropStmt);
    7144              : 
    7145          235 :                     n->removeType = OBJECT_DOMAIN;
    7146          235 :                     n->missing_ok = false;
    7147          235 :                     n->objects = $3;
    7148          235 :                     n->behavior = $4;
    7149          235 :                     n->concurrent = false;
    7150          235 :                     $$ = (Node *) n;
    7151              :                 }
    7152              :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7153              :                 {
    7154            9 :                     DropStmt *n = makeNode(DropStmt);
    7155              : 
    7156            9 :                     n->removeType = OBJECT_DOMAIN;
    7157            9 :                     n->missing_ok = true;
    7158            9 :                     n->objects = $5;
    7159            9 :                     n->behavior = $6;
    7160            9 :                     n->concurrent = false;
    7161            9 :                     $$ = (Node *) n;
    7162              :                 }
    7163              :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7164              :                 {
    7165           65 :                     DropStmt *n = makeNode(DropStmt);
    7166              : 
    7167           65 :                     n->removeType = OBJECT_INDEX;
    7168           65 :                     n->missing_ok = false;
    7169           65 :                     n->objects = $4;
    7170           65 :                     n->behavior = $5;
    7171           65 :                     n->concurrent = true;
    7172           65 :                     $$ = (Node *) n;
    7173              :                 }
    7174              :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7175              :                 {
    7176            6 :                     DropStmt *n = makeNode(DropStmt);
    7177              : 
    7178            6 :                     n->removeType = OBJECT_INDEX;
    7179            6 :                     n->missing_ok = true;
    7180            6 :                     n->objects = $6;
    7181            6 :                     n->behavior = $7;
    7182            6 :                     n->concurrent = true;
    7183            6 :                     $$ = (Node *) n;
    7184              :                 }
    7185              :         ;
    7186              : 
    7187              : /* object types taking any_name/any_name_list */
    7188              : object_type_any_name:
    7189         8031 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7190          100 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7191          519 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7192           65 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7193          389 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7194           93 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7195           48 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7196           28 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7197          115 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7198           10 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7199         1534 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7200           59 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7201         1536 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7202              :         ;
    7203              : 
    7204              : /*
    7205              :  * object types taking name/name_list
    7206              :  *
    7207              :  * DROP handles some of them separately
    7208              :  */
    7209              : 
    7210              : object_type_name:
    7211          128 :             drop_type_name                          { $$ = $1; }
    7212          123 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7213           26 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7214            5 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7215            0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7216              :         ;
    7217              : 
    7218              : drop_type_name:
    7219           29 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7220           65 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7221           93 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7222           77 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7223           78 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7224          204 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7225          315 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7226           69 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7227              :         ;
    7228              : 
    7229              : /* object types attached to a table */
    7230              : object_type_name_on_any_name:
    7231           92 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7232          137 :             | RULE                                  { $$ = OBJECT_RULE; }
    7233          400 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7234              :         ;
    7235              : 
    7236              : any_name_list:
    7237        14044 :             any_name                                { $$ = list_make1($1); }
    7238         2138 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7239              :         ;
    7240              : 
    7241        35501 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7242         4644 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7243              :         ;
    7244              : 
    7245              : attrs:      '.' attr_name
    7246        65325 :                     { $$ = list_make1(makeString($2)); }
    7247              :             | attrs '.' attr_name
    7248           32 :                     { $$ = lappend($1, makeString($3)); }
    7249              :         ;
    7250              : 
    7251              : type_name_list:
    7252          540 :             Typename                                { $$ = list_make1($1); }
    7253           51 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7254              :         ;
    7255              : 
    7256              : /*****************************************************************************
    7257              :  *
    7258              :  *      QUERY:
    7259              :  *              truncate table relname1, relname2, ...
    7260              :  *
    7261              :  *****************************************************************************/
    7262              : 
    7263              : TruncateStmt:
    7264              :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7265              :                 {
    7266          922 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7267              : 
    7268          922 :                     n->relations = $3;
    7269          922 :                     n->restart_seqs = $4;
    7270          922 :                     n->behavior = $5;
    7271          922 :                     $$ = (Node *) n;
    7272              :                 }
    7273              :         ;
    7274              : 
    7275              : opt_restart_seqs:
    7276           12 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7277           12 :             | RESTART IDENTITY_P        { $$ = true; }
    7278          898 :             | /* EMPTY */               { $$ = false; }
    7279              :         ;
    7280              : 
    7281              : /*****************************************************************************
    7282              :  *
    7283              :  * COMMENT ON <object> IS <text>
    7284              :  *
    7285              :  *****************************************************************************/
    7286              : 
    7287              : CommentStmt:
    7288              :             COMMENT ON object_type_any_name any_name IS comment_text
    7289              :                 {
    7290         3204 :                     CommentStmt *n = makeNode(CommentStmt);
    7291              : 
    7292         3204 :                     n->objtype = $3;
    7293         3204 :                     n->object = (Node *) $4;
    7294         3204 :                     n->comment = $6;
    7295         3204 :                     $$ = (Node *) n;
    7296              :                 }
    7297              :             | COMMENT ON COLUMN any_name IS comment_text
    7298              :                 {
    7299           72 :                     CommentStmt *n = makeNode(CommentStmt);
    7300              : 
    7301           72 :                     n->objtype = OBJECT_COLUMN;
    7302           72 :                     n->object = (Node *) $4;
    7303           72 :                     n->comment = $6;
    7304           72 :                     $$ = (Node *) n;
    7305              :                 }
    7306              :             | COMMENT ON object_type_name name IS comment_text
    7307              :                 {
    7308          251 :                     CommentStmt *n = makeNode(CommentStmt);
    7309              : 
    7310          251 :                     n->objtype = $3;
    7311          251 :                     n->object = (Node *) makeString($4);
    7312          251 :                     n->comment = $6;
    7313          251 :                     $$ = (Node *) n;
    7314              :                 }
    7315              :             | COMMENT ON TYPE_P Typename IS comment_text
    7316              :                 {
    7317           28 :                     CommentStmt *n = makeNode(CommentStmt);
    7318              : 
    7319           28 :                     n->objtype = OBJECT_TYPE;
    7320           28 :                     n->object = (Node *) $4;
    7321           28 :                     n->comment = $6;
    7322           28 :                     $$ = (Node *) n;
    7323              :                 }
    7324              :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7325              :                 {
    7326            4 :                     CommentStmt *n = makeNode(CommentStmt);
    7327              : 
    7328            4 :                     n->objtype = OBJECT_DOMAIN;
    7329            4 :                     n->object = (Node *) $4;
    7330            4 :                     n->comment = $6;
    7331            4 :                     $$ = (Node *) n;
    7332              :                 }
    7333              :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7334              :                 {
    7335           20 :                     CommentStmt *n = makeNode(CommentStmt);
    7336              : 
    7337           20 :                     n->objtype = OBJECT_AGGREGATE;
    7338           20 :                     n->object = (Node *) $4;
    7339           20 :                     n->comment = $6;
    7340           20 :                     $$ = (Node *) n;
    7341              :                 }
    7342              :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7343              :                 {
    7344           85 :                     CommentStmt *n = makeNode(CommentStmt);
    7345              : 
    7346           85 :                     n->objtype = OBJECT_FUNCTION;
    7347           85 :                     n->object = (Node *) $4;
    7348           85 :                     n->comment = $6;
    7349           85 :                     $$ = (Node *) n;
    7350              :                 }
    7351              :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7352              :                 {
    7353            9 :                     CommentStmt *n = makeNode(CommentStmt);
    7354              : 
    7355            9 :                     n->objtype = OBJECT_OPERATOR;
    7356            9 :                     n->object = (Node *) $4;
    7357            9 :                     n->comment = $6;
    7358            9 :                     $$ = (Node *) n;
    7359              :                 }
    7360              :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7361              :                 {
    7362           75 :                     CommentStmt *n = makeNode(CommentStmt);
    7363              : 
    7364           75 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7365           75 :                     n->object = (Node *) lappend($6, makeString($4));
    7366           75 :                     n->comment = $8;
    7367           75 :                     $$ = (Node *) n;
    7368              :                 }
    7369              :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7370              :                 {
    7371           24 :                     CommentStmt *n = makeNode(CommentStmt);
    7372              : 
    7373           24 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7374              :                     /*
    7375              :                      * should use Typename not any_name in the production, but
    7376              :                      * there's a shift/reduce conflict if we do that, so fix it
    7377              :                      * up here.
    7378              :                      */
    7379           24 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7380           24 :                     n->comment = $9;
    7381           24 :                     $$ = (Node *) n;
    7382              :                 }
    7383              :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7384              :                 {
    7385           21 :                     CommentStmt *n = makeNode(CommentStmt);
    7386              : 
    7387           21 :                     n->objtype = $3;
    7388           21 :                     n->object = (Node *) lappend($6, makeString($4));
    7389           21 :                     n->comment = $8;
    7390           21 :                     $$ = (Node *) n;
    7391              :                 }
    7392              :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7393              :                 {
    7394            0 :                     CommentStmt *n = makeNode(CommentStmt);
    7395              : 
    7396            0 :                     n->objtype = OBJECT_PROCEDURE;
    7397            0 :                     n->object = (Node *) $4;
    7398            0 :                     n->comment = $6;
    7399            0 :                     $$ = (Node *) n;
    7400              :                 }
    7401              :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7402              :                 {
    7403            0 :                     CommentStmt *n = makeNode(CommentStmt);
    7404              : 
    7405            0 :                     n->objtype = OBJECT_ROUTINE;
    7406            0 :                     n->object = (Node *) $4;
    7407            0 :                     n->comment = $6;
    7408            0 :                     $$ = (Node *) n;
    7409              :                 }
    7410              :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7411              :                 {
    7412            7 :                     CommentStmt *n = makeNode(CommentStmt);
    7413              : 
    7414            7 :                     n->objtype = OBJECT_TRANSFORM;
    7415            7 :                     n->object = (Node *) list_make2($5, makeString($7));
    7416            7 :                     n->comment = $9;
    7417            7 :                     $$ = (Node *) n;
    7418              :                 }
    7419              :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7420              :                 {
    7421            0 :                     CommentStmt *n = makeNode(CommentStmt);
    7422              : 
    7423            0 :                     n->objtype = OBJECT_OPCLASS;
    7424            0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7425            0 :                     n->comment = $9;
    7426            0 :                     $$ = (Node *) n;
    7427              :                 }
    7428              :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7429              :                 {
    7430            0 :                     CommentStmt *n = makeNode(CommentStmt);
    7431              : 
    7432            0 :                     n->objtype = OBJECT_OPFAMILY;
    7433            0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7434            0 :                     n->comment = $9;
    7435            0 :                     $$ = (Node *) n;
    7436              :                 }
    7437              :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7438              :                 {
    7439           21 :                     CommentStmt *n = makeNode(CommentStmt);
    7440              : 
    7441           21 :                     n->objtype = OBJECT_LARGEOBJECT;
    7442           21 :                     n->object = (Node *) $5;
    7443           21 :                     n->comment = $7;
    7444           21 :                     $$ = (Node *) n;
    7445              :                 }
    7446              :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7447              :                 {
    7448            0 :                     CommentStmt *n = makeNode(CommentStmt);
    7449              : 
    7450            0 :                     n->objtype = OBJECT_CAST;
    7451            0 :                     n->object = (Node *) list_make2($5, $7);
    7452            0 :                     n->comment = $10;
    7453            0 :                     $$ = (Node *) n;
    7454              :                 }
    7455              :         ;
    7456              : 
    7457              : comment_text:
    7458         3769 :             Sconst                              { $$ = $1; }
    7459           52 :             | NULL_P                            { $$ = NULL; }
    7460              :         ;
    7461              : 
    7462              : 
    7463              : /*****************************************************************************
    7464              :  *
    7465              :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7466              :  *
    7467              :  *  As with COMMENT ON, <object> can refer to various types of database
    7468              :  *  objects (e.g. TABLE, COLUMN, etc.).
    7469              :  *
    7470              :  *****************************************************************************/
    7471              : 
    7472              : SecLabelStmt:
    7473              :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7474              :             IS security_label
    7475              :                 {
    7476           24 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7477              : 
    7478           24 :                     n->provider = $3;
    7479           24 :                     n->objtype = $5;
    7480           24 :                     n->object = (Node *) $6;
    7481           24 :                     n->label = $8;
    7482           24 :                     $$ = (Node *) n;
    7483              :                 }
    7484              :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7485              :               IS security_label
    7486              :                 {
    7487            2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7488              : 
    7489            2 :                     n->provider = $3;
    7490            2 :                     n->objtype = OBJECT_COLUMN;
    7491            2 :                     n->object = (Node *) $6;
    7492            2 :                     n->label = $8;
    7493            2 :                     $$ = (Node *) n;
    7494              :                 }
    7495              :             | SECURITY LABEL opt_provider ON object_type_name name
    7496              :               IS security_label
    7497              :                 {
    7498           22 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7499              : 
    7500           22 :                     n->provider = $3;
    7501           22 :                     n->objtype = $5;
    7502           22 :                     n->object = (Node *) makeString($6);
    7503           22 :                     n->label = $8;
    7504           22 :                     $$ = (Node *) n;
    7505              :                 }
    7506              :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7507              :               IS security_label
    7508              :                 {
    7509            0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7510              : 
    7511            0 :                     n->provider = $3;
    7512            0 :                     n->objtype = OBJECT_TYPE;
    7513            0 :                     n->object = (Node *) $6;
    7514            0 :                     n->label = $8;
    7515            0 :                     $$ = (Node *) n;
    7516              :                 }
    7517              :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7518              :               IS security_label
    7519              :                 {
    7520            1 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7521              : 
    7522            1 :                     n->provider = $3;
    7523            1 :                     n->objtype = OBJECT_DOMAIN;
    7524            1 :                     n->object = (Node *) $6;
    7525            1 :                     n->label = $8;
    7526            1 :                     $$ = (Node *) n;
    7527              :                 }
    7528              :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7529              :               IS security_label
    7530              :                 {
    7531            0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7532              : 
    7533            0 :                     n->provider = $3;
    7534            0 :                     n->objtype = OBJECT_AGGREGATE;
    7535            0 :                     n->object = (Node *) $6;
    7536            0 :                     n->label = $8;
    7537            0 :                     $$ = (Node *) n;
    7538              :                 }
    7539              :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7540              :               IS security_label
    7541              :                 {
    7542            1 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7543              : 
    7544            1 :                     n->provider = $3;
    7545            1 :                     n->objtype = OBJECT_FUNCTION;
    7546            1 :                     n->object = (Node *) $6;
    7547            1 :                     n->label = $8;
    7548            1 :                     $$ = (Node *) n;
    7549              :                 }
    7550              :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7551              :               IS security_label
    7552              :                 {
    7553            9 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7554              : 
    7555            9 :                     n->provider = $3;
    7556            9 :                     n->objtype = OBJECT_LARGEOBJECT;
    7557            9 :                     n->object = (Node *) $7;
    7558            9 :                     n->label = $9;
    7559            9 :                     $$ = (Node *) n;
    7560              :                 }
    7561              :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7562              :               IS security_label
    7563              :                 {
    7564            0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7565              : 
    7566            0 :                     n->provider = $3;
    7567            0 :                     n->objtype = OBJECT_PROCEDURE;
    7568            0 :                     n->object = (Node *) $6;
    7569            0 :                     n->label = $8;
    7570            0 :                     $$ = (Node *) n;
    7571              :                 }
    7572              :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7573              :               IS security_label
    7574              :                 {
    7575            0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7576              : 
    7577            0 :                     n->provider = $3;
    7578            0 :                     n->objtype = OBJECT_ROUTINE;
    7579            0 :                     n->object = (Node *) $6;
    7580            0 :                     n->label = $8;
    7581            0 :                     $$ = (Node *) n;
    7582              :                 }
    7583              :         ;
    7584              : 
    7585           14 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7586           45 :                 | /* EMPTY */                   { $$ = NULL; }
    7587              :         ;
    7588              : 
    7589           59 : security_label: Sconst              { $$ = $1; }
    7590            0 :                 | NULL_P            { $$ = NULL; }
    7591              :         ;
    7592              : 
    7593              : /*****************************************************************************
    7594              :  *
    7595              :  *      QUERY:
    7596              :  *          fetch/move
    7597              :  *
    7598              :  *****************************************************************************/
    7599              : 
    7600              : FetchStmt:  FETCH fetch_args
    7601              :                 {
    7602         3828 :                     FetchStmt *n = (FetchStmt *) $2;
    7603              : 
    7604         3828 :                     n->ismove = false;
    7605         3828 :                     $$ = (Node *) n;
    7606              :                 }
    7607              :             | MOVE fetch_args
    7608              :                 {
    7609           34 :                     FetchStmt *n = (FetchStmt *) $2;
    7610              : 
    7611           34 :                     n->ismove = true;
    7612           34 :                     $$ = (Node *) n;
    7613              :                 }
    7614              :         ;
    7615              : 
    7616              : fetch_args: cursor_name
    7617              :                 {
    7618          132 :                     FetchStmt *n = makeNode(FetchStmt);
    7619              : 
    7620          132 :                     n->portalname = $1;
    7621          132 :                     n->direction = FETCH_FORWARD;
    7622          132 :                     n->howMany = 1;
    7623          132 :                     n->location = -1;
    7624          132 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7625          132 :                     $$ = (Node *) n;
    7626              :                 }
    7627              :             | from_in cursor_name
    7628              :                 {
    7629          109 :                     FetchStmt *n = makeNode(FetchStmt);
    7630              : 
    7631          109 :                     n->portalname = $2;
    7632          109 :                     n->direction = FETCH_FORWARD;
    7633          109 :                     n->howMany = 1;
    7634          109 :                     n->location = -1;
    7635          109 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7636          109 :                     $$ = (Node *) n;
    7637              :                 }
    7638              :             | SignedIconst opt_from_in cursor_name
    7639              :                 {
    7640         2149 :                     FetchStmt *n = makeNode(FetchStmt);
    7641              : 
    7642         2149 :                     n->portalname = $3;
    7643         2149 :                     n->direction = FETCH_FORWARD;
    7644         2149 :                     n->howMany = $1;
    7645         2149 :                     n->location = @1;
    7646         2149 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7647         2149 :                     $$ = (Node *) n;
    7648              :                 }
    7649              :             | NEXT opt_from_in cursor_name
    7650              :                 {
    7651         1005 :                     FetchStmt *n = makeNode(FetchStmt);
    7652              : 
    7653         1005 :                     n->portalname = $3;
    7654         1005 :                     n->direction = FETCH_FORWARD;
    7655         1005 :                     n->howMany = 1;
    7656         1005 :                     n->location = -1;
    7657         1005 :                     n->direction_keyword = FETCH_KEYWORD_NEXT;
    7658         1005 :                     $$ = (Node *) n;
    7659              :                 }
    7660              :             | PRIOR opt_from_in cursor_name
    7661              :                 {
    7662           16 :                     FetchStmt *n = makeNode(FetchStmt);
    7663              : 
    7664           16 :                     n->portalname = $3;
    7665           16 :                     n->direction = FETCH_BACKWARD;
    7666           16 :                     n->howMany = 1;
    7667           16 :                     n->location = -1;
    7668           16 :                     n->direction_keyword = FETCH_KEYWORD_PRIOR;
    7669           16 :                     $$ = (Node *) n;
    7670              :                 }
    7671              :             | FIRST_P opt_from_in cursor_name
    7672              :                 {
    7673           13 :                     FetchStmt *n = makeNode(FetchStmt);
    7674              : 
    7675           13 :                     n->portalname = $3;
    7676           13 :                     n->direction = FETCH_ABSOLUTE;
    7677           13 :                     n->howMany = 1;
    7678           13 :                     n->location = -1;
    7679           13 :                     n->direction_keyword = FETCH_KEYWORD_FIRST;
    7680           13 :                     $$ = (Node *) n;
    7681              :                 }
    7682              :             | LAST_P opt_from_in cursor_name
    7683              :                 {
    7684           10 :                     FetchStmt *n = makeNode(FetchStmt);
    7685              : 
    7686           10 :                     n->portalname = $3;
    7687           10 :                     n->direction = FETCH_ABSOLUTE;
    7688           10 :                     n->howMany = -1;
    7689           10 :                     n->location = -1;
    7690           10 :                     n->direction_keyword = FETCH_KEYWORD_LAST;
    7691           10 :                     $$ = (Node *) n;
    7692              :                 }
    7693              :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7694              :                 {
    7695           47 :                     FetchStmt *n = makeNode(FetchStmt);
    7696              : 
    7697           47 :                     n->portalname = $4;
    7698           47 :                     n->direction = FETCH_ABSOLUTE;
    7699           47 :                     n->howMany = $2;
    7700           47 :                     n->location = @2;
    7701           47 :                     n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
    7702           47 :                     $$ = (Node *) n;
    7703              :                 }
    7704              :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7705              :                 {
    7706           18 :                     FetchStmt *n = makeNode(FetchStmt);
    7707              : 
    7708           18 :                     n->portalname = $4;
    7709           18 :                     n->direction = FETCH_RELATIVE;
    7710           18 :                     n->howMany = $2;
    7711           18 :                     n->location = @2;
    7712           18 :                     n->direction_keyword = FETCH_KEYWORD_RELATIVE;
    7713           18 :                     $$ = (Node *) n;
    7714              :                 }
    7715              :             | ALL opt_from_in cursor_name
    7716              :                 {
    7717          135 :                     FetchStmt *n = makeNode(FetchStmt);
    7718              : 
    7719          135 :                     n->portalname = $3;
    7720          135 :                     n->direction = FETCH_FORWARD;
    7721          135 :                     n->howMany = FETCH_ALL;
    7722          135 :                     n->location = -1;
    7723          135 :                     n->direction_keyword = FETCH_KEYWORD_ALL;
    7724          135 :                     $$ = (Node *) n;
    7725              :                 }
    7726              :             | FORWARD opt_from_in cursor_name
    7727              :                 {
    7728           15 :                     FetchStmt *n = makeNode(FetchStmt);
    7729              : 
    7730           15 :                     n->portalname = $3;
    7731           15 :                     n->direction = FETCH_FORWARD;
    7732           15 :                     n->howMany = 1;
    7733           15 :                     n->location = -1;
    7734           15 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7735           15 :                     $$ = (Node *) n;
    7736              :                 }
    7737              :             | FORWARD SignedIconst opt_from_in cursor_name
    7738              :                 {
    7739            6 :                     FetchStmt *n = makeNode(FetchStmt);
    7740              : 
    7741            6 :                     n->portalname = $4;
    7742            6 :                     n->direction = FETCH_FORWARD;
    7743            6 :                     n->howMany = $2;
    7744            6 :                     n->location = @2;
    7745            6 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7746            6 :                     $$ = (Node *) n;
    7747              :                 }
    7748              :             | FORWARD ALL opt_from_in cursor_name
    7749              :                 {
    7750            8 :                     FetchStmt *n = makeNode(FetchStmt);
    7751              : 
    7752            8 :                     n->portalname = $4;
    7753            8 :                     n->direction = FETCH_FORWARD;
    7754            8 :                     n->howMany = FETCH_ALL;
    7755            8 :                     n->location = -1;
    7756            8 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
    7757            8 :                     $$ = (Node *) n;
    7758              :                 }
    7759              :             | BACKWARD opt_from_in cursor_name
    7760              :                 {
    7761           40 :                     FetchStmt *n = makeNode(FetchStmt);
    7762              : 
    7763           40 :                     n->portalname = $3;
    7764           40 :                     n->direction = FETCH_BACKWARD;
    7765           40 :                     n->howMany = 1;
    7766           40 :                     n->location = -1;
    7767           40 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7768           40 :                     $$ = (Node *) n;
    7769              :                 }
    7770              :             | BACKWARD SignedIconst opt_from_in cursor_name
    7771              :                 {
    7772          113 :                     FetchStmt *n = makeNode(FetchStmt);
    7773              : 
    7774          113 :                     n->portalname = $4;
    7775          113 :                     n->direction = FETCH_BACKWARD;
    7776          113 :                     n->howMany = $2;
    7777          113 :                     n->location = @2;
    7778          113 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7779          113 :                     $$ = (Node *) n;
    7780              :                 }
    7781              :             | BACKWARD ALL opt_from_in cursor_name
    7782              :                 {
    7783           46 :                     FetchStmt *n = makeNode(FetchStmt);
    7784              : 
    7785           46 :                     n->portalname = $4;
    7786           46 :                     n->direction = FETCH_BACKWARD;
    7787           46 :                     n->howMany = FETCH_ALL;
    7788           46 :                     n->location = -1;
    7789           46 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
    7790           46 :                     $$ = (Node *) n;
    7791              :                 }
    7792              :         ;
    7793              : 
    7794              : from_in:    FROM
    7795              :             | IN_P
    7796              :         ;
    7797              : 
    7798              : opt_from_in:    from_in
    7799              :             | /* EMPTY */
    7800              :         ;
    7801              : 
    7802              : 
    7803              : /*****************************************************************************
    7804              :  *
    7805              :  * GRANT and REVOKE statements
    7806              :  *
    7807              :  *****************************************************************************/
    7808              : 
    7809              : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7810              :             opt_grant_grant_option opt_granted_by
    7811              :                 {
    7812         6035 :                     GrantStmt *n = makeNode(GrantStmt);
    7813              : 
    7814         6035 :                     n->is_grant = true;
    7815         6035 :                     n->privileges = $2;
    7816         6035 :                     n->targtype = ($4)->targtype;
    7817         6035 :                     n->objtype = ($4)->objtype;
    7818         6035 :                     n->objects = ($4)->objs;
    7819         6035 :                     n->grantees = $6;
    7820         6035 :                     n->grant_option = $7;
    7821         6035 :                     n->grantor = $8;
    7822         6035 :                     $$ = (Node *) n;
    7823              :                 }
    7824              :         ;
    7825              : 
    7826              : RevokeStmt:
    7827              :             REVOKE privileges ON privilege_target
    7828              :             FROM grantee_list opt_granted_by opt_drop_behavior
    7829              :                 {
    7830         5341 :                     GrantStmt *n = makeNode(GrantStmt);
    7831              : 
    7832         5341 :                     n->is_grant = false;
    7833         5341 :                     n->grant_option = false;
    7834         5341 :                     n->privileges = $2;
    7835         5341 :                     n->targtype = ($4)->targtype;
    7836         5341 :                     n->objtype = ($4)->objtype;
    7837         5341 :                     n->objects = ($4)->objs;
    7838         5341 :                     n->grantees = $6;
    7839         5341 :                     n->grantor = $7;
    7840         5341 :                     n->behavior = $8;
    7841         5341 :                     $$ = (Node *) n;
    7842              :                 }
    7843              :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7844              :             FROM grantee_list opt_granted_by opt_drop_behavior
    7845              :                 {
    7846            8 :                     GrantStmt *n = makeNode(GrantStmt);
    7847              : 
    7848            8 :                     n->is_grant = false;
    7849            8 :                     n->grant_option = true;
    7850            8 :                     n->privileges = $5;
    7851            8 :                     n->targtype = ($7)->targtype;
    7852            8 :                     n->objtype = ($7)->objtype;
    7853            8 :                     n->objects = ($7)->objs;
    7854            8 :                     n->grantees = $9;
    7855            8 :                     n->grantor = $10;
    7856            8 :                     n->behavior = $11;
    7857            8 :                     $$ = (Node *) n;
    7858              :                 }
    7859              :         ;
    7860              : 
    7861              : 
    7862              : /*
    7863              :  * Privilege names are represented as strings; the validity of the privilege
    7864              :  * names gets checked at execution.  This is a bit annoying but we have little
    7865              :  * choice because of the syntactic conflict with lists of role names in
    7866              :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7867              :  * production any reserved keywords that need to be usable as privilege names.
    7868              :  */
    7869              : 
    7870              : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7871              : privileges: privilege_list
    7872        10023 :                 { $$ = $1; }
    7873              :             | ALL
    7874         1400 :                 { $$ = NIL; }
    7875              :             | ALL PRIVILEGES
    7876           61 :                 { $$ = NIL; }
    7877              :             | ALL '(' columnList ')'
    7878              :                 {
    7879            9 :                     AccessPriv *n = makeNode(AccessPriv);
    7880              : 
    7881            9 :                     n->priv_name = NULL;
    7882            9 :                     n->cols = $3;
    7883            9 :                     $$ = list_make1(n);
    7884              :                 }
    7885              :             | ALL PRIVILEGES '(' columnList ')'
    7886              :                 {
    7887            0 :                     AccessPriv *n = makeNode(AccessPriv);
    7888              : 
    7889            0 :                     n->priv_name = NULL;
    7890            0 :                     n->cols = $4;
    7891            0 :                     $$ = list_make1(n);
    7892              :                 }
    7893              :         ;
    7894              : 
    7895        10487 : privilege_list: privilege                           { $$ = list_make1($1); }
    7896          298 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7897              :         ;
    7898              : 
    7899              : privilege:  SELECT opt_column_list
    7900              :             {
    7901         4862 :                 AccessPriv *n = makeNode(AccessPriv);
    7902              : 
    7903         4862 :                 n->priv_name = pstrdup($1);
    7904         4862 :                 n->cols = $2;
    7905         4862 :                 $$ = n;
    7906              :             }
    7907              :         | REFERENCES opt_column_list
    7908              :             {
    7909            7 :                 AccessPriv *n = makeNode(AccessPriv);
    7910              : 
    7911            7 :                 n->priv_name = pstrdup($1);
    7912            7 :                 n->cols = $2;
    7913            7 :                 $$ = n;
    7914              :             }
    7915              :         | CREATE opt_column_list
    7916              :             {
    7917          164 :                 AccessPriv *n = makeNode(AccessPriv);
    7918              : 
    7919          164 :                 n->priv_name = pstrdup($1);
    7920          164 :                 n->cols = $2;
    7921          164 :                 $$ = n;
    7922              :             }
    7923              :         | ALTER SYSTEM_P
    7924              :             {
    7925           12 :                 AccessPriv *n = makeNode(AccessPriv);
    7926           12 :                 n->priv_name = pstrdup("alter system");
    7927           12 :                 n->cols = NIL;
    7928           12 :                 $$ = n;
    7929              :             }
    7930              :         | ColId opt_column_list
    7931              :             {
    7932         5740 :                 AccessPriv *n = makeNode(AccessPriv);
    7933              : 
    7934         5740 :                 n->priv_name = $1;
    7935         5740 :                 n->cols = $2;
    7936         5740 :                 $$ = n;
    7937              :             }
    7938              :         ;
    7939              : 
    7940              : parameter_name_list:
    7941              :         parameter_name
    7942              :             {
    7943           38 :                 $$ = list_make1(makeString($1));
    7944              :             }
    7945              :         | parameter_name_list ',' parameter_name
    7946              :             {
    7947           25 :                 $$ = lappend($1, makeString($3));
    7948              :             }
    7949              :         ;
    7950              : 
    7951              : parameter_name:
    7952              :         ColId
    7953              :             {
    7954           63 :                 $$ = $1;
    7955              :             }
    7956              :         | parameter_name '.' ColId
    7957              :             {
    7958           16 :                 $$ = psprintf("%s.%s", $1, $3);
    7959              :             }
    7960              :         ;
    7961              : 
    7962              : 
    7963              : /* Don't bother trying to fold the first two rules into one using
    7964              :  * opt_table.  You're going to get conflicts.
    7965              :  */
    7966              : privilege_target:
    7967              :             qualified_name_list
    7968              :                 {
    7969         5907 :                     PrivTarget *n = palloc_object(PrivTarget);
    7970              : 
    7971         5907 :                     n->targtype = ACL_TARGET_OBJECT;
    7972         5907 :                     n->objtype = OBJECT_TABLE;
    7973         5907 :                     n->objs = $1;
    7974         5907 :                     $$ = n;
    7975              :                 }
    7976              :             | TABLE qualified_name_list
    7977              :                 {
    7978          199 :                     PrivTarget *n = palloc_object(PrivTarget);
    7979              : 
    7980          199 :                     n->targtype = ACL_TARGET_OBJECT;
    7981          199 :                     n->objtype = OBJECT_TABLE;
    7982          199 :                     n->objs = $2;
    7983          199 :                     $$ = n;
    7984              :                 }
    7985              :             | SEQUENCE qualified_name_list
    7986              :                 {
    7987           12 :                     PrivTarget *n = palloc_object(PrivTarget);
    7988              : 
    7989           12 :                     n->targtype = ACL_TARGET_OBJECT;
    7990           12 :                     n->objtype = OBJECT_SEQUENCE;
    7991           12 :                     n->objs = $2;
    7992           12 :                     $$ = n;
    7993              :                 }
    7994              :             | FOREIGN DATA_P WRAPPER name_list
    7995              :                 {
    7996           46 :                     PrivTarget *n = palloc_object(PrivTarget);
    7997              : 
    7998           46 :                     n->targtype = ACL_TARGET_OBJECT;
    7999           46 :                     n->objtype = OBJECT_FDW;
    8000           46 :                     n->objs = $4;
    8001           46 :                     $$ = n;
    8002              :                 }
    8003              :             | FOREIGN SERVER name_list
    8004              :                 {
    8005           44 :                     PrivTarget *n = palloc_object(PrivTarget);
    8006              : 
    8007           44 :                     n->targtype = ACL_TARGET_OBJECT;
    8008           44 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    8009           44 :                     n->objs = $3;
    8010           44 :                     $$ = n;
    8011              :                 }
    8012              :             | FUNCTION function_with_argtypes_list
    8013              :                 {
    8014         4551 :                     PrivTarget *n = palloc_object(PrivTarget);
    8015              : 
    8016         4551 :                     n->targtype = ACL_TARGET_OBJECT;
    8017         4551 :                     n->objtype = OBJECT_FUNCTION;
    8018         4551 :                     n->objs = $2;
    8019         4551 :                     $$ = n;
    8020              :                 }
    8021              :             | PROCEDURE function_with_argtypes_list
    8022              :                 {
    8023           21 :                     PrivTarget *n = palloc_object(PrivTarget);
    8024              : 
    8025           21 :                     n->targtype = ACL_TARGET_OBJECT;
    8026           21 :                     n->objtype = OBJECT_PROCEDURE;
    8027           21 :                     n->objs = $2;
    8028           21 :                     $$ = n;
    8029              :                 }
    8030              :             | ROUTINE function_with_argtypes_list
    8031              :                 {
    8032            0 :                     PrivTarget *n = palloc_object(PrivTarget);
    8033              : 
    8034            0 :                     n->targtype = ACL_TARGET_OBJECT;
    8035            0 :                     n->objtype = OBJECT_ROUTINE;
    8036            0 :                     n->objs = $2;
    8037            0 :                     $$ = n;
    8038              :                 }
    8039              :             | DATABASE name_list
    8040              :                 {
    8041          178 :                     PrivTarget *n = palloc_object(PrivTarget);
    8042              : 
    8043          178 :                     n->targtype = ACL_TARGET_OBJECT;
    8044          178 :                     n->objtype = OBJECT_DATABASE;
    8045          178 :                     n->objs = $2;
    8046          178 :                     $$ = n;
    8047              :                 }
    8048              :             | DOMAIN_P any_name_list
    8049              :                 {
    8050           13 :                     PrivTarget *n = palloc_object(PrivTarget);
    8051              : 
    8052           13 :                     n->targtype = ACL_TARGET_OBJECT;
    8053           13 :                     n->objtype = OBJECT_DOMAIN;
    8054           13 :                     n->objs = $2;
    8055           13 :                     $$ = n;
    8056              :                 }
    8057              :             | LANGUAGE name_list
    8058              :                 {
    8059           21 :                     PrivTarget *n = palloc_object(PrivTarget);
    8060              : 
    8061           21 :                     n->targtype = ACL_TARGET_OBJECT;
    8062           21 :                     n->objtype = OBJECT_LANGUAGE;
    8063           21 :                     n->objs = $2;
    8064           21 :                     $$ = n;
    8065              :                 }
    8066              :             | LARGE_P OBJECT_P NumericOnly_list
    8067              :                 {
    8068           48 :                     PrivTarget *n = palloc_object(PrivTarget);
    8069              : 
    8070           48 :                     n->targtype = ACL_TARGET_OBJECT;
    8071           48 :                     n->objtype = OBJECT_LARGEOBJECT;
    8072           48 :                     n->objs = $3;
    8073           48 :                     $$ = n;
    8074              :                 }
    8075              :             | PARAMETER parameter_name_list
    8076              :                 {
    8077           38 :                     PrivTarget *n = palloc_object(PrivTarget);
    8078           38 :                     n->targtype = ACL_TARGET_OBJECT;
    8079           38 :                     n->objtype = OBJECT_PARAMETER_ACL;
    8080           38 :                     n->objs = $2;
    8081           38 :                     $$ = n;
    8082              :                 }
    8083              :             | SCHEMA name_list
    8084              :                 {
    8085          238 :                     PrivTarget *n = palloc_object(PrivTarget);
    8086              : 
    8087          238 :                     n->targtype = ACL_TARGET_OBJECT;
    8088          238 :                     n->objtype = OBJECT_SCHEMA;
    8089          238 :                     n->objs = $2;
    8090          238 :                     $$ = n;
    8091              :                 }
    8092              :             | TABLESPACE name_list
    8093              :                 {
    8094            3 :                     PrivTarget *n = palloc_object(PrivTarget);
    8095              : 
    8096            3 :                     n->targtype = ACL_TARGET_OBJECT;
    8097            3 :                     n->objtype = OBJECT_TABLESPACE;
    8098            3 :                     n->objs = $2;
    8099            3 :                     $$ = n;
    8100              :                 }
    8101              :             | TYPE_P any_name_list
    8102              :                 {
    8103           56 :                     PrivTarget *n = palloc_object(PrivTarget);
    8104              : 
    8105           56 :                     n->targtype = ACL_TARGET_OBJECT;
    8106           56 :                     n->objtype = OBJECT_TYPE;
    8107           56 :                     n->objs = $2;
    8108           56 :                     $$ = n;
    8109              :                 }
    8110              :             | ALL TABLES IN_P SCHEMA name_list
    8111              :                 {
    8112            6 :                     PrivTarget *n = palloc_object(PrivTarget);
    8113              : 
    8114            6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8115            6 :                     n->objtype = OBJECT_TABLE;
    8116            6 :                     n->objs = $5;
    8117            6 :                     $$ = n;
    8118              :                 }
    8119              :             | ALL SEQUENCES IN_P SCHEMA name_list
    8120              :                 {
    8121            0 :                     PrivTarget *n = palloc_object(PrivTarget);
    8122              : 
    8123            0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8124            0 :                     n->objtype = OBJECT_SEQUENCE;
    8125            0 :                     n->objs = $5;
    8126            0 :                     $$ = n;
    8127              :                 }
    8128              :             | ALL FUNCTIONS IN_P SCHEMA name_list
    8129              :                 {
    8130            3 :                     PrivTarget *n = palloc_object(PrivTarget);
    8131              : 
    8132            3 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8133            3 :                     n->objtype = OBJECT_FUNCTION;
    8134            3 :                     n->objs = $5;
    8135            3 :                     $$ = n;
    8136              :                 }
    8137              :             | ALL PROCEDURES IN_P SCHEMA name_list
    8138              :                 {
    8139            3 :                     PrivTarget *n = palloc_object(PrivTarget);
    8140              : 
    8141            3 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8142            3 :                     n->objtype = OBJECT_PROCEDURE;
    8143            3 :                     n->objs = $5;
    8144            3 :                     $$ = n;
    8145              :                 }
    8146              :             | ALL ROUTINES IN_P SCHEMA name_list
    8147              :                 {
    8148            3 :                     PrivTarget *n = palloc_object(PrivTarget);
    8149              : 
    8150            3 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8151            3 :                     n->objtype = OBJECT_ROUTINE;
    8152            3 :                     n->objs = $5;
    8153            3 :                     $$ = n;
    8154              :                 }
    8155              :         ;
    8156              : 
    8157              : 
    8158              : grantee_list:
    8159        11487 :             grantee                                 { $$ = list_make1($1); }
    8160           54 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    8161              :         ;
    8162              : 
    8163              : grantee:
    8164        11529 :             RoleSpec                                { $$ = $1; }
    8165           12 :             | GROUP_P RoleSpec                      { $$ = $2; }
    8166              :         ;
    8167              : 
    8168              : 
    8169              : opt_grant_grant_option:
    8170           51 :             WITH GRANT OPTION { $$ = true; }
    8171         6046 :             | /*EMPTY*/ { $$ = false; }
    8172              :         ;
    8173              : 
    8174              : /*****************************************************************************
    8175              :  *
    8176              :  * GRANT and REVOKE ROLE statements
    8177              :  *
    8178              :  *****************************************************************************/
    8179              : 
    8180              : GrantRoleStmt:
    8181              :             GRANT privilege_list TO role_list opt_granted_by
    8182              :                 {
    8183          297 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8184              : 
    8185          297 :                     n->is_grant = true;
    8186          297 :                     n->granted_roles = $2;
    8187          297 :                     n->grantee_roles = $4;
    8188          297 :                     n->opt = NIL;
    8189          297 :                     n->grantor = $5;
    8190          297 :                     $$ = (Node *) n;
    8191              :                 }
    8192              :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8193              :                 {
    8194           89 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8195              : 
    8196           89 :                     n->is_grant = true;
    8197           89 :                     n->granted_roles = $2;
    8198           89 :                     n->grantee_roles = $4;
    8199           89 :                     n->opt = $6;
    8200           89 :                     n->grantor = $7;
    8201           89 :                     $$ = (Node *) n;
    8202              :                 }
    8203              :         ;
    8204              : 
    8205              : RevokeRoleStmt:
    8206              :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8207              :                 {
    8208           45 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8209              : 
    8210           45 :                     n->is_grant = false;
    8211           45 :                     n->opt = NIL;
    8212           45 :                     n->granted_roles = $2;
    8213           45 :                     n->grantee_roles = $4;
    8214           45 :                     n->grantor = $5;
    8215           45 :                     n->behavior = $6;
    8216           45 :                     $$ = (Node *) n;
    8217              :                 }
    8218              :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8219              :                 {
    8220           33 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8221              :                     DefElem *opt;
    8222              : 
    8223           33 :                     opt = makeDefElem(pstrdup($2),
    8224           33 :                                       (Node *) makeBoolean(false), @2);
    8225           33 :                     n->is_grant = false;
    8226           33 :                     n->opt = list_make1(opt);
    8227           33 :                     n->granted_roles = $5;
    8228           33 :                     n->grantee_roles = $7;
    8229           33 :                     n->grantor = $8;
    8230           33 :                     n->behavior = $9;
    8231           33 :                     $$ = (Node *) n;
    8232              :                 }
    8233              :         ;
    8234              : 
    8235              : grant_role_opt_list:
    8236           60 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8237           89 :             | grant_role_opt                        { $$ = list_make1($1); }
    8238              :         ;
    8239              : 
    8240              : grant_role_opt:
    8241              :         ColLabel grant_role_opt_value
    8242              :             {
    8243          149 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8244              :             }
    8245              :         ;
    8246              : 
    8247              : grant_role_opt_value:
    8248           36 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8249           56 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8250           57 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8251              :         ;
    8252              : 
    8253           69 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8254        11779 :             | /*EMPTY*/                                 { $$ = NULL; }
    8255              :         ;
    8256              : 
    8257              : /*****************************************************************************
    8258              :  *
    8259              :  * ALTER DEFAULT PRIVILEGES statement
    8260              :  *
    8261              :  *****************************************************************************/
    8262              : 
    8263              : AlterDefaultPrivilegesStmt:
    8264              :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8265              :                 {
    8266          103 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8267              : 
    8268          103 :                     n->options = $4;
    8269          103 :                     n->action = (GrantStmt *) $5;
    8270          103 :                     $$ = (Node *) n;
    8271              :                 }
    8272              :         ;
    8273              : 
    8274              : DefACLOptionList:
    8275           72 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8276          103 :             | /* EMPTY */                           { $$ = NIL; }
    8277              :         ;
    8278              : 
    8279              : DefACLOption:
    8280              :             IN_P SCHEMA name_list
    8281              :                 {
    8282           30 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8283              :                 }
    8284              :             | FOR ROLE role_list
    8285              :                 {
    8286           42 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8287              :                 }
    8288              :             | FOR USER role_list
    8289              :                 {
    8290            0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8291              :                 }
    8292              :         ;
    8293              : 
    8294              : /*
    8295              :  * This should match GRANT/REVOKE, except that individual target objects
    8296              :  * are not mentioned and we only allow a subset of object types.
    8297              :  */
    8298              : DefACLAction:
    8299              :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8300              :             opt_grant_grant_option
    8301              :                 {
    8302           62 :                     GrantStmt *n = makeNode(GrantStmt);
    8303              : 
    8304           62 :                     n->is_grant = true;
    8305           62 :                     n->privileges = $2;
    8306           62 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8307           62 :                     n->objtype = $4;
    8308           62 :                     n->objects = NIL;
    8309           62 :                     n->grantees = $6;
    8310           62 :                     n->grant_option = $7;
    8311           62 :                     $$ = (Node *) n;
    8312              :                 }
    8313              :             | REVOKE privileges ON defacl_privilege_target
    8314              :             FROM grantee_list opt_drop_behavior
    8315              :                 {
    8316           41 :                     GrantStmt *n = makeNode(GrantStmt);
    8317              : 
    8318           41 :                     n->is_grant = false;
    8319           41 :                     n->grant_option = false;
    8320           41 :                     n->privileges = $2;
    8321           41 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8322           41 :                     n->objtype = $4;
    8323           41 :                     n->objects = NIL;
    8324           41 :                     n->grantees = $6;
    8325           41 :                     n->behavior = $7;
    8326           41 :                     $$ = (Node *) n;
    8327              :                 }
    8328              :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8329              :             FROM grantee_list opt_drop_behavior
    8330              :                 {
    8331            0 :                     GrantStmt *n = makeNode(GrantStmt);
    8332              : 
    8333            0 :                     n->is_grant = false;
    8334            0 :                     n->grant_option = true;
    8335            0 :                     n->privileges = $5;
    8336            0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8337            0 :                     n->objtype = $7;
    8338            0 :                     n->objects = NIL;
    8339            0 :                     n->grantees = $9;
    8340            0 :                     n->behavior = $10;
    8341            0 :                     $$ = (Node *) n;
    8342              :                 }
    8343              :         ;
    8344              : 
    8345              : defacl_privilege_target:
    8346           39 :             TABLES          { $$ = OBJECT_TABLE; }
    8347            8 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8348            3 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8349            3 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8350           17 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8351           18 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8352           15 :             | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
    8353              :         ;
    8354              : 
    8355              : 
    8356              : /*****************************************************************************
    8357              :  *
    8358              :  *      QUERY: CREATE INDEX
    8359              :  *
    8360              :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8361              :  * willing to make TABLESPACE a fully reserved word.
    8362              :  *****************************************************************************/
    8363              : 
    8364              : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8365              :             ON relation_expr access_method_clause '(' index_params ')'
    8366              :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8367              :                 {
    8368         3409 :                     IndexStmt *n = makeNode(IndexStmt);
    8369              : 
    8370         3409 :                     n->unique = $2;
    8371         3409 :                     n->concurrent = $4;
    8372         3409 :                     n->idxname = $5;
    8373         3409 :                     n->relation = $7;
    8374         3409 :                     n->accessMethod = $8;
    8375         3409 :                     n->indexParams = $10;
    8376         3409 :                     n->indexIncludingParams = $12;
    8377         3409 :                     n->nulls_not_distinct = !$13;
    8378         3409 :                     n->options = $14;
    8379         3409 :                     n->tableSpace = $15;
    8380         3409 :                     n->whereClause = $16;
    8381         3409 :                     n->excludeOpNames = NIL;
    8382         3409 :                     n->idxcomment = NULL;
    8383         3409 :                     n->indexOid = InvalidOid;
    8384         3409 :                     n->oldNumber = InvalidRelFileNumber;
    8385         3409 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8386         3409 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8387         3409 :                     n->primary = false;
    8388         3409 :                     n->isconstraint = false;
    8389         3409 :                     n->deferrable = false;
    8390         3409 :                     n->initdeferred = false;
    8391         3409 :                     n->transformed = false;
    8392         3409 :                     n->if_not_exists = false;
    8393         3409 :                     n->reset_default_tblspc = false;
    8394         3409 :                     $$ = (Node *) n;
    8395              :                 }
    8396              :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8397              :             ON relation_expr access_method_clause '(' index_params ')'
    8398              :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8399              :                 {
    8400            9 :                     IndexStmt *n = makeNode(IndexStmt);
    8401              : 
    8402            9 :                     n->unique = $2;
    8403            9 :                     n->concurrent = $4;
    8404            9 :                     n->idxname = $8;
    8405            9 :                     n->relation = $10;
    8406            9 :                     n->accessMethod = $11;
    8407            9 :                     n->indexParams = $13;
    8408            9 :                     n->indexIncludingParams = $15;
    8409            9 :                     n->nulls_not_distinct = !$16;
    8410            9 :                     n->options = $17;
    8411            9 :                     n->tableSpace = $18;
    8412            9 :                     n->whereClause = $19;
    8413            9 :                     n->excludeOpNames = NIL;
    8414            9 :                     n->idxcomment = NULL;
    8415            9 :                     n->indexOid = InvalidOid;
    8416            9 :                     n->oldNumber = InvalidRelFileNumber;
    8417            9 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8418            9 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8419            9 :                     n->primary = false;
    8420            9 :                     n->isconstraint = false;
    8421            9 :                     n->deferrable = false;
    8422            9 :                     n->initdeferred = false;
    8423            9 :                     n->transformed = false;
    8424            9 :                     n->if_not_exists = true;
    8425            9 :                     n->reset_default_tblspc = false;
    8426            9 :                     $$ = (Node *) n;
    8427              :                 }
    8428              :         ;
    8429              : 
    8430              : opt_unique:
    8431          658 :             UNIQUE                                  { $$ = true; }
    8432         2763 :             | /*EMPTY*/                             { $$ = false; }
    8433              :         ;
    8434              : 
    8435              : access_method_clause:
    8436         1548 :             USING name                              { $$ = $2; }
    8437         1987 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8438              :         ;
    8439              : 
    8440         4372 : index_params:   index_elem                          { $$ = list_make1($1); }
    8441         1082 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8442              :         ;
    8443              : 
    8444              : 
    8445              : index_elem_options:
    8446              :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8447              :         {
    8448         5742 :             $$ = makeNode(IndexElem);
    8449         5742 :             $$->name = NULL;
    8450         5742 :             $$->expr = NULL;
    8451         5742 :             $$->indexcolname = NULL;
    8452         5742 :             $$->collation = $1;
    8453         5742 :             $$->opclass = $2;
    8454         5742 :             $$->opclassopts = NIL;
    8455         5742 :             $$->ordering = $3;
    8456         5742 :             $$->nulls_ordering = $4;
    8457              :             /* location will be filled in index_elem production */
    8458              :         }
    8459              :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8460              :         {
    8461           74 :             $$ = makeNode(IndexElem);
    8462           74 :             $$->name = NULL;
    8463           74 :             $$->expr = NULL;
    8464           74 :             $$->indexcolname = NULL;
    8465           74 :             $$->collation = $1;
    8466           74 :             $$->opclass = $2;
    8467           74 :             $$->opclassopts = $3;
    8468           74 :             $$->ordering = $4;
    8469           74 :             $$->nulls_ordering = $5;
    8470              :             /* location will be filled in index_elem production */
    8471              :         }
    8472              :     ;
    8473              : 
    8474              : /*
    8475              :  * Index attributes can be either simple column references, or arbitrary
    8476              :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8477              :  * an expression that's just a function call to be written without parens.
    8478              :  */
    8479              : index_elem: ColId index_elem_options
    8480              :                 {
    8481         5240 :                     $$ = $2;
    8482         5240 :                     $$->name = $1;
    8483         5240 :                     $$->location = @1;
    8484              :                 }
    8485              :             | func_expr_windowless index_elem_options
    8486              :                 {
    8487          312 :                     $$ = $2;
    8488          312 :                     $$->expr = $1;
    8489          312 :                     $$->location = @1;
    8490              :                 }
    8491              :             | '(' a_expr ')' index_elem_options
    8492              :                 {
    8493          264 :                     $$ = $4;
    8494          264 :                     $$->expr = $2;
    8495          264 :                     $$->location = @1;
    8496              :                 }
    8497              :         ;
    8498              : 
    8499          109 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8500         3309 :              |      /* EMPTY */                     { $$ = NIL; }
    8501              :         ;
    8502              : 
    8503          109 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8504           83 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8505              :         ;
    8506              : 
    8507           96 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8508         8768 :             | /*EMPTY*/                             { $$ = NIL; }
    8509              :         ;
    8510              : 
    8511              : 
    8512          974 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8513         1842 :             | DESC                          { $$ = SORTBY_DESC; }
    8514        60602 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8515              :         ;
    8516              : 
    8517          174 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8518          879 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8519        62475 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8520              :         ;
    8521              : 
    8522              : 
    8523              : /*****************************************************************************
    8524              :  *
    8525              :  *      QUERY:
    8526              :  *              create [or replace] function <fname>
    8527              :  *                      [(<type-1> { , <type-n>})]
    8528              :  *                      returns <type-r>
    8529              :  *                      as <filename or code in language as appropriate>
    8530              :  *                      language <lang> [with parameters]
    8531              :  *
    8532              :  *****************************************************************************/
    8533              : 
    8534              : CreateFunctionStmt:
    8535              :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8536              :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8537              :                 {
    8538        10708 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8539              : 
    8540        10708 :                     n->is_procedure = false;
    8541        10708 :                     n->replace = $2;
    8542        10708 :                     n->funcname = $4;
    8543        10708 :                     n->parameters = $5;
    8544        10708 :                     n->returnType = $7;
    8545        10708 :                     n->options = $8;
    8546        10708 :                     n->sql_body = $9;
    8547        10708 :                     $$ = (Node *) n;
    8548              :                 }
    8549              :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8550              :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8551              :                 {
    8552           97 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8553              : 
    8554           97 :                     n->is_procedure = false;
    8555           97 :                     n->replace = $2;
    8556           97 :                     n->funcname = $4;
    8557           97 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8558           97 :                     n->returnType = TableFuncTypeName($9);
    8559           97 :                     n->returnType->location = @7;
    8560           97 :                     n->options = $11;
    8561           97 :                     n->sql_body = $12;
    8562           97 :                     $$ = (Node *) n;
    8563              :                 }
    8564              :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8565              :               opt_createfunc_opt_list opt_routine_body
    8566              :                 {
    8567          261 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8568              : 
    8569          261 :                     n->is_procedure = false;
    8570          261 :                     n->replace = $2;
    8571          261 :                     n->funcname = $4;
    8572          261 :                     n->parameters = $5;
    8573          261 :                     n->returnType = NULL;
    8574          261 :                     n->options = $6;
    8575          261 :                     n->sql_body = $7;
    8576          261 :                     $$ = (Node *) n;
    8577              :                 }
    8578              :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8579              :               opt_createfunc_opt_list opt_routine_body
    8580              :                 {
    8581          185 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8582              : 
    8583          185 :                     n->is_procedure = true;
    8584          185 :                     n->replace = $2;
    8585          185 :                     n->funcname = $4;
    8586          185 :                     n->parameters = $5;
    8587          185 :                     n->returnType = NULL;
    8588          185 :                     n->options = $6;
    8589          185 :                     n->sql_body = $7;
    8590          185 :                     $$ = (Node *) n;
    8591              :                 }
    8592              :         ;
    8593              : 
    8594              : opt_or_replace:
    8595         3342 :             OR REPLACE                              { $$ = true; }
    8596        10680 :             | /*EMPTY*/                             { $$ = false; }
    8597              :         ;
    8598              : 
    8599         5596 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8600         3009 :             | '(' ')'                               { $$ = NIL; }
    8601              :         ;
    8602              : 
    8603              : func_args_list:
    8604         5596 :             func_arg                                { $$ = list_make1($1); }
    8605         4960 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8606              :         ;
    8607              : 
    8608              : function_with_argtypes_list:
    8609         6525 :             function_with_argtypes                  { $$ = list_make1($1); }
    8610              :             | function_with_argtypes_list ',' function_with_argtypes
    8611           42 :                                                     { $$ = lappend($1, $3); }
    8612              :         ;
    8613              : 
    8614              : function_with_argtypes:
    8615              :             func_name func_args
    8616              :                 {
    8617         8605 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8618              : 
    8619         8605 :                     n->objname = $1;
    8620         8605 :                     n->objargs = extractArgTypes($2);
    8621         8605 :                     n->objfuncargs = $2;
    8622         8605 :                     $$ = n;
    8623              :                 }
    8624              :             /*
    8625              :              * Because of reduce/reduce conflicts, we can't use func_name
    8626              :              * below, but we can write it out the long way, which actually
    8627              :              * allows more cases.
    8628              :              */
    8629              :             | type_func_name_keyword
    8630              :                 {
    8631            0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8632              : 
    8633            0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8634            0 :                     n->args_unspecified = true;
    8635            0 :                     $$ = n;
    8636              :                 }
    8637              :             | ColId
    8638              :                 {
    8639          233 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8640              : 
    8641          233 :                     n->objname = list_make1(makeString($1));
    8642          233 :                     n->args_unspecified = true;
    8643          233 :                     $$ = n;
    8644              :                 }
    8645              :             | ColId indirection
    8646              :                 {
    8647           14 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8648              : 
    8649           14 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8650              :                                                   yyscanner);
    8651           14 :                     n->args_unspecified = true;
    8652           14 :                     $$ = n;
    8653              :                 }
    8654              :         ;
    8655              : 
    8656              : /*
    8657              :  * func_args_with_defaults is separate because we only want to accept
    8658              :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8659              :  */
    8660              : func_args_with_defaults:
    8661         8967 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8662         2284 :         | '(' ')'                                   { $$ = NIL; }
    8663              :         ;
    8664              : 
    8665              : func_args_with_defaults_list:
    8666         8967 :         func_arg_with_default                       { $$ = list_make1($1); }
    8667              :         | func_args_with_defaults_list ',' func_arg_with_default
    8668        13222 :                                                     { $$ = lappend($1, $3); }
    8669              :         ;
    8670              : 
    8671              : /*
    8672              :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8673              :  * param_name first; accept both since it's likely people will try both
    8674              :  * anyway.  Don't bother trying to save productions by letting arg_class
    8675              :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8676              :  *
    8677              :  * We can catch over-specified arguments here if we want to,
    8678              :  * but for now better to silently swallow typmod, etc.
    8679              :  * - thomas 2000-03-22
    8680              :  */
    8681              : func_arg:
    8682              :             arg_class param_name func_type
    8683              :                 {
    8684         6538 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8685              : 
    8686         6538 :                     n->name = $2;
    8687         6538 :                     n->argType = $3;
    8688         6538 :                     n->mode = $1;
    8689         6538 :                     n->defexpr = NULL;
    8690         6538 :                     n->location = @1;
    8691         6538 :                     $$ = n;
    8692              :                 }
    8693              :             | param_name arg_class func_type
    8694              :                 {
    8695          212 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8696              : 
    8697          212 :                     n->name = $1;
    8698          212 :                     n->argType = $3;
    8699          212 :                     n->mode = $2;
    8700          212 :                     n->defexpr = NULL;
    8701          212 :                     n->location = @1;
    8702          212 :                     $$ = n;
    8703              :                 }
    8704              :             | param_name func_type
    8705              :                 {
    8706         3577 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8707              : 
    8708         3577 :                     n->name = $1;
    8709         3577 :                     n->argType = $2;
    8710         3577 :                     n->mode = FUNC_PARAM_DEFAULT;
    8711         3577 :                     n->defexpr = NULL;
    8712         3577 :                     n->location = @1;
    8713         3577 :                     $$ = n;
    8714              :                 }
    8715              :             | arg_class func_type
    8716              :                 {
    8717          167 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8718              : 
    8719          167 :                     n->name = NULL;
    8720          167 :                     n->argType = $2;
    8721          167 :                     n->mode = $1;
    8722          167 :                     n->defexpr = NULL;
    8723          167 :                     n->location = @1;
    8724          167 :                     $$ = n;
    8725              :                 }
    8726              :             | func_type
    8727              :                 {
    8728        22701 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8729              : 
    8730        22701 :                     n->name = NULL;
    8731        22701 :                     n->argType = $1;
    8732        22701 :                     n->mode = FUNC_PARAM_DEFAULT;
    8733        22701 :                     n->defexpr = NULL;
    8734        22701 :                     n->location = @1;
    8735        22701 :                     $$ = n;
    8736              :                 }
    8737              :         ;
    8738              : 
    8739              : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8740         1282 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8741         5438 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8742          100 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8743            0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8744           97 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8745              :         ;
    8746              : 
    8747              : /*
    8748              :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8749              :  */
    8750              : param_name: type_function_name
    8751              :         ;
    8752              : 
    8753              : func_return:
    8754              :             func_type
    8755              :                 {
    8756              :                     /* We can catch over-specified results here if we want to,
    8757              :                      * but for now better to silently swallow typmod, etc.
    8758              :                      * - thomas 2000-03-22
    8759              :                      */
    8760        10708 :                     $$ = $1;
    8761              :                 }
    8762              :         ;
    8763              : 
    8764              : /*
    8765              :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8766              :  * but that causes reduce/reduce conflicts.  type_function_name
    8767              :  * is next best choice.
    8768              :  */
    8769        54810 : func_type:  Typename                                { $$ = $1; }
    8770              :             | type_function_name attrs '%' TYPE_P
    8771              :                 {
    8772            9 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8773            9 :                     $$->pct_type = true;
    8774            9 :                     $$->location = @1;
    8775              :                 }
    8776              :             | SETOF type_function_name attrs '%' TYPE_P
    8777              :                 {
    8778            3 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8779            3 :                     $$->pct_type = true;
    8780            3 :                     $$->setof = true;
    8781            3 :                     $$->location = @2;
    8782              :                 }
    8783              :         ;
    8784              : 
    8785              : func_arg_with_default:
    8786              :         func_arg
    8787              :                 {
    8788        21743 :                     $$ = $1;
    8789              :                 }
    8790              :         | func_arg DEFAULT a_expr
    8791              :                 {
    8792          348 :                     $$ = $1;
    8793          348 :                     $$->defexpr = $3;
    8794              :                 }
    8795              :         | func_arg '=' a_expr
    8796              :                 {
    8797           98 :                     $$ = $1;
    8798           98 :                     $$->defexpr = $3;
    8799              :                 }
    8800              :         ;
    8801              : 
    8802              : /* Aggregate args can be most things that function args can be */
    8803              : aggr_arg:   func_arg
    8804              :                 {
    8805          450 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8806           30 :                           $1->mode == FUNC_PARAM_IN ||
    8807           30 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8808            0 :                         ereport(ERROR,
    8809              :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8810              :                                  errmsg("aggregates cannot have output arguments"),
    8811              :                                  parser_errposition(@1)));
    8812          450 :                     $$ = $1;
    8813              :                 }
    8814              :         ;
    8815              : 
    8816              : /*
    8817              :  * The SQL standard offers no guidance on how to declare aggregate argument
    8818              :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8819              :  *
    8820              :  * (*)                                  - normal agg with no args
    8821              :  * (aggr_arg,...)                       - normal agg with args
    8822              :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8823              :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8824              :  *
    8825              :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8826              :  *
    8827              :  * An additional restriction is that if the direct-args list ends in a
    8828              :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8829              :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8830              :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8831              :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8832              :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8833              :  * in cases such as DROP AGGREGATE.
    8834              :  *
    8835              :  * The return value of this production is a two-element list, in which the
    8836              :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8837              :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8838              :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8839              :  * of argument declarations before the ORDER BY.  (If this number is equal
    8840              :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8841              :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8842              :  * on existing aggregates, we can just apply extractArgTypes to the first
    8843              :  * sublist.
    8844              :  */
    8845              : aggr_args:  '(' '*' ')'
    8846              :                 {
    8847           68 :                     $$ = list_make2(NIL, makeInteger(-1));
    8848              :                 }
    8849              :             | '(' aggr_args_list ')'
    8850              :                 {
    8851          366 :                     $$ = list_make2($2, makeInteger(-1));
    8852              :                 }
    8853              :             | '(' ORDER BY aggr_args_list ')'
    8854              :                 {
    8855            3 :                     $$ = list_make2($4, makeInteger(0));
    8856              :                 }
    8857              :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8858              :                 {
    8859              :                     /* this is the only case requiring consistency checking */
    8860           16 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8861              :                 }
    8862              :         ;
    8863              : 
    8864              : aggr_args_list:
    8865          401 :             aggr_arg                                { $$ = list_make1($1); }
    8866           49 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8867              :         ;
    8868              : 
    8869              : aggregate_with_argtypes:
    8870              :             func_name aggr_args
    8871              :                 {
    8872          181 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8873              : 
    8874          181 :                     n->objname = $1;
    8875          181 :                     n->objargs = extractAggrArgTypes($2);
    8876          181 :                     n->objfuncargs = (List *) linitial($2);
    8877          181 :                     $$ = n;
    8878              :                 }
    8879              :         ;
    8880              : 
    8881              : aggregate_with_argtypes_list:
    8882           52 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8883              :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8884            0 :                                                     { $$ = lappend($1, $3); }
    8885              :         ;
    8886              : 
    8887              : opt_createfunc_opt_list:
    8888              :             createfunc_opt_list
    8889           30 :             | /*EMPTY*/ { $$ = NIL; }
    8890              :     ;
    8891              : 
    8892              : createfunc_opt_list:
    8893              :             /* Must be at least one to prevent conflict */
    8894        11221 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8895        28172 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8896              :     ;
    8897              : 
    8898              : /*
    8899              :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8900              :  */
    8901              : common_func_opt_item:
    8902              :             CALLED ON NULL_P INPUT_P
    8903              :                 {
    8904           52 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8905              :                 }
    8906              :             | RETURNS NULL_P ON NULL_P INPUT_P
    8907              :                 {
    8908          451 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8909              :                 }
    8910              :             | STRICT_P
    8911              :                 {
    8912         5661 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8913              :                 }
    8914              :             | IMMUTABLE
    8915              :                 {
    8916         4577 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8917              :                 }
    8918              :             | STABLE
    8919              :                 {
    8920          850 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8921              :                 }
    8922              :             | VOLATILE
    8923              :                 {
    8924          160 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8925              :                 }
    8926              :             | EXTERNAL SECURITY DEFINER
    8927              :                 {
    8928            0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8929              :                 }
    8930              :             | EXTERNAL SECURITY INVOKER
    8931              :                 {
    8932            0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8933              :                 }
    8934              :             | SECURITY DEFINER
    8935              :                 {
    8936           29 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8937              :                 }
    8938              :             | SECURITY INVOKER
    8939              :                 {
    8940            9 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8941              :                 }
    8942              :             | LEAKPROOF
    8943              :                 {
    8944           23 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8945              :                 }
    8946              :             | NOT LEAKPROOF
    8947              :                 {
    8948            6 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8949              :                 }
    8950              :             | COST NumericOnly
    8951              :                 {
    8952         1980 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8953              :                 }
    8954              :             | ROWS NumericOnly
    8955              :                 {
    8956           61 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8957              :                 }
    8958              :             | SUPPORT any_name
    8959              :                 {
    8960           61 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8961              :                 }
    8962              :             | FunctionSetResetClause
    8963              :                 {
    8964              :                     /* we abuse the normal content of a DefElem here */
    8965           77 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8966              :                 }
    8967              :             | PARALLEL ColId
    8968              :                 {
    8969         5944 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8970              :                 }
    8971              :         ;
    8972              : 
    8973              : createfunc_opt_item:
    8974              :             AS func_as
    8975              :                 {
    8976         8353 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8977              :                 }
    8978              :             | LANGUAGE NonReservedWord_or_Sconst
    8979              :                 {
    8980        11211 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8981              :                 }
    8982              :             | TRANSFORM transform_type_list
    8983              :                 {
    8984           59 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8985              :                 }
    8986              :             | WINDOW
    8987              :                 {
    8988           10 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8989              :                 }
    8990              :             | common_func_opt_item
    8991              :                 {
    8992        19760 :                     $$ = $1;
    8993              :                 }
    8994              :         ;
    8995              : 
    8996         6649 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8997              :             | Sconst ',' Sconst
    8998              :                 {
    8999         1704 :                     $$ = list_make2(makeString($1), makeString($3));
    9000              :                 }
    9001              :         ;
    9002              : 
    9003              : ReturnStmt: RETURN a_expr
    9004              :                 {
    9005         2491 :                     ReturnStmt *r = makeNode(ReturnStmt);
    9006              : 
    9007         2491 :                     r->returnval = (Node *) $2;
    9008         2491 :                     $$ = (Node *) r;
    9009              :                 }
    9010              :         ;
    9011              : 
    9012              : opt_routine_body:
    9013              :             ReturnStmt
    9014              :                 {
    9015         2488 :                     $$ = $1;
    9016              :                 }
    9017              :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    9018              :                 {
    9019              :                     /*
    9020              :                      * A compound statement is stored as a single-item list
    9021              :                      * containing the list of statements as its member.  That
    9022              :                      * way, the parse analysis code can tell apart an empty
    9023              :                      * body from no body at all.
    9024              :                      */
    9025          413 :                     $$ = (Node *) list_make1($3);
    9026              :                 }
    9027              :             | /*EMPTY*/
    9028              :                 {
    9029         8350 :                     $$ = NULL;
    9030              :                 }
    9031              :         ;
    9032              : 
    9033              : routine_body_stmt_list:
    9034              :             routine_body_stmt_list routine_body_stmt ';'
    9035              :                 {
    9036              :                     /* As in stmtmulti, discard empty statements */
    9037          421 :                     if ($2 != NULL)
    9038          412 :                         $$ = lappend($1, $2);
    9039              :                     else
    9040            9 :                         $$ = $1;
    9041              :                 }
    9042              :             | /*EMPTY*/
    9043              :                 {
    9044          413 :                     $$ = NIL;
    9045              :                 }
    9046              :         ;
    9047              : 
    9048              : routine_body_stmt:
    9049              :             stmt
    9050              :             | ReturnStmt
    9051              :         ;
    9052              : 
    9053              : transform_type_list:
    9054           59 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    9055            2 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    9056              :         ;
    9057              : 
    9058              : opt_definition:
    9059          331 :             WITH definition                         { $$ = $2; }
    9060         5241 :             | /*EMPTY*/                             { $$ = NIL; }
    9061              :         ;
    9062              : 
    9063              : table_func_column:  param_name func_type
    9064              :                 {
    9065          227 :                     FunctionParameter *n = makeNode(FunctionParameter);
    9066              : 
    9067          227 :                     n->name = $1;
    9068          227 :                     n->argType = $2;
    9069          227 :                     n->mode = FUNC_PARAM_TABLE;
    9070          227 :                     n->defexpr = NULL;
    9071          227 :                     n->location = @1;
    9072          227 :                     $$ = n;
    9073              :                 }
    9074              :         ;
    9075              : 
    9076              : table_func_column_list:
    9077              :             table_func_column
    9078              :                 {
    9079           97 :                     $$ = list_make1($1);
    9080              :                 }
    9081              :             | table_func_column_list ',' table_func_column
    9082              :                 {
    9083          130 :                     $$ = lappend($1, $3);
    9084              :                 }
    9085              :         ;
    9086              : 
    9087              : /*****************************************************************************
    9088              :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    9089              :  *
    9090              :  * RENAME and OWNER subcommands are already provided by the generic
    9091              :  * ALTER infrastructure, here we just specify alterations that can
    9092              :  * only be applied to functions.
    9093              :  *
    9094              :  *****************************************************************************/
    9095              : AlterFunctionStmt:
    9096              :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    9097              :                 {
    9098          170 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9099              : 
    9100          170 :                     n->objtype = OBJECT_FUNCTION;
    9101          170 :                     n->func = $3;
    9102          170 :                     n->actions = $4;
    9103          170 :                     $$ = (Node *) n;
    9104              :                 }
    9105              :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    9106              :                 {
    9107            9 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9108              : 
    9109            9 :                     n->objtype = OBJECT_PROCEDURE;
    9110            9 :                     n->func = $3;
    9111            9 :                     n->actions = $4;
    9112            9 :                     $$ = (Node *) n;
    9113              :                 }
    9114              :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    9115              :                 {
    9116            0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9117              : 
    9118            0 :                     n->objtype = OBJECT_ROUTINE;
    9119            0 :                     n->func = $3;
    9120            0 :                     n->actions = $4;
    9121            0 :                     $$ = (Node *) n;
    9122              :                 }
    9123              :         ;
    9124              : 
    9125              : alterfunc_opt_list:
    9126              :             /* At least one option must be specified */
    9127          179 :             common_func_opt_item                    { $$ = list_make1($1); }
    9128            2 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    9129              :         ;
    9130              : 
    9131              : /* Ignored, merely for SQL compliance */
    9132              : opt_restrict:
    9133              :             RESTRICT
    9134              :             | /* EMPTY */
    9135              :         ;
    9136              : 
    9137              : 
    9138              : /*****************************************************************************
    9139              :  *
    9140              :  *      QUERY:
    9141              :  *
    9142              :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9143              :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9144              :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9145              :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    9146              :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    9147              :  *
    9148              :  *****************************************************************************/
    9149              : 
    9150              : RemoveFuncStmt:
    9151              :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    9152              :                 {
    9153         1741 :                     DropStmt *n = makeNode(DropStmt);
    9154              : 
    9155         1741 :                     n->removeType = OBJECT_FUNCTION;
    9156         1741 :                     n->objects = $3;
    9157         1741 :                     n->behavior = $4;
    9158         1741 :                     n->missing_ok = false;
    9159         1741 :                     n->concurrent = false;
    9160         1741 :                     $$ = (Node *) n;
    9161              :                 }
    9162              :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9163              :                 {
    9164          130 :                     DropStmt *n = makeNode(DropStmt);
    9165              : 
    9166          130 :                     n->removeType = OBJECT_FUNCTION;
    9167          130 :                     n->objects = $5;
    9168          130 :                     n->behavior = $6;
    9169          130 :                     n->missing_ok = true;
    9170          130 :                     n->concurrent = false;
    9171          130 :                     $$ = (Node *) n;
    9172              :                 }
    9173              :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    9174              :                 {
    9175           70 :                     DropStmt *n = makeNode(DropStmt);
    9176              : 
    9177           70 :                     n->removeType = OBJECT_PROCEDURE;
    9178           70 :                     n->objects = $3;
    9179           70 :                     n->behavior = $4;
    9180           70 :                     n->missing_ok = false;
    9181           70 :                     n->concurrent = false;
    9182           70 :                     $$ = (Node *) n;
    9183              :                 }
    9184              :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9185              :                 {
    9186            3 :                     DropStmt *n = makeNode(DropStmt);
    9187              : 
    9188            3 :                     n->removeType = OBJECT_PROCEDURE;
    9189            3 :                     n->objects = $5;
    9190            3 :                     n->behavior = $6;
    9191            3 :                     n->missing_ok = true;
    9192            3 :                     n->concurrent = false;
    9193            3 :                     $$ = (Node *) n;
    9194              :                 }
    9195              :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9196              :                 {
    9197            6 :                     DropStmt *n = makeNode(DropStmt);
    9198              : 
    9199            6 :                     n->removeType = OBJECT_ROUTINE;
    9200            6 :                     n->objects = $3;
    9201            6 :                     n->behavior = $4;
    9202            6 :                     n->missing_ok = false;
    9203            6 :                     n->concurrent = false;
    9204            6 :                     $$ = (Node *) n;
    9205              :                 }
    9206              :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9207              :                 {
    9208            3 :                     DropStmt *n = makeNode(DropStmt);
    9209              : 
    9210            3 :                     n->removeType = OBJECT_ROUTINE;
    9211            3 :                     n->objects = $5;
    9212            3 :                     n->behavior = $6;
    9213            3 :                     n->missing_ok = true;
    9214            3 :                     n->concurrent = false;
    9215            3 :                     $$ = (Node *) n;
    9216              :                 }
    9217              :         ;
    9218              : 
    9219              : RemoveAggrStmt:
    9220              :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9221              :                 {
    9222           37 :                     DropStmt *n = makeNode(DropStmt);
    9223              : 
    9224           37 :                     n->removeType = OBJECT_AGGREGATE;
    9225           37 :                     n->objects = $3;
    9226           37 :                     n->behavior = $4;
    9227           37 :                     n->missing_ok = false;
    9228           37 :                     n->concurrent = false;
    9229           37 :                     $$ = (Node *) n;
    9230              :                 }
    9231              :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9232              :                 {
    9233           15 :                     DropStmt *n = makeNode(DropStmt);
    9234              : 
    9235           15 :                     n->removeType = OBJECT_AGGREGATE;
    9236           15 :                     n->objects = $5;
    9237           15 :                     n->behavior = $6;
    9238           15 :                     n->missing_ok = true;
    9239           15 :                     n->concurrent = false;
    9240           15 :                     $$ = (Node *) n;
    9241              :                 }
    9242              :         ;
    9243              : 
    9244              : RemoveOperStmt:
    9245              :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9246              :                 {
    9247          100 :                     DropStmt *n = makeNode(DropStmt);
    9248              : 
    9249          100 :                     n->removeType = OBJECT_OPERATOR;
    9250          100 :                     n->objects = $3;
    9251          100 :                     n->behavior = $4;
    9252          100 :                     n->missing_ok = false;
    9253          100 :                     n->concurrent = false;
    9254          100 :                     $$ = (Node *) n;
    9255              :                 }
    9256              :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9257              :                 {
    9258           15 :                     DropStmt *n = makeNode(DropStmt);
    9259              : 
    9260           15 :                     n->removeType = OBJECT_OPERATOR;
    9261           15 :                     n->objects = $5;
    9262           15 :                     n->behavior = $6;
    9263           15 :                     n->missing_ok = true;
    9264           15 :                     n->concurrent = false;
    9265           15 :                     $$ = (Node *) n;
    9266              :                 }
    9267              :         ;
    9268              : 
    9269              : oper_argtypes:
    9270              :             '(' Typename ')'
    9271              :                 {
    9272            6 :                    ereport(ERROR,
    9273              :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9274              :                             errmsg("missing argument"),
    9275              :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9276              :                             parser_errposition(@3)));
    9277              :                 }
    9278              :             | '(' Typename ',' Typename ')'
    9279         1124 :                     { $$ = list_make2($2, $4); }
    9280              :             | '(' NONE ',' Typename ')'                 /* left unary */
    9281           16 :                     { $$ = list_make2(NULL, $4); }
    9282              :             | '(' Typename ',' NONE ')'                 /* right unary */
    9283            6 :                     { $$ = list_make2($2, NULL); }
    9284              :         ;
    9285              : 
    9286              : any_operator:
    9287              :             all_Op
    9288        11483 :                     { $$ = list_make1(makeString($1)); }
    9289              :             | ColId '.' any_operator
    9290         8347 :                     { $$ = lcons(makeString($1), $3); }
    9291              :         ;
    9292              : 
    9293              : operator_with_argtypes_list:
    9294          115 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9295              :             | operator_with_argtypes_list ',' operator_with_argtypes
    9296            0 :                                                     { $$ = lappend($1, $3); }
    9297              :         ;
    9298              : 
    9299              : operator_with_argtypes:
    9300              :             any_operator oper_argtypes
    9301              :                 {
    9302         1146 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9303              : 
    9304         1146 :                     n->objname = $1;
    9305         1146 :                     n->objargs = $2;
    9306         1146 :                     $$ = n;
    9307              :                 }
    9308              :         ;
    9309              : 
    9310              : /*****************************************************************************
    9311              :  *
    9312              :  *      DO <anonymous code block> [ LANGUAGE language ]
    9313              :  *
    9314              :  * We use a DefElem list for future extensibility, and to allow flexibility
    9315              :  * in the clause order.
    9316              :  *
    9317              :  *****************************************************************************/
    9318              : 
    9319              : DoStmt: DO dostmt_opt_list
    9320              :                 {
    9321          581 :                     DoStmt *n = makeNode(DoStmt);
    9322              : 
    9323          581 :                     n->args = $2;
    9324          581 :                     $$ = (Node *) n;
    9325              :                 }
    9326              :         ;
    9327              : 
    9328              : dostmt_opt_list:
    9329          581 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9330           99 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9331              :         ;
    9332              : 
    9333              : dostmt_opt_item:
    9334              :             Sconst
    9335              :                 {
    9336          581 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9337              :                 }
    9338              :             | LANGUAGE NonReservedWord_or_Sconst
    9339              :                 {
    9340           99 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9341              :                 }
    9342              :         ;
    9343              : 
    9344              : /*****************************************************************************
    9345              :  *
    9346              :  *      CREATE CAST / DROP CAST
    9347              :  *
    9348              :  *****************************************************************************/
    9349              : 
    9350              : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9351              :                     WITH FUNCTION function_with_argtypes cast_context
    9352              :                 {
    9353           54 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9354              : 
    9355           54 :                     n->sourcetype = $4;
    9356           54 :                     n->targettype = $6;
    9357           54 :                     n->func = $10;
    9358           54 :                     n->context = (CoercionContext) $11;
    9359           54 :                     n->inout = false;
    9360           54 :                     $$ = (Node *) n;
    9361              :                 }
    9362              :             | CREATE CAST '(' Typename AS Typename ')'
    9363              :                     WITHOUT FUNCTION cast_context
    9364              :                 {
    9365           81 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9366              : 
    9367           81 :                     n->sourcetype = $4;
    9368           81 :                     n->targettype = $6;
    9369           81 :                     n->func = NULL;
    9370           81 :                     n->context = (CoercionContext) $10;
    9371           81 :                     n->inout = false;
    9372           81 :                     $$ = (Node *) n;
    9373              :                 }
    9374              :             | CREATE CAST '(' Typename AS Typename ')'
    9375              :                     WITH INOUT cast_context
    9376              :                 {
    9377            4 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9378              : 
    9379            4 :                     n->sourcetype = $4;
    9380            4 :                     n->targettype = $6;
    9381            4 :                     n->func = NULL;
    9382            4 :                     n->context = (CoercionContext) $10;
    9383            4 :                     n->inout = true;
    9384            4 :                     $$ = (Node *) n;
    9385              :                 }
    9386              :         ;
    9387              : 
    9388           18 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9389           29 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9390           92 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9391              :         ;
    9392              : 
    9393              : 
    9394              : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9395              :                 {
    9396           30 :                     DropStmt *n = makeNode(DropStmt);
    9397              : 
    9398           30 :                     n->removeType = OBJECT_CAST;
    9399           30 :                     n->objects = list_make1(list_make2($5, $7));
    9400           30 :                     n->behavior = $9;
    9401           30 :                     n->missing_ok = $3;
    9402           30 :                     n->concurrent = false;
    9403           30 :                     $$ = (Node *) n;
    9404              :                 }
    9405              :         ;
    9406              : 
    9407           18 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9408           19 :         | /*EMPTY*/                             { $$ = false; }
    9409              :         ;
    9410              : 
    9411              : 
    9412              : /*****************************************************************************
    9413              :  *
    9414              :  *      CREATE TRANSFORM / DROP TRANSFORM
    9415              :  *
    9416              :  *****************************************************************************/
    9417              : 
    9418              : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9419              :                 {
    9420           25 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9421              : 
    9422           25 :                     n->replace = $2;
    9423           25 :                     n->type_name = $5;
    9424           25 :                     n->lang = $7;
    9425           25 :                     n->fromsql = linitial($9);
    9426           25 :                     n->tosql = lsecond($9);
    9427           25 :                     $$ = (Node *) n;
    9428              :                 }
    9429              :         ;
    9430              : 
    9431              : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9432              :                 {
    9433           22 :                     $$ = list_make2($5, $11);
    9434              :                 }
    9435              :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9436              :                 {
    9437            0 :                     $$ = list_make2($11, $5);
    9438              :                 }
    9439              :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9440              :                 {
    9441            2 :                     $$ = list_make2($5, NULL);
    9442              :                 }
    9443              :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9444              :                 {
    9445            1 :                     $$ = list_make2(NULL, $5);
    9446              :                 }
    9447              :         ;
    9448              : 
    9449              : 
    9450              : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9451              :                 {
    9452            7 :                     DropStmt *n = makeNode(DropStmt);
    9453              : 
    9454            7 :                     n->removeType = OBJECT_TRANSFORM;
    9455            7 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9456            7 :                     n->behavior = $8;
    9457            7 :                     n->missing_ok = $3;
    9458            7 :                     $$ = (Node *) n;
    9459              :                 }
    9460              :         ;
    9461              : 
    9462              : 
    9463              : /*****************************************************************************
    9464              :  *
    9465              :  *      QUERY:
    9466              :  *
    9467              :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9468              :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9469              :  *****************************************************************************/
    9470              : 
    9471              : ReindexStmt:
    9472              :             REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
    9473              :                 {
    9474          476 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9475              : 
    9476          476 :                     n->kind = $3;
    9477          476 :                     n->relation = $5;
    9478          476 :                     n->name = NULL;
    9479          476 :                     n->params = $2;
    9480          476 :                     if ($4)
    9481          274 :                         n->params = lappend(n->params,
    9482          274 :                                             makeDefElem("concurrently", NULL, @4));
    9483          476 :                     $$ = (Node *) n;
    9484              :                 }
    9485              :             | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
    9486              :                 {
    9487           57 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9488              : 
    9489           57 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9490           57 :                     n->relation = NULL;
    9491           57 :                     n->name = $5;
    9492           57 :                     n->params = $2;
    9493           57 :                     if ($4)
    9494           20 :                         n->params = lappend(n->params,
    9495           20 :                                             makeDefElem("concurrently", NULL, @4));
    9496           57 :                     $$ = (Node *) n;
    9497              :                 }
    9498              :             | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
    9499              :                 {
    9500           32 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9501              : 
    9502           32 :                     n->kind = $3;
    9503           32 :                     n->relation = NULL;
    9504           32 :                     n->name = $5;
    9505           32 :                     n->params = $2;
    9506           32 :                     if ($4)
    9507            5 :                         n->params = lappend(n->params,
    9508            5 :                                             makeDefElem("concurrently", NULL, @4));
    9509           32 :                     $$ = (Node *) n;
    9510              :                 }
    9511              :         ;
    9512              : reindex_target_relation:
    9513          212 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9514          264 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9515              :         ;
    9516              : reindex_target_all:
    9517           17 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9518           15 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9519              :         ;
    9520              : 
    9521              : /*****************************************************************************
    9522              :  *
    9523              :  * ALTER TABLESPACE
    9524              :  *
    9525              :  *****************************************************************************/
    9526              : 
    9527              : AlterTblSpcStmt:
    9528              :             ALTER TABLESPACE name SET reloptions
    9529              :                 {
    9530              :                     AlterTableSpaceOptionsStmt *n =
    9531            6 :                         makeNode(AlterTableSpaceOptionsStmt);
    9532              : 
    9533            6 :                     n->tablespacename = $3;
    9534            6 :                     n->options = $5;
    9535            6 :                     n->isReset = false;
    9536            6 :                     $$ = (Node *) n;
    9537              :                 }
    9538              :             | ALTER TABLESPACE name RESET reloptions
    9539              :                 {
    9540              :                     AlterTableSpaceOptionsStmt *n =
    9541            6 :                         makeNode(AlterTableSpaceOptionsStmt);
    9542              : 
    9543            6 :                     n->tablespacename = $3;
    9544            6 :                     n->options = $5;
    9545            6 :                     n->isReset = true;
    9546            6 :                     $$ = (Node *) n;
    9547              :                 }
    9548              :         ;
    9549              : 
    9550              : /*****************************************************************************
    9551              :  *
    9552              :  * ALTER THING name RENAME TO newname
    9553              :  *
    9554              :  *****************************************************************************/
    9555              : 
    9556              : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9557              :                 {
    9558           21 :                     RenameStmt *n = makeNode(RenameStmt);
    9559              : 
    9560           21 :                     n->renameType = OBJECT_AGGREGATE;
    9561           21 :                     n->object = (Node *) $3;
    9562           21 :                     n->newname = $6;
    9563           21 :                     n->missing_ok = false;
    9564           21 :                     $$ = (Node *) n;
    9565              :                 }
    9566              :             | ALTER COLLATION any_name RENAME TO name
    9567              :                 {
    9568            9 :                     RenameStmt *n = makeNode(RenameStmt);
    9569              : 
    9570            9 :                     n->renameType = OBJECT_COLLATION;
    9571            9 :                     n->object = (Node *) $3;
    9572            9 :                     n->newname = $6;
    9573            9 :                     n->missing_ok = false;
    9574            9 :                     $$ = (Node *) n;
    9575              :                 }
    9576              :             | ALTER CONVERSION_P any_name RENAME TO name
    9577              :                 {
    9578           12 :                     RenameStmt *n = makeNode(RenameStmt);
    9579              : 
    9580           12 :                     n->renameType = OBJECT_CONVERSION;
    9581           12 :                     n->object = (Node *) $3;
    9582           12 :                     n->newname = $6;
    9583           12 :                     n->missing_ok = false;
    9584           12 :                     $$ = (Node *) n;
    9585              :                 }
    9586              :             | ALTER DATABASE name RENAME TO name
    9587              :                 {
    9588            7 :                     RenameStmt *n = makeNode(RenameStmt);
    9589              : 
    9590            7 :                     n->renameType = OBJECT_DATABASE;
    9591            7 :                     n->subname = $3;
    9592            7 :                     n->newname = $6;
    9593            7 :                     n->missing_ok = false;
    9594            7 :                     $$ = (Node *) n;
    9595              :                 }
    9596              :             | ALTER DOMAIN_P any_name RENAME TO name
    9597              :                 {
    9598            3 :                     RenameStmt *n = makeNode(RenameStmt);
    9599              : 
    9600            3 :                     n->renameType = OBJECT_DOMAIN;
    9601            3 :                     n->object = (Node *) $3;
    9602            3 :                     n->newname = $6;
    9603            3 :                     n->missing_ok = false;
    9604            3 :                     $$ = (Node *) n;
    9605              :                 }
    9606              :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9607              :                 {
    9608            3 :                     RenameStmt *n = makeNode(RenameStmt);
    9609              : 
    9610            3 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9611            3 :                     n->object = (Node *) $3;
    9612            3 :                     n->subname = $6;
    9613            3 :                     n->newname = $8;
    9614            3 :                     $$ = (Node *) n;
    9615              :                 }
    9616              :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9617              :                 {
    9618           12 :                     RenameStmt *n = makeNode(RenameStmt);
    9619              : 
    9620           12 :                     n->renameType = OBJECT_FDW;
    9621           12 :                     n->object = (Node *) makeString($5);
    9622           12 :                     n->newname = $8;
    9623           12 :                     n->missing_ok = false;
    9624           12 :                     $$ = (Node *) n;
    9625              :                 }
    9626              :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9627              :                 {
    9628           12 :                     RenameStmt *n = makeNode(RenameStmt);
    9629              : 
    9630           12 :                     n->renameType = OBJECT_FUNCTION;
    9631           12 :                     n->object = (Node *) $3;
    9632           12 :                     n->newname = $6;
    9633           12 :                     n->missing_ok = false;
    9634           12 :                     $$ = (Node *) n;
    9635              :                 }
    9636              :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9637              :                 {
    9638            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9639              : 
    9640            0 :                     n->renameType = OBJECT_ROLE;
    9641            0 :                     n->subname = $3;
    9642            0 :                     n->newname = $6;
    9643            0 :                     n->missing_ok = false;
    9644            0 :                     $$ = (Node *) n;
    9645              :                 }
    9646              :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9647              :                 {
    9648            9 :                     RenameStmt *n = makeNode(RenameStmt);
    9649              : 
    9650            9 :                     n->renameType = OBJECT_LANGUAGE;
    9651            9 :                     n->object = (Node *) makeString($4);
    9652            9 :                     n->newname = $7;
    9653            9 :                     n->missing_ok = false;
    9654            9 :                     $$ = (Node *) n;
    9655              :                 }
    9656              :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9657              :                 {
    9658           12 :                     RenameStmt *n = makeNode(RenameStmt);
    9659              : 
    9660           12 :                     n->renameType = OBJECT_OPCLASS;
    9661           12 :                     n->object = (Node *) lcons(makeString($6), $4);
    9662           12 :                     n->newname = $9;
    9663           12 :                     n->missing_ok = false;
    9664           12 :                     $$ = (Node *) n;
    9665              :                 }
    9666              :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9667              :                 {
    9668           12 :                     RenameStmt *n = makeNode(RenameStmt);
    9669              : 
    9670           12 :                     n->renameType = OBJECT_OPFAMILY;
    9671           12 :                     n->object = (Node *) lcons(makeString($6), $4);
    9672           12 :                     n->newname = $9;
    9673           12 :                     n->missing_ok = false;
    9674           12 :                     $$ = (Node *) n;
    9675              :                 }
    9676              :             | ALTER POLICY name ON qualified_name RENAME TO name
    9677              :                 {
    9678            9 :                     RenameStmt *n = makeNode(RenameStmt);
    9679              : 
    9680            9 :                     n->renameType = OBJECT_POLICY;
    9681            9 :                     n->relation = $5;
    9682            9 :                     n->subname = $3;
    9683            9 :                     n->newname = $8;
    9684            9 :                     n->missing_ok = false;
    9685            9 :                     $$ = (Node *) n;
    9686              :                 }
    9687              :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9688              :                 {
    9689            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9690              : 
    9691            0 :                     n->renameType = OBJECT_POLICY;
    9692            0 :                     n->relation = $7;
    9693            0 :                     n->subname = $5;
    9694            0 :                     n->newname = $10;
    9695            0 :                     n->missing_ok = true;
    9696            0 :                     $$ = (Node *) n;
    9697              :                 }
    9698              :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9699              :                 {
    9700            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9701              : 
    9702            0 :                     n->renameType = OBJECT_PROCEDURE;
    9703            0 :                     n->object = (Node *) $3;
    9704            0 :                     n->newname = $6;
    9705            0 :                     n->missing_ok = false;
    9706            0 :                     $$ = (Node *) n;
    9707              :                 }
    9708              :             | ALTER PUBLICATION name RENAME TO name
    9709              :                 {
    9710           21 :                     RenameStmt *n = makeNode(RenameStmt);
    9711              : 
    9712           21 :                     n->renameType = OBJECT_PUBLICATION;
    9713           21 :                     n->object = (Node *) makeString($3);
    9714           21 :                     n->newname = $6;
    9715           21 :                     n->missing_ok = false;
    9716           21 :                     $$ = (Node *) n;
    9717              :                 }
    9718              :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9719              :                 {
    9720           12 :                     RenameStmt *n = makeNode(RenameStmt);
    9721              : 
    9722           12 :                     n->renameType = OBJECT_ROUTINE;
    9723           12 :                     n->object = (Node *) $3;
    9724           12 :                     n->newname = $6;
    9725           12 :                     n->missing_ok = false;
    9726           12 :                     $$ = (Node *) n;
    9727              :                 }
    9728              :             | ALTER SCHEMA name RENAME TO name
    9729              :                 {
    9730           10 :                     RenameStmt *n = makeNode(RenameStmt);
    9731              : 
    9732           10 :                     n->renameType = OBJECT_SCHEMA;
    9733           10 :                     n->subname = $3;
    9734           10 :                     n->newname = $6;
    9735           10 :                     n->missing_ok = false;
    9736           10 :                     $$ = (Node *) n;
    9737              :                 }
    9738              :             | ALTER SERVER name RENAME TO name
    9739              :                 {
    9740           12 :                     RenameStmt *n = makeNode(RenameStmt);
    9741              : 
    9742           12 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9743           12 :                     n->object = (Node *) makeString($3);
    9744           12 :                     n->newname = $6;
    9745           12 :                     n->missing_ok = false;
    9746           12 :                     $$ = (Node *) n;
    9747              :                 }
    9748              :             | ALTER SUBSCRIPTION name RENAME TO name
    9749              :                 {
    9750           19 :                     RenameStmt *n = makeNode(RenameStmt);
    9751              : 
    9752           19 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9753           19 :                     n->object = (Node *) makeString($3);
    9754           19 :                     n->newname = $6;
    9755           19 :                     n->missing_ok = false;
    9756           19 :                     $$ = (Node *) n;
    9757              :                 }
    9758              :             | ALTER TABLE relation_expr RENAME TO name
    9759              :                 {
    9760          147 :                     RenameStmt *n = makeNode(RenameStmt);
    9761              : 
    9762          147 :                     n->renameType = OBJECT_TABLE;
    9763          147 :                     n->relation = $3;
    9764          147 :                     n->subname = NULL;
    9765          147 :                     n->newname = $6;
    9766          147 :                     n->missing_ok = false;
    9767          147 :                     $$ = (Node *) n;
    9768              :                 }
    9769              :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9770              :                 {
    9771            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9772              : 
    9773            0 :                     n->renameType = OBJECT_TABLE;
    9774            0 :                     n->relation = $5;
    9775            0 :                     n->subname = NULL;
    9776            0 :                     n->newname = $8;
    9777            0 :                     n->missing_ok = true;
    9778            0 :                     $$ = (Node *) n;
    9779              :                 }
    9780              :             | ALTER SEQUENCE qualified_name RENAME TO name
    9781              :                 {
    9782            1 :                     RenameStmt *n = makeNode(RenameStmt);
    9783              : 
    9784            1 :                     n->renameType = OBJECT_SEQUENCE;
    9785            1 :                     n->relation = $3;
    9786            1 :                     n->subname = NULL;
    9787            1 :                     n->newname = $6;
    9788            1 :                     n->missing_ok = false;
    9789            1 :                     $$ = (Node *) n;
    9790              :                 }
    9791              :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9792              :                 {
    9793            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9794              : 
    9795            0 :                     n->renameType = OBJECT_SEQUENCE;
    9796            0 :                     n->relation = $5;
    9797            0 :                     n->subname = NULL;
    9798            0 :                     n->newname = $8;
    9799            0 :                     n->missing_ok = true;
    9800            0 :                     $$ = (Node *) n;
    9801              :                 }
    9802              :             | ALTER VIEW qualified_name RENAME TO name
    9803              :                 {
    9804            3 :                     RenameStmt *n = makeNode(RenameStmt);
    9805              : 
    9806            3 :                     n->renameType = OBJECT_VIEW;
    9807            3 :                     n->relation = $3;
    9808            3 :                     n->subname = NULL;
    9809            3 :                     n->newname = $6;
    9810            3 :                     n->missing_ok = false;
    9811            3 :                     $$ = (Node *) n;
    9812              :                 }
    9813              :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9814              :                 {
    9815            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9816              : 
    9817            0 :                     n->renameType = OBJECT_VIEW;
    9818            0 :                     n->relation = $5;
    9819            0 :                     n->subname = NULL;
    9820            0 :                     n->newname = $8;
    9821            0 :                     n->missing_ok = true;
    9822            0 :                     $$ = (Node *) n;
    9823              :                 }
    9824              :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9825              :                 {
    9826            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9827              : 
    9828            0 :                     n->renameType = OBJECT_MATVIEW;
    9829            0 :                     n->relation = $4;
    9830            0 :                     n->subname = NULL;
    9831            0 :                     n->newname = $7;
    9832            0 :                     n->missing_ok = false;
    9833            0 :                     $$ = (Node *) n;
    9834              :                 }
    9835              :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9836              :                 {
    9837            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9838              : 
    9839            0 :                     n->renameType = OBJECT_MATVIEW;
    9840            0 :                     n->relation = $6;
    9841            0 :                     n->subname = NULL;
    9842            0 :                     n->newname = $9;
    9843            0 :                     n->missing_ok = true;
    9844            0 :                     $$ = (Node *) n;
    9845              :                 }
    9846              :             | ALTER INDEX qualified_name RENAME TO name
    9847              :                 {
    9848           96 :                     RenameStmt *n = makeNode(RenameStmt);
    9849              : 
    9850           96 :                     n->renameType = OBJECT_INDEX;
    9851           96 :                     n->relation = $3;
    9852           96 :                     n->subname = NULL;
    9853           96 :                     n->newname = $6;
    9854           96 :                     n->missing_ok = false;
    9855           96 :                     $$ = (Node *) n;
    9856              :                 }
    9857              :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9858              :                 {
    9859            6 :                     RenameStmt *n = makeNode(RenameStmt);
    9860              : 
    9861            6 :                     n->renameType = OBJECT_INDEX;
    9862            6 :                     n->relation = $5;
    9863            6 :                     n->subname = NULL;
    9864            6 :                     n->newname = $8;
    9865            6 :                     n->missing_ok = true;
    9866            6 :                     $$ = (Node *) n;
    9867              :                 }
    9868              :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9869              :                 {
    9870            3 :                     RenameStmt *n = makeNode(RenameStmt);
    9871              : 
    9872            3 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9873            3 :                     n->relation = $4;
    9874            3 :                     n->subname = NULL;
    9875            3 :                     n->newname = $7;
    9876            3 :                     n->missing_ok = false;
    9877            3 :                     $$ = (Node *) n;
    9878              :                 }
    9879              :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9880              :                 {
    9881            3 :                     RenameStmt *n = makeNode(RenameStmt);
    9882              : 
    9883            3 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9884            3 :                     n->relation = $6;
    9885            3 :                     n->subname = NULL;
    9886            3 :                     n->newname = $9;
    9887            3 :                     n->missing_ok = true;
    9888            3 :                     $$ = (Node *) n;
    9889              :                 }
    9890              :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9891              :                 {
    9892          119 :                     RenameStmt *n = makeNode(RenameStmt);
    9893              : 
    9894          119 :                     n->renameType = OBJECT_COLUMN;
    9895          119 :                     n->relationType = OBJECT_TABLE;
    9896          119 :                     n->relation = $3;
    9897          119 :                     n->subname = $6;
    9898          119 :                     n->newname = $8;
    9899          119 :                     n->missing_ok = false;
    9900          119 :                     $$ = (Node *) n;
    9901              :                 }
    9902              :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9903              :                 {
    9904           12 :                     RenameStmt *n = makeNode(RenameStmt);
    9905              : 
    9906           12 :                     n->renameType = OBJECT_COLUMN;
    9907           12 :                     n->relationType = OBJECT_TABLE;
    9908           12 :                     n->relation = $5;
    9909           12 :                     n->subname = $8;
    9910           12 :                     n->newname = $10;
    9911           12 :                     n->missing_ok = true;
    9912           12 :                     $$ = (Node *) n;
    9913              :                 }
    9914              :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9915              :                 {
    9916            9 :                     RenameStmt *n = makeNode(RenameStmt);
    9917              : 
    9918            9 :                     n->renameType = OBJECT_COLUMN;
    9919            9 :                     n->relationType = OBJECT_VIEW;
    9920            9 :                     n->relation = $3;
    9921            9 :                     n->subname = $6;
    9922            9 :                     n->newname = $8;
    9923            9 :                     n->missing_ok = false;
    9924            9 :                     $$ = (Node *) n;
    9925              :                 }
    9926              :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9927              :                 {
    9928            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9929              : 
    9930            0 :                     n->renameType = OBJECT_COLUMN;
    9931            0 :                     n->relationType = OBJECT_VIEW;
    9932            0 :                     n->relation = $5;
    9933            0 :                     n->subname = $8;
    9934            0 :                     n->newname = $10;
    9935            0 :                     n->missing_ok = true;
    9936            0 :                     $$ = (Node *) n;
    9937              :                 }
    9938              :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9939              :                 {
    9940            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9941              : 
    9942            0 :                     n->renameType = OBJECT_COLUMN;
    9943            0 :                     n->relationType = OBJECT_MATVIEW;
    9944            0 :                     n->relation = $4;
    9945            0 :                     n->subname = $7;
    9946            0 :                     n->newname = $9;
    9947            0 :                     n->missing_ok = false;
    9948            0 :                     $$ = (Node *) n;
    9949              :                 }
    9950              :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9951              :                 {
    9952            0 :                     RenameStmt *n = makeNode(RenameStmt);
    9953              : 
    9954            0 :                     n->renameType = OBJECT_COLUMN;
    9955            0 :                     n->relationType = OBJECT_MATVIEW;
    9956            0 :                     n->relation = $6;
    9957            0 :                     n->subname = $9;
    9958            0 :                     n->newname = $11;
    9959            0 :                     n->missing_ok = true;
    9960            0 :                     $$ = (Node *) n;
    9961              :                 }
    9962              :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9963              :                 {
    9964           36 :                     RenameStmt *n = makeNode(RenameStmt);
    9965              : 
    9966           36 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9967           36 :                     n->relation = $3;
    9968           36 :                     n->subname = $6;
    9969           36 :                     n->newname = $8;
    9970           36 :                     n->missing_ok = false;
    9971           36 :                     $$ = (Node *) n;
    9972              :                 }
    9973              :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9974              :                 {
    9975            3 :                     RenameStmt *n = makeNode(RenameStmt);
    9976              : 
    9977            3 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9978            3 :                     n->relation = $5;
    9979            3 :                     n->subname = $8;
    9980            3 :                     n->newname = $10;
    9981            3 :                     n->missing_ok = true;
    9982            3 :                     $$ = (Node *) n;
    9983              :                 }
    9984              :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9985              :                 {
    9986            3 :                     RenameStmt *n = makeNode(RenameStmt);
    9987              : 
    9988            3 :                     n->renameType = OBJECT_COLUMN;
    9989            3 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9990            3 :                     n->relation = $4;
    9991            3 :                     n->subname = $7;
    9992            3 :                     n->newname = $9;
    9993            3 :                     n->missing_ok = false;
    9994            3 :                     $$ = (Node *) n;
    9995              :                 }
    9996              :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9997              :                 {
    9998            3 :                     RenameStmt *n = makeNode(RenameStmt);
    9999              : 
   10000            3 :                     n->renameType = OBJECT_COLUMN;
   10001            3 :                     n->relationType = OBJECT_FOREIGN_TABLE;
   10002            3 :                     n->relation = $6;
   10003            3 :                     n->subname = $9;
   10004            3 :                     n->newname = $11;
   10005            3 :                     n->missing_ok = true;
   10006            3 :                     $$ = (Node *) n;
   10007              :                 }
   10008              :             | ALTER RULE name ON qualified_name RENAME TO name
   10009              :                 {
   10010           17 :                     RenameStmt *n = makeNode(RenameStmt);
   10011              : 
   10012           17 :                     n->renameType = OBJECT_RULE;
   10013           17 :                     n->relation = $5;
   10014           17 :                     n->subname = $3;
   10015           17 :                     n->newname = $8;
   10016           17 :                     n->missing_ok = false;
   10017           17 :                     $$ = (Node *) n;
   10018              :                 }
   10019              :             | ALTER TRIGGER name ON qualified_name RENAME TO name
   10020              :                 {
   10021           20 :                     RenameStmt *n = makeNode(RenameStmt);
   10022              : 
   10023           20 :                     n->renameType = OBJECT_TRIGGER;
   10024           20 :                     n->relation = $5;
   10025           20 :                     n->subname = $3;
   10026           20 :                     n->newname = $8;
   10027           20 :                     n->missing_ok = false;
   10028           20 :                     $$ = (Node *) n;
   10029              :                 }
   10030              :             | ALTER EVENT TRIGGER name RENAME TO name
   10031              :                 {
   10032            6 :                     RenameStmt *n = makeNode(RenameStmt);
   10033              : 
   10034            6 :                     n->renameType = OBJECT_EVENT_TRIGGER;
   10035            6 :                     n->object = (Node *) makeString($4);
   10036            6 :                     n->newname = $7;
   10037            6 :                     $$ = (Node *) n;
   10038              :                 }
   10039              :             | ALTER ROLE RoleId RENAME TO RoleId
   10040              :                 {
   10041           15 :                     RenameStmt *n = makeNode(RenameStmt);
   10042              : 
   10043           15 :                     n->renameType = OBJECT_ROLE;
   10044           15 :                     n->subname = $3;
   10045           15 :                     n->newname = $6;
   10046           15 :                     n->missing_ok = false;
   10047           15 :                     $$ = (Node *) n;
   10048              :                 }
   10049              :             | ALTER USER RoleId RENAME TO RoleId
   10050              :                 {
   10051            0 :                     RenameStmt *n = makeNode(RenameStmt);
   10052              : 
   10053            0 :                     n->renameType = OBJECT_ROLE;
   10054            0 :                     n->subname = $3;
   10055            0 :                     n->newname = $6;
   10056            0 :                     n->missing_ok = false;
   10057            0 :                     $$ = (Node *) n;
   10058              :                 }
   10059              :             | ALTER TABLESPACE name RENAME TO name
   10060              :                 {
   10061            6 :                     RenameStmt *n = makeNode(RenameStmt);
   10062              : 
   10063            6 :                     n->renameType = OBJECT_TABLESPACE;
   10064            6 :                     n->subname = $3;
   10065            6 :                     n->newname = $6;
   10066            6 :                     n->missing_ok = false;
   10067            6 :                     $$ = (Node *) n;
   10068              :                 }
   10069              :             | ALTER STATISTICS any_name RENAME TO name
   10070              :                 {
   10071           15 :                     RenameStmt *n = makeNode(RenameStmt);
   10072              : 
   10073           15 :                     n->renameType = OBJECT_STATISTIC_EXT;
   10074           15 :                     n->object = (Node *) $3;
   10075           15 :                     n->newname = $6;
   10076           15 :                     n->missing_ok = false;
   10077           15 :                     $$ = (Node *) n;
   10078              :                 }
   10079              :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
   10080              :                 {
   10081            6 :                     RenameStmt *n = makeNode(RenameStmt);
   10082              : 
   10083            6 :                     n->renameType = OBJECT_TSPARSER;
   10084            6 :                     n->object = (Node *) $5;
   10085            6 :                     n->newname = $8;
   10086            6 :                     n->missing_ok = false;
   10087            6 :                     $$ = (Node *) n;
   10088              :                 }
   10089              :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
   10090              :                 {
   10091           12 :                     RenameStmt *n = makeNode(RenameStmt);
   10092              : 
   10093           12 :                     n->renameType = OBJECT_TSDICTIONARY;
   10094           12 :                     n->object = (Node *) $5;
   10095           12 :                     n->newname = $8;
   10096           12 :                     n->missing_ok = false;
   10097           12 :                     $$ = (Node *) n;
   10098              :                 }
   10099              :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
   10100              :                 {
   10101            6 :                     RenameStmt *n = makeNode(RenameStmt);
   10102              : 
   10103            6 :                     n->renameType = OBJECT_TSTEMPLATE;
   10104            6 :                     n->object = (Node *) $5;
   10105            6 :                     n->newname = $8;
   10106            6 :                     n->missing_ok = false;
   10107            6 :                     $$ = (Node *) n;
   10108              :                 }
   10109              :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
   10110              :                 {
   10111           12 :                     RenameStmt *n = makeNode(RenameStmt);
   10112              : 
   10113           12 :                     n->renameType = OBJECT_TSCONFIGURATION;
   10114           12 :                     n->object = (Node *) $5;
   10115           12 :                     n->newname = $8;
   10116           12 :                     n->missing_ok = false;
   10117           12 :                     $$ = (Node *) n;
   10118              :                 }
   10119              :             | ALTER TYPE_P any_name RENAME TO name
   10120              :                 {
   10121           13 :                     RenameStmt *n = makeNode(RenameStmt);
   10122              : 
   10123           13 :                     n->renameType = OBJECT_TYPE;
   10124           13 :                     n->object = (Node *) $3;
   10125           13 :                     n->newname = $6;
   10126           13 :                     n->missing_ok = false;
   10127           13 :                     $$ = (Node *) n;
   10128              :                 }
   10129              :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
   10130              :                 {
   10131           12 :                     RenameStmt *n = makeNode(RenameStmt);
   10132              : 
   10133           12 :                     n->renameType = OBJECT_ATTRIBUTE;
   10134           12 :                     n->relationType = OBJECT_TYPE;
   10135           12 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
   10136           12 :                     n->subname = $6;
   10137           12 :                     n->newname = $8;
   10138           12 :                     n->behavior = $9;
   10139           12 :                     n->missing_ok = false;
   10140           12 :                     $$ = (Node *) n;
   10141              :                 }
   10142              :         ;
   10143              : 
   10144              : opt_column: COLUMN
   10145              :             | /*EMPTY*/
   10146              :         ;
   10147              : 
   10148           92 : opt_set_data: SET DATA_P                            { $$ = 1; }
   10149          514 :             | /*EMPTY*/                             { $$ = 0; }
   10150              :         ;
   10151              : 
   10152              : /*****************************************************************************
   10153              :  *
   10154              :  * ALTER THING name DEPENDS ON EXTENSION name
   10155              :  *
   10156              :  *****************************************************************************/
   10157              : 
   10158              : AlterObjectDependsStmt:
   10159              :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10160              :                 {
   10161            6 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10162              : 
   10163            6 :                     n->objectType = OBJECT_FUNCTION;
   10164            6 :                     n->object = (Node *) $3;
   10165            6 :                     n->extname = makeString($8);
   10166            6 :                     n->remove = $4;
   10167            6 :                     $$ = (Node *) n;
   10168              :                 }
   10169              :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10170              :                 {
   10171            0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10172              : 
   10173            0 :                     n->objectType = OBJECT_PROCEDURE;
   10174            0 :                     n->object = (Node *) $3;
   10175            0 :                     n->extname = makeString($8);
   10176            0 :                     n->remove = $4;
   10177            0 :                     $$ = (Node *) n;
   10178              :                 }
   10179              :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10180              :                 {
   10181            0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10182              : 
   10183            0 :                     n->objectType = OBJECT_ROUTINE;
   10184            0 :                     n->object = (Node *) $3;
   10185            0 :                     n->extname = makeString($8);
   10186            0 :                     n->remove = $4;
   10187            0 :                     $$ = (Node *) n;
   10188              :                 }
   10189              :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10190              :                 {
   10191            5 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10192              : 
   10193            5 :                     n->objectType = OBJECT_TRIGGER;
   10194            5 :                     n->relation = $5;
   10195            5 :                     n->object = (Node *) list_make1(makeString($3));
   10196            5 :                     n->extname = makeString($10);
   10197            5 :                     n->remove = $6;
   10198            5 :                     $$ = (Node *) n;
   10199              :                 }
   10200              :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10201              :                 {
   10202            5 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10203              : 
   10204            5 :                     n->objectType = OBJECT_MATVIEW;
   10205            5 :                     n->relation = $4;
   10206            5 :                     n->extname = makeString($9);
   10207            5 :                     n->remove = $5;
   10208            5 :                     $$ = (Node *) n;
   10209              :                 }
   10210              :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10211              :                 {
   10212            7 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10213              : 
   10214            7 :                     n->objectType = OBJECT_INDEX;
   10215            7 :                     n->relation = $3;
   10216            7 :                     n->extname = makeString($8);
   10217            7 :                     n->remove = $4;
   10218            7 :                     $$ = (Node *) n;
   10219              :                 }
   10220              :         ;
   10221              : 
   10222            4 : opt_no:     NO              { $$ = true; }
   10223           19 :             | /* EMPTY */   { $$ = false;   }
   10224              :         ;
   10225              : 
   10226              : /*****************************************************************************
   10227              :  *
   10228              :  * ALTER THING name SET SCHEMA name
   10229              :  *
   10230              :  *****************************************************************************/
   10231              : 
   10232              : AlterObjectSchemaStmt:
   10233              :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10234              :                 {
   10235           12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10236              : 
   10237           12 :                     n->objectType = OBJECT_AGGREGATE;
   10238           12 :                     n->object = (Node *) $3;
   10239           12 :                     n->newschema = $6;
   10240           12 :                     n->missing_ok = false;
   10241           12 :                     $$ = (Node *) n;
   10242              :                 }
   10243              :             | ALTER COLLATION any_name SET SCHEMA name
   10244              :                 {
   10245            3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10246              : 
   10247            3 :                     n->objectType = OBJECT_COLLATION;
   10248            3 :                     n->object = (Node *) $3;
   10249            3 :                     n->newschema = $6;
   10250            3 :                     n->missing_ok = false;
   10251            3 :                     $$ = (Node *) n;
   10252              :                 }
   10253              :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10254              :                 {
   10255           12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10256              : 
   10257           12 :                     n->objectType = OBJECT_CONVERSION;
   10258           12 :                     n->object = (Node *) $3;
   10259           12 :                     n->newschema = $6;
   10260           12 :                     n->missing_ok = false;
   10261           12 :                     $$ = (Node *) n;
   10262              :                 }
   10263              :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10264              :                 {
   10265            3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10266              : 
   10267            3 :                     n->objectType = OBJECT_DOMAIN;
   10268            3 :                     n->object = (Node *) $3;
   10269            3 :                     n->newschema = $6;
   10270            3 :                     n->missing_ok = false;
   10271            3 :                     $$ = (Node *) n;
   10272              :                 }
   10273              :             | ALTER EXTENSION name SET SCHEMA name
   10274              :                 {
   10275            6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10276              : 
   10277            6 :                     n->objectType = OBJECT_EXTENSION;
   10278            6 :                     n->object = (Node *) makeString($3);
   10279            6 :                     n->newschema = $6;
   10280            6 :                     n->missing_ok = false;
   10281            6 :                     $$ = (Node *) n;
   10282              :                 }
   10283              :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10284              :                 {
   10285           21 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10286              : 
   10287           21 :                     n->objectType = OBJECT_FUNCTION;
   10288           21 :                     n->object = (Node *) $3;
   10289           21 :                     n->newschema = $6;
   10290           21 :                     n->missing_ok = false;
   10291           21 :                     $$ = (Node *) n;
   10292              :                 }
   10293              :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10294              :                 {
   10295            9 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10296              : 
   10297            9 :                     n->objectType = OBJECT_OPERATOR;
   10298            9 :                     n->object = (Node *) $3;
   10299            9 :                     n->newschema = $6;
   10300            9 :                     n->missing_ok = false;
   10301            9 :                     $$ = (Node *) n;
   10302              :                 }
   10303              :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10304              :                 {
   10305           12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10306              : 
   10307           12 :                     n->objectType = OBJECT_OPCLASS;
   10308           12 :                     n->object = (Node *) lcons(makeString($6), $4);
   10309           12 :                     n->newschema = $9;
   10310           12 :                     n->missing_ok = false;
   10311           12 :                     $$ = (Node *) n;
   10312              :                 }
   10313              :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10314              :                 {
   10315           12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10316              : 
   10317           12 :                     n->objectType = OBJECT_OPFAMILY;
   10318           12 :                     n->object = (Node *) lcons(makeString($6), $4);
   10319           12 :                     n->newschema = $9;
   10320           12 :                     n->missing_ok = false;
   10321           12 :                     $$ = (Node *) n;
   10322              :                 }
   10323              :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10324              :                 {
   10325            0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10326              : 
   10327            0 :                     n->objectType = OBJECT_PROCEDURE;
   10328            0 :                     n->object = (Node *) $3;
   10329            0 :                     n->newschema = $6;
   10330            0 :                     n->missing_ok = false;
   10331            0 :                     $$ = (Node *) n;
   10332              :                 }
   10333              :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10334              :                 {
   10335            0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10336              : 
   10337            0 :                     n->objectType = OBJECT_ROUTINE;
   10338            0 :                     n->object = (Node *) $3;
   10339            0 :                     n->newschema = $6;
   10340            0 :                     n->missing_ok = false;
   10341            0 :                     $$ = (Node *) n;
   10342              :                 }
   10343              :             | ALTER TABLE relation_expr SET SCHEMA name
   10344              :                 {
   10345           33 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10346              : 
   10347           33 :                     n->objectType = OBJECT_TABLE;
   10348           33 :                     n->relation = $3;
   10349           33 :                     n->newschema = $6;
   10350           33 :                     n->missing_ok = false;
   10351           33 :                     $$ = (Node *) n;
   10352              :                 }
   10353              :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10354              :                 {
   10355            6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10356              : 
   10357            6 :                     n->objectType = OBJECT_TABLE;
   10358            6 :                     n->relation = $5;
   10359            6 :                     n->newschema = $8;
   10360            6 :                     n->missing_ok = true;
   10361            6 :                     $$ = (Node *) n;
   10362              :                 }
   10363              :             | ALTER STATISTICS any_name SET SCHEMA name
   10364              :                 {
   10365            9 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10366              : 
   10367            9 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10368            9 :                     n->object = (Node *) $3;
   10369            9 :                     n->newschema = $6;
   10370            9 :                     n->missing_ok = false;
   10371            9 :                     $$ = (Node *) n;
   10372              :                 }
   10373              :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10374              :                 {
   10375            9 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10376              : 
   10377            9 :                     n->objectType = OBJECT_TSPARSER;
   10378            9 :                     n->object = (Node *) $5;
   10379            9 :                     n->newschema = $8;
   10380            9 :                     n->missing_ok = false;
   10381            9 :                     $$ = (Node *) n;
   10382              :                 }
   10383              :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10384              :                 {
   10385           12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10386              : 
   10387           12 :                     n->objectType = OBJECT_TSDICTIONARY;
   10388           12 :                     n->object = (Node *) $5;
   10389           12 :                     n->newschema = $8;
   10390           12 :                     n->missing_ok = false;
   10391           12 :                     $$ = (Node *) n;
   10392              :                 }
   10393              :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10394              :                 {
   10395            9 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10396              : 
   10397            9 :                     n->objectType = OBJECT_TSTEMPLATE;
   10398            9 :                     n->object = (Node *) $5;
   10399            9 :                     n->newschema = $8;
   10400            9 :                     n->missing_ok = false;
   10401            9 :                     $$ = (Node *) n;
   10402              :                 }
   10403              :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10404              :                 {
   10405           12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10406              : 
   10407           12 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10408           12 :                     n->object = (Node *) $5;
   10409           12 :                     n->newschema = $8;
   10410           12 :                     n->missing_ok = false;
   10411           12 :                     $$ = (Node *) n;
   10412              :                 }
   10413              :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10414              :                 {
   10415            4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10416              : 
   10417            4 :                     n->objectType = OBJECT_SEQUENCE;
   10418            4 :                     n->relation = $3;
   10419            4 :                     n->newschema = $6;
   10420            4 :                     n->missing_ok = false;
   10421            4 :                     $$ = (Node *) n;
   10422              :                 }
   10423              :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10424              :                 {
   10425            0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10426              : 
   10427            0 :                     n->objectType = OBJECT_SEQUENCE;
   10428            0 :                     n->relation = $5;
   10429            0 :                     n->newschema = $8;
   10430            0 :                     n->missing_ok = true;
   10431            0 :                     $$ = (Node *) n;
   10432              :                 }
   10433              :             | ALTER VIEW qualified_name SET SCHEMA name
   10434              :                 {
   10435            0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10436              : 
   10437            0 :                     n->objectType = OBJECT_VIEW;
   10438            0 :                     n->relation = $3;
   10439            0 :                     n->newschema = $6;
   10440            0 :                     n->missing_ok = false;
   10441            0 :                     $$ = (Node *) n;
   10442              :                 }
   10443              :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10444              :                 {
   10445            0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10446              : 
   10447            0 :                     n->objectType = OBJECT_VIEW;
   10448            0 :                     n->relation = $5;
   10449            0 :                     n->newschema = $8;
   10450            0 :                     n->missing_ok = true;
   10451            0 :                     $$ = (Node *) n;
   10452              :                 }
   10453              :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10454              :                 {
   10455            3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10456              : 
   10457            3 :                     n->objectType = OBJECT_MATVIEW;
   10458            3 :                     n->relation = $4;
   10459            3 :                     n->newschema = $7;
   10460            3 :                     n->missing_ok = false;
   10461            3 :                     $$ = (Node *) n;
   10462              :                 }
   10463              :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10464              :                 {
   10465            0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10466              : 
   10467            0 :                     n->objectType = OBJECT_MATVIEW;
   10468            0 :                     n->relation = $6;
   10469            0 :                     n->newschema = $9;
   10470            0 :                     n->missing_ok = true;
   10471            0 :                     $$ = (Node *) n;
   10472              :                 }
   10473              :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10474              :                 {
   10475            3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10476              : 
   10477            3 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10478            3 :                     n->relation = $4;
   10479            3 :                     n->newschema = $7;
   10480            3 :                     n->missing_ok = false;
   10481            3 :                     $$ = (Node *) n;
   10482              :                 }
   10483              :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10484              :                 {
   10485            3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10486              : 
   10487            3 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10488            3 :                     n->relation = $6;
   10489            3 :                     n->newschema = $9;
   10490            3 :                     n->missing_ok = true;
   10491            3 :                     $$ = (Node *) n;
   10492              :                 }
   10493              :             | ALTER TYPE_P any_name SET SCHEMA name
   10494              :                 {
   10495            6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10496              : 
   10497            6 :                     n->objectType = OBJECT_TYPE;
   10498            6 :                     n->object = (Node *) $3;
   10499            6 :                     n->newschema = $6;
   10500            6 :                     n->missing_ok = false;
   10501            6 :                     $$ = (Node *) n;
   10502              :                 }
   10503              :         ;
   10504              : 
   10505              : /*****************************************************************************
   10506              :  *
   10507              :  * ALTER OPERATOR name SET define
   10508              :  *
   10509              :  *****************************************************************************/
   10510              : 
   10511              : AlterOperatorStmt:
   10512              :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10513              :                 {
   10514          304 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10515              : 
   10516          304 :                     n->opername = $3;
   10517          304 :                     n->options = $6;
   10518          304 :                     $$ = (Node *) n;
   10519              :                 }
   10520              :         ;
   10521              : 
   10522          336 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10523          253 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10524              :         ;
   10525              : 
   10526              : operator_def_elem: ColLabel '=' NONE
   10527           15 :                         { $$ = makeDefElem($1, NULL, @1); }
   10528              :                    | ColLabel '=' operator_def_arg
   10529          557 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10530              :                    | ColLabel
   10531           17 :                         { $$ = makeDefElem($1, NULL, @1); }
   10532              :         ;
   10533              : 
   10534              : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10535              : operator_def_arg:
   10536          518 :             func_type                       { $$ = (Node *) $1; }
   10537           12 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10538           27 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10539            0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10540            0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10541              :         ;
   10542              : 
   10543              : /*****************************************************************************
   10544              :  *
   10545              :  * ALTER TYPE name SET define
   10546              :  *
   10547              :  * We repurpose ALTER OPERATOR's version of "definition" here
   10548              :  *
   10549              :  *****************************************************************************/
   10550              : 
   10551              : AlterTypeStmt:
   10552              :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10553              :                 {
   10554           32 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10555              : 
   10556           32 :                     n->typeName = $3;
   10557           32 :                     n->options = $6;
   10558           32 :                     $$ = (Node *) n;
   10559              :                 }
   10560              :         ;
   10561              : 
   10562              : /*****************************************************************************
   10563              :  *
   10564              :  * ALTER THING name OWNER TO newname
   10565              :  *
   10566              :  *****************************************************************************/
   10567              : 
   10568              : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10569              :                 {
   10570           71 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10571              : 
   10572           71 :                     n->objectType = OBJECT_AGGREGATE;
   10573           71 :                     n->object = (Node *) $3;
   10574           71 :                     n->newowner = $6;
   10575           71 :                     $$ = (Node *) n;
   10576              :                 }
   10577              :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10578              :                 {
   10579            9 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10580              : 
   10581            9 :                     n->objectType = OBJECT_COLLATION;
   10582            9 :                     n->object = (Node *) $3;
   10583            9 :                     n->newowner = $6;
   10584            9 :                     $$ = (Node *) n;
   10585              :                 }
   10586              :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10587              :                 {
   10588           12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10589              : 
   10590           12 :                     n->objectType = OBJECT_CONVERSION;
   10591           12 :                     n->object = (Node *) $3;
   10592           12 :                     n->newowner = $6;
   10593           12 :                     $$ = (Node *) n;
   10594              :                 }
   10595              :             | ALTER DATABASE name OWNER TO RoleSpec
   10596              :                 {
   10597           45 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10598              : 
   10599           45 :                     n->objectType = OBJECT_DATABASE;
   10600           45 :                     n->object = (Node *) makeString($3);
   10601           45 :                     n->newowner = $6;
   10602           45 :                     $$ = (Node *) n;
   10603              :                 }
   10604              :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10605              :                 {
   10606           24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10607              : 
   10608           24 :                     n->objectType = OBJECT_DOMAIN;
   10609           24 :                     n->object = (Node *) $3;
   10610           24 :                     n->newowner = $6;
   10611           24 :                     $$ = (Node *) n;
   10612              :                 }
   10613              :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10614              :                 {
   10615          299 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10616              : 
   10617          299 :                     n->objectType = OBJECT_FUNCTION;
   10618          299 :                     n->object = (Node *) $3;
   10619          299 :                     n->newowner = $6;
   10620          299 :                     $$ = (Node *) n;
   10621              :                 }
   10622              :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10623              :                 {
   10624           72 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10625              : 
   10626           72 :                     n->objectType = OBJECT_LANGUAGE;
   10627           72 :                     n->object = (Node *) makeString($4);
   10628           72 :                     n->newowner = $7;
   10629           72 :                     $$ = (Node *) n;
   10630              :                 }
   10631              :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10632              :                 {
   10633            8 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10634              : 
   10635            8 :                     n->objectType = OBJECT_LARGEOBJECT;
   10636            8 :                     n->object = (Node *) $4;
   10637            8 :                     n->newowner = $7;
   10638            8 :                     $$ = (Node *) n;
   10639              :                 }
   10640              :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10641              :                 {
   10642           23 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10643              : 
   10644           23 :                     n->objectType = OBJECT_OPERATOR;
   10645           23 :                     n->object = (Node *) $3;
   10646           23 :                     n->newowner = $6;
   10647           23 :                     $$ = (Node *) n;
   10648              :                 }
   10649              :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10650              :                 {
   10651           27 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10652              : 
   10653           27 :                     n->objectType = OBJECT_OPCLASS;
   10654           27 :                     n->object = (Node *) lcons(makeString($6), $4);
   10655           27 :                     n->newowner = $9;
   10656           27 :                     $$ = (Node *) n;
   10657              :                 }
   10658              :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10659              :                 {
   10660           31 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10661              : 
   10662           31 :                     n->objectType = OBJECT_OPFAMILY;
   10663           31 :                     n->object = (Node *) lcons(makeString($6), $4);
   10664           31 :                     n->newowner = $9;
   10665           31 :                     $$ = (Node *) n;
   10666              :                 }
   10667              :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10668              :                 {
   10669           12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10670              : 
   10671           12 :                     n->objectType = OBJECT_PROCEDURE;
   10672           12 :                     n->object = (Node *) $3;
   10673           12 :                     n->newowner = $6;
   10674           12 :                     $$ = (Node *) n;
   10675              :                 }
   10676              :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10677              :                 {
   10678            0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10679              : 
   10680            0 :                     n->objectType = OBJECT_ROUTINE;
   10681            0 :                     n->object = (Node *) $3;
   10682            0 :                     n->newowner = $6;
   10683            0 :                     $$ = (Node *) n;
   10684              :                 }
   10685              :             | ALTER SCHEMA name OWNER TO RoleSpec
   10686              :                 {
   10687           32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10688              : 
   10689           32 :                     n->objectType = OBJECT_SCHEMA;
   10690           32 :                     n->object = (Node *) makeString($3);
   10691           32 :                     n->newowner = $6;
   10692           32 :                     $$ = (Node *) n;
   10693              :                 }
   10694              :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10695              :                 {
   10696           42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10697              : 
   10698           42 :                     n->objectType = OBJECT_TYPE;
   10699           42 :                     n->object = (Node *) $3;
   10700           42 :                     n->newowner = $6;
   10701           42 :                     $$ = (Node *) n;
   10702              :                 }
   10703              :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10704              :                 {
   10705            3 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10706              : 
   10707            3 :                     n->objectType = OBJECT_TABLESPACE;
   10708            3 :                     n->object = (Node *) makeString($3);
   10709            3 :                     n->newowner = $6;
   10710            3 :                     $$ = (Node *) n;
   10711              :                 }
   10712              :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10713              :                 {
   10714           16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10715              : 
   10716           16 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10717           16 :                     n->object = (Node *) $3;
   10718           16 :                     n->newowner = $6;
   10719           16 :                     $$ = (Node *) n;
   10720              :                 }
   10721              :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10722              :                 {
   10723           21 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10724              : 
   10725           21 :                     n->objectType = OBJECT_TSDICTIONARY;
   10726           21 :                     n->object = (Node *) $5;
   10727           21 :                     n->newowner = $8;
   10728           21 :                     $$ = (Node *) n;
   10729              :                 }
   10730              :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10731              :                 {
   10732           16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10733              : 
   10734           16 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10735           16 :                     n->object = (Node *) $5;
   10736           16 :                     n->newowner = $8;
   10737           16 :                     $$ = (Node *) n;
   10738              :                 }
   10739              :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10740              :                 {
   10741           10 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10742              : 
   10743           10 :                     n->objectType = OBJECT_FDW;
   10744           10 :                     n->object = (Node *) makeString($5);
   10745           10 :                     n->newowner = $8;
   10746           10 :                     $$ = (Node *) n;
   10747              :                 }
   10748              :             | ALTER SERVER name OWNER TO RoleSpec
   10749              :                 {
   10750           34 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10751              : 
   10752           34 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10753           34 :                     n->object = (Node *) makeString($3);
   10754           34 :                     n->newowner = $6;
   10755           34 :                     $$ = (Node *) n;
   10756              :                 }
   10757              :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10758              :                 {
   10759            7 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10760              : 
   10761            7 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10762            7 :                     n->object = (Node *) makeString($4);
   10763            7 :                     n->newowner = $7;
   10764            7 :                     $$ = (Node *) n;
   10765              :                 }
   10766              :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10767              :                 {
   10768           18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10769              : 
   10770           18 :                     n->objectType = OBJECT_PUBLICATION;
   10771           18 :                     n->object = (Node *) makeString($3);
   10772           18 :                     n->newowner = $6;
   10773           18 :                     $$ = (Node *) n;
   10774              :                 }
   10775              :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10776              :                 {
   10777            9 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10778              : 
   10779            9 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10780            9 :                     n->object = (Node *) makeString($3);
   10781            9 :                     n->newowner = $6;
   10782            9 :                     $$ = (Node *) n;
   10783              :                 }
   10784              :         ;
   10785              : 
   10786              : 
   10787              : /*****************************************************************************
   10788              :  *
   10789              :  * CREATE PUBLICATION name [WITH options]
   10790              :  *
   10791              :  * CREATE PUBLICATION FOR ALL pub_all_obj_type [, ...] [WITH options]
   10792              :  *
   10793              :  * pub_all_obj_type is one of:
   10794              :  *
   10795              :  *      TABLES
   10796              :  *      SEQUENCES
   10797              :  *
   10798              :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10799              :  *
   10800              :  * pub_obj is one of:
   10801              :  *
   10802              :  *      TABLE table [, ...]
   10803              :  *      TABLES IN SCHEMA schema [, ...]
   10804              :  *
   10805              :  *****************************************************************************/
   10806              : 
   10807              : CreatePublicationStmt:
   10808              :             CREATE PUBLICATION name opt_definition
   10809              :                 {
   10810           73 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10811              : 
   10812           73 :                     n->pubname = $3;
   10813           73 :                     n->options = $4;
   10814           73 :                     $$ = (Node *) n;
   10815              :                 }
   10816              :             | CREATE PUBLICATION name FOR pub_all_obj_type_list opt_definition
   10817              :                 {
   10818           69 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10819              : 
   10820           69 :                     n->pubname = $3;
   10821           69 :                     preprocess_pub_all_objtype_list($5, &n->for_all_tables,
   10822              :                                                     &n->for_all_sequences,
   10823              :                                                     yyscanner);
   10824           63 :                     n->options = $6;
   10825           63 :                     $$ = (Node *) n;
   10826              :                 }
   10827              :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10828              :                 {
   10829          330 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10830              : 
   10831          330 :                     n->pubname = $3;
   10832          330 :                     n->options = $6;
   10833          330 :                     n->pubobjects = (List *) $5;
   10834          330 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10835          315 :                     $$ = (Node *) n;
   10836              :                 }
   10837              :         ;
   10838              : 
   10839              : /*
   10840              :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10841              :  *
   10842              :  * This rule parses publication objects with and without keyword prefixes.
   10843              :  *
   10844              :  * The actual type of the object without keyword prefix depends on the previous
   10845              :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10846              :  *
   10847              :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10848              :  * because some extended expressions in relation_expr cannot be used as a
   10849              :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10850              :  * relation_expr here.
   10851              :  */
   10852              : PublicationObjSpec:
   10853              :             TABLE relation_expr opt_column_list OptWhereClause
   10854              :                 {
   10855          664 :                     $$ = makeNode(PublicationObjSpec);
   10856          664 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10857          664 :                     $$->pubtable = makeNode(PublicationTable);
   10858          664 :                     $$->pubtable->relation = $2;
   10859          664 :                     $$->pubtable->columns = $3;
   10860          664 :                     $$->pubtable->whereClause = $4;
   10861              :                 }
   10862              :             | TABLES IN_P SCHEMA ColId
   10863              :                 {
   10864          186 :                     $$ = makeNode(PublicationObjSpec);
   10865          186 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10866          186 :                     $$->name = $4;
   10867          186 :                     $$->location = @4;
   10868              :                 }
   10869              :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10870              :                 {
   10871            9 :                     $$ = makeNode(PublicationObjSpec);
   10872            9 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10873            9 :                     $$->location = @4;
   10874              :                 }
   10875              :             | ColId opt_column_list OptWhereClause
   10876              :                 {
   10877           66 :                     $$ = makeNode(PublicationObjSpec);
   10878           66 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10879              :                     /*
   10880              :                      * If either a row filter or column list is specified, create
   10881              :                      * a PublicationTable object.
   10882              :                      */
   10883           66 :                     if ($2 || $3)
   10884              :                     {
   10885              :                         /*
   10886              :                          * The OptWhereClause must be stored here but it is
   10887              :                          * valid only for tables. For non-table objects, an
   10888              :                          * error will be thrown later via
   10889              :                          * preprocess_pubobj_list().
   10890              :                          */
   10891           21 :                         $$->pubtable = makeNode(PublicationTable);
   10892           21 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10893           21 :                         $$->pubtable->columns = $2;
   10894           21 :                         $$->pubtable->whereClause = $3;
   10895              :                     }
   10896              :                     else
   10897              :                     {
   10898           45 :                         $$->name = $1;
   10899              :                     }
   10900           66 :                     $$->location = @1;
   10901              :                 }
   10902              :             | ColId indirection opt_column_list OptWhereClause
   10903              :                 {
   10904           16 :                     $$ = makeNode(PublicationObjSpec);
   10905           16 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10906           16 :                     $$->pubtable = makeNode(PublicationTable);
   10907           16 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10908           16 :                     $$->pubtable->columns = $3;
   10909           16 :                     $$->pubtable->whereClause = $4;
   10910           16 :                     $$->location = @1;
   10911              :                 }
   10912              :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10913              :             | extended_relation_expr opt_column_list OptWhereClause
   10914              :                 {
   10915            3 :                     $$ = makeNode(PublicationObjSpec);
   10916            3 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10917            3 :                     $$->pubtable = makeNode(PublicationTable);
   10918            3 :                     $$->pubtable->relation = $1;
   10919            3 :                     $$->pubtable->columns = $2;
   10920            3 :                     $$->pubtable->whereClause = $3;
   10921              :                 }
   10922              :             | CURRENT_SCHEMA
   10923              :                 {
   10924            9 :                     $$ = makeNode(PublicationObjSpec);
   10925            9 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10926            9 :                     $$->location = @1;
   10927              :                 }
   10928              :                 ;
   10929              : 
   10930              : pub_obj_list:   PublicationObjSpec
   10931          825 :                     { $$ = list_make1($1); }
   10932              :             | pub_obj_list ',' PublicationObjSpec
   10933          128 :                     { $$ = lappend($1, $3); }
   10934              :     ;
   10935              : 
   10936              : PublicationAllObjSpec:
   10937              :                 ALL TABLES
   10938              :                     {
   10939           62 :                         $$ = makeNode(PublicationAllObjSpec);
   10940           62 :                         $$->pubobjtype = PUBLICATION_ALL_TABLES;
   10941           62 :                         $$->location = @1;
   10942              :                     }
   10943              :                 | ALL SEQUENCES
   10944              :                     {
   10945           23 :                         $$ = makeNode(PublicationAllObjSpec);
   10946           23 :                         $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
   10947           23 :                         $$->location = @1;
   10948              :                     }
   10949              :                     ;
   10950              : 
   10951              : pub_all_obj_type_list:  PublicationAllObjSpec
   10952           69 :                     { $$ = list_make1($1); }
   10953              :                 | pub_all_obj_type_list ',' PublicationAllObjSpec
   10954           16 :                     { $$ = lappend($1, $3); }
   10955              :     ;
   10956              : 
   10957              : 
   10958              : /*****************************************************************************
   10959              :  *
   10960              :  * ALTER PUBLICATION name SET ( options )
   10961              :  *
   10962              :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10963              :  *
   10964              :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10965              :  *
   10966              :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10967              :  *
   10968              :  * pub_obj is one of:
   10969              :  *
   10970              :  *      TABLE table_name [, ...]
   10971              :  *      TABLES IN SCHEMA schema_name [, ...]
   10972              :  *
   10973              :  *****************************************************************************/
   10974              : 
   10975              : AlterPublicationStmt:
   10976              :             ALTER PUBLICATION name SET definition
   10977              :                 {
   10978           64 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10979              : 
   10980           64 :                     n->pubname = $3;
   10981           64 :                     n->options = $5;
   10982           64 :                     $$ = (Node *) n;
   10983              :                 }
   10984              :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10985              :                 {
   10986          185 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10987              : 
   10988          185 :                     n->pubname = $3;
   10989          185 :                     n->pubobjects = $5;
   10990          185 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10991          182 :                     n->action = AP_AddObjects;
   10992          182 :                     $$ = (Node *) n;
   10993              :                 }
   10994              :             | ALTER PUBLICATION name SET pub_obj_list
   10995              :                 {
   10996          232 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10997              : 
   10998          232 :                     n->pubname = $3;
   10999          232 :                     n->pubobjects = $5;
   11000          232 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   11001          232 :                     n->action = AP_SetObjects;
   11002          232 :                     $$ = (Node *) n;
   11003              :                 }
   11004              :             | ALTER PUBLICATION name DROP pub_obj_list
   11005              :                 {
   11006           78 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   11007              : 
   11008           78 :                     n->pubname = $3;
   11009           78 :                     n->pubobjects = $5;
   11010           78 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   11011           78 :                     n->action = AP_DropObjects;
   11012           78 :                     $$ = (Node *) n;
   11013              :                 }
   11014              :         ;
   11015              : 
   11016              : /*****************************************************************************
   11017              :  *
   11018              :  * CREATE SUBSCRIPTION name ...
   11019              :  *
   11020              :  *****************************************************************************/
   11021              : 
   11022              : CreateSubscriptionStmt:
   11023              :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   11024              :                 {
   11025              :                     CreateSubscriptionStmt *n =
   11026          242 :                         makeNode(CreateSubscriptionStmt);
   11027          242 :                     n->subname = $3;
   11028          242 :                     n->conninfo = $5;
   11029          242 :                     n->publication = $7;
   11030          242 :                     n->options = $8;
   11031          242 :                     $$ = (Node *) n;
   11032              :                 }
   11033              :         ;
   11034              : 
   11035              : /*****************************************************************************
   11036              :  *
   11037              :  * ALTER SUBSCRIPTION name ...
   11038              :  *
   11039              :  *****************************************************************************/
   11040              : 
   11041              : AlterSubscriptionStmt:
   11042              :             ALTER SUBSCRIPTION name SET definition
   11043              :                 {
   11044              :                     AlterSubscriptionStmt *n =
   11045          118 :                         makeNode(AlterSubscriptionStmt);
   11046              : 
   11047          118 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   11048          118 :                     n->subname = $3;
   11049          118 :                     n->options = $5;
   11050          118 :                     $$ = (Node *) n;
   11051              :                 }
   11052              :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   11053              :                 {
   11054              :                     AlterSubscriptionStmt *n =
   11055           13 :                         makeNode(AlterSubscriptionStmt);
   11056              : 
   11057           13 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   11058           13 :                     n->subname = $3;
   11059           13 :                     n->conninfo = $5;
   11060           13 :                     $$ = (Node *) n;
   11061              :                 }
   11062              :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   11063              :                 {
   11064              :                     AlterSubscriptionStmt *n =
   11065           34 :                         makeNode(AlterSubscriptionStmt);
   11066              : 
   11067           34 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
   11068           34 :                     n->subname = $3;
   11069           34 :                     n->options = $6;
   11070           34 :                     $$ = (Node *) n;
   11071              :                 }
   11072              :             | ALTER SUBSCRIPTION name REFRESH SEQUENCES
   11073              :                 {
   11074              :                     AlterSubscriptionStmt *n =
   11075            1 :                         makeNode(AlterSubscriptionStmt);
   11076              : 
   11077            1 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
   11078            1 :                     n->subname = $3;
   11079            1 :                     $$ = (Node *) n;
   11080              :                 }
   11081              :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   11082              :                 {
   11083              :                     AlterSubscriptionStmt *n =
   11084           14 :                         makeNode(AlterSubscriptionStmt);
   11085              : 
   11086           14 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   11087           14 :                     n->subname = $3;
   11088           14 :                     n->publication = $6;
   11089           14 :                     n->options = $7;
   11090           14 :                     $$ = (Node *) n;
   11091              :                 }
   11092              :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   11093              :                 {
   11094              :                     AlterSubscriptionStmt *n =
   11095           13 :                         makeNode(AlterSubscriptionStmt);
   11096              : 
   11097           13 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   11098           13 :                     n->subname = $3;
   11099           13 :                     n->publication = $6;
   11100           13 :                     n->options = $7;
   11101           13 :                     $$ = (Node *) n;
   11102              :                 }
   11103              :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   11104              :                 {
   11105              :                     AlterSubscriptionStmt *n =
   11106           22 :                         makeNode(AlterSubscriptionStmt);
   11107              : 
   11108           22 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   11109           22 :                     n->subname = $3;
   11110           22 :                     n->publication = $6;
   11111           22 :                     n->options = $7;
   11112           22 :                     $$ = (Node *) n;
   11113              :                 }
   11114              :             | ALTER SUBSCRIPTION name ENABLE_P
   11115              :                 {
   11116              :                     AlterSubscriptionStmt *n =
   11117           31 :                         makeNode(AlterSubscriptionStmt);
   11118              : 
   11119           31 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11120           31 :                     n->subname = $3;
   11121           31 :                     n->options = list_make1(makeDefElem("enabled",
   11122              :                                             (Node *) makeBoolean(true), @1));
   11123           31 :                     $$ = (Node *) n;
   11124              :                 }
   11125              :             | ALTER SUBSCRIPTION name DISABLE_P
   11126              :                 {
   11127              :                     AlterSubscriptionStmt *n =
   11128           22 :                         makeNode(AlterSubscriptionStmt);
   11129              : 
   11130           22 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11131           22 :                     n->subname = $3;
   11132           22 :                     n->options = list_make1(makeDefElem("enabled",
   11133              :                                             (Node *) makeBoolean(false), @1));
   11134           22 :                     $$ = (Node *) n;
   11135              :                 }
   11136              :             | ALTER SUBSCRIPTION name SKIP definition
   11137              :                 {
   11138              :                     AlterSubscriptionStmt *n =
   11139           12 :                         makeNode(AlterSubscriptionStmt);
   11140              : 
   11141           12 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   11142           12 :                     n->subname = $3;
   11143           12 :                     n->options = $5;
   11144           12 :                     $$ = (Node *) n;
   11145              :                 }
   11146              :         ;
   11147              : 
   11148              : /*****************************************************************************
   11149              :  *
   11150              :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   11151              :  *
   11152              :  *****************************************************************************/
   11153              : 
   11154              : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   11155              :                 {
   11156          122 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11157              : 
   11158          122 :                     n->subname = $3;
   11159          122 :                     n->missing_ok = false;
   11160          122 :                     n->behavior = $4;
   11161          122 :                     $$ = (Node *) n;
   11162              :                 }
   11163              :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   11164              :                 {
   11165            3 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11166              : 
   11167            3 :                     n->subname = $5;
   11168            3 :                     n->missing_ok = true;
   11169            3 :                     n->behavior = $6;
   11170            3 :                     $$ = (Node *) n;
   11171              :                 }
   11172              :         ;
   11173              : 
   11174              : /*****************************************************************************
   11175              :  *
   11176              :  *      QUERY:  Define Rewrite Rule
   11177              :  *
   11178              :  *****************************************************************************/
   11179              : 
   11180              : RuleStmt:   CREATE opt_or_replace RULE name AS
   11181              :             ON event TO qualified_name where_clause
   11182              :             DO opt_instead RuleActionList
   11183              :                 {
   11184          554 :                     RuleStmt   *n = makeNode(RuleStmt);
   11185              : 
   11186          554 :                     n->replace = $2;
   11187          554 :                     n->relation = $9;
   11188          554 :                     n->rulename = $4;
   11189          554 :                     n->whereClause = $10;
   11190          554 :                     n->event = $7;
   11191          554 :                     n->instead = $12;
   11192          554 :                     n->actions = $13;
   11193          554 :                     $$ = (Node *) n;
   11194              :                 }
   11195              :         ;
   11196              : 
   11197              : RuleActionList:
   11198           82 :             NOTHING                                 { $$ = NIL; }
   11199          449 :             | RuleActionStmt                        { $$ = list_make1($1); }
   11200           23 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   11201              :         ;
   11202              : 
   11203              : /* the thrashing around here is to discard "empty" statements... */
   11204              : RuleActionMulti:
   11205              :             RuleActionMulti ';' RuleActionStmtOrEmpty
   11206           31 :                 { if ($3 != NULL)
   11207           23 :                     $$ = lappend($1, $3);
   11208              :                   else
   11209            8 :                     $$ = $1;
   11210              :                 }
   11211              :             | RuleActionStmtOrEmpty
   11212           23 :                 { if ($1 != NULL)
   11213           23 :                     $$ = list_make1($1);
   11214              :                   else
   11215            0 :                     $$ = NIL;
   11216              :                 }
   11217              :         ;
   11218              : 
   11219              : RuleActionStmt:
   11220              :             SelectStmt
   11221              :             | InsertStmt
   11222              :             | UpdateStmt
   11223              :             | DeleteStmt
   11224              :             | NotifyStmt
   11225              :         ;
   11226              : 
   11227              : RuleActionStmtOrEmpty:
   11228           46 :             RuleActionStmt                          { $$ = $1; }
   11229            8 :             |   /*EMPTY*/                           { $$ = NULL; }
   11230              :         ;
   11231              : 
   11232            9 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11233          218 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11234           82 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11235          245 :             | INSERT                                { $$ = CMD_INSERT; }
   11236              :          ;
   11237              : 
   11238              : opt_instead:
   11239          383 :             INSTEAD                                 { $$ = true; }
   11240           78 :             | ALSO                                  { $$ = false; }
   11241           93 :             | /*EMPTY*/                             { $$ = false; }
   11242              :         ;
   11243              : 
   11244              : 
   11245              : /*****************************************************************************
   11246              :  *
   11247              :  *      QUERY:
   11248              :  *              NOTIFY <identifier> can appear both in rule bodies and
   11249              :  *              as a query-level command
   11250              :  *
   11251              :  *****************************************************************************/
   11252              : 
   11253              : NotifyStmt: NOTIFY ColId notify_payload
   11254              :                 {
   11255           81 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11256              : 
   11257           81 :                     n->conditionname = $2;
   11258           81 :                     n->payload = $3;
   11259           81 :                     $$ = (Node *) n;
   11260              :                 }
   11261              :         ;
   11262              : 
   11263              : notify_payload:
   11264           47 :             ',' Sconst                          { $$ = $2; }
   11265           34 :             | /*EMPTY*/                         { $$ = NULL; }
   11266              :         ;
   11267              : 
   11268              : ListenStmt: LISTEN ColId
   11269              :                 {
   11270           58 :                     ListenStmt *n = makeNode(ListenStmt);
   11271              : 
   11272           58 :                     n->conditionname = $2;
   11273           58 :                     $$ = (Node *) n;
   11274              :                 }
   11275              :         ;
   11276              : 
   11277              : UnlistenStmt:
   11278              :             UNLISTEN ColId
   11279              :                 {
   11280            3 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11281              : 
   11282            3 :                     n->conditionname = $2;
   11283            3 :                     $$ = (Node *) n;
   11284              :                 }
   11285              :             | UNLISTEN '*'
   11286              :                 {
   11287           75 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11288              : 
   11289           75 :                     n->conditionname = NULL;
   11290           75 :                     $$ = (Node *) n;
   11291              :                 }
   11292              :         ;
   11293              : 
   11294              : 
   11295              : /*****************************************************************************
   11296              :  *
   11297              :  *      Transactions:
   11298              :  *
   11299              :  *      BEGIN / COMMIT / ROLLBACK
   11300              :  *      (also older versions END / ABORT)
   11301              :  *
   11302              :  *****************************************************************************/
   11303              : 
   11304              : TransactionStmt:
   11305              :             ABORT_P opt_transaction opt_transaction_chain
   11306              :                 {
   11307          392 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11308              : 
   11309          392 :                     n->kind = TRANS_STMT_ROLLBACK;
   11310          392 :                     n->options = NIL;
   11311          392 :                     n->chain = $3;
   11312          392 :                     n->location = -1;
   11313          392 :                     $$ = (Node *) n;
   11314              :                 }
   11315              :             | START TRANSACTION transaction_mode_list_or_empty
   11316              :                 {
   11317          823 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11318              : 
   11319          823 :                     n->kind = TRANS_STMT_START;
   11320          823 :                     n->options = $3;
   11321          823 :                     n->location = -1;
   11322          823 :                     $$ = (Node *) n;
   11323              :                 }
   11324              :             | COMMIT opt_transaction opt_transaction_chain
   11325              :                 {
   11326         8877 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11327              : 
   11328         8877 :                     n->kind = TRANS_STMT_COMMIT;
   11329         8877 :                     n->options = NIL;
   11330         8877 :                     n->chain = $3;
   11331         8877 :                     n->location = -1;
   11332         8877 :                     $$ = (Node *) n;
   11333              :                 }
   11334              :             | ROLLBACK opt_transaction opt_transaction_chain
   11335              :                 {
   11336         1389 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11337              : 
   11338         1389 :                     n->kind = TRANS_STMT_ROLLBACK;
   11339         1389 :                     n->options = NIL;
   11340         1389 :                     n->chain = $3;
   11341         1389 :                     n->location = -1;
   11342         1389 :                     $$ = (Node *) n;
   11343              :                 }
   11344              :             | SAVEPOINT ColId
   11345              :                 {
   11346         1007 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11347              : 
   11348         1007 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11349         1007 :                     n->savepoint_name = $2;
   11350         1007 :                     n->location = @2;
   11351         1007 :                     $$ = (Node *) n;
   11352              :                 }
   11353              :             | RELEASE SAVEPOINT ColId
   11354              :                 {
   11355          107 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11356              : 
   11357          107 :                     n->kind = TRANS_STMT_RELEASE;
   11358          107 :                     n->savepoint_name = $3;
   11359          107 :                     n->location = @3;
   11360          107 :                     $$ = (Node *) n;
   11361              :                 }
   11362              :             | RELEASE ColId
   11363              :                 {
   11364           44 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11365              : 
   11366           44 :                     n->kind = TRANS_STMT_RELEASE;
   11367           44 :                     n->savepoint_name = $2;
   11368           44 :                     n->location = @2;
   11369           44 :                     $$ = (Node *) n;
   11370              :                 }
   11371              :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11372              :                 {
   11373          124 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11374              : 
   11375          124 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11376          124 :                     n->savepoint_name = $5;
   11377          124 :                     n->location = @5;
   11378          124 :                     $$ = (Node *) n;
   11379              :                 }
   11380              :             | ROLLBACK opt_transaction TO ColId
   11381              :                 {
   11382          250 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11383              : 
   11384          250 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11385          250 :                     n->savepoint_name = $4;
   11386          250 :                     n->location = @4;
   11387          250 :                     $$ = (Node *) n;
   11388              :                 }
   11389              :             | PREPARE TRANSACTION Sconst
   11390              :                 {
   11391          338 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11392              : 
   11393          338 :                     n->kind = TRANS_STMT_PREPARE;
   11394          338 :                     n->gid = $3;
   11395          338 :                     n->location = @3;
   11396          338 :                     $$ = (Node *) n;
   11397              :                 }
   11398              :             | COMMIT PREPARED Sconst
   11399              :                 {
   11400          254 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11401              : 
   11402          254 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11403          254 :                     n->gid = $3;
   11404          254 :                     n->location = @3;
   11405          254 :                     $$ = (Node *) n;
   11406              :                 }
   11407              :             | ROLLBACK PREPARED Sconst
   11408              :                 {
   11409           43 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11410              : 
   11411           43 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11412           43 :                     n->gid = $3;
   11413           43 :                     n->location = @3;
   11414           43 :                     $$ = (Node *) n;
   11415              :                 }
   11416              :         ;
   11417              : 
   11418              : TransactionStmtLegacy:
   11419              :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11420              :                 {
   11421        10627 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11422              : 
   11423        10627 :                     n->kind = TRANS_STMT_BEGIN;
   11424        10627 :                     n->options = $3;
   11425        10627 :                     n->location = -1;
   11426        10627 :                     $$ = (Node *) n;
   11427              :                 }
   11428              :             | END_P opt_transaction opt_transaction_chain
   11429              :                 {
   11430          185 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11431              : 
   11432          185 :                     n->kind = TRANS_STMT_COMMIT;
   11433          185 :                     n->options = NIL;
   11434          185 :                     n->chain = $3;
   11435          185 :                     n->location = -1;
   11436          185 :                     $$ = (Node *) n;
   11437              :                 }
   11438              :         ;
   11439              : 
   11440              : opt_transaction:    WORK
   11441              :             | TRANSACTION
   11442              :             | /*EMPTY*/
   11443              :         ;
   11444              : 
   11445              : transaction_mode_item:
   11446              :             ISOLATION LEVEL iso_level
   11447         3589 :                     { $$ = makeDefElem("transaction_isolation",
   11448         3589 :                                        makeStringConst($3, @3), @1); }
   11449              :             | READ ONLY
   11450          778 :                     { $$ = makeDefElem("transaction_read_only",
   11451          778 :                                        makeIntConst(true, @1), @1); }
   11452              :             | READ WRITE
   11453           45 :                     { $$ = makeDefElem("transaction_read_only",
   11454           45 :                                        makeIntConst(false, @1), @1); }
   11455              :             | DEFERRABLE
   11456           22 :                     { $$ = makeDefElem("transaction_deferrable",
   11457              :                                        makeIntConst(true, @1), @1); }
   11458              :             | NOT DEFERRABLE
   11459            5 :                     { $$ = makeDefElem("transaction_deferrable",
   11460            5 :                                        makeIntConst(false, @1), @1); }
   11461              :         ;
   11462              : 
   11463              : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11464              : transaction_mode_list:
   11465              :             transaction_mode_item
   11466         3697 :                     { $$ = list_make1($1); }
   11467              :             | transaction_mode_list ',' transaction_mode_item
   11468          535 :                     { $$ = lappend($1, $3); }
   11469              :             | transaction_mode_list transaction_mode_item
   11470          207 :                     { $$ = lappend($1, $2); }
   11471              :         ;
   11472              : 
   11473              : transaction_mode_list_or_empty:
   11474              :             transaction_mode_list
   11475              :             | /* EMPTY */
   11476         8118 :                     { $$ = NIL; }
   11477              :         ;
   11478              : 
   11479              : opt_transaction_chain:
   11480           60 :             AND CHAIN       { $$ = true; }
   11481            1 :             | AND NO CHAIN  { $$ = false; }
   11482        10782 :             | /* EMPTY */   { $$ = false; }
   11483              :         ;
   11484              : 
   11485              : 
   11486              : /*****************************************************************************
   11487              :  *
   11488              :  *  QUERY:
   11489              :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11490              :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11491              :  *
   11492              :  *****************************************************************************/
   11493              : 
   11494              : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11495              :                 AS SelectStmt opt_check_option
   11496              :                 {
   11497         8558 :                     ViewStmt   *n = makeNode(ViewStmt);
   11498              : 
   11499         8558 :                     n->view = $4;
   11500         8558 :                     n->view->relpersistence = $2;
   11501         8558 :                     n->aliases = $5;
   11502         8558 :                     n->query = $8;
   11503         8558 :                     n->replace = false;
   11504         8558 :                     n->options = $6;
   11505         8558 :                     n->withCheckOption = $9;
   11506         8558 :                     $$ = (Node *) n;
   11507              :                 }
   11508              :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11509              :                 AS SelectStmt opt_check_option
   11510              :                 {
   11511          122 :                     ViewStmt   *n = makeNode(ViewStmt);
   11512              : 
   11513          122 :                     n->view = $6;
   11514          122 :                     n->view->relpersistence = $4;
   11515          122 :                     n->aliases = $7;
   11516          122 :                     n->query = $10;
   11517          122 :                     n->replace = true;
   11518          122 :                     n->options = $8;
   11519          122 :                     n->withCheckOption = $11;
   11520          122 :                     $$ = (Node *) n;
   11521              :                 }
   11522              :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11523              :                 AS SelectStmt opt_check_option
   11524              :                 {
   11525            4 :                     ViewStmt   *n = makeNode(ViewStmt);
   11526              : 
   11527            4 :                     n->view = $5;
   11528            4 :                     n->view->relpersistence = $2;
   11529            4 :                     n->aliases = $7;
   11530            4 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11531            4 :                     n->replace = false;
   11532            4 :                     n->options = $9;
   11533            4 :                     n->withCheckOption = $12;
   11534            4 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11535            0 :                         ereport(ERROR,
   11536              :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11537              :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11538              :                                  parser_errposition(@12)));
   11539            4 :                     $$ = (Node *) n;
   11540              :                 }
   11541              :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11542              :                 AS SelectStmt opt_check_option
   11543              :                 {
   11544            3 :                     ViewStmt   *n = makeNode(ViewStmt);
   11545              : 
   11546            3 :                     n->view = $7;
   11547            3 :                     n->view->relpersistence = $4;
   11548            3 :                     n->aliases = $9;
   11549            3 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11550            3 :                     n->replace = true;
   11551            3 :                     n->options = $11;
   11552            3 :                     n->withCheckOption = $14;
   11553            3 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11554            0 :                         ereport(ERROR,
   11555              :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11556              :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11557              :                                  parser_errposition(@14)));
   11558            3 :                     $$ = (Node *) n;
   11559              :                 }
   11560              :         ;
   11561              : 
   11562              : opt_check_option:
   11563           48 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11564            3 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11565           12 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11566         8624 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11567              :         ;
   11568              : 
   11569              : /*****************************************************************************
   11570              :  *
   11571              :  *      QUERY:
   11572              :  *              LOAD "filename"
   11573              :  *
   11574              :  *****************************************************************************/
   11575              : 
   11576              : LoadStmt:   LOAD file_name
   11577              :                 {
   11578           32 :                     LoadStmt   *n = makeNode(LoadStmt);
   11579              : 
   11580           32 :                     n->filename = $2;
   11581           32 :                     $$ = (Node *) n;
   11582              :                 }
   11583              :         ;
   11584              : 
   11585              : 
   11586              : /*****************************************************************************
   11587              :  *
   11588              :  *      CREATE DATABASE
   11589              :  *
   11590              :  *****************************************************************************/
   11591              : 
   11592              : CreatedbStmt:
   11593              :             CREATE DATABASE name opt_with createdb_opt_list
   11594              :                 {
   11595          420 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11596              : 
   11597          420 :                     n->dbname = $3;
   11598          420 :                     n->options = $5;
   11599          420 :                     $$ = (Node *) n;
   11600              :                 }
   11601              :         ;
   11602              : 
   11603              : createdb_opt_list:
   11604          342 :             createdb_opt_items                      { $$ = $1; }
   11605          112 :             | /* EMPTY */                           { $$ = NIL; }
   11606              :         ;
   11607              : 
   11608              : createdb_opt_items:
   11609          342 :             createdb_opt_item                       { $$ = list_make1($1); }
   11610          515 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11611              :         ;
   11612              : 
   11613              : createdb_opt_item:
   11614              :             createdb_opt_name opt_equal NumericOnly
   11615              :                 {
   11616          137 :                     $$ = makeDefElem($1, $3, @1);
   11617              :                 }
   11618              :             | createdb_opt_name opt_equal opt_boolean_or_string
   11619              :                 {
   11620          720 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11621              :                 }
   11622              :             | createdb_opt_name opt_equal DEFAULT
   11623              :                 {
   11624            0 :                     $$ = makeDefElem($1, NULL, @1);
   11625              :                 }
   11626              :         ;
   11627              : 
   11628              : /*
   11629              :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11630              :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11631              :  * we need, and allow IDENT so that database option names don't have to be
   11632              :  * parser keywords unless they are already keywords for other reasons.
   11633              :  *
   11634              :  * XXX this coding technique is fragile since if someone makes a formerly
   11635              :  * non-keyword option name into a keyword and forgets to add it here, the
   11636              :  * option will silently break.  Best defense is to provide a regression test
   11637              :  * exercising every such option, at least at the syntax level.
   11638              :  */
   11639              : createdb_opt_name:
   11640          596 :             IDENT                           { $$ = $1; }
   11641            1 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11642           54 :             | ENCODING                      { $$ = pstrdup($1); }
   11643            0 :             | LOCATION                      { $$ = pstrdup($1); }
   11644            1 :             | OWNER                         { $$ = pstrdup($1); }
   11645           17 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11646          188 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11647              :         ;
   11648              : 
   11649              : /*
   11650              :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11651              :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11652              :  */
   11653              : opt_equal:  '='
   11654              :             | /*EMPTY*/
   11655              :         ;
   11656              : 
   11657              : 
   11658              : /*****************************************************************************
   11659              :  *
   11660              :  *      ALTER DATABASE
   11661              :  *
   11662              :  *****************************************************************************/
   11663              : 
   11664              : AlterDatabaseStmt:
   11665              :             ALTER DATABASE name WITH createdb_opt_list
   11666              :                  {
   11667            1 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11668              : 
   11669            1 :                     n->dbname = $3;
   11670            1 :                     n->options = $5;
   11671            1 :                     $$ = (Node *) n;
   11672              :                  }
   11673              :             | ALTER DATABASE name createdb_opt_list
   11674              :                  {
   11675           33 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11676              : 
   11677           33 :                     n->dbname = $3;
   11678           33 :                     n->options = $4;
   11679           33 :                     $$ = (Node *) n;
   11680              :                  }
   11681              :             | ALTER DATABASE name SET TABLESPACE name
   11682              :                  {
   11683           12 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11684              : 
   11685           12 :                     n->dbname = $3;
   11686           12 :                     n->options = list_make1(makeDefElem("tablespace",
   11687              :                                                         (Node *) makeString($6), @6));
   11688           12 :                     $$ = (Node *) n;
   11689              :                  }
   11690              :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11691              :                  {
   11692            3 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11693              : 
   11694            3 :                     n->dbname = $3;
   11695            3 :                     $$ = (Node *) n;
   11696              :                  }
   11697              :         ;
   11698              : 
   11699              : AlterDatabaseSetStmt:
   11700              :             ALTER DATABASE name SetResetClause
   11701              :                 {
   11702          639 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11703              : 
   11704          639 :                     n->dbname = $3;
   11705          639 :                     n->setstmt = $4;
   11706          639 :                     $$ = (Node *) n;
   11707              :                 }
   11708              :         ;
   11709              : 
   11710              : 
   11711              : /*****************************************************************************
   11712              :  *
   11713              :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11714              :  *
   11715              :  * This is implicitly CASCADE, no need for drop behavior
   11716              :  *****************************************************************************/
   11717              : 
   11718              : DropdbStmt: DROP DATABASE name
   11719              :                 {
   11720           49 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11721              : 
   11722           49 :                     n->dbname = $3;
   11723           49 :                     n->missing_ok = false;
   11724           49 :                     n->options = NULL;
   11725           49 :                     $$ = (Node *) n;
   11726              :                 }
   11727              :             | DROP DATABASE IF_P EXISTS name
   11728              :                 {
   11729            2 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11730              : 
   11731            2 :                     n->dbname = $5;
   11732            2 :                     n->missing_ok = true;
   11733            2 :                     n->options = NULL;
   11734            2 :                     $$ = (Node *) n;
   11735              :                 }
   11736              :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11737              :                 {
   11738            7 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11739              : 
   11740            7 :                     n->dbname = $3;
   11741            7 :                     n->missing_ok = false;
   11742            7 :                     n->options = $6;
   11743            7 :                     $$ = (Node *) n;
   11744              :                 }
   11745              :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11746              :                 {
   11747            6 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11748              : 
   11749            6 :                     n->dbname = $5;
   11750            6 :                     n->missing_ok = true;
   11751            6 :                     n->options = $8;
   11752            6 :                     $$ = (Node *) n;
   11753              :                 }
   11754              :         ;
   11755              : 
   11756              : drop_option_list:
   11757              :             drop_option
   11758              :                 {
   11759           13 :                     $$ = list_make1((Node *) $1);
   11760              :                 }
   11761              :             | drop_option_list ',' drop_option
   11762              :                 {
   11763            0 :                     $$ = lappend($1, (Node *) $3);
   11764              :                 }
   11765              :         ;
   11766              : 
   11767              : /*
   11768              :  * Currently only the FORCE option is supported, but the syntax is designed
   11769              :  * to be extensible so that we can add more options in the future if required.
   11770              :  */
   11771              : drop_option:
   11772              :             FORCE
   11773              :                 {
   11774           13 :                     $$ = makeDefElem("force", NULL, @1);
   11775              :                 }
   11776              :         ;
   11777              : 
   11778              : /*****************************************************************************
   11779              :  *
   11780              :  *      ALTER COLLATION
   11781              :  *
   11782              :  *****************************************************************************/
   11783              : 
   11784              : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11785              :                 {
   11786            3 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11787              : 
   11788            3 :                     n->collname = $3;
   11789            3 :                     $$ = (Node *) n;
   11790              :                 }
   11791              :         ;
   11792              : 
   11793              : 
   11794              : /*****************************************************************************
   11795              :  *
   11796              :  *      ALTER SYSTEM
   11797              :  *
   11798              :  * This is used to change configuration parameters persistently.
   11799              :  *****************************************************************************/
   11800              : 
   11801              : AlterSystemStmt:
   11802              :             ALTER SYSTEM_P SET generic_set
   11803              :                 {
   11804           74 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11805              : 
   11806           74 :                     n->setstmt = $4;
   11807           74 :                     $$ = (Node *) n;
   11808              :                 }
   11809              :             | ALTER SYSTEM_P RESET generic_reset
   11810              :                 {
   11811           29 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11812              : 
   11813           29 :                     n->setstmt = $4;
   11814           29 :                     $$ = (Node *) n;
   11815              :                 }
   11816              :         ;
   11817              : 
   11818              : 
   11819              : /*****************************************************************************
   11820              :  *
   11821              :  * Manipulate a domain
   11822              :  *
   11823              :  *****************************************************************************/
   11824              : 
   11825              : CreateDomainStmt:
   11826              :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11827              :                 {
   11828          737 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11829              : 
   11830          737 :                     n->domainname = $3;
   11831          737 :                     n->typeName = $5;
   11832          737 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11833              :                                      yyscanner);
   11834          737 :                     $$ = (Node *) n;
   11835              :                 }
   11836              :         ;
   11837              : 
   11838              : AlterDomainStmt:
   11839              :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11840              :             ALTER DOMAIN_P any_name alter_column_default
   11841              :                 {
   11842            7 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11843              : 
   11844            7 :                     n->subtype = AD_AlterDefault;
   11845            7 :                     n->typeName = $3;
   11846            7 :                     n->def = $4;
   11847            7 :                     $$ = (Node *) n;
   11848              :                 }
   11849              :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11850              :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11851              :                 {
   11852            6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11853              : 
   11854            6 :                     n->subtype = AD_DropNotNull;
   11855            6 :                     n->typeName = $3;
   11856            6 :                     $$ = (Node *) n;
   11857              :                 }
   11858              :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11859              :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11860              :                 {
   11861           12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11862              : 
   11863           12 :                     n->subtype = AD_SetNotNull;
   11864           12 :                     n->typeName = $3;
   11865           12 :                     $$ = (Node *) n;
   11866              :                 }
   11867              :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11868              :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11869              :                 {
   11870           91 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11871              : 
   11872           91 :                     n->subtype = AD_AddConstraint;
   11873           91 :                     n->typeName = $3;
   11874           91 :                     n->def = $5;
   11875           91 :                     $$ = (Node *) n;
   11876              :                 }
   11877              :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11878              :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11879              :                 {
   11880           27 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11881              : 
   11882           27 :                     n->subtype = AD_DropConstraint;
   11883           27 :                     n->typeName = $3;
   11884           27 :                     n->name = $6;
   11885           27 :                     n->behavior = $7;
   11886           27 :                     n->missing_ok = false;
   11887           27 :                     $$ = (Node *) n;
   11888              :                 }
   11889              :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11890              :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11891              :                 {
   11892            3 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11893              : 
   11894            3 :                     n->subtype = AD_DropConstraint;
   11895            3 :                     n->typeName = $3;
   11896            3 :                     n->name = $8;
   11897            3 :                     n->behavior = $9;
   11898            3 :                     n->missing_ok = true;
   11899            3 :                     $$ = (Node *) n;
   11900              :                 }
   11901              :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11902              :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11903              :                 {
   11904            6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11905              : 
   11906            6 :                     n->subtype = AD_ValidateConstraint;
   11907            6 :                     n->typeName = $3;
   11908            6 :                     n->name = $6;
   11909            6 :                     $$ = (Node *) n;
   11910              :                 }
   11911              :             ;
   11912              : 
   11913              : opt_as:     AS
   11914              :             | /* EMPTY */
   11915              :         ;
   11916              : 
   11917              : 
   11918              : /*****************************************************************************
   11919              :  *
   11920              :  * Manipulate a text search dictionary or configuration
   11921              :  *
   11922              :  *****************************************************************************/
   11923              : 
   11924              : AlterTSDictionaryStmt:
   11925              :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11926              :                 {
   11927           20 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11928              : 
   11929           20 :                     n->dictname = $5;
   11930           20 :                     n->options = $6;
   11931           20 :                     $$ = (Node *) n;
   11932              :                 }
   11933              :         ;
   11934              : 
   11935              : AlterTSConfigurationStmt:
   11936              :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11937              :                 {
   11938         4640 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11939              : 
   11940         4640 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11941         4640 :                     n->cfgname = $5;
   11942         4640 :                     n->tokentype = $9;
   11943         4640 :                     n->dicts = $11;
   11944         4640 :                     n->override = false;
   11945         4640 :                     n->replace = false;
   11946         4640 :                     $$ = (Node *) n;
   11947              :                 }
   11948              :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11949              :                 {
   11950           13 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11951              : 
   11952           13 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11953           13 :                     n->cfgname = $5;
   11954           13 :                     n->tokentype = $9;
   11955           13 :                     n->dicts = $11;
   11956           13 :                     n->override = true;
   11957           13 :                     n->replace = false;
   11958           13 :                     $$ = (Node *) n;
   11959              :                 }
   11960              :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11961              :                 {
   11962            9 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11963              : 
   11964            9 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11965            9 :                     n->cfgname = $5;
   11966            9 :                     n->tokentype = NIL;
   11967            9 :                     n->dicts = list_make2($9,$11);
   11968            9 :                     n->override = false;
   11969            9 :                     n->replace = true;
   11970            9 :                     $$ = (Node *) n;
   11971              :                 }
   11972              :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11973              :                 {
   11974            0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11975              : 
   11976            0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11977            0 :                     n->cfgname = $5;
   11978            0 :                     n->tokentype = $9;
   11979            0 :                     n->dicts = list_make2($11,$13);
   11980            0 :                     n->override = false;
   11981            0 :                     n->replace = true;
   11982            0 :                     $$ = (Node *) n;
   11983              :                 }
   11984              :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11985              :                 {
   11986            9 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11987              : 
   11988            9 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11989            9 :                     n->cfgname = $5;
   11990            9 :                     n->tokentype = $9;
   11991            9 :                     n->missing_ok = false;
   11992            9 :                     $$ = (Node *) n;
   11993              :                 }
   11994              :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11995              :                 {
   11996            6 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11997              : 
   11998            6 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11999            6 :                     n->cfgname = $5;
   12000            6 :                     n->tokentype = $11;
   12001            6 :                     n->missing_ok = true;
   12002            6 :                     $$ = (Node *) n;
   12003              :                 }
   12004              :         ;
   12005              : 
   12006              : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   12007              : any_with:   WITH
   12008              :             | WITH_LA
   12009              :         ;
   12010              : 
   12011              : 
   12012              : /*****************************************************************************
   12013              :  *
   12014              :  * Manipulate a conversion
   12015              :  *
   12016              :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   12017              :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   12018              :  *
   12019              :  *****************************************************************************/
   12020              : 
   12021              : CreateConversionStmt:
   12022              :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   12023              :             TO Sconst FROM any_name
   12024              :             {
   12025           32 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   12026              : 
   12027           32 :                 n->conversion_name = $4;
   12028           32 :                 n->for_encoding_name = $6;
   12029           32 :                 n->to_encoding_name = $8;
   12030           32 :                 n->func_name = $10;
   12031           32 :                 n->def = $2;
   12032           32 :                 $$ = (Node *) n;
   12033              :             }
   12034              :         ;
   12035              : 
   12036              : /*****************************************************************************
   12037              :  *
   12038              :  *      QUERY:
   12039              :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   12040              :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   12041              :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   12042              :  *
   12043              :  *****************************************************************************/
   12044              : 
   12045              : ClusterStmt:
   12046              :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   12047              :                 {
   12048            0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12049              : 
   12050            0 :                     n->relation = $5;
   12051            0 :                     n->indexname = $6;
   12052            0 :                     n->params = $3;
   12053            0 :                     $$ = (Node *) n;
   12054              :                 }
   12055              :             | CLUSTER opt_utility_option_list
   12056              :                 {
   12057            8 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12058              : 
   12059            8 :                     n->relation = NULL;
   12060            8 :                     n->indexname = NULL;
   12061            8 :                     n->params = $2;
   12062            8 :                     $$ = (Node *) n;
   12063              :                 }
   12064              :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   12065              :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   12066              :                 {
   12067           96 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12068              : 
   12069           96 :                     n->relation = $3;
   12070           96 :                     n->indexname = $4;
   12071           96 :                     if ($2)
   12072            0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12073           96 :                     $$ = (Node *) n;
   12074              :                 }
   12075              :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   12076              :             | CLUSTER VERBOSE
   12077              :                 {
   12078            3 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12079              : 
   12080            3 :                     n->relation = NULL;
   12081            3 :                     n->indexname = NULL;
   12082            3 :                     n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12083            3 :                     $$ = (Node *) n;
   12084              :                 }
   12085              :             /* kept for pre-8.3 compatibility */
   12086              :             | CLUSTER opt_verbose name ON qualified_name
   12087              :                 {
   12088           10 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12089              : 
   12090           10 :                     n->relation = $5;
   12091           10 :                     n->indexname = $3;
   12092           10 :                     if ($2)
   12093            0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12094           10 :                     $$ = (Node *) n;
   12095              :                 }
   12096              :         ;
   12097              : 
   12098              : cluster_index_specification:
   12099           78 :             USING name              { $$ = $2; }
   12100           18 :             | /*EMPTY*/             { $$ = NULL; }
   12101              :         ;
   12102              : 
   12103              : 
   12104              : /*****************************************************************************
   12105              :  *
   12106              :  *      QUERY:
   12107              :  *              VACUUM
   12108              :  *              ANALYZE
   12109              :  *
   12110              :  *****************************************************************************/
   12111              : 
   12112              : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   12113              :                 {
   12114          631 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12115              : 
   12116          631 :                     n->options = NIL;
   12117          631 :                     if ($2)
   12118           76 :                         n->options = lappend(n->options,
   12119           76 :                                              makeDefElem("full", NULL, @2));
   12120          631 :                     if ($3)
   12121           82 :                         n->options = lappend(n->options,
   12122           82 :                                              makeDefElem("freeze", NULL, @3));
   12123          631 :                     if ($4)
   12124            9 :                         n->options = lappend(n->options,
   12125            9 :                                              makeDefElem("verbose", NULL, @4));
   12126          631 :                     if ($5)
   12127          152 :                         n->options = lappend(n->options,
   12128          152 :                                              makeDefElem("analyze", NULL, @5));
   12129          631 :                     n->rels = $6;
   12130          631 :                     n->is_vacuumcmd = true;
   12131          631 :                     $$ = (Node *) n;
   12132              :                 }
   12133              :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   12134              :                 {
   12135         4294 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12136              : 
   12137         4294 :                     n->options = $3;
   12138         4294 :                     n->rels = $5;
   12139         4294 :                     n->is_vacuumcmd = true;
   12140         4294 :                     $$ = (Node *) n;
   12141              :                 }
   12142              :         ;
   12143              : 
   12144              : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
   12145              :                 {
   12146         2420 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12147              : 
   12148         2420 :                     n->options = $2;
   12149         2420 :                     n->rels = $3;
   12150         2420 :                     n->is_vacuumcmd = false;
   12151         2420 :                     $$ = (Node *) n;
   12152              :                 }
   12153              :             | analyze_keyword VERBOSE opt_vacuum_relation_list
   12154              :                 {
   12155            0 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12156              : 
   12157            0 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12158            0 :                     n->rels = $3;
   12159            0 :                     n->is_vacuumcmd = false;
   12160            0 :                     $$ = (Node *) n;
   12161              :                 }
   12162              :         ;
   12163              : 
   12164              : analyze_keyword:
   12165              :             ANALYZE
   12166              :             | ANALYSE /* British */
   12167              :         ;
   12168              : 
   12169              : opt_analyze:
   12170          152 :             analyze_keyword                         { $$ = true; }
   12171          479 :             | /*EMPTY*/                             { $$ = false; }
   12172              :         ;
   12173              : 
   12174              : opt_verbose:
   12175            9 :             VERBOSE                                 { $$ = true; }
   12176         1886 :             | /*EMPTY*/                             { $$ = false; }
   12177              :         ;
   12178              : 
   12179           76 : opt_full:   FULL                                    { $$ = true; }
   12180          555 :             | /*EMPTY*/                             { $$ = false; }
   12181              :         ;
   12182              : 
   12183           82 : opt_freeze: FREEZE                                  { $$ = true; }
   12184          549 :             | /*EMPTY*/                             { $$ = false; }
   12185              :         ;
   12186              : 
   12187              : opt_name_list:
   12188         1499 :             '(' name_list ')'                       { $$ = $2; }
   12189         8729 :             | /*EMPTY*/                             { $$ = NIL; }
   12190              :         ;
   12191              : 
   12192              : vacuum_relation:
   12193              :             relation_expr opt_name_list
   12194              :                 {
   12195         7256 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12196              :                 }
   12197              :         ;
   12198              : 
   12199              : vacuum_relation_list:
   12200              :             vacuum_relation
   12201         7159 :                     { $$ = list_make1($1); }
   12202              :             | vacuum_relation_list ',' vacuum_relation
   12203           97 :                     { $$ = lappend($1, $3); }
   12204              :         ;
   12205              : 
   12206              : opt_vacuum_relation_list:
   12207         7159 :             vacuum_relation_list                    { $$ = $1; }
   12208          186 :             | /*EMPTY*/                             { $$ = NIL; }
   12209              :         ;
   12210              : 
   12211              : 
   12212              : /*****************************************************************************
   12213              :  *
   12214              :  *      QUERY:
   12215              :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12216              :  *              EXPLAIN ( options ) query
   12217              :  *
   12218              :  *****************************************************************************/
   12219              : 
   12220              : ExplainStmt:
   12221              :         EXPLAIN ExplainableStmt
   12222              :                 {
   12223         3893 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12224              : 
   12225         3893 :                     n->query = $2;
   12226         3893 :                     n->options = NIL;
   12227         3893 :                     $$ = (Node *) n;
   12228              :                 }
   12229              :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12230              :                 {
   12231         1158 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12232              : 
   12233         1158 :                     n->query = $4;
   12234         1158 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12235         1158 :                     if ($3)
   12236            0 :                         n->options = lappend(n->options,
   12237            0 :                                              makeDefElem("verbose", NULL, @3));
   12238         1158 :                     $$ = (Node *) n;
   12239              :                 }
   12240              :         | EXPLAIN VERBOSE ExplainableStmt
   12241              :                 {
   12242            6 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12243              : 
   12244            6 :                     n->query = $3;
   12245            6 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12246            6 :                     $$ = (Node *) n;
   12247              :                 }
   12248              :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12249              :                 {
   12250         7447 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12251              : 
   12252         7447 :                     n->query = $5;
   12253         7447 :                     n->options = $3;
   12254         7447 :                     $$ = (Node *) n;
   12255              :                 }
   12256              :         ;
   12257              : 
   12258              : ExplainableStmt:
   12259              :             SelectStmt
   12260              :             | InsertStmt
   12261              :             | UpdateStmt
   12262              :             | DeleteStmt
   12263              :             | MergeStmt
   12264              :             | DeclareCursorStmt
   12265              :             | CreateAsStmt
   12266              :             | CreateMatViewStmt
   12267              :             | RefreshMatViewStmt
   12268              :             | ExecuteStmt                   /* by default all are $$=$1 */
   12269              :         ;
   12270              : 
   12271              : /*****************************************************************************
   12272              :  *
   12273              :  *      QUERY:
   12274              :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12275              :  *
   12276              :  *****************************************************************************/
   12277              : 
   12278              : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12279              :                 {
   12280         1076 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12281              : 
   12282         1076 :                     n->name = $2;
   12283         1076 :                     n->argtypes = $3;
   12284         1076 :                     n->query = $5;
   12285         1076 :                     $$ = (Node *) n;
   12286              :                 }
   12287              :         ;
   12288              : 
   12289          915 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12290          170 :                 | /* EMPTY */               { $$ = NIL; }
   12291              :         ;
   12292              : 
   12293              : PreparableStmt:
   12294              :             SelectStmt
   12295              :             | InsertStmt
   12296              :             | UpdateStmt
   12297              :             | DeleteStmt
   12298              :             | MergeStmt                     /* by default all are $$=$1 */
   12299              :         ;
   12300              : 
   12301              : /*****************************************************************************
   12302              :  *
   12303              :  * EXECUTE <plan_name> [(params, ...)]
   12304              :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12305              :  *
   12306              :  *****************************************************************************/
   12307              : 
   12308              : ExecuteStmt: EXECUTE name execute_param_clause
   12309              :                 {
   12310         8348 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12311              : 
   12312         8348 :                     n->name = $2;
   12313         8348 :                     n->params = $3;
   12314         8348 :                     $$ = (Node *) n;
   12315              :                 }
   12316              :             | CREATE OptTemp TABLE create_as_target AS
   12317              :                 EXECUTE name execute_param_clause opt_with_data
   12318              :                 {
   12319           38 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12320           38 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12321              : 
   12322           38 :                     n->name = $7;
   12323           38 :                     n->params = $8;
   12324           38 :                     ctas->query = (Node *) n;
   12325           38 :                     ctas->into = $4;
   12326           38 :                     ctas->objtype = OBJECT_TABLE;
   12327           38 :                     ctas->is_select_into = false;
   12328           38 :                     ctas->if_not_exists = false;
   12329              :                     /* cram additional flags into the IntoClause */
   12330           38 :                     $4->rel->relpersistence = $2;
   12331           38 :                     $4->skipData = !($9);
   12332           38 :                     $$ = (Node *) ctas;
   12333              :                 }
   12334              :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12335              :                 EXECUTE name execute_param_clause opt_with_data
   12336              :                 {
   12337            6 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12338            6 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12339              : 
   12340            6 :                     n->name = $10;
   12341            6 :                     n->params = $11;
   12342            6 :                     ctas->query = (Node *) n;
   12343            6 :                     ctas->into = $7;
   12344            6 :                     ctas->objtype = OBJECT_TABLE;
   12345            6 :                     ctas->is_select_into = false;
   12346            6 :                     ctas->if_not_exists = true;
   12347              :                     /* cram additional flags into the IntoClause */
   12348            6 :                     $7->rel->relpersistence = $2;
   12349            6 :                     $7->skipData = !($12);
   12350            6 :                     $$ = (Node *) ctas;
   12351              :                 }
   12352              :         ;
   12353              : 
   12354         7811 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12355          581 :                     | /* EMPTY */                   { $$ = NIL; }
   12356              :                     ;
   12357              : 
   12358              : /*****************************************************************************
   12359              :  *
   12360              :  *      QUERY:
   12361              :  *              DEALLOCATE [PREPARE] <plan_name>
   12362              :  *
   12363              :  *****************************************************************************/
   12364              : 
   12365              : DeallocateStmt: DEALLOCATE name
   12366              :                     {
   12367         2005 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12368              : 
   12369         2005 :                         n->name = $2;
   12370         2005 :                         n->isall = false;
   12371         2005 :                         n->location = @2;
   12372         2005 :                         $$ = (Node *) n;
   12373              :                     }
   12374              :                 | DEALLOCATE PREPARE name
   12375              :                     {
   12376           10 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12377              : 
   12378           10 :                         n->name = $3;
   12379           10 :                         n->isall = false;
   12380           10 :                         n->location = @3;
   12381           10 :                         $$ = (Node *) n;
   12382              :                     }
   12383              :                 | DEALLOCATE ALL
   12384              :                     {
   12385           35 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12386              : 
   12387           35 :                         n->name = NULL;
   12388           35 :                         n->isall = true;
   12389           35 :                         n->location = -1;
   12390           35 :                         $$ = (Node *) n;
   12391              :                     }
   12392              :                 | DEALLOCATE PREPARE ALL
   12393              :                     {
   12394            1 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12395              : 
   12396            1 :                         n->name = NULL;
   12397            1 :                         n->isall = true;
   12398            1 :                         n->location = -1;
   12399            1 :                         $$ = (Node *) n;
   12400              :                     }
   12401              :         ;
   12402              : 
   12403              : /*****************************************************************************
   12404              :  *
   12405              :  *      QUERY:
   12406              :  *              INSERT STATEMENTS
   12407              :  *
   12408              :  *****************************************************************************/
   12409              : 
   12410              : InsertStmt:
   12411              :             opt_with_clause INSERT INTO insert_target insert_rest
   12412              :             opt_on_conflict returning_clause
   12413              :                 {
   12414        36399 :                     $5->relation = $4;
   12415        36399 :                     $5->onConflictClause = $6;
   12416        36399 :                     $5->returningClause = $7;
   12417        36399 :                     $5->withClause = $1;
   12418        36399 :                     $$ = (Node *) $5;
   12419              :                 }
   12420              :         ;
   12421              : 
   12422              : /*
   12423              :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12424              :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12425              :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12426              :  * divergence from other places.  So just require AS for now.
   12427              :  */
   12428              : insert_target:
   12429              :             qualified_name
   12430              :                 {
   12431        36318 :                     $$ = $1;
   12432              :                 }
   12433              :             | qualified_name AS ColId
   12434              :                 {
   12435           84 :                     $1->alias = makeAlias($3, NIL);
   12436           84 :                     $$ = $1;
   12437              :                 }
   12438              :         ;
   12439              : 
   12440              : insert_rest:
   12441              :             SelectStmt
   12442              :                 {
   12443        23579 :                     $$ = makeNode(InsertStmt);
   12444        23579 :                     $$->cols = NIL;
   12445        23579 :                     $$->selectStmt = $1;
   12446              :                 }
   12447              :             | OVERRIDING override_kind VALUE_P SelectStmt
   12448              :                 {
   12449           48 :                     $$ = makeNode(InsertStmt);
   12450           48 :                     $$->cols = NIL;
   12451           48 :                     $$->override = $2;
   12452           48 :                     $$->selectStmt = $4;
   12453              :                 }
   12454              :             | '(' insert_column_list ')' SelectStmt
   12455              :                 {
   12456         7359 :                     $$ = makeNode(InsertStmt);
   12457         7359 :                     $$->cols = $2;
   12458         7359 :                     $$->selectStmt = $4;
   12459              :                 }
   12460              :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12461              :                 {
   12462            0 :                     $$ = makeNode(InsertStmt);
   12463            0 :                     $$->cols = $2;
   12464            0 :                     $$->override = $5;
   12465            0 :                     $$->selectStmt = $7;
   12466              :                 }
   12467              :             | DEFAULT VALUES
   12468              :                 {
   12469         5416 :                     $$ = makeNode(InsertStmt);
   12470         5416 :                     $$->cols = NIL;
   12471         5416 :                     $$->selectStmt = NULL;
   12472              :                 }
   12473              :         ;
   12474              : 
   12475              : override_kind:
   12476           33 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12477           30 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12478              :         ;
   12479              : 
   12480              : insert_column_list:
   12481              :             insert_column_item
   12482         7526 :                     { $$ = list_make1($1); }
   12483              :             | insert_column_list ',' insert_column_item
   12484         8300 :                     { $$ = lappend($1, $3); }
   12485              :         ;
   12486              : 
   12487              : insert_column_item:
   12488              :             ColId opt_indirection
   12489              :                 {
   12490        15826 :                     $$ = makeNode(ResTarget);
   12491        15826 :                     $$->name = $1;
   12492        15826 :                     $$->indirection = check_indirection($2, yyscanner);
   12493        15826 :                     $$->val = NULL;
   12494        15826 :                     $$->location = @1;
   12495              :                 }
   12496              :         ;
   12497              : 
   12498              : opt_on_conflict:
   12499              :             ON CONFLICT opt_conf_expr DO SELECT opt_for_locking_strength where_clause
   12500              :                 {
   12501          183 :                     $$ = makeNode(OnConflictClause);
   12502          183 :                     $$->action = ONCONFLICT_SELECT;
   12503          183 :                     $$->infer = $3;
   12504          183 :                     $$->targetList = NIL;
   12505          183 :                     $$->lockStrength = $6;
   12506          183 :                     $$->whereClause = $7;
   12507          183 :                     $$->location = @1;
   12508              :                 }
   12509              :             |
   12510              :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12511              :                 {
   12512          700 :                     $$ = makeNode(OnConflictClause);
   12513          700 :                     $$->action = ONCONFLICT_UPDATE;
   12514          700 :                     $$->infer = $3;
   12515          700 :                     $$->targetList = $7;
   12516          700 :                     $$->lockStrength = LCS_NONE;
   12517          700 :                     $$->whereClause = $8;
   12518          700 :                     $$->location = @1;
   12519              :                 }
   12520              :             |
   12521              :             ON CONFLICT opt_conf_expr DO NOTHING
   12522              :                 {
   12523          302 :                     $$ = makeNode(OnConflictClause);
   12524          302 :                     $$->action = ONCONFLICT_NOTHING;
   12525          302 :                     $$->infer = $3;
   12526          302 :                     $$->targetList = NIL;
   12527          302 :                     $$->lockStrength = LCS_NONE;
   12528          302 :                     $$->whereClause = NULL;
   12529          302 :                     $$->location = @1;
   12530              :                 }
   12531              :             | /*EMPTY*/
   12532              :                 {
   12533        35217 :                     $$ = NULL;
   12534              :                 }
   12535              :         ;
   12536              : 
   12537              : opt_conf_expr:
   12538              :             '(' index_params ')' where_clause
   12539              :                 {
   12540          954 :                     $$ = makeNode(InferClause);
   12541          954 :                     $$->indexElems = $2;
   12542          954 :                     $$->whereClause = $4;
   12543          954 :                     $$->conname = NULL;
   12544          954 :                     $$->location = @1;
   12545              :                 }
   12546              :             |
   12547              :             ON CONSTRAINT name
   12548              :                 {
   12549          105 :                     $$ = makeNode(InferClause);
   12550          105 :                     $$->indexElems = NIL;
   12551          105 :                     $$->whereClause = NULL;
   12552          105 :                     $$->conname = $3;
   12553          105 :                     $$->location = @1;
   12554              :                 }
   12555              :             | /*EMPTY*/
   12556              :                 {
   12557          126 :                     $$ = NULL;
   12558              :                 }
   12559              :         ;
   12560              : 
   12561              : returning_clause:
   12562              :             RETURNING returning_with_clause target_list
   12563              :                 {
   12564         1845 :                     ReturningClause *n = makeNode(ReturningClause);
   12565              : 
   12566         1845 :                     n->options = $2;
   12567         1845 :                     n->exprs = $3;
   12568         1845 :                     $$ = n;
   12569              :                 }
   12570              :             | /* EMPTY */
   12571              :                 {
   12572        45506 :                     $$ = NULL;
   12573              :                 }
   12574              :         ;
   12575              : 
   12576              : returning_with_clause:
   12577           36 :             WITH '(' returning_options ')'      { $$ = $3; }
   12578         1809 :             | /* EMPTY */                       { $$ = NIL; }
   12579              :         ;
   12580              : 
   12581              : returning_options:
   12582           36 :             returning_option                            { $$ = list_make1($1); }
   12583           27 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12584              :         ;
   12585              : 
   12586              : returning_option:
   12587              :             returning_option_kind AS ColId
   12588              :                 {
   12589           63 :                     ReturningOption *n = makeNode(ReturningOption);
   12590              : 
   12591           63 :                     n->option = $1;
   12592           63 :                     n->value = $3;
   12593           63 :                     n->location = @1;
   12594           63 :                     $$ = (Node *) n;
   12595              :                 }
   12596              :         ;
   12597              : 
   12598              : returning_option_kind:
   12599           27 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12600           36 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12601              :         ;
   12602              : 
   12603              : 
   12604              : /*****************************************************************************
   12605              :  *
   12606              :  *      QUERY:
   12607              :  *              DELETE STATEMENTS
   12608              :  *
   12609              :  *****************************************************************************/
   12610              : 
   12611              : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12612              :             using_clause where_or_current_clause returning_clause
   12613              :                 {
   12614         2364 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12615              : 
   12616         2364 :                     n->relation = $4;
   12617         2364 :                     n->usingClause = $5;
   12618         2364 :                     n->whereClause = $6;
   12619         2364 :                     n->returningClause = $7;
   12620         2364 :                     n->withClause = $1;
   12621         2364 :                     $$ = (Node *) n;
   12622              :                 }
   12623              :         ;
   12624              : 
   12625              : using_clause:
   12626           54 :                 USING from_list                     { $$ = $2; }
   12627         2310 :             | /*EMPTY*/                             { $$ = NIL; }
   12628              :         ;
   12629              : 
   12630              : 
   12631              : /*****************************************************************************
   12632              :  *
   12633              :  *      QUERY:
   12634              :  *              LOCK TABLE
   12635              :  *
   12636              :  *****************************************************************************/
   12637              : 
   12638              : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12639              :                 {
   12640          575 :                     LockStmt   *n = makeNode(LockStmt);
   12641              : 
   12642          575 :                     n->relations = $3;
   12643          575 :                     n->mode = $4;
   12644          575 :                     n->nowait = $5;
   12645          575 :                     $$ = (Node *) n;
   12646              :                 }
   12647              :         ;
   12648              : 
   12649          521 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12650           54 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12651              :         ;
   12652              : 
   12653          276 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12654            7 :             | ROW SHARE                     { $$ = RowShareLock; }
   12655           44 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12656           33 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12657           40 :             | SHARE                         { $$ = ShareLock; }
   12658            7 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12659           51 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12660           63 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12661              :         ;
   12662              : 
   12663           96 : opt_nowait: NOWAIT                          { $$ = true; }
   12664          494 :             | /*EMPTY*/                     { $$ = false; }
   12665              :         ;
   12666              : 
   12667              : opt_nowait_or_skip:
   12668           25 :             NOWAIT                          { $$ = LockWaitError; }
   12669           95 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12670         5389 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12671              :         ;
   12672              : 
   12673              : 
   12674              : /*****************************************************************************
   12675              :  *
   12676              :  *      QUERY:
   12677              :  *              UpdateStmt (UPDATE)
   12678              :  *
   12679              :  *****************************************************************************/
   12680              : 
   12681              : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12682              :             SET set_clause_list
   12683              :             from_clause
   12684              :             where_or_current_clause
   12685              :             returning_clause
   12686              :                 {
   12687         7496 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12688              : 
   12689         7496 :                     n->relation = $3;
   12690         7496 :                     n->targetList = $5;
   12691         7496 :                     n->fromClause = $6;
   12692         7496 :                     n->whereClause = $7;
   12693         7496 :                     n->returningClause = $8;
   12694         7496 :                     n->withClause = $1;
   12695         7496 :                     $$ = (Node *) n;
   12696              :                 }
   12697              :         ;
   12698              : 
   12699              : set_clause_list:
   12700         9013 :             set_clause                          { $$ = $1; }
   12701         2190 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12702              :         ;
   12703              : 
   12704              : set_clause:
   12705              :             set_target '=' a_expr
   12706              :                 {
   12707        11111 :                     $1->val = (Node *) $3;
   12708        11111 :                     $$ = list_make1($1);
   12709              :                 }
   12710              :             | '(' set_target_list ')' '=' a_expr
   12711              :                 {
   12712           92 :                     int         ncolumns = list_length($2);
   12713           92 :                     int         i = 1;
   12714              :                     ListCell   *col_cell;
   12715              : 
   12716              :                     /* Create a MultiAssignRef source for each target */
   12717          284 :                     foreach(col_cell, $2)
   12718              :                     {
   12719          192 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12720          192 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12721              : 
   12722          192 :                         r->source = (Node *) $5;
   12723          192 :                         r->colno = i;
   12724          192 :                         r->ncolumns = ncolumns;
   12725          192 :                         res_col->val = (Node *) r;
   12726          192 :                         i++;
   12727              :                     }
   12728              : 
   12729           92 :                     $$ = $2;
   12730              :                 }
   12731              :         ;
   12732              : 
   12733              : set_target:
   12734              :             ColId opt_indirection
   12735              :                 {
   12736        11306 :                     $$ = makeNode(ResTarget);
   12737        11306 :                     $$->name = $1;
   12738        11306 :                     $$->indirection = check_indirection($2, yyscanner);
   12739        11306 :                     $$->val = NULL;  /* upper production sets this */
   12740        11306 :                     $$->location = @1;
   12741              :                 }
   12742              :         ;
   12743              : 
   12744              : set_target_list:
   12745           95 :             set_target                              { $$ = list_make1($1); }
   12746          100 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12747              :         ;
   12748              : 
   12749              : 
   12750              : /*****************************************************************************
   12751              :  *
   12752              :  *      QUERY:
   12753              :  *              MERGE
   12754              :  *
   12755              :  *****************************************************************************/
   12756              : 
   12757              : MergeStmt:
   12758              :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12759              :             USING table_ref
   12760              :             ON a_expr
   12761              :             merge_when_list
   12762              :             returning_clause
   12763              :                 {
   12764         1092 :                     MergeStmt  *m = makeNode(MergeStmt);
   12765              : 
   12766         1092 :                     m->withClause = $1;
   12767         1092 :                     m->relation = $4;
   12768         1092 :                     m->sourceRelation = $6;
   12769         1092 :                     m->joinCondition = $8;
   12770         1092 :                     m->mergeWhenClauses = $9;
   12771         1092 :                     m->returningClause = $10;
   12772              : 
   12773         1092 :                     $$ = (Node *) m;
   12774              :                 }
   12775              :         ;
   12776              : 
   12777              : merge_when_list:
   12778         1092 :             merge_when_clause                       { $$ = list_make1($1); }
   12779          610 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12780              :         ;
   12781              : 
   12782              : /*
   12783              :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12784              :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12785              :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12786              :  * tuples, and only supports INSERT/DO NOTHING actions.
   12787              :  */
   12788              : merge_when_clause:
   12789              :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12790              :                 {
   12791          817 :                     $4->matchKind = $1;
   12792          817 :                     $4->condition = $2;
   12793              : 
   12794          817 :                     $$ = (Node *) $4;
   12795              :                 }
   12796              :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12797              :                 {
   12798          271 :                     $4->matchKind = $1;
   12799          271 :                     $4->condition = $2;
   12800              : 
   12801          271 :                     $$ = (Node *) $4;
   12802              :                 }
   12803              :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12804              :                 {
   12805          566 :                     $4->matchKind = $1;
   12806          566 :                     $4->condition = $2;
   12807              : 
   12808          566 :                     $$ = (Node *) $4;
   12809              :                 }
   12810              :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12811              :                 {
   12812           35 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12813              : 
   12814           35 :                     m->matchKind = $1;
   12815           35 :                     m->commandType = CMD_NOTHING;
   12816           35 :                     m->condition = $2;
   12817              : 
   12818           35 :                     $$ = (Node *) m;
   12819              :                 }
   12820              :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12821              :                 {
   12822           13 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12823              : 
   12824           13 :                     m->matchKind = $1;
   12825           13 :                     m->commandType = CMD_NOTHING;
   12826           13 :                     m->condition = $2;
   12827              : 
   12828           13 :                     $$ = (Node *) m;
   12829              :                 }
   12830              :         ;
   12831              : 
   12832              : merge_when_tgt_matched:
   12833         1039 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12834           93 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12835              :         ;
   12836              : 
   12837              : merge_when_tgt_not_matched:
   12838          582 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12839            9 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12840              :         ;
   12841              : 
   12842              : opt_merge_when_condition:
   12843          425 :             AND a_expr              { $$ = $2; }
   12844         1298 :             |                       { $$ = NULL; }
   12845              :         ;
   12846              : 
   12847              : merge_update:
   12848              :             UPDATE SET set_clause_list
   12849              :                 {
   12850          817 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12851          817 :                     n->commandType = CMD_UPDATE;
   12852          817 :                     n->override = OVERRIDING_NOT_SET;
   12853          817 :                     n->targetList = $3;
   12854          817 :                     n->values = NIL;
   12855              : 
   12856          817 :                     $$ = n;
   12857              :                 }
   12858              :         ;
   12859              : 
   12860              : merge_delete:
   12861              :             DELETE_P
   12862              :                 {
   12863          271 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12864          271 :                     n->commandType = CMD_DELETE;
   12865          271 :                     n->override = OVERRIDING_NOT_SET;
   12866          271 :                     n->targetList = NIL;
   12867          271 :                     n->values = NIL;
   12868              : 
   12869          271 :                     $$ = n;
   12870              :                 }
   12871              :         ;
   12872              : 
   12873              : merge_insert:
   12874              :             INSERT merge_values_clause
   12875              :                 {
   12876          381 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12877          381 :                     n->commandType = CMD_INSERT;
   12878          381 :                     n->override = OVERRIDING_NOT_SET;
   12879          381 :                     n->targetList = NIL;
   12880          381 :                     n->values = $2;
   12881          381 :                     $$ = n;
   12882              :                 }
   12883              :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12884              :                 {
   12885            0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12886            0 :                     n->commandType = CMD_INSERT;
   12887            0 :                     n->override = $3;
   12888            0 :                     n->targetList = NIL;
   12889            0 :                     n->values = $5;
   12890            0 :                     $$ = n;
   12891              :                 }
   12892              :             | INSERT '(' insert_column_list ')' merge_values_clause
   12893              :                 {
   12894          152 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12895          152 :                     n->commandType = CMD_INSERT;
   12896          152 :                     n->override = OVERRIDING_NOT_SET;
   12897          152 :                     n->targetList = $3;
   12898          152 :                     n->values = $5;
   12899          152 :                     $$ = n;
   12900              :                 }
   12901              :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12902              :                 {
   12903           15 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12904           15 :                     n->commandType = CMD_INSERT;
   12905           15 :                     n->override = $6;
   12906           15 :                     n->targetList = $3;
   12907           15 :                     n->values = $8;
   12908           15 :                     $$ = n;
   12909              :                 }
   12910              :             | INSERT DEFAULT VALUES
   12911              :                 {
   12912           18 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12913           18 :                     n->commandType = CMD_INSERT;
   12914           18 :                     n->override = OVERRIDING_NOT_SET;
   12915           18 :                     n->targetList = NIL;
   12916           18 :                     n->values = NIL;
   12917           18 :                     $$ = n;
   12918              :                 }
   12919              :         ;
   12920              : 
   12921              : merge_values_clause:
   12922              :             VALUES '(' expr_list ')'
   12923              :                 {
   12924          548 :                     $$ = $3;
   12925              :                 }
   12926              :         ;
   12927              : 
   12928              : /*****************************************************************************
   12929              :  *
   12930              :  *      QUERY:
   12931              :  *              CURSOR STATEMENTS
   12932              :  *
   12933              :  *****************************************************************************/
   12934              : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12935              :                 {
   12936         2313 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12937              : 
   12938         2313 :                     n->portalname = $2;
   12939              :                     /* currently we always set FAST_PLAN option */
   12940         2313 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12941         2313 :                     n->query = $7;
   12942         2313 :                     $$ = (Node *) n;
   12943              :                 }
   12944              :         ;
   12945              : 
   12946         7432 : cursor_name:    name                        { $$ = $1; }
   12947              :         ;
   12948              : 
   12949         2313 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12950           14 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12951          120 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12952            7 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12953            0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12954            3 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12955              :         ;
   12956              : 
   12957         2263 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12958           47 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12959            3 :             | WITHOUT HOLD                  { $$ = 0; }
   12960              :         ;
   12961              : 
   12962              : /*****************************************************************************
   12963              :  *
   12964              :  *      QUERY:
   12965              :  *              SELECT STATEMENTS
   12966              :  *
   12967              :  *****************************************************************************/
   12968              : 
   12969              : /* A complete SELECT statement looks like this.
   12970              :  *
   12971              :  * The rule returns either a single SelectStmt node or a tree of them,
   12972              :  * representing a set-operation tree.
   12973              :  *
   12974              :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12975              :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12976              :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12977              :  * To resolve the ambiguity, we are careful to define the grammar so that
   12978              :  * the decision is staved off as long as possible: as long as we can keep
   12979              :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12980              :  * it's no longer possible to do that will we decide that parens belong to
   12981              :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12982              :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12983              :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12984              :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12985              :  * SELECT viewpoint when we see the UNION.
   12986              :  *
   12987              :  * This approach is implemented by defining a nonterminal select_with_parens,
   12988              :  * which represents a SELECT with at least one outer layer of parentheses,
   12989              :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12990              :  * in the expression grammar.  We will then have shift-reduce conflicts
   12991              :  * which we can resolve in favor of always treating '(' <select> ')' as
   12992              :  * a select_with_parens.  To resolve the conflicts, the productions that
   12993              :  * conflict with the select_with_parens productions are manually given
   12994              :  * precedences lower than the precedence of ')', thereby ensuring that we
   12995              :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12996              :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12997              :  * precedence for this, which is a fairly arbitrary choice.
   12998              :  *
   12999              :  * To be able to define select_with_parens itself without ambiguity, we need
   13000              :  * a nonterminal select_no_parens that represents a SELECT structure with no
   13001              :  * outermost parentheses.  This is a little bit tedious, but it works.
   13002              :  *
   13003              :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   13004              :  * with or without outer parentheses.
   13005              :  */
   13006              : 
   13007              : SelectStmt: select_no_parens            %prec UMINUS
   13008              :             | select_with_parens        %prec UMINUS
   13009              :         ;
   13010              : 
   13011              : select_with_parens:
   13012        37394 :             '(' select_no_parens ')'                { $$ = $2; }
   13013           78 :             | '(' select_with_parens ')'            { $$ = $2; }
   13014              :         ;
   13015              : 
   13016              : /*
   13017              :  * This rule parses the equivalent of the standard's <query expression>.
   13018              :  * The duplicative productions are annoying, but hard to get rid of without
   13019              :  * creating shift/reduce conflicts.
   13020              :  *
   13021              :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   13022              :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   13023              :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   13024              :  * clause.
   13025              :  *  2002-08-28 bjm
   13026              :  */
   13027              : select_no_parens:
   13028       208334 :             simple_select                       { $$ = $1; }
   13029              :             | select_clause sort_clause
   13030              :                 {
   13031        37623 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   13032              :                                         NULL, NULL,
   13033              :                                         yyscanner);
   13034        37623 :                     $$ = $1;
   13035              :                 }
   13036              :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   13037              :                 {
   13038         5285 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   13039         5285 :                                         $4,
   13040              :                                         NULL,
   13041              :                                         yyscanner);
   13042         5285 :                     $$ = $1;
   13043              :                 }
   13044              :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   13045              :                 {
   13046         2573 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   13047         2573 :                                         $3,
   13048              :                                         NULL,
   13049              :                                         yyscanner);
   13050         2567 :                     $$ = $1;
   13051              :                 }
   13052              :             | with_clause select_clause
   13053              :                 {
   13054         1226 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   13055              :                                         NULL,
   13056         1226 :                                         $1,
   13057              :                                         yyscanner);
   13058         1226 :                     $$ = $2;
   13059              :                 }
   13060              :             | with_clause select_clause sort_clause
   13061              :                 {
   13062          316 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   13063              :                                         NULL,
   13064          316 :                                         $1,
   13065              :                                         yyscanner);
   13066          316 :                     $$ = $2;
   13067              :                 }
   13068              :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   13069              :                 {
   13070            3 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   13071            3 :                                         $5,
   13072            3 :                                         $1,
   13073              :                                         yyscanner);
   13074            3 :                     $$ = $2;
   13075              :                 }
   13076              :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   13077              :                 {
   13078           32 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   13079           32 :                                         $4,
   13080           32 :                                         $1,
   13081              :                                         yyscanner);
   13082           32 :                     $$ = $2;
   13083              :                 }
   13084              :         ;
   13085              : 
   13086              : select_clause:
   13087        67329 :             simple_select                           { $$ = $1; }
   13088          295 :             | select_with_parens                    { $$ = $1; }
   13089              :         ;
   13090              : 
   13091              : /*
   13092              :  * This rule parses SELECT statements that can appear within set operations,
   13093              :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   13094              :  * the ordering of the set operations.  Without '(' and ')' we want the
   13095              :  * operations to be ordered per the precedence specs at the head of this file.
   13096              :  *
   13097              :  * As with select_no_parens, simple_select cannot have outer parentheses,
   13098              :  * but can have parenthesized subclauses.
   13099              :  *
   13100              :  * It might appear that we could fold the first two alternatives into one
   13101              :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   13102              :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   13103              :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   13104              :  *
   13105              :  * Note that sort clauses cannot be included at this level --- SQL requires
   13106              :  *      SELECT foo UNION SELECT bar ORDER BY baz
   13107              :  * to be parsed as
   13108              :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   13109              :  * not
   13110              :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   13111              :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   13112              :  * described as part of the select_no_parens production, not simple_select.
   13113              :  * This does not limit functionality, because you can reintroduce these
   13114              :  * clauses inside parentheses.
   13115              :  *
   13116              :  * NOTE: only the leftmost component SelectStmt should have INTO.
   13117              :  * However, this is not checked by the grammar; parse analysis must check it.
   13118              :  */
   13119              : simple_select:
   13120              :             SELECT opt_all_clause opt_target_list
   13121              :             into_clause from_clause where_clause
   13122              :             group_clause having_clause window_clause
   13123              :                 {
   13124       231494 :                     SelectStmt *n = makeNode(SelectStmt);
   13125              : 
   13126       231494 :                     n->targetList = $3;
   13127       231494 :                     n->intoClause = $4;
   13128       231494 :                     n->fromClause = $5;
   13129       231494 :                     n->whereClause = $6;
   13130       231494 :                     n->groupClause = ($7)->list;
   13131       231494 :                     n->groupDistinct = ($7)->distinct;
   13132       231494 :                     n->groupByAll = ($7)->all;
   13133       231494 :                     n->havingClause = $8;
   13134       231494 :                     n->windowClause = $9;
   13135       231494 :                     $$ = (Node *) n;
   13136              :                 }
   13137              :             | SELECT distinct_clause target_list
   13138              :             into_clause from_clause where_clause
   13139              :             group_clause having_clause window_clause
   13140              :                 {
   13141         2109 :                     SelectStmt *n = makeNode(SelectStmt);
   13142              : 
   13143         2109 :                     n->distinctClause = $2;
   13144         2109 :                     n->targetList = $3;
   13145         2109 :                     n->intoClause = $4;
   13146         2109 :                     n->fromClause = $5;
   13147         2109 :                     n->whereClause = $6;
   13148         2109 :                     n->groupClause = ($7)->list;
   13149         2109 :                     n->groupDistinct = ($7)->distinct;
   13150         2109 :                     n->groupByAll = ($7)->all;
   13151         2109 :                     n->havingClause = $8;
   13152         2109 :                     n->windowClause = $9;
   13153         2109 :                     $$ = (Node *) n;
   13154              :                 }
   13155        31623 :             | values_clause                         { $$ = $1; }
   13156              :             | TABLE relation_expr
   13157              :                 {
   13158              :                     /* same as SELECT * FROM relation_expr */
   13159          157 :                     ColumnRef  *cr = makeNode(ColumnRef);
   13160          157 :                     ResTarget  *rt = makeNode(ResTarget);
   13161          157 :                     SelectStmt *n = makeNode(SelectStmt);
   13162              : 
   13163          157 :                     cr->fields = list_make1(makeNode(A_Star));
   13164          157 :                     cr->location = -1;
   13165              : 
   13166          157 :                     rt->name = NULL;
   13167          157 :                     rt->indirection = NIL;
   13168          157 :                     rt->val = (Node *) cr;
   13169          157 :                     rt->location = -1;
   13170              : 
   13171          157 :                     n->targetList = list_make1(rt);
   13172          157 :                     n->fromClause = list_make1($2);
   13173          157 :                     $$ = (Node *) n;
   13174              :                 }
   13175              :             | select_clause UNION set_quantifier select_clause
   13176              :                 {
   13177         9889 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13178              :                 }
   13179              :             | select_clause INTERSECT set_quantifier select_clause
   13180              :                 {
   13181          138 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13182              :                 }
   13183              :             | select_clause EXCEPT set_quantifier select_clause
   13184              :                 {
   13185          253 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13186              :                 }
   13187              :         ;
   13188              : 
   13189              : /*
   13190              :  * SQL standard WITH clause looks like:
   13191              :  *
   13192              :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13193              :  *      AS (query) [ SEARCH or CYCLE clause ]
   13194              :  *
   13195              :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13196              :  */
   13197              : with_clause:
   13198              :         WITH cte_list
   13199              :             {
   13200         1127 :                 $$ = makeNode(WithClause);
   13201         1127 :                 $$->ctes = $2;
   13202         1127 :                 $$->recursive = false;
   13203         1127 :                 $$->location = @1;
   13204              :             }
   13205              :         | WITH_LA cte_list
   13206              :             {
   13207            3 :                 $$ = makeNode(WithClause);
   13208            3 :                 $$->ctes = $2;
   13209            3 :                 $$->recursive = false;
   13210            3 :                 $$->location = @1;
   13211              :             }
   13212              :         | WITH RECURSIVE cte_list
   13213              :             {
   13214          690 :                 $$ = makeNode(WithClause);
   13215          690 :                 $$->ctes = $3;
   13216          690 :                 $$->recursive = true;
   13217          690 :                 $$->location = @1;
   13218              :             }
   13219              :         ;
   13220              : 
   13221              : cte_list:
   13222         1820 :         common_table_expr                       { $$ = list_make1($1); }
   13223          659 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13224              :         ;
   13225              : 
   13226              : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13227              :             {
   13228         2479 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13229              : 
   13230         2479 :                 n->ctename = $1;
   13231         2479 :                 n->aliascolnames = $2;
   13232         2479 :                 n->ctematerialized = $4;
   13233         2479 :                 n->ctequery = $6;
   13234         2479 :                 n->search_clause = castNode(CTESearchClause, $8);
   13235         2479 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13236         2479 :                 n->location = @1;
   13237         2479 :                 $$ = (Node *) n;
   13238              :             }
   13239              :         ;
   13240              : 
   13241              : opt_materialized:
   13242           89 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13243           24 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13244         2366 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13245              :         ;
   13246              : 
   13247              : opt_search_clause:
   13248              :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13249              :             {
   13250           45 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13251              : 
   13252           45 :                 n->search_col_list = $5;
   13253           45 :                 n->search_breadth_first = false;
   13254           45 :                 n->search_seq_column = $7;
   13255           45 :                 n->location = @1;
   13256           45 :                 $$ = (Node *) n;
   13257              :             }
   13258              :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13259              :             {
   13260           18 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13261              : 
   13262           18 :                 n->search_col_list = $5;
   13263           18 :                 n->search_breadth_first = true;
   13264           18 :                 n->search_seq_column = $7;
   13265           18 :                 n->location = @1;
   13266           18 :                 $$ = (Node *) n;
   13267              :             }
   13268              :         | /*EMPTY*/
   13269              :             {
   13270         2416 :                 $$ = NULL;
   13271              :             }
   13272              :         ;
   13273              : 
   13274              : opt_cycle_clause:
   13275              :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13276              :             {
   13277           33 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13278              : 
   13279           33 :                 n->cycle_col_list = $2;
   13280           33 :                 n->cycle_mark_column = $4;
   13281           33 :                 n->cycle_mark_value = $6;
   13282           33 :                 n->cycle_mark_default = $8;
   13283           33 :                 n->cycle_path_column = $10;
   13284           33 :                 n->location = @1;
   13285           33 :                 $$ = (Node *) n;
   13286              :             }
   13287              :         | CYCLE columnList SET ColId USING ColId
   13288              :             {
   13289           30 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13290              : 
   13291           30 :                 n->cycle_col_list = $2;
   13292           30 :                 n->cycle_mark_column = $4;
   13293           30 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13294           30 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13295           30 :                 n->cycle_path_column = $6;
   13296           30 :                 n->location = @1;
   13297           30 :                 $$ = (Node *) n;
   13298              :             }
   13299              :         | /*EMPTY*/
   13300              :             {
   13301         2416 :                 $$ = NULL;
   13302              :             }
   13303              :         ;
   13304              : 
   13305              : opt_with_clause:
   13306          243 :         with_clause                             { $$ = $1; }
   13307        47166 :         | /*EMPTY*/                             { $$ = NULL; }
   13308              :         ;
   13309              : 
   13310              : into_clause:
   13311              :             INTO OptTempTableName
   13312              :                 {
   13313           69 :                     $$ = makeNode(IntoClause);
   13314           69 :                     $$->rel = $2;
   13315           69 :                     $$->colNames = NIL;
   13316           69 :                     $$->options = NIL;
   13317           69 :                     $$->onCommit = ONCOMMIT_NOOP;
   13318           69 :                     $$->tableSpaceName = NULL;
   13319           69 :                     $$->viewQuery = NULL;
   13320           69 :                     $$->skipData = false;
   13321              :                 }
   13322              :             | /*EMPTY*/
   13323       233549 :                 { $$ = NULL; }
   13324              :         ;
   13325              : 
   13326              : /*
   13327              :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13328              :  * since TEMP is not a reserved word.  See also OptTemp.
   13329              :  */
   13330              : OptTempTableName:
   13331              :             TEMPORARY opt_table qualified_name
   13332              :                 {
   13333            0 :                     $$ = $3;
   13334            0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13335              :                 }
   13336              :             | TEMP opt_table qualified_name
   13337              :                 {
   13338            3 :                     $$ = $3;
   13339            3 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13340              :                 }
   13341              :             | LOCAL TEMPORARY opt_table qualified_name
   13342              :                 {
   13343            0 :                     $$ = $4;
   13344            0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13345              :                 }
   13346              :             | LOCAL TEMP opt_table qualified_name
   13347              :                 {
   13348            0 :                     $$ = $4;
   13349            0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13350              :                 }
   13351              :             | GLOBAL TEMPORARY opt_table qualified_name
   13352              :                 {
   13353            0 :                     ereport(WARNING,
   13354              :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13355              :                              parser_errposition(@1)));
   13356            0 :                     $$ = $4;
   13357            0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13358              :                 }
   13359              :             | GLOBAL TEMP opt_table qualified_name
   13360              :                 {
   13361            0 :                     ereport(WARNING,
   13362              :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13363              :                              parser_errposition(@1)));
   13364            0 :                     $$ = $4;
   13365            0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13366              :                 }
   13367              :             | UNLOGGED opt_table qualified_name
   13368              :                 {
   13369            0 :                     $$ = $3;
   13370            0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13371              :                 }
   13372              :             | TABLE qualified_name
   13373              :                 {
   13374           15 :                     $$ = $2;
   13375           15 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13376              :                 }
   13377              :             | qualified_name
   13378              :                 {
   13379           51 :                     $$ = $1;
   13380           51 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13381              :                 }
   13382              :         ;
   13383              : 
   13384              : opt_table:  TABLE
   13385              :             | /*EMPTY*/
   13386              :         ;
   13387              : 
   13388              : set_quantifier:
   13389         5787 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13390           19 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13391         7051 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13392              :         ;
   13393              : 
   13394              : /* We use (NIL) as a placeholder to indicate that all target expressions
   13395              :  * should be placed in the DISTINCT list during parsetree analysis.
   13396              :  */
   13397              : distinct_clause:
   13398         1980 :             DISTINCT                                { $$ = list_make1(NIL); }
   13399          132 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13400              :         ;
   13401              : 
   13402              : opt_all_clause:
   13403              :             ALL
   13404              :             | /*EMPTY*/
   13405              :         ;
   13406              : 
   13407              : opt_distinct_clause:
   13408            0 :             distinct_clause                         { $$ = $1; }
   13409        20857 :             | opt_all_clause                        { $$ = NIL; }
   13410              :         ;
   13411              : 
   13412              : opt_sort_clause:
   13413         4029 :             sort_clause                             { $$ = $1; }
   13414       194327 :             | /*EMPTY*/                             { $$ = NIL; }
   13415              :         ;
   13416              : 
   13417              : sort_clause:
   13418        42142 :             ORDER BY sortby_list                    { $$ = $3; }
   13419              :         ;
   13420              : 
   13421              : sortby_list:
   13422        42151 :             sortby                                  { $$ = list_make1($1); }
   13423        15561 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13424              :         ;
   13425              : 
   13426              : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13427              :                 {
   13428          110 :                     $$ = makeNode(SortBy);
   13429          110 :                     $$->node = $1;
   13430          110 :                     $$->sortby_dir = SORTBY_USING;
   13431          110 :                     $$->sortby_nulls = $4;
   13432          110 :                     $$->useOp = $3;
   13433          110 :                     $$->location = @3;
   13434              :                 }
   13435              :             | a_expr opt_asc_desc opt_nulls_order
   13436              :                 {
   13437        57602 :                     $$ = makeNode(SortBy);
   13438        57602 :                     $$->node = $1;
   13439        57602 :                     $$->sortby_dir = $2;
   13440        57602 :                     $$->sortby_nulls = $3;
   13441        57602 :                     $$->useOp = NIL;
   13442        57602 :                     $$->location = -1;       /* no operator */
   13443              :                 }
   13444              :         ;
   13445              : 
   13446              : 
   13447              : select_limit:
   13448              :             limit_clause offset_clause
   13449              :                 {
   13450           86 :                     $$ = $1;
   13451           86 :                     ($$)->limitOffset = $2;
   13452           86 :                     ($$)->offsetLoc = @2;
   13453              :                 }
   13454              :             | offset_clause limit_clause
   13455              :                 {
   13456          111 :                     $$ = $2;
   13457          111 :                     ($$)->limitOffset = $1;
   13458          111 :                     ($$)->offsetLoc = @1;
   13459              :                 }
   13460              :             | limit_clause
   13461              :                 {
   13462         2267 :                     $$ = $1;
   13463              :                 }
   13464              :             | offset_clause
   13465              :                 {
   13466          236 :                     SelectLimit *n = palloc_object(SelectLimit);
   13467              : 
   13468          236 :                     n->limitOffset = $1;
   13469          236 :                     n->limitCount = NULL;
   13470          236 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13471          236 :                     n->offsetLoc = @1;
   13472          236 :                     n->countLoc = -1;
   13473          236 :                     n->optionLoc = -1;
   13474          236 :                     $$ = n;
   13475              :                 }
   13476              :         ;
   13477              : 
   13478              : opt_select_limit:
   13479           95 :             select_limit                        { $$ = $1; }
   13480        26050 :             | /* EMPTY */                       { $$ = NULL; }
   13481              :         ;
   13482              : 
   13483              : limit_clause:
   13484              :             LIMIT select_limit_value
   13485              :                 {
   13486         2416 :                     SelectLimit *n = palloc_object(SelectLimit);
   13487              : 
   13488         2416 :                     n->limitOffset = NULL;
   13489         2416 :                     n->limitCount = $2;
   13490         2416 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13491         2416 :                     n->offsetLoc = -1;
   13492         2416 :                     n->countLoc = @1;
   13493         2416 :                     n->optionLoc = -1;
   13494         2416 :                     $$ = n;
   13495              :                 }
   13496              :             | LIMIT select_limit_value ',' select_offset_value
   13497              :                 {
   13498              :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13499            0 :                     ereport(ERROR,
   13500              :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13501              :                              errmsg("LIMIT #,# syntax is not supported"),
   13502              :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13503              :                              parser_errposition(@1)));
   13504              :                 }
   13505              :             /* SQL:2008 syntax */
   13506              :             /* to avoid shift/reduce conflicts, handle the optional value with
   13507              :              * a separate production rather than an opt_ expression.  The fact
   13508              :              * that ONLY is fully reserved means that this way, we defer any
   13509              :              * decision about what rule reduces ROW or ROWS to the point where
   13510              :              * we can see the ONLY token in the lookahead slot.
   13511              :              */
   13512              :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13513              :                 {
   13514           12 :                     SelectLimit *n = palloc_object(SelectLimit);
   13515              : 
   13516           12 :                     n->limitOffset = NULL;
   13517           12 :                     n->limitCount = $3;
   13518           12 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13519           12 :                     n->offsetLoc = -1;
   13520           12 :                     n->countLoc = @1;
   13521           12 :                     n->optionLoc = -1;
   13522           12 :                     $$ = n;
   13523              :                 }
   13524              :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13525              :                 {
   13526           33 :                     SelectLimit *n = palloc_object(SelectLimit);
   13527              : 
   13528           33 :                     n->limitOffset = NULL;
   13529           33 :                     n->limitCount = $3;
   13530           33 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13531           33 :                     n->offsetLoc = -1;
   13532           33 :                     n->countLoc = @1;
   13533           33 :                     n->optionLoc = @5;
   13534           33 :                     $$ = n;
   13535              :                 }
   13536              :             | FETCH first_or_next row_or_rows ONLY
   13537              :                 {
   13538            0 :                     SelectLimit *n = palloc_object(SelectLimit);
   13539              : 
   13540            0 :                     n->limitOffset = NULL;
   13541            0 :                     n->limitCount = makeIntConst(1, -1);
   13542            0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13543            0 :                     n->offsetLoc = -1;
   13544            0 :                     n->countLoc = @1;
   13545            0 :                     n->optionLoc = -1;
   13546            0 :                     $$ = n;
   13547              :                 }
   13548              :             | FETCH first_or_next row_or_rows WITH TIES
   13549              :                 {
   13550            3 :                     SelectLimit *n = palloc_object(SelectLimit);
   13551              : 
   13552            3 :                     n->limitOffset = NULL;
   13553            3 :                     n->limitCount = makeIntConst(1, -1);
   13554            3 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13555            3 :                     n->offsetLoc = -1;
   13556            3 :                     n->countLoc = @1;
   13557            3 :                     n->optionLoc = @4;
   13558            3 :                     $$ = n;
   13559              :                 }
   13560              :         ;
   13561              : 
   13562              : offset_clause:
   13563              :             OFFSET select_offset_value
   13564          433 :                 { $$ = $2; }
   13565              :             /* SQL:2008 syntax */
   13566              :             | OFFSET select_fetch_first_value row_or_rows
   13567            0 :                 { $$ = $2; }
   13568              :         ;
   13569              : 
   13570              : select_limit_value:
   13571         2415 :             a_expr                                  { $$ = $1; }
   13572              :             | ALL
   13573              :                 {
   13574              :                     /* LIMIT ALL is represented as a NULL constant */
   13575            1 :                     $$ = makeNullAConst(@1);
   13576              :                 }
   13577              :         ;
   13578              : 
   13579              : select_offset_value:
   13580          433 :             a_expr                                  { $$ = $1; }
   13581              :         ;
   13582              : 
   13583              : /*
   13584              :  * Allowing full expressions without parentheses causes various parsing
   13585              :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13586              :  * <simple value specification>, which is either a literal or a parameter (but
   13587              :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13588              :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13589              :  * to determine whether the expression is missing rather than trying to make it
   13590              :  * optional in this rule.
   13591              :  *
   13592              :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13593              :  * cover signed numeric literals, which are allowed by the spec. So we include
   13594              :  * those here explicitly. We need FCONST as well as ICONST because values that
   13595              :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13596              :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13597              :  * builds.)
   13598              :  */
   13599              : select_fetch_first_value:
   13600           45 :             c_expr                                  { $$ = $1; }
   13601              :             | '+' I_or_F_const
   13602            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13603              :             | '-' I_or_F_const
   13604            0 :                 { $$ = doNegate($2, @1); }
   13605              :         ;
   13606              : 
   13607              : I_or_F_const:
   13608            0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13609            0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13610              :         ;
   13611              : 
   13612              : /* noise words */
   13613           18 : row_or_rows: ROW                                    { $$ = 0; }
   13614           30 :             | ROWS                                  { $$ = 0; }
   13615              :         ;
   13616              : 
   13617           48 : first_or_next: FIRST_P                              { $$ = 0; }
   13618            0 :             | NEXT                                  { $$ = 0; }
   13619              :         ;
   13620              : 
   13621              : 
   13622              : /*
   13623              :  * This syntax for group_clause tries to follow the spec quite closely.
   13624              :  * However, the spec allows only column references, not expressions,
   13625              :  * which introduces an ambiguity between implicit row constructors
   13626              :  * (a,b) and lists of column references.
   13627              :  *
   13628              :  * We handle this by using the a_expr production for what the spec calls
   13629              :  * <ordinary grouping set>, which in the spec represents either one column
   13630              :  * reference or a parenthesized list of column references. Then, we check the
   13631              :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13632              :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13633              :  * not here)
   13634              :  *
   13635              :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13636              :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13637              :  * in a group clause, but if they have a reason to, we make it possible.)
   13638              :  *
   13639              :  * Each item in the group_clause list is either an expression tree or a
   13640              :  * GroupingSet node of some type.
   13641              :  */
   13642              : group_clause:
   13643              :             GROUP_P BY set_quantifier group_by_list
   13644              :                 {
   13645         2571 :                     GroupClause *n = palloc_object(GroupClause);
   13646              : 
   13647         2571 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13648         2571 :                     n->all = false;
   13649         2571 :                     n->list = $4;
   13650         2571 :                     $$ = n;
   13651              :                 }
   13652              :             | GROUP_P BY ALL
   13653              :                 {
   13654           33 :                     GroupClause *n = palloc_object(GroupClause);
   13655           33 :                     n->distinct = false;
   13656           33 :                     n->all = true;
   13657           33 :                     n->list = NIL;
   13658           33 :                     $$ = n;
   13659              :                 }
   13660              :             | /*EMPTY*/
   13661              :                 {
   13662       251856 :                     GroupClause *n = palloc_object(GroupClause);
   13663              : 
   13664       251856 :                     n->distinct = false;
   13665       251856 :                     n->all = false;
   13666       251856 :                     n->list = NIL;
   13667       251856 :                     $$ = n;
   13668              :                 }
   13669              :         ;
   13670              : 
   13671              : group_by_list:
   13672         2929 :             group_by_item                           { $$ = list_make1($1); }
   13673         1577 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13674              :         ;
   13675              : 
   13676              : group_by_item:
   13677         3737 :             a_expr                                  { $$ = $1; }
   13678          155 :             | empty_grouping_set                    { $$ = $1; }
   13679           92 :             | cube_clause                           { $$ = $1; }
   13680          164 :             | rollup_clause                         { $$ = $1; }
   13681          358 :             | grouping_sets_clause                  { $$ = $1; }
   13682              :         ;
   13683              : 
   13684              : empty_grouping_set:
   13685              :             '(' ')'
   13686              :                 {
   13687          155 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13688              :                 }
   13689              :         ;
   13690              : 
   13691              : /*
   13692              :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13693              :  * so that they shift in these rules rather than reducing the conflicting
   13694              :  * unreserved_keyword rule.
   13695              :  */
   13696              : 
   13697              : rollup_clause:
   13698              :             ROLLUP '(' expr_list ')'
   13699              :                 {
   13700          164 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13701              :                 }
   13702              :         ;
   13703              : 
   13704              : cube_clause:
   13705              :             CUBE '(' expr_list ')'
   13706              :                 {
   13707           92 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13708              :                 }
   13709              :         ;
   13710              : 
   13711              : grouping_sets_clause:
   13712              :             GROUPING SETS '(' group_by_list ')'
   13713              :                 {
   13714          358 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13715              :                 }
   13716              :         ;
   13717              : 
   13718              : having_clause:
   13719          396 :             HAVING a_expr                           { $$ = $2; }
   13720       254064 :             | /*EMPTY*/                             { $$ = NULL; }
   13721              :         ;
   13722              : 
   13723              : for_locking_clause:
   13724         5458 :             for_locking_items                       { $$ = $1; }
   13725            0 :             | FOR READ ONLY                         { $$ = NIL; }
   13726              :         ;
   13727              : 
   13728              : opt_for_locking_clause:
   13729          170 :             for_locking_clause                      { $$ = $1; }
   13730        23292 :             | /* EMPTY */                           { $$ = NIL; }
   13731              :         ;
   13732              : 
   13733              : for_locking_items:
   13734         5458 :             for_locking_item                        { $$ = list_make1($1); }
   13735           51 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13736              :         ;
   13737              : 
   13738              : for_locking_item:
   13739              :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13740              :                 {
   13741         5509 :                     LockingClause *n = makeNode(LockingClause);
   13742              : 
   13743         5509 :                     n->lockedRels = $2;
   13744         5509 :                     n->strength = $1;
   13745         5509 :                     n->waitPolicy = $3;
   13746         5509 :                     $$ = (Node *) n;
   13747              :                 }
   13748              :         ;
   13749              : 
   13750              : for_locking_strength:
   13751          839 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13752           42 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13753          111 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13754         4578 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13755              :         ;
   13756              : 
   13757              : opt_for_locking_strength:
   13758           61 :             for_locking_strength                { $$ = $1; }
   13759          122 :             | /* EMPTY */                       { $$ = LCS_NONE; }
   13760              :         ;
   13761              : 
   13762              : locked_rels_list:
   13763         1819 :             OF qualified_name_list                  { $$ = $2; }
   13764         3690 :             | /* EMPTY */                           { $$ = NIL; }
   13765              :         ;
   13766              : 
   13767              : 
   13768              : /*
   13769              :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13770              :  * making VALUES a fully reserved word, which will probably break more apps
   13771              :  * than allowing the noise-word is worth.
   13772              :  */
   13773              : values_clause:
   13774              :             VALUES '(' expr_list ')'
   13775              :                 {
   13776        31623 :                     SelectStmt *n = makeNode(SelectStmt);
   13777              : 
   13778        31623 :                     n->valuesLists = list_make1($3);
   13779        31623 :                     $$ = (Node *) n;
   13780              :                 }
   13781              :             | values_clause ',' '(' expr_list ')'
   13782              :                 {
   13783        13514 :                     SelectStmt *n = (SelectStmt *) $1;
   13784              : 
   13785        13514 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13786        13514 :                     $$ = (Node *) n;
   13787              :                 }
   13788              :         ;
   13789              : 
   13790              : 
   13791              : /*****************************************************************************
   13792              :  *
   13793              :  *  clauses common to all Optimizable Stmts:
   13794              :  *      from_clause     - allow list of both JOIN expressions and table names
   13795              :  *      where_clause    - qualifications for joins or restrictions
   13796              :  *
   13797              :  *****************************************************************************/
   13798              : 
   13799              : from_clause:
   13800       172075 :             FROM from_list                          { $$ = $2; }
   13801        89881 :             | /*EMPTY*/                             { $$ = NIL; }
   13802              :         ;
   13803              : 
   13804              : from_list:
   13805       172607 :             table_ref                               { $$ = list_make1($1); }
   13806        31857 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13807              :         ;
   13808              : 
   13809              : /*
   13810              :  * table_ref is where an alias clause can be attached.
   13811              :  */
   13812              : table_ref:  relation_expr opt_alias_clause
   13813              :                 {
   13814       213306 :                     $1->alias = $2;
   13815       213306 :                     $$ = (Node *) $1;
   13816              :                 }
   13817              :             | relation_expr opt_alias_clause tablesample_clause
   13818              :                 {
   13819          133 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13820              : 
   13821          133 :                     $1->alias = $2;
   13822              :                     /* relation_expr goes inside the RangeTableSample node */
   13823          133 :                     n->relation = (Node *) $1;
   13824          133 :                     $$ = (Node *) n;
   13825              :                 }
   13826              :             | func_table func_alias_clause
   13827              :                 {
   13828        24689 :                     RangeFunction *n = (RangeFunction *) $1;
   13829              : 
   13830        24689 :                     n->alias = linitial($2);
   13831        24689 :                     n->coldeflist = lsecond($2);
   13832        24689 :                     $$ = (Node *) n;
   13833              :                 }
   13834              :             | LATERAL_P func_table func_alias_clause
   13835              :                 {
   13836          668 :                     RangeFunction *n = (RangeFunction *) $2;
   13837              : 
   13838          668 :                     n->lateral = true;
   13839          668 :                     n->alias = linitial($3);
   13840          668 :                     n->coldeflist = lsecond($3);
   13841          668 :                     $$ = (Node *) n;
   13842              :                 }
   13843              :             | xmltable opt_alias_clause
   13844              :                 {
   13845           43 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13846              : 
   13847           43 :                     n->alias = $2;
   13848           43 :                     $$ = (Node *) n;
   13849              :                 }
   13850              :             | LATERAL_P xmltable opt_alias_clause
   13851              :                 {
   13852           70 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13853              : 
   13854           70 :                     n->lateral = true;
   13855           70 :                     n->alias = $3;
   13856           70 :                     $$ = (Node *) n;
   13857              :                 }
   13858              :             | select_with_parens opt_alias_clause
   13859              :                 {
   13860        10024 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13861              : 
   13862        10024 :                     n->lateral = false;
   13863        10024 :                     n->subquery = $1;
   13864        10024 :                     n->alias = $2;
   13865        10024 :                     $$ = (Node *) n;
   13866              :                 }
   13867              :             | LATERAL_P select_with_parens opt_alias_clause
   13868              :                 {
   13869          974 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13870              : 
   13871          974 :                     n->lateral = true;
   13872          974 :                     n->subquery = $2;
   13873          974 :                     n->alias = $3;
   13874          974 :                     $$ = (Node *) n;
   13875              :                 }
   13876              :             | joined_table
   13877              :                 {
   13878        44508 :                     $$ = (Node *) $1;
   13879              :                 }
   13880              :             | '(' joined_table ')' alias_clause
   13881              :                 {
   13882           87 :                     $2->alias = $4;
   13883           87 :                     $$ = (Node *) $2;
   13884              :                 }
   13885              :             | json_table opt_alias_clause
   13886              :                 {
   13887          265 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13888              : 
   13889          265 :                     jt->alias = $2;
   13890          265 :                     $$ = (Node *) jt;
   13891              :                 }
   13892              :             | LATERAL_P json_table opt_alias_clause
   13893              :                 {
   13894            0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13895              : 
   13896            0 :                     jt->alias = $3;
   13897            0 :                     jt->lateral = true;
   13898            0 :                     $$ = (Node *) jt;
   13899              :                 }
   13900              :         ;
   13901              : 
   13902              : 
   13903              : /*
   13904              :  * It may seem silly to separate joined_table from table_ref, but there is
   13905              :  * method in SQL's madness: if you don't do it this way you get reduce-
   13906              :  * reduce conflicts, because it's not clear to the parser generator whether
   13907              :  * to expect alias_clause after ')' or not.  For the same reason we must
   13908              :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13909              :  * join_type to expand to empty; if we try it, the parser generator can't
   13910              :  * figure out when to reduce an empty join_type right after table_ref.
   13911              :  *
   13912              :  * Note that a CROSS JOIN is the same as an unqualified
   13913              :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13914              :  * but a qualification expression to limit membership.
   13915              :  * A NATURAL JOIN implicitly matches column names between
   13916              :  * tables and the shape is determined by which columns are
   13917              :  * in common. We'll collect columns during the later transformations.
   13918              :  */
   13919              : 
   13920              : joined_table:
   13921              :             '(' joined_table ')'
   13922              :                 {
   13923         2018 :                     $$ = $2;
   13924              :                 }
   13925              :             | table_ref CROSS JOIN table_ref
   13926              :                 {
   13927              :                     /* CROSS JOIN is same as unqualified inner join */
   13928          262 :                     JoinExpr   *n = makeNode(JoinExpr);
   13929              : 
   13930          262 :                     n->jointype = JOIN_INNER;
   13931          262 :                     n->isNatural = false;
   13932          262 :                     n->larg = $1;
   13933          262 :                     n->rarg = $4;
   13934          262 :                     n->usingClause = NIL;
   13935          262 :                     n->join_using_alias = NULL;
   13936          262 :                     n->quals = NULL;
   13937          262 :                     $$ = n;
   13938              :                 }
   13939              :             | table_ref join_type JOIN table_ref join_qual
   13940              :                 {
   13941        24822 :                     JoinExpr   *n = makeNode(JoinExpr);
   13942              : 
   13943        24822 :                     n->jointype = $2;
   13944        24822 :                     n->isNatural = false;
   13945        24822 :                     n->larg = $1;
   13946        24822 :                     n->rarg = $4;
   13947        24822 :                     if ($5 != NULL && IsA($5, List))
   13948              :                     {
   13949              :                          /* USING clause */
   13950          252 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13951          252 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13952              :                     }
   13953              :                     else
   13954              :                     {
   13955              :                         /* ON clause */
   13956        24570 :                         n->quals = $5;
   13957              :                     }
   13958        24822 :                     $$ = n;
   13959              :                 }
   13960              :             | table_ref JOIN table_ref join_qual
   13961              :                 {
   13962              :                     /* letting join_type reduce to empty doesn't work */
   13963        19379 :                     JoinExpr   *n = makeNode(JoinExpr);
   13964              : 
   13965        19379 :                     n->jointype = JOIN_INNER;
   13966        19379 :                     n->isNatural = false;
   13967        19379 :                     n->larg = $1;
   13968        19379 :                     n->rarg = $3;
   13969        19379 :                     if ($4 != NULL && IsA($4, List))
   13970              :                     {
   13971              :                         /* USING clause */
   13972          372 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13973          372 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13974              :                     }
   13975              :                     else
   13976              :                     {
   13977              :                         /* ON clause */
   13978        19007 :                         n->quals = $4;
   13979              :                     }
   13980        19379 :                     $$ = n;
   13981              :                 }
   13982              :             | table_ref NATURAL join_type JOIN table_ref
   13983              :                 {
   13984           39 :                     JoinExpr   *n = makeNode(JoinExpr);
   13985              : 
   13986           39 :                     n->jointype = $3;
   13987           39 :                     n->isNatural = true;
   13988           39 :                     n->larg = $1;
   13989           39 :                     n->rarg = $5;
   13990           39 :                     n->usingClause = NIL; /* figure out which columns later... */
   13991           39 :                     n->join_using_alias = NULL;
   13992           39 :                     n->quals = NULL; /* fill later */
   13993           39 :                     $$ = n;
   13994              :                 }
   13995              :             | table_ref NATURAL JOIN table_ref
   13996              :                 {
   13997              :                     /* letting join_type reduce to empty doesn't work */
   13998           93 :                     JoinExpr   *n = makeNode(JoinExpr);
   13999              : 
   14000           93 :                     n->jointype = JOIN_INNER;
   14001           93 :                     n->isNatural = true;
   14002           93 :                     n->larg = $1;
   14003           93 :                     n->rarg = $4;
   14004           93 :                     n->usingClause = NIL; /* figure out which columns later... */
   14005           93 :                     n->join_using_alias = NULL;
   14006           93 :                     n->quals = NULL; /* fill later */
   14007           93 :                     $$ = n;
   14008              :                 }
   14009              :         ;
   14010              : 
   14011              : alias_clause:
   14012              :             AS ColId '(' name_list ')'
   14013              :                 {
   14014         3810 :                     $$ = makeNode(Alias);
   14015         3810 :                     $$->aliasname = $2;
   14016         3810 :                     $$->colnames = $4;
   14017              :                 }
   14018              :             | AS ColId
   14019              :                 {
   14020         8411 :                     $$ = makeNode(Alias);
   14021         8411 :                     $$->aliasname = $2;
   14022              :                 }
   14023              :             | ColId '(' name_list ')'
   14024              :                 {
   14025         2955 :                     $$ = makeNode(Alias);
   14026         2955 :                     $$->aliasname = $1;
   14027         2955 :                     $$->colnames = $3;
   14028              :                 }
   14029              :             | ColId
   14030              :                 {
   14031       138568 :                     $$ = makeNode(Alias);
   14032       138568 :                     $$->aliasname = $1;
   14033              :                 }
   14034              :         ;
   14035              : 
   14036       138440 : opt_alias_clause: alias_clause                      { $$ = $1; }
   14037        86375 :             | /*EMPTY*/                             { $$ = NULL; }
   14038              :         ;
   14039              : 
   14040              : /*
   14041              :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   14042              :  * per SQL standard.  (The grammar could parse the other variants, but they
   14043              :  * don't seem to be useful, and it might lead to parser problems in the
   14044              :  * future.)
   14045              :  */
   14046              : opt_alias_clause_for_join_using:
   14047              :             AS ColId
   14048              :                 {
   14049           42 :                     $$ = makeNode(Alias);
   14050           42 :                     $$->aliasname = $2;
   14051              :                     /* the column name list will be inserted later */
   14052              :                 }
   14053          582 :             | /*EMPTY*/                             { $$ = NULL; }
   14054              :         ;
   14055              : 
   14056              : /*
   14057              :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   14058              :  * return a 2-element list that gets disassembled by calling production.
   14059              :  */
   14060              : func_alias_clause:
   14061              :             alias_clause
   14062              :                 {
   14063        15217 :                     $$ = list_make2($1, NIL);
   14064              :                 }
   14065              :             | AS '(' TableFuncElementList ')'
   14066              :                 {
   14067           57 :                     $$ = list_make2(NULL, $3);
   14068              :                 }
   14069              :             | AS ColId '(' TableFuncElementList ')'
   14070              :                 {
   14071          298 :                     Alias      *a = makeNode(Alias);
   14072              : 
   14073          298 :                     a->aliasname = $2;
   14074          298 :                     $$ = list_make2(a, $4);
   14075              :                 }
   14076              :             | ColId '(' TableFuncElementList ')'
   14077              :                 {
   14078           25 :                     Alias      *a = makeNode(Alias);
   14079              : 
   14080           25 :                     a->aliasname = $1;
   14081           25 :                     $$ = list_make2(a, $3);
   14082              :                 }
   14083              :             | /*EMPTY*/
   14084              :                 {
   14085         9760 :                     $$ = list_make2(NULL, NIL);
   14086              :                 }
   14087              :         ;
   14088              : 
   14089          521 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   14090        22112 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   14091          195 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   14092         2033 :             | INNER_P                               { $$ = JOIN_INNER; }
   14093              :         ;
   14094              : 
   14095              : /* OUTER is just noise... */
   14096              : opt_outer: OUTER_P
   14097              :             | /*EMPTY*/
   14098              :         ;
   14099              : 
   14100              : /* JOIN qualification clauses
   14101              :  * Possibilities are:
   14102              :  *  USING ( column list ) [ AS alias ]
   14103              :  *                        allows only unqualified column names,
   14104              :  *                        which must match between tables.
   14105              :  *  ON expr allows more general qualifications.
   14106              :  *
   14107              :  * We return USING as a two-element List (the first item being a sub-List
   14108              :  * of the common column names, and the second either an Alias item or NULL).
   14109              :  * An ON-expr will not be a List, so it can be told apart that way.
   14110              :  */
   14111              : 
   14112              : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   14113              :                 {
   14114          624 :                     $$ = (Node *) list_make2($3, $5);
   14115              :                 }
   14116              :             | ON a_expr
   14117              :                 {
   14118        43577 :                     $$ = $2;
   14119              :                 }
   14120              :         ;
   14121              : 
   14122              : 
   14123              : relation_expr:
   14124              :             qualified_name
   14125              :                 {
   14126              :                     /* inheritance query, implicitly */
   14127       255653 :                     $$ = $1;
   14128       255653 :                     $$->inh = true;
   14129       255653 :                     $$->alias = NULL;
   14130              :                 }
   14131              :             | extended_relation_expr
   14132              :                 {
   14133         3710 :                     $$ = $1;
   14134              :                 }
   14135              :         ;
   14136              : 
   14137              : extended_relation_expr:
   14138              :             qualified_name '*'
   14139              :                 {
   14140              :                     /* inheritance query, explicitly */
   14141          102 :                     $$ = $1;
   14142          102 :                     $$->inh = true;
   14143          102 :                     $$->alias = NULL;
   14144              :                 }
   14145              :             | ONLY qualified_name
   14146              :                 {
   14147              :                     /* no inheritance */
   14148         3611 :                     $$ = $2;
   14149         3611 :                     $$->inh = false;
   14150         3611 :                     $$->alias = NULL;
   14151              :                 }
   14152              :             | ONLY '(' qualified_name ')'
   14153              :                 {
   14154              :                     /* no inheritance, SQL99-style syntax */
   14155            0 :                     $$ = $3;
   14156            0 :                     $$->inh = false;
   14157            0 :                     $$->alias = NULL;
   14158              :                 }
   14159              :         ;
   14160              : 
   14161              : 
   14162              : relation_expr_list:
   14163         1511 :             relation_expr                           { $$ = list_make1($1); }
   14164         5809 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   14165              :         ;
   14166              : 
   14167              : 
   14168              : /*
   14169              :  * Given "UPDATE foo set set ...", we have to decide without looking any
   14170              :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   14171              :  * keyword.  Since "set" is allowed as a column name both interpretations
   14172              :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   14173              :  * relation_expr_opt_alias production a higher precedence than the SET token
   14174              :  * has, causing the parser to prefer to reduce, in effect assuming that the
   14175              :  * SET is not an alias.
   14176              :  */
   14177              : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   14178              :                 {
   14179         9780 :                     $$ = $1;
   14180              :                 }
   14181              :             | relation_expr ColId
   14182              :                 {
   14183         1154 :                     Alias      *alias = makeNode(Alias);
   14184              : 
   14185         1154 :                     alias->aliasname = $2;
   14186         1154 :                     $1->alias = alias;
   14187         1154 :                     $$ = $1;
   14188              :                 }
   14189              :             | relation_expr AS ColId
   14190              :                 {
   14191           45 :                     Alias      *alias = makeNode(Alias);
   14192              : 
   14193           45 :                     alias->aliasname = $3;
   14194           45 :                     $1->alias = alias;
   14195           45 :                     $$ = $1;
   14196              :                 }
   14197              :         ;
   14198              : 
   14199              : /*
   14200              :  * TABLESAMPLE decoration in a FROM item
   14201              :  */
   14202              : tablesample_clause:
   14203              :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14204              :                 {
   14205          133 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14206              : 
   14207              :                     /* n->relation will be filled in later */
   14208          133 :                     n->method = $2;
   14209          133 :                     n->args = $4;
   14210          133 :                     n->repeatable = $6;
   14211          133 :                     n->location = @2;
   14212          133 :                     $$ = (Node *) n;
   14213              :                 }
   14214              :         ;
   14215              : 
   14216              : opt_repeatable_clause:
   14217           54 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14218           79 :             | /*EMPTY*/                 { $$ = NULL; }
   14219              :         ;
   14220              : 
   14221              : /*
   14222              :  * func_table represents a function invocation in a FROM list. It can be
   14223              :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14224              :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14225              :  * optionally with WITH ORDINALITY attached.
   14226              :  * In the ROWS FROM syntax, a column definition list can be given for each
   14227              :  * function, for example:
   14228              :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14229              :  *                bar() AS (bar_res_a text, bar_res_b text))
   14230              :  * It's also possible to attach a column definition list to the RangeFunction
   14231              :  * as a whole, but that's handled by the table_ref production.
   14232              :  */
   14233              : func_table: func_expr_windowless opt_ordinality
   14234              :                 {
   14235        25294 :                     RangeFunction *n = makeNode(RangeFunction);
   14236              : 
   14237        25294 :                     n->lateral = false;
   14238        25294 :                     n->ordinality = $2;
   14239        25294 :                     n->is_rowsfrom = false;
   14240        25294 :                     n->functions = list_make1(list_make2($1, NIL));
   14241              :                     /* alias and coldeflist are set by table_ref production */
   14242        25294 :                     $$ = (Node *) n;
   14243              :                 }
   14244              :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14245              :                 {
   14246           66 :                     RangeFunction *n = makeNode(RangeFunction);
   14247              : 
   14248           66 :                     n->lateral = false;
   14249           66 :                     n->ordinality = $6;
   14250           66 :                     n->is_rowsfrom = true;
   14251           66 :                     n->functions = $4;
   14252              :                     /* alias and coldeflist are set by table_ref production */
   14253           66 :                     $$ = (Node *) n;
   14254              :                 }
   14255              :         ;
   14256              : 
   14257              : rowsfrom_item: func_expr_windowless opt_col_def_list
   14258          159 :                 { $$ = list_make2($1, $2); }
   14259              :         ;
   14260              : 
   14261              : rowsfrom_list:
   14262           66 :             rowsfrom_item                       { $$ = list_make1($1); }
   14263           93 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14264              :         ;
   14265              : 
   14266           27 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14267          132 :             | /*EMPTY*/                             { $$ = NIL; }
   14268              :         ;
   14269              : 
   14270          478 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14271        24882 :             | /*EMPTY*/                             { $$ = false; }
   14272              :         ;
   14273              : 
   14274              : 
   14275              : where_clause:
   14276       114403 :             WHERE a_expr                            { $$ = $2; }
   14277       151468 :             | /*EMPTY*/                             { $$ = NULL; }
   14278              :         ;
   14279              : 
   14280              : /* variant for UPDATE and DELETE */
   14281              : where_or_current_clause:
   14282         7157 :             WHERE a_expr                            { $$ = $2; }
   14283              :             | WHERE CURRENT_P OF cursor_name
   14284              :                 {
   14285          133 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14286              : 
   14287              :                     /* cvarno is filled in by parse analysis */
   14288          133 :                     n->cursor_name = $4;
   14289          133 :                     n->cursor_param = 0;
   14290          133 :                     $$ = (Node *) n;
   14291              :                 }
   14292         2570 :             | /*EMPTY*/                             { $$ = NULL; }
   14293              :         ;
   14294              : 
   14295              : 
   14296              : OptTableFuncElementList:
   14297          361 :             TableFuncElementList                { $$ = $1; }
   14298         1893 :             | /*EMPTY*/                         { $$ = NIL; }
   14299              :         ;
   14300              : 
   14301              : TableFuncElementList:
   14302              :             TableFuncElement
   14303              :                 {
   14304          768 :                     $$ = list_make1($1);
   14305              :                 }
   14306              :             | TableFuncElementList ',' TableFuncElement
   14307              :                 {
   14308         1035 :                     $$ = lappend($1, $3);
   14309              :                 }
   14310              :         ;
   14311              : 
   14312              : TableFuncElement:   ColId Typename opt_collate_clause
   14313              :                 {
   14314         1835 :                     ColumnDef *n = makeNode(ColumnDef);
   14315              : 
   14316         1835 :                     n->colname = $1;
   14317         1835 :                     n->typeName = $2;
   14318         1835 :                     n->inhcount = 0;
   14319         1835 :                     n->is_local = true;
   14320         1835 :                     n->is_not_null = false;
   14321         1835 :                     n->is_from_type = false;
   14322         1835 :                     n->storage = 0;
   14323         1835 :                     n->raw_default = NULL;
   14324         1835 :                     n->cooked_default = NULL;
   14325         1835 :                     n->collClause = (CollateClause *) $3;
   14326         1835 :                     n->collOid = InvalidOid;
   14327         1835 :                     n->constraints = NIL;
   14328         1835 :                     n->location = @1;
   14329         1835 :                     $$ = (Node *) n;
   14330              :                 }
   14331              :         ;
   14332              : 
   14333              : /*
   14334              :  * XMLTABLE
   14335              :  */
   14336              : xmltable:
   14337              :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14338              :                 {
   14339          103 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14340              : 
   14341          103 :                     n->rowexpr = $3;
   14342          103 :                     n->docexpr = $4;
   14343          103 :                     n->columns = $6;
   14344          103 :                     n->namespaces = NIL;
   14345          103 :                     n->location = @1;
   14346          103 :                     $$ = (Node *) n;
   14347              :                 }
   14348              :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14349              :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14350              :                 {
   14351           10 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14352              : 
   14353           10 :                     n->rowexpr = $8;
   14354           10 :                     n->docexpr = $9;
   14355           10 :                     n->columns = $11;
   14356           10 :                     n->namespaces = $5;
   14357           10 :                     n->location = @1;
   14358           10 :                     $$ = (Node *) n;
   14359              :                 }
   14360              :         ;
   14361              : 
   14362          113 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14363          265 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14364              :         ;
   14365              : 
   14366              : xmltable_column_el:
   14367              :             ColId Typename
   14368              :                 {
   14369          102 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14370              : 
   14371          102 :                     fc->colname = $1;
   14372          102 :                     fc->for_ordinality = false;
   14373          102 :                     fc->typeName = $2;
   14374          102 :                     fc->is_not_null = false;
   14375          102 :                     fc->colexpr = NULL;
   14376          102 :                     fc->coldefexpr = NULL;
   14377          102 :                     fc->location = @1;
   14378              : 
   14379          102 :                     $$ = (Node *) fc;
   14380              :                 }
   14381              :             | ColId Typename xmltable_column_option_list
   14382              :                 {
   14383          245 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14384              :                     ListCell   *option;
   14385          245 :                     bool        nullability_seen = false;
   14386              : 
   14387          245 :                     fc->colname = $1;
   14388          245 :                     fc->typeName = $2;
   14389          245 :                     fc->for_ordinality = false;
   14390          245 :                     fc->is_not_null = false;
   14391          245 :                     fc->colexpr = NULL;
   14392          245 :                     fc->coldefexpr = NULL;
   14393          245 :                     fc->location = @1;
   14394              : 
   14395          546 :                     foreach(option, $3)
   14396              :                     {
   14397          301 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14398              : 
   14399          301 :                         if (strcmp(defel->defname, "default") == 0)
   14400              :                         {
   14401           28 :                             if (fc->coldefexpr != NULL)
   14402            0 :                                 ereport(ERROR,
   14403              :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14404              :                                          errmsg("only one DEFAULT value is allowed"),
   14405              :                                          parser_errposition(defel->location)));
   14406           28 :                             fc->coldefexpr = defel->arg;
   14407              :                         }
   14408          273 :                         else if (strcmp(defel->defname, "path") == 0)
   14409              :                         {
   14410          245 :                             if (fc->colexpr != NULL)
   14411            0 :                                 ereport(ERROR,
   14412              :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14413              :                                          errmsg("only one PATH value per column is allowed"),
   14414              :                                          parser_errposition(defel->location)));
   14415          245 :                             fc->colexpr = defel->arg;
   14416              :                         }
   14417           28 :                         else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
   14418              :                         {
   14419           28 :                             if (nullability_seen)
   14420            0 :                                 ereport(ERROR,
   14421              :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14422              :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14423              :                                          parser_errposition(defel->location)));
   14424           28 :                             fc->is_not_null = boolVal(defel->arg);
   14425           28 :                             nullability_seen = true;
   14426              :                         }
   14427              :                         else
   14428              :                         {
   14429            0 :                             ereport(ERROR,
   14430              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14431              :                                      errmsg("unrecognized column option \"%s\"",
   14432              :                                             defel->defname),
   14433              :                                      parser_errposition(defel->location)));
   14434              :                         }
   14435              :                     }
   14436          245 :                     $$ = (Node *) fc;
   14437              :                 }
   14438              :             | ColId FOR ORDINALITY
   14439              :                 {
   14440           31 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14441              : 
   14442           31 :                     fc->colname = $1;
   14443           31 :                     fc->for_ordinality = true;
   14444              :                     /* other fields are ignored, initialized by makeNode */
   14445           31 :                     fc->location = @1;
   14446              : 
   14447           31 :                     $$ = (Node *) fc;
   14448              :                 }
   14449              :         ;
   14450              : 
   14451              : xmltable_column_option_list:
   14452              :             xmltable_column_option_el
   14453          245 :                 { $$ = list_make1($1); }
   14454              :             | xmltable_column_option_list xmltable_column_option_el
   14455           56 :                 { $$ = lappend($1, $2); }
   14456              :         ;
   14457              : 
   14458              : xmltable_column_option_el:
   14459              :             IDENT b_expr
   14460              :                 {
   14461            3 :                     if (strcmp($1, "__pg__is_not_null") == 0)
   14462            3 :                         ereport(ERROR,
   14463              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14464              :                                  errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
   14465              :                                  parser_errposition(@1)));
   14466            0 :                     $$ = makeDefElem($1, $2, @1);
   14467              :                 }
   14468              :             | DEFAULT b_expr
   14469           28 :                 { $$ = makeDefElem("default", $2, @1); }
   14470              :             | NOT NULL_P
   14471           28 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
   14472              :             | NULL_P
   14473            0 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
   14474              :             | PATH b_expr
   14475          245 :                 { $$ = makeDefElem("path", $2, @1); }
   14476              :         ;
   14477              : 
   14478              : xml_namespace_list:
   14479              :             xml_namespace_el
   14480           10 :                 { $$ = list_make1($1); }
   14481              :             | xml_namespace_list ',' xml_namespace_el
   14482            0 :                 { $$ = lappend($1, $3); }
   14483              :         ;
   14484              : 
   14485              : xml_namespace_el:
   14486              :             b_expr AS ColLabel
   14487              :                 {
   14488            7 :                     $$ = makeNode(ResTarget);
   14489            7 :                     $$->name = $3;
   14490            7 :                     $$->indirection = NIL;
   14491            7 :                     $$->val = $1;
   14492            7 :                     $$->location = @1;
   14493              :                 }
   14494              :             | DEFAULT b_expr
   14495              :                 {
   14496            3 :                     $$ = makeNode(ResTarget);
   14497            3 :                     $$->name = NULL;
   14498            3 :                     $$->indirection = NIL;
   14499            3 :                     $$->val = $2;
   14500            3 :                     $$->location = @1;
   14501              :                 }
   14502              :         ;
   14503              : 
   14504              : json_table:
   14505              :             JSON_TABLE '('
   14506              :                 json_value_expr ',' a_expr json_table_path_name_opt
   14507              :                 json_passing_clause_opt
   14508              :                 COLUMNS '(' json_table_column_definition_list ')'
   14509              :                 json_on_error_clause_opt
   14510              :             ')'
   14511              :                 {
   14512          268 :                     JsonTable *n = makeNode(JsonTable);
   14513              :                     char      *pathstring;
   14514              : 
   14515          268 :                     n->context_item = (JsonValueExpr *) $3;
   14516          268 :                     if (!IsA($5, A_Const) ||
   14517          265 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14518            3 :                         ereport(ERROR,
   14519              :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14520              :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14521              :                                 parser_errposition(@5));
   14522          265 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14523          265 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14524          265 :                     n->passing = $7;
   14525          265 :                     n->columns = $10;
   14526          265 :                     n->on_error = (JsonBehavior *) $12;
   14527          265 :                     n->location = @1;
   14528          265 :                     $$ = (Node *) n;
   14529              :                 }
   14530              :         ;
   14531              : 
   14532              : json_table_path_name_opt:
   14533           31 :             AS name         { $$ = $2; }
   14534          243 :             | /* empty */   { $$ = NULL; }
   14535              :         ;
   14536              : 
   14537              : json_table_column_definition_list:
   14538              :             json_table_column_definition
   14539          413 :                 { $$ = list_make1($1); }
   14540              :             | json_table_column_definition_list ',' json_table_column_definition
   14541          264 :                 { $$ = lappend($1, $3); }
   14542              :         ;
   14543              : 
   14544              : json_table_column_definition:
   14545              :             ColId FOR ORDINALITY
   14546              :                 {
   14547           42 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14548              : 
   14549           42 :                     n->coltype = JTC_FOR_ORDINALITY;
   14550           42 :                     n->name = $1;
   14551           42 :                     n->location = @1;
   14552           42 :                     $$ = (Node *) n;
   14553              :                 }
   14554              :             | ColId Typename
   14555              :                 json_table_column_path_clause_opt
   14556              :                 json_wrapper_behavior
   14557              :                 json_quotes_clause_opt
   14558              :                 json_behavior_clause_opt
   14559              :                 {
   14560          367 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14561              : 
   14562          367 :                     n->coltype = JTC_REGULAR;
   14563          367 :                     n->name = $1;
   14564          367 :                     n->typeName = $2;
   14565          367 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14566          367 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14567          367 :                     n->wrapper = $4;
   14568          367 :                     n->quotes = $5;
   14569          367 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14570          367 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14571          367 :                     n->location = @1;
   14572          367 :                     $$ = (Node *) n;
   14573              :                 }
   14574              :             | ColId Typename json_format_clause
   14575              :                 json_table_column_path_clause_opt
   14576              :                 json_wrapper_behavior
   14577              :                 json_quotes_clause_opt
   14578              :                 json_behavior_clause_opt
   14579              :                 {
   14580           54 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14581              : 
   14582           54 :                     n->coltype = JTC_FORMATTED;
   14583           54 :                     n->name = $1;
   14584           54 :                     n->typeName = $2;
   14585           54 :                     n->format = (JsonFormat *) $3;
   14586           54 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14587           54 :                     n->wrapper = $5;
   14588           54 :                     n->quotes = $6;
   14589           54 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14590           54 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14591           54 :                     n->location = @1;
   14592           54 :                     $$ = (Node *) n;
   14593              :                 }
   14594              :             | ColId Typename
   14595              :                 EXISTS json_table_column_path_clause_opt
   14596              :                 json_on_error_clause_opt
   14597              :                 {
   14598           69 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14599              : 
   14600           69 :                     n->coltype = JTC_EXISTS;
   14601           69 :                     n->name = $1;
   14602           69 :                     n->typeName = $2;
   14603           69 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14604           69 :                     n->wrapper = JSW_NONE;
   14605           69 :                     n->quotes = JS_QUOTES_UNSPEC;
   14606           69 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14607           69 :                     n->on_empty = NULL;
   14608           69 :                     n->on_error = (JsonBehavior *) $5;
   14609           69 :                     n->location = @1;
   14610           69 :                     $$ = (Node *) n;
   14611              :                 }
   14612              :             | NESTED path_opt Sconst
   14613              :                 COLUMNS '(' json_table_column_definition_list ')'
   14614              :                 {
   14615           72 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14616              : 
   14617           72 :                     n->coltype = JTC_NESTED;
   14618          144 :                     n->pathspec = (JsonTablePathSpec *)
   14619           72 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14620           72 :                     n->columns = $6;
   14621           72 :                     n->location = @1;
   14622           72 :                     $$ = (Node *) n;
   14623              :                 }
   14624              :             | NESTED path_opt Sconst AS name
   14625              :                 COLUMNS '(' json_table_column_definition_list ')'
   14626              :                 {
   14627           73 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14628              : 
   14629           73 :                     n->coltype = JTC_NESTED;
   14630          146 :                     n->pathspec = (JsonTablePathSpec *)
   14631           73 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14632           73 :                     n->columns = $8;
   14633           73 :                     n->location = @1;
   14634           73 :                     $$ = (Node *) n;
   14635              :                 }
   14636              :         ;
   14637              : 
   14638              : path_opt:
   14639              :             PATH
   14640              :             | /* EMPTY */
   14641              :         ;
   14642              : 
   14643              : json_table_column_path_clause_opt:
   14644              :             PATH Sconst
   14645          414 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14646              :             | /* EMPTY */
   14647           79 :                 { $$ = NULL; }
   14648              :         ;
   14649              : 
   14650              : /*****************************************************************************
   14651              :  *
   14652              :  *  Type syntax
   14653              :  *      SQL introduces a large amount of type-specific syntax.
   14654              :  *      Define individual clauses to handle these cases, and use
   14655              :  *       the generic case to handle regular type-extensible Postgres syntax.
   14656              :  *      - thomas 1997-10-10
   14657              :  *
   14658              :  *****************************************************************************/
   14659              : 
   14660              : Typename:   SimpleTypename opt_array_bounds
   14661              :                 {
   14662       260392 :                     $$ = $1;
   14663       260392 :                     $$->arrayBounds = $2;
   14664              :                 }
   14665              :             | SETOF SimpleTypename opt_array_bounds
   14666              :                 {
   14667          887 :                     $$ = $2;
   14668          887 :                     $$->arrayBounds = $3;
   14669          887 :                     $$->setof = true;
   14670              :                 }
   14671              :             /* SQL standard syntax, currently only one-dimensional */
   14672              :             | SimpleTypename ARRAY '[' Iconst ']'
   14673              :                 {
   14674            3 :                     $$ = $1;
   14675            3 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14676              :                 }
   14677              :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14678              :                 {
   14679            0 :                     $$ = $2;
   14680            0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14681            0 :                     $$->setof = true;
   14682              :                 }
   14683              :             | SimpleTypename ARRAY
   14684              :                 {
   14685            0 :                     $$ = $1;
   14686            0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14687              :                 }
   14688              :             | SETOF SimpleTypename ARRAY
   14689              :                 {
   14690            0 :                     $$ = $2;
   14691            0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14692            0 :                     $$->setof = true;
   14693              :                 }
   14694              :         ;
   14695              : 
   14696              : opt_array_bounds:
   14697              :             opt_array_bounds '[' ']'
   14698         7480 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14699              :             | opt_array_bounds '[' Iconst ']'
   14700           31 :                     {  $$ = lappend($1, makeInteger($3)); }
   14701              :             | /*EMPTY*/
   14702       261279 :                     {  $$ = NIL; }
   14703              :         ;
   14704              : 
   14705              : SimpleTypename:
   14706       205630 :             GenericType                             { $$ = $1; }
   14707        47982 :             | Numeric                               { $$ = $1; }
   14708          987 :             | Bit                                   { $$ = $1; }
   14709         1635 :             | Character                             { $$ = $1; }
   14710         2630 :             | ConstDatetime                         { $$ = $1; }
   14711              :             | ConstInterval opt_interval
   14712              :                 {
   14713         1863 :                     $$ = $1;
   14714         1863 :                     $$->typmods = $2;
   14715              :                 }
   14716              :             | ConstInterval '(' Iconst ')'
   14717              :                 {
   14718            0 :                     $$ = $1;
   14719            0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14720              :                                              makeIntConst($3, @3));
   14721              :                 }
   14722          759 :             | JsonType                              { $$ = $1; }
   14723              :         ;
   14724              : 
   14725              : /* We have a separate ConstTypename to allow defaulting fixed-length
   14726              :  * types such as CHAR() and BIT() to an unspecified length.
   14727              :  * SQL9x requires that these default to a length of one, but this
   14728              :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14729              :  * where there is an obvious better choice to make.
   14730              :  * Note that ConstInterval is not included here since it must
   14731              :  * be pushed up higher in the rules to accommodate the postfix
   14732              :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14733              :  * the generic-type-name case in AexprConst to avoid premature
   14734              :  * reduce/reduce conflicts against function names.
   14735              :  */
   14736              : ConstTypename:
   14737           39 :             Numeric                                 { $$ = $1; }
   14738            0 :             | ConstBit                              { $$ = $1; }
   14739           17 :             | ConstCharacter                        { $$ = $1; }
   14740         1400 :             | ConstDatetime                         { $$ = $1; }
   14741          132 :             | JsonType                              { $$ = $1; }
   14742              :         ;
   14743              : 
   14744              : /*
   14745              :  * GenericType covers all type names that don't have special syntax mandated
   14746              :  * by the standard, including qualified names.  We also allow type modifiers.
   14747              :  * To avoid parsing conflicts against function invocations, the modifiers
   14748              :  * have to be shown as expr_list here, but parse analysis will only accept
   14749              :  * constants for them.
   14750              :  */
   14751              : GenericType:
   14752              :             type_function_name opt_type_modifiers
   14753              :                 {
   14754       144962 :                     $$ = makeTypeName($1);
   14755       144962 :                     $$->typmods = $2;
   14756       144962 :                     $$->location = @1;
   14757              :                 }
   14758              :             | type_function_name attrs opt_type_modifiers
   14759              :                 {
   14760        60668 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14761        60668 :                     $$->typmods = $3;
   14762        60668 :                     $$->location = @1;
   14763              :                 }
   14764              :         ;
   14765              : 
   14766          675 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14767       208080 :                     | /* EMPTY */                   { $$ = NIL; }
   14768              :         ;
   14769              : 
   14770              : /*
   14771              :  * SQL numeric data types
   14772              :  */
   14773              : Numeric:    INT_P
   14774              :                 {
   14775        20105 :                     $$ = SystemTypeName("int4");
   14776        20105 :                     $$->location = @1;
   14777              :                 }
   14778              :             | INTEGER
   14779              :                 {
   14780        12732 :                     $$ = SystemTypeName("int4");
   14781        12732 :                     $$->location = @1;
   14782              :                 }
   14783              :             | SMALLINT
   14784              :                 {
   14785          649 :                     $$ = SystemTypeName("int2");
   14786          649 :                     $$->location = @1;
   14787              :                 }
   14788              :             | BIGINT
   14789              :                 {
   14790         2640 :                     $$ = SystemTypeName("int8");
   14791         2640 :                     $$->location = @1;
   14792              :                 }
   14793              :             | REAL
   14794              :                 {
   14795         3472 :                     $$ = SystemTypeName("float4");
   14796         3472 :                     $$->location = @1;
   14797              :                 }
   14798              :             | FLOAT_P opt_float
   14799              :                 {
   14800          269 :                     $$ = $2;
   14801          269 :                     $$->location = @1;
   14802              :                 }
   14803              :             | DOUBLE_P PRECISION
   14804              :                 {
   14805          402 :                     $$ = SystemTypeName("float8");
   14806          402 :                     $$->location = @1;
   14807              :                 }
   14808              :             | DECIMAL_P opt_type_modifiers
   14809              :                 {
   14810           18 :                     $$ = SystemTypeName("numeric");
   14811           18 :                     $$->typmods = $2;
   14812           18 :                     $$->location = @1;
   14813              :                 }
   14814              :             | DEC opt_type_modifiers
   14815              :                 {
   14816            0 :                     $$ = SystemTypeName("numeric");
   14817            0 :                     $$->typmods = $2;
   14818            0 :                     $$->location = @1;
   14819              :                 }
   14820              :             | NUMERIC opt_type_modifiers
   14821              :                 {
   14822         3107 :                     $$ = SystemTypeName("numeric");
   14823         3107 :                     $$->typmods = $2;
   14824         3107 :                     $$->location = @1;
   14825              :                 }
   14826              :             | BOOLEAN_P
   14827              :                 {
   14828         4627 :                     $$ = SystemTypeName("bool");
   14829         4627 :                     $$->location = @1;
   14830              :                 }
   14831              :         ;
   14832              : 
   14833              : opt_float:  '(' Iconst ')'
   14834              :                 {
   14835              :                     /*
   14836              :                      * Check FLOAT() precision limits assuming IEEE floating
   14837              :                      * types - thomas 1997-09-18
   14838              :                      */
   14839            1 :                     if ($2 < 1)
   14840            0 :                         ereport(ERROR,
   14841              :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14842              :                                  errmsg("precision for type float must be at least 1 bit"),
   14843              :                                  parser_errposition(@2)));
   14844            1 :                     else if ($2 <= 24)
   14845            1 :                         $$ = SystemTypeName("float4");
   14846            0 :                     else if ($2 <= 53)
   14847            0 :                         $$ = SystemTypeName("float8");
   14848              :                     else
   14849            0 :                         ereport(ERROR,
   14850              :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14851              :                                  errmsg("precision for type float must be less than 54 bits"),
   14852              :                                  parser_errposition(@2)));
   14853              :                 }
   14854              :             | /*EMPTY*/
   14855              :                 {
   14856          268 :                     $$ = SystemTypeName("float8");
   14857              :                 }
   14858              :         ;
   14859              : 
   14860              : /*
   14861              :  * SQL bit-field data types
   14862              :  * The following implements BIT() and BIT VARYING().
   14863              :  */
   14864              : Bit:        BitWithLength
   14865              :                 {
   14866          869 :                     $$ = $1;
   14867              :                 }
   14868              :             | BitWithoutLength
   14869              :                 {
   14870          118 :                     $$ = $1;
   14871              :                 }
   14872              :         ;
   14873              : 
   14874              : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14875              : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14876              : ConstBit:   BitWithLength
   14877              :                 {
   14878            0 :                     $$ = $1;
   14879              :                 }
   14880              :             | BitWithoutLength
   14881              :                 {
   14882            0 :                     $$ = $1;
   14883            0 :                     $$->typmods = NIL;
   14884              :                 }
   14885              :         ;
   14886              : 
   14887              : BitWithLength:
   14888              :             BIT opt_varying '(' expr_list ')'
   14889              :                 {
   14890              :                     char *typname;
   14891              : 
   14892          869 :                     typname = $2 ? "varbit" : "bit";
   14893          869 :                     $$ = SystemTypeName(typname);
   14894          869 :                     $$->typmods = $4;
   14895          869 :                     $$->location = @1;
   14896              :                 }
   14897              :         ;
   14898              : 
   14899              : BitWithoutLength:
   14900              :             BIT opt_varying
   14901              :                 {
   14902              :                     /* bit defaults to bit(1), varbit to no limit */
   14903          118 :                     if ($2)
   14904              :                     {
   14905           10 :                         $$ = SystemTypeName("varbit");
   14906              :                     }
   14907              :                     else
   14908              :                     {
   14909          108 :                         $$ = SystemTypeName("bit");
   14910          108 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14911              :                     }
   14912          118 :                     $$->location = @1;
   14913              :                 }
   14914              :         ;
   14915              : 
   14916              : 
   14917              : /*
   14918              :  * SQL character data types
   14919              :  * The following implements CHAR() and VARCHAR().
   14920              :  */
   14921              : Character:  CharacterWithLength
   14922              :                 {
   14923          992 :                     $$ = $1;
   14924              :                 }
   14925              :             | CharacterWithoutLength
   14926              :                 {
   14927          643 :                     $$ = $1;
   14928              :                 }
   14929              :         ;
   14930              : 
   14931              : ConstCharacter:  CharacterWithLength
   14932              :                 {
   14933            6 :                     $$ = $1;
   14934              :                 }
   14935              :             | CharacterWithoutLength
   14936              :                 {
   14937              :                     /* Length was not specified so allow to be unrestricted.
   14938              :                      * This handles problems with fixed-length (bpchar) strings
   14939              :                      * which in column definitions must default to a length
   14940              :                      * of one, but should not be constrained if the length
   14941              :                      * was not specified.
   14942              :                      */
   14943           11 :                     $$ = $1;
   14944           11 :                     $$->typmods = NIL;
   14945              :                 }
   14946              :         ;
   14947              : 
   14948              : CharacterWithLength:  character '(' Iconst ')'
   14949              :                 {
   14950          998 :                     $$ = SystemTypeName($1);
   14951          998 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14952          998 :                     $$->location = @1;
   14953              :                 }
   14954              :         ;
   14955              : 
   14956              : CharacterWithoutLength:  character
   14957              :                 {
   14958          654 :                     $$ = SystemTypeName($1);
   14959              :                     /* char defaults to char(1), varchar to no limit */
   14960          654 :                     if (strcmp($1, "bpchar") == 0)
   14961          125 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14962          654 :                     $$->location = @1;
   14963              :                 }
   14964              :         ;
   14965              : 
   14966              : character:  CHARACTER opt_varying
   14967          282 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14968              :             | CHAR_P opt_varying
   14969          586 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14970              :             | VARCHAR
   14971          782 :                                         { $$ = "varchar"; }
   14972              :             | NATIONAL CHARACTER opt_varying
   14973            0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14974              :             | NATIONAL CHAR_P opt_varying
   14975            0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14976              :             | NCHAR opt_varying
   14977            2 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14978              :         ;
   14979              : 
   14980              : opt_varying:
   14981          231 :             VARYING                                 { $$ = true; }
   14982         1626 :             | /*EMPTY*/                             { $$ = false; }
   14983              :         ;
   14984              : 
   14985              : /*
   14986              :  * SQL date/time types
   14987              :  */
   14988              : ConstDatetime:
   14989              :             TIMESTAMP '(' Iconst ')' opt_timezone
   14990              :                 {
   14991           68 :                     if ($5)
   14992           56 :                         $$ = SystemTypeName("timestamptz");
   14993              :                     else
   14994           12 :                         $$ = SystemTypeName("timestamp");
   14995           68 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14996           68 :                     $$->location = @1;
   14997              :                 }
   14998              :             | TIMESTAMP opt_timezone
   14999              :                 {
   15000         2688 :                     if ($2)
   15001          709 :                         $$ = SystemTypeName("timestamptz");
   15002              :                     else
   15003         1979 :                         $$ = SystemTypeName("timestamp");
   15004         2688 :                     $$->location = @1;
   15005              :                 }
   15006              :             | TIME '(' Iconst ')' opt_timezone
   15007              :                 {
   15008           11 :                     if ($5)
   15009            4 :                         $$ = SystemTypeName("timetz");
   15010              :                     else
   15011            7 :                         $$ = SystemTypeName("time");
   15012           11 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   15013           11 :                     $$->location = @1;
   15014              :                 }
   15015              :             | TIME opt_timezone
   15016              :                 {
   15017         1263 :                     if ($2)
   15018          171 :                         $$ = SystemTypeName("timetz");
   15019              :                     else
   15020         1092 :                         $$ = SystemTypeName("time");
   15021         1263 :                     $$->location = @1;
   15022              :                 }
   15023              :         ;
   15024              : 
   15025              : ConstInterval:
   15026              :             INTERVAL
   15027              :                 {
   15028         3518 :                     $$ = SystemTypeName("interval");
   15029         3518 :                     $$->location = @1;
   15030              :                 }
   15031              :         ;
   15032              : 
   15033              : opt_timezone:
   15034          940 :             WITH_LA TIME ZONE                       { $$ = true; }
   15035          288 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   15036         2802 :             | /*EMPTY*/                             { $$ = false; }
   15037              :         ;
   15038              : 
   15039              : opt_interval:
   15040              :             YEAR_P
   15041            6 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   15042              :             | MONTH_P
   15043            9 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   15044              :             | DAY_P
   15045            9 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   15046              :             | HOUR_P
   15047            6 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   15048              :             | MINUTE_P
   15049            6 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   15050              :             | interval_second
   15051           18 :                 { $$ = $1; }
   15052              :             | YEAR_P TO MONTH_P
   15053              :                 {
   15054            9 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   15055              :                                                  INTERVAL_MASK(MONTH), @1));
   15056              :                 }
   15057              :             | DAY_P TO HOUR_P
   15058              :                 {
   15059           12 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   15060              :                                                  INTERVAL_MASK(HOUR), @1));
   15061              :                 }
   15062              :             | DAY_P TO MINUTE_P
   15063              :                 {
   15064           12 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   15065              :                                                  INTERVAL_MASK(HOUR) |
   15066              :                                                  INTERVAL_MASK(MINUTE), @1));
   15067              :                 }
   15068              :             | DAY_P TO interval_second
   15069              :                 {
   15070           24 :                     $$ = $3;
   15071           24 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   15072              :                                                 INTERVAL_MASK(HOUR) |
   15073              :                                                 INTERVAL_MASK(MINUTE) |
   15074           24 :                                                 INTERVAL_MASK(SECOND), @1);
   15075              :                 }
   15076              :             | HOUR_P TO MINUTE_P
   15077              :                 {
   15078            9 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   15079              :                                                  INTERVAL_MASK(MINUTE), @1));
   15080              :                 }
   15081              :             | HOUR_P TO interval_second
   15082              :                 {
   15083           18 :                     $$ = $3;
   15084           18 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   15085              :                                                 INTERVAL_MASK(MINUTE) |
   15086           18 :                                                 INTERVAL_MASK(SECOND), @1);
   15087              :                 }
   15088              :             | MINUTE_P TO interval_second
   15089              :                 {
   15090           33 :                     $$ = $3;
   15091           33 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   15092           33 :                                                 INTERVAL_MASK(SECOND), @1);
   15093              :                 }
   15094              :             | /*EMPTY*/
   15095         3341 :                 { $$ = NIL; }
   15096              :         ;
   15097              : 
   15098              : interval_second:
   15099              :             SECOND_P
   15100              :                 {
   15101           51 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   15102              :                 }
   15103              :             | SECOND_P '(' Iconst ')'
   15104              :                 {
   15105           42 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   15106              :                                     makeIntConst($3, @3));
   15107              :                 }
   15108              :         ;
   15109              : 
   15110              : JsonType:
   15111              :             JSON
   15112              :                 {
   15113          891 :                     $$ = SystemTypeName("json");
   15114          891 :                     $$->location = @1;
   15115              :                 }
   15116              :         ;
   15117              : 
   15118              : /*****************************************************************************
   15119              :  *
   15120              :  *  expression grammar
   15121              :  *
   15122              :  *****************************************************************************/
   15123              : 
   15124              : /*
   15125              :  * General expressions
   15126              :  * This is the heart of the expression syntax.
   15127              :  *
   15128              :  * We have two expression types: a_expr is the unrestricted kind, and
   15129              :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   15130              :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   15131              :  * because that use of AND conflicts with AND as a boolean operator.  So,
   15132              :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   15133              :  *
   15134              :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   15135              :  * always be used by surrounding it with parens.
   15136              :  *
   15137              :  * c_expr is all the productions that are common to a_expr and b_expr;
   15138              :  * it's factored out just to eliminate redundant coding.
   15139              :  *
   15140              :  * Be careful of productions involving more than one terminal token.
   15141              :  * By default, bison will assign such productions the precedence of their
   15142              :  * last terminal, but in nearly all cases you want it to be the precedence
   15143              :  * of the first terminal instead; otherwise you will not get the behavior
   15144              :  * you expect!  So we use %prec annotations freely to set precedences.
   15145              :  */
   15146      1963107 : a_expr:     c_expr                                  { $$ = $1; }
   15147              :             | a_expr TYPECAST Typename
   15148       123989 :                     { $$ = makeTypeCast($1, $3, @2); }
   15149              :             | a_expr COLLATE any_name
   15150              :                 {
   15151         4758 :                     CollateClause *n = makeNode(CollateClause);
   15152              : 
   15153         4758 :                     n->arg = $1;
   15154         4758 :                     n->collname = $3;
   15155         4758 :                     n->location = @2;
   15156         4758 :                     $$ = (Node *) n;
   15157              :                 }
   15158              :             | a_expr AT TIME ZONE a_expr            %prec AT
   15159              :                 {
   15160          204 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15161          204 :                                                list_make2($5, $1),
   15162              :                                                COERCE_SQL_SYNTAX,
   15163          204 :                                                @2);
   15164              :                 }
   15165              :             | a_expr AT LOCAL                       %prec AT
   15166              :                 {
   15167           21 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15168           21 :                                                list_make1($1),
   15169              :                                                COERCE_SQL_SYNTAX,
   15170              :                                                -1);
   15171              :                 }
   15172              :         /*
   15173              :          * These operators must be called out explicitly in order to make use
   15174              :          * of bison's automatic operator-precedence handling.  All other
   15175              :          * operator names are handled by the generic productions using "Op",
   15176              :          * below; and all those operators will have the same precedence.
   15177              :          *
   15178              :          * If you add more explicitly-known operators, be sure to add them
   15179              :          * also to b_expr and to the MathOp list below.
   15180              :          */
   15181              :             | '+' a_expr                    %prec UMINUS
   15182            6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15183              :             | '-' a_expr                    %prec UMINUS
   15184         4678 :                 { $$ = doNegate($2, @1); }
   15185              :             | a_expr '+' a_expr
   15186         7552 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15187              :             | a_expr '-' a_expr
   15188         2302 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15189              :             | a_expr '*' a_expr
   15190         3229 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15191              :             | a_expr '/' a_expr
   15192         1748 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15193              :             | a_expr '%' a_expr
   15194         1714 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15195              :             | a_expr '^' a_expr
   15196          239 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15197              :             | a_expr '<' a_expr
   15198         5385 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15199              :             | a_expr '>' a_expr
   15200         8776 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15201              :             | a_expr '=' a_expr
   15202       207831 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15203              :             | a_expr LESS_EQUALS a_expr
   15204         2531 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15205              :             | a_expr GREATER_EQUALS a_expr
   15206         6501 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15207              :             | a_expr NOT_EQUALS a_expr
   15208        21290 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15209              : 
   15210              :             | a_expr qual_Op a_expr             %prec Op
   15211        30666 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15212              :             | qual_Op a_expr                    %prec Op
   15213          123 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15214              : 
   15215              :             | a_expr AND a_expr
   15216       123449 :                 { $$ = makeAndExpr($1, $3, @2); }
   15217              :             | a_expr OR a_expr
   15218         8796 :                 { $$ = makeOrExpr($1, $3, @2); }
   15219              :             | NOT a_expr
   15220         8732 :                 { $$ = makeNotExpr($2, @1); }
   15221              :             | NOT_LA a_expr                     %prec NOT
   15222            0 :                 { $$ = makeNotExpr($2, @1); }
   15223              : 
   15224              :             | a_expr LIKE a_expr
   15225              :                 {
   15226          986 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15227          986 :                                                    $1, $3, @2);
   15228              :                 }
   15229              :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15230              :                 {
   15231           48 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15232           48 :                                                  list_make2($3, $5),
   15233              :                                                  COERCE_EXPLICIT_CALL,
   15234           48 :                                                  @2);
   15235           48 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15236           48 :                                                    $1, (Node *) n, @2);
   15237              :                 }
   15238              :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15239              :                 {
   15240           99 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15241           99 :                                                    $1, $4, @2);
   15242              :                 }
   15243              :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15244              :                 {
   15245           48 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15246           48 :                                                  list_make2($4, $6),
   15247              :                                                  COERCE_EXPLICIT_CALL,
   15248           48 :                                                  @2);
   15249           48 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15250           48 :                                                    $1, (Node *) n, @2);
   15251              :                 }
   15252              :             | a_expr ILIKE a_expr
   15253              :                 {
   15254           86 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15255           86 :                                                    $1, $3, @2);
   15256              :                 }
   15257              :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15258              :                 {
   15259            0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15260            0 :                                                  list_make2($3, $5),
   15261              :                                                  COERCE_EXPLICIT_CALL,
   15262            0 :                                                  @2);
   15263            0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15264            0 :                                                    $1, (Node *) n, @2);
   15265              :                 }
   15266              :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15267              :                 {
   15268           15 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15269           15 :                                                    $1, $4, @2);
   15270              :                 }
   15271              :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15272              :                 {
   15273            0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15274            0 :                                                  list_make2($4, $6),
   15275              :                                                  COERCE_EXPLICIT_CALL,
   15276            0 :                                                  @2);
   15277            0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15278            0 :                                                    $1, (Node *) n, @2);
   15279              :                 }
   15280              : 
   15281              :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15282              :                 {
   15283           44 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15284           44 :                                                  list_make1($4),
   15285              :                                                  COERCE_EXPLICIT_CALL,
   15286           44 :                                                  @2);
   15287           44 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15288           44 :                                                    $1, (Node *) n, @2);
   15289              :                 }
   15290              :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15291              :                 {
   15292           18 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15293           18 :                                                  list_make2($4, $6),
   15294              :                                                  COERCE_EXPLICIT_CALL,
   15295           18 :                                                  @2);
   15296           18 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15297           18 :                                                    $1, (Node *) n, @2);
   15298              :                 }
   15299              :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15300              :                 {
   15301            0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15302            0 :                                                  list_make1($5),
   15303              :                                                  COERCE_EXPLICIT_CALL,
   15304            0 :                                                  @2);
   15305            0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15306            0 :                                                    $1, (Node *) n, @2);
   15307              :                 }
   15308              :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15309              :                 {
   15310            0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15311            0 :                                                  list_make2($5, $7),
   15312              :                                                  COERCE_EXPLICIT_CALL,
   15313            0 :                                                  @2);
   15314            0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15315            0 :                                                    $1, (Node *) n, @2);
   15316              :                 }
   15317              : 
   15318              :             /* NullTest clause
   15319              :              * Define SQL-style Null test clause.
   15320              :              * Allow two forms described in the standard:
   15321              :              *  a IS NULL
   15322              :              *  a IS NOT NULL
   15323              :              * Allow two SQL extensions
   15324              :              *  a ISNULL
   15325              :              *  a NOTNULL
   15326              :              */
   15327              :             | a_expr IS NULL_P                          %prec IS
   15328              :                 {
   15329         2828 :                     NullTest   *n = makeNode(NullTest);
   15330              : 
   15331         2828 :                     n->arg = (Expr *) $1;
   15332         2828 :                     n->nulltesttype = IS_NULL;
   15333         2828 :                     n->location = @2;
   15334         2828 :                     $$ = (Node *) n;
   15335              :                 }
   15336              :             | a_expr ISNULL
   15337              :                 {
   15338           48 :                     NullTest   *n = makeNode(NullTest);
   15339              : 
   15340           48 :                     n->arg = (Expr *) $1;
   15341           48 :                     n->nulltesttype = IS_NULL;
   15342           48 :                     n->location = @2;
   15343           48 :                     $$ = (Node *) n;
   15344              :                 }
   15345              :             | a_expr IS NOT NULL_P                      %prec IS
   15346              :                 {
   15347         6991 :                     NullTest   *n = makeNode(NullTest);
   15348              : 
   15349         6991 :                     n->arg = (Expr *) $1;
   15350         6991 :                     n->nulltesttype = IS_NOT_NULL;
   15351         6991 :                     n->location = @2;
   15352         6991 :                     $$ = (Node *) n;
   15353              :                 }
   15354              :             | a_expr NOTNULL
   15355              :                 {
   15356            3 :                     NullTest   *n = makeNode(NullTest);
   15357              : 
   15358            3 :                     n->arg = (Expr *) $1;
   15359            3 :                     n->nulltesttype = IS_NOT_NULL;
   15360            3 :                     n->location = @2;
   15361            3 :                     $$ = (Node *) n;
   15362              :                 }
   15363              :             | row OVERLAPS row
   15364              :                 {
   15365          492 :                     if (list_length($1) != 2)
   15366            0 :                         ereport(ERROR,
   15367              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15368              :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15369              :                                  parser_errposition(@1)));
   15370          492 :                     if (list_length($3) != 2)
   15371            0 :                         ereport(ERROR,
   15372              :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15373              :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15374              :                                  parser_errposition(@3)));
   15375          492 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15376          492 :                                                list_concat($1, $3),
   15377              :                                                COERCE_SQL_SYNTAX,
   15378          492 :                                                @2);
   15379              :                 }
   15380              :             | a_expr IS TRUE_P                          %prec IS
   15381              :                 {
   15382          296 :                     BooleanTest *b = makeNode(BooleanTest);
   15383              : 
   15384          296 :                     b->arg = (Expr *) $1;
   15385          296 :                     b->booltesttype = IS_TRUE;
   15386          296 :                     b->location = @2;
   15387          296 :                     $$ = (Node *) b;
   15388              :                 }
   15389              :             | a_expr IS NOT TRUE_P                      %prec IS
   15390              :                 {
   15391           76 :                     BooleanTest *b = makeNode(BooleanTest);
   15392              : 
   15393           76 :                     b->arg = (Expr *) $1;
   15394           76 :                     b->booltesttype = IS_NOT_TRUE;
   15395           76 :                     b->location = @2;
   15396           76 :                     $$ = (Node *) b;
   15397              :                 }
   15398              :             | a_expr IS FALSE_P                         %prec IS
   15399              :                 {
   15400          135 :                     BooleanTest *b = makeNode(BooleanTest);
   15401              : 
   15402          135 :                     b->arg = (Expr *) $1;
   15403          135 :                     b->booltesttype = IS_FALSE;
   15404          135 :                     b->location = @2;
   15405          135 :                     $$ = (Node *) b;
   15406              :                 }
   15407              :             | a_expr IS NOT FALSE_P                     %prec IS
   15408              :                 {
   15409           52 :                     BooleanTest *b = makeNode(BooleanTest);
   15410              : 
   15411           52 :                     b->arg = (Expr *) $1;
   15412           52 :                     b->booltesttype = IS_NOT_FALSE;
   15413           52 :                     b->location = @2;
   15414           52 :                     $$ = (Node *) b;
   15415              :                 }
   15416              :             | a_expr IS UNKNOWN                         %prec IS
   15417              :                 {
   15418           38 :                     BooleanTest *b = makeNode(BooleanTest);
   15419              : 
   15420           38 :                     b->arg = (Expr *) $1;
   15421           38 :                     b->booltesttype = IS_UNKNOWN;
   15422           38 :                     b->location = @2;
   15423           38 :                     $$ = (Node *) b;
   15424              :                 }
   15425              :             | a_expr IS NOT UNKNOWN                     %prec IS
   15426              :                 {
   15427           30 :                     BooleanTest *b = makeNode(BooleanTest);
   15428              : 
   15429           30 :                     b->arg = (Expr *) $1;
   15430           30 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15431           30 :                     b->location = @2;
   15432           30 :                     $$ = (Node *) b;
   15433              :                 }
   15434              :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15435              :                 {
   15436          711 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15437              :                 }
   15438              :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15439              :                 {
   15440           64 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15441              :                 }
   15442              :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15443              :                 {
   15444          235 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15445              :                                                    "BETWEEN",
   15446          235 :                                                    $1,
   15447          235 :                                                    (Node *) list_make2($4, $6),
   15448          235 :                                                    @2);
   15449              :                 }
   15450              :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15451              :                 {
   15452            6 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15453              :                                                    "NOT BETWEEN",
   15454            6 :                                                    $1,
   15455            6 :                                                    (Node *) list_make2($5, $7),
   15456            6 :                                                    @2);
   15457              :                 }
   15458              :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15459              :                 {
   15460            6 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15461              :                                                    "BETWEEN SYMMETRIC",
   15462            6 :                                                    $1,
   15463            6 :                                                    (Node *) list_make2($4, $6),
   15464            6 :                                                    @2);
   15465              :                 }
   15466              :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15467              :                 {
   15468            6 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15469              :                                                    "NOT BETWEEN SYMMETRIC",
   15470            6 :                                                    $1,
   15471            6 :                                                    (Node *) list_make2($5, $7),
   15472            6 :                                                    @2);
   15473              :                 }
   15474              :             | a_expr IN_P select_with_parens
   15475              :                 {
   15476              :                     /* generate foo = ANY (subquery) */
   15477         2866 :                     SubLink    *n = makeNode(SubLink);
   15478              : 
   15479         2866 :                     n->subselect = $3;
   15480         2866 :                     n->subLinkType = ANY_SUBLINK;
   15481         2866 :                     n->subLinkId = 0;
   15482         2866 :                     n->testexpr = $1;
   15483         2866 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15484         2866 :                     n->location = @2;
   15485         2866 :                     $$ = (Node *) n;
   15486              :                 }
   15487              :             | a_expr IN_P '(' expr_list ')'
   15488              :                 {
   15489              :                     /* generate scalar IN expression */
   15490         9893 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
   15491              : 
   15492         9893 :                     n->rexpr_list_start = @3;
   15493         9893 :                     n->rexpr_list_end = @5;
   15494         9893 :                     $$ = (Node *) n;
   15495              :                 }
   15496              :             | a_expr NOT_LA IN_P select_with_parens         %prec NOT_LA
   15497              :                 {
   15498              :                     /* generate NOT (foo = ANY (subquery)) */
   15499           60 :                     SubLink    *n = makeNode(SubLink);
   15500              : 
   15501           60 :                     n->subselect = $4;
   15502           60 :                     n->subLinkType = ANY_SUBLINK;
   15503           60 :                     n->subLinkId = 0;
   15504           60 :                     n->testexpr = $1;
   15505           60 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15506           60 :                     n->location = @2;
   15507              :                     /* Stick a NOT on top; must have same parse location */
   15508           60 :                     $$ = makeNotExpr((Node *) n, @2);
   15509              :                 }
   15510              :             | a_expr NOT_LA IN_P '(' expr_list ')'
   15511              :                 {
   15512              :                     /* generate scalar NOT IN expression */
   15513         1427 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
   15514              : 
   15515         1427 :                     n->rexpr_list_start = @4;
   15516         1427 :                     n->rexpr_list_end = @6;
   15517         1427 :                     $$ = (Node *) n;
   15518              :                 }
   15519              :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15520              :                 {
   15521           90 :                     SubLink    *n = makeNode(SubLink);
   15522              : 
   15523           90 :                     n->subLinkType = $3;
   15524           90 :                     n->subLinkId = 0;
   15525           90 :                     n->testexpr = $1;
   15526           90 :                     n->operName = $2;
   15527           90 :                     n->subselect = $4;
   15528           90 :                     n->location = @2;
   15529           90 :                     $$ = (Node *) n;
   15530              :                 }
   15531              :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15532              :                 {
   15533         8863 :                     if ($3 == ANY_SUBLINK)
   15534         8713 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15535              :                     else
   15536          150 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15537              :                 }
   15538              :             | UNIQUE opt_unique_null_treatment select_with_parens
   15539              :                 {
   15540              :                     /* Not sure how to get rid of the parentheses
   15541              :                      * but there are lots of shift/reduce errors without them.
   15542              :                      *
   15543              :                      * Should be able to implement this by plopping the entire
   15544              :                      * select into a node, then transforming the target expressions
   15545              :                      * from whatever they are into count(*), and testing the
   15546              :                      * entire result equal to one.
   15547              :                      * But, will probably implement a separate node in the executor.
   15548              :                      */
   15549            0 :                     ereport(ERROR,
   15550              :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15551              :                              errmsg("UNIQUE predicate is not yet implemented"),
   15552              :                              parser_errposition(@1)));
   15553              :                 }
   15554              :             | a_expr IS DOCUMENT_P                  %prec IS
   15555              :                 {
   15556            9 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15557            9 :                                      list_make1($1), @2);
   15558              :                 }
   15559              :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15560              :                 {
   15561            9 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15562            9 :                                                  list_make1($1), @2),
   15563            9 :                                      @2);
   15564              :                 }
   15565              :             | a_expr IS NORMALIZED                              %prec IS
   15566              :                 {
   15567            6 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15568            6 :                                                list_make1($1),
   15569              :                                                COERCE_SQL_SYNTAX,
   15570            6 :                                                @2);
   15571              :                 }
   15572              :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15573              :                 {
   15574           18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15575           18 :                                                list_make2($1, makeStringConst($3, @3)),
   15576              :                                                COERCE_SQL_SYNTAX,
   15577           18 :                                                @2);
   15578              :                 }
   15579              :             | a_expr IS NOT NORMALIZED                          %prec IS
   15580              :                 {
   15581            0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15582            0 :                                                            list_make1($1),
   15583              :                                                            COERCE_SQL_SYNTAX,
   15584            0 :                                                            @2),
   15585            0 :                                      @2);
   15586              :                 }
   15587              :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15588              :                 {
   15589            0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15590            0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15591              :                                                            COERCE_SQL_SYNTAX,
   15592            0 :                                                            @2),
   15593            0 :                                      @2);
   15594              :                 }
   15595              :             | a_expr IS json_predicate_type_constraint
   15596              :                     json_key_uniqueness_constraint_opt      %prec IS
   15597              :                 {
   15598          152 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15599              : 
   15600          152 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15601              :                 }
   15602              :             /*
   15603              :              * Required by SQL/JSON, but there are conflicts
   15604              :             | a_expr
   15605              :                 json_format_clause
   15606              :                 IS  json_predicate_type_constraint
   15607              :                     json_key_uniqueness_constraint_opt      %prec IS
   15608              :                 {
   15609              :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15610              :                 }
   15611              :             */
   15612              :             | a_expr IS NOT
   15613              :                     json_predicate_type_constraint
   15614              :                     json_key_uniqueness_constraint_opt      %prec IS
   15615              :                 {
   15616           23 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15617              : 
   15618           23 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15619              :                 }
   15620              :             /*
   15621              :              * Required by SQL/JSON, but there are conflicts
   15622              :             | a_expr
   15623              :                 json_format_clause
   15624              :                 IS NOT
   15625              :                     json_predicate_type_constraint
   15626              :                     json_key_uniqueness_constraint_opt      %prec IS
   15627              :                 {
   15628              :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15629              :                 }
   15630              :             */
   15631              :             | DEFAULT
   15632              :                 {
   15633              :                     /*
   15634              :                      * The SQL spec only allows DEFAULT in "contextually typed
   15635              :                      * expressions", but for us, it's easier to allow it in
   15636              :                      * any a_expr and then throw error during parse analysis
   15637              :                      * if it's in an inappropriate context.  This way also
   15638              :                      * lets us say something smarter than "syntax error".
   15639              :                      */
   15640          796 :                     SetToDefault *n = makeNode(SetToDefault);
   15641              : 
   15642              :                     /* parse analysis will fill in the rest */
   15643          796 :                     n->location = @1;
   15644          796 :                     $$ = (Node *) n;
   15645              :                 }
   15646              :         ;
   15647              : 
   15648              : /*
   15649              :  * Restricted expressions
   15650              :  *
   15651              :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15652              :  *
   15653              :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15654              :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15655              :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15656              :  */
   15657              : b_expr:     c_expr
   15658         1945 :                 { $$ = $1; }
   15659              :             | b_expr TYPECAST Typename
   15660          106 :                 { $$ = makeTypeCast($1, $3, @2); }
   15661              :             | '+' b_expr                    %prec UMINUS
   15662            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15663              :             | '-' b_expr                    %prec UMINUS
   15664           33 :                 { $$ = doNegate($2, @1); }
   15665              :             | b_expr '+' b_expr
   15666           18 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15667              :             | b_expr '-' b_expr
   15668            6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15669              :             | b_expr '*' b_expr
   15670            6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15671              :             | b_expr '/' b_expr
   15672            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15673              :             | b_expr '%' b_expr
   15674            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15675              :             | b_expr '^' b_expr
   15676            3 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15677              :             | b_expr '<' b_expr
   15678            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15679              :             | b_expr '>' b_expr
   15680            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15681              :             | b_expr '=' b_expr
   15682            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15683              :             | b_expr LESS_EQUALS b_expr
   15684            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15685              :             | b_expr GREATER_EQUALS b_expr
   15686            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15687              :             | b_expr NOT_EQUALS b_expr
   15688            0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15689              :             | b_expr qual_Op b_expr             %prec Op
   15690            6 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15691              :             | qual_Op b_expr                    %prec Op
   15692            0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15693              :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15694              :                 {
   15695            0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15696              :                 }
   15697              :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15698              :                 {
   15699            0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15700              :                 }
   15701              :             | b_expr IS DOCUMENT_P                  %prec IS
   15702              :                 {
   15703            0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15704            0 :                                      list_make1($1), @2);
   15705              :                 }
   15706              :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15707              :                 {
   15708            0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15709            0 :                                                  list_make1($1), @2),
   15710            0 :                                      @2);
   15711              :                 }
   15712              :         ;
   15713              : 
   15714              : /*
   15715              :  * Productions that can be used in both a_expr and b_expr.
   15716              :  *
   15717              :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15718              :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15719              :  * inside parentheses, such as function arguments; that cannot introduce
   15720              :  * ambiguity to the b_expr syntax.
   15721              :  */
   15722       976556 : c_expr:     columnref                               { $$ = $1; }
   15723       656662 :             | AexprConst                            { $$ = $1; }
   15724              :             | PARAM opt_indirection
   15725              :                 {
   15726        23653 :                     ParamRef   *p = makeNode(ParamRef);
   15727              : 
   15728        23653 :                     p->number = $1;
   15729        23653 :                     p->location = @1;
   15730        23653 :                     if ($2)
   15731              :                     {
   15732          548 :                         A_Indirection *n = makeNode(A_Indirection);
   15733              : 
   15734          548 :                         n->arg = (Node *) p;
   15735          548 :                         n->indirection = check_indirection($2, yyscanner);
   15736          548 :                         $$ = (Node *) n;
   15737              :                     }
   15738              :                     else
   15739        23105 :                         $$ = (Node *) p;
   15740              :                 }
   15741              :             | '(' a_expr ')' opt_indirection
   15742              :                 {
   15743        49434 :                     if ($4)
   15744              :                     {
   15745         7804 :                         A_Indirection *n = makeNode(A_Indirection);
   15746              : 
   15747         7804 :                         n->arg = $2;
   15748         7804 :                         n->indirection = check_indirection($4, yyscanner);
   15749         7804 :                         $$ = (Node *) n;
   15750              :                     }
   15751              :                     else
   15752        41630 :                         $$ = $2;
   15753              :                 }
   15754              :             | case_expr
   15755        21078 :                 { $$ = $1; }
   15756              :             | func_expr
   15757       207771 :                 { $$ = $1; }
   15758              :             | select_with_parens            %prec UMINUS
   15759              :                 {
   15760        14875 :                     SubLink    *n = makeNode(SubLink);
   15761              : 
   15762        14875 :                     n->subLinkType = EXPR_SUBLINK;
   15763        14875 :                     n->subLinkId = 0;
   15764        14875 :                     n->testexpr = NULL;
   15765        14875 :                     n->operName = NIL;
   15766        14875 :                     n->subselect = $1;
   15767        14875 :                     n->location = @1;
   15768        14875 :                     $$ = (Node *) n;
   15769              :                 }
   15770              :             | select_with_parens indirection
   15771              :                 {
   15772              :                     /*
   15773              :                      * Because the select_with_parens nonterminal is designed
   15774              :                      * to "eat" as many levels of parens as possible, the
   15775              :                      * '(' a_expr ')' opt_indirection production above will
   15776              :                      * fail to match a sub-SELECT with indirection decoration;
   15777              :                      * the sub-SELECT won't be regarded as an a_expr as long
   15778              :                      * as there are parens around it.  To support applying
   15779              :                      * subscripting or field selection to a sub-SELECT result,
   15780              :                      * we need this redundant-looking production.
   15781              :                      */
   15782            9 :                     SubLink    *n = makeNode(SubLink);
   15783            9 :                     A_Indirection *a = makeNode(A_Indirection);
   15784              : 
   15785            9 :                     n->subLinkType = EXPR_SUBLINK;
   15786            9 :                     n->subLinkId = 0;
   15787            9 :                     n->testexpr = NULL;
   15788            9 :                     n->operName = NIL;
   15789            9 :                     n->subselect = $1;
   15790            9 :                     n->location = @1;
   15791            9 :                     a->arg = (Node *) n;
   15792            9 :                     a->indirection = check_indirection($2, yyscanner);
   15793            9 :                     $$ = (Node *) a;
   15794              :                 }
   15795              :             | EXISTS select_with_parens
   15796              :                 {
   15797         3395 :                     SubLink    *n = makeNode(SubLink);
   15798              : 
   15799         3395 :                     n->subLinkType = EXISTS_SUBLINK;
   15800         3395 :                     n->subLinkId = 0;
   15801         3395 :                     n->testexpr = NULL;
   15802         3395 :                     n->operName = NIL;
   15803         3395 :                     n->subselect = $2;
   15804         3395 :                     n->location = @1;
   15805         3395 :                     $$ = (Node *) n;
   15806              :                 }
   15807              :             | ARRAY select_with_parens
   15808              :                 {
   15809         4615 :                     SubLink    *n = makeNode(SubLink);
   15810              : 
   15811         4615 :                     n->subLinkType = ARRAY_SUBLINK;
   15812         4615 :                     n->subLinkId = 0;
   15813         4615 :                     n->testexpr = NULL;
   15814         4615 :                     n->operName = NIL;
   15815         4615 :                     n->subselect = $2;
   15816         4615 :                     n->location = @1;
   15817         4615 :                     $$ = (Node *) n;
   15818              :                 }
   15819              :             | ARRAY array_expr
   15820              :                 {
   15821         3843 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15822              : 
   15823              :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15824         3843 :                     n->location = @1;
   15825         3843 :                     $$ = (Node *) n;
   15826              :                 }
   15827              :             | explicit_row
   15828              :                 {
   15829         1943 :                     RowExpr    *r = makeNode(RowExpr);
   15830              : 
   15831         1943 :                     r->args = $1;
   15832         1943 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15833         1943 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15834         1943 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15835         1943 :                     r->location = @1;
   15836         1943 :                     $$ = (Node *) r;
   15837              :                 }
   15838              :             | implicit_row
   15839              :                 {
   15840         1376 :                     RowExpr    *r = makeNode(RowExpr);
   15841              : 
   15842         1376 :                     r->args = $1;
   15843         1376 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15844         1376 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15845         1376 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15846         1376 :                     r->location = @1;
   15847         1376 :                     $$ = (Node *) r;
   15848              :                 }
   15849              :             | GROUPING '(' expr_list ')'
   15850              :               {
   15851          185 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15852              : 
   15853          185 :                   g->args = $3;
   15854          185 :                   g->location = @1;
   15855          185 :                   $$ = (Node *) g;
   15856              :               }
   15857              :         ;
   15858              : 
   15859              : func_application: func_name '(' ')'
   15860              :                 {
   15861        17168 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15862              :                                                COERCE_EXPLICIT_CALL,
   15863        17168 :                                                @1);
   15864              :                 }
   15865              :             | func_name '(' func_arg_list opt_sort_clause ')'
   15866              :                 {
   15867       167175 :                     FuncCall   *n = makeFuncCall($1, $3,
   15868              :                                                  COERCE_EXPLICIT_CALL,
   15869       167175 :                                                  @1);
   15870              : 
   15871       167175 :                     n->agg_order = $4;
   15872       167175 :                     $$ = (Node *) n;
   15873              :                 }
   15874              :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15875              :                 {
   15876          317 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15877              :                                                  COERCE_EXPLICIT_CALL,
   15878          317 :                                                  @1);
   15879              : 
   15880          317 :                     n->func_variadic = true;
   15881          317 :                     n->agg_order = $5;
   15882          317 :                     $$ = (Node *) n;
   15883              :                 }
   15884              :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15885              :                 {
   15886           84 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15887              :                                                  COERCE_EXPLICIT_CALL,
   15888           84 :                                                  @1);
   15889              : 
   15890           84 :                     n->func_variadic = true;
   15891           84 :                     n->agg_order = $7;
   15892           84 :                     $$ = (Node *) n;
   15893              :                 }
   15894              :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15895              :                 {
   15896            0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15897              :                                                  COERCE_EXPLICIT_CALL,
   15898            0 :                                                  @1);
   15899              : 
   15900            0 :                     n->agg_order = $5;
   15901              :                     /* Ideally we'd mark the FuncCall node to indicate
   15902              :                      * "must be an aggregate", but there's no provision
   15903              :                      * for that in FuncCall at the moment.
   15904              :                      */
   15905            0 :                     $$ = (Node *) n;
   15906              :                 }
   15907              :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15908              :                 {
   15909          278 :                     FuncCall   *n = makeFuncCall($1, $4,
   15910              :                                                  COERCE_EXPLICIT_CALL,
   15911          278 :                                                  @1);
   15912              : 
   15913          278 :                     n->agg_order = $5;
   15914          278 :                     n->agg_distinct = true;
   15915          278 :                     $$ = (Node *) n;
   15916              :                 }
   15917              :             | func_name '(' '*' ')'
   15918              :                 {
   15919              :                     /*
   15920              :                      * We consider AGGREGATE(*) to invoke a parameterless
   15921              :                      * aggregate.  This does the right thing for COUNT(*),
   15922              :                      * and there are no other aggregates in SQL that accept
   15923              :                      * '*' as parameter.
   15924              :                      *
   15925              :                      * The FuncCall node is also marked agg_star = true,
   15926              :                      * so that later processing can detect what the argument
   15927              :                      * really was.
   15928              :                      */
   15929         9571 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15930              :                                                  COERCE_EXPLICIT_CALL,
   15931         9571 :                                                  @1);
   15932              : 
   15933         9571 :                     n->agg_star = true;
   15934         9571 :                     $$ = (Node *) n;
   15935              :                 }
   15936              :         ;
   15937              : 
   15938              : 
   15939              : /*
   15940              :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15941              :  * so that we have classifications for "everything that is a function call or
   15942              :  * looks like one".  This isn't very important, but it saves us having to
   15943              :  * document which variants are legal in places like "FROM function()" or the
   15944              :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15945              :  * (Note that many of the special SQL functions wouldn't actually make any
   15946              :  * sense as functional index entries, but we ignore that consideration here.)
   15947              :  */
   15948              : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
   15949              :                 {
   15950       168590 :                     FuncCall   *n = (FuncCall *) $1;
   15951              : 
   15952              :                     /*
   15953              :                      * The order clause for WITHIN GROUP and the one for
   15954              :                      * plain-aggregate ORDER BY share a field, so we have to
   15955              :                      * check here that at most one is present.  We also check
   15956              :                      * for DISTINCT and VARIADIC here to give a better error
   15957              :                      * location.  Other consistency checks are deferred to
   15958              :                      * parse analysis.
   15959              :                      */
   15960       168590 :                     if ($2 != NIL)
   15961              :                     {
   15962          174 :                         if (n->agg_order != NIL)
   15963            3 :                             ereport(ERROR,
   15964              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15965              :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15966              :                                      parser_errposition(@2)));
   15967          171 :                         if (n->agg_distinct)
   15968            0 :                             ereport(ERROR,
   15969              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15970              :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15971              :                                      parser_errposition(@2)));
   15972          171 :                         if (n->func_variadic)
   15973            0 :                             ereport(ERROR,
   15974              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15975              :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15976              :                                      parser_errposition(@2)));
   15977          171 :                         n->agg_order = $2;
   15978          171 :                         n->agg_within_group = true;
   15979              :                     }
   15980       168587 :                     n->agg_filter = $3;
   15981       168587 :                     n->ignore_nulls = $4;
   15982       168587 :                     n->over = $5;
   15983       168587 :                     $$ = (Node *) n;
   15984              :                 }
   15985              :             | json_aggregate_func filter_clause over_clause
   15986              :                 {
   15987          360 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15988          180 :                         ((JsonObjectAgg *) $1)->constructor :
   15989           78 :                         ((JsonArrayAgg *) $1)->constructor;
   15990              : 
   15991          180 :                     n->agg_filter = $2;
   15992          180 :                     n->over = $3;
   15993          180 :                     $$ = (Node *) $1;
   15994              :                 }
   15995              :             | func_expr_common_subexpr
   15996        39004 :                 { $$ = $1; }
   15997              :         ;
   15998              : 
   15999              : /*
   16000              :  * Like func_expr but does not accept WINDOW functions directly
   16001              :  * (but they can still be contained in arguments for functions etc).
   16002              :  * Use this when window expressions are not allowed, where needed to
   16003              :  * disambiguate the grammar (e.g. in CREATE INDEX).
   16004              :  */
   16005              : func_expr_windowless:
   16006        25686 :             func_application                        { $$ = $1; }
   16007          201 :             | func_expr_common_subexpr              { $$ = $1; }
   16008            0 :             | json_aggregate_func                   { $$ = $1; }
   16009              :         ;
   16010              : 
   16011              : /*
   16012              :  * Special expressions that are considered to be functions.
   16013              :  */
   16014              : func_expr_common_subexpr:
   16015              :             COLLATION FOR '(' a_expr ')'
   16016              :                 {
   16017           15 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   16018           15 :                                                list_make1($4),
   16019              :                                                COERCE_SQL_SYNTAX,
   16020           15 :                                                @1);
   16021              :                 }
   16022              :             | CURRENT_DATE
   16023              :                 {
   16024          156 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   16025              :                 }
   16026              :             | CURRENT_TIME
   16027              :                 {
   16028           12 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   16029              :                 }
   16030              :             | CURRENT_TIME '(' Iconst ')'
   16031              :                 {
   16032           12 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   16033              :                 }
   16034              :             | CURRENT_TIMESTAMP
   16035              :                 {
   16036          143 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   16037              :                 }
   16038              :             | CURRENT_TIMESTAMP '(' Iconst ')'
   16039              :                 {
   16040           88 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   16041              :                 }
   16042              :             | LOCALTIME
   16043              :                 {
   16044           12 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   16045              :                 }
   16046              :             | LOCALTIME '(' Iconst ')'
   16047              :                 {
   16048           12 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   16049              :                 }
   16050              :             | LOCALTIMESTAMP
   16051              :                 {
   16052           18 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   16053              :                 }
   16054              :             | LOCALTIMESTAMP '(' Iconst ')'
   16055              :                 {
   16056           12 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   16057              :                 }
   16058              :             | CURRENT_ROLE
   16059              :                 {
   16060           34 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   16061              :                 }
   16062              :             | CURRENT_USER
   16063              :                 {
   16064          556 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   16065              :                 }
   16066              :             | SESSION_USER
   16067              :                 {
   16068          296 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   16069              :                 }
   16070              :             | SYSTEM_USER
   16071              :                 {
   16072           10 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   16073              :                                                NIL,
   16074              :                                                COERCE_SQL_SYNTAX,
   16075              :                                                @1);
   16076              :                 }
   16077              :             | USER
   16078              :                 {
   16079           12 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   16080              :                 }
   16081              :             | CURRENT_CATALOG
   16082              :                 {
   16083           30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   16084              :                 }
   16085              :             | CURRENT_SCHEMA
   16086              :                 {
   16087           15 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   16088              :                 }
   16089              :             | CAST '(' a_expr AS Typename ')'
   16090        31879 :                 { $$ = makeTypeCast($3, $5, @1); }
   16091              :             | EXTRACT '(' extract_list ')'
   16092              :                 {
   16093          695 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   16094          695 :                                                $3,
   16095              :                                                COERCE_SQL_SYNTAX,
   16096          695 :                                                @1);
   16097              :                 }
   16098              :             | NORMALIZE '(' a_expr ')'
   16099              :                 {
   16100            9 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   16101            9 :                                                list_make1($3),
   16102              :                                                COERCE_SQL_SYNTAX,
   16103            9 :                                                @1);
   16104              :                 }
   16105              :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   16106              :                 {
   16107           21 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   16108           21 :                                                list_make2($3, makeStringConst($5, @5)),
   16109              :                                                COERCE_SQL_SYNTAX,
   16110           21 :                                                @1);
   16111              :                 }
   16112              :             | OVERLAY '(' overlay_list ')'
   16113              :                 {
   16114           41 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   16115           41 :                                                $3,
   16116              :                                                COERCE_SQL_SYNTAX,
   16117           41 :                                                @1);
   16118              :                 }
   16119              :             | OVERLAY '(' func_arg_list_opt ')'
   16120              :                 {
   16121              :                     /*
   16122              :                      * allow functions named overlay() to be called without
   16123              :                      * special syntax
   16124              :                      */
   16125            0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   16126            0 :                                                $3,
   16127              :                                                COERCE_EXPLICIT_CALL,
   16128            0 :                                                @1);
   16129              :                 }
   16130              :             | POSITION '(' position_list ')'
   16131              :                 {
   16132              :                     /*
   16133              :                      * position(A in B) is converted to position(B, A)
   16134              :                      *
   16135              :                      * We deliberately don't offer a "plain syntax" option
   16136              :                      * for position(), because the reversal of the arguments
   16137              :                      * creates too much risk of confusion.
   16138              :                      */
   16139          204 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   16140          204 :                                                $3,
   16141              :                                                COERCE_SQL_SYNTAX,
   16142          204 :                                                @1);
   16143              :                 }
   16144              :             | SUBSTRING '(' substr_list ')'
   16145              :                 {
   16146              :                     /* substring(A from B for C) is converted to
   16147              :                      * substring(A, B, C) - thomas 2000-11-28
   16148              :                      */
   16149          377 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   16150          377 :                                                $3,
   16151              :                                                COERCE_SQL_SYNTAX,
   16152          377 :                                                @1);
   16153              :                 }
   16154              :             | SUBSTRING '(' func_arg_list_opt ')'
   16155              :                 {
   16156              :                     /*
   16157              :                      * allow functions named substring() to be called without
   16158              :                      * special syntax
   16159              :                      */
   16160          163 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   16161          163 :                                                $3,
   16162              :                                                COERCE_EXPLICIT_CALL,
   16163          163 :                                                @1);
   16164              :                 }
   16165              :             | TREAT '(' a_expr AS Typename ')'
   16166              :                 {
   16167              :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   16168              :                      * which is defined to be a subtype of the original expression.
   16169              :                      * In SQL99, this is intended for use with structured UDTs,
   16170              :                      * but let's make this a generally useful form allowing stronger
   16171              :                      * coercions than are handled by implicit casting.
   16172              :                      *
   16173              :                      * Convert SystemTypeName() to SystemFuncName() even though
   16174              :                      * at the moment they result in the same thing.
   16175              :                      */
   16176            0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   16177            0 :                                                list_make1($3),
   16178              :                                                COERCE_EXPLICIT_CALL,
   16179            0 :                                                @1);
   16180              :                 }
   16181              :             | TRIM '(' BOTH trim_list ')'
   16182              :                 {
   16183              :                     /* various trim expressions are defined in SQL
   16184              :                      * - thomas 1997-07-19
   16185              :                      */
   16186            6 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16187            6 :                                                $4,
   16188              :                                                COERCE_SQL_SYNTAX,
   16189            6 :                                                @1);
   16190              :                 }
   16191              :             | TRIM '(' LEADING trim_list ')'
   16192              :                 {
   16193           12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   16194           12 :                                                $4,
   16195              :                                                COERCE_SQL_SYNTAX,
   16196           12 :                                                @1);
   16197              :                 }
   16198              :             | TRIM '(' TRAILING trim_list ')'
   16199              :                 {
   16200          292 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16201          292 :                                                $4,
   16202              :                                                COERCE_SQL_SYNTAX,
   16203          292 :                                                @1);
   16204              :                 }
   16205              :             | TRIM '(' trim_list ')'
   16206              :                 {
   16207           49 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16208           49 :                                                $3,
   16209              :                                                COERCE_SQL_SYNTAX,
   16210           49 :                                                @1);
   16211              :                 }
   16212              :             | NULLIF '(' a_expr ',' a_expr ')'
   16213              :                 {
   16214          194 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16215              :                 }
   16216              :             | COALESCE '(' expr_list ')'
   16217              :                 {
   16218         1669 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16219              : 
   16220         1669 :                     c->args = $3;
   16221         1669 :                     c->location = @1;
   16222         1669 :                     $$ = (Node *) c;
   16223              :                 }
   16224              :             | GREATEST '(' expr_list ')'
   16225              :                 {
   16226           79 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16227              : 
   16228           79 :                     v->args = $3;
   16229           79 :                     v->op = IS_GREATEST;
   16230           79 :                     v->location = @1;
   16231           79 :                     $$ = (Node *) v;
   16232              :                 }
   16233              :             | LEAST '(' expr_list ')'
   16234              :                 {
   16235           74 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16236              : 
   16237           74 :                     v->args = $3;
   16238           74 :                     v->op = IS_LEAST;
   16239           74 :                     v->location = @1;
   16240           74 :                     $$ = (Node *) v;
   16241              :                 }
   16242              :             | XMLCONCAT '(' expr_list ')'
   16243              :                 {
   16244           31 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16245              :                 }
   16246              :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16247              :                 {
   16248            3 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16249              :                 }
   16250              :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16251              :                 {
   16252           18 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16253              :                 }
   16254              :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16255              :                 {
   16256           58 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16257              :                 }
   16258              :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16259              :                 {
   16260           10 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16261              :                 }
   16262              :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16263              :                 {
   16264              :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16265              :                      * converted to xmlexists(A, B)*/
   16266           27 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16267           27 :                                                list_make2($3, $4),
   16268              :                                                COERCE_SQL_SYNTAX,
   16269           27 :                                                @1);
   16270              :                 }
   16271              :             | XMLFOREST '(' xml_attribute_list ')'
   16272              :                 {
   16273           16 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16274              :                 }
   16275              :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16276              :                 {
   16277              :                     XmlExpr *x = (XmlExpr *)
   16278           70 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16279           70 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16280           70 :                                     @1);
   16281              : 
   16282           70 :                     x->xmloption = $3;
   16283           70 :                     $$ = (Node *) x;
   16284              :                 }
   16285              :             | XMLPI '(' NAME_P ColLabel ')'
   16286              :                 {
   16287           15 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16288              :                 }
   16289              :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16290              :                 {
   16291           25 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16292              :                 }
   16293              :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16294              :                 {
   16295           34 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16296           34 :                                      list_make3($3, $5, $6), @1);
   16297              :                 }
   16298              :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16299              :                 {
   16300          109 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16301              : 
   16302          109 :                     n->xmloption = $3;
   16303          109 :                     n->expr = $4;
   16304          109 :                     n->typeName = $6;
   16305          109 :                     n->indent = $7;
   16306          109 :                     n->location = @1;
   16307          109 :                     $$ = (Node *) n;
   16308              :                 }
   16309              :             | JSON_OBJECT '(' func_arg_list ')'
   16310              :                 {
   16311              :                     /* Support for legacy (non-standard) json_object() */
   16312           45 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16313           45 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16314              :                 }
   16315              :             | JSON_OBJECT '(' json_name_and_value_list
   16316              :                 json_object_constructor_null_clause_opt
   16317              :                 json_key_uniqueness_constraint_opt
   16318              :                 json_returning_clause_opt ')'
   16319              :                 {
   16320          174 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16321              : 
   16322          174 :                     n->exprs = $3;
   16323          174 :                     n->absent_on_null = $4;
   16324          174 :                     n->unique = $5;
   16325          174 :                     n->output = (JsonOutput *) $6;
   16326          174 :                     n->location = @1;
   16327          174 :                     $$ = (Node *) n;
   16328              :                 }
   16329              :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16330              :                 {
   16331           46 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16332              : 
   16333           46 :                     n->exprs = NULL;
   16334           46 :                     n->absent_on_null = false;
   16335           46 :                     n->unique = false;
   16336           46 :                     n->output = (JsonOutput *) $3;
   16337           46 :                     n->location = @1;
   16338           46 :                     $$ = (Node *) n;
   16339              :                 }
   16340              :             | JSON_ARRAY '('
   16341              :                 json_value_expr_list
   16342              :                 json_array_constructor_null_clause_opt
   16343              :                 json_returning_clause_opt
   16344              :             ')'
   16345              :                 {
   16346           60 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16347              : 
   16348           60 :                     n->exprs = $3;
   16349           60 :                     n->absent_on_null = $4;
   16350           60 :                     n->output = (JsonOutput *) $5;
   16351           60 :                     n->location = @1;
   16352           60 :                     $$ = (Node *) n;
   16353              :                 }
   16354              :             | JSON_ARRAY '('
   16355              :                 select_no_parens
   16356              :                 json_format_clause_opt
   16357              :                 /* json_array_constructor_null_clause_opt */
   16358              :                 json_returning_clause_opt
   16359              :             ')'
   16360              :                 {
   16361           30 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16362              : 
   16363           30 :                     n->query = $3;
   16364           30 :                     n->format = (JsonFormat *) $4;
   16365           30 :                     n->absent_on_null = true;    /* XXX */
   16366           30 :                     n->output = (JsonOutput *) $5;
   16367           30 :                     n->location = @1;
   16368           30 :                     $$ = (Node *) n;
   16369              :                 }
   16370              :             | JSON_ARRAY '('
   16371              :                 json_returning_clause_opt
   16372              :             ')'
   16373              :                 {
   16374           43 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16375              : 
   16376           43 :                     n->exprs = NIL;
   16377           43 :                     n->absent_on_null = true;
   16378           43 :                     n->output = (JsonOutput *) $3;
   16379           43 :                     n->location = @1;
   16380           43 :                     $$ = (Node *) n;
   16381              :                 }
   16382              :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16383              :                 {
   16384           82 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16385              : 
   16386           82 :                     n->expr = (JsonValueExpr *) $3;
   16387           82 :                     n->unique_keys = $4;
   16388           82 :                     n->output = NULL;
   16389           82 :                     n->location = @1;
   16390           82 :                     $$ = (Node *) n;
   16391              :                 }
   16392              :             | JSON_SCALAR '(' a_expr ')'
   16393              :                 {
   16394           56 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16395              : 
   16396           56 :                     n->expr = (Expr *) $3;
   16397           56 :                     n->output = NULL;
   16398           56 :                     n->location = @1;
   16399           56 :                     $$ = (Node *) n;
   16400              :                 }
   16401              :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16402              :                 {
   16403           54 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16404              : 
   16405           54 :                     n->expr = (JsonValueExpr *) $3;
   16406           54 :                     n->output = (JsonOutput *) $4;
   16407           54 :                     n->location = @1;
   16408           54 :                     $$ = (Node *) n;
   16409              :                 }
   16410              :             | MERGE_ACTION '(' ')'
   16411              :                 {
   16412          108 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16413              : 
   16414          108 :                     m->msftype = TEXTOID;
   16415          108 :                     m->location = @1;
   16416          108 :                     $$ = (Node *) m;
   16417              :                 }
   16418              :             | JSON_QUERY '('
   16419              :                 json_value_expr ',' a_expr json_passing_clause_opt
   16420              :                 json_returning_clause_opt
   16421              :                 json_wrapper_behavior
   16422              :                 json_quotes_clause_opt
   16423              :                 json_behavior_clause_opt
   16424              :             ')'
   16425              :                 {
   16426          495 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16427              : 
   16428          495 :                     n->op = JSON_QUERY_OP;
   16429          495 :                     n->context_item = (JsonValueExpr *) $3;
   16430          495 :                     n->pathspec = $5;
   16431          495 :                     n->passing = $6;
   16432          495 :                     n->output = (JsonOutput *) $7;
   16433          495 :                     n->wrapper = $8;
   16434          495 :                     n->quotes = $9;
   16435          495 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16436          495 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16437          495 :                     n->location = @1;
   16438          495 :                     $$ = (Node *) n;
   16439              :                 }
   16440              :             | JSON_EXISTS '('
   16441              :                 json_value_expr ',' a_expr json_passing_clause_opt
   16442              :                 json_on_error_clause_opt
   16443              :             ')'
   16444              :                 {
   16445           84 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16446              : 
   16447           84 :                     n->op = JSON_EXISTS_OP;
   16448           84 :                     n->context_item = (JsonValueExpr *) $3;
   16449           84 :                     n->pathspec = $5;
   16450           84 :                     n->passing = $6;
   16451           84 :                     n->output = NULL;
   16452           84 :                     n->on_error = (JsonBehavior *) $7;
   16453           84 :                     n->location = @1;
   16454           84 :                     $$ = (Node *) n;
   16455              :                 }
   16456              :             | JSON_VALUE '('
   16457              :                 json_value_expr ',' a_expr json_passing_clause_opt
   16458              :                 json_returning_clause_opt
   16459              :                 json_behavior_clause_opt
   16460              :             ')'
   16461              :                 {
   16462          315 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16463              : 
   16464          315 :                     n->op = JSON_VALUE_OP;
   16465          315 :                     n->context_item = (JsonValueExpr *) $3;
   16466          315 :                     n->pathspec = $5;
   16467          315 :                     n->passing = $6;
   16468          315 :                     n->output = (JsonOutput *) $7;
   16469          315 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16470          315 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16471          315 :                     n->location = @1;
   16472          315 :                     $$ = (Node *) n;
   16473              :                 }
   16474              :             ;
   16475              : 
   16476              : 
   16477              : /*
   16478              :  * SQL/XML support
   16479              :  */
   16480              : xml_root_version: VERSION_P a_expr
   16481           12 :                 { $$ = $2; }
   16482              :             | VERSION_P NO VALUE_P
   16483           22 :                 { $$ = makeNullAConst(-1); }
   16484              :         ;
   16485              : 
   16486              : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16487           13 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16488              :             | ',' STANDALONE_P NO
   16489            6 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16490              :             | ',' STANDALONE_P NO VALUE_P
   16491            6 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16492              :             | /*EMPTY*/
   16493            9 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16494              :         ;
   16495              : 
   16496           28 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16497              :         ;
   16498              : 
   16499           44 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16500           72 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16501              :         ;
   16502              : 
   16503              : xml_attribute_el: a_expr AS ColLabel
   16504              :                 {
   16505           53 :                     $$ = makeNode(ResTarget);
   16506           53 :                     $$->name = $3;
   16507           53 :                     $$->indirection = NIL;
   16508           53 :                     $$->val = (Node *) $1;
   16509           53 :                     $$->location = @1;
   16510              :                 }
   16511              :             | a_expr
   16512              :                 {
   16513           63 :                     $$ = makeNode(ResTarget);
   16514           63 :                     $$->name = NULL;
   16515           63 :                     $$->indirection = NIL;
   16516           63 :                     $$->val = (Node *) $1;
   16517           63 :                     $$->location = @1;
   16518              :                 }
   16519              :         ;
   16520              : 
   16521           93 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16522           94 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16523              :         ;
   16524              : 
   16525           70 : xml_indent_option: INDENT                           { $$ = true; }
   16526           18 :             | NO INDENT                             { $$ = false; }
   16527           21 :             | /*EMPTY*/                             { $$ = false; }
   16528              :         ;
   16529              : 
   16530            0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16531            1 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16532           69 :             | /*EMPTY*/                             { $$ = false; }
   16533              :         ;
   16534              : 
   16535              : /* We allow several variants for SQL and other compatibility. */
   16536              : xmlexists_argument:
   16537              :             PASSING c_expr
   16538              :                 {
   16539          119 :                     $$ = $2;
   16540              :                 }
   16541              :             | PASSING c_expr xml_passing_mech
   16542              :                 {
   16543            0 :                     $$ = $2;
   16544              :                 }
   16545              :             | PASSING xml_passing_mech c_expr
   16546              :                 {
   16547           21 :                     $$ = $3;
   16548              :                 }
   16549              :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16550              :                 {
   16551            3 :                     $$ = $3;
   16552              :                 }
   16553              :         ;
   16554              : 
   16555              : xml_passing_mech:
   16556              :             BY REF_P
   16557              :             | BY VALUE_P
   16558              :         ;
   16559              : 
   16560              : /*****************************************************************************
   16561              :  *
   16562              :  * WAIT FOR LSN
   16563              :  *
   16564              :  *****************************************************************************/
   16565              : 
   16566              : WaitStmt:
   16567              :             WAIT FOR LSN_P Sconst opt_wait_with_clause
   16568              :                 {
   16569           56 :                     WaitStmt *n = makeNode(WaitStmt);
   16570           56 :                     n->lsn_literal = $4;
   16571           56 :                     n->options = $5;
   16572           56 :                     $$ = (Node *) n;
   16573              :                 }
   16574              :             ;
   16575              : 
   16576              : opt_wait_with_clause:
   16577           45 :             WITH '(' utility_option_list ')'        { $$ = $3; }
   16578           11 :             | /*EMPTY*/                             { $$ = NIL; }
   16579              :             ;
   16580              : 
   16581              : /*
   16582              :  * Aggregate decoration clauses
   16583              :  */
   16584              : within_group_clause:
   16585          174 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16586       168419 :             | /*EMPTY*/                             { $$ = NIL; }
   16587              :         ;
   16588              : 
   16589              : filter_clause:
   16590          431 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16591       168342 :             | /*EMPTY*/                             { $$ = NULL; }
   16592              :         ;
   16593              : 
   16594              : 
   16595              : /*
   16596              :  * Window Definitions
   16597              :  */
   16598              : null_treatment:
   16599           99 :             IGNORE_P NULLS_P                        { $$ = PARSER_IGNORE_NULLS; }
   16600           48 :             | RESPECT_P NULLS_P                     { $$ = PARSER_RESPECT_NULLS; }
   16601       168446 :             | /*EMPTY*/                             { $$ = NO_NULLTREATMENT; }
   16602              :         ;
   16603              : 
   16604              : window_clause:
   16605          303 :             WINDOW window_definition_list           { $$ = $2; }
   16606       254157 :             | /*EMPTY*/                             { $$ = NIL; }
   16607              :         ;
   16608              : 
   16609              : window_definition_list:
   16610          303 :             window_definition                       { $$ = list_make1($1); }
   16611              :             | window_definition_list ',' window_definition
   16612           15 :                                                     { $$ = lappend($1, $3); }
   16613              :         ;
   16614              : 
   16615              : window_definition:
   16616              :             ColId AS window_specification
   16617              :                 {
   16618          318 :                     WindowDef  *n = $3;
   16619              : 
   16620          318 :                     n->name = $1;
   16621          318 :                     $$ = n;
   16622              :                 }
   16623              :         ;
   16624              : 
   16625              : over_clause: OVER window_specification
   16626         1434 :                 { $$ = $2; }
   16627              :             | OVER ColId
   16628              :                 {
   16629          591 :                     WindowDef  *n = makeNode(WindowDef);
   16630              : 
   16631          591 :                     n->name = $2;
   16632          591 :                     n->refname = NULL;
   16633          591 :                     n->partitionClause = NIL;
   16634          591 :                     n->orderClause = NIL;
   16635          591 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16636          591 :                     n->startOffset = NULL;
   16637          591 :                     n->endOffset = NULL;
   16638          591 :                     n->location = @2;
   16639          591 :                     $$ = n;
   16640              :                 }
   16641              :             | /*EMPTY*/
   16642       166745 :                 { $$ = NULL; }
   16643              :         ;
   16644              : 
   16645              : window_specification: '(' opt_existing_window_name opt_partition_clause
   16646              :                         opt_sort_clause opt_frame_clause ')'
   16647              :                 {
   16648         1752 :                     WindowDef  *n = makeNode(WindowDef);
   16649              : 
   16650         1752 :                     n->name = NULL;
   16651         1752 :                     n->refname = $2;
   16652         1752 :                     n->partitionClause = $3;
   16653         1752 :                     n->orderClause = $4;
   16654              :                     /* copy relevant fields of opt_frame_clause */
   16655         1752 :                     n->frameOptions = $5->frameOptions;
   16656         1752 :                     n->startOffset = $5->startOffset;
   16657         1752 :                     n->endOffset = $5->endOffset;
   16658         1752 :                     n->location = @1;
   16659         1752 :                     $$ = n;
   16660              :                 }
   16661              :         ;
   16662              : 
   16663              : /*
   16664              :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16665              :  * of a window_specification, we want the assumption to be that there is
   16666              :  * no existing_window_name; but those keywords are unreserved and so could
   16667              :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16668              :  * and giving the empty production here a slightly higher precedence, so
   16669              :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16670              :  * These keywords are thus precluded from being an existing_window_name but
   16671              :  * are not reserved for any other purpose.
   16672              :  */
   16673           27 : opt_existing_window_name: ColId                     { $$ = $1; }
   16674         1728 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16675              :         ;
   16676              : 
   16677          467 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16678         1285 :             | /*EMPTY*/                             { $$ = NIL; }
   16679              :         ;
   16680              : 
   16681              : /*
   16682              :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16683              :  * frameOptions, startOffset, and endOffset.
   16684              :  */
   16685              : opt_frame_clause:
   16686              :             RANGE frame_extent opt_window_exclusion_clause
   16687              :                 {
   16688          398 :                     WindowDef  *n = $2;
   16689              : 
   16690          398 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16691          398 :                     n->frameOptions |= $3;
   16692          398 :                     $$ = n;
   16693              :                 }
   16694              :             | ROWS frame_extent opt_window_exclusion_clause
   16695              :                 {
   16696          345 :                     WindowDef  *n = $2;
   16697              : 
   16698          345 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16699          345 :                     n->frameOptions |= $3;
   16700          345 :                     $$ = n;
   16701              :                 }
   16702              :             | GROUPS frame_extent opt_window_exclusion_clause
   16703              :                 {
   16704          102 :                     WindowDef  *n = $2;
   16705              : 
   16706          102 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16707          102 :                     n->frameOptions |= $3;
   16708          102 :                     $$ = n;
   16709              :                 }
   16710              :             | /*EMPTY*/
   16711              :                 {
   16712          907 :                     WindowDef  *n = makeNode(WindowDef);
   16713              : 
   16714          907 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16715          907 :                     n->startOffset = NULL;
   16716          907 :                     n->endOffset = NULL;
   16717          907 :                     $$ = n;
   16718              :                 }
   16719              :         ;
   16720              : 
   16721              : frame_extent: frame_bound
   16722              :                 {
   16723            6 :                     WindowDef  *n = $1;
   16724              : 
   16725              :                     /* reject invalid cases */
   16726            6 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16727            0 :                         ereport(ERROR,
   16728              :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16729              :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16730              :                                  parser_errposition(@1)));
   16731            6 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16732            0 :                         ereport(ERROR,
   16733              :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16734              :                                  errmsg("frame starting from following row cannot end with current row"),
   16735              :                                  parser_errposition(@1)));
   16736            6 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16737            6 :                     $$ = n;
   16738              :                 }
   16739              :             | BETWEEN frame_bound AND frame_bound
   16740              :                 {
   16741          839 :                     WindowDef  *n1 = $2;
   16742          839 :                     WindowDef  *n2 = $4;
   16743              : 
   16744              :                     /* form merged options */
   16745          839 :                     int     frameOptions = n1->frameOptions;
   16746              :                     /* shift converts START_ options to END_ options */
   16747          839 :                     frameOptions |= n2->frameOptions << 1;
   16748          839 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16749              :                     /* reject invalid cases */
   16750          839 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16751            0 :                         ereport(ERROR,
   16752              :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16753              :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16754              :                                  parser_errposition(@2)));
   16755          839 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16756            0 :                         ereport(ERROR,
   16757              :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16758              :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16759              :                                  parser_errposition(@4)));
   16760          839 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16761          230 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16762            0 :                         ereport(ERROR,
   16763              :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16764              :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16765              :                                  parser_errposition(@4)));
   16766          839 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16767           84 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16768              :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16769            0 :                         ereport(ERROR,
   16770              :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16771              :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16772              :                                  parser_errposition(@4)));
   16773          839 :                     n1->frameOptions = frameOptions;
   16774          839 :                     n1->endOffset = n2->startOffset;
   16775          839 :                     $$ = n1;
   16776              :                 }
   16777              :         ;
   16778              : 
   16779              : /*
   16780              :  * This is used for both frame start and frame end, with output set up on
   16781              :  * the assumption it's frame start; the frame_extent productions must reject
   16782              :  * invalid cases.
   16783              :  */
   16784              : frame_bound:
   16785              :             UNBOUNDED PRECEDING
   16786              :                 {
   16787          108 :                     WindowDef  *n = makeNode(WindowDef);
   16788              : 
   16789          108 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16790          108 :                     n->startOffset = NULL;
   16791          108 :                     n->endOffset = NULL;
   16792          108 :                     $$ = n;
   16793              :                 }
   16794              :             | UNBOUNDED FOLLOWING
   16795              :                 {
   16796          197 :                     WindowDef  *n = makeNode(WindowDef);
   16797              : 
   16798          197 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16799          197 :                     n->startOffset = NULL;
   16800          197 :                     n->endOffset = NULL;
   16801          197 :                     $$ = n;
   16802              :                 }
   16803              :             | CURRENT_P ROW
   16804              :                 {
   16805          302 :                     WindowDef  *n = makeNode(WindowDef);
   16806              : 
   16807          302 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16808          302 :                     n->startOffset = NULL;
   16809          302 :                     n->endOffset = NULL;
   16810          302 :                     $$ = n;
   16811              :                 }
   16812              :             | a_expr PRECEDING
   16813              :                 {
   16814          477 :                     WindowDef  *n = makeNode(WindowDef);
   16815              : 
   16816          477 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16817          477 :                     n->startOffset = $1;
   16818          477 :                     n->endOffset = NULL;
   16819          477 :                     $$ = n;
   16820              :                 }
   16821              :             | a_expr FOLLOWING
   16822              :                 {
   16823          600 :                     WindowDef  *n = makeNode(WindowDef);
   16824              : 
   16825          600 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16826          600 :                     n->startOffset = $1;
   16827          600 :                     n->endOffset = NULL;
   16828          600 :                     $$ = n;
   16829              :                 }
   16830              :         ;
   16831              : 
   16832              : opt_window_exclusion_clause:
   16833           48 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16834           48 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16835           75 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16836            9 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16837          665 :             | /*EMPTY*/             { $$ = 0; }
   16838              :         ;
   16839              : 
   16840              : 
   16841              : /*
   16842              :  * Supporting nonterminals for expressions.
   16843              :  */
   16844              : 
   16845              : /* Explicit row production.
   16846              :  *
   16847              :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16848              :  * without conflicting with the parenthesized a_expr production.  Without the
   16849              :  * ROW keyword, there must be more than one a_expr inside the parens.
   16850              :  */
   16851            0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16852            0 :             | ROW '(' ')'                           { $$ = NIL; }
   16853          984 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16854              :         ;
   16855              : 
   16856         1925 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16857           18 :             | ROW '(' ')'                           { $$ = NIL; }
   16858              :         ;
   16859              : 
   16860         1376 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16861              :         ;
   16862              : 
   16863         8791 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16864            0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16865          162 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16866              :         ;
   16867              : 
   16868         5782 : all_Op:     Op                                      { $$ = $1; }
   16869        15214 :             | MathOp                                { $$ = $1; }
   16870              :         ;
   16871              : 
   16872           20 : MathOp:      '+'                                    { $$ = "+"; }
   16873           34 :             | '-'                                   { $$ = "-"; }
   16874           75 :             | '*'                                   { $$ = "*"; }
   16875            0 :             | '/'                                   { $$ = "/"; }
   16876            4 :             | '%'                                   { $$ = "%"; }
   16877            0 :             | '^'                                   { $$ = "^"; }
   16878          493 :             | '<'                                    { $$ = "<"; }
   16879          447 :             | '>'                                    { $$ = ">"; }
   16880        12888 :             | '='                                   { $$ = "="; }
   16881          426 :             | LESS_EQUALS                           { $$ = "<="; }
   16882          422 :             | GREATER_EQUALS                        { $$ = ">="; }
   16883          405 :             | NOT_EQUALS                            { $$ = "<>"; }
   16884              :         ;
   16885              : 
   16886              : qual_Op:    Op
   16887        22683 :                     { $$ = list_make1(makeString($1)); }
   16888              :             | OPERATOR '(' any_operator ')'
   16889         8115 :                     { $$ = $3; }
   16890              :         ;
   16891              : 
   16892              : qual_all_Op:
   16893              :             all_Op
   16894          720 :                     { $$ = list_make1(makeString($1)); }
   16895              :             | OPERATOR '(' any_operator ')'
   16896           17 :                     { $$ = $3; }
   16897              :         ;
   16898              : 
   16899              : subquery_Op:
   16900              :             all_Op
   16901         8793 :                     { $$ = list_make1(makeString($1)); }
   16902              :             | OPERATOR '(' any_operator ')'
   16903          144 :                     { $$ = $3; }
   16904              :             | LIKE
   16905           12 :                     { $$ = list_make1(makeString("~~")); }
   16906              :             | NOT_LA LIKE
   16907            6 :                     { $$ = list_make1(makeString("!~~")); }
   16908              :             | ILIKE
   16909            6 :                     { $$ = list_make1(makeString("~~*")); }
   16910              :             | NOT_LA ILIKE
   16911            0 :                     { $$ = list_make1(makeString("!~~*")); }
   16912              : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16913              :  * the regular expression is preprocessed by a function (similar_to_escape),
   16914              :  * and the ~ operator for posix regular expressions is used.
   16915              :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16916              :  * this transformation is made on the fly by the parser upwards.
   16917              :  * however the SubLink structure which handles any/some/all stuff
   16918              :  * is not ready for such a thing.
   16919              :  */
   16920              :             ;
   16921              : 
   16922              : expr_list:  a_expr
   16923              :                 {
   16924        86643 :                     $$ = list_make1($1);
   16925              :                 }
   16926              :             | expr_list ',' a_expr
   16927              :                 {
   16928        79238 :                     $$ = lappend($1, $3);
   16929              :                 }
   16930              :         ;
   16931              : 
   16932              : /* function arguments can have names */
   16933              : func_arg_list:  func_arg_expr
   16934              :                 {
   16935       167745 :                     $$ = list_make1($1);
   16936              :                 }
   16937              :             | func_arg_list ',' func_arg_expr
   16938              :                 {
   16939       148320 :                     $$ = lappend($1, $3);
   16940              :                 }
   16941              :         ;
   16942              : 
   16943              : func_arg_expr:  a_expr
   16944              :                 {
   16945       291728 :                     $$ = $1;
   16946              :                 }
   16947              :             | param_name COLON_EQUALS a_expr
   16948              :                 {
   16949        23679 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16950              : 
   16951        23679 :                     na->name = $1;
   16952        23679 :                     na->arg = (Expr *) $3;
   16953        23679 :                     na->argnumber = -1;      /* until determined */
   16954        23679 :                     na->location = @1;
   16955        23679 :                     $$ = (Node *) na;
   16956              :                 }
   16957              :             | param_name EQUALS_GREATER a_expr
   16958              :                 {
   16959         1059 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16960              : 
   16961         1059 :                     na->name = $1;
   16962         1059 :                     na->arg = (Expr *) $3;
   16963         1059 :                     na->argnumber = -1;      /* until determined */
   16964         1059 :                     na->location = @1;
   16965         1059 :                     $$ = (Node *) na;
   16966              :                 }
   16967              :         ;
   16968              : 
   16969          163 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16970            0 :             | /*EMPTY*/                             { $$ = NIL; }
   16971              :         ;
   16972              : 
   16973         1077 : type_list:  Typename                                { $$ = list_make1($1); }
   16974          326 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16975              :         ;
   16976              : 
   16977              : array_expr: '[' expr_list ']'
   16978              :                 {
   16979         3959 :                     $$ = makeAArrayExpr($2, @1, @3);
   16980              :                 }
   16981              :             | '[' array_expr_list ']'
   16982              :                 {
   16983          206 :                     $$ = makeAArrayExpr($2, @1, @3);
   16984              :                 }
   16985              :             | '[' ']'
   16986              :                 {
   16987           55 :                     $$ = makeAArrayExpr(NIL, @1, @2);
   16988              :                 }
   16989              :         ;
   16990              : 
   16991          206 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16992          171 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16993              :         ;
   16994              : 
   16995              : 
   16996              : extract_list:
   16997              :             extract_arg FROM a_expr
   16998              :                 {
   16999          695 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   17000              :                 }
   17001              :         ;
   17002              : 
   17003              : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   17004              :  * - thomas 2001-04-12
   17005              :  */
   17006              : extract_arg:
   17007          566 :             IDENT                                   { $$ = $1; }
   17008           36 :             | YEAR_P                                { $$ = "year"; }
   17009           21 :             | MONTH_P                               { $$ = "month"; }
   17010           27 :             | DAY_P                                 { $$ = "day"; }
   17011           15 :             | HOUR_P                                { $$ = "hour"; }
   17012           15 :             | MINUTE_P                              { $$ = "minute"; }
   17013           15 :             | SECOND_P                              { $$ = "second"; }
   17014            0 :             | Sconst                                { $$ = $1; }
   17015              :         ;
   17016              : 
   17017              : unicode_normal_form:
   17018           12 :             NFC                                     { $$ = "NFC"; }
   17019            9 :             | NFD                                   { $$ = "NFD"; }
   17020            9 :             | NFKC                                  { $$ = "NFKC"; }
   17021            9 :             | NFKD                                  { $$ = "NFKD"; }
   17022              :         ;
   17023              : 
   17024              : /* OVERLAY() arguments */
   17025              : overlay_list:
   17026              :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   17027              :                 {
   17028              :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   17029           17 :                     $$ = list_make4($1, $3, $5, $7);
   17030              :                 }
   17031              :             | a_expr PLACING a_expr FROM a_expr
   17032              :                 {
   17033              :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   17034           24 :                     $$ = list_make3($1, $3, $5);
   17035              :                 }
   17036              :         ;
   17037              : 
   17038              : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   17039              : position_list:
   17040          204 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   17041              :         ;
   17042              : 
   17043              : /*
   17044              :  * SUBSTRING() arguments
   17045              :  *
   17046              :  * Note that SQL:1999 has both
   17047              :  *     text FROM int FOR int
   17048              :  * and
   17049              :  *     text FROM pattern FOR escape
   17050              :  *
   17051              :  * In the parser we map them both to a call to the substring() function and
   17052              :  * rely on type resolution to pick the right one.
   17053              :  *
   17054              :  * In SQL:2003, the second variant was changed to
   17055              :  *     text SIMILAR pattern ESCAPE escape
   17056              :  * We could in theory map that to a different function internally, but
   17057              :  * since we still support the SQL:1999 version, we don't.  However,
   17058              :  * ruleutils.c will reverse-list the call in the newer style.
   17059              :  */
   17060              : substr_list:
   17061              :             a_expr FROM a_expr FOR a_expr
   17062              :                 {
   17063           76 :                     $$ = list_make3($1, $3, $5);
   17064              :                 }
   17065              :             | a_expr FOR a_expr FROM a_expr
   17066              :                 {
   17067              :                     /* not legal per SQL, but might as well allow it */
   17068            0 :                     $$ = list_make3($1, $5, $3);
   17069              :                 }
   17070              :             | a_expr FROM a_expr
   17071              :                 {
   17072              :                     /*
   17073              :                      * Because we aren't restricting data types here, this
   17074              :                      * syntax can end up resolving to textregexsubstr().
   17075              :                      * We've historically allowed that to happen, so continue
   17076              :                      * to accept it.  However, ruleutils.c will reverse-list
   17077              :                      * such a call in regular function call syntax.
   17078              :                      */
   17079          188 :                     $$ = list_make2($1, $3);
   17080              :                 }
   17081              :             | a_expr FOR a_expr
   17082              :                 {
   17083              :                     /* not legal per SQL */
   17084              : 
   17085              :                     /*
   17086              :                      * Since there are no cases where this syntax allows
   17087              :                      * a textual FOR value, we forcibly cast the argument
   17088              :                      * to int4.  The possible matches in pg_proc are
   17089              :                      * substring(text,int4) and substring(text,text),
   17090              :                      * and we don't want the parser to choose the latter,
   17091              :                      * which it is likely to do if the second argument
   17092              :                      * is unknown or doesn't have an implicit cast to int4.
   17093              :                      */
   17094           18 :                     $$ = list_make3($1, makeIntConst(1, -1),
   17095              :                                     makeTypeCast($3,
   17096              :                                                  SystemTypeName("int4"), -1));
   17097              :                 }
   17098              :             | a_expr SIMILAR a_expr ESCAPE a_expr
   17099              :                 {
   17100           95 :                     $$ = list_make3($1, $3, $5);
   17101              :                 }
   17102              :         ;
   17103              : 
   17104          304 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   17105           12 :             | FROM expr_list                        { $$ = $2; }
   17106           43 :             | expr_list                             { $$ = $1; }
   17107              :         ;
   17108              : 
   17109              : /*
   17110              :  * Define SQL-style CASE clause.
   17111              :  * - Full specification
   17112              :  *  CASE WHEN a = b THEN c ... ELSE d END
   17113              :  * - Implicit argument
   17114              :  *  CASE a WHEN b THEN c ... ELSE d END
   17115              :  */
   17116              : case_expr:  CASE case_arg when_clause_list case_default END_P
   17117              :                 {
   17118        21078 :                     CaseExpr   *c = makeNode(CaseExpr);
   17119              : 
   17120        21078 :                     c->casetype = InvalidOid; /* not analyzed yet */
   17121        21078 :                     c->arg = (Expr *) $2;
   17122        21078 :                     c->args = $3;
   17123        21078 :                     c->defresult = (Expr *) $4;
   17124        21078 :                     c->location = @1;
   17125        21078 :                     $$ = (Node *) c;
   17126              :                 }
   17127              :         ;
   17128              : 
   17129              : when_clause_list:
   17130              :             /* There must be at least one */
   17131        21078 :             when_clause                             { $$ = list_make1($1); }
   17132        15827 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   17133              :         ;
   17134              : 
   17135              : when_clause:
   17136              :             WHEN a_expr THEN a_expr
   17137              :                 {
   17138        36905 :                     CaseWhen   *w = makeNode(CaseWhen);
   17139              : 
   17140        36905 :                     w->expr = (Expr *) $2;
   17141        36905 :                     w->result = (Expr *) $4;
   17142        36905 :                     w->location = @1;
   17143        36905 :                     $$ = (Node *) w;
   17144              :                 }
   17145              :         ;
   17146              : 
   17147              : case_default:
   17148        15934 :             ELSE a_expr                             { $$ = $2; }
   17149         5144 :             | /*EMPTY*/                             { $$ = NULL; }
   17150              :         ;
   17151              : 
   17152         3607 : case_arg:   a_expr                                  { $$ = $1; }
   17153        17471 :             | /*EMPTY*/                             { $$ = NULL; }
   17154              :         ;
   17155              : 
   17156              : columnref:  ColId
   17157              :                 {
   17158       408888 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   17159              :                 }
   17160              :             | ColId indirection
   17161              :                 {
   17162       567668 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   17163              :                 }
   17164              :         ;
   17165              : 
   17166              : indirection_el:
   17167              :             '.' attr_name
   17168              :                 {
   17169       764057 :                     $$ = (Node *) makeString($2);
   17170              :                 }
   17171              :             | '.' '*'
   17172              :                 {
   17173         3610 :                     $$ = (Node *) makeNode(A_Star);
   17174              :                 }
   17175              :             | '[' a_expr ']'
   17176              :                 {
   17177         6997 :                     A_Indices *ai = makeNode(A_Indices);
   17178              : 
   17179         6997 :                     ai->is_slice = false;
   17180         6997 :                     ai->lidx = NULL;
   17181         6997 :                     ai->uidx = $2;
   17182         6997 :                     $$ = (Node *) ai;
   17183              :                 }
   17184              :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   17185              :                 {
   17186          306 :                     A_Indices *ai = makeNode(A_Indices);
   17187              : 
   17188          306 :                     ai->is_slice = true;
   17189          306 :                     ai->lidx = $2;
   17190          306 :                     ai->uidx = $4;
   17191          306 :                     $$ = (Node *) ai;
   17192              :                 }
   17193              :         ;
   17194              : 
   17195              : opt_slice_bound:
   17196          522 :             a_expr                                  { $$ = $1; }
   17197           90 :             | /*EMPTY*/                             { $$ = NULL; }
   17198              :         ;
   17199              : 
   17200              : indirection:
   17201       762761 :             indirection_el                          { $$ = list_make1($1); }
   17202         1615 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   17203              :         ;
   17204              : 
   17205              : opt_indirection:
   17206       103803 :             /*EMPTY*/                               { $$ = NIL; }
   17207        10594 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   17208              :         ;
   17209              : 
   17210              : opt_asymmetric: ASYMMETRIC
   17211              :             | /*EMPTY*/
   17212              :         ;
   17213              : 
   17214              : /* SQL/JSON support */
   17215              : json_passing_clause_opt:
   17216          168 :             PASSING json_arguments                  { $$ = $2; }
   17217         1000 :             | /*EMPTY*/                             { $$ = NIL; }
   17218              :         ;
   17219              : 
   17220              : json_arguments:
   17221          168 :             json_argument                           { $$ = list_make1($1); }
   17222           63 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17223              :         ;
   17224              : 
   17225              : json_argument:
   17226              :             json_value_expr AS ColLabel
   17227              :             {
   17228          231 :                 JsonArgument *n = makeNode(JsonArgument);
   17229              : 
   17230          231 :                 n->val = (JsonValueExpr *) $1;
   17231          231 :                 n->name = $3;
   17232          231 :                 $$ = (Node *) n;
   17233              :             }
   17234              :         ;
   17235              : 
   17236              : /* ARRAY is a noise word */
   17237              : json_wrapper_behavior:
   17238           21 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17239            0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17240           42 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17241            6 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17242            0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17243            6 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17244           18 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17245            3 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17246          820 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17247              :         ;
   17248              : 
   17249              : json_behavior:
   17250              :             DEFAULT a_expr
   17251          216 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17252              :             | json_behavior_type
   17253          351 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17254              :         ;
   17255              : 
   17256              : json_behavior_type:
   17257          246 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17258           15 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17259           15 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17260            6 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17261            6 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17262           15 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17263           36 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17264              :             /* non-standard, for Oracle compatibility only */
   17265           12 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17266              :         ;
   17267              : 
   17268              : json_behavior_clause_opt:
   17269              :             json_behavior ON EMPTY_P
   17270          111 :                 { $$ = list_make2($1, NULL); }
   17271              :             | json_behavior ON ERROR_P
   17272          276 :                 { $$ = list_make2(NULL, $1); }
   17273              :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17274           51 :                 { $$ = list_make2($1, $4); }
   17275              :             | /* EMPTY */
   17276          793 :                 { $$ = list_make2(NULL, NULL); }
   17277              :         ;
   17278              : 
   17279              : json_on_error_clause_opt:
   17280              :             json_behavior ON ERROR_P
   17281           75 :                 { $$ = $1; }
   17282              :             | /* EMPTY */
   17283          346 :                 { $$ = NULL; }
   17284              :         ;
   17285              : 
   17286              : json_value_expr:
   17287              :             a_expr json_format_clause_opt
   17288              :             {
   17289              :                 /* formatted_expr will be set during parse-analysis. */
   17290         2146 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17291         2146 :                                                 castNode(JsonFormat, $2));
   17292              :             }
   17293              :         ;
   17294              : 
   17295              : json_format_clause:
   17296              :             FORMAT_LA JSON ENCODING name
   17297              :                 {
   17298              :                     int     encoding;
   17299              : 
   17300           50 :                     if (!pg_strcasecmp($4, "utf8"))
   17301           32 :                         encoding = JS_ENC_UTF8;
   17302           18 :                     else if (!pg_strcasecmp($4, "utf16"))
   17303            6 :                         encoding = JS_ENC_UTF16;
   17304           12 :                     else if (!pg_strcasecmp($4, "utf32"))
   17305            6 :                         encoding = JS_ENC_UTF32;
   17306              :                     else
   17307            6 :                         ereport(ERROR,
   17308              :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17309              :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17310              :                                  parser_errposition(@4)));
   17311              : 
   17312           44 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17313              :                 }
   17314              :             | FORMAT_LA JSON
   17315              :                 {
   17316          206 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17317              :                 }
   17318              :         ;
   17319              : 
   17320              : json_format_clause_opt:
   17321              :             json_format_clause
   17322              :                 {
   17323          196 :                     $$ = $1;
   17324              :                 }
   17325              :             | /* EMPTY */
   17326              :                 {
   17327         2729 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17328              :                 }
   17329              :         ;
   17330              : 
   17331              : json_quotes_clause_opt:
   17332            6 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17333           45 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17334            6 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17335           84 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17336          775 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17337              :         ;
   17338              : 
   17339              : json_returning_clause_opt:
   17340              :             RETURNING Typename json_format_clause_opt
   17341              :                 {
   17342          749 :                     JsonOutput *n = makeNode(JsonOutput);
   17343              : 
   17344          749 :                     n->typeName = $2;
   17345          749 :                     n->returning = makeNode(JsonReturning);
   17346          749 :                     n->returning->format = (JsonFormat *) $3;
   17347          749 :                     $$ = (Node *) n;
   17348              :                 }
   17349          648 :             | /* EMPTY */                           { $$ = NULL; }
   17350              :         ;
   17351              : 
   17352              : /*
   17353              :  * We must assign the only-JSON production a precedence less than IDENT in
   17354              :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17355              :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17356              :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17357              :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17358              :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17359              :  * really related to this syntax, but it's a convenient choice because it
   17360              :  * already has a precedence less than IDENT for other reasons.
   17361              :  */
   17362              : json_predicate_type_constraint:
   17363          101 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17364           14 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17365           20 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17366           20 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17367           20 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17368              :         ;
   17369              : 
   17370              : /*
   17371              :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17372              :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17373              :  * This prevents reducing them when the next token is KEYS.
   17374              :  */
   17375              : json_key_uniqueness_constraint_opt:
   17376           54 :             WITH UNIQUE KEYS                            { $$ = true; }
   17377           50 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17378           22 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17379            8 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17380          399 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17381              :         ;
   17382              : 
   17383              : json_name_and_value_list:
   17384              :             json_name_and_value
   17385          174 :                 { $$ = list_make1($1); }
   17386              :             | json_name_and_value_list ',' json_name_and_value
   17387          128 :                 { $$ = lappend($1, $3); }
   17388              :         ;
   17389              : 
   17390              : json_name_and_value:
   17391              : /* Supporting this syntax seems to require major surgery
   17392              :             KEY c_expr VALUE_P json_value_expr
   17393              :                 { $$ = makeJsonKeyValue($2, $4); }
   17394              :             |
   17395              : */
   17396              :             c_expr VALUE_P json_value_expr
   17397           12 :                 { $$ = makeJsonKeyValue($1, $3); }
   17398              :             |
   17399              :             a_expr ':' json_value_expr
   17400          392 :                 { $$ = makeJsonKeyValue($1, $3); }
   17401              :         ;
   17402              : 
   17403              : /* empty means false for objects, true for arrays */
   17404              : json_object_constructor_null_clause_opt:
   17405           15 :             NULL_P ON NULL_P                    { $$ = false; }
   17406           55 :             | ABSENT ON NULL_P                  { $$ = true; }
   17407          206 :             | /* EMPTY */                       { $$ = false; }
   17408              :         ;
   17409              : 
   17410              : json_array_constructor_null_clause_opt:
   17411           30 :             NULL_P ON NULL_P                        { $$ = false; }
   17412           18 :             | ABSENT ON NULL_P                      { $$ = true; }
   17413           90 :             | /* EMPTY */                           { $$ = true; }
   17414              :         ;
   17415              : 
   17416              : json_value_expr_list:
   17417           60 :             json_value_expr                             { $$ = list_make1($1); }
   17418           69 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17419              :         ;
   17420              : 
   17421              : json_aggregate_func:
   17422              :             JSON_OBJECTAGG '('
   17423              :                 json_name_and_value
   17424              :                 json_object_constructor_null_clause_opt
   17425              :                 json_key_uniqueness_constraint_opt
   17426              :                 json_returning_clause_opt
   17427              :             ')'
   17428              :                 {
   17429          102 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17430              : 
   17431          102 :                     n->arg = (JsonKeyValue *) $3;
   17432          102 :                     n->absent_on_null = $4;
   17433          102 :                     n->unique = $5;
   17434          102 :                     n->constructor = makeNode(JsonAggConstructor);
   17435          102 :                     n->constructor->output = (JsonOutput *) $6;
   17436          102 :                     n->constructor->agg_order = NULL;
   17437          102 :                     n->constructor->location = @1;
   17438          102 :                     $$ = (Node *) n;
   17439              :                 }
   17440              :             | JSON_ARRAYAGG '('
   17441              :                 json_value_expr
   17442              :                 json_array_aggregate_order_by_clause_opt
   17443              :                 json_array_constructor_null_clause_opt
   17444              :                 json_returning_clause_opt
   17445              :             ')'
   17446              :                 {
   17447           78 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17448              : 
   17449           78 :                     n->arg = (JsonValueExpr *) $3;
   17450           78 :                     n->absent_on_null = $5;
   17451           78 :                     n->constructor = makeNode(JsonAggConstructor);
   17452           78 :                     n->constructor->agg_order = $4;
   17453           78 :                     n->constructor->output = (JsonOutput *) $6;
   17454           78 :                     n->constructor->location = @1;
   17455           78 :                     $$ = (Node *) n;
   17456              :                 }
   17457              :         ;
   17458              : 
   17459              : json_array_aggregate_order_by_clause_opt:
   17460            9 :             ORDER BY sortby_list                    { $$ = $3; }
   17461           69 :             | /* EMPTY */                           { $$ = NIL; }
   17462              :         ;
   17463              : 
   17464              : /*****************************************************************************
   17465              :  *
   17466              :  *  target list for SELECT
   17467              :  *
   17468              :  *****************************************************************************/
   17469              : 
   17470       252082 : opt_target_list: target_list                        { $$ = $1; }
   17471          284 :             | /* EMPTY */                           { $$ = NIL; }
   17472              :         ;
   17473              : 
   17474              : target_list:
   17475       256039 :             target_el                               { $$ = list_make1($1); }
   17476       371757 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17477              :         ;
   17478              : 
   17479              : target_el:  a_expr AS ColLabel
   17480              :                 {
   17481       126330 :                     $$ = makeNode(ResTarget);
   17482       126330 :                     $$->name = $3;
   17483       126330 :                     $$->indirection = NIL;
   17484       126330 :                     $$->val = (Node *) $1;
   17485       126330 :                     $$->location = @1;
   17486              :                 }
   17487              :             | a_expr BareColLabel
   17488              :                 {
   17489         1861 :                     $$ = makeNode(ResTarget);
   17490         1861 :                     $$->name = $2;
   17491         1861 :                     $$->indirection = NIL;
   17492         1861 :                     $$->val = (Node *) $1;
   17493         1861 :                     $$->location = @1;
   17494              :                 }
   17495              :             | a_expr
   17496              :                 {
   17497       467758 :                     $$ = makeNode(ResTarget);
   17498       467758 :                     $$->name = NULL;
   17499       467758 :                     $$->indirection = NIL;
   17500       467758 :                     $$->val = (Node *) $1;
   17501       467758 :                     $$->location = @1;
   17502              :                 }
   17503              :             | '*'
   17504              :                 {
   17505        31847 :                     ColumnRef  *n = makeNode(ColumnRef);
   17506              : 
   17507        31847 :                     n->fields = list_make1(makeNode(A_Star));
   17508        31847 :                     n->location = @1;
   17509              : 
   17510        31847 :                     $$ = makeNode(ResTarget);
   17511        31847 :                     $$->name = NULL;
   17512        31847 :                     $$->indirection = NIL;
   17513        31847 :                     $$->val = (Node *) n;
   17514        31847 :                     $$->location = @1;
   17515              :                 }
   17516              :         ;
   17517              : 
   17518              : 
   17519              : /*****************************************************************************
   17520              :  *
   17521              :  *  Names and constants
   17522              :  *
   17523              :  *****************************************************************************/
   17524              : 
   17525              : qualified_name_list:
   17526         9166 :             qualified_name                          { $$ = list_make1($1); }
   17527          404 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17528              :         ;
   17529              : 
   17530              : /*
   17531              :  * The production for a qualified relation name has to exactly match the
   17532              :  * production for a qualified func_name, because in a FROM clause we cannot
   17533              :  * tell which we are parsing until we see what comes after it ('(' for a
   17534              :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17535              :  * which may contain subscripts, and reject that case in the C code.
   17536              :  */
   17537              : qualified_name:
   17538              :             ColId
   17539              :                 {
   17540       226632 :                     $$ = makeRangeVar(NULL, $1, @1);
   17541              :                 }
   17542              :             | ColId indirection
   17543              :                 {
   17544       128365 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17545              :                 }
   17546              :         ;
   17547              : 
   17548              : name_list:  name
   17549        15224 :                     { $$ = list_make1(makeString($1)); }
   17550              :             | name_list ',' name
   17551        33062 :                     { $$ = lappend($1, makeString($3)); }
   17552              :         ;
   17553              : 
   17554              : 
   17555        92445 : name:       ColId                                   { $$ = $1; };
   17556              : 
   17557       829414 : attr_name:  ColLabel                                { $$ = $1; };
   17558              : 
   17559           32 : file_name:  Sconst                                  { $$ = $1; };
   17560              : 
   17561              : /*
   17562              :  * The production for a qualified func_name has to exactly match the
   17563              :  * production for a qualified columnref, because we cannot tell which we
   17564              :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17565              :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17566              :  * may contain subscripts, and reject that case in the C code.  (If we
   17567              :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17568              :  */
   17569              : func_name:  type_function_name
   17570       155211 :                     { $$ = list_make1(makeString($1)); }
   17571              :             | ColId indirection
   17572              :                     {
   17573        66689 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17574              :                                              yyscanner);
   17575              :                     }
   17576              :         ;
   17577              : 
   17578              : 
   17579              : /*
   17580              :  * Constants
   17581              :  */
   17582              : AexprConst: Iconst
   17583              :                 {
   17584       203524 :                     $$ = makeIntConst($1, @1);
   17585              :                 }
   17586              :             | FCONST
   17587              :                 {
   17588         5980 :                     $$ = makeFloatConst($1, @1);
   17589              :                 }
   17590              :             | Sconst
   17591              :                 {
   17592       367877 :                     $$ = makeStringConst($1, @1);
   17593              :                 }
   17594              :             | BCONST
   17595              :                 {
   17596          377 :                     $$ = makeBitStringConst($1, @1);
   17597              :                 }
   17598              :             | XCONST
   17599              :                 {
   17600              :                     /* This is a bit constant per SQL99:
   17601              :                      * Without Feature F511, "BIT data type",
   17602              :                      * a <general literal> shall not be a
   17603              :                      * <bit string literal> or a <hex string literal>.
   17604              :                      */
   17605         1667 :                     $$ = makeBitStringConst($1, @1);
   17606              :                 }
   17607              :             | func_name Sconst
   17608              :                 {
   17609              :                     /* generic type 'literal' syntax */
   17610         4924 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17611              : 
   17612         4924 :                     t->location = @1;
   17613         4924 :                     $$ = makeStringConstCast($2, @2, t);
   17614              :                 }
   17615              :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17616              :                 {
   17617              :                     /* generic syntax with a type modifier */
   17618            0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17619              :                     ListCell   *lc;
   17620              : 
   17621              :                     /*
   17622              :                      * We must use func_arg_list and opt_sort_clause in the
   17623              :                      * production to avoid reduce/reduce conflicts, but we
   17624              :                      * don't actually wish to allow NamedArgExpr in this
   17625              :                      * context, nor ORDER BY.
   17626              :                      */
   17627            0 :                     foreach(lc, $3)
   17628              :                     {
   17629            0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17630              : 
   17631            0 :                         if (IsA(arg, NamedArgExpr))
   17632            0 :                             ereport(ERROR,
   17633              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17634              :                                      errmsg("type modifier cannot have parameter name"),
   17635              :                                      parser_errposition(arg->location)));
   17636              :                     }
   17637            0 :                     if ($4 != NIL)
   17638            0 :                             ereport(ERROR,
   17639              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17640              :                                      errmsg("type modifier cannot have ORDER BY"),
   17641              :                                      parser_errposition(@4)));
   17642              : 
   17643            0 :                     t->typmods = $3;
   17644            0 :                     t->location = @1;
   17645            0 :                     $$ = makeStringConstCast($6, @6, t);
   17646              :                 }
   17647              :             | ConstTypename Sconst
   17648              :                 {
   17649         1588 :                     $$ = makeStringConstCast($2, @2, $1);
   17650              :                 }
   17651              :             | ConstInterval Sconst opt_interval
   17652              :                 {
   17653         1649 :                     TypeName   *t = $1;
   17654              : 
   17655         1649 :                     t->typmods = $3;
   17656         1649 :                     $$ = makeStringConstCast($2, @2, t);
   17657              :                 }
   17658              :             | ConstInterval '(' Iconst ')' Sconst
   17659              :                 {
   17660            6 :                     TypeName   *t = $1;
   17661              : 
   17662            6 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17663              :                                             makeIntConst($3, @3));
   17664            6 :                     $$ = makeStringConstCast($5, @5, t);
   17665              :                 }
   17666              :             | TRUE_P
   17667              :                 {
   17668        15839 :                     $$ = makeBoolAConst(true, @1);
   17669              :                 }
   17670              :             | FALSE_P
   17671              :                 {
   17672        18123 :                     $$ = makeBoolAConst(false, @1);
   17673              :                 }
   17674              :             | NULL_P
   17675              :                 {
   17676        35174 :                     $$ = makeNullAConst(@1);
   17677              :                 }
   17678              :         ;
   17679              : 
   17680       217835 : Iconst:     ICONST                                  { $$ = $1; };
   17681       403690 : Sconst:     SCONST                                  { $$ = $1; };
   17682              : 
   17683         8751 : SignedIconst: Iconst                                { $$ = $1; }
   17684            0 :             | '+' Iconst                            { $$ = + $2; }
   17685          144 :             | '-' Iconst                            { $$ = - $2; }
   17686              :         ;
   17687              : 
   17688              : /* Role specifications */
   17689              : RoleId:     RoleSpec
   17690              :                 {
   17691         1008 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17692              : 
   17693         1008 :                     switch (spc->roletype)
   17694              :                     {
   17695         1003 :                         case ROLESPEC_CSTRING:
   17696         1003 :                             $$ = spc->rolename;
   17697         1003 :                             break;
   17698            2 :                         case ROLESPEC_PUBLIC:
   17699            2 :                             ereport(ERROR,
   17700              :                                     (errcode(ERRCODE_RESERVED_NAME),
   17701              :                                      errmsg("role name \"%s\" is reserved",
   17702              :                                             "public"),
   17703              :                                      parser_errposition(@1)));
   17704              :                             break;
   17705            1 :                         case ROLESPEC_SESSION_USER:
   17706            1 :                             ereport(ERROR,
   17707              :                                     (errcode(ERRCODE_RESERVED_NAME),
   17708              :                                      errmsg("%s cannot be used as a role name here",
   17709              :                                             "SESSION_USER"),
   17710              :                                      parser_errposition(@1)));
   17711              :                             break;
   17712            1 :                         case ROLESPEC_CURRENT_USER:
   17713            1 :                             ereport(ERROR,
   17714              :                                     (errcode(ERRCODE_RESERVED_NAME),
   17715              :                                      errmsg("%s cannot be used as a role name here",
   17716              :                                             "CURRENT_USER"),
   17717              :                                      parser_errposition(@1)));
   17718              :                             break;
   17719            1 :                         case ROLESPEC_CURRENT_ROLE:
   17720            1 :                             ereport(ERROR,
   17721              :                                     (errcode(ERRCODE_RESERVED_NAME),
   17722              :                                      errmsg("%s cannot be used as a role name here",
   17723              :                                             "CURRENT_ROLE"),
   17724              :                                      parser_errposition(@1)));
   17725              :                             break;
   17726              :                     }
   17727              :                 }
   17728              :             ;
   17729              : 
   17730              : RoleSpec:   NonReservedWord
   17731              :                 {
   17732              :                     /*
   17733              :                      * "public" and "none" are not keywords, but they must
   17734              :                      * be treated specially here.
   17735              :                      */
   17736              :                     RoleSpec   *n;
   17737              : 
   17738        16732 :                     if (strcmp($1, "public") == 0)
   17739              :                     {
   17740         9077 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17741         9077 :                         n->roletype = ROLESPEC_PUBLIC;
   17742              :                     }
   17743         7655 :                     else if (strcmp($1, "none") == 0)
   17744              :                     {
   17745           13 :                         ereport(ERROR,
   17746              :                                 (errcode(ERRCODE_RESERVED_NAME),
   17747              :                                  errmsg("role name \"%s\" is reserved",
   17748              :                                         "none"),
   17749              :                                  parser_errposition(@1)));
   17750              :                     }
   17751              :                     else
   17752              :                     {
   17753         7642 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17754         7642 :                         n->rolename = pstrdup($1);
   17755              :                     }
   17756        16719 :                     $$ = n;
   17757              :                 }
   17758              :             | CURRENT_ROLE
   17759              :                 {
   17760           65 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17761              :                 }
   17762              :             | CURRENT_USER
   17763              :                 {
   17764          114 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17765              :                 }
   17766              :             | SESSION_USER
   17767              :                 {
   17768           18 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17769              :                 }
   17770              :         ;
   17771              : 
   17772              : role_list:  RoleSpec
   17773         1653 :                 { $$ = list_make1($1); }
   17774              :             | role_list ',' RoleSpec
   17775          135 :                 { $$ = lappend($1, $3); }
   17776              :         ;
   17777              : 
   17778              : 
   17779              : /*****************************************************************************
   17780              :  *
   17781              :  * PL/pgSQL extensions
   17782              :  *
   17783              :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17784              :  * historically it can include just about anything that can follow SELECT.
   17785              :  * Therefore the returned struct is a SelectStmt.
   17786              :  *****************************************************************************/
   17787              : 
   17788              : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17789              :             from_clause where_clause
   17790              :             group_clause having_clause window_clause
   17791              :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17792              :                 {
   17793        20857 :                     SelectStmt *n = makeNode(SelectStmt);
   17794              : 
   17795        20857 :                     n->distinctClause = $1;
   17796        20857 :                     n->targetList = $2;
   17797        20857 :                     n->fromClause = $3;
   17798        20857 :                     n->whereClause = $4;
   17799        20857 :                     n->groupClause = ($5)->list;
   17800        20857 :                     n->groupDistinct = ($5)->distinct;
   17801        20857 :                     n->groupByAll = ($5)->all;
   17802        20857 :                     n->havingClause = $6;
   17803        20857 :                     n->windowClause = $7;
   17804        20857 :                     n->sortClause = $8;
   17805        20857 :                     if ($9)
   17806              :                     {
   17807            2 :                         n->limitOffset = $9->limitOffset;
   17808            2 :                         n->limitCount = $9->limitCount;
   17809            2 :                         if (!n->sortClause &&
   17810            2 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17811            0 :                             ereport(ERROR,
   17812              :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17813              :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17814              :                                      parser_errposition($9->optionLoc)));
   17815            2 :                         n->limitOption = $9->limitOption;
   17816              :                     }
   17817        20857 :                     n->lockingClause = $10;
   17818        20857 :                     $$ = (Node *) n;
   17819              :                 }
   17820              :         ;
   17821              : 
   17822              : /*
   17823              :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17824              :  */
   17825              : 
   17826              : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17827              :                 {
   17828         3584 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17829              : 
   17830         3584 :                     n->name = $1;
   17831         3584 :                     n->indirection = check_indirection($2, yyscanner);
   17832              :                     /* nnames will be filled by calling production */
   17833         3584 :                     n->val = (SelectStmt *) $4;
   17834         3584 :                     n->location = @1;
   17835         3584 :                     $$ = (Node *) n;
   17836              :                 }
   17837              :         ;
   17838              : 
   17839         3572 : plassign_target: ColId                          { $$ = $1; }
   17840           12 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17841              :         ;
   17842              : 
   17843              : plassign_equals: COLON_EQUALS
   17844              :             | '='
   17845              :         ;
   17846              : 
   17847              : 
   17848              : /*
   17849              :  * Name classification hierarchy.
   17850              :  *
   17851              :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17852              :  * no known keyword.  In most cases, we can accept certain keywords as
   17853              :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17854              :  * as possible to minimize the impact of "reserved words" on programmers.
   17855              :  * So, we divide names into several possible classes.  The classification
   17856              :  * is chosen in part to make keywords acceptable as names wherever possible.
   17857              :  */
   17858              : 
   17859              : /* Column identifier --- names that can be column, table, etc names.
   17860              :  */
   17861      1800016 : ColId:      IDENT                                   { $$ = $1; }
   17862        31280 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17863         3342 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17864              :         ;
   17865              : 
   17866              : /* Type/function identifier --- names that can be type or function names.
   17867              :  */
   17868       360919 : type_function_name: IDENT                           { $$ = $1; }
   17869        35193 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17870           33 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17871              :         ;
   17872              : 
   17873              : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17874              :  */
   17875        41892 : NonReservedWord:    IDENT                           { $$ = $1; }
   17876        15903 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17877          110 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17878         3104 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17879              :         ;
   17880              : 
   17881              : /* Column label --- allowed labels in "AS" clauses.
   17882              :  * This presently includes *all* Postgres keywords.
   17883              :  */
   17884       946770 : ColLabel:   IDENT                                   { $$ = $1; }
   17885        21449 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17886          145 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17887          893 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17888         3831 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17889              :         ;
   17890              : 
   17891              : /* Bare column label --- names that can be column labels without writing "AS".
   17892              :  * This classification is orthogonal to the other keyword categories.
   17893              :  */
   17894         1854 : BareColLabel:   IDENT                               { $$ = $1; }
   17895            7 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17896              :         ;
   17897              : 
   17898              : 
   17899              : /*
   17900              :  * Keyword category lists.  Generally, every keyword present in
   17901              :  * the Postgres grammar should appear in exactly one of these lists.
   17902              :  *
   17903              :  * Put a new keyword into the first list that it can go into without causing
   17904              :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17905              :  * categories of keywords.
   17906              :  *
   17907              :  * Make sure that each keyword's category in kwlist.h matches where
   17908              :  * it is listed here.  (Someday we may be able to generate these lists and
   17909              :  * kwlist.h's table from one source of truth.)
   17910              :  */
   17911              : 
   17912              : /* "Unreserved" keywords --- available for use as any kind of name.
   17913              :  */
   17914              : unreserved_keyword:
   17915              :               ABORT_P
   17916              :             | ABSENT
   17917              :             | ABSOLUTE_P
   17918              :             | ACCESS
   17919              :             | ACTION
   17920              :             | ADD_P
   17921              :             | ADMIN
   17922              :             | AFTER
   17923              :             | AGGREGATE
   17924              :             | ALSO
   17925              :             | ALTER
   17926              :             | ALWAYS
   17927              :             | ASENSITIVE
   17928              :             | ASSERTION
   17929              :             | ASSIGNMENT
   17930              :             | AT
   17931              :             | ATOMIC
   17932              :             | ATTACH
   17933              :             | ATTRIBUTE
   17934              :             | BACKWARD
   17935              :             | BEFORE
   17936              :             | BEGIN_P
   17937              :             | BREADTH
   17938              :             | BY
   17939              :             | CACHE
   17940              :             | CALL
   17941              :             | CALLED
   17942              :             | CASCADE
   17943              :             | CASCADED
   17944              :             | CATALOG_P
   17945              :             | CHAIN
   17946              :             | CHARACTERISTICS
   17947              :             | CHECKPOINT
   17948              :             | CLASS
   17949              :             | CLOSE
   17950              :             | CLUSTER
   17951              :             | COLUMNS
   17952              :             | COMMENT
   17953              :             | COMMENTS
   17954              :             | COMMIT
   17955              :             | COMMITTED
   17956              :             | COMPRESSION
   17957              :             | CONDITIONAL
   17958              :             | CONFIGURATION
   17959              :             | CONFLICT
   17960              :             | CONNECTION
   17961              :             | CONSTRAINTS
   17962              :             | CONTENT_P
   17963              :             | CONTINUE_P
   17964              :             | CONVERSION_P
   17965              :             | COPY
   17966              :             | COST
   17967              :             | CSV
   17968              :             | CUBE
   17969              :             | CURRENT_P
   17970              :             | CURSOR
   17971              :             | CYCLE
   17972              :             | DATA_P
   17973              :             | DATABASE
   17974              :             | DAY_P
   17975              :             | DEALLOCATE
   17976              :             | DECLARE
   17977              :             | DEFAULTS
   17978              :             | DEFERRED
   17979              :             | DEFINER
   17980              :             | DELETE_P
   17981              :             | DELIMITER
   17982              :             | DELIMITERS
   17983              :             | DEPENDS
   17984              :             | DEPTH
   17985              :             | DETACH
   17986              :             | DICTIONARY
   17987              :             | DISABLE_P
   17988              :             | DISCARD
   17989              :             | DOCUMENT_P
   17990              :             | DOMAIN_P
   17991              :             | DOUBLE_P
   17992              :             | DROP
   17993              :             | EACH
   17994              :             | EMPTY_P
   17995              :             | ENABLE_P
   17996              :             | ENCODING
   17997              :             | ENCRYPTED
   17998              :             | ENFORCED
   17999              :             | ENUM_P
   18000              :             | ERROR_P
   18001              :             | ESCAPE
   18002              :             | EVENT
   18003              :             | EXCLUDE
   18004              :             | EXCLUDING
   18005              :             | EXCLUSIVE
   18006              :             | EXECUTE
   18007              :             | EXPLAIN
   18008              :             | EXPRESSION
   18009              :             | EXTENSION
   18010              :             | EXTERNAL
   18011              :             | FAMILY
   18012              :             | FILTER
   18013              :             | FINALIZE
   18014              :             | FIRST_P
   18015              :             | FOLLOWING
   18016              :             | FORCE
   18017              :             | FORMAT
   18018              :             | FORWARD
   18019              :             | FUNCTION
   18020              :             | FUNCTIONS
   18021              :             | GENERATED
   18022              :             | GLOBAL
   18023              :             | GRANTED
   18024              :             | GROUPS
   18025              :             | HANDLER
   18026              :             | HEADER_P
   18027              :             | HOLD
   18028              :             | HOUR_P
   18029              :             | IDENTITY_P
   18030              :             | IF_P
   18031              :             | IGNORE_P
   18032              :             | IMMEDIATE
   18033              :             | IMMUTABLE
   18034              :             | IMPLICIT_P
   18035              :             | IMPORT_P
   18036              :             | INCLUDE
   18037              :             | INCLUDING
   18038              :             | INCREMENT
   18039              :             | INDENT
   18040              :             | INDEX
   18041              :             | INDEXES
   18042              :             | INHERIT
   18043              :             | INHERITS
   18044              :             | INLINE_P
   18045              :             | INPUT_P
   18046              :             | INSENSITIVE
   18047              :             | INSERT
   18048              :             | INSTEAD
   18049              :             | INVOKER
   18050              :             | ISOLATION
   18051              :             | KEEP
   18052              :             | KEY
   18053              :             | KEYS
   18054              :             | LABEL
   18055              :             | LANGUAGE
   18056              :             | LARGE_P
   18057              :             | LAST_P
   18058              :             | LEAKPROOF
   18059              :             | LEVEL
   18060              :             | LISTEN
   18061              :             | LOAD
   18062              :             | LOCAL
   18063              :             | LOCATION
   18064              :             | LOCK_P
   18065              :             | LOCKED
   18066              :             | LOGGED
   18067              :             | LSN_P
   18068              :             | MAPPING
   18069              :             | MATCH
   18070              :             | MATCHED
   18071              :             | MATERIALIZED
   18072              :             | MAXVALUE
   18073              :             | MERGE
   18074              :             | METHOD
   18075              :             | MINUTE_P
   18076              :             | MINVALUE
   18077              :             | MODE
   18078              :             | MONTH_P
   18079              :             | MOVE
   18080              :             | NAME_P
   18081              :             | NAMES
   18082              :             | NESTED
   18083              :             | NEW
   18084              :             | NEXT
   18085              :             | NFC
   18086              :             | NFD
   18087              :             | NFKC
   18088              :             | NFKD
   18089              :             | NO
   18090              :             | NORMALIZED
   18091              :             | NOTHING
   18092              :             | NOTIFY
   18093              :             | NOWAIT
   18094              :             | NULLS_P
   18095              :             | OBJECT_P
   18096              :             | OBJECTS_P
   18097              :             | OF
   18098              :             | OFF
   18099              :             | OIDS
   18100              :             | OLD
   18101              :             | OMIT
   18102              :             | OPERATOR
   18103              :             | OPTION
   18104              :             | OPTIONS
   18105              :             | ORDINALITY
   18106              :             | OTHERS
   18107              :             | OVER
   18108              :             | OVERRIDING
   18109              :             | OWNED
   18110              :             | OWNER
   18111              :             | PARALLEL
   18112              :             | PARAMETER
   18113              :             | PARSER
   18114              :             | PARTIAL
   18115              :             | PARTITION
   18116              :             | PARTITIONS
   18117              :             | PASSING
   18118              :             | PASSWORD
   18119              :             | PATH
   18120              :             | PERIOD
   18121              :             | PLAN
   18122              :             | PLANS
   18123              :             | POLICY
   18124              :             | PRECEDING
   18125              :             | PREPARE
   18126              :             | PREPARED
   18127              :             | PRESERVE
   18128              :             | PRIOR
   18129              :             | PRIVILEGES
   18130              :             | PROCEDURAL
   18131              :             | PROCEDURE
   18132              :             | PROCEDURES
   18133              :             | PROGRAM
   18134              :             | PUBLICATION
   18135              :             | QUOTE
   18136              :             | QUOTES
   18137              :             | RANGE
   18138              :             | READ
   18139              :             | REASSIGN
   18140              :             | RECURSIVE
   18141              :             | REF_P
   18142              :             | REFERENCING
   18143              :             | REFRESH
   18144              :             | REINDEX
   18145              :             | RELATIVE_P
   18146              :             | RELEASE
   18147              :             | RENAME
   18148              :             | REPEATABLE
   18149              :             | REPLACE
   18150              :             | REPLICA
   18151              :             | RESET
   18152              :             | RESPECT_P
   18153              :             | RESTART
   18154              :             | RESTRICT
   18155              :             | RETURN
   18156              :             | RETURNS
   18157              :             | REVOKE
   18158              :             | ROLE
   18159              :             | ROLLBACK
   18160              :             | ROLLUP
   18161              :             | ROUTINE
   18162              :             | ROUTINES
   18163              :             | ROWS
   18164              :             | RULE
   18165              :             | SAVEPOINT
   18166              :             | SCALAR
   18167              :             | SCHEMA
   18168              :             | SCHEMAS
   18169              :             | SCROLL
   18170              :             | SEARCH
   18171              :             | SECOND_P
   18172              :             | SECURITY
   18173              :             | SEQUENCE
   18174              :             | SEQUENCES
   18175              :             | SERIALIZABLE
   18176              :             | SERVER
   18177              :             | SESSION
   18178              :             | SET
   18179              :             | SETS
   18180              :             | SHARE
   18181              :             | SHOW
   18182              :             | SIMPLE
   18183              :             | SKIP
   18184              :             | SNAPSHOT
   18185              :             | SOURCE
   18186              :             | SPLIT
   18187              :             | SQL_P
   18188              :             | STABLE
   18189              :             | STANDALONE_P
   18190              :             | START
   18191              :             | STATEMENT
   18192              :             | STATISTICS
   18193              :             | STDIN
   18194              :             | STDOUT
   18195              :             | STORAGE
   18196              :             | STORED
   18197              :             | STRICT_P
   18198              :             | STRING_P
   18199              :             | STRIP_P
   18200              :             | SUBSCRIPTION
   18201              :             | SUPPORT
   18202              :             | SYSID
   18203              :             | SYSTEM_P
   18204              :             | TABLES
   18205              :             | TABLESPACE
   18206              :             | TARGET
   18207              :             | TEMP
   18208              :             | TEMPLATE
   18209              :             | TEMPORARY
   18210              :             | TEXT_P
   18211              :             | TIES
   18212              :             | TRANSACTION
   18213              :             | TRANSFORM
   18214              :             | TRIGGER
   18215              :             | TRUNCATE
   18216              :             | TRUSTED
   18217              :             | TYPE_P
   18218              :             | TYPES_P
   18219              :             | UESCAPE
   18220              :             | UNBOUNDED
   18221              :             | UNCOMMITTED
   18222              :             | UNCONDITIONAL
   18223              :             | UNENCRYPTED
   18224              :             | UNKNOWN
   18225              :             | UNLISTEN
   18226              :             | UNLOGGED
   18227              :             | UNTIL
   18228              :             | UPDATE
   18229              :             | VACUUM
   18230              :             | VALID
   18231              :             | VALIDATE
   18232              :             | VALIDATOR
   18233              :             | VALUE_P
   18234              :             | VARYING
   18235              :             | VERSION_P
   18236              :             | VIEW
   18237              :             | VIEWS
   18238              :             | VIRTUAL
   18239              :             | VOLATILE
   18240              :             | WAIT
   18241              :             | WHITESPACE_P
   18242              :             | WITHIN
   18243              :             | WITHOUT
   18244              :             | WORK
   18245              :             | WRAPPER
   18246              :             | WRITE
   18247              :             | XML_P
   18248              :             | YEAR_P
   18249              :             | YES_P
   18250              :             | ZONE
   18251              :         ;
   18252              : 
   18253              : /* Column identifier --- keywords that can be column, table, etc names.
   18254              :  *
   18255              :  * Many of these keywords will in fact be recognized as type or function
   18256              :  * names too; but they have special productions for the purpose, and so
   18257              :  * can't be treated as "generic" type or function names.
   18258              :  *
   18259              :  * The type names appearing here are not usable as function names
   18260              :  * because they can be followed by '(' in typename productions, which
   18261              :  * looks too much like a function call for an LR(1) parser.
   18262              :  */
   18263              : col_name_keyword:
   18264              :               BETWEEN
   18265              :             | BIGINT
   18266              :             | BIT
   18267              :             | BOOLEAN_P
   18268              :             | CHAR_P
   18269              :             | CHARACTER
   18270              :             | COALESCE
   18271              :             | DEC
   18272              :             | DECIMAL_P
   18273              :             | EXISTS
   18274              :             | EXTRACT
   18275              :             | FLOAT_P
   18276              :             | GREATEST
   18277              :             | GROUPING
   18278              :             | INOUT
   18279              :             | INT_P
   18280              :             | INTEGER
   18281              :             | INTERVAL
   18282              :             | JSON
   18283              :             | JSON_ARRAY
   18284              :             | JSON_ARRAYAGG
   18285              :             | JSON_EXISTS
   18286              :             | JSON_OBJECT
   18287              :             | JSON_OBJECTAGG
   18288              :             | JSON_QUERY
   18289              :             | JSON_SCALAR
   18290              :             | JSON_SERIALIZE
   18291              :             | JSON_TABLE
   18292              :             | JSON_VALUE
   18293              :             | LEAST
   18294              :             | MERGE_ACTION
   18295              :             | NATIONAL
   18296              :             | NCHAR
   18297              :             | NONE
   18298              :             | NORMALIZE
   18299              :             | NULLIF
   18300              :             | NUMERIC
   18301              :             | OUT_P
   18302              :             | OVERLAY
   18303              :             | POSITION
   18304              :             | PRECISION
   18305              :             | REAL
   18306              :             | ROW
   18307              :             | SETOF
   18308              :             | SMALLINT
   18309              :             | SUBSTRING
   18310              :             | TIME
   18311              :             | TIMESTAMP
   18312              :             | TREAT
   18313              :             | TRIM
   18314              :             | VALUES
   18315              :             | VARCHAR
   18316              :             | XMLATTRIBUTES
   18317              :             | XMLCONCAT
   18318              :             | XMLELEMENT
   18319              :             | XMLEXISTS
   18320              :             | XMLFOREST
   18321              :             | XMLNAMESPACES
   18322              :             | XMLPARSE
   18323              :             | XMLPI
   18324              :             | XMLROOT
   18325              :             | XMLSERIALIZE
   18326              :             | XMLTABLE
   18327              :         ;
   18328              : 
   18329              : /* Type/function identifier --- keywords that can be type or function names.
   18330              :  *
   18331              :  * Most of these are keywords that are used as operators in expressions;
   18332              :  * in general such keywords can't be column names because they would be
   18333              :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18334              :  *
   18335              :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18336              :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18337              :  * - thomas 2000-11-28
   18338              :  */
   18339              : type_func_name_keyword:
   18340              :               AUTHORIZATION
   18341              :             | BINARY
   18342              :             | COLLATION
   18343              :             | CONCURRENTLY
   18344              :             | CROSS
   18345              :             | CURRENT_SCHEMA
   18346              :             | FREEZE
   18347              :             | FULL
   18348              :             | ILIKE
   18349              :             | INNER_P
   18350              :             | IS
   18351              :             | ISNULL
   18352              :             | JOIN
   18353              :             | LEFT
   18354              :             | LIKE
   18355              :             | NATURAL
   18356              :             | NOTNULL
   18357              :             | OUTER_P
   18358              :             | OVERLAPS
   18359              :             | RIGHT
   18360              :             | SIMILAR
   18361              :             | TABLESAMPLE
   18362              :             | VERBOSE
   18363              :         ;
   18364              : 
   18365              : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18366              :  *
   18367              :  * Keywords appear here if they could not be distinguished from variable,
   18368              :  * type, or function names in some contexts.  Don't put things here unless
   18369              :  * forced to.
   18370              :  */
   18371              : reserved_keyword:
   18372              :               ALL
   18373              :             | ANALYSE
   18374              :             | ANALYZE
   18375              :             | AND
   18376              :             | ANY
   18377              :             | ARRAY
   18378              :             | AS
   18379              :             | ASC
   18380              :             | ASYMMETRIC
   18381              :             | BOTH
   18382              :             | CASE
   18383              :             | CAST
   18384              :             | CHECK
   18385              :             | COLLATE
   18386              :             | COLUMN
   18387              :             | CONSTRAINT
   18388              :             | CREATE
   18389              :             | CURRENT_CATALOG
   18390              :             | CURRENT_DATE
   18391              :             | CURRENT_ROLE
   18392              :             | CURRENT_TIME
   18393              :             | CURRENT_TIMESTAMP
   18394              :             | CURRENT_USER
   18395              :             | DEFAULT
   18396              :             | DEFERRABLE
   18397              :             | DESC
   18398              :             | DISTINCT
   18399              :             | DO
   18400              :             | ELSE
   18401              :             | END_P
   18402              :             | EXCEPT
   18403              :             | FALSE_P
   18404              :             | FETCH
   18405              :             | FOR
   18406              :             | FOREIGN
   18407              :             | FROM
   18408              :             | GRANT
   18409              :             | GROUP_P
   18410              :             | HAVING
   18411              :             | IN_P
   18412              :             | INITIALLY
   18413              :             | INTERSECT
   18414              :             | INTO
   18415              :             | LATERAL_P
   18416              :             | LEADING
   18417              :             | LIMIT
   18418              :             | LOCALTIME
   18419              :             | LOCALTIMESTAMP
   18420              :             | NOT
   18421              :             | NULL_P
   18422              :             | OFFSET
   18423              :             | ON
   18424              :             | ONLY
   18425              :             | OR
   18426              :             | ORDER
   18427              :             | PLACING
   18428              :             | PRIMARY
   18429              :             | REFERENCES
   18430              :             | RETURNING
   18431              :             | SELECT
   18432              :             | SESSION_USER
   18433              :             | SOME
   18434              :             | SYMMETRIC
   18435              :             | SYSTEM_USER
   18436              :             | TABLE
   18437              :             | THEN
   18438              :             | TO
   18439              :             | TRAILING
   18440              :             | TRUE_P
   18441              :             | UNION
   18442              :             | UNIQUE
   18443              :             | USER
   18444              :             | USING
   18445              :             | VARIADIC
   18446              :             | WHEN
   18447              :             | WHERE
   18448              :             | WINDOW
   18449              :             | WITH
   18450              :         ;
   18451              : 
   18452              : /*
   18453              :  * While all keywords can be used as column labels when preceded by AS,
   18454              :  * not all of them can be used as a "bare" column label without AS.
   18455              :  * Those that can be used as a bare label must be listed here,
   18456              :  * in addition to appearing in one of the category lists above.
   18457              :  *
   18458              :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18459              :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18460              :  */
   18461              : bare_label_keyword:
   18462              :               ABORT_P
   18463              :             | ABSENT
   18464              :             | ABSOLUTE_P
   18465              :             | ACCESS
   18466              :             | ACTION
   18467              :             | ADD_P
   18468              :             | ADMIN
   18469              :             | AFTER
   18470              :             | AGGREGATE
   18471              :             | ALL
   18472              :             | ALSO
   18473              :             | ALTER
   18474              :             | ALWAYS
   18475              :             | ANALYSE
   18476              :             | ANALYZE
   18477              :             | AND
   18478              :             | ANY
   18479              :             | ASC
   18480              :             | ASENSITIVE
   18481              :             | ASSERTION
   18482              :             | ASSIGNMENT
   18483              :             | ASYMMETRIC
   18484              :             | AT
   18485              :             | ATOMIC
   18486              :             | ATTACH
   18487              :             | ATTRIBUTE
   18488              :             | AUTHORIZATION
   18489              :             | BACKWARD
   18490              :             | BEFORE
   18491              :             | BEGIN_P
   18492              :             | BETWEEN
   18493              :             | BIGINT
   18494              :             | BINARY
   18495              :             | BIT
   18496              :             | BOOLEAN_P
   18497              :             | BOTH
   18498              :             | BREADTH
   18499              :             | BY
   18500              :             | CACHE
   18501              :             | CALL
   18502              :             | CALLED
   18503              :             | CASCADE
   18504              :             | CASCADED
   18505              :             | CASE
   18506              :             | CAST
   18507              :             | CATALOG_P
   18508              :             | CHAIN
   18509              :             | CHARACTERISTICS
   18510              :             | CHECK
   18511              :             | CHECKPOINT
   18512              :             | CLASS
   18513              :             | CLOSE
   18514              :             | CLUSTER
   18515              :             | COALESCE
   18516              :             | COLLATE
   18517              :             | COLLATION
   18518              :             | COLUMN
   18519              :             | COLUMNS
   18520              :             | COMMENT
   18521              :             | COMMENTS
   18522              :             | COMMIT
   18523              :             | COMMITTED
   18524              :             | COMPRESSION
   18525              :             | CONCURRENTLY
   18526              :             | CONDITIONAL
   18527              :             | CONFIGURATION
   18528              :             | CONFLICT
   18529              :             | CONNECTION
   18530              :             | CONSTRAINT
   18531              :             | CONSTRAINTS
   18532              :             | CONTENT_P
   18533              :             | CONTINUE_P
   18534              :             | CONVERSION_P
   18535              :             | COPY
   18536              :             | COST
   18537              :             | CROSS
   18538              :             | CSV
   18539              :             | CUBE
   18540              :             | CURRENT_P
   18541              :             | CURRENT_CATALOG
   18542              :             | CURRENT_DATE
   18543              :             | CURRENT_ROLE
   18544              :             | CURRENT_SCHEMA
   18545              :             | CURRENT_TIME
   18546              :             | CURRENT_TIMESTAMP
   18547              :             | CURRENT_USER
   18548              :             | CURSOR
   18549              :             | CYCLE
   18550              :             | DATA_P
   18551              :             | DATABASE
   18552              :             | DEALLOCATE
   18553              :             | DEC
   18554              :             | DECIMAL_P
   18555              :             | DECLARE
   18556              :             | DEFAULT
   18557              :             | DEFAULTS
   18558              :             | DEFERRABLE
   18559              :             | DEFERRED
   18560              :             | DEFINER
   18561              :             | DELETE_P
   18562              :             | DELIMITER
   18563              :             | DELIMITERS
   18564              :             | DEPENDS
   18565              :             | DEPTH
   18566              :             | DESC
   18567              :             | DETACH
   18568              :             | DICTIONARY
   18569              :             | DISABLE_P
   18570              :             | DISCARD
   18571              :             | DISTINCT
   18572              :             | DO
   18573              :             | DOCUMENT_P
   18574              :             | DOMAIN_P
   18575              :             | DOUBLE_P
   18576              :             | DROP
   18577              :             | EACH
   18578              :             | ELSE
   18579              :             | EMPTY_P
   18580              :             | ENABLE_P
   18581              :             | ENCODING
   18582              :             | ENCRYPTED
   18583              :             | END_P
   18584              :             | ENFORCED
   18585              :             | ENUM_P
   18586              :             | ERROR_P
   18587              :             | ESCAPE
   18588              :             | EVENT
   18589              :             | EXCLUDE
   18590              :             | EXCLUDING
   18591              :             | EXCLUSIVE
   18592              :             | EXECUTE
   18593              :             | EXISTS
   18594              :             | EXPLAIN
   18595              :             | EXPRESSION
   18596              :             | EXTENSION
   18597              :             | EXTERNAL
   18598              :             | EXTRACT
   18599              :             | FALSE_P
   18600              :             | FAMILY
   18601              :             | FINALIZE
   18602              :             | FIRST_P
   18603              :             | FLOAT_P
   18604              :             | FOLLOWING
   18605              :             | FORCE
   18606              :             | FOREIGN
   18607              :             | FORMAT
   18608              :             | FORWARD
   18609              :             | FREEZE
   18610              :             | FULL
   18611              :             | FUNCTION
   18612              :             | FUNCTIONS
   18613              :             | GENERATED
   18614              :             | GLOBAL
   18615              :             | GRANTED
   18616              :             | GREATEST
   18617              :             | GROUPING
   18618              :             | GROUPS
   18619              :             | HANDLER
   18620              :             | HEADER_P
   18621              :             | HOLD
   18622              :             | IDENTITY_P
   18623              :             | IF_P
   18624              :             | ILIKE
   18625              :             | IMMEDIATE
   18626              :             | IMMUTABLE
   18627              :             | IMPLICIT_P
   18628              :             | IMPORT_P
   18629              :             | IN_P
   18630              :             | INCLUDE
   18631              :             | INCLUDING
   18632              :             | INCREMENT
   18633              :             | INDENT
   18634              :             | INDEX
   18635              :             | INDEXES
   18636              :             | INHERIT
   18637              :             | INHERITS
   18638              :             | INITIALLY
   18639              :             | INLINE_P
   18640              :             | INNER_P
   18641              :             | INOUT
   18642              :             | INPUT_P
   18643              :             | INSENSITIVE
   18644              :             | INSERT
   18645              :             | INSTEAD
   18646              :             | INT_P
   18647              :             | INTEGER
   18648              :             | INTERVAL
   18649              :             | INVOKER
   18650              :             | IS
   18651              :             | ISOLATION
   18652              :             | JOIN
   18653              :             | JSON
   18654              :             | JSON_ARRAY
   18655              :             | JSON_ARRAYAGG
   18656              :             | JSON_EXISTS
   18657              :             | JSON_OBJECT
   18658              :             | JSON_OBJECTAGG
   18659              :             | JSON_QUERY
   18660              :             | JSON_SCALAR
   18661              :             | JSON_SERIALIZE
   18662              :             | JSON_TABLE
   18663              :             | JSON_VALUE
   18664              :             | KEEP
   18665              :             | KEY
   18666              :             | KEYS
   18667              :             | LABEL
   18668              :             | LANGUAGE
   18669              :             | LARGE_P
   18670              :             | LAST_P
   18671              :             | LATERAL_P
   18672              :             | LEADING
   18673              :             | LEAKPROOF
   18674              :             | LEAST
   18675              :             | LEFT
   18676              :             | LEVEL
   18677              :             | LIKE
   18678              :             | LISTEN
   18679              :             | LOAD
   18680              :             | LOCAL
   18681              :             | LOCALTIME
   18682              :             | LOCALTIMESTAMP
   18683              :             | LOCATION
   18684              :             | LOCK_P
   18685              :             | LOCKED
   18686              :             | LOGGED
   18687              :             | LSN_P
   18688              :             | MAPPING
   18689              :             | MATCH
   18690              :             | MATCHED
   18691              :             | MATERIALIZED
   18692              :             | MAXVALUE
   18693              :             | MERGE
   18694              :             | MERGE_ACTION
   18695              :             | METHOD
   18696              :             | MINVALUE
   18697              :             | MODE
   18698              :             | MOVE
   18699              :             | NAME_P
   18700              :             | NAMES
   18701              :             | NATIONAL
   18702              :             | NATURAL
   18703              :             | NCHAR
   18704              :             | NESTED
   18705              :             | NEW
   18706              :             | NEXT
   18707              :             | NFC
   18708              :             | NFD
   18709              :             | NFKC
   18710              :             | NFKD
   18711              :             | NO
   18712              :             | NONE
   18713              :             | NORMALIZE
   18714              :             | NORMALIZED
   18715              :             | NOT
   18716              :             | NOTHING
   18717              :             | NOTIFY
   18718              :             | NOWAIT
   18719              :             | NULL_P
   18720              :             | NULLIF
   18721              :             | NULLS_P
   18722              :             | NUMERIC
   18723              :             | OBJECT_P
   18724              :             | OBJECTS_P
   18725              :             | OF
   18726              :             | OFF
   18727              :             | OIDS
   18728              :             | OLD
   18729              :             | OMIT
   18730              :             | ONLY
   18731              :             | OPERATOR
   18732              :             | OPTION
   18733              :             | OPTIONS
   18734              :             | OR
   18735              :             | ORDINALITY
   18736              :             | OTHERS
   18737              :             | OUT_P
   18738              :             | OUTER_P
   18739              :             | OVERLAY
   18740              :             | OVERRIDING
   18741              :             | OWNED
   18742              :             | OWNER
   18743              :             | PARALLEL
   18744              :             | PARAMETER
   18745              :             | PARSER
   18746              :             | PARTIAL
   18747              :             | PARTITION
   18748              :             | PARTITIONS
   18749              :             | PASSING
   18750              :             | PASSWORD
   18751              :             | PATH
   18752              :             | PERIOD
   18753              :             | PLACING
   18754              :             | PLAN
   18755              :             | PLANS
   18756              :             | POLICY
   18757              :             | POSITION
   18758              :             | PRECEDING
   18759              :             | PREPARE
   18760              :             | PREPARED
   18761              :             | PRESERVE
   18762              :             | PRIMARY
   18763              :             | PRIOR
   18764              :             | PRIVILEGES
   18765              :             | PROCEDURAL
   18766              :             | PROCEDURE
   18767              :             | PROCEDURES
   18768              :             | PROGRAM
   18769              :             | PUBLICATION
   18770              :             | QUOTE
   18771              :             | QUOTES
   18772              :             | RANGE
   18773              :             | READ
   18774              :             | REAL
   18775              :             | REASSIGN
   18776              :             | RECURSIVE
   18777              :             | REF_P
   18778              :             | REFERENCES
   18779              :             | REFERENCING
   18780              :             | REFRESH
   18781              :             | REINDEX
   18782              :             | RELATIVE_P
   18783              :             | RELEASE
   18784              :             | RENAME
   18785              :             | REPEATABLE
   18786              :             | REPLACE
   18787              :             | REPLICA
   18788              :             | RESET
   18789              :             | RESTART
   18790              :             | RESTRICT
   18791              :             | RETURN
   18792              :             | RETURNS
   18793              :             | REVOKE
   18794              :             | RIGHT
   18795              :             | ROLE
   18796              :             | ROLLBACK
   18797              :             | ROLLUP
   18798              :             | ROUTINE
   18799              :             | ROUTINES
   18800              :             | ROW
   18801              :             | ROWS
   18802              :             | RULE
   18803              :             | SAVEPOINT
   18804              :             | SCALAR
   18805              :             | SCHEMA
   18806              :             | SCHEMAS
   18807              :             | SCROLL
   18808              :             | SEARCH
   18809              :             | SECURITY
   18810              :             | SELECT
   18811              :             | SEQUENCE
   18812              :             | SEQUENCES
   18813              :             | SERIALIZABLE
   18814              :             | SERVER
   18815              :             | SESSION
   18816              :             | SESSION_USER
   18817              :             | SET
   18818              :             | SETOF
   18819              :             | SETS
   18820              :             | SHARE
   18821              :             | SHOW
   18822              :             | SIMILAR
   18823              :             | SIMPLE
   18824              :             | SKIP
   18825              :             | SMALLINT
   18826              :             | SNAPSHOT
   18827              :             | SOME
   18828              :             | SOURCE
   18829              :             | SPLIT
   18830              :             | SQL_P
   18831              :             | STABLE
   18832              :             | STANDALONE_P
   18833              :             | START
   18834              :             | STATEMENT
   18835              :             | STATISTICS
   18836              :             | STDIN
   18837              :             | STDOUT
   18838              :             | STORAGE
   18839              :             | STORED
   18840              :             | STRICT_P
   18841              :             | STRING_P
   18842              :             | STRIP_P
   18843              :             | SUBSCRIPTION
   18844              :             | SUBSTRING
   18845              :             | SUPPORT
   18846              :             | SYMMETRIC
   18847              :             | SYSID
   18848              :             | SYSTEM_P
   18849              :             | SYSTEM_USER
   18850              :             | TABLE
   18851              :             | TABLES
   18852              :             | TABLESAMPLE
   18853              :             | TABLESPACE
   18854              :             | TARGET
   18855              :             | TEMP
   18856              :             | TEMPLATE
   18857              :             | TEMPORARY
   18858              :             | TEXT_P
   18859              :             | THEN
   18860              :             | TIES
   18861              :             | TIME
   18862              :             | TIMESTAMP
   18863              :             | TRAILING
   18864              :             | TRANSACTION
   18865              :             | TRANSFORM
   18866              :             | TREAT
   18867              :             | TRIGGER
   18868              :             | TRIM
   18869              :             | TRUE_P
   18870              :             | TRUNCATE
   18871              :             | TRUSTED
   18872              :             | TYPE_P
   18873              :             | TYPES_P
   18874              :             | UESCAPE
   18875              :             | UNBOUNDED
   18876              :             | UNCOMMITTED
   18877              :             | UNCONDITIONAL
   18878              :             | UNENCRYPTED
   18879              :             | UNIQUE
   18880              :             | UNKNOWN
   18881              :             | UNLISTEN
   18882              :             | UNLOGGED
   18883              :             | UNTIL
   18884              :             | UPDATE
   18885              :             | USER
   18886              :             | USING
   18887              :             | VACUUM
   18888              :             | VALID
   18889              :             | VALIDATE
   18890              :             | VALIDATOR
   18891              :             | VALUE_P
   18892              :             | VALUES
   18893              :             | VARCHAR
   18894              :             | VARIADIC
   18895              :             | VERBOSE
   18896              :             | VERSION_P
   18897              :             | VIEW
   18898              :             | VIEWS
   18899              :             | VIRTUAL
   18900              :             | VOLATILE
   18901              :             | WAIT
   18902              :             | WHEN
   18903              :             | WHITESPACE_P
   18904              :             | WORK
   18905              :             | WRAPPER
   18906              :             | WRITE
   18907              :             | XML_P
   18908              :             | XMLATTRIBUTES
   18909              :             | XMLCONCAT
   18910              :             | XMLELEMENT
   18911              :             | XMLEXISTS
   18912              :             | XMLFOREST
   18913              :             | XMLNAMESPACES
   18914              :             | XMLPARSE
   18915              :             | XMLPI
   18916              :             | XMLROOT
   18917              :             | XMLSERIALIZE
   18918              :             | XMLTABLE
   18919              :             | YES_P
   18920              :             | ZONE
   18921              :         ;
   18922              : 
   18923              : %%
   18924              : 
   18925              : /*
   18926              :  * The signature of this function is required by bison.  However, we
   18927              :  * ignore the passed yylloc and instead use the last token position
   18928              :  * available from the scanner.
   18929              :  */
   18930              : static void
   18931          353 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18932              : {
   18933          353 :     parser_yyerror(msg);
   18934              : }
   18935              : 
   18936              : static RawStmt *
   18937       431935 : makeRawStmt(Node *stmt, int stmt_location)
   18938              : {
   18939       431935 :     RawStmt    *rs = makeNode(RawStmt);
   18940              : 
   18941       431935 :     rs->stmt = stmt;
   18942       431935 :     rs->stmt_location = stmt_location;
   18943       431935 :     rs->stmt_len = 0;            /* might get changed later */
   18944       431935 :     return rs;
   18945              : }
   18946              : 
   18947              : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18948              : static void
   18949       309920 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18950              : {
   18951              :     /*
   18952              :      * If we already set the length, don't change it.  This is for situations
   18953              :      * like "select foo ;; select bar" where the same statement will be last
   18954              :      * in the string for more than one semicolon.
   18955              :      */
   18956       309920 :     if (rs->stmt_len > 0)
   18957          287 :         return;
   18958              : 
   18959              :     /* OK, update length of RawStmt */
   18960       309633 :     rs->stmt_len = end_location - rs->stmt_location;
   18961              : }
   18962              : 
   18963              : static Node *
   18964       976563 : makeColumnRef(char *colname, List *indirection,
   18965              :               int location, core_yyscan_t yyscanner)
   18966              : {
   18967              :     /*
   18968              :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18969              :      * any subscripting in the specified indirection list.  However, any field
   18970              :      * selection at the start of the indirection list must be transposed into
   18971              :      * the "fields" part of the ColumnRef node.
   18972              :      */
   18973       976563 :     ColumnRef  *c = makeNode(ColumnRef);
   18974       976563 :     int         nfields = 0;
   18975              :     ListCell   *l;
   18976              : 
   18977       976563 :     c->location = location;
   18978      1540433 :     foreach(l, indirection)
   18979              :     {
   18980       569128 :         if (IsA(lfirst(l), A_Indices))
   18981              :         {
   18982         5258 :             A_Indirection *i = makeNode(A_Indirection);
   18983              : 
   18984         5258 :             if (nfields == 0)
   18985              :             {
   18986              :                 /* easy case - all indirection goes to A_Indirection */
   18987         3841 :                 c->fields = list_make1(makeString(colname));
   18988         3841 :                 i->indirection = check_indirection(indirection, yyscanner);
   18989              :             }
   18990              :             else
   18991              :             {
   18992              :                 /* got to split the list in two */
   18993         1417 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18994              :                                                                   nfields),
   18995              :                                                    yyscanner);
   18996         1417 :                 indirection = list_truncate(indirection, nfields);
   18997         1417 :                 c->fields = lcons(makeString(colname), indirection);
   18998              :             }
   18999         5258 :             i->arg = (Node *) c;
   19000         5258 :             return (Node *) i;
   19001              :         }
   19002       563870 :         else if (IsA(lfirst(l), A_Star))
   19003              :         {
   19004              :             /* We only allow '*' at the end of a ColumnRef */
   19005         2856 :             if (lnext(indirection, l) != NULL)
   19006            0 :                 parser_yyerror("improper use of \"*\"");
   19007              :         }
   19008       563870 :         nfields++;
   19009              :     }
   19010              :     /* No subscripting, so all indirection gets added to field list */
   19011       971305 :     c->fields = lcons(makeString(colname), indirection);
   19012       971305 :     return (Node *) c;
   19013              : }
   19014              : 
   19015              : static Node *
   19016       164159 : makeTypeCast(Node *arg, TypeName *typename, int location)
   19017              : {
   19018       164159 :     TypeCast   *n = makeNode(TypeCast);
   19019              : 
   19020       164159 :     n->arg = arg;
   19021       164159 :     n->typeName = typename;
   19022       164159 :     n->location = location;
   19023       164159 :     return (Node *) n;
   19024              : }
   19025              : 
   19026              : static Node *
   19027         8167 : makeStringConstCast(char *str, int location, TypeName *typename)
   19028              : {
   19029         8167 :     Node       *s = makeStringConst(str, location);
   19030              : 
   19031         8167 :     return makeTypeCast(s, typename, -1);
   19032              : }
   19033              : 
   19034              : static Node *
   19035       208984 : makeIntConst(int val, int location)
   19036              : {
   19037       208984 :     A_Const    *n = makeNode(A_Const);
   19038              : 
   19039       208984 :     n->val.ival.type = T_Integer;
   19040       208984 :     n->val.ival.ival = val;
   19041       208984 :     n->location = location;
   19042              : 
   19043       208984 :     return (Node *) n;
   19044              : }
   19045              : 
   19046              : static Node *
   19047         6089 : makeFloatConst(char *str, int location)
   19048              : {
   19049         6089 :     A_Const    *n = makeNode(A_Const);
   19050              : 
   19051         6089 :     n->val.fval.type = T_Float;
   19052         6089 :     n->val.fval.fval = str;
   19053         6089 :     n->location = location;
   19054              : 
   19055         6089 :     return (Node *) n;
   19056              : }
   19057              : 
   19058              : static Node *
   19059        34092 : makeBoolAConst(bool state, int location)
   19060              : {
   19061        34092 :     A_Const    *n = makeNode(A_Const);
   19062              : 
   19063        34092 :     n->val.boolval.type = T_Boolean;
   19064        34092 :     n->val.boolval.boolval = state;
   19065        34092 :     n->location = location;
   19066              : 
   19067        34092 :     return (Node *) n;
   19068              : }
   19069              : 
   19070              : static Node *
   19071         2044 : makeBitStringConst(char *str, int location)
   19072              : {
   19073         2044 :     A_Const    *n = makeNode(A_Const);
   19074              : 
   19075         2044 :     n->val.bsval.type = T_BitString;
   19076         2044 :     n->val.bsval.bsval = str;
   19077         2044 :     n->location = location;
   19078              : 
   19079         2044 :     return (Node *) n;
   19080              : }
   19081              : 
   19082              : static Node *
   19083        35210 : makeNullAConst(int location)
   19084              : {
   19085        35210 :     A_Const    *n = makeNode(A_Const);
   19086              : 
   19087        35210 :     n->isnull = true;
   19088        35210 :     n->location = location;
   19089              : 
   19090        35210 :     return (Node *) n;
   19091              : }
   19092              : 
   19093              : static Node *
   19094         3054 : makeAConst(Node *v, int location)
   19095              : {
   19096              :     Node       *n;
   19097              : 
   19098         3054 :     switch (v->type)
   19099              :     {
   19100          109 :         case T_Float:
   19101          109 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   19102          109 :             break;
   19103              : 
   19104         2945 :         case T_Integer:
   19105         2945 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   19106         2945 :             break;
   19107              : 
   19108            0 :         default:
   19109              :             /* currently not used */
   19110              :             Assert(false);
   19111            0 :             n = NULL;
   19112              :     }
   19113              : 
   19114         3054 :     return n;
   19115              : }
   19116              : 
   19117              : /* makeRoleSpec
   19118              :  * Create a RoleSpec with the given type
   19119              :  */
   19120              : static RoleSpec *
   19121        17269 : makeRoleSpec(RoleSpecType type, int location)
   19122              : {
   19123        17269 :     RoleSpec   *spec = makeNode(RoleSpec);
   19124              : 
   19125        17269 :     spec->roletype = type;
   19126        17269 :     spec->location = location;
   19127              : 
   19128        17269 :     return spec;
   19129              : }
   19130              : 
   19131              : /* check_qualified_name --- check the result of qualified_name production
   19132              :  *
   19133              :  * It's easiest to let the grammar production for qualified_name allow
   19134              :  * subscripts and '*', which we then must reject here.
   19135              :  */
   19136              : static void
   19137       128381 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   19138              : {
   19139              :     ListCell   *i;
   19140              : 
   19141       256762 :     foreach(i, names)
   19142              :     {
   19143       128381 :         if (!IsA(lfirst(i), String))
   19144            0 :             parser_yyerror("syntax error");
   19145              :     }
   19146       128381 : }
   19147              : 
   19148              : /* check_func_name --- check the result of func_name production
   19149              :  *
   19150              :  * It's easiest to let the grammar production for func_name allow subscripts
   19151              :  * and '*', which we then must reject here.
   19152              :  */
   19153              : static List *
   19154        66703 : check_func_name(List *names, core_yyscan_t yyscanner)
   19155              : {
   19156              :     ListCell   *i;
   19157              : 
   19158       200109 :     foreach(i, names)
   19159              :     {
   19160       133406 :         if (!IsA(lfirst(i), String))
   19161            0 :             parser_yyerror("syntax error");
   19162              :     }
   19163        66703 :     return names;
   19164              : }
   19165              : 
   19166              : /* check_indirection --- check the result of indirection production
   19167              :  *
   19168              :  * We only allow '*' at the end of the list, but it's hard to enforce that
   19169              :  * in the grammar, so do it here.
   19170              :  */
   19171              : static List *
   19172        44335 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   19173              : {
   19174              :     ListCell   *l;
   19175              : 
   19176        60351 :     foreach(l, indirection)
   19177              :     {
   19178        16016 :         if (IsA(lfirst(l), A_Star))
   19179              :         {
   19180          754 :             if (lnext(indirection, l) != NULL)
   19181            0 :                 parser_yyerror("improper use of \"*\"");
   19182              :         }
   19183              :     }
   19184        44335 :     return indirection;
   19185              : }
   19186              : 
   19187              : /* extractArgTypes()
   19188              :  * Given a list of FunctionParameter nodes, extract a list of just the
   19189              :  * argument types (TypeNames) for input parameters only.  This is what
   19190              :  * is needed to look up an existing function, which is what is wanted by
   19191              :  * the productions that use this call.
   19192              :  */
   19193              : static List *
   19194         8786 : extractArgTypes(List *parameters)
   19195              : {
   19196         8786 :     List       *result = NIL;
   19197              :     ListCell   *i;
   19198              : 
   19199        19514 :     foreach(i, parameters)
   19200              :     {
   19201        10728 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19202              : 
   19203        10728 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19204        10644 :             result = lappend(result, p->argType);
   19205              :     }
   19206         8786 :     return result;
   19207              : }
   19208              : 
   19209              : /* extractAggrArgTypes()
   19210              :  * As above, but work from the output of the aggr_args production.
   19211              :  */
   19212              : static List *
   19213          181 : extractAggrArgTypes(List *aggrargs)
   19214              : {
   19215              :     Assert(list_length(aggrargs) == 2);
   19216          181 :     return extractArgTypes((List *) linitial(aggrargs));
   19217              : }
   19218              : 
   19219              : /* makeOrderedSetArgs()
   19220              :  * Build the result of the aggr_args production (which see the comments for).
   19221              :  * This handles only the case where both given lists are nonempty, so that
   19222              :  * we have to deal with multiple VARIADIC arguments.
   19223              :  */
   19224              : static List *
   19225           16 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19226              :                    core_yyscan_t yyscanner)
   19227              : {
   19228           16 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19229              :     Integer    *ndirectargs;
   19230              : 
   19231              :     /* No restriction unless last direct arg is VARIADIC */
   19232           16 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19233              :     {
   19234            8 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19235              : 
   19236              :         /*
   19237              :          * We ignore the names, though the aggr_arg production allows them; it
   19238              :          * doesn't allow default values, so those need not be checked.
   19239              :          */
   19240            8 :         if (list_length(orderedargs) != 1 ||
   19241            8 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19242            8 :             !equal(lastd->argType, firsto->argType))
   19243            0 :             ereport(ERROR,
   19244              :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19245              :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19246              :                      parser_errposition(firsto->location)));
   19247              : 
   19248              :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19249            8 :         orderedargs = NIL;
   19250              :     }
   19251              : 
   19252              :     /* don't merge into the next line, as list_concat changes directargs */
   19253           16 :     ndirectargs = makeInteger(list_length(directargs));
   19254              : 
   19255           16 :     return list_make2(list_concat(directargs, orderedargs),
   19256              :                       ndirectargs);
   19257              : }
   19258              : 
   19259              : /* insertSelectOptions()
   19260              :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19261              :  *
   19262              :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19263              :  */
   19264              : static void
   19265        47058 : insertSelectOptions(SelectStmt *stmt,
   19266              :                     List *sortClause, List *lockingClause,
   19267              :                     SelectLimit *limitClause,
   19268              :                     WithClause *withClause,
   19269              :                     core_yyscan_t yyscanner)
   19270              : {
   19271              :     Assert(IsA(stmt, SelectStmt));
   19272              : 
   19273              :     /*
   19274              :      * Tests here are to reject constructs like
   19275              :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19276              :      */
   19277        47058 :     if (sortClause)
   19278              :     {
   19279        39315 :         if (stmt->sortClause)
   19280            0 :             ereport(ERROR,
   19281              :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19282              :                      errmsg("multiple ORDER BY clauses not allowed"),
   19283              :                      parser_errposition(exprLocation((Node *) sortClause))));
   19284        39315 :         stmt->sortClause = sortClause;
   19285              :     }
   19286              :     /* We can handle multiple locking clauses, though */
   19287        47058 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19288        47058 :     if (limitClause && limitClause->limitOffset)
   19289              :     {
   19290          433 :         if (stmt->limitOffset)
   19291            0 :             ereport(ERROR,
   19292              :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19293              :                      errmsg("multiple OFFSET clauses not allowed"),
   19294              :                      parser_errposition(limitClause->offsetLoc)));
   19295          433 :         stmt->limitOffset = limitClause->limitOffset;
   19296              :     }
   19297        47058 :     if (limitClause && limitClause->limitCount)
   19298              :     {
   19299         2462 :         if (stmt->limitCount)
   19300            0 :             ereport(ERROR,
   19301              :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19302              :                      errmsg("multiple LIMIT clauses not allowed"),
   19303              :                      parser_errposition(limitClause->countLoc)));
   19304         2462 :         stmt->limitCount = limitClause->limitCount;
   19305              :     }
   19306        47058 :     if (limitClause)
   19307              :     {
   19308              :         /* If there was a conflict, we must have detected it above */
   19309              :         Assert(!stmt->limitOption);
   19310         2698 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19311            3 :             ereport(ERROR,
   19312              :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19313              :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19314              :                      parser_errposition(limitClause->optionLoc)));
   19315         2695 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19316              :         {
   19317              :             ListCell   *lc;
   19318              : 
   19319            3 :             foreach(lc, stmt->lockingClause)
   19320              :             {
   19321            3 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19322              : 
   19323            3 :                 if (lock->waitPolicy == LockWaitSkip)
   19324            3 :                     ereport(ERROR,
   19325              :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19326              :                              errmsg("%s and %s options cannot be used together",
   19327              :                                     "SKIP LOCKED", "WITH TIES"),
   19328              :                              parser_errposition(limitClause->optionLoc)));
   19329              :             }
   19330              :         }
   19331         2692 :         stmt->limitOption = limitClause->limitOption;
   19332              :     }
   19333        47052 :     if (withClause)
   19334              :     {
   19335         1577 :         if (stmt->withClause)
   19336            0 :             ereport(ERROR,
   19337              :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19338              :                      errmsg("multiple WITH clauses not allowed"),
   19339              :                      parser_errposition(exprLocation((Node *) withClause))));
   19340         1577 :         stmt->withClause = withClause;
   19341              :     }
   19342        47052 : }
   19343              : 
   19344              : static Node *
   19345        10280 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   19346              : {
   19347        10280 :     SelectStmt *n = makeNode(SelectStmt);
   19348              : 
   19349        10280 :     n->op = op;
   19350        10280 :     n->all = all;
   19351        10280 :     n->larg = (SelectStmt *) larg;
   19352        10280 :     n->rarg = (SelectStmt *) rarg;
   19353        10280 :     return (Node *) n;
   19354              : }
   19355              : 
   19356              : /* SystemFuncName()
   19357              :  * Build a properly-qualified reference to a built-in function.
   19358              :  */
   19359              : List *
   19360         9937 : SystemFuncName(char *name)
   19361              : {
   19362         9937 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19363              : }
   19364              : 
   19365              : /* SystemTypeName()
   19366              :  * Build a properly-qualified reference to a built-in type.
   19367              :  *
   19368              :  * typmod is defaulted, but may be changed afterwards by caller.
   19369              :  * Likewise for the location.
   19370              :  */
   19371              : TypeName *
   19372        59621 : SystemTypeName(char *name)
   19373              : {
   19374        59621 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19375              :                                                makeString(name)));
   19376              : }
   19377              : 
   19378              : /* doNegate()
   19379              :  * Handle negation of a numeric constant.
   19380              :  *
   19381              :  * Formerly, we did this here because the optimizer couldn't cope with
   19382              :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19383              :  * and a unary minus operator applied to a constant didn't qualify.
   19384              :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19385              :  * is a constant-subexpression simplifier in the optimizer.  However,
   19386              :  * there's still a good reason for doing this here, which is that we can
   19387              :  * postpone committing to a particular internal representation for simple
   19388              :  * negative constants.  It's better to leave "-123.456" in string form
   19389              :  * until we know what the desired type is.
   19390              :  */
   19391              : static Node *
   19392         4711 : doNegate(Node *n, int location)
   19393              : {
   19394         4711 :     if (IsA(n, A_Const))
   19395              :     {
   19396         4206 :         A_Const    *con = (A_Const *) n;
   19397              : 
   19398              :         /* report the constant's location as that of the '-' sign */
   19399         4206 :         con->location = location;
   19400              : 
   19401         4206 :         if (IsA(&con->val, Integer))
   19402              :         {
   19403         3727 :             con->val.ival.ival = -con->val.ival.ival;
   19404         3727 :             return n;
   19405              :         }
   19406          479 :         if (IsA(&con->val, Float))
   19407              :         {
   19408          479 :             doNegateFloat(&con->val.fval);
   19409          479 :             return n;
   19410              :         }
   19411              :     }
   19412              : 
   19413          505 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19414              : }
   19415              : 
   19416              : static void
   19417          489 : doNegateFloat(Float *v)
   19418              : {
   19419          489 :     char       *oldval = v->fval;
   19420              : 
   19421          489 :     if (*oldval == '+')
   19422            0 :         oldval++;
   19423          489 :     if (*oldval == '-')
   19424            0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19425              :     else
   19426          489 :         v->fval = psprintf("-%s", oldval);
   19427          489 : }
   19428              : 
   19429              : static Node *
   19430       123449 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19431              : {
   19432              :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19433       123449 :     if (IsA(lexpr, BoolExpr))
   19434              :     {
   19435        58311 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19436              : 
   19437        58311 :         if (blexpr->boolop == AND_EXPR)
   19438              :         {
   19439        56906 :             blexpr->args = lappend(blexpr->args, rexpr);
   19440        56906 :             return (Node *) blexpr;
   19441              :         }
   19442              :     }
   19443        66543 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19444              : }
   19445              : 
   19446              : static Node *
   19447         8796 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19448              : {
   19449              :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19450         8796 :     if (IsA(lexpr, BoolExpr))
   19451              :     {
   19452         3134 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19453              : 
   19454         3134 :         if (blexpr->boolop == OR_EXPR)
   19455              :         {
   19456         2288 :             blexpr->args = lappend(blexpr->args, rexpr);
   19457         2288 :             return (Node *) blexpr;
   19458              :         }
   19459              :     }
   19460         6508 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19461              : }
   19462              : 
   19463              : static Node *
   19464         8824 : makeNotExpr(Node *expr, int location)
   19465              : {
   19466         8824 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19467              : }
   19468              : 
   19469              : static Node *
   19470         4220 : makeAArrayExpr(List *elements, int location, int location_end)
   19471              : {
   19472         4220 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19473              : 
   19474         4220 :     n->elements = elements;
   19475         4220 :     n->location = location;
   19476         4220 :     n->list_start = location;
   19477         4220 :     n->list_end = location_end;
   19478         4220 :     return (Node *) n;
   19479              : }
   19480              : 
   19481              : static Node *
   19482         1408 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19483              : {
   19484         1408 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19485              : 
   19486         1408 :     svf->op = op;
   19487              :     /* svf->type will be filled during parse analysis */
   19488         1408 :     svf->typmod = typmod;
   19489         1408 :     svf->location = location;
   19490         1408 :     return (Node *) svf;
   19491              : }
   19492              : 
   19493              : static Node *
   19494          298 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19495              :             int location)
   19496              : {
   19497          298 :     XmlExpr    *x = makeNode(XmlExpr);
   19498              : 
   19499          298 :     x->op = op;
   19500          298 :     x->name = name;
   19501              : 
   19502              :     /*
   19503              :      * named_args is a list of ResTarget; it'll be split apart into separate
   19504              :      * expression and name lists in transformXmlExpr().
   19505              :      */
   19506          298 :     x->named_args = named_args;
   19507          298 :     x->arg_names = NIL;
   19508          298 :     x->args = args;
   19509              :     /* xmloption, if relevant, must be filled in by caller */
   19510              :     /* type and typmod will be filled in during parse analysis */
   19511          298 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19512          298 :     x->location = location;
   19513          298 :     return (Node *) x;
   19514              : }
   19515              : 
   19516              : /*
   19517              :  * Merge the input and output parameters of a table function.
   19518              :  */
   19519              : static List *
   19520           97 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19521              : {
   19522              :     ListCell   *lc;
   19523              : 
   19524              :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19525          197 :     foreach(lc, func_args)
   19526              :     {
   19527          100 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19528              : 
   19529          100 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19530            0 :             p->mode != FUNC_PARAM_IN &&
   19531            0 :             p->mode != FUNC_PARAM_VARIADIC)
   19532            0 :             ereport(ERROR,
   19533              :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19534              :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19535              :                      parser_errposition(p->location)));
   19536              :     }
   19537              : 
   19538           97 :     return list_concat(func_args, columns);
   19539              : }
   19540              : 
   19541              : /*
   19542              :  * Determine return type of a TABLE function.  A single result column
   19543              :  * returns setof that column's type; otherwise return setof record.
   19544              :  */
   19545              : static TypeName *
   19546           97 : TableFuncTypeName(List *columns)
   19547              : {
   19548              :     TypeName   *result;
   19549              : 
   19550           97 :     if (list_length(columns) == 1)
   19551              :     {
   19552           31 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19553              : 
   19554           31 :         result = copyObject(p->argType);
   19555              :     }
   19556              :     else
   19557           66 :         result = SystemTypeName("record");
   19558              : 
   19559           97 :     result->setof = true;
   19560              : 
   19561           97 :     return result;
   19562              : }
   19563              : 
   19564              : /*
   19565              :  * Convert a list of (dotted) names to a RangeVar (like
   19566              :  * makeRangeVarFromNameList, but with position support).  The
   19567              :  * "AnyName" refers to the any_name production in the grammar.
   19568              :  */
   19569              : static RangeVar *
   19570         2371 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19571              : {
   19572         2371 :     RangeVar   *r = makeNode(RangeVar);
   19573              : 
   19574         2371 :     switch (list_length(names))
   19575              :     {
   19576         2326 :         case 1:
   19577         2326 :             r->catalogname = NULL;
   19578         2326 :             r->schemaname = NULL;
   19579         2326 :             r->relname = strVal(linitial(names));
   19580         2326 :             break;
   19581           45 :         case 2:
   19582           45 :             r->catalogname = NULL;
   19583           45 :             r->schemaname = strVal(linitial(names));
   19584           45 :             r->relname = strVal(lsecond(names));
   19585           45 :             break;
   19586            0 :         case 3:
   19587            0 :             r->catalogname = strVal(linitial(names));
   19588            0 :             r->schemaname = strVal(lsecond(names));
   19589            0 :             r->relname = strVal(lthird(names));
   19590            0 :             break;
   19591            0 :         default:
   19592            0 :             ereport(ERROR,
   19593              :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19594              :                      errmsg("improper qualified name (too many dotted names): %s",
   19595              :                             NameListToString(names)),
   19596              :                      parser_errposition(position)));
   19597              :             break;
   19598              :     }
   19599              : 
   19600         2371 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19601         2371 :     r->location = position;
   19602              : 
   19603         2371 :     return r;
   19604              : }
   19605              : 
   19606              : /*
   19607              :  * Convert a relation_name with name and namelist to a RangeVar using
   19608              :  * makeRangeVar.
   19609              :  */
   19610              : static RangeVar *
   19611       128381 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19612              :                               core_yyscan_t yyscanner)
   19613              : {
   19614              :     RangeVar   *r;
   19615              : 
   19616       128381 :     check_qualified_name(namelist, yyscanner);
   19617       128381 :     r = makeRangeVar(NULL, NULL, location);
   19618              : 
   19619       128381 :     switch (list_length(namelist))
   19620              :     {
   19621       128381 :         case 1:
   19622       128381 :             r->catalogname = NULL;
   19623       128381 :             r->schemaname = name;
   19624       128381 :             r->relname = strVal(linitial(namelist));
   19625       128381 :             break;
   19626            0 :         case 2:
   19627            0 :             r->catalogname = name;
   19628            0 :             r->schemaname = strVal(linitial(namelist));
   19629            0 :             r->relname = strVal(lsecond(namelist));
   19630            0 :             break;
   19631            0 :         default:
   19632            0 :             ereport(ERROR,
   19633              :                     errcode(ERRCODE_SYNTAX_ERROR),
   19634              :                     errmsg("improper qualified name (too many dotted names): %s",
   19635              :                            NameListToString(lcons(makeString(name), namelist))),
   19636              :                     parser_errposition(location));
   19637              :             break;
   19638              :     }
   19639              : 
   19640       128381 :     return r;
   19641              : }
   19642              : 
   19643              : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19644              : static void
   19645        36224 : SplitColQualList(List *qualList,
   19646              :                  List **constraintList, CollateClause **collClause,
   19647              :                  core_yyscan_t yyscanner)
   19648              : {
   19649              :     ListCell   *cell;
   19650              : 
   19651        36224 :     *collClause = NULL;
   19652        46619 :     foreach(cell, qualList)
   19653              :     {
   19654        10395 :         Node       *n = (Node *) lfirst(cell);
   19655              : 
   19656        10395 :         if (IsA(n, Constraint))
   19657              :         {
   19658              :             /* keep it in list */
   19659        10006 :             continue;
   19660              :         }
   19661          389 :         if (IsA(n, CollateClause))
   19662              :         {
   19663          389 :             CollateClause *c = (CollateClause *) n;
   19664              : 
   19665          389 :             if (*collClause)
   19666            0 :                 ereport(ERROR,
   19667              :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19668              :                          errmsg("multiple COLLATE clauses not allowed"),
   19669              :                          parser_errposition(c->location)));
   19670          389 :             *collClause = c;
   19671              :         }
   19672              :         else
   19673            0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19674              :         /* remove non-Constraint nodes from qualList */
   19675          389 :         qualList = foreach_delete_current(qualList, cell);
   19676              :     }
   19677        36224 :     *constraintList = qualList;
   19678        36224 : }
   19679              : 
   19680              : /*
   19681              :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19682              :  * in the output command node.  Pass NULL for any flags the particular
   19683              :  * command doesn't support.
   19684              :  */
   19685              : static void
   19686         9147 : processCASbits(int cas_bits, int location, const char *constrType,
   19687              :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19688              :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19689              : {
   19690              :     /* defaults */
   19691         9147 :     if (deferrable)
   19692         8044 :         *deferrable = false;
   19693         9147 :     if (initdeferred)
   19694         8044 :         *initdeferred = false;
   19695         9147 :     if (not_valid)
   19696         2022 :         *not_valid = false;
   19697         9147 :     if (is_enforced)
   19698         1773 :         *is_enforced = true;
   19699              : 
   19700         9147 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19701              :     {
   19702          115 :         if (deferrable)
   19703          115 :             *deferrable = true;
   19704              :         else
   19705            0 :             ereport(ERROR,
   19706              :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19707              :             /* translator: %s is CHECK, UNIQUE, or similar */
   19708              :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19709              :                             constrType),
   19710              :                      parser_errposition(location)));
   19711              :     }
   19712              : 
   19713         9147 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19714              :     {
   19715           73 :         if (initdeferred)
   19716           73 :             *initdeferred = true;
   19717              :         else
   19718            0 :             ereport(ERROR,
   19719              :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19720              :             /* translator: %s is CHECK, UNIQUE, or similar */
   19721              :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19722              :                             constrType),
   19723              :                      parser_errposition(location)));
   19724              :     }
   19725              : 
   19726         9147 :     if (cas_bits & CAS_NOT_VALID)
   19727              :     {
   19728          372 :         if (not_valid)
   19729          372 :             *not_valid = true;
   19730              :         else
   19731            0 :             ereport(ERROR,
   19732              :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19733              :             /* translator: %s is CHECK, UNIQUE, or similar */
   19734              :                      errmsg("%s constraints cannot be marked NOT VALID",
   19735              :                             constrType),
   19736              :                      parser_errposition(location)));
   19737              :     }
   19738              : 
   19739         9147 :     if (cas_bits & CAS_NO_INHERIT)
   19740              :     {
   19741          123 :         if (no_inherit)
   19742          123 :             *no_inherit = true;
   19743              :         else
   19744            0 :             ereport(ERROR,
   19745              :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19746              :             /* translator: %s is CHECK, UNIQUE, or similar */
   19747              :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19748              :                             constrType),
   19749              :                      parser_errposition(location)));
   19750              :     }
   19751              : 
   19752         9147 :     if (cas_bits & CAS_NOT_ENFORCED)
   19753              :     {
   19754           87 :         if (is_enforced)
   19755           84 :             *is_enforced = false;
   19756              :         else
   19757            3 :             ereport(ERROR,
   19758              :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19759              :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19760              :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19761              :                             constrType),
   19762              :                      parser_errposition(location)));
   19763              : 
   19764              :         /*
   19765              :          * NB: The validated status is irrelevant when the constraint is set to
   19766              :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19767              :          * This ensures that if the constraint is later changed to ENFORCED, it
   19768              :          * will automatically be in the correct NOT VALIDATED state.
   19769              :          */
   19770           84 :         if (not_valid)
   19771           66 :             *not_valid = true;
   19772              :     }
   19773              : 
   19774         9144 :     if (cas_bits & CAS_ENFORCED)
   19775              :     {
   19776           54 :         if (is_enforced)
   19777           51 :             *is_enforced = true;
   19778              :         else
   19779            3 :             ereport(ERROR,
   19780              :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19781              :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19782              :                      errmsg("%s constraints cannot be marked ENFORCED",
   19783              :                             constrType),
   19784              :                      parser_errposition(location)));
   19785              :     }
   19786         9141 : }
   19787              : 
   19788              : /*
   19789              :  * Parse a user-supplied partition strategy string into parse node
   19790              :  * PartitionStrategy representation, or die trying.
   19791              :  */
   19792              : static PartitionStrategy
   19793         2805 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19794              : {
   19795         2805 :     if (pg_strcasecmp(strategy, "list") == 0)
   19796         1314 :         return PARTITION_STRATEGY_LIST;
   19797         1491 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19798         1349 :         return PARTITION_STRATEGY_RANGE;
   19799          142 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19800          139 :         return PARTITION_STRATEGY_HASH;
   19801              : 
   19802            3 :     ereport(ERROR,
   19803              :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19804              :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19805              :              parser_errposition(location)));
   19806              :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19807              : 
   19808              : }
   19809              : 
   19810              : /*
   19811              :  * Process all_objects_list to set all_tables and/or all_sequences.
   19812              :  * Also, checks if the pub_object_type has been specified more than once.
   19813              :  */
   19814              : static void
   19815           69 : preprocess_pub_all_objtype_list(List *all_objects_list, bool *all_tables,
   19816              :                                 bool *all_sequences, core_yyscan_t yyscanner)
   19817              : {
   19818           69 :     if (!all_objects_list)
   19819            0 :         return;
   19820              : 
   19821           69 :     *all_tables = false;
   19822           69 :     *all_sequences = false;
   19823              : 
   19824          211 :     foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
   19825              :     {
   19826           85 :         if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
   19827              :         {
   19828           62 :             if (*all_tables)
   19829            3 :                 ereport(ERROR,
   19830              :                         errcode(ERRCODE_SYNTAX_ERROR),
   19831              :                         errmsg("invalid publication object list"),
   19832              :                         errdetail("ALL TABLES can be specified only once."),
   19833              :                         parser_errposition(obj->location));
   19834              : 
   19835           59 :             *all_tables = true;
   19836              :         }
   19837           23 :         else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
   19838              :         {
   19839           23 :             if (*all_sequences)
   19840            3 :                 ereport(ERROR,
   19841              :                     errcode(ERRCODE_SYNTAX_ERROR),
   19842              :                         errmsg("invalid publication object list"),
   19843              :                         errdetail("ALL SEQUENCES can be specified only once."),
   19844              :                         parser_errposition(obj->location));
   19845              : 
   19846           20 :             *all_sequences = true;
   19847              :         }
   19848              :     }
   19849              : }
   19850              : 
   19851              : /*
   19852              :  * Process pubobjspec_list to check for errors in any of the objects and
   19853              :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19854              :  */
   19855              : static void
   19856          825 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19857              : {
   19858              :     ListCell   *cell;
   19859              :     PublicationObjSpec *pubobj;
   19860          825 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19861              : 
   19862          825 :     if (!pubobjspec_list)
   19863            0 :         return;
   19864              : 
   19865          825 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19866          825 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19867            6 :         ereport(ERROR,
   19868              :                 errcode(ERRCODE_SYNTAX_ERROR),
   19869              :                 errmsg("invalid publication object list"),
   19870              :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19871              :                 parser_errposition(pubobj->location));
   19872              : 
   19873         1754 :     foreach(cell, pubobjspec_list)
   19874              :     {
   19875          947 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19876              : 
   19877          947 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19878           88 :             pubobj->pubobjtype = prevobjtype;
   19879              : 
   19880          947 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19881              :         {
   19882              :             /* relation name or pubtable must be set for this type of object */
   19883          725 :             if (!pubobj->name && !pubobj->pubtable)
   19884            3 :                 ereport(ERROR,
   19885              :                         errcode(ERRCODE_SYNTAX_ERROR),
   19886              :                         errmsg("invalid table name"),
   19887              :                         parser_errposition(pubobj->location));
   19888              : 
   19889          722 :             if (pubobj->name)
   19890              :             {
   19891              :                 /* convert it to PublicationTable */
   19892           30 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19893              : 
   19894           30 :                 pubtable->relation =
   19895           30 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19896           30 :                 pubobj->pubtable = pubtable;
   19897           30 :                 pubobj->name = NULL;
   19898              :             }
   19899              :         }
   19900          222 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19901           12 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19902              :         {
   19903              :             /* WHERE clause is not allowed on a schema object */
   19904          222 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19905            3 :                 ereport(ERROR,
   19906              :                         errcode(ERRCODE_SYNTAX_ERROR),
   19907              :                         errmsg("WHERE clause not allowed for schema"),
   19908              :                         parser_errposition(pubobj->location));
   19909              : 
   19910              :             /* Column list is not allowed on a schema object */
   19911          219 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19912            3 :                 ereport(ERROR,
   19913              :                         errcode(ERRCODE_SYNTAX_ERROR),
   19914              :                         errmsg("column specification not allowed for schema"),
   19915              :                         parser_errposition(pubobj->location));
   19916              : 
   19917              :             /*
   19918              :              * We can distinguish between the different type of schema objects
   19919              :              * based on whether name and pubtable is set.
   19920              :              */
   19921          216 :             if (pubobj->name)
   19922          201 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19923           15 :             else if (!pubobj->name && !pubobj->pubtable)
   19924           12 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19925              :             else
   19926            3 :                 ereport(ERROR,
   19927              :                         errcode(ERRCODE_SYNTAX_ERROR),
   19928              :                         errmsg("invalid schema name"),
   19929              :                         parser_errposition(pubobj->location));
   19930              :         }
   19931              : 
   19932          935 :         prevobjtype = pubobj->pubobjtype;
   19933              :     }
   19934              : }
   19935              : 
   19936              : /*----------
   19937              :  * Recursive view transformation
   19938              :  *
   19939              :  * Convert
   19940              :  *
   19941              :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19942              :  *
   19943              :  * to
   19944              :  *
   19945              :  *     CREATE VIEW relname (aliases) AS
   19946              :  *         WITH RECURSIVE relname (aliases) AS (query)
   19947              :  *         SELECT aliases FROM relname
   19948              :  *
   19949              :  * Actually, just the WITH ... part, which is then inserted into the original
   19950              :  * view definition as the query.
   19951              :  * ----------
   19952              :  */
   19953              : static Node *
   19954            7 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19955              : {
   19956            7 :     SelectStmt *s = makeNode(SelectStmt);
   19957            7 :     WithClause *w = makeNode(WithClause);
   19958            7 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19959            7 :     List       *tl = NIL;
   19960              :     ListCell   *lc;
   19961              : 
   19962              :     /* create common table expression */
   19963            7 :     cte->ctename = relname;
   19964            7 :     cte->aliascolnames = aliases;
   19965            7 :     cte->ctematerialized = CTEMaterializeDefault;
   19966            7 :     cte->ctequery = query;
   19967            7 :     cte->location = -1;
   19968              : 
   19969              :     /* create WITH clause and attach CTE */
   19970            7 :     w->recursive = true;
   19971            7 :     w->ctes = list_make1(cte);
   19972            7 :     w->location = -1;
   19973              : 
   19974              :     /*
   19975              :      * create target list for the new SELECT from the alias list of the
   19976              :      * recursive view specification
   19977              :      */
   19978           14 :     foreach(lc, aliases)
   19979              :     {
   19980            7 :         ResTarget  *rt = makeNode(ResTarget);
   19981              : 
   19982            7 :         rt->name = NULL;
   19983            7 :         rt->indirection = NIL;
   19984            7 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19985            7 :         rt->location = -1;
   19986              : 
   19987            7 :         tl = lappend(tl, rt);
   19988              :     }
   19989              : 
   19990              :     /*
   19991              :      * create new SELECT combining WITH clause, target list, and fake FROM
   19992              :      * clause
   19993              :      */
   19994            7 :     s->withClause = w;
   19995            7 :     s->targetList = tl;
   19996            7 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19997              : 
   19998            7 :     return (Node *) s;
   19999              : }
   20000              : 
   20001              : /* parser_init()
   20002              :  * Initialize to parse one query string
   20003              :  */
   20004              : void
   20005       409007 : parser_init(base_yy_extra_type *yyext)
   20006              : {
   20007       409007 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   20008       409007 : }
        

Generated by: LCOV version 2.0-1