LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 19devel Lines: 6883 7580 90.8 %
Date: 2026-01-14 06:18:51 Functions: 42 42 100.0 %
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
     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      751468 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     928             :                 (void) yynerrs;     /* suppress compiler warning */
     929             :             }
     930             :             | MODE_TYPE_NAME Typename
     931             :             {
     932       10256 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     933             :             }
     934             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     935             :             {
     936       34418 :                 pg_yyget_extra(yyscanner)->parsetree =
     937       34418 :                     list_make1(makeRawStmt($2, @2));
     938             :             }
     939             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     940             :             {
     941        6382 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     942             : 
     943        6382 :                 n->nnames = 1;
     944        6382 :                 pg_yyget_extra(yyscanner)->parsetree =
     945        6382 :                     list_make1(makeRawStmt((Node *) n, @2));
     946             :             }
     947             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     948             :             {
     949         686 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     950             : 
     951         686 :                 n->nnames = 2;
     952         686 :                 pg_yyget_extra(yyscanner)->parsetree =
     953         686 :                     list_make1(makeRawStmt((Node *) n, @2));
     954             :             }
     955             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     956             :             {
     957          28 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     958             : 
     959          28 :                 n->nnames = 3;
     960          28 :                 pg_yyget_extra(yyscanner)->parsetree =
     961          28 :                     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      618316 :                     if ($1 != NIL)
     974             :                     {
     975             :                         /* update length of previous stmt */
     976      617228 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     977             :                     }
     978      618316 :                     if ($3 != NULL)
     979       59136 :                         $$ = lappend($1, makeRawStmt($3, @3));
     980             :                     else
     981      559180 :                         $$ = $1;
     982             :                 }
     983             :             | toplevel_stmt
     984             :                 {
     985      751476 :                     if ($1 != NULL)
     986      749594 :                         $$ = list_make1(makeRawStmt($1, @1));
     987             :                     else
     988        1882 :                         $$ = 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      561078 :                 { $$ = NULL; }
    1129             :         ;
    1130             : 
    1131             : /*
    1132             :  * Generic supporting productions for DDL
    1133             :  */
    1134             : opt_single_name:
    1135        5514 :             ColId                           { $$ = $1; }
    1136        1590 :             | /* EMPTY */                   { $$ = NULL; }
    1137             :         ;
    1138             : 
    1139             : opt_qualified_name:
    1140        1994 :             any_name                        { $$ = $1; }
    1141       16124 :             | /*EMPTY*/                     { $$ = NIL; }
    1142             :         ;
    1143             : 
    1144             : opt_concurrently:
    1145        1102 :             CONCURRENTLY                    { $$ = true; }
    1146        7782 :             | /*EMPTY*/                     { $$ = false; }
    1147             :         ;
    1148             : 
    1149             : opt_drop_behavior:
    1150        2074 :             CASCADE                         { $$ = DROP_CASCADE; }
    1151         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1152       40556 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1153             :         ;
    1154             : 
    1155             : opt_utility_option_list:
    1156         366 :             '(' utility_option_list ')'     { $$ = $2; }
    1157        5970 :             | /* EMPTY */                   { $$ = NULL; }
    1158             :         ;
    1159             : 
    1160             : utility_option_list:
    1161             :             utility_option_elem
    1162             :                 {
    1163       23618 :                     $$ = list_make1($1);
    1164             :                 }
    1165             :             | utility_option_list ',' utility_option_elem
    1166             :                 {
    1167       13728 :                     $$ = lappend($1, $3);
    1168             :                 }
    1169             :         ;
    1170             : 
    1171             : utility_option_elem:
    1172             :             utility_option_name utility_option_arg
    1173             :                 {
    1174       37346 :                     $$ = makeDefElem($1, $2, @1);
    1175             :                 }
    1176             :         ;
    1177             : 
    1178             : utility_option_name:
    1179       33274 :             NonReservedWord                 { $$ = $1; }
    1180        3930 :             | analyze_keyword               { $$ = "analyze"; }
    1181         148 :             | FORMAT_LA                     { $$ = "format"; }
    1182             :         ;
    1183             : 
    1184             : utility_option_arg:
    1185       18510 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    1186         384 :             | NumericOnly                   { $$ = (Node *) $1; }
    1187       18452 :             | /* EMPTY */                   { $$ = NULL; }
    1188             :         ;
    1189             : 
    1190             : /*****************************************************************************
    1191             :  *
    1192             :  * CALL statement
    1193             :  *
    1194             :  *****************************************************************************/
    1195             : 
    1196             : CallStmt:   CALL func_application
    1197             :                 {
    1198         628 :                     CallStmt   *n = makeNode(CallStmt);
    1199             : 
    1200         628 :                     n->funccall = castNode(FuncCall, $2);
    1201         628 :                     $$ = (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        1418 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1215             : 
    1216        1418 :                     n->stmt_type = ROLESTMT_ROLE;
    1217        1418 :                     n->role = $3;
    1218        1418 :                     n->options = $5;
    1219        1418 :                     $$ = (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        1164 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1236        1900 :             | /* EMPTY */                           { $$ = NIL; }
    1237             :         ;
    1238             : 
    1239             : AlterOptRoleList:
    1240         784 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1241         436 :             | /* EMPTY */                           { $$ = NIL; }
    1242             :         ;
    1243             : 
    1244             : AlterOptRoleElem:
    1245             :             PASSWORD Sconst
    1246             :                 {
    1247         188 :                     $$ = makeDefElem("password",
    1248         188 :                                      (Node *) makeString($2), @1);
    1249             :                 }
    1250             :             | PASSWORD NULL_P
    1251             :                 {
    1252          12 :                     $$ = 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          16 :                     $$ = makeDefElem("password",
    1262          16 :                                      (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         110 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1275             :                 }
    1276             :             | CONNECTION LIMIT SignedIconst
    1277             :                 {
    1278          24 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1279             :                 }
    1280             :             | VALID UNTIL Sconst
    1281             :                 {
    1282           2 :                     $$ = 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           6 :                     $$ = 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        1442 :                     if (strcmp($1, "superuser") == 0)
    1297         194 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1298        1248 :                     else if (strcmp($1, "nosuperuser") == 0)
    1299         112 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1300        1136 :                     else if (strcmp($1, "createrole") == 0)
    1301         104 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1302        1032 :                     else if (strcmp($1, "nocreaterole") == 0)
    1303          50 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1304         982 :                     else if (strcmp($1, "replication") == 0)
    1305         132 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1306         850 :                     else if (strcmp($1, "noreplication") == 0)
    1307         108 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1308         742 :                     else if (strcmp($1, "createdb") == 0)
    1309          94 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1310         648 :                     else if (strcmp($1, "nocreatedb") == 0)
    1311          58 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1312         590 :                     else if (strcmp($1, "login") == 0)
    1313         288 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1314         302 :                     else if (strcmp($1, "nologin") == 0)
    1315         102 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1316         200 :                     else if (strcmp($1, "bypassrls") == 0)
    1317          84 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1318         116 :                     else if (strcmp($1, "nobypassrls") == 0)
    1319          80 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1320          36 :                     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          36 :                         $$ = 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        1016 :             AlterOptRoleElem            { $$ = $1; }
    1338             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1339             :             | SYSID Iconst
    1340             :                 {
    1341           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1342             :                 }
    1343             :             | ADMIN role_list
    1344             :                 {
    1345          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1346             :                 }
    1347             :             | ROLE role_list
    1348             :                 {
    1349          22 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1350             :                 }
    1351             :             | IN_P ROLE role_list
    1352             :                 {
    1353          98 :                     $$ = 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         458 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1372             : 
    1373         458 :                     n->stmt_type = ROLESTMT_USER;
    1374         458 :                     n->role = $3;
    1375         458 :                     n->options = $5;
    1376         458 :                     $$ = (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         344 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1391             : 
    1392         344 :                     n->role = $3;
    1393         344 :                     n->action = +1;  /* add, if there are members */
    1394         344 :                     n->options = $5;
    1395         344 :                     $$ = (Node *) n;
    1396             :                  }
    1397             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1398             :                  {
    1399          92 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1400             : 
    1401          92 :                     n->role = $3;
    1402          92 :                     n->action = +1;  /* add, if there are members */
    1403          92 :                     n->options = $5;
    1404          92 :                     $$ = (Node *) n;
    1405             :                  }
    1406             :         ;
    1407             : 
    1408             : opt_in_database:
    1409          94 :                /* EMPTY */                  { $$ = NULL; }
    1410           4 :             | IN_P DATABASE name    { $$ = $3; }
    1411             :         ;
    1412             : 
    1413             : AlterRoleSetStmt:
    1414             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1415             :                 {
    1416          58 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1417             : 
    1418          58 :                     n->role = $3;
    1419          58 :                     n->database = $4;
    1420          58 :                     n->setstmt = $5;
    1421          58 :                     $$ = (Node *) n;
    1422             :                 }
    1423             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1424             :                 {
    1425           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1426             : 
    1427           4 :                     n->role = NULL;
    1428           4 :                     n->database = $4;
    1429           4 :                     n->setstmt = $5;
    1430           4 :                     $$ = (Node *) n;
    1431             :                 }
    1432             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1433             :                 {
    1434          28 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1435             : 
    1436          28 :                     n->role = $3;
    1437          28 :                     n->database = $4;
    1438          28 :                     n->setstmt = $5;
    1439          28 :                     $$ = (Node *) n;
    1440             :                 }
    1441             :             | ALTER USER ALL opt_in_database SetResetClause
    1442             :                 {
    1443           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1444             : 
    1445           4 :                     n->role = NULL;
    1446           4 :                     n->database = $4;
    1447           4 :                     n->setstmt = $5;
    1448           4 :                     $$ = (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        1136 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1466             : 
    1467        1136 :                     n->missing_ok = false;
    1468        1136 :                     n->roles = $3;
    1469        1136 :                     $$ = (Node *) n;
    1470             :                 }
    1471             :             | DROP ROLE IF_P EXISTS role_list
    1472             :                 {
    1473         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1474             : 
    1475         134 :                     n->missing_ok = true;
    1476         134 :                     n->roles = $5;
    1477         134 :                     $$ = (Node *) n;
    1478             :                 }
    1479             :             | DROP USER role_list
    1480             :                 {
    1481         406 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1482             : 
    1483         406 :                     n->missing_ok = false;
    1484         406 :                     n->roles = $3;
    1485         406 :                     $$ = (Node *) n;
    1486             :                 }
    1487             :             | DROP USER IF_P EXISTS role_list
    1488             :                 {
    1489          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1490             : 
    1491          36 :                     n->roles = $5;
    1492          36 :                     n->missing_ok = true;
    1493          36 :                     $$ = (Node *) n;
    1494             :                 }
    1495             :             | DROP GROUP_P role_list
    1496             :                 {
    1497          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1498             : 
    1499          36 :                     n->missing_ok = false;
    1500          36 :                     n->roles = $3;
    1501          36 :                     $$ = (Node *) n;
    1502             :                 }
    1503             :             | DROP GROUP_P IF_P EXISTS role_list
    1504             :                 {
    1505           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1506             : 
    1507           6 :                     n->missing_ok = true;
    1508           6 :                     n->roles = $5;
    1509           6 :                     $$ = (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          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1524             : 
    1525          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1526          24 :                     n->role = $3;
    1527          24 :                     n->options = $5;
    1528          24 :                     $$ = (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          42 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1543             : 
    1544          42 :                     n->role = $3;
    1545          42 :                     n->action = $4;
    1546          42 :                     n->options = list_make1(makeDefElem("rolemembers",
    1547             :                                                         (Node *) $6, @6));
    1548          42 :                     $$ = (Node *) n;
    1549             :                 }
    1550             :         ;
    1551             : 
    1552          94 : add_drop:   ADD_P                                   { $$ = +1; }
    1553         224 :             | 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         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1567             : 
    1568             :                     /* One can omit the schema name or the authorization id. */
    1569         158 :                     n->schemaname = $3;
    1570         158 :                     n->authrole = $5;
    1571         158 :                     n->schemaElts = $6;
    1572         158 :                     n->if_not_exists = false;
    1573         158 :                     $$ = (Node *) n;
    1574             :                 }
    1575             :             | CREATE SCHEMA ColId OptSchemaEltList
    1576             :                 {
    1577         928 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1578             : 
    1579             :                     /* ...but not both */
    1580         928 :                     n->schemaname = $3;
    1581         928 :                     n->authrole = NULL;
    1582         928 :                     n->schemaElts = $4;
    1583         928 :                     n->if_not_exists = false;
    1584         928 :                     $$ = (Node *) n;
    1585             :                 }
    1586             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1587             :                 {
    1588          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1589             : 
    1590             :                     /* schema name can be omitted here, too */
    1591          18 :                     n->schemaname = $6;
    1592          18 :                     n->authrole = $8;
    1593          18 :                     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          18 :                     n->schemaElts = $9;
    1599          18 :                     n->if_not_exists = true;
    1600          18 :                     $$ = (Node *) n;
    1601             :                 }
    1602             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1603             :                 {
    1604          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1605             : 
    1606             :                     /* ...but not here */
    1607          34 :                     n->schemaname = $6;
    1608          34 :                     n->authrole = NULL;
    1609          34 :                     if ($7 != NIL)
    1610           6 :                         ereport(ERROR,
    1611             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1612             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1613             :                                  parser_errposition(@7)));
    1614          28 :                     n->schemaElts = $7;
    1615          28 :                     n->if_not_exists = true;
    1616          28 :                     $$ = (Node *) n;
    1617             :                 }
    1618             :         ;
    1619             : 
    1620             : OptSchemaEltList:
    1621             :             OptSchemaEltList schema_stmt
    1622             :                 {
    1623         586 :                     $$ = lappend($1, $2);
    1624             :                 }
    1625             :             | /* EMPTY */
    1626        1138 :                 { $$ = 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       22362 :                     VariableSetStmt *n = $2;
    1656             : 
    1657       22362 :                     n->is_local = false;
    1658       22362 :                     $$ = (Node *) n;
    1659             :                 }
    1660             :             | SET LOCAL set_rest
    1661             :                 {
    1662        1296 :                     VariableSetStmt *n = $3;
    1663             : 
    1664        1296 :                     n->is_local = true;
    1665        1296 :                     $$ = (Node *) n;
    1666             :                 }
    1667             :             | SET SESSION set_rest
    1668             :                 {
    1669          84 :                     VariableSetStmt *n = $3;
    1670             : 
    1671          84 :                     n->is_local = false;
    1672          84 :                     $$ = (Node *) n;
    1673             :                 }
    1674             :         ;
    1675             : 
    1676             : set_rest:
    1677             :             TRANSACTION transaction_mode_list
    1678             :                 {
    1679         586 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1680             : 
    1681         586 :                     n->kind = VAR_SET_MULTI;
    1682         586 :                     n->name = "TRANSACTION";
    1683         586 :                     n->args = $2;
    1684         586 :                     n->jumble_args = true;
    1685         586 :                     n->location = -1;
    1686         586 :                     $$ = n;
    1687             :                 }
    1688             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1689             :                 {
    1690          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1691             : 
    1692          18 :                     n->kind = VAR_SET_MULTI;
    1693          18 :                     n->name = "SESSION CHARACTERISTICS";
    1694          18 :                     n->args = $5;
    1695          18 :                     n->jumble_args = true;
    1696          18 :                     n->location = -1;
    1697          18 :                     $$ = n;
    1698             :                 }
    1699             :             | set_rest_more
    1700             :             ;
    1701             : 
    1702             : generic_set:
    1703             :             var_name TO var_list
    1704             :                 {
    1705        5240 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1706             : 
    1707        5240 :                     n->kind = VAR_SET_VALUE;
    1708        5240 :                     n->name = $1;
    1709        5240 :                     n->args = $3;
    1710        5240 :                     n->location = @3;
    1711        5240 :                     $$ = n;
    1712             :                 }
    1713             :             | var_name '=' var_list
    1714             :                 {
    1715       15478 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1716             : 
    1717       15478 :                     n->kind = VAR_SET_VALUE;
    1718       15478 :                     n->name = $1;
    1719       15478 :                     n->args = $3;
    1720       15478 :                     n->location = @3;
    1721       15478 :                     $$ = n;
    1722             :                 }
    1723             :             | var_name TO NULL_P
    1724             :                 {
    1725           8 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1726             : 
    1727           8 :                     n->kind = VAR_SET_VALUE;
    1728           8 :                     n->name = $1;
    1729           8 :                     n->args = list_make1(makeNullAConst(@3));
    1730           8 :                     n->location = @3;
    1731           8 :                     $$ = n;
    1732             :                 }
    1733             :             | var_name '=' NULL_P
    1734             :                 {
    1735          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1736             : 
    1737          18 :                     n->kind = VAR_SET_VALUE;
    1738          18 :                     n->name = $1;
    1739          18 :                     n->args = list_make1(makeNullAConst(@3));
    1740          18 :                     n->location = @3;
    1741          18 :                     $$ = n;
    1742             :                 }
    1743             :             | var_name TO DEFAULT
    1744             :                 {
    1745         136 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1746             : 
    1747         136 :                     n->kind = VAR_SET_DEFAULT;
    1748         136 :                     n->name = $1;
    1749         136 :                     n->location = -1;
    1750         136 :                     $$ = n;
    1751             :                 }
    1752             :             | var_name '=' DEFAULT
    1753             :                 {
    1754          10 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1755             : 
    1756          10 :                     n->kind = VAR_SET_DEFAULT;
    1757          10 :                     n->name = $1;
    1758          10 :                     n->location = -1;
    1759          10 :                     $$ = n;
    1760             :                 }
    1761             :         ;
    1762             : 
    1763             : set_rest_more:  /* Generic SET syntaxes: */
    1764       20742 :             generic_set                         {$$ = $1;}
    1765             :             | var_name FROM CURRENT_P
    1766             :                 {
    1767           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1768             : 
    1769           4 :                     n->kind = VAR_SET_CURRENT;
    1770           4 :                     n->name = $1;
    1771           4 :                     n->location = -1;
    1772           4 :                     $$ = n;
    1773             :                 }
    1774             :             /* Special syntaxes mandated by SQL standard: */
    1775             :             | TIME ZONE zone_value
    1776             :                 {
    1777         104 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1778             : 
    1779         104 :                     n->kind = VAR_SET_VALUE;
    1780         104 :                     n->name = "timezone";
    1781         104 :                     n->location = -1;
    1782         104 :                     n->jumble_args = true;
    1783         104 :                     if ($3 != NULL)
    1784          88 :                         n->args = list_make1($3);
    1785             :                     else
    1786          16 :                         n->kind = VAR_SET_DEFAULT;
    1787         104 :                     $$ = 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           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1800             : 
    1801           4 :                     n->kind = VAR_SET_VALUE;
    1802           4 :                     n->name = "search_path";
    1803           4 :                     n->args = list_make1(makeStringConst($2, @2));
    1804           4 :                     n->location = @2;
    1805           4 :                     $$ = 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         974 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1823             : 
    1824         974 :                     n->kind = VAR_SET_VALUE;
    1825         974 :                     n->name = "role";
    1826         974 :                     n->args = list_make1(makeStringConst($2, @2));
    1827         974 :                     n->location = @2;
    1828         974 :                     $$ = n;
    1829             :                 }
    1830             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1831             :                 {
    1832        2694 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1833             : 
    1834        2694 :                     n->kind = VAR_SET_VALUE;
    1835        2694 :                     n->name = "session_authorization";
    1836        2694 :                     n->args = list_make1(makeStringConst($3, @3));
    1837        2694 :                     n->location = @3;
    1838        2694 :                     $$ = n;
    1839             :                 }
    1840             :             | SESSION AUTHORIZATION DEFAULT
    1841             :                 {
    1842           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1843             : 
    1844           4 :                     n->kind = VAR_SET_DEFAULT;
    1845           4 :                     n->name = "session_authorization";
    1846           4 :                     n->location = -1;
    1847           4 :                     $$ = n;
    1848             :                 }
    1849             :             | XML_P OPTION document_or_content
    1850             :                 {
    1851          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1852             : 
    1853          16 :                     n->kind = VAR_SET_VALUE;
    1854          16 :                     n->name = "xmloption";
    1855          16 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1856          16 :                     n->jumble_args = true;
    1857          16 :                     n->location = -1;
    1858          16 :                     $$ = n;
    1859             :                 }
    1860             :             /* Special syntaxes invented by PostgreSQL: */
    1861             :             | TRANSACTION SNAPSHOT Sconst
    1862             :                 {
    1863          44 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1864             : 
    1865          44 :                     n->kind = VAR_SET_MULTI;
    1866          44 :                     n->name = "TRANSACTION SNAPSHOT";
    1867          44 :                     n->args = list_make1(makeStringConst($3, @3));
    1868          44 :                     n->location = @3;
    1869          44 :                     $$ = n;
    1870             :                 }
    1871             :         ;
    1872             : 
    1873       25828 : var_name:   ColId                               { $$ = $1; }
    1874             :             | var_name '.' ColId
    1875         496 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1876             :         ;
    1877             : 
    1878       20718 : var_list:   var_value                               { $$ = list_make1($1); }
    1879         302 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1880             :         ;
    1881             : 
    1882             : var_value:  opt_boolean_or_string
    1883       15574 :                 { $$ = makeStringConst($1, @1); }
    1884             :             | NumericOnly
    1885        5446 :                 { $$ = makeAConst($1, @1); }
    1886             :         ;
    1887             : 
    1888           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1889        1028 :             | READ COMMITTED                        { $$ = "read committed"; }
    1890        2688 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1891        3252 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1892             :         ;
    1893             : 
    1894             : opt_boolean_or_string:
    1895         716 :             TRUE_P                                  { $$ = "true"; }
    1896        1508 :             | FALSE_P                               { $$ = "false"; }
    1897        2278 :             | 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       31998 :             | 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          60 :                     $$ = makeStringConst($1, @1);
    1918             :                 }
    1919             :             | IDENT
    1920             :                 {
    1921           4 :                     $$ = 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          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1949          14 :             | DEFAULT                               { $$ = NULL; }
    1950           2 :             | 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       55926 :             NonReservedWord                         { $$ = $1; }
    1961        5924 :             | Sconst                                { $$ = $1; }
    1962             :         ;
    1963             : 
    1964             : VariableResetStmt:
    1965        4914 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1966             :         ;
    1967             : 
    1968             : reset_rest:
    1969        4020 :             generic_reset                           { $$ = $1; }
    1970             :             | TIME ZONE
    1971             :                 {
    1972          14 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1973             : 
    1974          14 :                     n->kind = VAR_RESET;
    1975          14 :                     n->name = "timezone";
    1976          14 :                     n->location = -1;
    1977          14 :                     $$ = 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         880 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1991             : 
    1992         880 :                     n->kind = VAR_RESET;
    1993         880 :                     n->name = "session_authorization";
    1994         880 :                     n->location = -1;
    1995         880 :                     $$ = n;
    1996             :                 }
    1997             :         ;
    1998             : 
    1999             : generic_reset:
    2000             :             var_name
    2001             :                 {
    2002        4050 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    2003             : 
    2004        4050 :                     n->kind = VAR_RESET;
    2005        4050 :                     n->name = $1;
    2006        4050 :                     n->location = -1;
    2007        4050 :                     $$ = n;
    2008             :                 }
    2009             :             | ALL
    2010             :                 {
    2011          28 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    2012             : 
    2013          28 :                     n->kind = VAR_RESET_ALL;
    2014          28 :                     n->location = -1;
    2015          28 :                     $$ = n;
    2016             :                 }
    2017             :         ;
    2018             : 
    2019             : /* SetResetClause allows SET or RESET without LOCAL */
    2020             : SetResetClause:
    2021        1306 :             SET set_rest                    { $$ = $2; }
    2022          42 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    2023             :         ;
    2024             : 
    2025             : /* SetResetClause allows SET or RESET without LOCAL */
    2026             : FunctionSetResetClause:
    2027         142 :             SET set_rest_more               { $$ = $2; }
    2028          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    2029             :         ;
    2030             : 
    2031             : 
    2032             : VariableShowStmt:
    2033             :             SHOW var_name
    2034             :                 {
    2035         884 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2036             : 
    2037         884 :                     n->name = $2;
    2038         884 :                     $$ = (Node *) n;
    2039             :                 }
    2040             :             | SHOW TIME ZONE
    2041             :                 {
    2042          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2043             : 
    2044          10 :                     n->name = "timezone";
    2045          10 :                     $$ = (Node *) n;
    2046             :                 }
    2047             :             | SHOW TRANSACTION ISOLATION LEVEL
    2048             :                 {
    2049           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2050             : 
    2051           4 :                     n->name = "transaction_isolation";
    2052           4 :                     $$ = (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         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2075             : 
    2076         104 :                     n->constraints = $3;
    2077         104 :                     n->deferred = $4;
    2078         104 :                     $$ = (Node *) n;
    2079             :                 }
    2080             :         ;
    2081             : 
    2082             : constraints_set_list:
    2083          56 :             ALL                                     { $$ = NIL; }
    2084          48 :             | qualified_name_list                   { $$ = $1; }
    2085             :         ;
    2086             : 
    2087             : constraints_set_mode:
    2088          68 :             DEFERRED                                { $$ = true; }
    2089          36 :             | IMMEDIATE                             { $$ = false; }
    2090             :         ;
    2091             : 
    2092             : 
    2093             : /*
    2094             :  * Checkpoint statement
    2095             :  */
    2096             : CheckPointStmt:
    2097             :             CHECKPOINT opt_utility_option_list
    2098             :                 {
    2099         248 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2100             : 
    2101         248 :                     $$ = (Node *) n;
    2102         248 :                     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           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2117             : 
    2118           6 :                     n->target = DISCARD_ALL;
    2119           6 :                     $$ = (Node *) n;
    2120             :                 }
    2121             :             | DISCARD TEMP
    2122             :                 {
    2123          14 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2124             : 
    2125          14 :                     n->target = DISCARD_TEMP;
    2126          14 :                     $$ = (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           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2138             : 
    2139           4 :                     n->target = DISCARD_PLANS;
    2140           4 :                     $$ = (Node *) n;
    2141             :                 }
    2142             :             | DISCARD SEQUENCES
    2143             :                 {
    2144          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2145             : 
    2146          12 :                     n->target = DISCARD_SEQUENCES;
    2147          12 :                     $$ = (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       26944 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2165             : 
    2166       26944 :                     n->relation = $3;
    2167       26944 :                     n->cmds = $4;
    2168       26944 :                     n->objtype = OBJECT_TABLE;
    2169       26944 :                     n->missing_ok = false;
    2170       26944 :                     $$ = (Node *) n;
    2171             :                 }
    2172             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2173             :                 {
    2174          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2175             : 
    2176          54 :                     n->relation = $5;
    2177          54 :                     n->cmds = $6;
    2178          54 :                     n->objtype = OBJECT_TABLE;
    2179          54 :                     n->missing_ok = true;
    2180          54 :                     $$ = (Node *) n;
    2181             :                 }
    2182             :         |   ALTER TABLE relation_expr partition_cmd
    2183             :                 {
    2184        3848 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2185             : 
    2186        3848 :                     n->relation = $3;
    2187        3848 :                     n->cmds = list_make1($4);
    2188        3848 :                     n->objtype = OBJECT_TABLE;
    2189        3848 :                     n->missing_ok = false;
    2190        3848 :                     $$ = (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          12 :                         makeNode(AlterTableMoveAllStmt);
    2206             : 
    2207          12 :                     n->orig_tablespacename = $6;
    2208          12 :                     n->objtype = OBJECT_TABLE;
    2209          12 :                     n->roles = NIL;
    2210          12 :                     n->new_tablespacename = $9;
    2211          12 :                     n->nowait = $10;
    2212          12 :                     $$ = (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         228 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2229             : 
    2230         228 :                     n->relation = $3;
    2231         228 :                     n->cmds = $4;
    2232         228 :                     n->objtype = OBJECT_INDEX;
    2233         228 :                     n->missing_ok = false;
    2234         228 :                     $$ = (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         390 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2249             : 
    2250         390 :                     n->relation = $3;
    2251         390 :                     n->cmds = list_make1($4);
    2252         390 :                     n->objtype = OBJECT_INDEX;
    2253         390 :                     n->missing_ok = false;
    2254         390 :                     $$ = (Node *) n;
    2255             :                 }
    2256             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2257             :                 {
    2258             :                     AlterTableMoveAllStmt *n =
    2259           6 :                         makeNode(AlterTableMoveAllStmt);
    2260             : 
    2261           6 :                     n->orig_tablespacename = $6;
    2262           6 :                     n->objtype = OBJECT_INDEX;
    2263           6 :                     n->roles = NIL;
    2264           6 :                     n->new_tablespacename = $9;
    2265           6 :                     n->nowait = $10;
    2266           6 :                     $$ = (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          94 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2283             : 
    2284          94 :                     n->relation = $3;
    2285          94 :                     n->cmds = $4;
    2286          94 :                     n->objtype = OBJECT_SEQUENCE;
    2287          94 :                     n->missing_ok = false;
    2288          94 :                     $$ = (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         254 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2303             : 
    2304         254 :                     n->relation = $3;
    2305         254 :                     n->cmds = $4;
    2306         254 :                     n->objtype = OBJECT_VIEW;
    2307         254 :                     n->missing_ok = false;
    2308         254 :                     $$ = (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          48 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2323             : 
    2324          48 :                     n->relation = $4;
    2325          48 :                     n->cmds = $5;
    2326          48 :                     n->objtype = OBJECT_MATVIEW;
    2327          48 :                     n->missing_ok = false;
    2328          48 :                     $$ = (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          12 :                         makeNode(AlterTableMoveAllStmt);
    2344             : 
    2345          12 :                     n->orig_tablespacename = $7;
    2346          12 :                     n->objtype = OBJECT_MATVIEW;
    2347          12 :                     n->roles = NIL;
    2348          12 :                     n->new_tablespacename = $10;
    2349          12 :                     n->nowait = $11;
    2350          12 :                     $$ = (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         378 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2367             : 
    2368         378 :                     n->relation = $4;
    2369         378 :                     n->cmds = $5;
    2370         378 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2371         378 :                     n->missing_ok = false;
    2372         378 :                     $$ = (Node *) n;
    2373             :                 }
    2374             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2375             :                 {
    2376         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2377             : 
    2378         108 :                     n->relation = $6;
    2379         108 :                     n->cmds = $7;
    2380         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2381         108 :                     n->missing_ok = true;
    2382         108 :                     $$ = (Node *) n;
    2383             :                 }
    2384             :         ;
    2385             : 
    2386             : alter_table_cmds:
    2387       28108 :             alter_table_cmd                         { $$ = list_make1($1); }
    2388        1020 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2389             :         ;
    2390             : 
    2391             : partitions_list:
    2392         390 :             SinglePartitionSpec                         { $$ = list_make1($1); }
    2393         714 :             | partitions_list ',' SinglePartitionSpec   { $$ = lappend($1, $3); }
    2394             :         ;
    2395             : 
    2396             : SinglePartitionSpec:
    2397             :             PARTITION qualified_name PartitionBoundSpec
    2398             :                 {
    2399        1104 :                     SinglePartitionSpec *n = makeNode(SinglePartitionSpec);
    2400             : 
    2401        1104 :                     n->name = $2;
    2402        1104 :                     n->bound = $3;
    2403             : 
    2404        1104 :                     $$ = 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        2560 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2413        2560 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2414             : 
    2415        2560 :                     n->subtype = AT_AttachPartition;
    2416        2560 :                     cmd->name = $3;
    2417        2560 :                     cmd->bound = $4;
    2418        2560 :                     cmd->partlist = NIL;
    2419        2560 :                     cmd->concurrent = false;
    2420        2560 :                     n->def = (Node *) cmd;
    2421             : 
    2422        2560 :                     $$ = (Node *) n;
    2423             :                 }
    2424             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2425             :             | DETACH PARTITION qualified_name opt_concurrently
    2426             :                 {
    2427         608 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2428         608 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2429             : 
    2430         608 :                     n->subtype = AT_DetachPartition;
    2431         608 :                     cmd->name = $3;
    2432         608 :                     cmd->bound = NULL;
    2433         608 :                     cmd->partlist = NIL;
    2434         608 :                     cmd->concurrent = $4;
    2435         608 :                     n->def = (Node *) cmd;
    2436             : 
    2437         608 :                     $$ = (Node *) n;
    2438             :                 }
    2439             :             | DETACH PARTITION qualified_name FINALIZE
    2440             :                 {
    2441          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2442          20 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2443             : 
    2444          20 :                     n->subtype = AT_DetachPartitionFinalize;
    2445          20 :                     cmd->name = $3;
    2446          20 :                     cmd->bound = NULL;
    2447          20 :                     cmd->partlist = NIL;
    2448          20 :                     cmd->concurrent = false;
    2449          20 :                     n->def = (Node *) cmd;
    2450          20 :                     $$ = (Node *) n;
    2451             :                 }
    2452             :             /* ALTER TABLE <name> SPLIT PARTITION <partition_name> INTO () */
    2453             :             | SPLIT PARTITION qualified_name INTO '(' partitions_list ')'
    2454             :                 {
    2455         390 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2456         390 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2457             : 
    2458         390 :                     n->subtype = AT_SplitPartition;
    2459         390 :                     cmd->name = $3;
    2460         390 :                     cmd->bound = NULL;
    2461         390 :                     cmd->partlist = $6;
    2462         390 :                     cmd->concurrent = false;
    2463         390 :                     n->def = (Node *) cmd;
    2464         390 :                     $$ = (Node *) n;
    2465             :                 }
    2466             :             /* ALTER TABLE <name> MERGE PARTITIONS () INTO <partition_name> */
    2467             :             | MERGE PARTITIONS '(' qualified_name_list ')' INTO qualified_name
    2468             :                 {
    2469         270 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2470         270 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2471             : 
    2472         270 :                     n->subtype = AT_MergePartitions;
    2473         270 :                     cmd->name = $7;
    2474         270 :                     cmd->bound = NULL;
    2475         270 :                     cmd->partlist = $4;
    2476         270 :                     cmd->concurrent = false;
    2477         270 :                     n->def = (Node *) cmd;
    2478         270 :                     $$ = (Node *) n;
    2479             :                 }
    2480             :         ;
    2481             : 
    2482             : index_partition_cmd:
    2483             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2484             :             ATTACH PARTITION qualified_name
    2485             :                 {
    2486         390 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2487         390 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2488             : 
    2489         390 :                     n->subtype = AT_AttachPartition;
    2490         390 :                     cmd->name = $3;
    2491         390 :                     cmd->bound = NULL;
    2492         390 :                     cmd->partlist = NIL;
    2493         390 :                     cmd->concurrent = false;
    2494         390 :                     n->def = (Node *) cmd;
    2495             : 
    2496         390 :                     $$ = (Node *) n;
    2497             :                 }
    2498             :         ;
    2499             : 
    2500             : alter_table_cmd:
    2501             :             /* ALTER TABLE <name> ADD <coldef> */
    2502             :             ADD_P columnDef
    2503             :                 {
    2504         192 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2505             : 
    2506         192 :                     n->subtype = AT_AddColumn;
    2507         192 :                     n->def = $2;
    2508         192 :                     n->missing_ok = false;
    2509         192 :                     $$ = (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        1922 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2525             : 
    2526        1922 :                     n->subtype = AT_AddColumn;
    2527        1922 :                     n->def = $3;
    2528        1922 :                     n->missing_ok = false;
    2529        1922 :                     $$ = (Node *) n;
    2530             :                 }
    2531             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2532             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2533             :                 {
    2534          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2535             : 
    2536          60 :                     n->subtype = AT_AddColumn;
    2537          60 :                     n->def = $6;
    2538          60 :                     n->missing_ok = true;
    2539          60 :                     $$ = (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         550 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2545             : 
    2546         550 :                     n->subtype = AT_ColumnDefault;
    2547         550 :                     n->name = $3;
    2548         550 :                     n->def = $4;
    2549         550 :                     $$ = (Node *) n;
    2550             :                 }
    2551             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2552             :             | ALTER opt_column ColId DROP NOT NULL_P
    2553             :                 {
    2554         294 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2555             : 
    2556         294 :                     n->subtype = AT_DropNotNull;
    2557         294 :                     n->name = $3;
    2558         294 :                     $$ = (Node *) n;
    2559             :                 }
    2560             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2561             :             | ALTER opt_column ColId SET NOT NULL_P
    2562             :                 {
    2563         440 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2564             : 
    2565         440 :                     n->subtype = AT_SetNotNull;
    2566         440 :                     n->name = $3;
    2567         440 :                     $$ = (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         176 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2573             : 
    2574         176 :                     n->subtype = AT_SetExpression;
    2575         176 :                     n->name = $3;
    2576         176 :                     n->def = $8;
    2577         176 :                     $$ = (Node *) n;
    2578             :                 }
    2579             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2580             :             | ALTER opt_column ColId DROP EXPRESSION
    2581             :                 {
    2582          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2583             : 
    2584          62 :                     n->subtype = AT_DropExpression;
    2585          62 :                     n->name = $3;
    2586          62 :                     $$ = (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          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2592             : 
    2593          12 :                     n->subtype = AT_DropExpression;
    2594          12 :                     n->name = $3;
    2595          12 :                     n->missing_ok = true;
    2596          12 :                     $$ = (Node *) n;
    2597             :                 }
    2598             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2599             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2600             :                 {
    2601          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2602             : 
    2603          62 :                     n->subtype = AT_SetStatistics;
    2604          62 :                     n->name = $3;
    2605          62 :                     n->def = $6;
    2606          62 :                     $$ = (Node *) n;
    2607             :                 }
    2608             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2609             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2610             :                 {
    2611          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2612             : 
    2613          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2614           6 :                         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          64 :                     n->subtype = AT_SetStatistics;
    2620          64 :                     n->num = (int16) $3;
    2621          64 :                     n->def = $6;
    2622          64 :                     $$ = (Node *) n;
    2623             :                 }
    2624             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2625             :             | ALTER opt_column ColId SET reloptions
    2626             :                 {
    2627          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2628             : 
    2629          38 :                     n->subtype = AT_SetOptions;
    2630          38 :                     n->name = $3;
    2631          38 :                     n->def = (Node *) $5;
    2632          38 :                     $$ = (Node *) n;
    2633             :                 }
    2634             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2635             :             | ALTER opt_column ColId RESET reloptions
    2636             :                 {
    2637           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2638             : 
    2639           6 :                     n->subtype = AT_ResetOptions;
    2640           6 :                     n->name = $3;
    2641           6 :                     n->def = (Node *) $5;
    2642           6 :                     $$ = (Node *) n;
    2643             :                 }
    2644             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2645             :             | ALTER opt_column ColId SET column_storage
    2646             :                 {
    2647         238 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2648             : 
    2649         238 :                     n->subtype = AT_SetStorage;
    2650         238 :                     n->name = $3;
    2651         238 :                     n->def = (Node *) makeString($5);
    2652         238 :                     $$ = (Node *) n;
    2653             :                 }
    2654             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2655             :             | ALTER opt_column ColId SET column_compression
    2656             :                 {
    2657          78 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2658             : 
    2659          78 :                     n->subtype = AT_SetCompression;
    2660          78 :                     n->name = $3;
    2661          78 :                     n->def = (Node *) makeString($5);
    2662          78 :                     $$ = (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         172 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2668         172 :                     Constraint *c = makeNode(Constraint);
    2669             : 
    2670         172 :                     c->contype = CONSTR_IDENTITY;
    2671         172 :                     c->generated_when = $6;
    2672         172 :                     c->options = $9;
    2673         172 :                     c->location = @5;
    2674             : 
    2675         172 :                     n->subtype = AT_AddIdentity;
    2676         172 :                     n->name = $3;
    2677         172 :                     n->def = (Node *) c;
    2678             : 
    2679         172 :                     $$ = (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          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2685             : 
    2686          62 :                     n->subtype = AT_SetIdentity;
    2687          62 :                     n->name = $3;
    2688          62 :                     n->def = (Node *) $4;
    2689          62 :                     $$ = (Node *) n;
    2690             :                 }
    2691             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2692             :             | ALTER opt_column ColId DROP IDENTITY_P
    2693             :                 {
    2694          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2695             : 
    2696          50 :                     n->subtype = AT_DropIdentity;
    2697          50 :                     n->name = $3;
    2698          50 :                     n->missing_ok = false;
    2699          50 :                     $$ = (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           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2705             : 
    2706           6 :                     n->subtype = AT_DropIdentity;
    2707           6 :                     n->name = $3;
    2708           6 :                     n->missing_ok = true;
    2709           6 :                     $$ = (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          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2715             : 
    2716          18 :                     n->subtype = AT_DropColumn;
    2717          18 :                     n->name = $5;
    2718          18 :                     n->behavior = $6;
    2719          18 :                     n->missing_ok = true;
    2720          18 :                     $$ = (Node *) n;
    2721             :                 }
    2722             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2723             :             | DROP opt_column ColId opt_drop_behavior
    2724             :                 {
    2725        1616 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2726             : 
    2727        1616 :                     n->subtype = AT_DropColumn;
    2728        1616 :                     n->name = $3;
    2729        1616 :                     n->behavior = $4;
    2730        1616 :                     n->missing_ok = false;
    2731        1616 :                     $$ = (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        1138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2740        1138 :                     ColumnDef *def = makeNode(ColumnDef);
    2741             : 
    2742        1138 :                     n->subtype = AT_AlterColumnType;
    2743        1138 :                     n->name = $3;
    2744        1138 :                     n->def = (Node *) def;
    2745             :                     /* We only use these fields of the ColumnDef node */
    2746        1138 :                     def->typeName = $6;
    2747        1138 :                     def->collClause = (CollateClause *) $7;
    2748        1138 :                     def->raw_default = $8;
    2749        1138 :                     def->location = @3;
    2750        1138 :                     $$ = (Node *) n;
    2751             :                 }
    2752             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2753             :             | ALTER opt_column ColId alter_generic_options
    2754             :                 {
    2755          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2756             : 
    2757          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2758          50 :                     n->name = $3;
    2759          50 :                     n->def = (Node *) $4;
    2760          50 :                     $$ = (Node *) n;
    2761             :                 }
    2762             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2763             :             | ADD_P TableConstraint
    2764             :                 {
    2765       14872 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2766             : 
    2767       14872 :                     n->subtype = AT_AddConstraint;
    2768       14872 :                     n->def = $2;
    2769       14872 :                     $$ = (Node *) n;
    2770             :                 }
    2771             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2772             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2773             :                 {
    2774         246 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2775         246 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2776             : 
    2777         246 :                     n->subtype = AT_AlterConstraint;
    2778         246 :                     n->def = (Node *) c;
    2779         246 :                     c->conname = $3;
    2780         246 :                     if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
    2781          90 :                         c->alterEnforceability = true;
    2782         246 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2783             :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2784         120 :                         c->alterDeferrability = true;
    2785         246 :                     if ($4 & CAS_NO_INHERIT)
    2786          30 :                         c->alterInheritability = true;
    2787             :                     /* handle unsupported case with specific error message */
    2788         246 :                     if ($4 & CAS_NOT_VALID)
    2789          12 :                         ereport(ERROR,
    2790             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    2791             :                                 errmsg("constraints cannot be altered to be NOT VALID"),
    2792             :                                 parser_errposition(@4));
    2793         234 :                     processCASbits($4, @4, "FOREIGN KEY",
    2794             :                                     &c->deferrable,
    2795             :                                     &c->initdeferred,
    2796             :                                     &c->is_enforced,
    2797             :                                     NULL,
    2798             :                                     &c->noinherit,
    2799             :                                     yyscanner);
    2800         234 :                     $$ = (Node *) n;
    2801             :                 }
    2802             :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2803             :             | ALTER CONSTRAINT name INHERIT
    2804             :                 {
    2805          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2806          66 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2807             : 
    2808          66 :                     n->subtype = AT_AlterConstraint;
    2809          66 :                     n->def = (Node *) c;
    2810          66 :                     c->conname = $3;
    2811          66 :                     c->alterInheritability = true;
    2812          66 :                     c->noinherit = false;
    2813             : 
    2814          66 :                     $$ = (Node *) n;
    2815             :                 }
    2816             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2817             :             | VALIDATE CONSTRAINT name
    2818             :                 {
    2819         482 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2820             : 
    2821         482 :                     n->subtype = AT_ValidateConstraint;
    2822         482 :                     n->name = $3;
    2823         482 :                     $$ = (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          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2829             : 
    2830          18 :                     n->subtype = AT_DropConstraint;
    2831          18 :                     n->name = $5;
    2832          18 :                     n->behavior = $6;
    2833          18 :                     n->missing_ok = true;
    2834          18 :                     $$ = (Node *) n;
    2835             :                 }
    2836             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2837             :             | DROP CONSTRAINT name opt_drop_behavior
    2838             :                 {
    2839         818 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2840             : 
    2841         818 :                     n->subtype = AT_DropConstraint;
    2842         818 :                     n->name = $3;
    2843         818 :                     n->behavior = $4;
    2844         818 :                     n->missing_ok = false;
    2845         818 :                     $$ = (Node *) n;
    2846             :                 }
    2847             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2848             :             | SET WITHOUT OIDS
    2849             :                 {
    2850           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2851             : 
    2852           6 :                     n->subtype = AT_DropOids;
    2853           6 :                     $$ = (Node *) n;
    2854             :                 }
    2855             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2856             :             | CLUSTER ON name
    2857             :                 {
    2858          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2859             : 
    2860          46 :                     n->subtype = AT_ClusterOn;
    2861          46 :                     n->name = $3;
    2862          46 :                     $$ = (Node *) n;
    2863             :                 }
    2864             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2865             :             | SET WITHOUT CLUSTER
    2866             :                 {
    2867          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2868             : 
    2869          18 :                     n->subtype = AT_DropCluster;
    2870          18 :                     n->name = NULL;
    2871          18 :                     $$ = (Node *) n;
    2872             :                 }
    2873             :             /* ALTER TABLE <name> SET LOGGED */
    2874             :             | SET LOGGED
    2875             :                 {
    2876          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2877             : 
    2878          50 :                     n->subtype = AT_SetLogged;
    2879          50 :                     $$ = (Node *) n;
    2880             :                 }
    2881             :             /* ALTER TABLE <name> SET UNLOGGED */
    2882             :             | SET UNLOGGED
    2883             :                 {
    2884          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2885             : 
    2886          62 :                     n->subtype = AT_SetUnLogged;
    2887          62 :                     $$ = (Node *) n;
    2888             :                 }
    2889             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2890             :             | ENABLE_P TRIGGER name
    2891             :                 {
    2892         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2893             : 
    2894         122 :                     n->subtype = AT_EnableTrig;
    2895         122 :                     n->name = $3;
    2896         122 :                     $$ = (Node *) n;
    2897             :                 }
    2898             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2899             :             | ENABLE_P ALWAYS TRIGGER name
    2900             :                 {
    2901          42 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2902             : 
    2903          42 :                     n->subtype = AT_EnableAlwaysTrig;
    2904          42 :                     n->name = $4;
    2905          42 :                     $$ = (Node *) n;
    2906             :                 }
    2907             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2908             :             | ENABLE_P REPLICA TRIGGER name
    2909             :                 {
    2910          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2911             : 
    2912          16 :                     n->subtype = AT_EnableReplicaTrig;
    2913          16 :                     n->name = $4;
    2914          16 :                     $$ = (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         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2936             : 
    2937         138 :                     n->subtype = AT_DisableTrig;
    2938         138 :                     n->name = $3;
    2939         138 :                     $$ = (Node *) n;
    2940             :                 }
    2941             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2942             :             | DISABLE_P TRIGGER ALL
    2943             :                 {
    2944          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2945             : 
    2946          12 :                     n->subtype = AT_DisableTrigAll;
    2947          12 :                     $$ = (Node *) n;
    2948             :                 }
    2949             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2950             :             | DISABLE_P TRIGGER USER
    2951             :                 {
    2952          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2953             : 
    2954          12 :                     n->subtype = AT_DisableTrigUser;
    2955          12 :                     $$ = (Node *) n;
    2956             :                 }
    2957             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2958             :             | ENABLE_P RULE name
    2959             :                 {
    2960           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2961             : 
    2962           8 :                     n->subtype = AT_EnableRule;
    2963           8 :                     n->name = $3;
    2964           8 :                     $$ = (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           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2979             : 
    2980           6 :                     n->subtype = AT_EnableReplicaRule;
    2981           6 :                     n->name = $4;
    2982           6 :                     $$ = (Node *) n;
    2983             :                 }
    2984             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2985             :             | DISABLE_P RULE name
    2986             :                 {
    2987          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2988             : 
    2989          32 :                     n->subtype = AT_DisableRule;
    2990          32 :                     n->name = $3;
    2991          32 :                     $$ = (Node *) n;
    2992             :                 }
    2993             :             /* ALTER TABLE <name> INHERIT <parent> */
    2994             :             | INHERIT qualified_name
    2995             :                 {
    2996         464 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2997             : 
    2998         464 :                     n->subtype = AT_AddInherit;
    2999         464 :                     n->def = (Node *) $2;
    3000         464 :                     $$ = (Node *) n;
    3001             :                 }
    3002             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    3003             :             | NO INHERIT qualified_name
    3004             :                 {
    3005          94 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3006             : 
    3007          94 :                     n->subtype = AT_DropInherit;
    3008          94 :                     n->def = (Node *) $3;
    3009          94 :                     $$ = (Node *) n;
    3010             :                 }
    3011             :             /* ALTER TABLE <name> OF <type_name> */
    3012             :             | OF any_name
    3013             :                 {
    3014          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3015          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    3016             : 
    3017          66 :                     def->location = @2;
    3018          66 :                     n->subtype = AT_AddOf;
    3019          66 :                     n->def = (Node *) def;
    3020          66 :                     $$ = (Node *) n;
    3021             :                 }
    3022             :             /* ALTER TABLE <name> NOT OF */
    3023             :             | NOT OF
    3024             :                 {
    3025           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3026             : 
    3027           6 :                     n->subtype = AT_DropOf;
    3028           6 :                     $$ = (Node *) n;
    3029             :                 }
    3030             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    3031             :             | OWNER TO RoleSpec
    3032             :                 {
    3033        2082 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3034             : 
    3035        2082 :                     n->subtype = AT_ChangeOwner;
    3036        2082 :                     n->newowner = $3;
    3037        2082 :                     $$ = (Node *) n;
    3038             :                 }
    3039             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    3040             :             | SET ACCESS METHOD set_access_method_name
    3041             :                 {
    3042         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3043             : 
    3044         128 :                     n->subtype = AT_SetAccessMethod;
    3045         128 :                     n->name = $4;
    3046         128 :                     $$ = (Node *) n;
    3047             :                 }
    3048             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    3049             :             | SET TABLESPACE name
    3050             :                 {
    3051         110 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3052             : 
    3053         110 :                     n->subtype = AT_SetTableSpace;
    3054         110 :                     n->name = $3;
    3055         110 :                     $$ = (Node *) n;
    3056             :                 }
    3057             :             /* ALTER TABLE <name> SET (...) */
    3058             :             | SET reloptions
    3059             :                 {
    3060         604 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3061             : 
    3062         604 :                     n->subtype = AT_SetRelOptions;
    3063         604 :                     n->def = (Node *) $2;
    3064         604 :                     $$ = (Node *) n;
    3065             :                 }
    3066             :             /* ALTER TABLE <name> RESET (...) */
    3067             :             | RESET reloptions
    3068             :                 {
    3069         170 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3070             : 
    3071         170 :                     n->subtype = AT_ResetRelOptions;
    3072         170 :                     n->def = (Node *) $2;
    3073         170 :                     $$ = (Node *) n;
    3074             :                 }
    3075             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    3076             :             | REPLICA IDENTITY_P replica_identity
    3077             :                 {
    3078         494 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3079             : 
    3080         494 :                     n->subtype = AT_ReplicaIdentity;
    3081         494 :                     n->def = $3;
    3082         494 :                     $$ = (Node *) n;
    3083             :                 }
    3084             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    3085             :             | ENABLE_P ROW LEVEL SECURITY
    3086             :                 {
    3087         338 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3088             : 
    3089         338 :                     n->subtype = AT_EnableRowSecurity;
    3090         338 :                     $$ = (Node *) n;
    3091             :                 }
    3092             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    3093             :             | DISABLE_P ROW LEVEL SECURITY
    3094             :                 {
    3095          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3096             : 
    3097          10 :                     n->subtype = AT_DisableRowSecurity;
    3098          10 :                     $$ = (Node *) n;
    3099             :                 }
    3100             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    3101             :             | FORCE ROW LEVEL SECURITY
    3102             :                 {
    3103         100 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3104             : 
    3105         100 :                     n->subtype = AT_ForceRowSecurity;
    3106         100 :                     $$ = (Node *) n;
    3107             :                 }
    3108             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    3109             :             | NO FORCE ROW LEVEL SECURITY
    3110             :                 {
    3111          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3112             : 
    3113          32 :                     n->subtype = AT_NoForceRowSecurity;
    3114          32 :                     $$ = (Node *) n;
    3115             :                 }
    3116             :             | alter_generic_options
    3117             :                 {
    3118          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3119             : 
    3120          64 :                     n->subtype = AT_GenericOptions;
    3121          64 :                     n->def = (Node *) $1;
    3122          64 :                     $$ = (Node *) n;
    3123             :                 }
    3124             :         ;
    3125             : 
    3126             : alter_column_default:
    3127         378 :             SET DEFAULT a_expr          { $$ = $3; }
    3128         186 :             | DROP DEFAULT              { $$ = NULL; }
    3129             :         ;
    3130             : 
    3131             : opt_collate_clause:
    3132             :             COLLATE any_name
    3133             :                 {
    3134          18 :                     CollateClause *n = makeNode(CollateClause);
    3135             : 
    3136          18 :                     n->arg = NULL;
    3137          18 :                     n->collname = $2;
    3138          18 :                     n->location = @1;
    3139          18 :                     $$ = (Node *) n;
    3140             :                 }
    3141        4852 :             | /* EMPTY */               { $$ = NULL; }
    3142             :         ;
    3143             : 
    3144             : alter_using:
    3145         180 :             USING a_expr                { $$ = $2; }
    3146         958 :             | /* EMPTY */               { $$ = NULL; }
    3147             :         ;
    3148             : 
    3149             : replica_identity:
    3150             :             NOTHING
    3151             :                 {
    3152          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3153             : 
    3154          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3155          48 :                     n->name = NULL;
    3156          48 :                     $$ = (Node *) n;
    3157             :                 }
    3158             :             | FULL
    3159             :                 {
    3160         170 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3161             : 
    3162         170 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3163         170 :                     n->name = NULL;
    3164         170 :                     $$ = (Node *) n;
    3165             :                 }
    3166             :             | DEFAULT
    3167             :                 {
    3168           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3169             : 
    3170           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3171           6 :                     n->name = NULL;
    3172           6 :                     $$ = (Node *) n;
    3173             :                 }
    3174             :             | USING INDEX name
    3175             :                 {
    3176         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3177             : 
    3178         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3179         270 :                     n->name = $3;
    3180         270 :                     $$ = (Node *) n;
    3181             :                 }
    3182             : ;
    3183             : 
    3184             : reloptions:
    3185        2820 :             '(' reloption_list ')'                  { $$ = $2; }
    3186             :         ;
    3187             : 
    3188         972 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3189       24008 :              |      /* EMPTY */                     { $$ = NIL; }
    3190             :         ;
    3191             : 
    3192             : reloption_list:
    3193        2820 :             reloption_elem                          { $$ = list_make1($1); }
    3194         252 :             | 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        2404 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3202             :                 }
    3203             :             | ColLabel
    3204             :                 {
    3205         590 :                     $$ = makeDefElem($1, NULL, @1);
    3206             :                 }
    3207             :             | ColLabel '.' ColLabel '=' def_arg
    3208             :                 {
    3209          72 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3210          72 :                                              DEFELEM_UNSPEC, @1);
    3211             :                 }
    3212             :             | ColLabel '.' ColLabel
    3213             :                 {
    3214           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3215             :                 }
    3216             :         ;
    3217             : 
    3218             : alter_identity_column_option_list:
    3219             :             alter_identity_column_option
    3220          62 :                 { $$ = list_make1($1); }
    3221             :             | alter_identity_column_option_list alter_identity_column_option
    3222          60 :                 { $$ = lappend($1, $2); }
    3223             :         ;
    3224             : 
    3225             : alter_identity_column_option:
    3226             :             RESTART
    3227             :                 {
    3228          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3229             :                 }
    3230             :             | RESTART opt_with NumericOnly
    3231             :                 {
    3232           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3233             :                 }
    3234             :             | SET SeqOptElem
    3235             :                 {
    3236          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3237          54 :                         strcmp($2->defname, "restart") == 0 ||
    3238          54 :                         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          54 :                     $$ = $2;
    3244             :                 }
    3245             :             | SET GENERATED generated_when
    3246             :                 {
    3247          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3248             :                 }
    3249             :         ;
    3250             : 
    3251             : set_statistics_value:
    3252         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3253           0 :             | DEFAULT                       { $$ = NULL; }
    3254             :         ;
    3255             : 
    3256             : set_access_method_name:
    3257          92 :             ColId                           { $$ = $1; }
    3258          36 :             | DEFAULT                       { $$ = NULL; }
    3259             :         ;
    3260             : 
    3261             : PartitionBoundSpec:
    3262             :             /* a HASH partition */
    3263             :             FOR VALUES WITH '(' hash_partbound ')'
    3264             :                 {
    3265             :                     ListCell   *lc;
    3266         774 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3267             : 
    3268         774 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3269         774 :                     n->modulus = n->remainder = -1;
    3270             : 
    3271        2322 :                     foreach (lc, $5)
    3272             :                     {
    3273        1548 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3274             : 
    3275        1548 :                         if (strcmp(opt->defname, "modulus") == 0)
    3276             :                         {
    3277         774 :                             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         774 :                             n->modulus = defGetInt32(opt);
    3283             :                         }
    3284         774 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3285             :                         {
    3286         774 :                             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         774 :                             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         774 :                     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         774 :                     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         774 :                     n->location = @3;
    3313             : 
    3314         774 :                     $$ = n;
    3315             :                 }
    3316             : 
    3317             :             /* a LIST partition */
    3318             :             | FOR VALUES IN_P '(' expr_list ')'
    3319             :                 {
    3320        5300 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3321             : 
    3322        5300 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3323        5300 :                     n->is_default = false;
    3324        5300 :                     n->listdatums = $5;
    3325        5300 :                     n->location = @3;
    3326             : 
    3327        5300 :                     $$ = n;
    3328             :                 }
    3329             : 
    3330             :             /* a RANGE partition */
    3331             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3332             :                 {
    3333        5914 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3334             : 
    3335        5914 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3336        5914 :                     n->is_default = false;
    3337        5914 :                     n->lowerdatums = $5;
    3338        5914 :                     n->upperdatums = $9;
    3339        5914 :                     n->location = @3;
    3340             : 
    3341        5914 :                     $$ = n;
    3342             :                 }
    3343             : 
    3344             :             /* a DEFAULT partition */
    3345             :             | DEFAULT
    3346             :                 {
    3347         846 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3348             : 
    3349         846 :                     n->is_default = true;
    3350         846 :                     n->location = @1;
    3351             : 
    3352         846 :                     $$ = n;
    3353             :                 }
    3354             :         ;
    3355             : 
    3356             : hash_partbound_elem:
    3357             :         NonReservedWord Iconst
    3358             :             {
    3359        1548 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3360             :             }
    3361             :         ;
    3362             : 
    3363             : hash_partbound:
    3364             :         hash_partbound_elem
    3365             :             {
    3366         774 :                 $$ = list_make1($1);
    3367             :             }
    3368             :         | hash_partbound ',' hash_partbound_elem
    3369             :             {
    3370         774 :                 $$ = 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         210 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3385             : 
    3386             :                     /* can't use qualified_name, sigh */
    3387         210 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3388         210 :                     n->cmds = $4;
    3389         210 :                     n->objtype = OBJECT_TYPE;
    3390         210 :                     $$ = (Node *) n;
    3391             :                 }
    3392             :             ;
    3393             : 
    3394             : alter_type_cmds:
    3395         210 :             alter_type_cmd                          { $$ = list_make1($1); }
    3396          12 :             | 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          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3404             : 
    3405          64 :                     n->subtype = AT_AddColumn;
    3406          64 :                     n->def = $3;
    3407          64 :                     n->behavior = $4;
    3408          64 :                     $$ = (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           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3414             : 
    3415           6 :                     n->subtype = AT_DropColumn;
    3416           6 :                     n->name = $5;
    3417           6 :                     n->behavior = $6;
    3418           6 :                     n->missing_ok = true;
    3419           6 :                     $$ = (Node *) n;
    3420             :                 }
    3421             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3422             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3423             :                 {
    3424          78 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3425             : 
    3426          78 :                     n->subtype = AT_DropColumn;
    3427          78 :                     n->name = $3;
    3428          78 :                     n->behavior = $4;
    3429          78 :                     n->missing_ok = false;
    3430          78 :                     $$ = (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          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3436          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3437             : 
    3438          74 :                     n->subtype = AT_AlterColumnType;
    3439          74 :                     n->name = $3;
    3440          74 :                     n->def = (Node *) def;
    3441          74 :                     n->behavior = $8;
    3442             :                     /* We only use these fields of the ColumnDef node */
    3443          74 :                     def->typeName = $6;
    3444          74 :                     def->collClause = (CollateClause *) $7;
    3445          74 :                     def->raw_default = NULL;
    3446          74 :                     def->location = @3;
    3447          74 :                     $$ = (Node *) n;
    3448             :                 }
    3449             :         ;
    3450             : 
    3451             : 
    3452             : /*****************************************************************************
    3453             :  *
    3454             :  *      QUERY :
    3455             :  *              close <portalname>
    3456             :  *
    3457             :  *****************************************************************************/
    3458             : 
    3459             : ClosePortalStmt:
    3460             :             CLOSE cursor_name
    3461             :                 {
    3462        2236 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3463             : 
    3464        2236 :                     n->portalname = $2;
    3465        2236 :                     $$ = (Node *) n;
    3466             :                 }
    3467             :             | CLOSE ALL
    3468             :                 {
    3469          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3470             : 
    3471          12 :                     n->portalname = NULL;
    3472          12 :                     $$ = (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       10776 :                     CopyStmt *n = makeNode(CopyStmt);
    3506             : 
    3507       10776 :                     n->relation = $3;
    3508       10776 :                     n->query = NULL;
    3509       10776 :                     n->attlist = $4;
    3510       10776 :                     n->is_from = $5;
    3511       10776 :                     n->is_program = $6;
    3512       10776 :                     n->filename = $7;
    3513       10776 :                     n->whereClause = $11;
    3514             : 
    3515       10776 :                     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       10776 :                     if (!n->is_from && n->whereClause != NULL)
    3522           6 :                         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       10770 :                     n->options = NIL;
    3529             :                     /* Concatenate user-supplied flags */
    3530       10770 :                     if ($2)
    3531          12 :                         n->options = lappend(n->options, $2);
    3532       10770 :                     if ($8)
    3533           0 :                         n->options = lappend(n->options, $8);
    3534       10770 :                     if ($10)
    3535         992 :                         n->options = list_concat(n->options, $10);
    3536       10770 :                     $$ = (Node *) n;
    3537             :                 }
    3538             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3539             :                 {
    3540         588 :                     CopyStmt *n = makeNode(CopyStmt);
    3541             : 
    3542         588 :                     n->relation = NULL;
    3543         588 :                     n->query = $3;
    3544         588 :                     n->attlist = NIL;
    3545         588 :                     n->is_from = false;
    3546         588 :                     n->is_program = $6;
    3547         588 :                     n->filename = $7;
    3548         588 :                     n->options = $9;
    3549             : 
    3550         588 :                     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         588 :                     $$ = (Node *) n;
    3557             :                 }
    3558             :         ;
    3559             : 
    3560             : copy_from:
    3561        1890 :             FROM                                    { $$ = true; }
    3562        8886 :             | TO                                    { $$ = false; }
    3563             :         ;
    3564             : 
    3565             : opt_program:
    3566           0 :             PROGRAM                                 { $$ = true; }
    3567       11364 :             | /* 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         454 :             Sconst                                  { $$ = $1; }
    3577        1500 :             | STDIN                                 { $$ = NULL; }
    3578        9410 :             | STDOUT                                { $$ = NULL; }
    3579             :         ;
    3580             : 
    3581       10642 : copy_options: copy_opt_list                         { $$ = $1; }
    3582         722 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3583             :         ;
    3584             : 
    3585             : /* old COPY option syntax */
    3586             : copy_opt_list:
    3587         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3588       10642 :             | /* EMPTY */                           { $$ = NIL; }
    3589             :         ;
    3590             : 
    3591             : copy_opt_item:
    3592             :             BINARY
    3593             :                 {
    3594           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3595             :                 }
    3596             :             | FREEZE
    3597             :                 {
    3598          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3599             :                 }
    3600             :             | DELIMITER opt_as Sconst
    3601             :                 {
    3602         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3603             :                 }
    3604             :             | NULL_P opt_as Sconst
    3605             :                 {
    3606          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3607             :                 }
    3608             :             | CSV
    3609             :                 {
    3610         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3611             :                 }
    3612             :             | HEADER_P
    3613             :                 {
    3614          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3615             :                 }
    3616             :             | QUOTE opt_as Sconst
    3617             :                 {
    3618          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3619             :                 }
    3620             :             | ESCAPE opt_as Sconst
    3621             :                 {
    3622          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3623             :                 }
    3624             :             | FORCE QUOTE columnList
    3625             :                 {
    3626          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3627             :                 }
    3628             :             | FORCE QUOTE '*'
    3629             :                 {
    3630           6 :                     $$ = 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          12 :                     $$ = 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          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3660             :                 }
    3661       10764 :             | /*EMPTY*/                             { $$ = NULL; }
    3662             :         ;
    3663             : 
    3664             : copy_delimiter:
    3665             :             opt_using DELIMITERS Sconst
    3666             :                 {
    3667           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3668             :                 }
    3669       10776 :             | /*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         722 :                     $$ = list_make1($1);
    3682             :                 }
    3683             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3684             :                 {
    3685         468 :                     $$ = lappend($1, $3);
    3686             :                 }
    3687             :         ;
    3688             : 
    3689             : copy_generic_opt_elem:
    3690             :             ColLabel copy_generic_opt_arg
    3691             :                 {
    3692        1190 :                     $$ = makeDefElem($1, $2, @1);
    3693             :                 }
    3694             :         ;
    3695             : 
    3696             : copy_generic_opt_arg:
    3697         836 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3698          60 :             | NumericOnly                   { $$ = (Node *) $1; }
    3699          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3700           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3701         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3702          48 :             | /* EMPTY */                   { $$ = NULL; }
    3703             :         ;
    3704             : 
    3705             : copy_generic_opt_arg_list:
    3706             :               copy_generic_opt_arg_list_item
    3707             :                 {
    3708         150 :                     $$ = list_make1($1);
    3709             :                 }
    3710             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3711             :                 {
    3712          12 :                     $$ = 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         162 :             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       30848 :                     CreateStmt *n = makeNode(CreateStmt);
    3734             : 
    3735       30848 :                     $4->relpersistence = $2;
    3736       30848 :                     n->relation = $4;
    3737       30848 :                     n->tableElts = $6;
    3738       30848 :                     n->inhRelations = $8;
    3739       30848 :                     n->partspec = $9;
    3740       30848 :                     n->ofTypename = NULL;
    3741       30848 :                     n->constraints = NIL;
    3742       30848 :                     n->accessMethod = $10;
    3743       30848 :                     n->options = $11;
    3744       30848 :                     n->oncommit = $12;
    3745       30848 :                     n->tablespacename = $13;
    3746       30848 :                     n->if_not_exists = false;
    3747       30848 :                     $$ = (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          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3754             : 
    3755          30 :                     $7->relpersistence = $2;
    3756          30 :                     n->relation = $7;
    3757          30 :                     n->tableElts = $9;
    3758          30 :                     n->inhRelations = $11;
    3759          30 :                     n->partspec = $12;
    3760          30 :                     n->ofTypename = NULL;
    3761          30 :                     n->constraints = NIL;
    3762          30 :                     n->accessMethod = $13;
    3763          30 :                     n->options = $14;
    3764          30 :                     n->oncommit = $15;
    3765          30 :                     n->tablespacename = $16;
    3766          30 :                     n->if_not_exists = true;
    3767          30 :                     $$ = (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         122 :                     CreateStmt *n = makeNode(CreateStmt);
    3774             : 
    3775         122 :                     $4->relpersistence = $2;
    3776         122 :                     n->relation = $4;
    3777         122 :                     n->tableElts = $7;
    3778         122 :                     n->inhRelations = NIL;
    3779         122 :                     n->partspec = $8;
    3780         122 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3781         122 :                     n->ofTypename->location = @6;
    3782         122 :                     n->constraints = NIL;
    3783         122 :                     n->accessMethod = $9;
    3784         122 :                     n->options = $10;
    3785         122 :                     n->oncommit = $11;
    3786         122 :                     n->tablespacename = $12;
    3787         122 :                     n->if_not_exists = false;
    3788         122 :                     $$ = (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           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3795             : 
    3796           6 :                     $7->relpersistence = $2;
    3797           6 :                     n->relation = $7;
    3798           6 :                     n->tableElts = $10;
    3799           6 :                     n->inhRelations = NIL;
    3800           6 :                     n->partspec = $11;
    3801           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3802           6 :                     n->ofTypename->location = @9;
    3803           6 :                     n->constraints = NIL;
    3804           6 :                     n->accessMethod = $12;
    3805           6 :                     n->options = $13;
    3806           6 :                     n->oncommit = $14;
    3807           6 :                     n->tablespacename = $15;
    3808           6 :                     n->if_not_exists = true;
    3809           6 :                     $$ = (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        9080 :                     CreateStmt *n = makeNode(CreateStmt);
    3816             : 
    3817        9080 :                     $4->relpersistence = $2;
    3818        9080 :                     n->relation = $4;
    3819        9080 :                     n->tableElts = $8;
    3820        9080 :                     n->inhRelations = list_make1($7);
    3821        9080 :                     n->partbound = $9;
    3822        9080 :                     n->partspec = $10;
    3823        9080 :                     n->ofTypename = NULL;
    3824        9080 :                     n->constraints = NIL;
    3825        9080 :                     n->accessMethod = $11;
    3826        9080 :                     n->options = $12;
    3827        9080 :                     n->oncommit = $13;
    3828        9080 :                     n->tablespacename = $14;
    3829        9080 :                     n->if_not_exists = false;
    3830        9080 :                     $$ = (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         352 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3867        2900 :             | 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         168 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3885       56276 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3886             :         ;
    3887             : 
    3888             : OptTableElementList:
    3889       29672 :             TableElementList                    { $$ = $1; }
    3890        1668 :             | /*EMPTY*/                         { $$ = NIL; }
    3891             :         ;
    3892             : 
    3893             : OptTypedTableElementList:
    3894         354 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3895        8950 :             | /*EMPTY*/                         { $$ = NIL; }
    3896             :         ;
    3897             : 
    3898             : TableElementList:
    3899             :             TableElement
    3900             :                 {
    3901       29726 :                     $$ = list_make1($1);
    3902             :                 }
    3903             :             | TableElementList ',' TableElement
    3904             :                 {
    3905       41904 :                     $$ = lappend($1, $3);
    3906             :                 }
    3907             :         ;
    3908             : 
    3909             : TypedTableElementList:
    3910             :             TypedTableElement
    3911             :                 {
    3912         354 :                     $$ = list_make1($1);
    3913             :                 }
    3914             :             | TypedTableElementList ',' TypedTableElement
    3915             :                 {
    3916          68 :                     $$ = lappend($1, $3);
    3917             :                 }
    3918             :         ;
    3919             : 
    3920             : TableElement:
    3921       68068 :             columnDef                           { $$ = $1; }
    3922         786 :             | TableLikeClause                   { $$ = $1; }
    3923        2776 :             | TableConstraint                   { $$ = $1; }
    3924             :         ;
    3925             : 
    3926             : TypedTableElement:
    3927         358 :             columnOptions                       { $$ = $1; }
    3928          64 :             | TableConstraint                   { $$ = $1; }
    3929             :         ;
    3930             : 
    3931             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3932             :                 {
    3933       70242 :                     ColumnDef *n = makeNode(ColumnDef);
    3934             : 
    3935       70242 :                     n->colname = $1;
    3936       70242 :                     n->typeName = $2;
    3937       70242 :                     n->storage_name = $3;
    3938       70242 :                     n->compression = $4;
    3939       70242 :                     n->inhcount = 0;
    3940       70242 :                     n->is_local = true;
    3941       70242 :                     n->is_not_null = false;
    3942       70242 :                     n->is_from_type = false;
    3943       70242 :                     n->storage = 0;
    3944       70242 :                     n->raw_default = NULL;
    3945       70242 :                     n->cooked_default = NULL;
    3946       70242 :                     n->collOid = InvalidOid;
    3947       70242 :                     n->fdwoptions = $5;
    3948       70242 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3949             :                                      yyscanner);
    3950       70242 :                     n->location = @1;
    3951       70242 :                     $$ = (Node *) n;
    3952             :                 }
    3953             :         ;
    3954             : 
    3955             : columnOptions:  ColId ColQualList
    3956             :                 {
    3957         138 :                     ColumnDef *n = makeNode(ColumnDef);
    3958             : 
    3959         138 :                     n->colname = $1;
    3960         138 :                     n->typeName = NULL;
    3961         138 :                     n->inhcount = 0;
    3962         138 :                     n->is_local = true;
    3963         138 :                     n->is_not_null = false;
    3964         138 :                     n->is_from_type = false;
    3965         138 :                     n->storage = 0;
    3966         138 :                     n->raw_default = NULL;
    3967         138 :                     n->cooked_default = NULL;
    3968         138 :                     n->collOid = InvalidOid;
    3969         138 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3970             :                                      yyscanner);
    3971         138 :                     n->location = @1;
    3972         138 :                     $$ = (Node *) n;
    3973             :                 }
    3974             :                 | ColId WITH OPTIONS ColQualList
    3975             :                 {
    3976         220 :                     ColumnDef *n = makeNode(ColumnDef);
    3977             : 
    3978         220 :                     n->colname = $1;
    3979         220 :                     n->typeName = NULL;
    3980         220 :                     n->inhcount = 0;
    3981         220 :                     n->is_local = true;
    3982         220 :                     n->is_not_null = false;
    3983         220 :                     n->is_from_type = false;
    3984         220 :                     n->storage = 0;
    3985         220 :                     n->raw_default = NULL;
    3986         220 :                     n->cooked_default = NULL;
    3987         220 :                     n->collOid = InvalidOid;
    3988         220 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3989             :                                      yyscanner);
    3990         220 :                     n->location = @1;
    3991         220 :                     $$ = (Node *) n;
    3992             :                 }
    3993             :         ;
    3994             : 
    3995             : column_compression:
    3996         178 :             COMPRESSION ColId                       { $$ = $2; }
    3997           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3998             :         ;
    3999             : 
    4000             : opt_column_compression:
    4001         106 :             column_compression                      { $$ = $1; }
    4002       70202 :             | /*EMPTY*/                             { $$ = NULL; }
    4003             :         ;
    4004             : 
    4005             : column_storage:
    4006         288 :             STORAGE ColId                           { $$ = $2; }
    4007           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    4008             :         ;
    4009             : 
    4010             : opt_column_storage:
    4011          56 :             column_storage                          { $$ = $1; }
    4012       70252 :             | /*EMPTY*/                             { $$ = NULL; }
    4013             :         ;
    4014             : 
    4015             : ColQualList:
    4016       20690 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    4017       72140 :             | /*EMPTY*/                             { $$ = NIL; }
    4018             :         ;
    4019             : 
    4020             : ColConstraint:
    4021             :             CONSTRAINT name ColConstraintElem
    4022             :                 {
    4023         810 :                     Constraint *n = castNode(Constraint, $3);
    4024             : 
    4025         810 :                     n->conname = $2;
    4026         810 :                     n->location = @1;
    4027         810 :                     $$ = (Node *) n;
    4028             :                 }
    4029       18808 :             | ColConstraintElem                     { $$ = $1; }
    4030         294 :             | 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         778 :                     CollateClause *n = makeNode(CollateClause);
    4039             : 
    4040         778 :                     n->arg = NULL;
    4041         778 :                     n->collname = $2;
    4042         778 :                     n->location = @1;
    4043         778 :                     $$ = (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        7018 :                     Constraint *n = makeNode(Constraint);
    4066             : 
    4067        7018 :                     n->contype = CONSTR_NOTNULL;
    4068        7018 :                     n->location = @1;
    4069        7018 :                     n->is_no_inherit = $3;
    4070        7018 :                     n->is_enforced = true;
    4071        7018 :                     n->skip_validation = false;
    4072        7018 :                     n->initially_valid = true;
    4073        7018 :                     $$ = (Node *) n;
    4074             :                 }
    4075             :             | NULL_P
    4076             :                 {
    4077          30 :                     Constraint *n = makeNode(Constraint);
    4078             : 
    4079          30 :                     n->contype = CONSTR_NULL;
    4080          30 :                     n->location = @1;
    4081          30 :                     $$ = (Node *) n;
    4082             :                 }
    4083             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    4084             :                 {
    4085         466 :                     Constraint *n = makeNode(Constraint);
    4086             : 
    4087         466 :                     n->contype = CONSTR_UNIQUE;
    4088         466 :                     n->location = @1;
    4089         466 :                     n->nulls_not_distinct = !$2;
    4090         466 :                     n->keys = NULL;
    4091         466 :                     n->options = $3;
    4092         466 :                     n->indexname = NULL;
    4093         466 :                     n->indexspace = $4;
    4094         466 :                     $$ = (Node *) n;
    4095             :                 }
    4096             :             | PRIMARY KEY opt_definition OptConsTableSpace
    4097             :                 {
    4098        6008 :                     Constraint *n = makeNode(Constraint);
    4099             : 
    4100        6008 :                     n->contype = CONSTR_PRIMARY;
    4101        6008 :                     n->location = @1;
    4102        6008 :                     n->keys = NULL;
    4103        6008 :                     n->options = $3;
    4104        6008 :                     n->indexname = NULL;
    4105        6008 :                     n->indexspace = $4;
    4106        6008 :                     $$ = (Node *) n;
    4107             :                 }
    4108             :             | CHECK '(' a_expr ')' opt_no_inherit
    4109             :                 {
    4110        1104 :                     Constraint *n = makeNode(Constraint);
    4111             : 
    4112        1104 :                     n->contype = CONSTR_CHECK;
    4113        1104 :                     n->location = @1;
    4114        1104 :                     n->is_no_inherit = $5;
    4115        1104 :                     n->raw_expr = $3;
    4116        1104 :                     n->cooked_expr = NULL;
    4117        1104 :                     n->is_enforced = true;
    4118        1104 :                     n->skip_validation = false;
    4119        1104 :                     n->initially_valid = true;
    4120        1104 :                     $$ = (Node *) n;
    4121             :                 }
    4122             :             | DEFAULT b_expr
    4123             :                 {
    4124        1906 :                     Constraint *n = makeNode(Constraint);
    4125             : 
    4126        1906 :                     n->contype = CONSTR_DEFAULT;
    4127        1906 :                     n->location = @1;
    4128        1906 :                     n->raw_expr = $2;
    4129        1906 :                     n->cooked_expr = NULL;
    4130        1906 :                     $$ = (Node *) n;
    4131             :                 }
    4132             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4133             :                 {
    4134         374 :                     Constraint *n = makeNode(Constraint);
    4135             : 
    4136         374 :                     n->contype = CONSTR_IDENTITY;
    4137         374 :                     n->generated_when = $2;
    4138         374 :                     n->options = $5;
    4139         374 :                     n->location = @1;
    4140         374 :                     $$ = (Node *) n;
    4141             :                 }
    4142             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4143             :                 {
    4144        1872 :                     Constraint *n = makeNode(Constraint);
    4145             : 
    4146        1872 :                     n->contype = CONSTR_GENERATED;
    4147        1872 :                     n->generated_when = $2;
    4148        1872 :                     n->raw_expr = $5;
    4149        1872 :                     n->cooked_expr = NULL;
    4150        1872 :                     n->generated_kind = $7;
    4151        1872 :                     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        1872 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4160          12 :                         ereport(ERROR,
    4161             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4162             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4163             :                                  parser_errposition(@2)));
    4164             : 
    4165        1860 :                     $$ = (Node *) n;
    4166             :                 }
    4167             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4168             :                 {
    4169         852 :                     Constraint *n = makeNode(Constraint);
    4170             : 
    4171         852 :                     n->contype = CONSTR_FOREIGN;
    4172         852 :                     n->location = @1;
    4173         852 :                     n->pktable = $2;
    4174         852 :                     n->fk_attrs = NIL;
    4175         852 :                     n->pk_attrs = $3;
    4176         852 :                     n->fk_matchtype = $4;
    4177         852 :                     n->fk_upd_action = ($5)->updateAction->action;
    4178         852 :                     n->fk_del_action = ($5)->deleteAction->action;
    4179         852 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4180         852 :                     n->is_enforced = true;
    4181         852 :                     n->skip_validation = false;
    4182         852 :                     n->initially_valid = true;
    4183         852 :                     $$ = (Node *) n;
    4184             :                 }
    4185             :         ;
    4186             : 
    4187             : opt_unique_null_treatment:
    4188          12 :             NULLS_P DISTINCT        { $$ = true; }
    4189          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4190        7888 :             | /*EMPTY*/             { $$ = true; }
    4191             :         ;
    4192             : 
    4193             : generated_when:
    4194        2280 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4195         182 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4196             :         ;
    4197             : 
    4198             : opt_virtual_or_stored:
    4199        1088 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4200         658 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4201         126 :             | /*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         102 :                     Constraint *n = makeNode(Constraint);
    4223             : 
    4224         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4225         102 :                     n->location = @1;
    4226         102 :                     $$ = (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          78 :                     Constraint *n = makeNode(Constraint);
    4239             : 
    4240          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4241          78 :                     n->location = @1;
    4242          78 :                     $$ = (Node *) n;
    4243             :                 }
    4244             :             | INITIALLY IMMEDIATE
    4245             :                 {
    4246           6 :                     Constraint *n = makeNode(Constraint);
    4247             : 
    4248           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4249           6 :                     n->location = @1;
    4250           6 :                     $$ = (Node *) n;
    4251             :                 }
    4252             :             | ENFORCED
    4253             :                 {
    4254          42 :                     Constraint *n = makeNode(Constraint);
    4255             : 
    4256          42 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4257          42 :                     n->location = @1;
    4258          42 :                     $$ = (Node *) n;
    4259             :                 }
    4260             :             | NOT ENFORCED
    4261             :                 {
    4262          66 :                     Constraint *n = makeNode(Constraint);
    4263             : 
    4264          66 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4265          66 :                     n->location = @1;
    4266          66 :                     $$ = (Node *) n;
    4267             :                 }
    4268             :         ;
    4269             : 
    4270             : 
    4271             : TableLikeClause:
    4272             :             LIKE qualified_name TableLikeOptionList
    4273             :                 {
    4274         786 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4275             : 
    4276         786 :                     n->relation = $2;
    4277         786 :                     n->options = $3;
    4278         786 :                     n->relationOid = InvalidOid;
    4279         786 :                     $$ = (Node *) n;
    4280             :                 }
    4281             :         ;
    4282             : 
    4283             : TableLikeOptionList:
    4284         288 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4285           8 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4286         786 :                 | /* EMPTY */                       { $$ = 0; }
    4287             :         ;
    4288             : 
    4289             : TableLikeOption:
    4290          30 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4291           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4292          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4293          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4294          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4295          30 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4296          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4297           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4298          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4299          68 :                 | 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        4184 :                     Constraint *n = castNode(Constraint, $3);
    4311             : 
    4312        4184 :                     n->conname = $2;
    4313        4184 :                     n->location = @1;
    4314        4184 :                     $$ = (Node *) n;
    4315             :                 }
    4316       13528 :             | ConstraintElem                        { $$ = $1; }
    4317             :         ;
    4318             : 
    4319             : ConstraintElem:
    4320             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4321             :                 {
    4322        1328 :                     Constraint *n = makeNode(Constraint);
    4323             : 
    4324        1328 :                     n->contype = CONSTR_CHECK;
    4325        1328 :                     n->location = @1;
    4326        1328 :                     n->raw_expr = $3;
    4327        1328 :                     n->cooked_expr = NULL;
    4328        1328 :                     processCASbits($5, @5, "CHECK",
    4329             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4330             :                                    &n->is_no_inherit, yyscanner);
    4331        1328 :                     n->initially_valid = !n->skip_validation;
    4332        1328 :                     $$ = (Node *) n;
    4333             :                 }
    4334             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4335             :                 {
    4336         610 :                     Constraint *n = makeNode(Constraint);
    4337             : 
    4338         610 :                     n->contype = CONSTR_NOTNULL;
    4339         610 :                     n->location = @1;
    4340         610 :                     n->keys = list_make1(makeString($3));
    4341         610 :                     processCASbits($4, @4, "NOT NULL",
    4342             :                                    NULL, NULL, NULL, &n->skip_validation,
    4343             :                                    &n->is_no_inherit, yyscanner);
    4344         610 :                     n->initially_valid = !n->skip_validation;
    4345         610 :                     $$ = (Node *) n;
    4346             :                 }
    4347             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4348             :                 ConstraintAttributeSpec
    4349             :                 {
    4350         598 :                     Constraint *n = makeNode(Constraint);
    4351             : 
    4352         598 :                     n->contype = CONSTR_UNIQUE;
    4353         598 :                     n->location = @1;
    4354         598 :                     n->nulls_not_distinct = !$2;
    4355         598 :                     n->keys = $4;
    4356         598 :                     n->without_overlaps = $5;
    4357         598 :                     n->including = $7;
    4358         598 :                     n->options = $8;
    4359         598 :                     n->indexname = NULL;
    4360         598 :                     n->indexspace = $9;
    4361         598 :                     processCASbits($10, @10, "UNIQUE",
    4362             :                                    &n->deferrable, &n->initdeferred, NULL,
    4363             :                                    NULL, NULL, yyscanner);
    4364         598 :                     $$ = (Node *) n;
    4365             :                 }
    4366             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4367             :                 {
    4368        4744 :                     Constraint *n = makeNode(Constraint);
    4369             : 
    4370        4744 :                     n->contype = CONSTR_UNIQUE;
    4371        4744 :                     n->location = @1;
    4372        4744 :                     n->keys = NIL;
    4373        4744 :                     n->including = NIL;
    4374        4744 :                     n->options = NIL;
    4375        4744 :                     n->indexname = $2;
    4376        4744 :                     n->indexspace = NULL;
    4377        4744 :                     processCASbits($3, @3, "UNIQUE",
    4378             :                                    &n->deferrable, &n->initdeferred, NULL,
    4379             :                                    NULL, NULL, yyscanner);
    4380        4744 :                     $$ = (Node *) n;
    4381             :                 }
    4382             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4383             :                 ConstraintAttributeSpec
    4384             :                 {
    4385        2188 :                     Constraint *n = makeNode(Constraint);
    4386             : 
    4387        2188 :                     n->contype = CONSTR_PRIMARY;
    4388        2188 :                     n->location = @1;
    4389        2188 :                     n->keys = $4;
    4390        2188 :                     n->without_overlaps = $5;
    4391        2188 :                     n->including = $7;
    4392        2188 :                     n->options = $8;
    4393        2188 :                     n->indexname = NULL;
    4394        2188 :                     n->indexspace = $9;
    4395        2188 :                     processCASbits($10, @10, "PRIMARY KEY",
    4396             :                                    &n->deferrable, &n->initdeferred, NULL,
    4397             :                                    NULL, NULL, yyscanner);
    4398        2188 :                     $$ = (Node *) n;
    4399             :                 }
    4400             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4401             :                 {
    4402        6142 :                     Constraint *n = makeNode(Constraint);
    4403             : 
    4404        6142 :                     n->contype = CONSTR_PRIMARY;
    4405        6142 :                     n->location = @1;
    4406        6142 :                     n->keys = NIL;
    4407        6142 :                     n->including = NIL;
    4408        6142 :                     n->options = NIL;
    4409        6142 :                     n->indexname = $3;
    4410        6142 :                     n->indexspace = NULL;
    4411        6142 :                     processCASbits($4, @4, "PRIMARY KEY",
    4412             :                                    &n->deferrable, &n->initdeferred, NULL,
    4413             :                                    NULL, NULL, yyscanner);
    4414        6142 :                     $$ = (Node *) n;
    4415             :                 }
    4416             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4417             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4418             :                 ConstraintAttributeSpec
    4419             :                 {
    4420         234 :                     Constraint *n = makeNode(Constraint);
    4421             : 
    4422         234 :                     n->contype = CONSTR_EXCLUSION;
    4423         234 :                     n->location = @1;
    4424         234 :                     n->access_method = $2;
    4425         234 :                     n->exclusions = $4;
    4426         234 :                     n->including = $6;
    4427         234 :                     n->options = $7;
    4428         234 :                     n->indexname = NULL;
    4429         234 :                     n->indexspace = $8;
    4430         234 :                     n->where_clause = $9;
    4431         234 :                     processCASbits($10, @10, "EXCLUDE",
    4432             :                                    &n->deferrable, &n->initdeferred, NULL,
    4433             :                                    NULL, NULL, yyscanner);
    4434         234 :                     $$ = (Node *) n;
    4435             :                 }
    4436             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4437             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4438             :                 {
    4439        1868 :                     Constraint *n = makeNode(Constraint);
    4440             : 
    4441        1868 :                     n->contype = CONSTR_FOREIGN;
    4442        1868 :                     n->location = @1;
    4443        1868 :                     n->pktable = $8;
    4444        1868 :                     n->fk_attrs = $4;
    4445        1868 :                     if ($5)
    4446             :                     {
    4447         326 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4448         326 :                         n->fk_with_period = true;
    4449             :                     }
    4450        1868 :                     n->pk_attrs = linitial($9);
    4451        1868 :                     if (lsecond($9))
    4452             :                     {
    4453         170 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4454         170 :                         n->pk_with_period = true;
    4455             :                     }
    4456        1868 :                     n->fk_matchtype = $10;
    4457        1868 :                     n->fk_upd_action = ($11)->updateAction->action;
    4458        1868 :                     n->fk_del_action = ($11)->deleteAction->action;
    4459        1868 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4460        1868 :                     processCASbits($12, @12, "FOREIGN KEY",
    4461             :                                    &n->deferrable, &n->initdeferred,
    4462             :                                    &n->is_enforced, &n->skip_validation, NULL,
    4463             :                                    yyscanner);
    4464        1868 :                     n->initially_valid = !n->skip_validation;
    4465        1868 :                     $$ = (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         164 :                     Constraint *n = castNode(Constraint, $3);
    4484             : 
    4485         164 :                     n->conname = $2;
    4486         164 :                     n->location = @1;
    4487         164 :                     $$ = (Node *) n;
    4488             :                 }
    4489          18 :             | DomainConstraintElem                  { $$ = $1; }
    4490             :         ;
    4491             : 
    4492             : DomainConstraintElem:
    4493             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4494             :                 {
    4495         164 :                     Constraint *n = makeNode(Constraint);
    4496             : 
    4497         164 :                     n->contype = CONSTR_CHECK;
    4498         164 :                     n->location = @1;
    4499         164 :                     n->raw_expr = $3;
    4500         164 :                     n->cooked_expr = NULL;
    4501         164 :                     processCASbits($5, @5, "CHECK",
    4502             :                                    NULL, NULL, NULL, &n->skip_validation,
    4503             :                                    &n->is_no_inherit, yyscanner);
    4504         152 :                     n->is_enforced = true;
    4505         152 :                     n->initially_valid = !n->skip_validation;
    4506         152 :                     $$ = (Node *) n;
    4507             :                 }
    4508             :             | NOT NULL_P ConstraintAttributeSpec
    4509             :                 {
    4510          30 :                     Constraint *n = makeNode(Constraint);
    4511             : 
    4512          30 :                     n->contype = CONSTR_NOTNULL;
    4513          30 :                     n->location = @1;
    4514          30 :                     n->keys = list_make1(makeString("value"));
    4515             :                     /* no NOT VALID, NO INHERIT support */
    4516          30 :                     processCASbits($3, @3, "NOT NULL",
    4517             :                                    NULL, NULL, NULL,
    4518             :                                    NULL, NULL, yyscanner);
    4519          30 :                     n->initially_valid = true;
    4520          30 :                     $$ = (Node *) n;
    4521             :                 }
    4522             :         ;
    4523             : 
    4524         138 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4525        7984 :             | /* EMPTY */                           {  $$ = false; }
    4526             :         ;
    4527             : 
    4528             : opt_without_overlaps:
    4529         590 :             WITHOUT OVERLAPS                        { $$ = true; }
    4530        2196 :             | /*EMPTY*/                             { $$ = false; }
    4531             :     ;
    4532             : 
    4533             : opt_column_list:
    4534       10304 :             '(' columnList ')'                      { $$ = $2; }
    4535       43988 :             | /*EMPTY*/                             { $$ = NIL; }
    4536             :         ;
    4537             : 
    4538             : columnList:
    4539       16652 :             columnElem                              { $$ = list_make1($1); }
    4540       28654 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4541             :         ;
    4542             : 
    4543             : optionalPeriodName:
    4544         496 :             ',' PERIOD columnElem { $$ = $3; }
    4545        2502 :             | /*EMPTY*/               { $$ = NULL; }
    4546             :     ;
    4547             : 
    4548             : opt_column_and_period_list:
    4549        1124 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4550         750 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4551             :         ;
    4552             : 
    4553             : columnElem: ColId
    4554             :                 {
    4555       45802 :                     $$ = (Node *) makeString($1);
    4556             :                 }
    4557             :         ;
    4558             : 
    4559         168 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4560        2852 :              |      /* EMPTY */                     { $$ = NIL; }
    4561             :         ;
    4562             : 
    4563             : key_match:  MATCH FULL
    4564             :             {
    4565          98 :                 $$ = 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           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4578             :             }
    4579             :         | /*EMPTY*/
    4580             :             {
    4581        2622 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4582             :             }
    4583             :         ;
    4584             : 
    4585             : ExclusionConstraintList:
    4586         234 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4587             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4588         106 :                                                     { $$ = lappend($1, $3); }
    4589             :         ;
    4590             : 
    4591             : ExclusionConstraintElem: index_elem WITH any_operator
    4592             :             {
    4593         340 :                 $$ = 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         464 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4604        1268 :             | /*EMPTY*/                             { $$ = NULL; }
    4605             :         ;
    4606             : 
    4607             : key_actions:
    4608             :             key_update
    4609             :                 {
    4610          74 :                     KeyActions *n = palloc_object(KeyActions);
    4611             : 
    4612          74 :                     n->updateAction = $1;
    4613          74 :                     n->deleteAction = palloc_object(KeyAction);
    4614          74 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4615          74 :                     n->deleteAction->cols = NIL;
    4616          74 :                     $$ = n;
    4617             :                 }
    4618             :             | key_delete
    4619             :                 {
    4620         150 :                     KeyActions *n = palloc_object(KeyActions);
    4621             : 
    4622         150 :                     n->updateAction = palloc_object(KeyAction);
    4623         150 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4624         150 :                     n->updateAction->cols = NIL;
    4625         150 :                     n->deleteAction = $1;
    4626         150 :                     $$ = n;
    4627             :                 }
    4628             :             | key_update key_delete
    4629             :                 {
    4630         168 :                     KeyActions *n = palloc_object(KeyActions);
    4631             : 
    4632         168 :                     n->updateAction = $1;
    4633         168 :                     n->deleteAction = $2;
    4634         168 :                     $$ = n;
    4635             :                 }
    4636             :             | key_delete key_update
    4637             :                 {
    4638         150 :                     KeyActions *n = palloc_object(KeyActions);
    4639             : 
    4640         150 :                     n->updateAction = $2;
    4641         150 :                     n->deleteAction = $1;
    4642         150 :                     $$ = n;
    4643             :                 }
    4644             :             | /*EMPTY*/
    4645             :                 {
    4646        2178 :                     KeyActions *n = palloc_object(KeyActions);
    4647             : 
    4648        2178 :                     n->updateAction = palloc_object(KeyAction);
    4649        2178 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4650        2178 :                     n->updateAction->cols = NIL;
    4651        2178 :                     n->deleteAction = palloc_object(KeyAction);
    4652        2178 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4653        2178 :                     n->deleteAction->cols = NIL;
    4654        2178 :                     $$ = n;
    4655             :                 }
    4656             :         ;
    4657             : 
    4658             : key_update: ON UPDATE key_action
    4659             :                 {
    4660         398 :                     if (($3)->cols)
    4661           6 :                         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         392 :                     $$ = $3;
    4667             :                 }
    4668             :         ;
    4669             : 
    4670             : key_delete: ON DELETE_P key_action
    4671             :                 {
    4672         468 :                     $$ = $3;
    4673             :                 }
    4674             :         ;
    4675             : 
    4676             : key_action:
    4677             :             NO ACTION
    4678             :                 {
    4679          80 :                     KeyAction *n = palloc_object(KeyAction);
    4680             : 
    4681          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4682          80 :                     n->cols = NIL;
    4683          80 :                     $$ = n;
    4684             :                 }
    4685             :             | RESTRICT
    4686             :                 {
    4687          48 :                     KeyAction *n = palloc_object(KeyAction);
    4688             : 
    4689          48 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4690          48 :                     n->cols = NIL;
    4691          48 :                     $$ = n;
    4692             :                 }
    4693             :             | CASCADE
    4694             :                 {
    4695         446 :                     KeyAction *n = palloc_object(KeyAction);
    4696             : 
    4697         446 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4698         446 :                     n->cols = NIL;
    4699         446 :                     $$ = n;
    4700             :                 }
    4701             :             | SET NULL_P opt_column_list
    4702             :                 {
    4703         190 :                     KeyAction *n = palloc_object(KeyAction);
    4704             : 
    4705         190 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4706         190 :                     n->cols = $3;
    4707         190 :                     $$ = n;
    4708             :                 }
    4709             :             | SET DEFAULT opt_column_list
    4710             :                 {
    4711         102 :                     KeyAction *n = palloc_object(KeyAction);
    4712             : 
    4713         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4714         102 :                     n->cols = $3;
    4715         102 :                     $$ = n;
    4716             :                 }
    4717             :         ;
    4718             : 
    4719        2132 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4720       29190 :             | /*EMPTY*/                             { $$ = NIL; }
    4721             :         ;
    4722             : 
    4723             : /* Optional partition key specification */
    4724        5594 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4725       34504 :             | /*EMPTY*/         { $$ = NULL; }
    4726             :         ;
    4727             : 
    4728             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4729             :                 {
    4730        5600 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4731             : 
    4732        5600 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4733        5594 :                     n->partParams = $5;
    4734        5594 :                     n->location = @1;
    4735             : 
    4736        5594 :                     $$ = n;
    4737             :                 }
    4738             :         ;
    4739             : 
    4740        5600 : part_params:    part_elem                       { $$ = list_make1($1); }
    4741         486 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4742             :         ;
    4743             : 
    4744             : part_elem: ColId opt_collate opt_qualified_name
    4745             :                 {
    4746        5734 :                     PartitionElem *n = makeNode(PartitionElem);
    4747             : 
    4748        5734 :                     n->name = $1;
    4749        5734 :                     n->expr = NULL;
    4750        5734 :                     n->collation = $2;
    4751        5734 :                     n->opclass = $3;
    4752        5734 :                     n->location = @1;
    4753        5734 :                     $$ = n;
    4754             :                 }
    4755             :             | func_expr_windowless opt_collate opt_qualified_name
    4756             :                 {
    4757         142 :                     PartitionElem *n = makeNode(PartitionElem);
    4758             : 
    4759         142 :                     n->name = NULL;
    4760         142 :                     n->expr = $1;
    4761         142 :                     n->collation = $2;
    4762         142 :                     n->opclass = $3;
    4763         142 :                     n->location = @1;
    4764         142 :                     $$ = n;
    4765             :                 }
    4766             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4767             :                 {
    4768         210 :                     PartitionElem *n = makeNode(PartitionElem);
    4769             : 
    4770         210 :                     n->name = NULL;
    4771         210 :                     n->expr = $2;
    4772         210 :                     n->collation = $4;
    4773         210 :                     n->opclass = $5;
    4774         210 :                     n->location = @1;
    4775         210 :                     $$ = n;
    4776             :                 }
    4777             :         ;
    4778             : 
    4779             : table_access_method_clause:
    4780         134 :             USING name                          { $$ = $2; }
    4781       41916 :             | /*EMPTY*/                         { $$ = NULL; }
    4782             :         ;
    4783             : 
    4784             : /* WITHOUT OIDS is legacy only */
    4785             : OptWith:
    4786         858 :             WITH reloptions             { $$ = $2; }
    4787          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4788       40574 :             | /*EMPTY*/                 { $$ = NIL; }
    4789             :         ;
    4790             : 
    4791          66 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4792         104 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4793          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4794       41262 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4795             :         ;
    4796             : 
    4797         228 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4798       48688 :             | /*EMPTY*/                             { $$ = NULL; }
    4799             :         ;
    4800             : 
    4801          78 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4802        9416 :             | /*EMPTY*/                             { $$ = NULL; }
    4803             :         ;
    4804             : 
    4805       10886 : 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         862 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4829             : 
    4830         862 :                     n->defnames = $3;
    4831         862 :                     n->stat_types = $4;
    4832         862 :                     n->exprs = $6;
    4833         862 :                     n->relations = $8;
    4834         862 :                     n->stxcomment = NULL;
    4835         862 :                     n->if_not_exists = false;
    4836         862 :                     $$ = (Node *) n;
    4837             :                 }
    4838             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4839             :             opt_name_list ON stats_params FROM from_list
    4840             :                 {
    4841          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4842             : 
    4843          12 :                     n->defnames = $6;
    4844          12 :                     n->stat_types = $7;
    4845          12 :                     n->exprs = $9;
    4846          12 :                     n->relations = $11;
    4847          12 :                     n->stxcomment = NULL;
    4848          12 :                     n->if_not_exists = true;
    4849          12 :                     $$ = (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         886 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4861        1200 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4862             :         ;
    4863             : 
    4864             : stats_param:    ColId
    4865             :                 {
    4866        1576 :                     $$ = makeNode(StatsElem);
    4867        1576 :                     $$->name = $1;
    4868        1576 :                     $$->expr = NULL;
    4869             :                 }
    4870             :             | func_expr_windowless
    4871             :                 {
    4872          38 :                     $$ = makeNode(StatsElem);
    4873          38 :                     $$->name = NULL;
    4874          38 :                     $$->expr = $1;
    4875             :                 }
    4876             :             | '(' a_expr ')'
    4877             :                 {
    4878         472 :                     $$ = makeNode(StatsElem);
    4879         472 :                     $$->name = NULL;
    4880         472 :                     $$->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          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4896             : 
    4897          20 :                     n->defnames = $3;
    4898          20 :                     n->missing_ok = false;
    4899          20 :                     n->stxstattarget = $6;
    4900          20 :                     $$ = (Node *) n;
    4901             :                 }
    4902             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4903             :                 {
    4904           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4905             : 
    4906           6 :                     n->defnames = $5;
    4907           6 :                     n->missing_ok = true;
    4908           6 :                     n->stxstattarget = $8;
    4909           6 :                     $$ = (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        1230 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4927             : 
    4928        1230 :                     ctas->query = $6;
    4929        1230 :                     ctas->into = $4;
    4930        1230 :                     ctas->objtype = OBJECT_TABLE;
    4931        1230 :                     ctas->is_select_into = false;
    4932        1230 :                     ctas->if_not_exists = false;
    4933             :                     /* cram additional flags into the IntoClause */
    4934        1230 :                     $4->rel->relpersistence = $2;
    4935        1230 :                     $4->skipData = !($7);
    4936        1230 :                     $$ = (Node *) ctas;
    4937             :                 }
    4938             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4939             :                 {
    4940          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4941             : 
    4942          52 :                     ctas->query = $9;
    4943          52 :                     ctas->into = $7;
    4944          52 :                     ctas->objtype = OBJECT_TABLE;
    4945          52 :                     ctas->is_select_into = false;
    4946          52 :                     ctas->if_not_exists = true;
    4947             :                     /* cram additional flags into the IntoClause */
    4948          52 :                     $7->rel->relpersistence = $2;
    4949          52 :                     $7->skipData = !($10);
    4950          52 :                     $$ = (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        1370 :                     $$ = makeNode(IntoClause);
    4959        1370 :                     $$->rel = $1;
    4960        1370 :                     $$->colNames = $2;
    4961        1370 :                     $$->accessMethod = $3;
    4962        1370 :                     $$->options = $4;
    4963        1370 :                     $$->onCommit = $5;
    4964        1370 :                     $$->tableSpaceName = $6;
    4965        1370 :                     $$->viewQuery = NULL;
    4966        1370 :                     $$->skipData = false;        /* might get changed later */
    4967             :                 }
    4968             :         ;
    4969             : 
    4970             : opt_with_data:
    4971          36 :             WITH DATA_P                             { $$ = true; }
    4972         218 :             | WITH NO DATA_P                        { $$ = false; }
    4973        1972 :             | /*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         540 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4988             : 
    4989         540 :                     ctas->query = $7;
    4990         540 :                     ctas->into = $5;
    4991         540 :                     ctas->objtype = OBJECT_MATVIEW;
    4992         540 :                     ctas->is_select_into = false;
    4993         540 :                     ctas->if_not_exists = false;
    4994             :                     /* cram additional flags into the IntoClause */
    4995         540 :                     $5->rel->relpersistence = $2;
    4996         540 :                     $5->skipData = !($8);
    4997         540 :                     $$ = (Node *) ctas;
    4998             :                 }
    4999             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    5000             :                 {
    5001          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    5002             : 
    5003          48 :                     ctas->query = $10;
    5004          48 :                     ctas->into = $8;
    5005          48 :                     ctas->objtype = OBJECT_MATVIEW;
    5006          48 :                     ctas->is_select_into = false;
    5007          48 :                     ctas->if_not_exists = true;
    5008             :                     /* cram additional flags into the IntoClause */
    5009          48 :                     $8->rel->relpersistence = $2;
    5010          48 :                     $8->skipData = !($11);
    5011          48 :                     $$ = (Node *) ctas;
    5012             :                 }
    5013             :         ;
    5014             : 
    5015             : create_mv_target:
    5016             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    5017             :                 {
    5018         588 :                     $$ = makeNode(IntoClause);
    5019         588 :                     $$->rel = $1;
    5020         588 :                     $$->colNames = $2;
    5021         588 :                     $$->accessMethod = $3;
    5022         588 :                     $$->options = $4;
    5023         588 :                     $$->onCommit = ONCOMMIT_NOOP;
    5024         588 :                     $$->tableSpaceName = $5;
    5025         588 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    5026         588 :                     $$->skipData = false;        /* might get changed later */
    5027             :                 }
    5028             :         ;
    5029             : 
    5030           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    5031         588 :             | /*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         268 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    5046             : 
    5047         268 :                     n->concurrent = $4;
    5048         268 :                     n->relation = $5;
    5049         268 :                     n->skipData = !($6);
    5050         268 :                     $$ = (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         702 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    5067             : 
    5068         702 :                     $4->relpersistence = $2;
    5069         702 :                     n->sequence = $4;
    5070         702 :                     n->options = $5;
    5071         702 :                     n->ownerId = InvalidOid;
    5072         702 :                     n->if_not_exists = false;
    5073         702 :                     $$ = (Node *) n;
    5074             :                 }
    5075             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    5076             :                 {
    5077          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    5078             : 
    5079          24 :                     $7->relpersistence = $2;
    5080          24 :                     n->sequence = $7;
    5081          24 :                     n->options = $8;
    5082          24 :                     n->ownerId = InvalidOid;
    5083          24 :                     n->if_not_exists = true;
    5084          24 :                     $$ = (Node *) n;
    5085             :                 }
    5086             :         ;
    5087             : 
    5088             : AlterSeqStmt:
    5089             :             ALTER SEQUENCE qualified_name SeqOptList
    5090             :                 {
    5091         188 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5092             : 
    5093         188 :                     n->sequence = $3;
    5094         188 :                     n->options = $4;
    5095         188 :                     n->missing_ok = false;
    5096         188 :                     $$ = (Node *) n;
    5097             :                 }
    5098             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    5099             :                 {
    5100          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5101             : 
    5102          12 :                     n->sequence = $5;
    5103          12 :                     n->options = $6;
    5104          12 :                     n->missing_ok = true;
    5105          12 :                     $$ = (Node *) n;
    5106             :                 }
    5107             : 
    5108             :         ;
    5109             : 
    5110         270 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    5111         456 :             | /*EMPTY*/                             { $$ = NIL; }
    5112             :         ;
    5113             : 
    5114          74 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    5115         472 :             | /*EMPTY*/                             { $$ = NIL; }
    5116             :         ;
    5117             : 
    5118         544 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    5119         806 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    5120             :         ;
    5121             : 
    5122             : SeqOptElem: AS SimpleTypename
    5123             :                 {
    5124         190 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5125             :                 }
    5126             :             | CACHE NumericOnly
    5127             :                 {
    5128         130 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5129             :                 }
    5130             :             | CYCLE
    5131             :                 {
    5132          34 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5133             :                 }
    5134             :             | NO CYCLE
    5135             :                 {
    5136          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5137             :                 }
    5138             :             | INCREMENT opt_by NumericOnly
    5139             :                 {
    5140         258 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5141             :                 }
    5142             :             | LOGGED
    5143             :                 {
    5144           2 :                     $$ = makeDefElem("logged", NULL, @1);
    5145             :                 }
    5146             :             | MAXVALUE NumericOnly
    5147             :                 {
    5148          68 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5149             :                 }
    5150             :             | MINVALUE NumericOnly
    5151             :                 {
    5152          68 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5153             :                 }
    5154             :             | NO MAXVALUE
    5155             :                 {
    5156         108 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5157             :                 }
    5158             :             | NO MINVALUE
    5159             :                 {
    5160         108 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5161             :                 }
    5162             :             | OWNED BY any_name
    5163             :                 {
    5164          72 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5165             :                 }
    5166             :             | SEQUENCE NAME_P any_name
    5167             :                 {
    5168          44 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5169             :                 }
    5170             :             | START opt_with NumericOnly
    5171             :                 {
    5172         240 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5173             :                 }
    5174             :             | RESTART
    5175             :                 {
    5176           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5177             :                 }
    5178             :             | RESTART opt_with NumericOnly
    5179             :                 {
    5180          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5181             :                 }
    5182             :             | UNLOGGED
    5183             :                 {
    5184           2 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5185             :                 }
    5186             :         ;
    5187             : 
    5188             : opt_by:     BY
    5189             :             | /* EMPTY */
    5190             :       ;
    5191             : 
    5192             : NumericOnly:
    5193         324 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5194           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5195             :             | '-' FCONST
    5196             :                 {
    5197          20 :                     Float      *f = makeFloat($2);
    5198             : 
    5199          20 :                     doNegateFloat(f);
    5200          20 :                     $$ = (Node *) f;
    5201             :                 }
    5202       13258 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5203             :         ;
    5204             : 
    5205          90 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5206           6 :                 | 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         144 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5238             : 
    5239         144 :                 n->replace = $2;
    5240         144 :                 n->plname = $6;
    5241         144 :                 n->plhandler = $8;
    5242         144 :                 n->plinline = $9;
    5243         144 :                 n->plvalidator = $10;
    5244         144 :                 n->pltrusted = $3;
    5245         144 :                 $$ = (Node *) n;
    5246             :             }
    5247             :         ;
    5248             : 
    5249             : opt_trusted:
    5250         114 :             TRUSTED                                 { $$ = true; }
    5251          38 :             | /*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         576 :             name                        { $$ = list_make1(makeString($1)); }
    5260           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5261             :         ;
    5262             : 
    5263             : opt_inline_handler:
    5264         126 :             INLINE_P handler_name                   { $$ = $2; }
    5265          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5266             :         ;
    5267             : 
    5268             : validator_clause:
    5269         126 :             VALIDATOR handler_name                  { $$ = $2; }
    5270           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5271             :         ;
    5272             : 
    5273             : opt_validator:
    5274         126 :             validator_clause                        { $$ = $1; }
    5275          18 :             | /*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         132 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5293             : 
    5294         132 :                     n->tablespacename = $3;
    5295         132 :                     n->owner = $4;
    5296         132 :                     n->location = $6;
    5297         132 :                     n->options = $7;
    5298         132 :                     $$ = (Node *) n;
    5299             :                 }
    5300             :         ;
    5301             : 
    5302          10 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5303         122 :             | /*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          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5319             : 
    5320          64 :                     n->tablespacename = $3;
    5321          64 :                     n->missing_ok = false;
    5322          64 :                     $$ = (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         562 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5345             : 
    5346         562 :                     n->extname = $3;
    5347         562 :                     n->if_not_exists = false;
    5348         562 :                     n->options = $5;
    5349         562 :                     $$ = (Node *) n;
    5350             :                 }
    5351             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5352             :                 {
    5353          20 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5354             : 
    5355          20 :                     n->extname = $6;
    5356          20 :                     n->if_not_exists = true;
    5357          20 :                     n->options = $8;
    5358          20 :                     $$ = (Node *) n;
    5359             :                 }
    5360             :         ;
    5361             : 
    5362             : create_extension_opt_list:
    5363             :             create_extension_opt_list create_extension_opt_item
    5364          98 :                 { $$ = lappend($1, $2); }
    5365             :             | /* EMPTY */
    5366         582 :                 { $$ = NIL; }
    5367             :         ;
    5368             : 
    5369             : create_extension_opt_item:
    5370             :             SCHEMA name
    5371             :                 {
    5372          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5373             :                 }
    5374             :             | VERSION_P NonReservedWord_or_Sconst
    5375             :                 {
    5376          12 :                     $$ = 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          40 :                     $$ = 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          40 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5400             : 
    5401          40 :                     n->extname = $3;
    5402          40 :                     n->options = $5;
    5403          40 :                     $$ = (Node *) n;
    5404             :                 }
    5405             :         ;
    5406             : 
    5407             : alter_extension_opt_list:
    5408             :             alter_extension_opt_list alter_extension_opt_item
    5409          40 :                 { $$ = lappend($1, $2); }
    5410             :             | /* EMPTY */
    5411          40 :                 { $$ = NIL; }
    5412             :         ;
    5413             : 
    5414             : alter_extension_opt_item:
    5415             :             TO NonReservedWord_or_Sconst
    5416             :                 {
    5417          40 :                     $$ = 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          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5431             : 
    5432          18 :                     n->extname = $3;
    5433          18 :                     n->action = $4;
    5434          18 :                     n->objtype = $5;
    5435          18 :                     n->object = (Node *) makeString($6);
    5436          18 :                     $$ = (Node *) n;
    5437             :                 }
    5438             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5439             :                 {
    5440          88 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5441             : 
    5442          88 :                     n->extname = $3;
    5443          88 :                     n->action = $4;
    5444          88 :                     n->objtype = $5;
    5445          88 :                     n->object = (Node *) $6;
    5446          88 :                     $$ = (Node *) n;
    5447             :                 }
    5448             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5449             :                 {
    5450           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5451             : 
    5452           8 :                     n->extname = $3;
    5453           8 :                     n->action = $4;
    5454           8 :                     n->objtype = OBJECT_AGGREGATE;
    5455           8 :                     n->object = (Node *) $6;
    5456           8 :                     $$ = (Node *) n;
    5457             :                 }
    5458             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5459             :                 {
    5460           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5461             : 
    5462           4 :                     n->extname = $3;
    5463           4 :                     n->action = $4;
    5464           4 :                     n->objtype = OBJECT_CAST;
    5465           4 :                     n->object = (Node *) list_make2($7, $9);
    5466           4 :                     $$ = (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         120 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5481             : 
    5482         120 :                     n->extname = $3;
    5483         120 :                     n->action = $4;
    5484         120 :                     n->objtype = OBJECT_FUNCTION;
    5485         120 :                     n->object = (Node *) $6;
    5486         120 :                     $$ = (Node *) n;
    5487             :                 }
    5488             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5489             :                 {
    5490          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5491             : 
    5492          18 :                     n->extname = $3;
    5493          18 :                     n->action = $4;
    5494          18 :                     n->objtype = OBJECT_OPERATOR;
    5495          18 :                     n->object = (Node *) $6;
    5496          18 :                     $$ = (Node *) n;
    5497             :                 }
    5498             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5499             :                 {
    5500           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5501             : 
    5502           4 :                     n->extname = $3;
    5503           4 :                     n->action = $4;
    5504           4 :                     n->objtype = OBJECT_OPCLASS;
    5505           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5506           4 :                     $$ = (Node *) n;
    5507             :                 }
    5508             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5509             :                 {
    5510           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5511             : 
    5512           4 :                     n->extname = $3;
    5513           4 :                     n->action = $4;
    5514           4 :                     n->objtype = OBJECT_OPFAMILY;
    5515           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5516           4 :                     $$ = (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           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5541             : 
    5542           4 :                     n->extname = $3;
    5543           4 :                     n->action = $4;
    5544           4 :                     n->objtype = OBJECT_TRANSFORM;
    5545           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5546           4 :                     $$ = (Node *) n;
    5547             :                 }
    5548             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5549             :                 {
    5550           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5551             : 
    5552           8 :                     n->extname = $3;
    5553           8 :                     n->action = $4;
    5554           8 :                     n->objtype = OBJECT_TYPE;
    5555           8 :                     n->object = (Node *) $6;
    5556           8 :                     $$ = (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         208 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5570             : 
    5571         208 :                     n->fdwname = $5;
    5572         208 :                     n->func_options = $6;
    5573         208 :                     n->options = $7;
    5574         208 :                     $$ = (Node *) n;
    5575             :                 }
    5576             :         ;
    5577             : 
    5578             : fdw_option:
    5579          58 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5580           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5581          50 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5582           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5583             :         ;
    5584             : 
    5585             : fdw_options:
    5586          92 :             fdw_option                          { $$ = list_make1($1); }
    5587          22 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5588             :         ;
    5589             : 
    5590             : opt_fdw_options:
    5591          56 :             fdw_options                         { $$ = $1; }
    5592         244 :             | /*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          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5605             : 
    5606          86 :                     n->fdwname = $5;
    5607          86 :                     n->func_options = $6;
    5608          86 :                     n->options = $7;
    5609          86 :                     $$ = (Node *) n;
    5610             :                 }
    5611             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5612             :                 {
    5613          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5614             : 
    5615          36 :                     n->fdwname = $5;
    5616          36 :                     n->func_options = $6;
    5617          36 :                     n->options = NIL;
    5618          36 :                     $$ = (Node *) n;
    5619             :                 }
    5620             :         ;
    5621             : 
    5622             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5623             : create_generic_options:
    5624         772 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5625       70866 :             | /*EMPTY*/                                 { $$ = NIL; }
    5626             :         ;
    5627             : 
    5628             : generic_option_list:
    5629             :             generic_option_elem
    5630             :                 {
    5631         772 :                     $$ = list_make1($1);
    5632             :                 }
    5633             :             | generic_option_list ',' generic_option_elem
    5634             :                 {
    5635         496 :                     $$ = lappend($1, $3);
    5636             :                 }
    5637             :         ;
    5638             : 
    5639             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5640             : alter_generic_options:
    5641         508 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5642             :         ;
    5643             : 
    5644             : alter_generic_option_list:
    5645             :             alter_generic_option_elem
    5646             :                 {
    5647         508 :                     $$ = list_make1($1);
    5648             :                 }
    5649             :             | alter_generic_option_list ',' alter_generic_option_elem
    5650             :                 {
    5651         168 :                     $$ = lappend($1, $3);
    5652             :                 }
    5653             :         ;
    5654             : 
    5655             : alter_generic_option_elem:
    5656             :             generic_option_elem
    5657             :                 {
    5658         200 :                     $$ = $1;
    5659             :                 }
    5660             :             | SET generic_option_elem
    5661             :                 {
    5662         128 :                     $$ = $2;
    5663         128 :                     $$->defaction = DEFELEM_SET;
    5664             :                 }
    5665             :             | ADD_P generic_option_elem
    5666             :                 {
    5667         220 :                     $$ = $2;
    5668         220 :                     $$->defaction = DEFELEM_ADD;
    5669             :                 }
    5670             :             | DROP generic_option_name
    5671             :                 {
    5672         128 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5673             :                 }
    5674             :         ;
    5675             : 
    5676             : generic_option_elem:
    5677             :             generic_option_name generic_option_arg
    5678             :                 {
    5679        1816 :                     $$ = makeDefElem($1, $2, @1);
    5680             :                 }
    5681             :         ;
    5682             : 
    5683             : generic_option_name:
    5684        1944 :                 ColLabel            { $$ = $1; }
    5685             :         ;
    5686             : 
    5687             : /* We could use def_arg here, but the spec only requires string literals */
    5688             : generic_option_arg:
    5689        1816 :                 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         280 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5703             : 
    5704         280 :                     n->servername = $3;
    5705         280 :                     n->servertype = $4;
    5706         280 :                     n->version = $5;
    5707         280 :                     n->fdwname = $9;
    5708         280 :                     n->options = $10;
    5709         280 :                     n->if_not_exists = false;
    5710         280 :                     $$ = (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          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5716             : 
    5717          24 :                     n->servername = $6;
    5718          24 :                     n->servertype = $7;
    5719          24 :                     n->version = $8;
    5720          24 :                     n->fdwname = $12;
    5721          24 :                     n->options = $13;
    5722          24 :                     n->if_not_exists = true;
    5723          24 :                     $$ = (Node *) n;
    5724             :                 }
    5725             :         ;
    5726             : 
    5727             : opt_type:
    5728          18 :             TYPE_P Sconst           { $$ = $2; }
    5729         286 :             | /*EMPTY*/             { $$ = NULL; }
    5730             :         ;
    5731             : 
    5732             : 
    5733             : foreign_server_version:
    5734          66 :             VERSION_P Sconst        { $$ = $2; }
    5735           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5736             :         ;
    5737             : 
    5738             : opt_foreign_server_version:
    5739          18 :             foreign_server_version  { $$ = $1; }
    5740         286 :             | /*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           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5753             : 
    5754           6 :                     n->servername = $3;
    5755           6 :                     n->version = $4;
    5756           6 :                     n->options = $5;
    5757           6 :                     n->has_version = true;
    5758           6 :                     $$ = (Node *) n;
    5759             :                 }
    5760             :             | ALTER SERVER name foreign_server_version
    5761             :                 {
    5762          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5763             : 
    5764          42 :                     n->servername = $3;
    5765          42 :                     n->version = $4;
    5766          42 :                     n->has_version = true;
    5767          42 :                     $$ = (Node *) n;
    5768             :                 }
    5769             :             | ALTER SERVER name alter_generic_options
    5770             :                 {
    5771         184 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5772             : 
    5773         184 :                     n->servername = $3;
    5774         184 :                     n->options = $4;
    5775         184 :                     $$ = (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         420 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5792             : 
    5793         420 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5794         420 :                     n->base.relation = $4;
    5795         420 :                     n->base.tableElts = $6;
    5796         420 :                     n->base.inhRelations = $8;
    5797         420 :                     n->base.ofTypename = NULL;
    5798         420 :                     n->base.constraints = NIL;
    5799         420 :                     n->base.options = NIL;
    5800         420 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5801         420 :                     n->base.tablespacename = NULL;
    5802         420 :                     n->base.if_not_exists = false;
    5803             :                     /* FDW-specific data */
    5804         420 :                     n->servername = $10;
    5805         420 :                     n->options = $11;
    5806         420 :                     $$ = (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          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5834             : 
    5835          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5836          90 :                     n->base.relation = $4;
    5837          90 :                     n->base.inhRelations = list_make1($7);
    5838          90 :                     n->base.tableElts = $8;
    5839          90 :                     n->base.partbound = $9;
    5840          90 :                     n->base.ofTypename = NULL;
    5841          90 :                     n->base.constraints = NIL;
    5842          90 :                     n->base.options = NIL;
    5843          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5844          90 :                     n->base.tablespacename = NULL;
    5845          90 :                     n->base.if_not_exists = false;
    5846             :                     /* FDW-specific data */
    5847          90 :                     n->servername = $11;
    5848          90 :                     n->options = $12;
    5849          90 :                     $$ = (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          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5889             : 
    5890          48 :                 n->server_name = $8;
    5891          48 :                 n->remote_schema = $4;
    5892          48 :                 n->local_schema = $10;
    5893          48 :                 n->list_type = $5->type;
    5894          48 :                 n->table_list = $5->table_names;
    5895          48 :                 n->options = $11;
    5896          48 :                 $$ = (Node *) n;
    5897             :             }
    5898             :         ;
    5899             : 
    5900             : import_qualification_type:
    5901          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5902          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5903             :         ;
    5904             : 
    5905             : import_qualification:
    5906             :         import_qualification_type '(' relation_expr_list ')'
    5907             :             {
    5908          28 :                 ImportQual *n = palloc_object(ImportQual);
    5909             : 
    5910          28 :                 n->type = $1;
    5911          28 :                 n->table_names = $3;
    5912          28 :                 $$ = n;
    5913             :             }
    5914             :         | /*EMPTY*/
    5915             :             {
    5916          20 :                 ImportQual *n = palloc_object(ImportQual);
    5917          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5918          20 :                 n->table_names = NIL;
    5919          20 :                 $$ = 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         254 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5933             : 
    5934         254 :                     n->user = $5;
    5935         254 :                     n->servername = $7;
    5936         254 :                     n->options = $8;
    5937         254 :                     n->if_not_exists = false;
    5938         254 :                     $$ = (Node *) n;
    5939             :                 }
    5940             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5941             :                 {
    5942           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5943             : 
    5944           6 :                     n->user = $8;
    5945           6 :                     n->servername = $10;
    5946           6 :                     n->options = $11;
    5947           6 :                     n->if_not_exists = true;
    5948           6 :                     $$ = (Node *) n;
    5949             :                 }
    5950             :         ;
    5951             : 
    5952             : /* User mapping authorization identifier */
    5953         458 : auth_ident: RoleSpec            { $$ = $1; }
    5954          46 :             | 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          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5969             : 
    5970          88 :                     n->user = $5;
    5971          88 :                     n->servername = $7;
    5972          88 :                     n->missing_ok = false;
    5973          88 :                     $$ = (Node *) n;
    5974             :                 }
    5975             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5976             :                 {
    5977          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5978             : 
    5979          38 :                     n->user = $7;
    5980          38 :                     n->servername = $9;
    5981          38 :                     n->missing_ok = true;
    5982          38 :                     $$ = (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         118 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5996             : 
    5997         118 :                     n->user = $5;
    5998         118 :                     n->servername = $7;
    5999         118 :                     n->options = $8;
    6000         118 :                     $$ = (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         772 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    6023             : 
    6024         772 :                     n->policy_name = $3;
    6025         772 :                     n->table = $5;
    6026         772 :                     n->permissive = $6;
    6027         772 :                     n->cmd_name = $7;
    6028         772 :                     n->roles = $8;
    6029         772 :                     n->qual = $9;
    6030         772 :                     n->with_check = $10;
    6031         772 :                     $$ = (Node *) n;
    6032             :                 }
    6033             :         ;
    6034             : 
    6035             : AlterPolicyStmt:
    6036             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    6037             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    6038             :                 {
    6039          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    6040             : 
    6041          84 :                     n->policy_name = $3;
    6042          84 :                     n->table = $5;
    6043          84 :                     n->roles = $6;
    6044          84 :                     n->qual = $7;
    6045          84 :                     n->with_check = $8;
    6046          84 :                     $$ = (Node *) n;
    6047             :                 }
    6048             :         ;
    6049             : 
    6050             : RowSecurityOptionalExpr:
    6051         792 :             USING '(' a_expr ')'    { $$ = $3; }
    6052          64 :             | /* EMPTY */           { $$ = NULL; }
    6053             :         ;
    6054             : 
    6055             : RowSecurityOptionalWithCheck:
    6056         140 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    6057         716 :             | /* EMPTY */                   { $$ = NULL; }
    6058             :         ;
    6059             : 
    6060             : RowSecurityDefaultToRole:
    6061         130 :             TO role_list            { $$ = $2; }
    6062         642 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    6063             :         ;
    6064             : 
    6065             : RowSecurityOptionalToRole:
    6066          12 :             TO role_list            { $$ = $2; }
    6067          72 :             | /* EMPTY */           { $$ = NULL; }
    6068             :         ;
    6069             : 
    6070             : RowSecurityDefaultPermissive:
    6071             :             AS IDENT
    6072             :                 {
    6073          98 :                     if (strcmp($2, "permissive") == 0)
    6074          24 :                         $$ = true;
    6075          74 :                     else if (strcmp($2, "restrictive") == 0)
    6076          68 :                         $$ = false;
    6077             :                     else
    6078           6 :                         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         680 :             | /* EMPTY */           { $$ = true; }
    6086             :         ;
    6087             : 
    6088             : RowSecurityDefaultForCmd:
    6089         356 :             FOR row_security_cmd    { $$ = $2; }
    6090         416 :             | /* EMPTY */           { $$ = "all"; }
    6091             :         ;
    6092             : 
    6093             : row_security_cmd:
    6094          44 :             ALL             { $$ = "all"; }
    6095         124 :         |   SELECT          { $$ = "select"; }
    6096          50 :         |   INSERT          { $$ = "insert"; }
    6097          90 :         |   UPDATE          { $$ = "update"; }
    6098          48 :         |   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          74 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    6111             : 
    6112          74 :                     n->amname = $4;
    6113          74 :                     n->handler_name = $8;
    6114          74 :                     n->amtype = $6;
    6115          74 :                     $$ = (Node *) n;
    6116             :                 }
    6117             :         ;
    6118             : 
    6119             : am_type:
    6120          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    6121          40 :         |   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        3228 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6137             : 
    6138        3228 :                     n->replace = $2;
    6139        3228 :                     n->isconstraint = false;
    6140        3228 :                     n->trigname = $4;
    6141        3228 :                     n->relation = $8;
    6142        3228 :                     n->funcname = $14;
    6143        3228 :                     n->args = $16;
    6144        3228 :                     n->row = $10;
    6145        3228 :                     n->timing = $5;
    6146        3228 :                     n->events = intVal(linitial($6));
    6147        3228 :                     n->columns = (List *) lsecond($6);
    6148        3228 :                     n->whenClause = $11;
    6149        3228 :                     n->transitionRels = $9;
    6150        3228 :                     n->deferrable = false;
    6151        3228 :                     n->initdeferred = false;
    6152        3228 :                     n->constrrel = NULL;
    6153        3228 :                     $$ = (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          80 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6161             :                     bool        dummy;
    6162             : 
    6163          80 :                     if (($11 & CAS_NOT_VALID) != 0)
    6164           6 :                         ereport(ERROR,
    6165             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6166             :                                 errmsg("constraint triggers cannot be marked %s",
    6167             :                                        "NOT VALID"),
    6168             :                                 parser_errposition(@11));
    6169          74 :                     if (($11 & CAS_NO_INHERIT) != 0)
    6170           6 :                         ereport(ERROR,
    6171             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6172             :                                 errmsg("constraint triggers cannot be marked %s",
    6173             :                                        "NO INHERIT"),
    6174             :                                 parser_errposition(@11));
    6175          68 :                     if (($11 & CAS_NOT_ENFORCED) != 0)
    6176           6 :                         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          62 :                     n->replace = $2;
    6183          62 :                     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          62 :                     n->isconstraint = true;
    6189          62 :                     n->trigname = $5;
    6190          62 :                     n->relation = $9;
    6191          62 :                     n->funcname = $18;
    6192          62 :                     n->args = $20;
    6193          62 :                     n->row = true;
    6194          62 :                     n->timing = TRIGGER_TYPE_AFTER;
    6195          62 :                     n->events = intVal(linitial($7));
    6196          62 :                     n->columns = (List *) lsecond($7);
    6197          62 :                     n->whenClause = $15;
    6198          62 :                     n->transitionRels = NIL;
    6199          62 :                     processCASbits($11, @11, "TRIGGER",
    6200             :                                    &n->deferrable, &n->initdeferred, &dummy,
    6201             :                                    NULL, NULL, yyscanner);
    6202          62 :                     n->constrrel = $10;
    6203          62 :                     $$ = (Node *) n;
    6204             :                 }
    6205             :         ;
    6206             : 
    6207             : TriggerActionTime:
    6208        1472 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6209        1624 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6210         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6211             :         ;
    6212             : 
    6213             : TriggerEvents:
    6214             :             TriggerOneEvent
    6215        3320 :                 { $$ = $1; }
    6216             :             | TriggerEvents OR TriggerOneEvent
    6217             :                 {
    6218        1162 :                     int         events1 = intVal(linitial($1));
    6219        1162 :                     int         events2 = intVal(linitial($3));
    6220        1162 :                     List       *columns1 = (List *) lsecond($1);
    6221        1162 :                     List       *columns2 = (List *) lsecond($3);
    6222             : 
    6223        1162 :                     if (events1 & events2)
    6224           6 :                         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        1156 :                     $$ = list_make2(makeInteger(events1 | events2),
    6233             :                                     list_concat(columns1, columns2));
    6234             :                 }
    6235             :         ;
    6236             : 
    6237             : TriggerOneEvent:
    6238             :             INSERT
    6239        1734 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6240             :             | DELETE_P
    6241         886 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6242             :             | UPDATE
    6243        1724 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6244             :             | UPDATE OF columnList
    6245         100 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6246             :             | TRUNCATE
    6247          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6248             :         ;
    6249             : 
    6250             : TriggerReferencing:
    6251         464 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6252        2764 :             | /*EMPTY*/                             { $$ = NIL; }
    6253             :         ;
    6254             : 
    6255             : TriggerTransitions:
    6256         464 :             TriggerTransition                       { $$ = list_make1($1); }
    6257         142 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6258             :         ;
    6259             : 
    6260             : TriggerTransition:
    6261             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6262             :                 {
    6263         606 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6264             : 
    6265         606 :                     n->name = $4;
    6266         606 :                     n->isNew = $1;
    6267         606 :                     n->isTable = $2;
    6268         606 :                     $$ = (Node *) n;
    6269             :                 }
    6270             :         ;
    6271             : 
    6272             : TransitionOldOrNew:
    6273         330 :             NEW                                     { $$ = true; }
    6274         276 :             | OLD                                   { $$ = false; }
    6275             :         ;
    6276             : 
    6277             : TransitionRowOrTable:
    6278         606 :             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         606 :             ColId                                   { $$ = $1; }
    6292             :         ;
    6293             : 
    6294             : TriggerForSpec:
    6295             :             FOR TriggerForOptEach TriggerForType
    6296             :                 {
    6297        2988 :                     $$ = $3;
    6298             :                 }
    6299             :             | /* EMPTY */
    6300             :                 {
    6301             :                     /*
    6302             :                      * If ROW/STATEMENT not specified, default to
    6303             :                      * STATEMENT, per SQL
    6304             :                      */
    6305         240 :                     $$ = false;
    6306             :                 }
    6307             :         ;
    6308             : 
    6309             : TriggerForOptEach:
    6310             :             EACH
    6311             :             | /*EMPTY*/
    6312             :         ;
    6313             : 
    6314             : TriggerForType:
    6315        2156 :             ROW                                     { $$ = true; }
    6316         832 :             | STATEMENT                             { $$ = false; }
    6317             :         ;
    6318             : 
    6319             : TriggerWhen:
    6320         190 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6321        3118 :             | /*EMPTY*/                             { $$ = NULL; }
    6322             :         ;
    6323             : 
    6324             : FUNCTION_or_PROCEDURE:
    6325             :             FUNCTION
    6326             :         |   PROCEDURE
    6327             :         ;
    6328             : 
    6329             : TriggerFuncArgs:
    6330         600 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6331         162 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6332        2708 :             | /*EMPTY*/                             { $$ = NIL; }
    6333             :         ;
    6334             : 
    6335             : TriggerFuncArg:
    6336             :             Iconst
    6337             :                 {
    6338          94 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6339             :                 }
    6340           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6341         646 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6342          22 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6343             :         ;
    6344             : 
    6345             : OptConstrFromTable:
    6346          12 :             FROM qualified_name                     { $$ = $2; }
    6347          68 :             | /*EMPTY*/                             { $$ = NULL; }
    6348             :         ;
    6349             : 
    6350             : ConstraintAttributeSpec:
    6351             :             /*EMPTY*/
    6352       18244 :                 { $$ = 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        1736 :                     int     newspec = $1 | $2;
    6361             : 
    6362             :                     /* special message for this case */
    6363        1736 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6364           6 :                         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        1730 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6370        1730 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6371        1730 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6372           6 :                         ereport(ERROR,
    6373             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6374             :                                  errmsg("conflicting constraint properties"),
    6375             :                                  parser_errposition(@2)));
    6376        1724 :                     $$ = newspec;
    6377             :                 }
    6378             :         ;
    6379             : 
    6380             : ConstraintAttributeElem:
    6381          42 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6382         200 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6383          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6384         152 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6385         762 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6386         250 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6387         186 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6388         114 :             | 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         102 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6405             : 
    6406         102 :                     n->trigname = $4;
    6407         102 :                     n->eventname = $6;
    6408         102 :                     n->whenclause = NULL;
    6409         102 :                     n->funcname = $9;
    6410         102 :                     $$ = (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          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6417             : 
    6418          98 :                     n->trigname = $4;
    6419          98 :                     n->eventname = $6;
    6420          98 :                     n->whenclause = $8;
    6421          98 :                     n->funcname = $11;
    6422          98 :                     $$ = (Node *) n;
    6423             :                 }
    6424             :         ;
    6425             : 
    6426             : event_trigger_when_list:
    6427             :           event_trigger_when_item
    6428          98 :             { $$ = list_make1($1); }
    6429             :         | event_trigger_when_list AND event_trigger_when_item
    6430           6 :             { $$ = lappend($1, $3); }
    6431             :         ;
    6432             : 
    6433             : event_trigger_when_item:
    6434             :         ColId IN_P '(' event_trigger_value_list ')'
    6435         104 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6436             :         ;
    6437             : 
    6438             : event_trigger_value_list:
    6439             :           SCONST
    6440         104 :             { $$ = list_make1(makeString($1)); }
    6441             :         | event_trigger_value_list ',' SCONST
    6442          66 :             { $$ = lappend($1, makeString($3)); }
    6443             :         ;
    6444             : 
    6445             : AlterEventTrigStmt:
    6446             :             ALTER EVENT TRIGGER name enable_trigger
    6447             :                 {
    6448          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6449             : 
    6450          48 :                     n->trigname = $4;
    6451          48 :                     n->tgenabled = $5;
    6452          48 :                     $$ = (Node *) n;
    6453             :                 }
    6454             :         ;
    6455             : 
    6456             : enable_trigger:
    6457           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6458           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6459          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6460          20 :             | 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         544 :                     DefineStmt *n = makeNode(DefineStmt);
    6494             : 
    6495         544 :                     n->kind = OBJECT_AGGREGATE;
    6496         544 :                     n->oldstyle = false;
    6497         544 :                     n->replace = $2;
    6498         544 :                     n->defnames = $4;
    6499         544 :                     n->args = $5;
    6500         544 :                     n->definition = $6;
    6501         544 :                     $$ = (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         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6507             : 
    6508         362 :                     n->kind = OBJECT_AGGREGATE;
    6509         362 :                     n->oldstyle = true;
    6510         362 :                     n->replace = $2;
    6511         362 :                     n->defnames = $4;
    6512         362 :                     n->args = NIL;
    6513         362 :                     n->definition = $5;
    6514         362 :                     $$ = (Node *) n;
    6515             :                 }
    6516             :             | CREATE OPERATOR any_operator definition
    6517             :                 {
    6518        1642 :                     DefineStmt *n = makeNode(DefineStmt);
    6519             : 
    6520        1642 :                     n->kind = OBJECT_OPERATOR;
    6521        1642 :                     n->oldstyle = false;
    6522        1642 :                     n->defnames = $3;
    6523        1642 :                     n->args = NIL;
    6524        1642 :                     n->definition = $4;
    6525        1642 :                     $$ = (Node *) n;
    6526             :                 }
    6527             :             | CREATE TYPE_P any_name definition
    6528             :                 {
    6529         240 :                     DefineStmt *n = makeNode(DefineStmt);
    6530             : 
    6531         240 :                     n->kind = OBJECT_TYPE;
    6532         240 :                     n->oldstyle = false;
    6533         240 :                     n->defnames = $3;
    6534         240 :                     n->args = NIL;
    6535         240 :                     n->definition = $4;
    6536         240 :                     $$ = (Node *) n;
    6537             :                 }
    6538             :             | CREATE TYPE_P any_name
    6539             :                 {
    6540             :                     /* Shell type (identified by lack of definition) */
    6541         156 :                     DefineStmt *n = makeNode(DefineStmt);
    6542             : 
    6543         156 :                     n->kind = OBJECT_TYPE;
    6544         156 :                     n->oldstyle = false;
    6545         156 :                     n->defnames = $3;
    6546         156 :                     n->args = NIL;
    6547         156 :                     n->definition = NIL;
    6548         156 :                     $$ = (Node *) n;
    6549             :                 }
    6550             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6551             :                 {
    6552        4502 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6553             : 
    6554             :                     /* can't use qualified_name, sigh */
    6555        4502 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6556        4502 :                     n->coldeflist = $6;
    6557        4502 :                     $$ = (Node *) n;
    6558             :                 }
    6559             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6560             :                 {
    6561         208 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6562             : 
    6563         208 :                     n->typeName = $3;
    6564         208 :                     n->vals = $7;
    6565         208 :                     $$ = (Node *) n;
    6566             :                 }
    6567             :             | CREATE TYPE_P any_name AS RANGE definition
    6568             :                 {
    6569         184 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6570             : 
    6571         184 :                     n->typeName = $3;
    6572         184 :                     n->params = $6;
    6573         184 :                     $$ = (Node *) n;
    6574             :                 }
    6575             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6576             :                 {
    6577          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6578             : 
    6579          40 :                     n->kind = OBJECT_TSPARSER;
    6580          40 :                     n->args = NIL;
    6581          40 :                     n->defnames = $5;
    6582          40 :                     n->definition = $6;
    6583          40 :                     $$ = (Node *) n;
    6584             :                 }
    6585             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6586             :                 {
    6587        3184 :                     DefineStmt *n = makeNode(DefineStmt);
    6588             : 
    6589        3184 :                     n->kind = OBJECT_TSDICTIONARY;
    6590        3184 :                     n->args = NIL;
    6591        3184 :                     n->defnames = $5;
    6592        3184 :                     n->definition = $6;
    6593        3184 :                     $$ = (Node *) n;
    6594             :                 }
    6595             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6596             :                 {
    6597         142 :                     DefineStmt *n = makeNode(DefineStmt);
    6598             : 
    6599         142 :                     n->kind = OBJECT_TSTEMPLATE;
    6600         142 :                     n->args = NIL;
    6601         142 :                     n->defnames = $5;
    6602         142 :                     n->definition = $6;
    6603         142 :                     $$ = (Node *) n;
    6604             :                 }
    6605             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6606             :                 {
    6607        3126 :                     DefineStmt *n = makeNode(DefineStmt);
    6608             : 
    6609        3126 :                     n->kind = OBJECT_TSCONFIGURATION;
    6610        3126 :                     n->args = NIL;
    6611        3126 :                     n->defnames = $5;
    6612        3126 :                     n->definition = $6;
    6613        3126 :                     $$ = (Node *) n;
    6614             :                 }
    6615             :             | CREATE COLLATION any_name definition
    6616             :                 {
    6617         292 :                     DefineStmt *n = makeNode(DefineStmt);
    6618             : 
    6619         292 :                     n->kind = OBJECT_COLLATION;
    6620         292 :                     n->args = NIL;
    6621         292 :                     n->defnames = $3;
    6622         292 :                     n->definition = $4;
    6623         292 :                     $$ = (Node *) n;
    6624             :                 }
    6625             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6626             :                 {
    6627          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6628             : 
    6629          18 :                     n->kind = OBJECT_COLLATION;
    6630          18 :                     n->args = NIL;
    6631          18 :                     n->defnames = $6;
    6632          18 :                     n->definition = $7;
    6633          18 :                     n->if_not_exists = true;
    6634          18 :                     $$ = (Node *) n;
    6635             :                 }
    6636             :             | CREATE COLLATION any_name FROM any_name
    6637             :                 {
    6638          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6639             : 
    6640          54 :                     n->kind = OBJECT_COLLATION;
    6641          54 :                     n->args = NIL;
    6642          54 :                     n->defnames = $3;
    6643          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6644          54 :                     $$ = (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       10484 : definition: '(' def_list ')'                        { $$ = $2; }
    6660             :         ;
    6661             : 
    6662       10484 : def_list:   def_elem                                { $$ = list_make1($1); }
    6663       15104 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6664             :         ;
    6665             : 
    6666             : def_elem:   ColLabel '=' def_arg
    6667             :                 {
    6668       25250 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6669             :                 }
    6670             :             | ColLabel
    6671             :                 {
    6672         338 :                     $$ = makeDefElem($1, NULL, @1);
    6673             :                 }
    6674             :         ;
    6675             : 
    6676             : /* Note: any simple identifier will be returned as a type name! */
    6677       20276 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6678        4482 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6679        1176 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6680        1356 :             | NumericOnly                   { $$ = (Node *) $1; }
    6681        1908 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6682         182 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6683             :         ;
    6684             : 
    6685         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6686             :         ;
    6687             : 
    6688         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6689        1292 :             | 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        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6700             :                 }
    6701             :         ;
    6702             : 
    6703             : opt_enum_val_list:
    6704         200 :         enum_val_list                           { $$ = $1; }
    6705           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6706             :         ;
    6707             : 
    6708             : enum_val_list:  Sconst
    6709         200 :                 { $$ = list_make1(makeString($1)); }
    6710             :             | enum_val_list ',' Sconst
    6711       10420 :                 { $$ = 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         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6724             : 
    6725         154 :                 n->typeName = $3;
    6726         154 :                 n->oldVal = NULL;
    6727         154 :                 n->newVal = $7;
    6728         154 :                 n->newValNeighbor = NULL;
    6729         154 :                 n->newValIsAfter = true;
    6730         154 :                 n->skipIfNewValExists = $6;
    6731         154 :                 $$ = (Node *) n;
    6732             :             }
    6733             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6734             :             {
    6735         196 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6736             : 
    6737         196 :                 n->typeName = $3;
    6738         196 :                 n->oldVal = NULL;
    6739         196 :                 n->newVal = $7;
    6740         196 :                 n->newValNeighbor = $9;
    6741         196 :                 n->newValIsAfter = false;
    6742         196 :                 n->skipIfNewValExists = $6;
    6743         196 :                 $$ = (Node *) n;
    6744             :             }
    6745             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6746             :             {
    6747          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6748             : 
    6749          22 :                 n->typeName = $3;
    6750          22 :                 n->oldVal = NULL;
    6751          22 :                 n->newVal = $7;
    6752          22 :                 n->newValNeighbor = $9;
    6753          22 :                 n->newValIsAfter = true;
    6754          22 :                 n->skipIfNewValExists = $6;
    6755          22 :                 $$ = (Node *) n;
    6756             :             }
    6757             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6758             :             {
    6759          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6760             : 
    6761          24 :                 n->typeName = $3;
    6762          24 :                 n->oldVal = $6;
    6763          24 :                 n->newVal = $8;
    6764          24 :                 n->newValNeighbor = NULL;
    6765          24 :                 n->newValIsAfter = false;
    6766          24 :                 n->skipIfNewValExists = false;
    6767          24 :                 $$ = (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          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6799         360 :         | /* 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         556 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6819             : 
    6820         556 :                     n->opclassname = $4;
    6821         556 :                     n->isDefault = $5;
    6822         556 :                     n->datatype = $8;
    6823         556 :                     n->amname = $10;
    6824         556 :                     n->opfamilyname = $11;
    6825         556 :                     n->items = $13;
    6826         556 :                     $$ = (Node *) n;
    6827             :                 }
    6828             :         ;
    6829             : 
    6830             : opclass_item_list:
    6831         950 :             opclass_item                            { $$ = list_make1($1); }
    6832        5850 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6833             :         ;
    6834             : 
    6835             : opclass_item:
    6836             :             OPERATOR Iconst any_operator opclass_purpose
    6837             :                 {
    6838        2082 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6839        2082 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6840             : 
    6841        2082 :                     owa->objname = $3;
    6842        2082 :                     owa->objargs = NIL;
    6843        2082 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6844        2082 :                     n->name = owa;
    6845        2082 :                     n->number = $2;
    6846        2082 :                     n->order_family = $4;
    6847        2082 :                     $$ = (Node *) n;
    6848             :                 }
    6849             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6850             :                 {
    6851        1354 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6852             : 
    6853        1354 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6854        1354 :                     n->name = $3;
    6855        1354 :                     n->number = $2;
    6856        1354 :                     n->order_family = $4;
    6857        1354 :                     $$ = (Node *) n;
    6858             :                 }
    6859             :             | FUNCTION Iconst function_with_argtypes
    6860             :                 {
    6861        2774 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6862             : 
    6863        2774 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6864        2774 :                     n->name = $3;
    6865        2774 :                     n->number = $2;
    6866        2774 :                     $$ = (Node *) n;
    6867             :                 }
    6868             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6869             :                 {
    6870         230 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6871             : 
    6872         230 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6873         230 :                     n->name = $6;
    6874         230 :                     n->number = $2;
    6875         230 :                     n->class_args = $4;
    6876         230 :                     $$ = (Node *) n;
    6877             :                 }
    6878             :             | STORAGE Typename
    6879             :                 {
    6880         360 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6881             : 
    6882         360 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6883         360 :                     n->storedtype = $2;
    6884         360 :                     $$ = (Node *) n;
    6885             :                 }
    6886             :         ;
    6887             : 
    6888         440 : opt_default:    DEFAULT                     { $$ = true; }
    6889         180 :             | /*EMPTY*/                     { $$ = false; }
    6890             :         ;
    6891             : 
    6892          44 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6893         512 :             | /*EMPTY*/                     { $$ = NIL; }
    6894             :         ;
    6895             : 
    6896           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6897         120 :             | FOR ORDER BY any_name         { $$ = $4; }
    6898        3316 :             | /*EMPTY*/                     { $$ = NIL; }
    6899             :         ;
    6900             : 
    6901             : 
    6902             : CreateOpFamilyStmt:
    6903             :             CREATE OPERATOR FAMILY any_name USING name
    6904             :                 {
    6905         148 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6906             : 
    6907         148 :                     n->opfamilyname = $4;
    6908         148 :                     n->amname = $6;
    6909         148 :                     $$ = (Node *) n;
    6910             :                 }
    6911             :         ;
    6912             : 
    6913             : AlterOpFamilyStmt:
    6914             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6915             :                 {
    6916         394 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6917             : 
    6918         394 :                     n->opfamilyname = $4;
    6919         394 :                     n->amname = $6;
    6920         394 :                     n->isDrop = false;
    6921         394 :                     n->items = $8;
    6922         394 :                     $$ = (Node *) n;
    6923             :                 }
    6924             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6925             :                 {
    6926          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6927             : 
    6928          64 :                     n->opfamilyname = $4;
    6929          64 :                     n->amname = $6;
    6930          64 :                     n->isDrop = true;
    6931          64 :                     n->items = $8;
    6932          64 :                     $$ = (Node *) n;
    6933             :                 }
    6934             :         ;
    6935             : 
    6936             : opclass_drop_list:
    6937          64 :             opclass_drop                            { $$ = list_make1($1); }
    6938          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6939             :         ;
    6940             : 
    6941             : opclass_drop:
    6942             :             OPERATOR Iconst '(' type_list ')'
    6943             :                 {
    6944          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6945             : 
    6946          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6947          56 :                     n->number = $2;
    6948          56 :                     n->class_args = $4;
    6949          56 :                     $$ = (Node *) n;
    6950             :                 }
    6951             :             | FUNCTION Iconst '(' type_list ')'
    6952             :                 {
    6953          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6954             : 
    6955          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6956          38 :                     n->number = $2;
    6957          38 :                     n->class_args = $4;
    6958          38 :                     $$ = (Node *) n;
    6959             :                 }
    6960             :         ;
    6961             : 
    6962             : 
    6963             : DropOpClassStmt:
    6964             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6965             :                 {
    6966          38 :                     DropStmt *n = makeNode(DropStmt);
    6967             : 
    6968          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6969          38 :                     n->removeType = OBJECT_OPCLASS;
    6970          38 :                     n->behavior = $7;
    6971          38 :                     n->missing_ok = false;
    6972          38 :                     n->concurrent = false;
    6973          38 :                     $$ = (Node *) n;
    6974             :                 }
    6975             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6976             :                 {
    6977          18 :                     DropStmt *n = makeNode(DropStmt);
    6978             : 
    6979          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6980          18 :                     n->removeType = OBJECT_OPCLASS;
    6981          18 :                     n->behavior = $9;
    6982          18 :                     n->missing_ok = true;
    6983          18 :                     n->concurrent = false;
    6984          18 :                     $$ = (Node *) n;
    6985             :                 }
    6986             :         ;
    6987             : 
    6988             : DropOpFamilyStmt:
    6989             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6990             :                 {
    6991         110 :                     DropStmt *n = makeNode(DropStmt);
    6992             : 
    6993         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6994         110 :                     n->removeType = OBJECT_OPFAMILY;
    6995         110 :                     n->behavior = $7;
    6996         110 :                     n->missing_ok = false;
    6997         110 :                     n->concurrent = false;
    6998         110 :                     $$ = (Node *) n;
    6999             :                 }
    7000             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    7001             :                 {
    7002          18 :                     DropStmt *n = makeNode(DropStmt);
    7003             : 
    7004          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    7005          18 :                     n->removeType = OBJECT_OPFAMILY;
    7006          18 :                     n->behavior = $9;
    7007          18 :                     n->missing_ok = true;
    7008          18 :                     n->concurrent = false;
    7009          18 :                     $$ = (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         148 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    7026             : 
    7027         148 :                     n->roles = $4;
    7028         148 :                     n->behavior = $5;
    7029         148 :                     $$ = (Node *) n;
    7030             :                 }
    7031             :         ;
    7032             : 
    7033             : ReassignOwnedStmt:
    7034             :             REASSIGN OWNED BY role_list TO RoleSpec
    7035             :                 {
    7036          46 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    7037             : 
    7038          46 :                     n->roles = $4;
    7039          46 :                     n->newrole = $6;
    7040          46 :                     $$ = (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        1396 :                     DropStmt *n = makeNode(DropStmt);
    7056             : 
    7057        1396 :                     n->removeType = $2;
    7058        1396 :                     n->missing_ok = true;
    7059        1396 :                     n->objects = $5;
    7060        1396 :                     n->behavior = $6;
    7061        1396 :                     n->concurrent = false;
    7062        1396 :                     $$ = (Node *) n;
    7063             :                 }
    7064             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    7065             :                 {
    7066       17008 :                     DropStmt *n = makeNode(DropStmt);
    7067             : 
    7068       17008 :                     n->removeType = $2;
    7069       17008 :                     n->missing_ok = false;
    7070       17008 :                     n->objects = $3;
    7071       17008 :                     n->behavior = $4;
    7072       17008 :                     n->concurrent = false;
    7073       17008 :                     $$ = (Node *) n;
    7074             :                 }
    7075             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    7076             :                 {
    7077          86 :                     DropStmt *n = makeNode(DropStmt);
    7078             : 
    7079          86 :                     n->removeType = $2;
    7080          86 :                     n->missing_ok = true;
    7081          86 :                     n->objects = $5;
    7082          86 :                     n->behavior = $6;
    7083          86 :                     n->concurrent = false;
    7084          86 :                     $$ = (Node *) n;
    7085             :                 }
    7086             :             | DROP drop_type_name name_list opt_drop_behavior
    7087             :                 {
    7088        1514 :                     DropStmt *n = makeNode(DropStmt);
    7089             : 
    7090        1514 :                     n->removeType = $2;
    7091        1514 :                     n->missing_ok = false;
    7092        1514 :                     n->objects = $3;
    7093        1514 :                     n->behavior = $4;
    7094        1514 :                     n->concurrent = false;
    7095        1514 :                     $$ = (Node *) n;
    7096             :                 }
    7097             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    7098             :                 {
    7099        1130 :                     DropStmt *n = makeNode(DropStmt);
    7100             : 
    7101        1130 :                     n->removeType = $2;
    7102        1130 :                     n->objects = list_make1(lappend($5, makeString($3)));
    7103        1130 :                     n->behavior = $6;
    7104        1130 :                     n->missing_ok = false;
    7105        1130 :                     n->concurrent = false;
    7106        1130 :                     $$ = (Node *) n;
    7107             :                 }
    7108             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    7109             :                 {
    7110          48 :                     DropStmt *n = makeNode(DropStmt);
    7111             : 
    7112          48 :                     n->removeType = $2;
    7113          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    7114          48 :                     n->behavior = $8;
    7115          48 :                     n->missing_ok = true;
    7116          48 :                     n->concurrent = false;
    7117          48 :                     $$ = (Node *) n;
    7118             :                 }
    7119             :             | DROP TYPE_P type_name_list opt_drop_behavior
    7120             :                 {
    7121         560 :                     DropStmt *n = makeNode(DropStmt);
    7122             : 
    7123         560 :                     n->removeType = OBJECT_TYPE;
    7124         560 :                     n->missing_ok = false;
    7125         560 :                     n->objects = $3;
    7126         560 :                     n->behavior = $4;
    7127         560 :                     n->concurrent = false;
    7128         560 :                     $$ = (Node *) n;
    7129             :                 }
    7130             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    7131             :                 {
    7132          26 :                     DropStmt *n = makeNode(DropStmt);
    7133             : 
    7134          26 :                     n->removeType = OBJECT_TYPE;
    7135          26 :                     n->missing_ok = true;
    7136          26 :                     n->objects = $5;
    7137          26 :                     n->behavior = $6;
    7138          26 :                     n->concurrent = false;
    7139          26 :                     $$ = (Node *) n;
    7140             :                 }
    7141             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    7142             :                 {
    7143         470 :                     DropStmt *n = makeNode(DropStmt);
    7144             : 
    7145         470 :                     n->removeType = OBJECT_DOMAIN;
    7146         470 :                     n->missing_ok = false;
    7147         470 :                     n->objects = $3;
    7148         470 :                     n->behavior = $4;
    7149         470 :                     n->concurrent = false;
    7150         470 :                     $$ = (Node *) n;
    7151             :                 }
    7152             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7153             :                 {
    7154          18 :                     DropStmt *n = makeNode(DropStmt);
    7155             : 
    7156          18 :                     n->removeType = OBJECT_DOMAIN;
    7157          18 :                     n->missing_ok = true;
    7158          18 :                     n->objects = $5;
    7159          18 :                     n->behavior = $6;
    7160          18 :                     n->concurrent = false;
    7161          18 :                     $$ = (Node *) n;
    7162             :                 }
    7163             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7164             :                 {
    7165         190 :                     DropStmt *n = makeNode(DropStmt);
    7166             : 
    7167         190 :                     n->removeType = OBJECT_INDEX;
    7168         190 :                     n->missing_ok = false;
    7169         190 :                     n->objects = $4;
    7170         190 :                     n->behavior = $5;
    7171         190 :                     n->concurrent = true;
    7172         190 :                     $$ = (Node *) n;
    7173             :                 }
    7174             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7175             :                 {
    7176          12 :                     DropStmt *n = makeNode(DropStmt);
    7177             : 
    7178          12 :                     n->removeType = OBJECT_INDEX;
    7179          12 :                     n->missing_ok = true;
    7180          12 :                     n->objects = $6;
    7181          12 :                     n->behavior = $7;
    7182          12 :                     n->concurrent = true;
    7183          12 :                     $$ = (Node *) n;
    7184             :                 }
    7185             :         ;
    7186             : 
    7187             : /* object types taking any_name/any_name_list */
    7188             : object_type_any_name:
    7189       15966 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7190         200 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7191        1054 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7192         130 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7193         778 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7194         186 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7195          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7196          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7197         222 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7198          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7199        3068 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7200         118 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7201        3072 :             | 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         256 :             drop_type_name                          { $$ = $1; }
    7212         246 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7213          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7214          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7215           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7216             :         ;
    7217             : 
    7218             : drop_type_name:
    7219          58 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7220         128 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7221         184 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7222         154 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7223         156 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7224         408 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7225         630 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7226         138 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7227             :         ;
    7228             : 
    7229             : /* object types attached to a table */
    7230             : object_type_name_on_any_name:
    7231         166 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7232         268 :             | RULE                                  { $$ = OBJECT_RULE; }
    7233         798 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7234             :         ;
    7235             : 
    7236             : any_name_list:
    7237       28050 :             any_name                                { $$ = list_make1($1); }
    7238        4270 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7239             :         ;
    7240             : 
    7241       70908 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7242        9200 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7243             :         ;
    7244             : 
    7245             : attrs:      '.' attr_name
    7246      127352 :                     { $$ = list_make1(makeString($2)); }
    7247             :             | attrs '.' attr_name
    7248          64 :                     { $$ = lappend($1, makeString($3)); }
    7249             :         ;
    7250             : 
    7251             : type_name_list:
    7252        1074 :             Typename                                { $$ = list_make1($1); }
    7253         102 :             | 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        1798 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7267             : 
    7268        1798 :                     n->relations = $3;
    7269        1798 :                     n->restart_seqs = $4;
    7270        1798 :                     n->behavior = $5;
    7271        1798 :                     $$ = (Node *) n;
    7272             :                 }
    7273             :         ;
    7274             : 
    7275             : opt_restart_seqs:
    7276          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7277          22 :             | RESTART IDENTITY_P        { $$ = true; }
    7278        1752 :             | /* 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        6408 :                     CommentStmt *n = makeNode(CommentStmt);
    7291             : 
    7292        6408 :                     n->objtype = $3;
    7293        6408 :                     n->object = (Node *) $4;
    7294        6408 :                     n->comment = $6;
    7295        6408 :                     $$ = (Node *) n;
    7296             :                 }
    7297             :             | COMMENT ON COLUMN any_name IS comment_text
    7298             :                 {
    7299         144 :                     CommentStmt *n = makeNode(CommentStmt);
    7300             : 
    7301         144 :                     n->objtype = OBJECT_COLUMN;
    7302         144 :                     n->object = (Node *) $4;
    7303         144 :                     n->comment = $6;
    7304         144 :                     $$ = (Node *) n;
    7305             :                 }
    7306             :             | COMMENT ON object_type_name name IS comment_text
    7307             :                 {
    7308         502 :                     CommentStmt *n = makeNode(CommentStmt);
    7309             : 
    7310         502 :                     n->objtype = $3;
    7311         502 :                     n->object = (Node *) makeString($4);
    7312         502 :                     n->comment = $6;
    7313         502 :                     $$ = (Node *) n;
    7314             :                 }
    7315             :             | COMMENT ON TYPE_P Typename IS comment_text
    7316             :                 {
    7317          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7318             : 
    7319          56 :                     n->objtype = OBJECT_TYPE;
    7320          56 :                     n->object = (Node *) $4;
    7321          56 :                     n->comment = $6;
    7322          56 :                     $$ = (Node *) n;
    7323             :                 }
    7324             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7325             :                 {
    7326           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7327             : 
    7328           8 :                     n->objtype = OBJECT_DOMAIN;
    7329           8 :                     n->object = (Node *) $4;
    7330           8 :                     n->comment = $6;
    7331           8 :                     $$ = (Node *) n;
    7332             :                 }
    7333             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7334             :                 {
    7335          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7336             : 
    7337          40 :                     n->objtype = OBJECT_AGGREGATE;
    7338          40 :                     n->object = (Node *) $4;
    7339          40 :                     n->comment = $6;
    7340          40 :                     $$ = (Node *) n;
    7341             :                 }
    7342             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7343             :                 {
    7344         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7345             : 
    7346         170 :                     n->objtype = OBJECT_FUNCTION;
    7347         170 :                     n->object = (Node *) $4;
    7348         170 :                     n->comment = $6;
    7349         170 :                     $$ = (Node *) n;
    7350             :                 }
    7351             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7352             :                 {
    7353          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7354             : 
    7355          18 :                     n->objtype = OBJECT_OPERATOR;
    7356          18 :                     n->object = (Node *) $4;
    7357          18 :                     n->comment = $6;
    7358          18 :                     $$ = (Node *) n;
    7359             :                 }
    7360             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7361             :                 {
    7362         150 :                     CommentStmt *n = makeNode(CommentStmt);
    7363             : 
    7364         150 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7365         150 :                     n->object = (Node *) lappend($6, makeString($4));
    7366         150 :                     n->comment = $8;
    7367         150 :                     $$ = (Node *) n;
    7368             :                 }
    7369             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7370             :                 {
    7371          48 :                     CommentStmt *n = makeNode(CommentStmt);
    7372             : 
    7373          48 :                     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          48 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7380          48 :                     n->comment = $9;
    7381          48 :                     $$ = (Node *) n;
    7382             :                 }
    7383             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7384             :                 {
    7385          42 :                     CommentStmt *n = makeNode(CommentStmt);
    7386             : 
    7387          42 :                     n->objtype = $3;
    7388          42 :                     n->object = (Node *) lappend($6, makeString($4));
    7389          42 :                     n->comment = $8;
    7390          42 :                     $$ = (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          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7413             : 
    7414          14 :                     n->objtype = OBJECT_TRANSFORM;
    7415          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7416          14 :                     n->comment = $9;
    7417          14 :                     $$ = (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          42 :                     CommentStmt *n = makeNode(CommentStmt);
    7440             : 
    7441          42 :                     n->objtype = OBJECT_LARGEOBJECT;
    7442          42 :                     n->object = (Node *) $5;
    7443          42 :                     n->comment = $7;
    7444          42 :                     $$ = (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        7538 :             Sconst                              { $$ = $1; }
    7459         104 :             | 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          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7477             : 
    7478          48 :                     n->provider = $3;
    7479          48 :                     n->objtype = $5;
    7480          48 :                     n->object = (Node *) $6;
    7481          48 :                     n->label = $8;
    7482          48 :                     $$ = (Node *) n;
    7483             :                 }
    7484             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7485             :               IS security_label
    7486             :                 {
    7487           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7488             : 
    7489           4 :                     n->provider = $3;
    7490           4 :                     n->objtype = OBJECT_COLUMN;
    7491           4 :                     n->object = (Node *) $6;
    7492           4 :                     n->label = $8;
    7493           4 :                     $$ = (Node *) n;
    7494             :                 }
    7495             :             | SECURITY LABEL opt_provider ON object_type_name name
    7496             :               IS security_label
    7497             :                 {
    7498          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7499             : 
    7500          44 :                     n->provider = $3;
    7501          44 :                     n->objtype = $5;
    7502          44 :                     n->object = (Node *) makeString($6);
    7503          44 :                     n->label = $8;
    7504          44 :                     $$ = (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           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7521             : 
    7522           2 :                     n->provider = $3;
    7523           2 :                     n->objtype = OBJECT_DOMAIN;
    7524           2 :                     n->object = (Node *) $6;
    7525           2 :                     n->label = $8;
    7526           2 :                     $$ = (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           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7543             : 
    7544           2 :                     n->provider = $3;
    7545           2 :                     n->objtype = OBJECT_FUNCTION;
    7546           2 :                     n->object = (Node *) $6;
    7547           2 :                     n->label = $8;
    7548           2 :                     $$ = (Node *) n;
    7549             :                 }
    7550             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7551             :               IS security_label
    7552             :                 {
    7553          18 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7554             : 
    7555          18 :                     n->provider = $3;
    7556          18 :                     n->objtype = OBJECT_LARGEOBJECT;
    7557          18 :                     n->object = (Node *) $7;
    7558          18 :                     n->label = $9;
    7559          18 :                     $$ = (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          28 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7586          90 :                 | /* EMPTY */                   { $$ = NULL; }
    7587             :         ;
    7588             : 
    7589         118 : 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        7648 :                     FetchStmt *n = (FetchStmt *) $2;
    7603             : 
    7604        7648 :                     n->ismove = false;
    7605        7648 :                     $$ = (Node *) n;
    7606             :                 }
    7607             :             | MOVE fetch_args
    7608             :                 {
    7609          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7610             : 
    7611          68 :                     n->ismove = true;
    7612          68 :                     $$ = (Node *) n;
    7613             :                 }
    7614             :         ;
    7615             : 
    7616             : fetch_args: cursor_name
    7617             :                 {
    7618         272 :                     FetchStmt *n = makeNode(FetchStmt);
    7619             : 
    7620         272 :                     n->portalname = $1;
    7621         272 :                     n->direction = FETCH_FORWARD;
    7622         272 :                     n->howMany = 1;
    7623         272 :                     n->location = -1;
    7624         272 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7625         272 :                     $$ = (Node *) n;
    7626             :                 }
    7627             :             | from_in cursor_name
    7628             :                 {
    7629         218 :                     FetchStmt *n = makeNode(FetchStmt);
    7630             : 
    7631         218 :                     n->portalname = $2;
    7632         218 :                     n->direction = FETCH_FORWARD;
    7633         218 :                     n->howMany = 1;
    7634         218 :                     n->location = -1;
    7635         218 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7636         218 :                     $$ = (Node *) n;
    7637             :                 }
    7638             :             | SignedIconst opt_from_in cursor_name
    7639             :                 {
    7640        4282 :                     FetchStmt *n = makeNode(FetchStmt);
    7641             : 
    7642        4282 :                     n->portalname = $3;
    7643        4282 :                     n->direction = FETCH_FORWARD;
    7644        4282 :                     n->howMany = $1;
    7645        4282 :                     n->location = @1;
    7646        4282 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7647        4282 :                     $$ = (Node *) n;
    7648             :                 }
    7649             :             | NEXT opt_from_in cursor_name
    7650             :                 {
    7651        2010 :                     FetchStmt *n = makeNode(FetchStmt);
    7652             : 
    7653        2010 :                     n->portalname = $3;
    7654        2010 :                     n->direction = FETCH_FORWARD;
    7655        2010 :                     n->howMany = 1;
    7656        2010 :                     n->location = -1;
    7657        2010 :                     n->direction_keyword = FETCH_KEYWORD_NEXT;
    7658        2010 :                     $$ = (Node *) n;
    7659             :                 }
    7660             :             | PRIOR opt_from_in cursor_name
    7661             :                 {
    7662          32 :                     FetchStmt *n = makeNode(FetchStmt);
    7663             : 
    7664          32 :                     n->portalname = $3;
    7665          32 :                     n->direction = FETCH_BACKWARD;
    7666          32 :                     n->howMany = 1;
    7667          32 :                     n->location = -1;
    7668          32 :                     n->direction_keyword = FETCH_KEYWORD_PRIOR;
    7669          32 :                     $$ = (Node *) n;
    7670             :                 }
    7671             :             | FIRST_P opt_from_in cursor_name
    7672             :                 {
    7673          26 :                     FetchStmt *n = makeNode(FetchStmt);
    7674             : 
    7675          26 :                     n->portalname = $3;
    7676          26 :                     n->direction = FETCH_ABSOLUTE;
    7677          26 :                     n->howMany = 1;
    7678          26 :                     n->location = -1;
    7679          26 :                     n->direction_keyword = FETCH_KEYWORD_FIRST;
    7680          26 :                     $$ = (Node *) n;
    7681             :                 }
    7682             :             | LAST_P opt_from_in cursor_name
    7683             :                 {
    7684          20 :                     FetchStmt *n = makeNode(FetchStmt);
    7685             : 
    7686          20 :                     n->portalname = $3;
    7687          20 :                     n->direction = FETCH_ABSOLUTE;
    7688          20 :                     n->howMany = -1;
    7689          20 :                     n->location = -1;
    7690          20 :                     n->direction_keyword = FETCH_KEYWORD_LAST;
    7691          20 :                     $$ = (Node *) n;
    7692             :                 }
    7693             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7694             :                 {
    7695          94 :                     FetchStmt *n = makeNode(FetchStmt);
    7696             : 
    7697          94 :                     n->portalname = $4;
    7698          94 :                     n->direction = FETCH_ABSOLUTE;
    7699          94 :                     n->howMany = $2;
    7700          94 :                     n->location = @2;
    7701          94 :                     n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
    7702          94 :                     $$ = (Node *) n;
    7703             :                 }
    7704             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7705             :                 {
    7706          36 :                     FetchStmt *n = makeNode(FetchStmt);
    7707             : 
    7708          36 :                     n->portalname = $4;
    7709          36 :                     n->direction = FETCH_RELATIVE;
    7710          36 :                     n->howMany = $2;
    7711          36 :                     n->location = @2;
    7712          36 :                     n->direction_keyword = FETCH_KEYWORD_RELATIVE;
    7713          36 :                     $$ = (Node *) n;
    7714             :                 }
    7715             :             | ALL opt_from_in cursor_name
    7716             :                 {
    7717         270 :                     FetchStmt *n = makeNode(FetchStmt);
    7718             : 
    7719         270 :                     n->portalname = $3;
    7720         270 :                     n->direction = FETCH_FORWARD;
    7721         270 :                     n->howMany = FETCH_ALL;
    7722         270 :                     n->location = -1;
    7723         270 :                     n->direction_keyword = FETCH_KEYWORD_ALL;
    7724         270 :                     $$ = (Node *) n;
    7725             :                 }
    7726             :             | FORWARD opt_from_in cursor_name
    7727             :                 {
    7728          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7729             : 
    7730          30 :                     n->portalname = $3;
    7731          30 :                     n->direction = FETCH_FORWARD;
    7732          30 :                     n->howMany = 1;
    7733          30 :                     n->location = -1;
    7734          30 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7735          30 :                     $$ = (Node *) n;
    7736             :                 }
    7737             :             | FORWARD SignedIconst opt_from_in cursor_name
    7738             :                 {
    7739          12 :                     FetchStmt *n = makeNode(FetchStmt);
    7740             : 
    7741          12 :                     n->portalname = $4;
    7742          12 :                     n->direction = FETCH_FORWARD;
    7743          12 :                     n->howMany = $2;
    7744          12 :                     n->location = @2;
    7745          12 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7746          12 :                     $$ = (Node *) n;
    7747             :                 }
    7748             :             | FORWARD ALL opt_from_in cursor_name
    7749             :                 {
    7750          16 :                     FetchStmt *n = makeNode(FetchStmt);
    7751             : 
    7752          16 :                     n->portalname = $4;
    7753          16 :                     n->direction = FETCH_FORWARD;
    7754          16 :                     n->howMany = FETCH_ALL;
    7755          16 :                     n->location = -1;
    7756          16 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
    7757          16 :                     $$ = (Node *) n;
    7758             :                 }
    7759             :             | BACKWARD opt_from_in cursor_name
    7760             :                 {
    7761          80 :                     FetchStmt *n = makeNode(FetchStmt);
    7762             : 
    7763          80 :                     n->portalname = $3;
    7764          80 :                     n->direction = FETCH_BACKWARD;
    7765          80 :                     n->howMany = 1;
    7766          80 :                     n->location = -1;
    7767          80 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7768          80 :                     $$ = (Node *) n;
    7769             :                 }
    7770             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7771             :                 {
    7772         226 :                     FetchStmt *n = makeNode(FetchStmt);
    7773             : 
    7774         226 :                     n->portalname = $4;
    7775         226 :                     n->direction = FETCH_BACKWARD;
    7776         226 :                     n->howMany = $2;
    7777         226 :                     n->location = @2;
    7778         226 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7779         226 :                     $$ = (Node *) n;
    7780             :                 }
    7781             :             | BACKWARD ALL opt_from_in cursor_name
    7782             :                 {
    7783          92 :                     FetchStmt *n = makeNode(FetchStmt);
    7784             : 
    7785          92 :                     n->portalname = $4;
    7786          92 :                     n->direction = FETCH_BACKWARD;
    7787          92 :                     n->howMany = FETCH_ALL;
    7788          92 :                     n->location = -1;
    7789          92 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
    7790          92 :                     $$ = (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       12058 :                     GrantStmt *n = makeNode(GrantStmt);
    7813             : 
    7814       12058 :                     n->is_grant = true;
    7815       12058 :                     n->privileges = $2;
    7816       12058 :                     n->targtype = ($4)->targtype;
    7817       12058 :                     n->objtype = ($4)->objtype;
    7818       12058 :                     n->objects = ($4)->objs;
    7819       12058 :                     n->grantees = $6;
    7820       12058 :                     n->grant_option = $7;
    7821       12058 :                     n->grantor = $8;
    7822       12058 :                     $$ = (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       10680 :                     GrantStmt *n = makeNode(GrantStmt);
    7831             : 
    7832       10680 :                     n->is_grant = false;
    7833       10680 :                     n->grant_option = false;
    7834       10680 :                     n->privileges = $2;
    7835       10680 :                     n->targtype = ($4)->targtype;
    7836       10680 :                     n->objtype = ($4)->objtype;
    7837       10680 :                     n->objects = ($4)->objs;
    7838       10680 :                     n->grantees = $6;
    7839       10680 :                     n->grantor = $7;
    7840       10680 :                     n->behavior = $8;
    7841       10680 :                     $$ = (Node *) n;
    7842             :                 }
    7843             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7844             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7845             :                 {
    7846          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7847             : 
    7848          16 :                     n->is_grant = false;
    7849          16 :                     n->grant_option = true;
    7850          16 :                     n->privileges = $5;
    7851          16 :                     n->targtype = ($7)->targtype;
    7852          16 :                     n->objtype = ($7)->objtype;
    7853          16 :                     n->objects = ($7)->objs;
    7854          16 :                     n->grantees = $9;
    7855          16 :                     n->grantor = $10;
    7856          16 :                     n->behavior = $11;
    7857          16 :                     $$ = (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       20052 :                 { $$ = $1; }
    7873             :             | ALL
    7874        2782 :                 { $$ = NIL; }
    7875             :             | ALL PRIVILEGES
    7876         120 :                 { $$ = NIL; }
    7877             :             | ALL '(' columnList ')'
    7878             :                 {
    7879          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7880             : 
    7881          18 :                     n->priv_name = NULL;
    7882          18 :                     n->cols = $3;
    7883          18 :                     $$ = 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       20978 : privilege_list: privilege                           { $$ = list_make1($1); }
    7896         588 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7897             :         ;
    7898             : 
    7899             : privilege:  SELECT opt_column_list
    7900             :             {
    7901        9770 :                 AccessPriv *n = makeNode(AccessPriv);
    7902             : 
    7903        9770 :                 n->priv_name = pstrdup($1);
    7904        9770 :                 n->cols = $2;
    7905        9770 :                 $$ = n;
    7906             :             }
    7907             :         | REFERENCES opt_column_list
    7908             :             {
    7909          14 :                 AccessPriv *n = makeNode(AccessPriv);
    7910             : 
    7911          14 :                 n->priv_name = pstrdup($1);
    7912          14 :                 n->cols = $2;
    7913          14 :                 $$ = n;
    7914             :             }
    7915             :         | CREATE opt_column_list
    7916             :             {
    7917         324 :                 AccessPriv *n = makeNode(AccessPriv);
    7918             : 
    7919         324 :                 n->priv_name = pstrdup($1);
    7920         324 :                 n->cols = $2;
    7921         324 :                 $$ = n;
    7922             :             }
    7923             :         | ALTER SYSTEM_P
    7924             :             {
    7925          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7926          24 :                 n->priv_name = pstrdup("alter system");
    7927          24 :                 n->cols = NIL;
    7928          24 :                 $$ = n;
    7929             :             }
    7930             :         | ColId opt_column_list
    7931             :             {
    7932       11434 :                 AccessPriv *n = makeNode(AccessPriv);
    7933             : 
    7934       11434 :                 n->priv_name = $1;
    7935       11434 :                 n->cols = $2;
    7936       11434 :                 $$ = n;
    7937             :             }
    7938             :         ;
    7939             : 
    7940             : parameter_name_list:
    7941             :         parameter_name
    7942             :             {
    7943          76 :                 $$ = list_make1(makeString($1));
    7944             :             }
    7945             :         | parameter_name_list ',' parameter_name
    7946             :             {
    7947          50 :                 $$ = lappend($1, makeString($3));
    7948             :             }
    7949             :         ;
    7950             : 
    7951             : parameter_name:
    7952             :         ColId
    7953             :             {
    7954         126 :                 $$ = $1;
    7955             :             }
    7956             :         | parameter_name '.' ColId
    7957             :             {
    7958          32 :                 $$ = 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       11834 :                     PrivTarget *n = palloc_object(PrivTarget);
    7970             : 
    7971       11834 :                     n->targtype = ACL_TARGET_OBJECT;
    7972       11834 :                     n->objtype = OBJECT_TABLE;
    7973       11834 :                     n->objs = $1;
    7974       11834 :                     $$ = n;
    7975             :                 }
    7976             :             | TABLE qualified_name_list
    7977             :                 {
    7978         392 :                     PrivTarget *n = palloc_object(PrivTarget);
    7979             : 
    7980         392 :                     n->targtype = ACL_TARGET_OBJECT;
    7981         392 :                     n->objtype = OBJECT_TABLE;
    7982         392 :                     n->objs = $2;
    7983         392 :                     $$ = n;
    7984             :                 }
    7985             :             | SEQUENCE qualified_name_list
    7986             :                 {
    7987          22 :                     PrivTarget *n = palloc_object(PrivTarget);
    7988             : 
    7989          22 :                     n->targtype = ACL_TARGET_OBJECT;
    7990          22 :                     n->objtype = OBJECT_SEQUENCE;
    7991          22 :                     n->objs = $2;
    7992          22 :                     $$ = n;
    7993             :                 }
    7994             :             | FOREIGN DATA_P WRAPPER name_list
    7995             :                 {
    7996          92 :                     PrivTarget *n = palloc_object(PrivTarget);
    7997             : 
    7998          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7999          92 :                     n->objtype = OBJECT_FDW;
    8000          92 :                     n->objs = $4;
    8001          92 :                     $$ = n;
    8002             :                 }
    8003             :             | FOREIGN SERVER name_list
    8004             :                 {
    8005          88 :                     PrivTarget *n = palloc_object(PrivTarget);
    8006             : 
    8007          88 :                     n->targtype = ACL_TARGET_OBJECT;
    8008          88 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    8009          88 :                     n->objs = $3;
    8010          88 :                     $$ = n;
    8011             :                 }
    8012             :             | FUNCTION function_with_argtypes_list
    8013             :                 {
    8014        9110 :                     PrivTarget *n = palloc_object(PrivTarget);
    8015             : 
    8016        9110 :                     n->targtype = ACL_TARGET_OBJECT;
    8017        9110 :                     n->objtype = OBJECT_FUNCTION;
    8018        9110 :                     n->objs = $2;
    8019        9110 :                     $$ = n;
    8020             :                 }
    8021             :             | PROCEDURE function_with_argtypes_list
    8022             :                 {
    8023          42 :                     PrivTarget *n = palloc_object(PrivTarget);
    8024             : 
    8025          42 :                     n->targtype = ACL_TARGET_OBJECT;
    8026          42 :                     n->objtype = OBJECT_PROCEDURE;
    8027          42 :                     n->objs = $2;
    8028          42 :                     $$ = 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         354 :                     PrivTarget *n = palloc_object(PrivTarget);
    8042             : 
    8043         354 :                     n->targtype = ACL_TARGET_OBJECT;
    8044         354 :                     n->objtype = OBJECT_DATABASE;
    8045         354 :                     n->objs = $2;
    8046         354 :                     $$ = n;
    8047             :                 }
    8048             :             | DOMAIN_P any_name_list
    8049             :                 {
    8050          26 :                     PrivTarget *n = palloc_object(PrivTarget);
    8051             : 
    8052          26 :                     n->targtype = ACL_TARGET_OBJECT;
    8053          26 :                     n->objtype = OBJECT_DOMAIN;
    8054          26 :                     n->objs = $2;
    8055          26 :                     $$ = n;
    8056             :                 }
    8057             :             | LANGUAGE name_list
    8058             :                 {
    8059          42 :                     PrivTarget *n = palloc_object(PrivTarget);
    8060             : 
    8061          42 :                     n->targtype = ACL_TARGET_OBJECT;
    8062          42 :                     n->objtype = OBJECT_LANGUAGE;
    8063          42 :                     n->objs = $2;
    8064          42 :                     $$ = n;
    8065             :                 }
    8066             :             | LARGE_P OBJECT_P NumericOnly_list
    8067             :                 {
    8068          90 :                     PrivTarget *n = palloc_object(PrivTarget);
    8069             : 
    8070          90 :                     n->targtype = ACL_TARGET_OBJECT;
    8071          90 :                     n->objtype = OBJECT_LARGEOBJECT;
    8072          90 :                     n->objs = $3;
    8073          90 :                     $$ = n;
    8074             :                 }
    8075             :             | PARAMETER parameter_name_list
    8076             :                 {
    8077          76 :                     PrivTarget *n = palloc_object(PrivTarget);
    8078          76 :                     n->targtype = ACL_TARGET_OBJECT;
    8079          76 :                     n->objtype = OBJECT_PARAMETER_ACL;
    8080          76 :                     n->objs = $2;
    8081          76 :                     $$ = n;
    8082             :                 }
    8083             :             | SCHEMA name_list
    8084             :                 {
    8085         450 :                     PrivTarget *n = palloc_object(PrivTarget);
    8086             : 
    8087         450 :                     n->targtype = ACL_TARGET_OBJECT;
    8088         450 :                     n->objtype = OBJECT_SCHEMA;
    8089         450 :                     n->objs = $2;
    8090         450 :                     $$ = n;
    8091             :                 }
    8092             :             | TABLESPACE name_list
    8093             :                 {
    8094           6 :                     PrivTarget *n = palloc_object(PrivTarget);
    8095             : 
    8096           6 :                     n->targtype = ACL_TARGET_OBJECT;
    8097           6 :                     n->objtype = OBJECT_TABLESPACE;
    8098           6 :                     n->objs = $2;
    8099           6 :                     $$ = n;
    8100             :                 }
    8101             :             | TYPE_P any_name_list
    8102             :                 {
    8103         112 :                     PrivTarget *n = palloc_object(PrivTarget);
    8104             : 
    8105         112 :                     n->targtype = ACL_TARGET_OBJECT;
    8106         112 :                     n->objtype = OBJECT_TYPE;
    8107         112 :                     n->objs = $2;
    8108         112 :                     $$ = n;
    8109             :                 }
    8110             :             | ALL TABLES IN_P SCHEMA name_list
    8111             :                 {
    8112          12 :                     PrivTarget *n = palloc_object(PrivTarget);
    8113             : 
    8114          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8115          12 :                     n->objtype = OBJECT_TABLE;
    8116          12 :                     n->objs = $5;
    8117          12 :                     $$ = 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           6 :                     PrivTarget *n = palloc_object(PrivTarget);
    8131             : 
    8132           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8133           6 :                     n->objtype = OBJECT_FUNCTION;
    8134           6 :                     n->objs = $5;
    8135           6 :                     $$ = n;
    8136             :                 }
    8137             :             | ALL PROCEDURES IN_P SCHEMA name_list
    8138             :                 {
    8139           6 :                     PrivTarget *n = palloc_object(PrivTarget);
    8140             : 
    8141           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8142           6 :                     n->objtype = OBJECT_PROCEDURE;
    8143           6 :                     n->objs = $5;
    8144           6 :                     $$ = n;
    8145             :                 }
    8146             :             | ALL ROUTINES IN_P SCHEMA name_list
    8147             :                 {
    8148           6 :                     PrivTarget *n = palloc_object(PrivTarget);
    8149             : 
    8150           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8151           6 :                     n->objtype = OBJECT_ROUTINE;
    8152           6 :                     n->objs = $5;
    8153           6 :                     $$ = n;
    8154             :                 }
    8155             :         ;
    8156             : 
    8157             : 
    8158             : grantee_list:
    8159       22960 :             grantee                                 { $$ = list_make1($1); }
    8160         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    8161             :         ;
    8162             : 
    8163             : grantee:
    8164       23044 :             RoleSpec                                { $$ = $1; }
    8165          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    8166             :         ;
    8167             : 
    8168             : 
    8169             : opt_grant_grant_option:
    8170         102 :             WITH GRANT OPTION { $$ = true; }
    8171       12080 :             | /*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         592 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8184             : 
    8185         592 :                     n->is_grant = true;
    8186         592 :                     n->granted_roles = $2;
    8187         592 :                     n->grantee_roles = $4;
    8188         592 :                     n->opt = NIL;
    8189         592 :                     n->grantor = $5;
    8190         592 :                     $$ = (Node *) n;
    8191             :                 }
    8192             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8193             :                 {
    8194         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8195             : 
    8196         178 :                     n->is_grant = true;
    8197         178 :                     n->granted_roles = $2;
    8198         178 :                     n->grantee_roles = $4;
    8199         178 :                     n->opt = $6;
    8200         178 :                     n->grantor = $7;
    8201         178 :                     $$ = (Node *) n;
    8202             :                 }
    8203             :         ;
    8204             : 
    8205             : RevokeRoleStmt:
    8206             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8207             :                 {
    8208          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8209             : 
    8210          90 :                     n->is_grant = false;
    8211          90 :                     n->opt = NIL;
    8212          90 :                     n->granted_roles = $2;
    8213          90 :                     n->grantee_roles = $4;
    8214          90 :                     n->grantor = $5;
    8215          90 :                     n->behavior = $6;
    8216          90 :                     $$ = (Node *) n;
    8217             :                 }
    8218             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8219             :                 {
    8220          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8221             :                     DefElem *opt;
    8222             : 
    8223          66 :                     opt = makeDefElem(pstrdup($2),
    8224          66 :                                       (Node *) makeBoolean(false), @2);
    8225          66 :                     n->is_grant = false;
    8226          66 :                     n->opt = list_make1(opt);
    8227          66 :                     n->granted_roles = $5;
    8228          66 :                     n->grantee_roles = $7;
    8229          66 :                     n->grantor = $8;
    8230          66 :                     n->behavior = $9;
    8231          66 :                     $$ = (Node *) n;
    8232             :                 }
    8233             :         ;
    8234             : 
    8235             : grant_role_opt_list:
    8236         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8237         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8238             :         ;
    8239             : 
    8240             : grant_role_opt:
    8241             :         ColLabel grant_role_opt_value
    8242             :             {
    8243         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8244             :             }
    8245             :         ;
    8246             : 
    8247             : grant_role_opt_value:
    8248          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8249         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8250         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8251             :         ;
    8252             : 
    8253         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8254       23542 :             | /*EMPTY*/                                 { $$ = NULL; }
    8255             :         ;
    8256             : 
    8257             : /*****************************************************************************
    8258             :  *
    8259             :  * ALTER DEFAULT PRIVILEGES statement
    8260             :  *
    8261             :  *****************************************************************************/
    8262             : 
    8263             : AlterDefaultPrivilegesStmt:
    8264             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8265             :                 {
    8266         206 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8267             : 
    8268         206 :                     n->options = $4;
    8269         206 :                     n->action = (GrantStmt *) $5;
    8270         206 :                     $$ = (Node *) n;
    8271             :                 }
    8272             :         ;
    8273             : 
    8274             : DefACLOptionList:
    8275         144 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8276         206 :             | /* EMPTY */                           { $$ = NIL; }
    8277             :         ;
    8278             : 
    8279             : DefACLOption:
    8280             :             IN_P SCHEMA name_list
    8281             :                 {
    8282          60 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8283             :                 }
    8284             :             | FOR ROLE role_list
    8285             :                 {
    8286          84 :                     $$ = 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         124 :                     GrantStmt *n = makeNode(GrantStmt);
    8303             : 
    8304         124 :                     n->is_grant = true;
    8305         124 :                     n->privileges = $2;
    8306         124 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8307         124 :                     n->objtype = $4;
    8308         124 :                     n->objects = NIL;
    8309         124 :                     n->grantees = $6;
    8310         124 :                     n->grant_option = $7;
    8311         124 :                     $$ = (Node *) n;
    8312             :                 }
    8313             :             | REVOKE privileges ON defacl_privilege_target
    8314             :             FROM grantee_list opt_drop_behavior
    8315             :                 {
    8316          82 :                     GrantStmt *n = makeNode(GrantStmt);
    8317             : 
    8318          82 :                     n->is_grant = false;
    8319          82 :                     n->grant_option = false;
    8320          82 :                     n->privileges = $2;
    8321          82 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8322          82 :                     n->objtype = $4;
    8323          82 :                     n->objects = NIL;
    8324          82 :                     n->grantees = $6;
    8325          82 :                     n->behavior = $7;
    8326          82 :                     $$ = (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          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8347          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8348           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8349           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8350          34 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8351          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8352          30 :             | 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        6854 :                     IndexStmt *n = makeNode(IndexStmt);
    8369             : 
    8370        6854 :                     n->unique = $2;
    8371        6854 :                     n->concurrent = $4;
    8372        6854 :                     n->idxname = $5;
    8373        6854 :                     n->relation = $7;
    8374        6854 :                     n->accessMethod = $8;
    8375        6854 :                     n->indexParams = $10;
    8376        6854 :                     n->indexIncludingParams = $12;
    8377        6854 :                     n->nulls_not_distinct = !$13;
    8378        6854 :                     n->options = $14;
    8379        6854 :                     n->tableSpace = $15;
    8380        6854 :                     n->whereClause = $16;
    8381        6854 :                     n->excludeOpNames = NIL;
    8382        6854 :                     n->idxcomment = NULL;
    8383        6854 :                     n->indexOid = InvalidOid;
    8384        6854 :                     n->oldNumber = InvalidRelFileNumber;
    8385        6854 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8386        6854 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8387        6854 :                     n->primary = false;
    8388        6854 :                     n->isconstraint = false;
    8389        6854 :                     n->deferrable = false;
    8390        6854 :                     n->initdeferred = false;
    8391        6854 :                     n->transformed = false;
    8392        6854 :                     n->if_not_exists = false;
    8393        6854 :                     n->reset_default_tblspc = false;
    8394        6854 :                     $$ = (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          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8401             : 
    8402          18 :                     n->unique = $2;
    8403          18 :                     n->concurrent = $4;
    8404          18 :                     n->idxname = $8;
    8405          18 :                     n->relation = $10;
    8406          18 :                     n->accessMethod = $11;
    8407          18 :                     n->indexParams = $13;
    8408          18 :                     n->indexIncludingParams = $15;
    8409          18 :                     n->nulls_not_distinct = !$16;
    8410          18 :                     n->options = $17;
    8411          18 :                     n->tableSpace = $18;
    8412          18 :                     n->whereClause = $19;
    8413          18 :                     n->excludeOpNames = NIL;
    8414          18 :                     n->idxcomment = NULL;
    8415          18 :                     n->indexOid = InvalidOid;
    8416          18 :                     n->oldNumber = InvalidRelFileNumber;
    8417          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8418          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8419          18 :                     n->primary = false;
    8420          18 :                     n->isconstraint = false;
    8421          18 :                     n->deferrable = false;
    8422          18 :                     n->initdeferred = false;
    8423          18 :                     n->transformed = false;
    8424          18 :                     n->if_not_exists = true;
    8425          18 :                     n->reset_default_tblspc = false;
    8426          18 :                     $$ = (Node *) n;
    8427             :                 }
    8428             :         ;
    8429             : 
    8430             : opt_unique:
    8431        1314 :             UNIQUE                                  { $$ = true; }
    8432        5564 :             | /*EMPTY*/                             { $$ = false; }
    8433             :         ;
    8434             : 
    8435             : access_method_clause:
    8436        3118 :             USING name                              { $$ = $2; }
    8437        3988 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8438             :         ;
    8439             : 
    8440        8400 : index_params:   index_elem                          { $$ = list_make1($1); }
    8441        2164 :             | 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       11140 :             $$ = makeNode(IndexElem);
    8449       11140 :             $$->name = NULL;
    8450       11140 :             $$->expr = NULL;
    8451       11140 :             $$->indexcolname = NULL;
    8452       11140 :             $$->collation = $1;
    8453       11140 :             $$->opclass = $2;
    8454       11140 :             $$->opclassopts = NIL;
    8455       11140 :             $$->ordering = $3;
    8456       11140 :             $$->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         148 :             $$ = makeNode(IndexElem);
    8462         148 :             $$->name = NULL;
    8463         148 :             $$->expr = NULL;
    8464         148 :             $$->indexcolname = NULL;
    8465         148 :             $$->collation = $1;
    8466         148 :             $$->opclass = $2;
    8467         148 :             $$->opclassopts = $3;
    8468         148 :             $$->ordering = $4;
    8469         148 :             $$->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       10146 :                     $$ = $2;
    8482       10146 :                     $$->name = $1;
    8483       10146 :                     $$->location = @1;
    8484             :                 }
    8485             :             | func_expr_windowless index_elem_options
    8486             :                 {
    8487         620 :                     $$ = $2;
    8488         620 :                     $$->expr = $1;
    8489         620 :                     $$->location = @1;
    8490             :                 }
    8491             :             | '(' a_expr ')' index_elem_options
    8492             :                 {
    8493         522 :                     $$ = $4;
    8494         522 :                     $$->expr = $2;
    8495         522 :                     $$->location = @1;
    8496             :                 }
    8497             :         ;
    8498             : 
    8499         218 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8500        6654 :              |      /* EMPTY */                     { $$ = NIL; }
    8501             :         ;
    8502             : 
    8503         218 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8504         166 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8505             :         ;
    8506             : 
    8507         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8508       17182 :             | /*EMPTY*/                             { $$ = NIL; }
    8509             :         ;
    8510             : 
    8511             : 
    8512        1848 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8513        3674 :             | DESC                          { $$ = SORTBY_DESC; }
    8514      115890 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8515             :         ;
    8516             : 
    8517         346 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8518        1758 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8519      119528 :             | /*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       24928 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8539             : 
    8540       24928 :                     n->is_procedure = false;
    8541       24928 :                     n->replace = $2;
    8542       24928 :                     n->funcname = $4;
    8543       24928 :                     n->parameters = $5;
    8544       24928 :                     n->returnType = $7;
    8545       24928 :                     n->options = $8;
    8546       24928 :                     n->sql_body = $9;
    8547       24928 :                     $$ = (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         194 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8553             : 
    8554         194 :                     n->is_procedure = false;
    8555         194 :                     n->replace = $2;
    8556         194 :                     n->funcname = $4;
    8557         194 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8558         194 :                     n->returnType = TableFuncTypeName($9);
    8559         194 :                     n->returnType->location = @7;
    8560         194 :                     n->options = $11;
    8561         194 :                     n->sql_body = $12;
    8562         194 :                     $$ = (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         494 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8568             : 
    8569         494 :                     n->is_procedure = false;
    8570         494 :                     n->replace = $2;
    8571         494 :                     n->funcname = $4;
    8572         494 :                     n->parameters = $5;
    8573         494 :                     n->returnType = NULL;
    8574         494 :                     n->options = $6;
    8575         494 :                     n->sql_body = $7;
    8576         494 :                     $$ = (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         370 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8582             : 
    8583         370 :                     n->is_procedure = true;
    8584         370 :                     n->replace = $2;
    8585         370 :                     n->funcname = $4;
    8586         370 :                     n->parameters = $5;
    8587         370 :                     n->returnType = NULL;
    8588         370 :                     n->options = $6;
    8589         370 :                     n->sql_body = $7;
    8590         370 :                     $$ = (Node *) n;
    8591             :                 }
    8592             :         ;
    8593             : 
    8594             : opt_or_replace:
    8595       10314 :             OR REPLACE                              { $$ = true; }
    8596       21202 :             | /*EMPTY*/                             { $$ = false; }
    8597             :         ;
    8598             : 
    8599       11152 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8600        6024 :             | '(' ')'                               { $$ = NIL; }
    8601             :         ;
    8602             : 
    8603             : func_args_list:
    8604       11152 :             func_arg                                { $$ = list_make1($1); }
    8605        9844 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8606             :         ;
    8607             : 
    8608             : function_with_argtypes_list:
    8609       12998 :             function_with_argtypes                  { $$ = list_make1($1); }
    8610             :             | function_with_argtypes_list ',' function_with_argtypes
    8611          84 :                                                     { $$ = lappend($1, $3); }
    8612             :         ;
    8613             : 
    8614             : function_with_argtypes:
    8615             :             func_name func_args
    8616             :                 {
    8617       17176 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8618             : 
    8619       17176 :                     n->objname = $1;
    8620       17176 :                     n->objargs = extractArgTypes($2);
    8621       17176 :                     n->objfuncargs = $2;
    8622       17176 :                     $$ = 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         422 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8640             : 
    8641         422 :                     n->objname = list_make1(makeString($1));
    8642         422 :                     n->args_unspecified = true;
    8643         422 :                     $$ = n;
    8644             :                 }
    8645             :             | ColId indirection
    8646             :                 {
    8647          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8648             : 
    8649          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8650             :                                                   yyscanner);
    8651          28 :                     n->args_unspecified = true;
    8652          28 :                     $$ = 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       21416 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8662        4570 :         | '(' ')'                                   { $$ = NIL; }
    8663             :         ;
    8664             : 
    8665             : func_args_with_defaults_list:
    8666       21416 :         func_arg_with_default                       { $$ = list_make1($1); }
    8667             :         | func_args_with_defaults_list ',' func_arg_with_default
    8668       36422 :                                                     { $$ = 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       17188 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8685             : 
    8686       17188 :                     n->name = $2;
    8687       17188 :                     n->argType = $3;
    8688       17188 :                     n->mode = $1;
    8689       17188 :                     n->defexpr = NULL;
    8690       17188 :                     n->location = @1;
    8691       17188 :                     $$ = n;
    8692             :                 }
    8693             :             | param_name arg_class func_type
    8694             :                 {
    8695         420 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8696             : 
    8697         420 :                     n->name = $1;
    8698         420 :                     n->argType = $3;
    8699         420 :                     n->mode = $2;
    8700         420 :                     n->defexpr = NULL;
    8701         420 :                     n->location = @1;
    8702         420 :                     $$ = n;
    8703             :                 }
    8704             :             | param_name func_type
    8705             :                 {
    8706       16190 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8707             : 
    8708       16190 :                     n->name = $1;
    8709       16190 :                     n->argType = $2;
    8710       16190 :                     n->mode = FUNC_PARAM_DEFAULT;
    8711       16190 :                     n->defexpr = NULL;
    8712       16190 :                     n->location = @1;
    8713       16190 :                     $$ = n;
    8714             :                 }
    8715             :             | arg_class func_type
    8716             :                 {
    8717         334 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8718             : 
    8719         334 :                     n->name = NULL;
    8720         334 :                     n->argType = $2;
    8721         334 :                     n->mode = $1;
    8722         334 :                     n->defexpr = NULL;
    8723         334 :                     n->location = @1;
    8724         334 :                     $$ = n;
    8725             :                 }
    8726             :             | func_type
    8727             :                 {
    8728       45602 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8729             : 
    8730       45602 :                     n->name = NULL;
    8731       45602 :                     n->argType = $1;
    8732       45602 :                     n->mode = FUNC_PARAM_DEFAULT;
    8733       45602 :                     n->defexpr = NULL;
    8734       45602 :                     n->location = @1;
    8735       45602 :                     $$ = n;
    8736             :                 }
    8737             :         ;
    8738             : 
    8739             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8740        4418 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8741       12738 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8742         200 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8743           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8744         586 :             | 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       24928 :                     $$ = $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      126400 : func_type:  Typename                                { $$ = $1; }
    8770             :             | type_function_name attrs '%' TYPE_P
    8771             :                 {
    8772          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8773          18 :                     $$->pct_type = true;
    8774          18 :                     $$->location = @1;
    8775             :                 }
    8776             :             | SETOF type_function_name attrs '%' TYPE_P
    8777             :                 {
    8778           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8779           6 :                     $$->pct_type = true;
    8780           6 :                     $$->setof = true;
    8781           6 :                     $$->location = @2;
    8782             :                 }
    8783             :         ;
    8784             : 
    8785             : func_arg_with_default:
    8786             :         func_arg
    8787             :                 {
    8788       51150 :                     $$ = $1;
    8789             :                 }
    8790             :         | func_arg DEFAULT a_expr
    8791             :                 {
    8792        6492 :                     $$ = $1;
    8793        6492 :                     $$->defexpr = $3;
    8794             :                 }
    8795             :         | func_arg '=' a_expr
    8796             :                 {
    8797         196 :                     $$ = $1;
    8798         196 :                     $$->defexpr = $3;
    8799             :                 }
    8800             :         ;
    8801             : 
    8802             : /* Aggregate args can be most things that function args can be */
    8803             : aggr_arg:   func_arg
    8804             :                 {
    8805         900 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8806          60 :                           $1->mode == FUNC_PARAM_IN ||
    8807          60 :                           $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         900 :                     $$ = $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         136 :                     $$ = list_make2(NIL, makeInteger(-1));
    8848             :                 }
    8849             :             | '(' aggr_args_list ')'
    8850             :                 {
    8851         732 :                     $$ = list_make2($2, makeInteger(-1));
    8852             :                 }
    8853             :             | '(' ORDER BY aggr_args_list ')'
    8854             :                 {
    8855           6 :                     $$ = 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          32 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8861             :                 }
    8862             :         ;
    8863             : 
    8864             : aggr_args_list:
    8865         802 :             aggr_arg                                { $$ = list_make1($1); }
    8866          98 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8867             :         ;
    8868             : 
    8869             : aggregate_with_argtypes:
    8870             :             func_name aggr_args
    8871             :                 {
    8872         362 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8873             : 
    8874         362 :                     n->objname = $1;
    8875         362 :                     n->objargs = extractAggrArgTypes($2);
    8876         362 :                     n->objfuncargs = (List *) linitial($2);
    8877         362 :                     $$ = n;
    8878             :                 }
    8879             :         ;
    8880             : 
    8881             : aggregate_with_argtypes_list:
    8882         104 :             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          60 :             | /*EMPTY*/ { $$ = NIL; }
    8890             :     ;
    8891             : 
    8892             : createfunc_opt_list:
    8893             :             /* Must be at least one to prevent conflict */
    8894       25926 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8895       70126 :             | 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         398 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8905             :                 }
    8906             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8907             :                 {
    8908         902 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8909             :                 }
    8910             :             | STRICT_P
    8911             :                 {
    8912       13946 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8913             :                 }
    8914             :             | IMMUTABLE
    8915             :                 {
    8916       10312 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8917             :                 }
    8918             :             | STABLE
    8919             :                 {
    8920        2576 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8921             :                 }
    8922             :             | VOLATILE
    8923             :                 {
    8924        1898 :                     $$ = 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          58 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8937             :                 }
    8938             :             | SECURITY INVOKER
    8939             :                 {
    8940          18 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8941             :                 }
    8942             :             | LEAKPROOF
    8943             :                 {
    8944          46 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8945             :                 }
    8946             :             | NOT LEAKPROOF
    8947             :                 {
    8948          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8949             :                 }
    8950             :             | COST NumericOnly
    8951             :                 {
    8952        4450 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8953             :                 }
    8954             :             | ROWS NumericOnly
    8955             :                 {
    8956         612 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8957             :                 }
    8958             :             | SUPPORT any_name
    8959             :                 {
    8960         122 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8961             :                 }
    8962             :             | FunctionSetResetClause
    8963             :                 {
    8964             :                     /* we abuse the normal content of a DefElem here */
    8965         154 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8966             :                 }
    8967             :             | PARALLEL ColId
    8968             :                 {
    8969       14636 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8970             :                 }
    8971             :         ;
    8972             : 
    8973             : createfunc_opt_item:
    8974             :             AS func_as
    8975             :                 {
    8976       20194 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8977             :                 }
    8978             :             | LANGUAGE NonReservedWord_or_Sconst
    8979             :                 {
    8980       25906 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8981             :                 }
    8982             :             | TRANSFORM transform_type_list
    8983             :                 {
    8984         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8985             :                 }
    8986             :             | WINDOW
    8987             :                 {
    8988          20 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8989             :                 }
    8990             :             | common_func_opt_item
    8991             :                 {
    8992       49814 :                     $$ = $1;
    8993             :                 }
    8994             :         ;
    8995             : 
    8996       16852 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8997             :             | Sconst ',' Sconst
    8998             :                 {
    8999        3342 :                     $$ = list_make2(makeString($1), makeString($3));
    9000             :                 }
    9001             :         ;
    9002             : 
    9003             : ReturnStmt: RETURN a_expr
    9004             :                 {
    9005        4982 :                     ReturnStmt *r = makeNode(ReturnStmt);
    9006             : 
    9007        4982 :                     r->returnval = (Node *) $2;
    9008        4982 :                     $$ = (Node *) r;
    9009             :                 }
    9010             :         ;
    9011             : 
    9012             : opt_routine_body:
    9013             :             ReturnStmt
    9014             :                 {
    9015        4976 :                     $$ = $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         822 :                     $$ = (Node *) list_make1($3);
    9026             :                 }
    9027             :             | /*EMPTY*/
    9028             :                 {
    9029       20188 :                     $$ = 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         838 :                     if ($2 != NULL)
    9038         820 :                         $$ = lappend($1, $2);
    9039             :                     else
    9040          18 :                         $$ = $1;
    9041             :                 }
    9042             :             | /*EMPTY*/
    9043             :                 {
    9044         822 :                     $$ = NIL;
    9045             :                 }
    9046             :         ;
    9047             : 
    9048             : routine_body_stmt:
    9049             :             stmt
    9050             :             | ReturnStmt
    9051             :         ;
    9052             : 
    9053             : transform_type_list:
    9054         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    9055           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    9056             :         ;
    9057             : 
    9058             : opt_definition:
    9059         662 :             WITH definition                         { $$ = $2; }
    9060       10426 :             | /*EMPTY*/                             { $$ = NIL; }
    9061             :         ;
    9062             : 
    9063             : table_func_column:  param_name func_type
    9064             :                 {
    9065         454 :                     FunctionParameter *n = makeNode(FunctionParameter);
    9066             : 
    9067         454 :                     n->name = $1;
    9068         454 :                     n->argType = $2;
    9069         454 :                     n->mode = FUNC_PARAM_TABLE;
    9070         454 :                     n->defexpr = NULL;
    9071         454 :                     n->location = @1;
    9072         454 :                     $$ = n;
    9073             :                 }
    9074             :         ;
    9075             : 
    9076             : table_func_column_list:
    9077             :             table_func_column
    9078             :                 {
    9079         194 :                     $$ = list_make1($1);
    9080             :                 }
    9081             :             | table_func_column_list ',' table_func_column
    9082             :                 {
    9083         260 :                     $$ = 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         304 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9099             : 
    9100         304 :                     n->objtype = OBJECT_FUNCTION;
    9101         304 :                     n->func = $3;
    9102         304 :                     n->actions = $4;
    9103         304 :                     $$ = (Node *) n;
    9104             :                 }
    9105             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    9106             :                 {
    9107          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9108             : 
    9109          18 :                     n->objtype = OBJECT_PROCEDURE;
    9110          18 :                     n->func = $3;
    9111          18 :                     n->actions = $4;
    9112          18 :                     $$ = (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         322 :             common_func_opt_item                    { $$ = list_make1($1); }
    9128           4 :             | 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        3422 :                     DropStmt *n = makeNode(DropStmt);
    9154             : 
    9155        3422 :                     n->removeType = OBJECT_FUNCTION;
    9156        3422 :                     n->objects = $3;
    9157        3422 :                     n->behavior = $4;
    9158        3422 :                     n->missing_ok = false;
    9159        3422 :                     n->concurrent = false;
    9160        3422 :                     $$ = (Node *) n;
    9161             :                 }
    9162             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9163             :                 {
    9164         260 :                     DropStmt *n = makeNode(DropStmt);
    9165             : 
    9166         260 :                     n->removeType = OBJECT_FUNCTION;
    9167         260 :                     n->objects = $5;
    9168         260 :                     n->behavior = $6;
    9169         260 :                     n->missing_ok = true;
    9170         260 :                     n->concurrent = false;
    9171         260 :                     $$ = (Node *) n;
    9172             :                 }
    9173             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    9174             :                 {
    9175         140 :                     DropStmt *n = makeNode(DropStmt);
    9176             : 
    9177         140 :                     n->removeType = OBJECT_PROCEDURE;
    9178         140 :                     n->objects = $3;
    9179         140 :                     n->behavior = $4;
    9180         140 :                     n->missing_ok = false;
    9181         140 :                     n->concurrent = false;
    9182         140 :                     $$ = (Node *) n;
    9183             :                 }
    9184             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9185             :                 {
    9186           6 :                     DropStmt *n = makeNode(DropStmt);
    9187             : 
    9188           6 :                     n->removeType = OBJECT_PROCEDURE;
    9189           6 :                     n->objects = $5;
    9190           6 :                     n->behavior = $6;
    9191           6 :                     n->missing_ok = true;
    9192           6 :                     n->concurrent = false;
    9193           6 :                     $$ = (Node *) n;
    9194             :                 }
    9195             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9196             :                 {
    9197          12 :                     DropStmt *n = makeNode(DropStmt);
    9198             : 
    9199          12 :                     n->removeType = OBJECT_ROUTINE;
    9200          12 :                     n->objects = $3;
    9201          12 :                     n->behavior = $4;
    9202          12 :                     n->missing_ok = false;
    9203          12 :                     n->concurrent = false;
    9204          12 :                     $$ = (Node *) n;
    9205             :                 }
    9206             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9207             :                 {
    9208           6 :                     DropStmt *n = makeNode(DropStmt);
    9209             : 
    9210           6 :                     n->removeType = OBJECT_ROUTINE;
    9211           6 :                     n->objects = $5;
    9212           6 :                     n->behavior = $6;
    9213           6 :                     n->missing_ok = true;
    9214           6 :                     n->concurrent = false;
    9215           6 :                     $$ = (Node *) n;
    9216             :                 }
    9217             :         ;
    9218             : 
    9219             : RemoveAggrStmt:
    9220             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9221             :                 {
    9222          74 :                     DropStmt *n = makeNode(DropStmt);
    9223             : 
    9224          74 :                     n->removeType = OBJECT_AGGREGATE;
    9225          74 :                     n->objects = $3;
    9226          74 :                     n->behavior = $4;
    9227          74 :                     n->missing_ok = false;
    9228          74 :                     n->concurrent = false;
    9229          74 :                     $$ = (Node *) n;
    9230             :                 }
    9231             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9232             :                 {
    9233          30 :                     DropStmt *n = makeNode(DropStmt);
    9234             : 
    9235          30 :                     n->removeType = OBJECT_AGGREGATE;
    9236          30 :                     n->objects = $5;
    9237          30 :                     n->behavior = $6;
    9238          30 :                     n->missing_ok = true;
    9239          30 :                     n->concurrent = false;
    9240          30 :                     $$ = (Node *) n;
    9241             :                 }
    9242             :         ;
    9243             : 
    9244             : RemoveOperStmt:
    9245             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9246             :                 {
    9247         200 :                     DropStmt *n = makeNode(DropStmt);
    9248             : 
    9249         200 :                     n->removeType = OBJECT_OPERATOR;
    9250         200 :                     n->objects = $3;
    9251         200 :                     n->behavior = $4;
    9252         200 :                     n->missing_ok = false;
    9253         200 :                     n->concurrent = false;
    9254         200 :                     $$ = (Node *) n;
    9255             :                 }
    9256             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9257             :                 {
    9258          30 :                     DropStmt *n = makeNode(DropStmt);
    9259             : 
    9260          30 :                     n->removeType = OBJECT_OPERATOR;
    9261          30 :                     n->objects = $5;
    9262          30 :                     n->behavior = $6;
    9263          30 :                     n->missing_ok = true;
    9264          30 :                     n->concurrent = false;
    9265          30 :                     $$ = (Node *) n;
    9266             :                 }
    9267             :         ;
    9268             : 
    9269             : oper_argtypes:
    9270             :             '(' Typename ')'
    9271             :                 {
    9272          12 :                    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        2248 :                     { $$ = list_make2($2, $4); }
    9280             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9281          32 :                     { $$ = list_make2(NULL, $4); }
    9282             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9283          12 :                     { $$ = list_make2($2, NULL); }
    9284             :         ;
    9285             : 
    9286             : any_operator:
    9287             :             all_Op
    9288       22856 :                     { $$ = list_make1(makeString($1)); }
    9289             :             | ColId '.' any_operator
    9290       16606 :                     { $$ = lcons(makeString($1), $3); }
    9291             :         ;
    9292             : 
    9293             : operator_with_argtypes_list:
    9294         230 :             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        2292 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9303             : 
    9304        2292 :                     n->objname = $1;
    9305        2292 :                     n->objargs = $2;
    9306        2292 :                     $$ = 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        1158 :                     DoStmt *n = makeNode(DoStmt);
    9322             : 
    9323        1158 :                     n->args = $2;
    9324        1158 :                     $$ = (Node *) n;
    9325             :                 }
    9326             :         ;
    9327             : 
    9328             : dostmt_opt_list:
    9329        1158 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9330         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9331             :         ;
    9332             : 
    9333             : dostmt_opt_item:
    9334             :             Sconst
    9335             :                 {
    9336        1158 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9337             :                 }
    9338             :             | LANGUAGE NonReservedWord_or_Sconst
    9339             :                 {
    9340         198 :                     $$ = 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         108 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9354             : 
    9355         108 :                     n->sourcetype = $4;
    9356         108 :                     n->targettype = $6;
    9357         108 :                     n->func = $10;
    9358         108 :                     n->context = (CoercionContext) $11;
    9359         108 :                     n->inout = false;
    9360         108 :                     $$ = (Node *) n;
    9361             :                 }
    9362             :             | CREATE CAST '(' Typename AS Typename ')'
    9363             :                     WITHOUT FUNCTION cast_context
    9364             :                 {
    9365         162 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9366             : 
    9367         162 :                     n->sourcetype = $4;
    9368         162 :                     n->targettype = $6;
    9369         162 :                     n->func = NULL;
    9370         162 :                     n->context = (CoercionContext) $10;
    9371         162 :                     n->inout = false;
    9372         162 :                     $$ = (Node *) n;
    9373             :                 }
    9374             :             | CREATE CAST '(' Typename AS Typename ')'
    9375             :                     WITH INOUT cast_context
    9376             :                 {
    9377           8 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9378             : 
    9379           8 :                     n->sourcetype = $4;
    9380           8 :                     n->targettype = $6;
    9381           8 :                     n->func = NULL;
    9382           8 :                     n->context = (CoercionContext) $10;
    9383           8 :                     n->inout = true;
    9384           8 :                     $$ = (Node *) n;
    9385             :                 }
    9386             :         ;
    9387             : 
    9388          36 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9389          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9390         184 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9391             :         ;
    9392             : 
    9393             : 
    9394             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9395             :                 {
    9396          60 :                     DropStmt *n = makeNode(DropStmt);
    9397             : 
    9398          60 :                     n->removeType = OBJECT_CAST;
    9399          60 :                     n->objects = list_make1(list_make2($5, $7));
    9400          60 :                     n->behavior = $9;
    9401          60 :                     n->missing_ok = $3;
    9402          60 :                     n->concurrent = false;
    9403          60 :                     $$ = (Node *) n;
    9404             :                 }
    9405             :         ;
    9406             : 
    9407          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9408          38 :         | /*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          50 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9421             : 
    9422          50 :                     n->replace = $2;
    9423          50 :                     n->type_name = $5;
    9424          50 :                     n->lang = $7;
    9425          50 :                     n->fromsql = linitial($9);
    9426          50 :                     n->tosql = lsecond($9);
    9427          50 :                     $$ = (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          44 :                     $$ = 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           4 :                     $$ = list_make2($5, NULL);
    9442             :                 }
    9443             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9444             :                 {
    9445           2 :                     $$ = list_make2(NULL, $5);
    9446             :                 }
    9447             :         ;
    9448             : 
    9449             : 
    9450             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9451             :                 {
    9452          14 :                     DropStmt *n = makeNode(DropStmt);
    9453             : 
    9454          14 :                     n->removeType = OBJECT_TRANSFORM;
    9455          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9456          14 :                     n->behavior = $8;
    9457          14 :                     n->missing_ok = $3;
    9458          14 :                     $$ = (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         950 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9475             : 
    9476         950 :                     n->kind = $3;
    9477         950 :                     n->relation = $5;
    9478         950 :                     n->name = NULL;
    9479         950 :                     n->params = $2;
    9480         950 :                     if ($4)
    9481         546 :                         n->params = lappend(n->params,
    9482         546 :                                             makeDefElem("concurrently", NULL, @4));
    9483         950 :                     $$ = (Node *) n;
    9484             :                 }
    9485             :             | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
    9486             :                 {
    9487         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9488             : 
    9489         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9490         114 :                     n->relation = NULL;
    9491         114 :                     n->name = $5;
    9492         114 :                     n->params = $2;
    9493         114 :                     if ($4)
    9494          40 :                         n->params = lappend(n->params,
    9495          40 :                                             makeDefElem("concurrently", NULL, @4));
    9496         114 :                     $$ = (Node *) n;
    9497             :                 }
    9498             :             | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
    9499             :                 {
    9500          66 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9501             : 
    9502          66 :                     n->kind = $3;
    9503          66 :                     n->relation = NULL;
    9504          66 :                     n->name = $5;
    9505          66 :                     n->params = $2;
    9506          66 :                     if ($4)
    9507          10 :                         n->params = lappend(n->params,
    9508          10 :                                             makeDefElem("concurrently", NULL, @4));
    9509          66 :                     $$ = (Node *) n;
    9510             :                 }
    9511             :         ;
    9512             : reindex_target_relation:
    9513         422 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9514         528 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9515             :         ;
    9516             : reindex_target_all:
    9517          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9518          32 :             | 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          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9532             : 
    9533          12 :                     n->tablespacename = $3;
    9534          12 :                     n->options = $5;
    9535          12 :                     n->isReset = false;
    9536          12 :                     $$ = (Node *) n;
    9537             :                 }
    9538             :             | ALTER TABLESPACE name RESET reloptions
    9539             :                 {
    9540             :                     AlterTableSpaceOptionsStmt *n =
    9541          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9542             : 
    9543          12 :                     n->tablespacename = $3;
    9544          12 :                     n->options = $5;
    9545          12 :                     n->isReset = true;
    9546          12 :                     $$ = (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          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9559             : 
    9560          42 :                     n->renameType = OBJECT_AGGREGATE;
    9561          42 :                     n->object = (Node *) $3;
    9562          42 :                     n->newname = $6;
    9563          42 :                     n->missing_ok = false;
    9564          42 :                     $$ = (Node *) n;
    9565             :                 }
    9566             :             | ALTER COLLATION any_name RENAME TO name
    9567             :                 {
    9568          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9569             : 
    9570          18 :                     n->renameType = OBJECT_COLLATION;
    9571          18 :                     n->object = (Node *) $3;
    9572          18 :                     n->newname = $6;
    9573          18 :                     n->missing_ok = false;
    9574          18 :                     $$ = (Node *) n;
    9575             :                 }
    9576             :             | ALTER CONVERSION_P any_name RENAME TO name
    9577             :                 {
    9578          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9579             : 
    9580          24 :                     n->renameType = OBJECT_CONVERSION;
    9581          24 :                     n->object = (Node *) $3;
    9582          24 :                     n->newname = $6;
    9583          24 :                     n->missing_ok = false;
    9584          24 :                     $$ = (Node *) n;
    9585             :                 }
    9586             :             | ALTER DATABASE name RENAME TO name
    9587             :                 {
    9588          14 :                     RenameStmt *n = makeNode(RenameStmt);
    9589             : 
    9590          14 :                     n->renameType = OBJECT_DATABASE;
    9591          14 :                     n->subname = $3;
    9592          14 :                     n->newname = $6;
    9593          14 :                     n->missing_ok = false;
    9594          14 :                     $$ = (Node *) n;
    9595             :                 }
    9596             :             | ALTER DOMAIN_P any_name RENAME TO name
    9597             :                 {
    9598           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9599             : 
    9600           6 :                     n->renameType = OBJECT_DOMAIN;
    9601           6 :                     n->object = (Node *) $3;
    9602           6 :                     n->newname = $6;
    9603           6 :                     n->missing_ok = false;
    9604           6 :                     $$ = (Node *) n;
    9605             :                 }
    9606             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9607             :                 {
    9608           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9609             : 
    9610           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9611           6 :                     n->object = (Node *) $3;
    9612           6 :                     n->subname = $6;
    9613           6 :                     n->newname = $8;
    9614           6 :                     $$ = (Node *) n;
    9615             :                 }
    9616             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9617             :                 {
    9618          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9619             : 
    9620          24 :                     n->renameType = OBJECT_FDW;
    9621          24 :                     n->object = (Node *) makeString($5);
    9622          24 :                     n->newname = $8;
    9623          24 :                     n->missing_ok = false;
    9624          24 :                     $$ = (Node *) n;
    9625             :                 }
    9626             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9627             :                 {
    9628          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9629             : 
    9630          24 :                     n->renameType = OBJECT_FUNCTION;
    9631          24 :                     n->object = (Node *) $3;
    9632          24 :                     n->newname = $6;
    9633          24 :                     n->missing_ok = false;
    9634          24 :                     $$ = (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          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9649             : 
    9650          18 :                     n->renameType = OBJECT_LANGUAGE;
    9651          18 :                     n->object = (Node *) makeString($4);
    9652          18 :                     n->newname = $7;
    9653          18 :                     n->missing_ok = false;
    9654          18 :                     $$ = (Node *) n;
    9655             :                 }
    9656             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9657             :                 {
    9658          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9659             : 
    9660          24 :                     n->renameType = OBJECT_OPCLASS;
    9661          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9662          24 :                     n->newname = $9;
    9663          24 :                     n->missing_ok = false;
    9664          24 :                     $$ = (Node *) n;
    9665             :                 }
    9666             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9667             :                 {
    9668          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9669             : 
    9670          24 :                     n->renameType = OBJECT_OPFAMILY;
    9671          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9672          24 :                     n->newname = $9;
    9673          24 :                     n->missing_ok = false;
    9674          24 :                     $$ = (Node *) n;
    9675             :                 }
    9676             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9677             :                 {
    9678          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9679             : 
    9680          18 :                     n->renameType = OBJECT_POLICY;
    9681          18 :                     n->relation = $5;
    9682          18 :                     n->subname = $3;
    9683          18 :                     n->newname = $8;
    9684          18 :                     n->missing_ok = false;
    9685          18 :                     $$ = (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          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9711             : 
    9712          42 :                     n->renameType = OBJECT_PUBLICATION;
    9713          42 :                     n->object = (Node *) makeString($3);
    9714          42 :                     n->newname = $6;
    9715          42 :                     n->missing_ok = false;
    9716          42 :                     $$ = (Node *) n;
    9717             :                 }
    9718             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9719             :                 {
    9720          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9721             : 
    9722          24 :                     n->renameType = OBJECT_ROUTINE;
    9723          24 :                     n->object = (Node *) $3;
    9724          24 :                     n->newname = $6;
    9725          24 :                     n->missing_ok = false;
    9726          24 :                     $$ = (Node *) n;
    9727             :                 }
    9728             :             | ALTER SCHEMA name RENAME TO name
    9729             :                 {
    9730          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9731             : 
    9732          20 :                     n->renameType = OBJECT_SCHEMA;
    9733          20 :                     n->subname = $3;
    9734          20 :                     n->newname = $6;
    9735          20 :                     n->missing_ok = false;
    9736          20 :                     $$ = (Node *) n;
    9737             :                 }
    9738             :             | ALTER SERVER name RENAME TO name
    9739             :                 {
    9740          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9741             : 
    9742          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9743          24 :                     n->object = (Node *) makeString($3);
    9744          24 :                     n->newname = $6;
    9745          24 :                     n->missing_ok = false;
    9746          24 :                     $$ = (Node *) n;
    9747             :                 }
    9748             :             | ALTER SUBSCRIPTION name RENAME TO name
    9749             :                 {
    9750          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9751             : 
    9752          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9753          38 :                     n->object = (Node *) makeString($3);
    9754          38 :                     n->newname = $6;
    9755          38 :                     n->missing_ok = false;
    9756          38 :                     $$ = (Node *) n;
    9757             :                 }
    9758             :             | ALTER TABLE relation_expr RENAME TO name
    9759             :                 {
    9760         288 :                     RenameStmt *n = makeNode(RenameStmt);
    9761             : 
    9762         288 :                     n->renameType = OBJECT_TABLE;
    9763         288 :                     n->relation = $3;
    9764         288 :                     n->subname = NULL;
    9765         288 :                     n->newname = $6;
    9766         288 :                     n->missing_ok = false;
    9767         288 :                     $$ = (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           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9783             : 
    9784           2 :                     n->renameType = OBJECT_SEQUENCE;
    9785           2 :                     n->relation = $3;
    9786           2 :                     n->subname = NULL;
    9787           2 :                     n->newname = $6;
    9788           2 :                     n->missing_ok = false;
    9789           2 :                     $$ = (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           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9805             : 
    9806           6 :                     n->renameType = OBJECT_VIEW;
    9807           6 :                     n->relation = $3;
    9808           6 :                     n->subname = NULL;
    9809           6 :                     n->newname = $6;
    9810           6 :                     n->missing_ok = false;
    9811           6 :                     $$ = (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         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9849             : 
    9850         192 :                     n->renameType = OBJECT_INDEX;
    9851         192 :                     n->relation = $3;
    9852         192 :                     n->subname = NULL;
    9853         192 :                     n->newname = $6;
    9854         192 :                     n->missing_ok = false;
    9855         192 :                     $$ = (Node *) n;
    9856             :                 }
    9857             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9858             :                 {
    9859          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9860             : 
    9861          12 :                     n->renameType = OBJECT_INDEX;
    9862          12 :                     n->relation = $5;
    9863          12 :                     n->subname = NULL;
    9864          12 :                     n->newname = $8;
    9865          12 :                     n->missing_ok = true;
    9866          12 :                     $$ = (Node *) n;
    9867             :                 }
    9868             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9869             :                 {
    9870           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9871             : 
    9872           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9873           6 :                     n->relation = $4;
    9874           6 :                     n->subname = NULL;
    9875           6 :                     n->newname = $7;
    9876           6 :                     n->missing_ok = false;
    9877           6 :                     $$ = (Node *) n;
    9878             :                 }
    9879             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9880             :                 {
    9881           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9882             : 
    9883           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9884           6 :                     n->relation = $6;
    9885           6 :                     n->subname = NULL;
    9886           6 :                     n->newname = $9;
    9887           6 :                     n->missing_ok = true;
    9888           6 :                     $$ = (Node *) n;
    9889             :                 }
    9890             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9891             :                 {
    9892         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9893             : 
    9894         238 :                     n->renameType = OBJECT_COLUMN;
    9895         238 :                     n->relationType = OBJECT_TABLE;
    9896         238 :                     n->relation = $3;
    9897         238 :                     n->subname = $6;
    9898         238 :                     n->newname = $8;
    9899         238 :                     n->missing_ok = false;
    9900         238 :                     $$ = (Node *) n;
    9901             :                 }
    9902             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9903             :                 {
    9904          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9905             : 
    9906          24 :                     n->renameType = OBJECT_COLUMN;
    9907          24 :                     n->relationType = OBJECT_TABLE;
    9908          24 :                     n->relation = $5;
    9909          24 :                     n->subname = $8;
    9910          24 :                     n->newname = $10;
    9911          24 :                     n->missing_ok = true;
    9912          24 :                     $$ = (Node *) n;
    9913             :                 }
    9914             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9915             :                 {
    9916          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9917             : 
    9918          18 :                     n->renameType = OBJECT_COLUMN;
    9919          18 :                     n->relationType = OBJECT_VIEW;
    9920          18 :                     n->relation = $3;
    9921          18 :                     n->subname = $6;
    9922          18 :                     n->newname = $8;
    9923          18 :                     n->missing_ok = false;
    9924          18 :                     $$ = (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          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9965             : 
    9966          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9967          72 :                     n->relation = $3;
    9968          72 :                     n->subname = $6;
    9969          72 :                     n->newname = $8;
    9970          72 :                     n->missing_ok = false;
    9971          72 :                     $$ = (Node *) n;
    9972             :                 }
    9973             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9974             :                 {
    9975           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9976             : 
    9977           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9978           6 :                     n->relation = $5;
    9979           6 :                     n->subname = $8;
    9980           6 :                     n->newname = $10;
    9981           6 :                     n->missing_ok = true;
    9982           6 :                     $$ = (Node *) n;
    9983             :                 }
    9984             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9985             :                 {
    9986           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9987             : 
    9988           6 :                     n->renameType = OBJECT_COLUMN;
    9989           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9990           6 :                     n->relation = $4;
    9991           6 :                     n->subname = $7;
    9992           6 :                     n->newname = $9;
    9993           6 :                     n->missing_ok = false;
    9994           6 :                     $$ = (Node *) n;
    9995             :                 }
    9996             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9997             :                 {
    9998           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9999             : 
   10000           6 :                     n->renameType = OBJECT_COLUMN;
   10001           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
   10002           6 :                     n->relation = $6;
   10003           6 :                     n->subname = $9;
   10004           6 :                     n->newname = $11;
   10005           6 :                     n->missing_ok = true;
   10006           6 :                     $$ = (Node *) n;
   10007             :                 }
   10008             :             | ALTER RULE name ON qualified_name RENAME TO name
   10009             :                 {
   10010          34 :                     RenameStmt *n = makeNode(RenameStmt);
   10011             : 
   10012          34 :                     n->renameType = OBJECT_RULE;
   10013          34 :                     n->relation = $5;
   10014          34 :                     n->subname = $3;
   10015          34 :                     n->newname = $8;
   10016          34 :                     n->missing_ok = false;
   10017          34 :                     $$ = (Node *) n;
   10018             :                 }
   10019             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
   10020             :                 {
   10021          40 :                     RenameStmt *n = makeNode(RenameStmt);
   10022             : 
   10023          40 :                     n->renameType = OBJECT_TRIGGER;
   10024          40 :                     n->relation = $5;
   10025          40 :                     n->subname = $3;
   10026          40 :                     n->newname = $8;
   10027          40 :                     n->missing_ok = false;
   10028          40 :                     $$ = (Node *) n;
   10029             :                 }
   10030             :             | ALTER EVENT TRIGGER name RENAME TO name
   10031             :                 {
   10032          12 :                     RenameStmt *n = makeNode(RenameStmt);
   10033             : 
   10034          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
   10035          12 :                     n->object = (Node *) makeString($4);
   10036          12 :                     n->newname = $7;
   10037          12 :                     $$ = (Node *) n;
   10038             :                 }
   10039             :             | ALTER ROLE RoleId RENAME TO RoleId
   10040             :                 {
   10041          32 :                     RenameStmt *n = makeNode(RenameStmt);
   10042             : 
   10043          32 :                     n->renameType = OBJECT_ROLE;
   10044          32 :                     n->subname = $3;
   10045          32 :                     n->newname = $6;
   10046          32 :                     n->missing_ok = false;
   10047          32 :                     $$ = (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          30 :                     RenameStmt *n = makeNode(RenameStmt);
   10072             : 
   10073          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
   10074          30 :                     n->object = (Node *) $3;
   10075          30 :                     n->newname = $6;
   10076          30 :                     n->missing_ok = false;
   10077          30 :                     $$ = (Node *) n;
   10078             :                 }
   10079             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
   10080             :                 {
   10081          12 :                     RenameStmt *n = makeNode(RenameStmt);
   10082             : 
   10083          12 :                     n->renameType = OBJECT_TSPARSER;
   10084          12 :                     n->object = (Node *) $5;
   10085          12 :                     n->newname = $8;
   10086          12 :                     n->missing_ok = false;
   10087          12 :                     $$ = (Node *) n;
   10088             :                 }
   10089             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
   10090             :                 {
   10091          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10092             : 
   10093          24 :                     n->renameType = OBJECT_TSDICTIONARY;
   10094          24 :                     n->object = (Node *) $5;
   10095          24 :                     n->newname = $8;
   10096          24 :                     n->missing_ok = false;
   10097          24 :                     $$ = (Node *) n;
   10098             :                 }
   10099             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
   10100             :                 {
   10101          12 :                     RenameStmt *n = makeNode(RenameStmt);
   10102             : 
   10103          12 :                     n->renameType = OBJECT_TSTEMPLATE;
   10104          12 :                     n->object = (Node *) $5;
   10105          12 :                     n->newname = $8;
   10106          12 :                     n->missing_ok = false;
   10107          12 :                     $$ = (Node *) n;
   10108             :                 }
   10109             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
   10110             :                 {
   10111          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10112             : 
   10113          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
   10114          24 :                     n->object = (Node *) $5;
   10115          24 :                     n->newname = $8;
   10116          24 :                     n->missing_ok = false;
   10117          24 :                     $$ = (Node *) n;
   10118             :                 }
   10119             :             | ALTER TYPE_P any_name RENAME TO name
   10120             :                 {
   10121          26 :                     RenameStmt *n = makeNode(RenameStmt);
   10122             : 
   10123          26 :                     n->renameType = OBJECT_TYPE;
   10124          26 :                     n->object = (Node *) $3;
   10125          26 :                     n->newname = $6;
   10126          26 :                     n->missing_ok = false;
   10127          26 :                     $$ = (Node *) n;
   10128             :                 }
   10129             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
   10130             :                 {
   10131          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10132             : 
   10133          24 :                     n->renameType = OBJECT_ATTRIBUTE;
   10134          24 :                     n->relationType = OBJECT_TYPE;
   10135          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
   10136          24 :                     n->subname = $6;
   10137          24 :                     n->newname = $8;
   10138          24 :                     n->behavior = $9;
   10139          24 :                     n->missing_ok = false;
   10140          24 :                     $$ = (Node *) n;
   10141             :                 }
   10142             :         ;
   10143             : 
   10144             : opt_column: COLUMN
   10145             :             | /*EMPTY*/
   10146             :         ;
   10147             : 
   10148         184 : opt_set_data: SET DATA_P                            { $$ = 1; }
   10149        1028 :             | /*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          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10162             : 
   10163          12 :                     n->objectType = OBJECT_FUNCTION;
   10164          12 :                     n->object = (Node *) $3;
   10165          12 :                     n->extname = makeString($8);
   10166          12 :                     n->remove = $4;
   10167          12 :                     $$ = (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          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10192             : 
   10193          10 :                     n->objectType = OBJECT_TRIGGER;
   10194          10 :                     n->relation = $5;
   10195          10 :                     n->object = (Node *) list_make1(makeString($3));
   10196          10 :                     n->extname = makeString($10);
   10197          10 :                     n->remove = $6;
   10198          10 :                     $$ = (Node *) n;
   10199             :                 }
   10200             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10201             :                 {
   10202          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10203             : 
   10204          10 :                     n->objectType = OBJECT_MATVIEW;
   10205          10 :                     n->relation = $4;
   10206          10 :                     n->extname = makeString($9);
   10207          10 :                     n->remove = $5;
   10208          10 :                     $$ = (Node *) n;
   10209             :                 }
   10210             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10211             :                 {
   10212          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10213             : 
   10214          14 :                     n->objectType = OBJECT_INDEX;
   10215          14 :                     n->relation = $3;
   10216          14 :                     n->extname = makeString($8);
   10217          14 :                     n->remove = $4;
   10218          14 :                     $$ = (Node *) n;
   10219             :                 }
   10220             :         ;
   10221             : 
   10222           8 : opt_no:     NO              { $$ = true; }
   10223          38 :             | /* 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          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10236             : 
   10237          24 :                     n->objectType = OBJECT_AGGREGATE;
   10238          24 :                     n->object = (Node *) $3;
   10239          24 :                     n->newschema = $6;
   10240          24 :                     n->missing_ok = false;
   10241          24 :                     $$ = (Node *) n;
   10242             :                 }
   10243             :             | ALTER COLLATION any_name SET SCHEMA name
   10244             :                 {
   10245           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10246             : 
   10247           6 :                     n->objectType = OBJECT_COLLATION;
   10248           6 :                     n->object = (Node *) $3;
   10249           6 :                     n->newschema = $6;
   10250           6 :                     n->missing_ok = false;
   10251           6 :                     $$ = (Node *) n;
   10252             :                 }
   10253             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10254             :                 {
   10255          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10256             : 
   10257          24 :                     n->objectType = OBJECT_CONVERSION;
   10258          24 :                     n->object = (Node *) $3;
   10259          24 :                     n->newschema = $6;
   10260          24 :                     n->missing_ok = false;
   10261          24 :                     $$ = (Node *) n;
   10262             :                 }
   10263             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10264             :                 {
   10265           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10266             : 
   10267           6 :                     n->objectType = OBJECT_DOMAIN;
   10268           6 :                     n->object = (Node *) $3;
   10269           6 :                     n->newschema = $6;
   10270           6 :                     n->missing_ok = false;
   10271           6 :                     $$ = (Node *) n;
   10272             :                 }
   10273             :             | ALTER EXTENSION name SET SCHEMA name
   10274             :                 {
   10275          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10276             : 
   10277          12 :                     n->objectType = OBJECT_EXTENSION;
   10278          12 :                     n->object = (Node *) makeString($3);
   10279          12 :                     n->newschema = $6;
   10280          12 :                     n->missing_ok = false;
   10281          12 :                     $$ = (Node *) n;
   10282             :                 }
   10283             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10284             :                 {
   10285          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10286             : 
   10287          42 :                     n->objectType = OBJECT_FUNCTION;
   10288          42 :                     n->object = (Node *) $3;
   10289          42 :                     n->newschema = $6;
   10290          42 :                     n->missing_ok = false;
   10291          42 :                     $$ = (Node *) n;
   10292             :                 }
   10293             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10294             :                 {
   10295          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10296             : 
   10297          18 :                     n->objectType = OBJECT_OPERATOR;
   10298          18 :                     n->object = (Node *) $3;
   10299          18 :                     n->newschema = $6;
   10300          18 :                     n->missing_ok = false;
   10301          18 :                     $$ = (Node *) n;
   10302             :                 }
   10303             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10304             :                 {
   10305          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10306             : 
   10307          24 :                     n->objectType = OBJECT_OPCLASS;
   10308          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10309          24 :                     n->newschema = $9;
   10310          24 :                     n->missing_ok = false;
   10311          24 :                     $$ = (Node *) n;
   10312             :                 }
   10313             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10314             :                 {
   10315          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10316             : 
   10317          24 :                     n->objectType = OBJECT_OPFAMILY;
   10318          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10319          24 :                     n->newschema = $9;
   10320          24 :                     n->missing_ok = false;
   10321          24 :                     $$ = (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          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10346             : 
   10347          66 :                     n->objectType = OBJECT_TABLE;
   10348          66 :                     n->relation = $3;
   10349          66 :                     n->newschema = $6;
   10350          66 :                     n->missing_ok = false;
   10351          66 :                     $$ = (Node *) n;
   10352             :                 }
   10353             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10354             :                 {
   10355          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10356             : 
   10357          12 :                     n->objectType = OBJECT_TABLE;
   10358          12 :                     n->relation = $5;
   10359          12 :                     n->newschema = $8;
   10360          12 :                     n->missing_ok = true;
   10361          12 :                     $$ = (Node *) n;
   10362             :                 }
   10363             :             | ALTER STATISTICS any_name SET SCHEMA name
   10364             :                 {
   10365          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10366             : 
   10367          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10368          18 :                     n->object = (Node *) $3;
   10369          18 :                     n->newschema = $6;
   10370          18 :                     n->missing_ok = false;
   10371          18 :                     $$ = (Node *) n;
   10372             :                 }
   10373             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10374             :                 {
   10375          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10376             : 
   10377          18 :                     n->objectType = OBJECT_TSPARSER;
   10378          18 :                     n->object = (Node *) $5;
   10379          18 :                     n->newschema = $8;
   10380          18 :                     n->missing_ok = false;
   10381          18 :                     $$ = (Node *) n;
   10382             :                 }
   10383             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10384             :                 {
   10385          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10386             : 
   10387          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10388          24 :                     n->object = (Node *) $5;
   10389          24 :                     n->newschema = $8;
   10390          24 :                     n->missing_ok = false;
   10391          24 :                     $$ = (Node *) n;
   10392             :                 }
   10393             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10394             :                 {
   10395          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10396             : 
   10397          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10398          18 :                     n->object = (Node *) $5;
   10399          18 :                     n->newschema = $8;
   10400          18 :                     n->missing_ok = false;
   10401          18 :                     $$ = (Node *) n;
   10402             :                 }
   10403             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10404             :                 {
   10405          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10406             : 
   10407          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10408          24 :                     n->object = (Node *) $5;
   10409          24 :                     n->newschema = $8;
   10410          24 :                     n->missing_ok = false;
   10411          24 :                     $$ = (Node *) n;
   10412             :                 }
   10413             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10414             :                 {
   10415           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10416             : 
   10417           8 :                     n->objectType = OBJECT_SEQUENCE;
   10418           8 :                     n->relation = $3;
   10419           8 :                     n->newschema = $6;
   10420           8 :                     n->missing_ok = false;
   10421           8 :                     $$ = (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           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10456             : 
   10457           6 :                     n->objectType = OBJECT_MATVIEW;
   10458           6 :                     n->relation = $4;
   10459           6 :                     n->newschema = $7;
   10460           6 :                     n->missing_ok = false;
   10461           6 :                     $$ = (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           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10476             : 
   10477           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10478           6 :                     n->relation = $4;
   10479           6 :                     n->newschema = $7;
   10480           6 :                     n->missing_ok = false;
   10481           6 :                     $$ = (Node *) n;
   10482             :                 }
   10483             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10484             :                 {
   10485           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10486             : 
   10487           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10488           6 :                     n->relation = $6;
   10489           6 :                     n->newschema = $9;
   10490           6 :                     n->missing_ok = true;
   10491           6 :                     $$ = (Node *) n;
   10492             :                 }
   10493             :             | ALTER TYPE_P any_name SET SCHEMA name
   10494             :                 {
   10495          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10496             : 
   10497          12 :                     n->objectType = OBJECT_TYPE;
   10498          12 :                     n->object = (Node *) $3;
   10499          12 :                     n->newschema = $6;
   10500          12 :                     n->missing_ok = false;
   10501          12 :                     $$ = (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         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10515             : 
   10516         608 :                     n->opername = $3;
   10517         608 :                     n->options = $6;
   10518         608 :                     $$ = (Node *) n;
   10519             :                 }
   10520             :         ;
   10521             : 
   10522         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10523         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10524             :         ;
   10525             : 
   10526             : operator_def_elem: ColLabel '=' NONE
   10527          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10528             :                    | ColLabel '=' operator_def_arg
   10529        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10530             :                    | ColLabel
   10531          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10532             :         ;
   10533             : 
   10534             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10535             : operator_def_arg:
   10536        1032 :             func_type                       { $$ = (Node *) $1; }
   10537          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10538          54 :             | 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          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10555             : 
   10556          60 :                     n->typeName = $3;
   10557          60 :                     n->options = $6;
   10558          60 :                     $$ = (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         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10571             : 
   10572         142 :                     n->objectType = OBJECT_AGGREGATE;
   10573         142 :                     n->object = (Node *) $3;
   10574         142 :                     n->newowner = $6;
   10575         142 :                     $$ = (Node *) n;
   10576             :                 }
   10577             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10578             :                 {
   10579          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10580             : 
   10581          18 :                     n->objectType = OBJECT_COLLATION;
   10582          18 :                     n->object = (Node *) $3;
   10583          18 :                     n->newowner = $6;
   10584          18 :                     $$ = (Node *) n;
   10585             :                 }
   10586             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10587             :                 {
   10588          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10589             : 
   10590          24 :                     n->objectType = OBJECT_CONVERSION;
   10591          24 :                     n->object = (Node *) $3;
   10592          24 :                     n->newowner = $6;
   10593          24 :                     $$ = (Node *) n;
   10594             :                 }
   10595             :             | ALTER DATABASE name OWNER TO RoleSpec
   10596             :                 {
   10597          90 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10598             : 
   10599          90 :                     n->objectType = OBJECT_DATABASE;
   10600          90 :                     n->object = (Node *) makeString($3);
   10601          90 :                     n->newowner = $6;
   10602          90 :                     $$ = (Node *) n;
   10603             :                 }
   10604             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10605             :                 {
   10606          48 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10607             : 
   10608          48 :                     n->objectType = OBJECT_DOMAIN;
   10609          48 :                     n->object = (Node *) $3;
   10610          48 :                     n->newowner = $6;
   10611          48 :                     $$ = (Node *) n;
   10612             :                 }
   10613             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10614             :                 {
   10615         598 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10616             : 
   10617         598 :                     n->objectType = OBJECT_FUNCTION;
   10618         598 :                     n->object = (Node *) $3;
   10619         598 :                     n->newowner = $6;
   10620         598 :                     $$ = (Node *) n;
   10621             :                 }
   10622             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10623             :                 {
   10624         144 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10625             : 
   10626         144 :                     n->objectType = OBJECT_LANGUAGE;
   10627         144 :                     n->object = (Node *) makeString($4);
   10628         144 :                     n->newowner = $7;
   10629         144 :                     $$ = (Node *) n;
   10630             :                 }
   10631             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10632             :                 {
   10633          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10634             : 
   10635          16 :                     n->objectType = OBJECT_LARGEOBJECT;
   10636          16 :                     n->object = (Node *) $4;
   10637          16 :                     n->newowner = $7;
   10638          16 :                     $$ = (Node *) n;
   10639             :                 }
   10640             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10641             :                 {
   10642          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10643             : 
   10644          46 :                     n->objectType = OBJECT_OPERATOR;
   10645          46 :                     n->object = (Node *) $3;
   10646          46 :                     n->newowner = $6;
   10647          46 :                     $$ = (Node *) n;
   10648             :                 }
   10649             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10650             :                 {
   10651          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10652             : 
   10653          54 :                     n->objectType = OBJECT_OPCLASS;
   10654          54 :                     n->object = (Node *) lcons(makeString($6), $4);
   10655          54 :                     n->newowner = $9;
   10656          54 :                     $$ = (Node *) n;
   10657             :                 }
   10658             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10659             :                 {
   10660          62 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10661             : 
   10662          62 :                     n->objectType = OBJECT_OPFAMILY;
   10663          62 :                     n->object = (Node *) lcons(makeString($6), $4);
   10664          62 :                     n->newowner = $9;
   10665          62 :                     $$ = (Node *) n;
   10666             :                 }
   10667             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10668             :                 {
   10669          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10670             : 
   10671          24 :                     n->objectType = OBJECT_PROCEDURE;
   10672          24 :                     n->object = (Node *) $3;
   10673          24 :                     n->newowner = $6;
   10674          24 :                     $$ = (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          64 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10688             : 
   10689          64 :                     n->objectType = OBJECT_SCHEMA;
   10690          64 :                     n->object = (Node *) makeString($3);
   10691          64 :                     n->newowner = $6;
   10692          64 :                     $$ = (Node *) n;
   10693             :                 }
   10694             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10695             :                 {
   10696          84 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10697             : 
   10698          84 :                     n->objectType = OBJECT_TYPE;
   10699          84 :                     n->object = (Node *) $3;
   10700          84 :                     n->newowner = $6;
   10701          84 :                     $$ = (Node *) n;
   10702             :                 }
   10703             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10704             :                 {
   10705           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10706             : 
   10707           6 :                     n->objectType = OBJECT_TABLESPACE;
   10708           6 :                     n->object = (Node *) makeString($3);
   10709           6 :                     n->newowner = $6;
   10710           6 :                     $$ = (Node *) n;
   10711             :                 }
   10712             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10713             :                 {
   10714          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10715             : 
   10716          32 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10717          32 :                     n->object = (Node *) $3;
   10718          32 :                     n->newowner = $6;
   10719          32 :                     $$ = (Node *) n;
   10720             :                 }
   10721             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10722             :                 {
   10723          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10724             : 
   10725          42 :                     n->objectType = OBJECT_TSDICTIONARY;
   10726          42 :                     n->object = (Node *) $5;
   10727          42 :                     n->newowner = $8;
   10728          42 :                     $$ = (Node *) n;
   10729             :                 }
   10730             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10731             :                 {
   10732          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10733             : 
   10734          32 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10735          32 :                     n->object = (Node *) $5;
   10736          32 :                     n->newowner = $8;
   10737          32 :                     $$ = (Node *) n;
   10738             :                 }
   10739             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10740             :                 {
   10741          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10742             : 
   10743          20 :                     n->objectType = OBJECT_FDW;
   10744          20 :                     n->object = (Node *) makeString($5);
   10745          20 :                     n->newowner = $8;
   10746          20 :                     $$ = (Node *) n;
   10747             :                 }
   10748             :             | ALTER SERVER name OWNER TO RoleSpec
   10749             :                 {
   10750          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10751             : 
   10752          68 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10753          68 :                     n->object = (Node *) makeString($3);
   10754          68 :                     n->newowner = $6;
   10755          68 :                     $$ = (Node *) n;
   10756             :                 }
   10757             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10758             :                 {
   10759          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10760             : 
   10761          14 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10762          14 :                     n->object = (Node *) makeString($4);
   10763          14 :                     n->newowner = $7;
   10764          14 :                     $$ = (Node *) n;
   10765             :                 }
   10766             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10767             :                 {
   10768          36 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10769             : 
   10770          36 :                     n->objectType = OBJECT_PUBLICATION;
   10771          36 :                     n->object = (Node *) makeString($3);
   10772          36 :                     n->newowner = $6;
   10773          36 :                     $$ = (Node *) n;
   10774             :                 }
   10775             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10776             :                 {
   10777          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10778             : 
   10779          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10780          18 :                     n->object = (Node *) makeString($3);
   10781          18 :                     n->newowner = $6;
   10782          18 :                     $$ = (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         146 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10811             : 
   10812         146 :                     n->pubname = $3;
   10813         146 :                     n->options = $4;
   10814         146 :                     $$ = (Node *) n;
   10815             :                 }
   10816             :             | CREATE PUBLICATION name FOR pub_all_obj_type_list opt_definition
   10817             :                 {
   10818         138 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10819             : 
   10820         138 :                     n->pubname = $3;
   10821         138 :                     preprocess_pub_all_objtype_list($5, &n->for_all_tables,
   10822             :                                                     &n->for_all_sequences,
   10823             :                                                     yyscanner);
   10824         126 :                     n->options = $6;
   10825         126 :                     $$ = (Node *) n;
   10826             :                 }
   10827             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10828             :                 {
   10829         660 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10830             : 
   10831         660 :                     n->pubname = $3;
   10832         660 :                     n->options = $6;
   10833         660 :                     n->pubobjects = (List *) $5;
   10834         660 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10835         630 :                     $$ = (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        1328 :                     $$ = makeNode(PublicationObjSpec);
   10856        1328 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10857        1328 :                     $$->pubtable = makeNode(PublicationTable);
   10858        1328 :                     $$->pubtable->relation = $2;
   10859        1328 :                     $$->pubtable->columns = $3;
   10860        1328 :                     $$->pubtable->whereClause = $4;
   10861             :                 }
   10862             :             | TABLES IN_P SCHEMA ColId
   10863             :                 {
   10864         372 :                     $$ = makeNode(PublicationObjSpec);
   10865         372 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10866         372 :                     $$->name = $4;
   10867         372 :                     $$->location = @4;
   10868             :                 }
   10869             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10870             :                 {
   10871          18 :                     $$ = makeNode(PublicationObjSpec);
   10872          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10873          18 :                     $$->location = @4;
   10874             :                 }
   10875             :             | ColId opt_column_list OptWhereClause
   10876             :                 {
   10877         132 :                     $$ = makeNode(PublicationObjSpec);
   10878         132 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10879             :                     /*
   10880             :                      * If either a row filter or column list is specified, create
   10881             :                      * a PublicationTable object.
   10882             :                      */
   10883         132 :                     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          42 :                         $$->pubtable = makeNode(PublicationTable);
   10892          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10893          42 :                         $$->pubtable->columns = $2;
   10894          42 :                         $$->pubtable->whereClause = $3;
   10895             :                     }
   10896             :                     else
   10897             :                     {
   10898          90 :                         $$->name = $1;
   10899             :                     }
   10900         132 :                     $$->location = @1;
   10901             :                 }
   10902             :             | ColId indirection opt_column_list OptWhereClause
   10903             :                 {
   10904          32 :                     $$ = makeNode(PublicationObjSpec);
   10905          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10906          32 :                     $$->pubtable = makeNode(PublicationTable);
   10907          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10908          32 :                     $$->pubtable->columns = $3;
   10909          32 :                     $$->pubtable->whereClause = $4;
   10910          32 :                     $$->location = @1;
   10911             :                 }
   10912             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10913             :             | extended_relation_expr opt_column_list OptWhereClause
   10914             :                 {
   10915           6 :                     $$ = makeNode(PublicationObjSpec);
   10916           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10917           6 :                     $$->pubtable = makeNode(PublicationTable);
   10918           6 :                     $$->pubtable->relation = $1;
   10919           6 :                     $$->pubtable->columns = $2;
   10920           6 :                     $$->pubtable->whereClause = $3;
   10921             :                 }
   10922             :             | CURRENT_SCHEMA
   10923             :                 {
   10924          18 :                     $$ = makeNode(PublicationObjSpec);
   10925          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10926          18 :                     $$->location = @1;
   10927             :                 }
   10928             :                 ;
   10929             : 
   10930             : pub_obj_list:   PublicationObjSpec
   10931        1650 :                     { $$ = list_make1($1); }
   10932             :             | pub_obj_list ',' PublicationObjSpec
   10933         256 :                     { $$ = lappend($1, $3); }
   10934             :     ;
   10935             : 
   10936             : PublicationAllObjSpec:
   10937             :                 ALL TABLES
   10938             :                     {
   10939         124 :                         $$ = makeNode(PublicationAllObjSpec);
   10940         124 :                         $$->pubobjtype = PUBLICATION_ALL_TABLES;
   10941         124 :                         $$->location = @1;
   10942             :                     }
   10943             :                 | ALL SEQUENCES
   10944             :                     {
   10945          46 :                         $$ = makeNode(PublicationAllObjSpec);
   10946          46 :                         $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
   10947          46 :                         $$->location = @1;
   10948             :                     }
   10949             :                     ;
   10950             : 
   10951             : pub_all_obj_type_list:  PublicationAllObjSpec
   10952         138 :                     { $$ = list_make1($1); }
   10953             :                 | pub_all_obj_type_list ',' PublicationAllObjSpec
   10954          32 :                     { $$ = 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         128 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10979             : 
   10980         128 :                     n->pubname = $3;
   10981         128 :                     n->options = $5;
   10982         128 :                     $$ = (Node *) n;
   10983             :                 }
   10984             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10985             :                 {
   10986         370 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10987             : 
   10988         370 :                     n->pubname = $3;
   10989         370 :                     n->pubobjects = $5;
   10990         370 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10991         364 :                     n->action = AP_AddObjects;
   10992         364 :                     $$ = (Node *) n;
   10993             :                 }
   10994             :             | ALTER PUBLICATION name SET pub_obj_list
   10995             :                 {
   10996         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10997             : 
   10998         464 :                     n->pubname = $3;
   10999         464 :                     n->pubobjects = $5;
   11000         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   11001         464 :                     n->action = AP_SetObjects;
   11002         464 :                     $$ = (Node *) n;
   11003             :                 }
   11004             :             | ALTER PUBLICATION name DROP pub_obj_list
   11005             :                 {
   11006         156 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   11007             : 
   11008         156 :                     n->pubname = $3;
   11009         156 :                     n->pubobjects = $5;
   11010         156 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   11011         156 :                     n->action = AP_DropObjects;
   11012         156 :                     $$ = (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         484 :                         makeNode(CreateSubscriptionStmt);
   11027         484 :                     n->subname = $3;
   11028         484 :                     n->conninfo = $5;
   11029         484 :                     n->publication = $7;
   11030         484 :                     n->options = $8;
   11031         484 :                     $$ = (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         218 :                         makeNode(AlterSubscriptionStmt);
   11046             : 
   11047         218 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   11048         218 :                     n->subname = $3;
   11049         218 :                     n->options = $5;
   11050         218 :                     $$ = (Node *) n;
   11051             :                 }
   11052             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   11053             :                 {
   11054             :                     AlterSubscriptionStmt *n =
   11055          26 :                         makeNode(AlterSubscriptionStmt);
   11056             : 
   11057          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   11058          26 :                     n->subname = $3;
   11059          26 :                     n->conninfo = $5;
   11060          26 :                     $$ = (Node *) n;
   11061             :                 }
   11062             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   11063             :                 {
   11064             :                     AlterSubscriptionStmt *n =
   11065          68 :                         makeNode(AlterSubscriptionStmt);
   11066             : 
   11067          68 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
   11068          68 :                     n->subname = $3;
   11069          68 :                     n->options = $6;
   11070          68 :                     $$ = (Node *) n;
   11071             :                 }
   11072             :             | ALTER SUBSCRIPTION name REFRESH SEQUENCES
   11073             :                 {
   11074             :                     AlterSubscriptionStmt *n =
   11075           2 :                         makeNode(AlterSubscriptionStmt);
   11076             : 
   11077           2 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
   11078           2 :                     n->subname = $3;
   11079           2 :                     $$ = (Node *) n;
   11080             :                 }
   11081             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   11082             :                 {
   11083             :                     AlterSubscriptionStmt *n =
   11084          28 :                         makeNode(AlterSubscriptionStmt);
   11085             : 
   11086          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   11087          28 :                     n->subname = $3;
   11088          28 :                     n->publication = $6;
   11089          28 :                     n->options = $7;
   11090          28 :                     $$ = (Node *) n;
   11091             :                 }
   11092             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   11093             :                 {
   11094             :                     AlterSubscriptionStmt *n =
   11095          26 :                         makeNode(AlterSubscriptionStmt);
   11096             : 
   11097          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   11098          26 :                     n->subname = $3;
   11099          26 :                     n->publication = $6;
   11100          26 :                     n->options = $7;
   11101          26 :                     $$ = (Node *) n;
   11102             :                 }
   11103             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   11104             :                 {
   11105             :                     AlterSubscriptionStmt *n =
   11106          44 :                         makeNode(AlterSubscriptionStmt);
   11107             : 
   11108          44 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   11109          44 :                     n->subname = $3;
   11110          44 :                     n->publication = $6;
   11111          44 :                     n->options = $7;
   11112          44 :                     $$ = (Node *) n;
   11113             :                 }
   11114             :             | ALTER SUBSCRIPTION name ENABLE_P
   11115             :                 {
   11116             :                     AlterSubscriptionStmt *n =
   11117          62 :                         makeNode(AlterSubscriptionStmt);
   11118             : 
   11119          62 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11120          62 :                     n->subname = $3;
   11121          62 :                     n->options = list_make1(makeDefElem("enabled",
   11122             :                                             (Node *) makeBoolean(true), @1));
   11123          62 :                     $$ = (Node *) n;
   11124             :                 }
   11125             :             | ALTER SUBSCRIPTION name DISABLE_P
   11126             :                 {
   11127             :                     AlterSubscriptionStmt *n =
   11128          44 :                         makeNode(AlterSubscriptionStmt);
   11129             : 
   11130          44 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11131          44 :                     n->subname = $3;
   11132          44 :                     n->options = list_make1(makeDefElem("enabled",
   11133             :                                             (Node *) makeBoolean(false), @1));
   11134          44 :                     $$ = (Node *) n;
   11135             :                 }
   11136             :             | ALTER SUBSCRIPTION name SKIP definition
   11137             :                 {
   11138             :                     AlterSubscriptionStmt *n =
   11139          24 :                         makeNode(AlterSubscriptionStmt);
   11140             : 
   11141          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   11142          24 :                     n->subname = $3;
   11143          24 :                     n->options = $5;
   11144          24 :                     $$ = (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         242 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11157             : 
   11158         242 :                     n->subname = $3;
   11159         242 :                     n->missing_ok = false;
   11160         242 :                     n->behavior = $4;
   11161         242 :                     $$ = (Node *) n;
   11162             :                 }
   11163             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   11164             :                 {
   11165           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11166             : 
   11167           6 :                     n->subname = $5;
   11168           6 :                     n->missing_ok = true;
   11169           6 :                     n->behavior = $6;
   11170           6 :                     $$ = (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        1102 :                     RuleStmt   *n = makeNode(RuleStmt);
   11185             : 
   11186        1102 :                     n->replace = $2;
   11187        1102 :                     n->relation = $9;
   11188        1102 :                     n->rulename = $4;
   11189        1102 :                     n->whereClause = $10;
   11190        1102 :                     n->event = $7;
   11191        1102 :                     n->instead = $12;
   11192        1102 :                     n->actions = $13;
   11193        1102 :                     $$ = (Node *) n;
   11194             :                 }
   11195             :         ;
   11196             : 
   11197             : RuleActionList:
   11198         164 :             NOTHING                                 { $$ = NIL; }
   11199         892 :             | RuleActionStmt                        { $$ = list_make1($1); }
   11200          46 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   11201             :         ;
   11202             : 
   11203             : /* the thrashing around here is to discard "empty" statements... */
   11204             : RuleActionMulti:
   11205             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   11206          62 :                 { if ($3 != NULL)
   11207          46 :                     $$ = lappend($1, $3);
   11208             :                   else
   11209          16 :                     $$ = $1;
   11210             :                 }
   11211             :             | RuleActionStmtOrEmpty
   11212          46 :                 { if ($1 != NULL)
   11213          46 :                     $$ = 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          92 :             RuleActionStmt                          { $$ = $1; }
   11229          16 :             |   /*EMPTY*/                           { $$ = NULL; }
   11230             :         ;
   11231             : 
   11232          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11233         436 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11234         164 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11235         484 :             | INSERT                                { $$ = CMD_INSERT; }
   11236             :          ;
   11237             : 
   11238             : opt_instead:
   11239         760 :             INSTEAD                                 { $$ = true; }
   11240         156 :             | ALSO                                  { $$ = false; }
   11241         186 :             | /*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         148 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11256             : 
   11257         148 :                     n->conditionname = $2;
   11258         148 :                     n->payload = $3;
   11259         148 :                     $$ = (Node *) n;
   11260             :                 }
   11261             :         ;
   11262             : 
   11263             : notify_payload:
   11264          82 :             ',' Sconst                          { $$ = $2; }
   11265          66 :             | /*EMPTY*/                         { $$ = NULL; }
   11266             :         ;
   11267             : 
   11268             : ListenStmt: LISTEN ColId
   11269             :                 {
   11270          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11271             : 
   11272          74 :                     n->conditionname = $2;
   11273          74 :                     $$ = (Node *) n;
   11274             :                 }
   11275             :         ;
   11276             : 
   11277             : UnlistenStmt:
   11278             :             UNLISTEN ColId
   11279             :                 {
   11280           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11281             : 
   11282           6 :                     n->conditionname = $2;
   11283           6 :                     $$ = (Node *) n;
   11284             :                 }
   11285             :             | UNLISTEN '*'
   11286             :                 {
   11287          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11288             : 
   11289          32 :                     n->conditionname = NULL;
   11290          32 :                     $$ = (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         782 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11308             : 
   11309         782 :                     n->kind = TRANS_STMT_ROLLBACK;
   11310         782 :                     n->options = NIL;
   11311         782 :                     n->chain = $3;
   11312         782 :                     n->location = -1;
   11313         782 :                     $$ = (Node *) n;
   11314             :                 }
   11315             :             | START TRANSACTION transaction_mode_list_or_empty
   11316             :                 {
   11317        1646 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11318             : 
   11319        1646 :                     n->kind = TRANS_STMT_START;
   11320        1646 :                     n->options = $3;
   11321        1646 :                     n->location = -1;
   11322        1646 :                     $$ = (Node *) n;
   11323             :                 }
   11324             :             | COMMIT opt_transaction opt_transaction_chain
   11325             :                 {
   11326       17672 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11327             : 
   11328       17672 :                     n->kind = TRANS_STMT_COMMIT;
   11329       17672 :                     n->options = NIL;
   11330       17672 :                     n->chain = $3;
   11331       17672 :                     n->location = -1;
   11332       17672 :                     $$ = (Node *) n;
   11333             :                 }
   11334             :             | ROLLBACK opt_transaction opt_transaction_chain
   11335             :                 {
   11336        2754 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11337             : 
   11338        2754 :                     n->kind = TRANS_STMT_ROLLBACK;
   11339        2754 :                     n->options = NIL;
   11340        2754 :                     n->chain = $3;
   11341        2754 :                     n->location = -1;
   11342        2754 :                     $$ = (Node *) n;
   11343             :                 }
   11344             :             | SAVEPOINT ColId
   11345             :                 {
   11346        1944 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11347             : 
   11348        1944 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11349        1944 :                     n->savepoint_name = $2;
   11350        1944 :                     n->location = @2;
   11351        1944 :                     $$ = (Node *) n;
   11352             :                 }
   11353             :             | RELEASE SAVEPOINT ColId
   11354             :                 {
   11355         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11356             : 
   11357         208 :                     n->kind = TRANS_STMT_RELEASE;
   11358         208 :                     n->savepoint_name = $3;
   11359         208 :                     n->location = @3;
   11360         208 :                     $$ = (Node *) n;
   11361             :                 }
   11362             :             | RELEASE ColId
   11363             :                 {
   11364          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11365             : 
   11366          86 :                     n->kind = TRANS_STMT_RELEASE;
   11367          86 :                     n->savepoint_name = $2;
   11368          86 :                     n->location = @2;
   11369          86 :                     $$ = (Node *) n;
   11370             :                 }
   11371             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11372             :                 {
   11373         246 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11374             : 
   11375         246 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11376         246 :                     n->savepoint_name = $5;
   11377         246 :                     n->location = @5;
   11378         246 :                     $$ = (Node *) n;
   11379             :                 }
   11380             :             | ROLLBACK opt_transaction TO ColId
   11381             :                 {
   11382         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11383             : 
   11384         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11385         496 :                     n->savepoint_name = $4;
   11386         496 :                     n->location = @4;
   11387         496 :                     $$ = (Node *) n;
   11388             :                 }
   11389             :             | PREPARE TRANSACTION Sconst
   11390             :                 {
   11391         668 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11392             : 
   11393         668 :                     n->kind = TRANS_STMT_PREPARE;
   11394         668 :                     n->gid = $3;
   11395         668 :                     n->location = @3;
   11396         668 :                     $$ = (Node *) n;
   11397             :                 }
   11398             :             | COMMIT PREPARED Sconst
   11399             :                 {
   11400         506 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11401             : 
   11402         506 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11403         506 :                     n->gid = $3;
   11404         506 :                     n->location = @3;
   11405         506 :                     $$ = (Node *) n;
   11406             :                 }
   11407             :             | ROLLBACK PREPARED Sconst
   11408             :                 {
   11409          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11410             : 
   11411          86 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11412          86 :                     n->gid = $3;
   11413          86 :                     n->location = @3;
   11414          86 :                     $$ = (Node *) n;
   11415             :                 }
   11416             :         ;
   11417             : 
   11418             : TransactionStmtLegacy:
   11419             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11420             :                 {
   11421       21010 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11422             : 
   11423       21010 :                     n->kind = TRANS_STMT_BEGIN;
   11424       21010 :                     n->options = $3;
   11425       21010 :                     n->location = -1;
   11426       21010 :                     $$ = (Node *) n;
   11427             :                 }
   11428             :             | END_P opt_transaction opt_transaction_chain
   11429             :                 {
   11430         370 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11431             : 
   11432         370 :                     n->kind = TRANS_STMT_COMMIT;
   11433         370 :                     n->options = NIL;
   11434         370 :                     n->chain = $3;
   11435         370 :                     n->location = -1;
   11436         370 :                     $$ = (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        6968 :                     { $$ = makeDefElem("transaction_isolation",
   11448        6968 :                                        makeStringConst($3, @3), @1); }
   11449             :             | READ ONLY
   11450        1424 :                     { $$ = makeDefElem("transaction_read_only",
   11451        1424 :                                        makeIntConst(true, @1), @1); }
   11452             :             | READ WRITE
   11453          90 :                     { $$ = makeDefElem("transaction_read_only",
   11454          90 :                                        makeIntConst(false, @1), @1); }
   11455             :             | DEFERRABLE
   11456          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11457             :                                        makeIntConst(true, @1), @1); }
   11458             :             | NOT DEFERRABLE
   11459          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11460          10 :                                        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        7184 :                     { $$ = list_make1($1); }
   11467             :             | transaction_mode_list ',' transaction_mode_item
   11468         944 :                     { $$ = lappend($1, $3); }
   11469             :             | transaction_mode_list transaction_mode_item
   11470         408 :                     { $$ = lappend($1, $2); }
   11471             :         ;
   11472             : 
   11473             : transaction_mode_list_or_empty:
   11474             :             transaction_mode_list
   11475             :             | /* EMPTY */
   11476       16076 :                     { $$ = NIL; }
   11477             :         ;
   11478             : 
   11479             : opt_transaction_chain:
   11480         120 :             AND CHAIN       { $$ = true; }
   11481           2 :             | AND NO CHAIN  { $$ = false; }
   11482       21456 :             | /* 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       17124 :                     ViewStmt   *n = makeNode(ViewStmt);
   11498             : 
   11499       17124 :                     n->view = $4;
   11500       17124 :                     n->view->relpersistence = $2;
   11501       17124 :                     n->aliases = $5;
   11502       17124 :                     n->query = $8;
   11503       17124 :                     n->replace = false;
   11504       17124 :                     n->options = $6;
   11505       17124 :                     n->withCheckOption = $9;
   11506       17124 :                     $$ = (Node *) n;
   11507             :                 }
   11508             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11509             :                 AS SelectStmt opt_check_option
   11510             :                 {
   11511         244 :                     ViewStmt   *n = makeNode(ViewStmt);
   11512             : 
   11513         244 :                     n->view = $6;
   11514         244 :                     n->view->relpersistence = $4;
   11515         244 :                     n->aliases = $7;
   11516         244 :                     n->query = $10;
   11517         244 :                     n->replace = true;
   11518         244 :                     n->options = $8;
   11519         244 :                     n->withCheckOption = $11;
   11520         244 :                     $$ = (Node *) n;
   11521             :                 }
   11522             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11523             :                 AS SelectStmt opt_check_option
   11524             :                 {
   11525           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11526             : 
   11527           8 :                     n->view = $5;
   11528           8 :                     n->view->relpersistence = $2;
   11529           8 :                     n->aliases = $7;
   11530           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11531           8 :                     n->replace = false;
   11532           8 :                     n->options = $9;
   11533           8 :                     n->withCheckOption = $12;
   11534           8 :                     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           8 :                     $$ = (Node *) n;
   11540             :                 }
   11541             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11542             :                 AS SelectStmt opt_check_option
   11543             :                 {
   11544           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11545             : 
   11546           6 :                     n->view = $7;
   11547           6 :                     n->view->relpersistence = $4;
   11548           6 :                     n->aliases = $9;
   11549           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11550           6 :                     n->replace = true;
   11551           6 :                     n->options = $11;
   11552           6 :                     n->withCheckOption = $14;
   11553           6 :                     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           6 :                     $$ = (Node *) n;
   11559             :                 }
   11560             :         ;
   11561             : 
   11562             : opt_check_option:
   11563          96 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11564           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11565          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11566       17256 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11567             :         ;
   11568             : 
   11569             : /*****************************************************************************
   11570             :  *
   11571             :  *      QUERY:
   11572             :  *              LOAD "filename"
   11573             :  *
   11574             :  *****************************************************************************/
   11575             : 
   11576             : LoadStmt:   LOAD file_name
   11577             :                 {
   11578          64 :                     LoadStmt   *n = makeNode(LoadStmt);
   11579             : 
   11580          64 :                     n->filename = $2;
   11581          64 :                     $$ = (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         818 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11596             : 
   11597         818 :                     n->dbname = $3;
   11598         818 :                     n->options = $5;
   11599         818 :                     $$ = (Node *) n;
   11600             :                 }
   11601             :         ;
   11602             : 
   11603             : createdb_opt_list:
   11604         676 :             createdb_opt_items                      { $$ = $1; }
   11605         210 :             | /* EMPTY */                           { $$ = NIL; }
   11606             :         ;
   11607             : 
   11608             : createdb_opt_items:
   11609         676 :             createdb_opt_item                       { $$ = list_make1($1); }
   11610        1016 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11611             :         ;
   11612             : 
   11613             : createdb_opt_item:
   11614             :             createdb_opt_name opt_equal NumericOnly
   11615             :                 {
   11616         274 :                     $$ = makeDefElem($1, $3, @1);
   11617             :                 }
   11618             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11619             :                 {
   11620        1418 :                     $$ = 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        1180 :             IDENT                           { $$ = $1; }
   11641           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11642         106 :             | ENCODING                      { $$ = pstrdup($1); }
   11643           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11644           2 :             | OWNER                         { $$ = pstrdup($1); }
   11645          34 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11646         368 :             | 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           2 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11668             : 
   11669           2 :                     n->dbname = $3;
   11670           2 :                     n->options = $5;
   11671           2 :                     $$ = (Node *) n;
   11672             :                  }
   11673             :             | ALTER DATABASE name createdb_opt_list
   11674             :                  {
   11675          66 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11676             : 
   11677          66 :                     n->dbname = $3;
   11678          66 :                     n->options = $4;
   11679          66 :                     $$ = (Node *) n;
   11680             :                  }
   11681             :             | ALTER DATABASE name SET TABLESPACE name
   11682             :                  {
   11683          24 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11684             : 
   11685          24 :                     n->dbname = $3;
   11686          24 :                     n->options = list_make1(makeDefElem("tablespace",
   11687             :                                                         (Node *) makeString($6), @6));
   11688          24 :                     $$ = (Node *) n;
   11689             :                  }
   11690             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11691             :                  {
   11692           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11693             : 
   11694           6 :                     n->dbname = $3;
   11695           6 :                     $$ = (Node *) n;
   11696             :                  }
   11697             :         ;
   11698             : 
   11699             : AlterDatabaseSetStmt:
   11700             :             ALTER DATABASE name SetResetClause
   11701             :                 {
   11702        1254 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11703             : 
   11704        1254 :                     n->dbname = $3;
   11705        1254 :                     n->setstmt = $4;
   11706        1254 :                     $$ = (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          98 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11721             : 
   11722          98 :                     n->dbname = $3;
   11723          98 :                     n->missing_ok = false;
   11724          98 :                     n->options = NULL;
   11725          98 :                     $$ = (Node *) n;
   11726             :                 }
   11727             :             | DROP DATABASE IF_P EXISTS name
   11728             :                 {
   11729           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11730             : 
   11731           4 :                     n->dbname = $5;
   11732           4 :                     n->missing_ok = true;
   11733           4 :                     n->options = NULL;
   11734           4 :                     $$ = (Node *) n;
   11735             :                 }
   11736             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11737             :                 {
   11738          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11739             : 
   11740          14 :                     n->dbname = $3;
   11741          14 :                     n->missing_ok = false;
   11742          14 :                     n->options = $6;
   11743          14 :                     $$ = (Node *) n;
   11744             :                 }
   11745             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11746             :                 {
   11747          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11748             : 
   11749          12 :                     n->dbname = $5;
   11750          12 :                     n->missing_ok = true;
   11751          12 :                     n->options = $8;
   11752          12 :                     $$ = (Node *) n;
   11753             :                 }
   11754             :         ;
   11755             : 
   11756             : drop_option_list:
   11757             :             drop_option
   11758             :                 {
   11759          26 :                     $$ = 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          26 :                     $$ = 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           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11787             : 
   11788           6 :                     n->collname = $3;
   11789           6 :                     $$ = (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         148 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11805             : 
   11806         148 :                     n->setstmt = $4;
   11807         148 :                     $$ = (Node *) n;
   11808             :                 }
   11809             :             | ALTER SYSTEM_P RESET generic_reset
   11810             :                 {
   11811          58 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11812             : 
   11813          58 :                     n->setstmt = $4;
   11814          58 :                     $$ = (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        1474 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11829             : 
   11830        1474 :                     n->domainname = $3;
   11831        1474 :                     n->typeName = $5;
   11832        1474 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11833             :                                      yyscanner);
   11834        1474 :                     $$ = (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          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11843             : 
   11844          14 :                     n->subtype = AD_AlterDefault;
   11845          14 :                     n->typeName = $3;
   11846          14 :                     n->def = $4;
   11847          14 :                     $$ = (Node *) n;
   11848             :                 }
   11849             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11850             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11851             :                 {
   11852          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11853             : 
   11854          12 :                     n->subtype = AD_DropNotNull;
   11855          12 :                     n->typeName = $3;
   11856          12 :                     $$ = (Node *) n;
   11857             :                 }
   11858             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11859             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11860             :                 {
   11861          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11862             : 
   11863          24 :                     n->subtype = AD_SetNotNull;
   11864          24 :                     n->typeName = $3;
   11865          24 :                     $$ = (Node *) n;
   11866             :                 }
   11867             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11868             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11869             :                 {
   11870         182 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11871             : 
   11872         182 :                     n->subtype = AD_AddConstraint;
   11873         182 :                     n->typeName = $3;
   11874         182 :                     n->def = $5;
   11875         182 :                     $$ = (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          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11881             : 
   11882          54 :                     n->subtype = AD_DropConstraint;
   11883          54 :                     n->typeName = $3;
   11884          54 :                     n->name = $6;
   11885          54 :                     n->behavior = $7;
   11886          54 :                     n->missing_ok = false;
   11887          54 :                     $$ = (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           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11893             : 
   11894           6 :                     n->subtype = AD_DropConstraint;
   11895           6 :                     n->typeName = $3;
   11896           6 :                     n->name = $8;
   11897           6 :                     n->behavior = $9;
   11898           6 :                     n->missing_ok = true;
   11899           6 :                     $$ = (Node *) n;
   11900             :                 }
   11901             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11902             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11903             :                 {
   11904          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11905             : 
   11906          12 :                     n->subtype = AD_ValidateConstraint;
   11907          12 :                     n->typeName = $3;
   11908          12 :                     n->name = $6;
   11909          12 :                     $$ = (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          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11928             : 
   11929          40 :                     n->dictname = $5;
   11930          40 :                     n->options = $6;
   11931          40 :                     $$ = (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        9280 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11939             : 
   11940        9280 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11941        9280 :                     n->cfgname = $5;
   11942        9280 :                     n->tokentype = $9;
   11943        9280 :                     n->dicts = $11;
   11944        9280 :                     n->override = false;
   11945        9280 :                     n->replace = false;
   11946        9280 :                     $$ = (Node *) n;
   11947             :                 }
   11948             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11949             :                 {
   11950          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11951             : 
   11952          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11953          26 :                     n->cfgname = $5;
   11954          26 :                     n->tokentype = $9;
   11955          26 :                     n->dicts = $11;
   11956          26 :                     n->override = true;
   11957          26 :                     n->replace = false;
   11958          26 :                     $$ = (Node *) n;
   11959             :                 }
   11960             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11961             :                 {
   11962          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11963             : 
   11964          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11965          18 :                     n->cfgname = $5;
   11966          18 :                     n->tokentype = NIL;
   11967          18 :                     n->dicts = list_make2($9,$11);
   11968          18 :                     n->override = false;
   11969          18 :                     n->replace = true;
   11970          18 :                     $$ = (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          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11987             : 
   11988          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11989          18 :                     n->cfgname = $5;
   11990          18 :                     n->tokentype = $9;
   11991          18 :                     n->missing_ok = false;
   11992          18 :                     $$ = (Node *) n;
   11993             :                 }
   11994             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11995             :                 {
   11996          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11997             : 
   11998          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11999          12 :                     n->cfgname = $5;
   12000          12 :                     n->tokentype = $11;
   12001          12 :                     n->missing_ok = true;
   12002          12 :                     $$ = (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          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   12026             : 
   12027          64 :                 n->conversion_name = $4;
   12028          64 :                 n->for_encoding_name = $6;
   12029          64 :                 n->to_encoding_name = $8;
   12030          64 :                 n->func_name = $10;
   12031          64 :                 n->def = $2;
   12032          64 :                 $$ = (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          16 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12058             : 
   12059          16 :                     n->relation = NULL;
   12060          16 :                     n->indexname = NULL;
   12061          16 :                     n->params = $2;
   12062          16 :                     $$ = (Node *) n;
   12063             :                 }
   12064             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   12065             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   12066             :                 {
   12067         190 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12068             : 
   12069         190 :                     n->relation = $3;
   12070         190 :                     n->indexname = $4;
   12071         190 :                     if ($2)
   12072           0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12073         190 :                     $$ = (Node *) n;
   12074             :                 }
   12075             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   12076             :             | CLUSTER VERBOSE
   12077             :                 {
   12078           8 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12079             : 
   12080           8 :                     n->relation = NULL;
   12081           8 :                     n->indexname = NULL;
   12082           8 :                     n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12083           8 :                     $$ = (Node *) n;
   12084             :                 }
   12085             :             /* kept for pre-8.3 compatibility */
   12086             :             | CLUSTER opt_verbose name ON qualified_name
   12087             :                 {
   12088          20 :                     ClusterStmt *n = makeNode(ClusterStmt);
   12089             : 
   12090          20 :                     n->relation = $5;
   12091          20 :                     n->indexname = $3;
   12092          20 :                     if ($2)
   12093           0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12094          20 :                     $$ = (Node *) n;
   12095             :                 }
   12096             :         ;
   12097             : 
   12098             : cluster_index_specification:
   12099         156 :             USING name              { $$ = $2; }
   12100          34 :             | /*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        1256 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12115             : 
   12116        1256 :                     n->options = NIL;
   12117        1256 :                     if ($2)
   12118         152 :                         n->options = lappend(n->options,
   12119         152 :                                              makeDefElem("full", NULL, @2));
   12120        1256 :                     if ($3)
   12121         164 :                         n->options = lappend(n->options,
   12122         164 :                                              makeDefElem("freeze", NULL, @3));
   12123        1256 :                     if ($4)
   12124          16 :                         n->options = lappend(n->options,
   12125          16 :                                              makeDefElem("verbose", NULL, @4));
   12126        1256 :                     if ($5)
   12127         304 :                         n->options = lappend(n->options,
   12128         304 :                                              makeDefElem("analyze", NULL, @5));
   12129        1256 :                     n->rels = $6;
   12130        1256 :                     n->is_vacuumcmd = true;
   12131        1256 :                     $$ = (Node *) n;
   12132             :                 }
   12133             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   12134             :                 {
   12135        8446 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12136             : 
   12137        8446 :                     n->options = $3;
   12138        8446 :                     n->rels = $5;
   12139        8446 :                     n->is_vacuumcmd = true;
   12140        8446 :                     $$ = (Node *) n;
   12141             :                 }
   12142             :         ;
   12143             : 
   12144             : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
   12145             :                 {
   12146        4942 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12147             : 
   12148        4942 :                     n->options = $2;
   12149        4942 :                     n->rels = $3;
   12150        4942 :                     n->is_vacuumcmd = false;
   12151        4942 :                     $$ = (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         304 :             analyze_keyword                         { $$ = true; }
   12171         952 :             | /*EMPTY*/                             { $$ = false; }
   12172             :         ;
   12173             : 
   12174             : opt_verbose:
   12175          16 :             VERBOSE                                 { $$ = true; }
   12176        3766 :             | /*EMPTY*/                             { $$ = false; }
   12177             :         ;
   12178             : 
   12179         152 : opt_full:   FULL                                    { $$ = true; }
   12180        1104 :             | /*EMPTY*/                             { $$ = false; }
   12181             :         ;
   12182             : 
   12183         164 : opt_freeze: FREEZE                                  { $$ = true; }
   12184        1092 :             | /*EMPTY*/                             { $$ = false; }
   12185             :         ;
   12186             : 
   12187             : opt_name_list:
   12188        2946 :             '(' name_list ')'                       { $$ = $2; }
   12189       17136 :             | /*EMPTY*/                             { $$ = NIL; }
   12190             :         ;
   12191             : 
   12192             : vacuum_relation:
   12193             :             relation_expr opt_name_list
   12194             :                 {
   12195       14468 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12196             :                 }
   12197             :         ;
   12198             : 
   12199             : vacuum_relation_list:
   12200             :             vacuum_relation
   12201       14274 :                     { $$ = list_make1($1); }
   12202             :             | vacuum_relation_list ',' vacuum_relation
   12203         194 :                     { $$ = lappend($1, $3); }
   12204             :         ;
   12205             : 
   12206             : opt_vacuum_relation_list:
   12207       14274 :             vacuum_relation_list                    { $$ = $1; }
   12208         370 :             | /*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        7786 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12224             : 
   12225        7786 :                     n->query = $2;
   12226        7786 :                     n->options = NIL;
   12227        7786 :                     $$ = (Node *) n;
   12228             :                 }
   12229             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12230             :                 {
   12231        2316 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12232             : 
   12233        2316 :                     n->query = $4;
   12234        2316 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12235        2316 :                     if ($3)
   12236           0 :                         n->options = lappend(n->options,
   12237           0 :                                              makeDefElem("verbose", NULL, @3));
   12238        2316 :                     $$ = (Node *) n;
   12239             :                 }
   12240             :         | EXPLAIN VERBOSE ExplainableStmt
   12241             :                 {
   12242          12 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12243             : 
   12244          12 :                     n->query = $3;
   12245          12 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12246          12 :                     $$ = (Node *) n;
   12247             :                 }
   12248             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12249             :                 {
   12250       14716 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12251             : 
   12252       14716 :                     n->query = $5;
   12253       14716 :                     n->options = $3;
   12254       14716 :                     $$ = (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        1946 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12281             : 
   12282        1946 :                     n->name = $2;
   12283        1946 :                     n->argtypes = $3;
   12284        1946 :                     n->query = $5;
   12285        1946 :                     $$ = (Node *) n;
   12286             :                 }
   12287             :         ;
   12288             : 
   12289        1624 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12290         340 :                 | /* 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       16294 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12311             : 
   12312       16294 :                     n->name = $2;
   12313       16294 :                     n->params = $3;
   12314       16294 :                     $$ = (Node *) n;
   12315             :                 }
   12316             :             | CREATE OptTemp TABLE create_as_target AS
   12317             :                 EXECUTE name execute_param_clause opt_with_data
   12318             :                 {
   12319          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12320          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12321             : 
   12322          76 :                     n->name = $7;
   12323          76 :                     n->params = $8;
   12324          76 :                     ctas->query = (Node *) n;
   12325          76 :                     ctas->into = $4;
   12326          76 :                     ctas->objtype = OBJECT_TABLE;
   12327          76 :                     ctas->is_select_into = false;
   12328          76 :                     ctas->if_not_exists = false;
   12329             :                     /* cram additional flags into the IntoClause */
   12330          76 :                     $4->rel->relpersistence = $2;
   12331          76 :                     $4->skipData = !($9);
   12332          76 :                     $$ = (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          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12338          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12339             : 
   12340          12 :                     n->name = $10;
   12341          12 :                     n->params = $11;
   12342          12 :                     ctas->query = (Node *) n;
   12343          12 :                     ctas->into = $7;
   12344          12 :                     ctas->objtype = OBJECT_TABLE;
   12345          12 :                     ctas->is_select_into = false;
   12346          12 :                     ctas->if_not_exists = true;
   12347             :                     /* cram additional flags into the IntoClause */
   12348          12 :                     $7->rel->relpersistence = $2;
   12349          12 :                     $7->skipData = !($12);
   12350          12 :                     $$ = (Node *) ctas;
   12351             :                 }
   12352             :         ;
   12353             : 
   12354       15220 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12355        1162 :                     | /* EMPTY */                   { $$ = NIL; }
   12356             :                     ;
   12357             : 
   12358             : /*****************************************************************************
   12359             :  *
   12360             :  *      QUERY:
   12361             :  *              DEALLOCATE [PREPARE] <plan_name>
   12362             :  *
   12363             :  *****************************************************************************/
   12364             : 
   12365             : DeallocateStmt: DEALLOCATE name
   12366             :                     {
   12367        4010 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12368             : 
   12369        4010 :                         n->name = $2;
   12370        4010 :                         n->isall = false;
   12371        4010 :                         n->location = @2;
   12372        4010 :                         $$ = (Node *) n;
   12373             :                     }
   12374             :                 | DEALLOCATE PREPARE name
   12375             :                     {
   12376          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12377             : 
   12378          20 :                         n->name = $3;
   12379          20 :                         n->isall = false;
   12380          20 :                         n->location = @3;
   12381          20 :                         $$ = (Node *) n;
   12382             :                     }
   12383             :                 | DEALLOCATE ALL
   12384             :                     {
   12385          70 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12386             : 
   12387          70 :                         n->name = NULL;
   12388          70 :                         n->isall = true;
   12389          70 :                         n->location = -1;
   12390          70 :                         $$ = (Node *) n;
   12391             :                     }
   12392             :                 | DEALLOCATE PREPARE ALL
   12393             :                     {
   12394           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12395             : 
   12396           2 :                         n->name = NULL;
   12397           2 :                         n->isall = true;
   12398           2 :                         n->location = -1;
   12399           2 :                         $$ = (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       70182 :                     $5->relation = $4;
   12415       70182 :                     $5->onConflictClause = $6;
   12416       70182 :                     $5->returningClause = $7;
   12417       70182 :                     $5->withClause = $1;
   12418       70182 :                     $$ = (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       70056 :                     $$ = $1;
   12432             :                 }
   12433             :             | qualified_name AS ColId
   12434             :                 {
   12435         132 :                     $1->alias = makeAlias($3, NIL);
   12436         132 :                     $$ = $1;
   12437             :                 }
   12438             :         ;
   12439             : 
   12440             : insert_rest:
   12441             :             SelectStmt
   12442             :                 {
   12443       44720 :                     $$ = makeNode(InsertStmt);
   12444       44720 :                     $$->cols = NIL;
   12445       44720 :                     $$->selectStmt = $1;
   12446             :                 }
   12447             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12448             :                 {
   12449          96 :                     $$ = makeNode(InsertStmt);
   12450          96 :                     $$->cols = NIL;
   12451          96 :                     $$->override = $2;
   12452          96 :                     $$->selectStmt = $4;
   12453             :                 }
   12454             :             | '(' insert_column_list ')' SelectStmt
   12455             :                 {
   12456       14540 :                     $$ = makeNode(InsertStmt);
   12457       14540 :                     $$->cols = $2;
   12458       14540 :                     $$->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       10832 :                     $$ = makeNode(InsertStmt);
   12470       10832 :                     $$->cols = NIL;
   12471       10832 :                     $$->selectStmt = NULL;
   12472             :                 }
   12473             :         ;
   12474             : 
   12475             : override_kind:
   12476          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12477          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12478             :         ;
   12479             : 
   12480             : insert_column_list:
   12481             :             insert_column_item
   12482       14874 :                     { $$ = list_make1($1); }
   12483             :             | insert_column_list ',' insert_column_item
   12484       16480 :                     { $$ = lappend($1, $3); }
   12485             :         ;
   12486             : 
   12487             : insert_column_item:
   12488             :             ColId opt_indirection
   12489             :                 {
   12490       31354 :                     $$ = makeNode(ResTarget);
   12491       31354 :                     $$->name = $1;
   12492       31354 :                     $$->indirection = check_indirection($2, yyscanner);
   12493       31354 :                     $$->val = NULL;
   12494       31354 :                     $$->location = @1;
   12495             :                 }
   12496             :         ;
   12497             : 
   12498             : opt_on_conflict:
   12499             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12500             :                 {
   12501        1380 :                     $$ = makeNode(OnConflictClause);
   12502        1380 :                     $$->action = ONCONFLICT_UPDATE;
   12503        1380 :                     $$->infer = $3;
   12504        1380 :                     $$->targetList = $7;
   12505        1380 :                     $$->whereClause = $8;
   12506        1380 :                     $$->location = @1;
   12507             :                 }
   12508             :             |
   12509             :             ON CONFLICT opt_conf_expr DO NOTHING
   12510             :                 {
   12511         604 :                     $$ = makeNode(OnConflictClause);
   12512         604 :                     $$->action = ONCONFLICT_NOTHING;
   12513         604 :                     $$->infer = $3;
   12514         604 :                     $$->targetList = NIL;
   12515         604 :                     $$->whereClause = NULL;
   12516         604 :                     $$->location = @1;
   12517             :                 }
   12518             :             | /*EMPTY*/
   12519             :                 {
   12520       68204 :                     $$ = NULL;
   12521             :                 }
   12522             :         ;
   12523             : 
   12524             : opt_conf_expr:
   12525             :             '(' index_params ')' where_clause
   12526             :                 {
   12527        1528 :                     $$ = makeNode(InferClause);
   12528        1528 :                     $$->indexElems = $2;
   12529        1528 :                     $$->whereClause = $4;
   12530        1528 :                     $$->conname = NULL;
   12531        1528 :                     $$->location = @1;
   12532             :                 }
   12533             :             |
   12534             :             ON CONSTRAINT name
   12535             :                 {
   12536         204 :                     $$ = makeNode(InferClause);
   12537         204 :                     $$->indexElems = NIL;
   12538         204 :                     $$->whereClause = NULL;
   12539         204 :                     $$->conname = $3;
   12540         204 :                     $$->location = @1;
   12541             :                 }
   12542             :             | /*EMPTY*/
   12543             :                 {
   12544         252 :                     $$ = NULL;
   12545             :                 }
   12546             :         ;
   12547             : 
   12548             : returning_clause:
   12549             :             RETURNING returning_with_clause target_list
   12550             :                 {
   12551        3296 :                     ReturningClause *n = makeNode(ReturningClause);
   12552             : 
   12553        3296 :                     n->options = $2;
   12554        3296 :                     n->exprs = $3;
   12555        3296 :                     $$ = n;
   12556             :                 }
   12557             :             | /* EMPTY */
   12558             :                 {
   12559       88718 :                     $$ = NULL;
   12560             :                 }
   12561             :         ;
   12562             : 
   12563             : returning_with_clause:
   12564          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12565        3224 :             | /* EMPTY */                       { $$ = NIL; }
   12566             :         ;
   12567             : 
   12568             : returning_options:
   12569          72 :             returning_option                            { $$ = list_make1($1); }
   12570          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12571             :         ;
   12572             : 
   12573             : returning_option:
   12574             :             returning_option_kind AS ColId
   12575             :                 {
   12576         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12577             : 
   12578         126 :                     n->option = $1;
   12579         126 :                     n->value = $3;
   12580         126 :                     n->location = @1;
   12581         126 :                     $$ = (Node *) n;
   12582             :                 }
   12583             :         ;
   12584             : 
   12585             : returning_option_kind:
   12586          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12587          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12588             :         ;
   12589             : 
   12590             : 
   12591             : /*****************************************************************************
   12592             :  *
   12593             :  *      QUERY:
   12594             :  *              DELETE STATEMENTS
   12595             :  *
   12596             :  *****************************************************************************/
   12597             : 
   12598             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12599             :             using_clause where_or_current_clause returning_clause
   12600             :                 {
   12601        4708 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12602             : 
   12603        4708 :                     n->relation = $4;
   12604        4708 :                     n->usingClause = $5;
   12605        4708 :                     n->whereClause = $6;
   12606        4708 :                     n->returningClause = $7;
   12607        4708 :                     n->withClause = $1;
   12608        4708 :                     $$ = (Node *) n;
   12609             :                 }
   12610             :         ;
   12611             : 
   12612             : using_clause:
   12613         108 :                 USING from_list                     { $$ = $2; }
   12614        4600 :             | /*EMPTY*/                             { $$ = NIL; }
   12615             :         ;
   12616             : 
   12617             : 
   12618             : /*****************************************************************************
   12619             :  *
   12620             :  *      QUERY:
   12621             :  *              LOCK TABLE
   12622             :  *
   12623             :  *****************************************************************************/
   12624             : 
   12625             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12626             :                 {
   12627        1048 :                     LockStmt   *n = makeNode(LockStmt);
   12628             : 
   12629        1048 :                     n->relations = $3;
   12630        1048 :                     n->mode = $4;
   12631        1048 :                     n->nowait = $5;
   12632        1048 :                     $$ = (Node *) n;
   12633             :                 }
   12634             :         ;
   12635             : 
   12636         940 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12637         108 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12638             :         ;
   12639             : 
   12640         450 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12641          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12642          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12643          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12644          80 :             | SHARE                         { $$ = ShareLock; }
   12645          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12646         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12647         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12648             :         ;
   12649             : 
   12650         186 : opt_nowait: NOWAIT                          { $$ = true; }
   12651         892 :             | /*EMPTY*/                     { $$ = false; }
   12652             :         ;
   12653             : 
   12654             : opt_nowait_or_skip:
   12655          50 :             NOWAIT                          { $$ = LockWaitError; }
   12656         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12657       10774 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12658             :         ;
   12659             : 
   12660             : 
   12661             : /*****************************************************************************
   12662             :  *
   12663             :  *      QUERY:
   12664             :  *              UpdateStmt (UPDATE)
   12665             :  *
   12666             :  *****************************************************************************/
   12667             : 
   12668             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12669             :             SET set_clause_list
   12670             :             from_clause
   12671             :             where_or_current_clause
   12672             :             returning_clause
   12673             :                 {
   12674       14952 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12675             : 
   12676       14952 :                     n->relation = $3;
   12677       14952 :                     n->targetList = $5;
   12678       14952 :                     n->fromClause = $6;
   12679       14952 :                     n->whereClause = $7;
   12680       14952 :                     n->returningClause = $8;
   12681       14952 :                     n->withClause = $1;
   12682       14952 :                     $$ = (Node *) n;
   12683             :                 }
   12684             :         ;
   12685             : 
   12686             : set_clause_list:
   12687       17960 :             set_clause                          { $$ = $1; }
   12688        4374 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12689             :         ;
   12690             : 
   12691             : set_clause:
   12692             :             set_target '=' a_expr
   12693             :                 {
   12694       22150 :                     $1->val = (Node *) $3;
   12695       22150 :                     $$ = list_make1($1);
   12696             :                 }
   12697             :             | '(' set_target_list ')' '=' a_expr
   12698             :                 {
   12699         184 :                     int         ncolumns = list_length($2);
   12700         184 :                     int         i = 1;
   12701             :                     ListCell   *col_cell;
   12702             : 
   12703             :                     /* Create a MultiAssignRef source for each target */
   12704         568 :                     foreach(col_cell, $2)
   12705             :                     {
   12706         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12707         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12708             : 
   12709         384 :                         r->source = (Node *) $5;
   12710         384 :                         r->colno = i;
   12711         384 :                         r->ncolumns = ncolumns;
   12712         384 :                         res_col->val = (Node *) r;
   12713         384 :                         i++;
   12714             :                     }
   12715             : 
   12716         184 :                     $$ = $2;
   12717             :                 }
   12718             :         ;
   12719             : 
   12720             : set_target:
   12721             :             ColId opt_indirection
   12722             :                 {
   12723       22540 :                     $$ = makeNode(ResTarget);
   12724       22540 :                     $$->name = $1;
   12725       22540 :                     $$->indirection = check_indirection($2, yyscanner);
   12726       22540 :                     $$->val = NULL;  /* upper production sets this */
   12727       22540 :                     $$->location = @1;
   12728             :                 }
   12729             :         ;
   12730             : 
   12731             : set_target_list:
   12732         190 :             set_target                              { $$ = list_make1($1); }
   12733         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12734             :         ;
   12735             : 
   12736             : 
   12737             : /*****************************************************************************
   12738             :  *
   12739             :  *      QUERY:
   12740             :  *              MERGE
   12741             :  *
   12742             :  *****************************************************************************/
   12743             : 
   12744             : MergeStmt:
   12745             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12746             :             USING table_ref
   12747             :             ON a_expr
   12748             :             merge_when_list
   12749             :             returning_clause
   12750             :                 {
   12751        2172 :                     MergeStmt  *m = makeNode(MergeStmt);
   12752             : 
   12753        2172 :                     m->withClause = $1;
   12754        2172 :                     m->relation = $4;
   12755        2172 :                     m->sourceRelation = $6;
   12756        2172 :                     m->joinCondition = $8;
   12757        2172 :                     m->mergeWhenClauses = $9;
   12758        2172 :                     m->returningClause = $10;
   12759             : 
   12760        2172 :                     $$ = (Node *) m;
   12761             :                 }
   12762             :         ;
   12763             : 
   12764             : merge_when_list:
   12765        2172 :             merge_when_clause                       { $$ = list_make1($1); }
   12766        1218 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12767             :         ;
   12768             : 
   12769             : /*
   12770             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12771             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12772             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12773             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12774             :  */
   12775             : merge_when_clause:
   12776             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12777             :                 {
   12778        1628 :                     $4->matchKind = $1;
   12779        1628 :                     $4->condition = $2;
   12780             : 
   12781        1628 :                     $$ = (Node *) $4;
   12782             :                 }
   12783             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12784             :                 {
   12785         542 :                     $4->matchKind = $1;
   12786         542 :                     $4->condition = $2;
   12787             : 
   12788         542 :                     $$ = (Node *) $4;
   12789             :                 }
   12790             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12791             :                 {
   12792        1124 :                     $4->matchKind = $1;
   12793        1124 :                     $4->condition = $2;
   12794             : 
   12795        1124 :                     $$ = (Node *) $4;
   12796             :                 }
   12797             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12798             :                 {
   12799          70 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12800             : 
   12801          70 :                     m->matchKind = $1;
   12802          70 :                     m->commandType = CMD_NOTHING;
   12803          70 :                     m->condition = $2;
   12804             : 
   12805          70 :                     $$ = (Node *) m;
   12806             :                 }
   12807             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12808             :                 {
   12809          26 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12810             : 
   12811          26 :                     m->matchKind = $1;
   12812          26 :                     m->commandType = CMD_NOTHING;
   12813          26 :                     m->condition = $2;
   12814             : 
   12815          26 :                     $$ = (Node *) m;
   12816             :                 }
   12817             :         ;
   12818             : 
   12819             : merge_when_tgt_matched:
   12820        2072 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12821         186 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12822             :         ;
   12823             : 
   12824             : merge_when_tgt_not_matched:
   12825        1156 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12826          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12827             :         ;
   12828             : 
   12829             : opt_merge_when_condition:
   12830         850 :             AND a_expr              { $$ = $2; }
   12831        2582 :             |                       { $$ = NULL; }
   12832             :         ;
   12833             : 
   12834             : merge_update:
   12835             :             UPDATE SET set_clause_list
   12836             :                 {
   12837        1628 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12838        1628 :                     n->commandType = CMD_UPDATE;
   12839        1628 :                     n->override = OVERRIDING_NOT_SET;
   12840        1628 :                     n->targetList = $3;
   12841        1628 :                     n->values = NIL;
   12842             : 
   12843        1628 :                     $$ = n;
   12844             :                 }
   12845             :         ;
   12846             : 
   12847             : merge_delete:
   12848             :             DELETE_P
   12849             :                 {
   12850         542 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12851         542 :                     n->commandType = CMD_DELETE;
   12852         542 :                     n->override = OVERRIDING_NOT_SET;
   12853         542 :                     n->targetList = NIL;
   12854         542 :                     n->values = NIL;
   12855             : 
   12856         542 :                     $$ = n;
   12857             :                 }
   12858             :         ;
   12859             : 
   12860             : merge_insert:
   12861             :             INSERT merge_values_clause
   12862             :                 {
   12863         754 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12864         754 :                     n->commandType = CMD_INSERT;
   12865         754 :                     n->override = OVERRIDING_NOT_SET;
   12866         754 :                     n->targetList = NIL;
   12867         754 :                     n->values = $2;
   12868         754 :                     $$ = n;
   12869             :                 }
   12870             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12871             :                 {
   12872           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12873           0 :                     n->commandType = CMD_INSERT;
   12874           0 :                     n->override = $3;
   12875           0 :                     n->targetList = NIL;
   12876           0 :                     n->values = $5;
   12877           0 :                     $$ = n;
   12878             :                 }
   12879             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12880             :                 {
   12881         304 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12882         304 :                     n->commandType = CMD_INSERT;
   12883         304 :                     n->override = OVERRIDING_NOT_SET;
   12884         304 :                     n->targetList = $3;
   12885         304 :                     n->values = $5;
   12886         304 :                     $$ = n;
   12887             :                 }
   12888             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12889             :                 {
   12890          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12891          30 :                     n->commandType = CMD_INSERT;
   12892          30 :                     n->override = $6;
   12893          30 :                     n->targetList = $3;
   12894          30 :                     n->values = $8;
   12895          30 :                     $$ = n;
   12896             :                 }
   12897             :             | INSERT DEFAULT VALUES
   12898             :                 {
   12899          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12900          36 :                     n->commandType = CMD_INSERT;
   12901          36 :                     n->override = OVERRIDING_NOT_SET;
   12902          36 :                     n->targetList = NIL;
   12903          36 :                     n->values = NIL;
   12904          36 :                     $$ = n;
   12905             :                 }
   12906             :         ;
   12907             : 
   12908             : merge_values_clause:
   12909             :             VALUES '(' expr_list ')'
   12910             :                 {
   12911        1088 :                     $$ = $3;
   12912             :                 }
   12913             :         ;
   12914             : 
   12915             : /*****************************************************************************
   12916             :  *
   12917             :  *      QUERY:
   12918             :  *              CURSOR STATEMENTS
   12919             :  *
   12920             :  *****************************************************************************/
   12921             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12922             :                 {
   12923        4614 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12924             : 
   12925        4614 :                     n->portalname = $2;
   12926             :                     /* currently we always set FAST_PLAN option */
   12927        4614 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12928        4614 :                     n->query = $7;
   12929        4614 :                     $$ = (Node *) n;
   12930             :                 }
   12931             :         ;
   12932             : 
   12933       14832 : cursor_name:    name                        { $$ = $1; }
   12934             :         ;
   12935             : 
   12936        4614 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12937          28 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12938         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12939          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12940           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12941           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12942             :         ;
   12943             : 
   12944        4514 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12945          94 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12946           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12947             :         ;
   12948             : 
   12949             : /*****************************************************************************
   12950             :  *
   12951             :  *      QUERY:
   12952             :  *              SELECT STATEMENTS
   12953             :  *
   12954             :  *****************************************************************************/
   12955             : 
   12956             : /* A complete SELECT statement looks like this.
   12957             :  *
   12958             :  * The rule returns either a single SelectStmt node or a tree of them,
   12959             :  * representing a set-operation tree.
   12960             :  *
   12961             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12962             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12963             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12964             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12965             :  * the decision is staved off as long as possible: as long as we can keep
   12966             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12967             :  * it's no longer possible to do that will we decide that parens belong to
   12968             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12969             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12970             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12971             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12972             :  * SELECT viewpoint when we see the UNION.
   12973             :  *
   12974             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12975             :  * which represents a SELECT with at least one outer layer of parentheses,
   12976             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12977             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12978             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12979             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12980             :  * conflict with the select_with_parens productions are manually given
   12981             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12982             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12983             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12984             :  * precedence for this, which is a fairly arbitrary choice.
   12985             :  *
   12986             :  * To be able to define select_with_parens itself without ambiguity, we need
   12987             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12988             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12989             :  *
   12990             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12991             :  * with or without outer parentheses.
   12992             :  */
   12993             : 
   12994             : SelectStmt: select_no_parens            %prec UMINUS
   12995             :             | select_with_parens        %prec UMINUS
   12996             :         ;
   12997             : 
   12998             : select_with_parens:
   12999       71794 :             '(' select_no_parens ')'                { $$ = $2; }
   13000         156 :             | '(' select_with_parens ')'            { $$ = $2; }
   13001             :         ;
   13002             : 
   13003             : /*
   13004             :  * This rule parses the equivalent of the standard's <query expression>.
   13005             :  * The duplicative productions are annoying, but hard to get rid of without
   13006             :  * creating shift/reduce conflicts.
   13007             :  *
   13008             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   13009             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   13010             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   13011             :  * clause.
   13012             :  *  2002-08-28 bjm
   13013             :  */
   13014             : select_no_parens:
   13015      404404 :             simple_select                       { $$ = $1; }
   13016             :             | select_clause sort_clause
   13017             :                 {
   13018       72324 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   13019             :                                         NULL, NULL,
   13020             :                                         yyscanner);
   13021       72324 :                     $$ = $1;
   13022             :                 }
   13023             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   13024             :                 {
   13025       10566 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   13026       10566 :                                         $4,
   13027             :                                         NULL,
   13028             :                                         yyscanner);
   13029       10566 :                     $$ = $1;
   13030             :                 }
   13031             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   13032             :                 {
   13033        5034 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   13034        5034 :                                         $3,
   13035             :                                         NULL,
   13036             :                                         yyscanner);
   13037        5022 :                     $$ = $1;
   13038             :                 }
   13039             :             | with_clause select_clause
   13040             :                 {
   13041        2226 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   13042             :                                         NULL,
   13043        2226 :                                         $1,
   13044             :                                         yyscanner);
   13045        2226 :                     $$ = $2;
   13046             :                 }
   13047             :             | with_clause select_clause sort_clause
   13048             :                 {
   13049         626 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   13050             :                                         NULL,
   13051         626 :                                         $1,
   13052             :                                         yyscanner);
   13053         626 :                     $$ = $2;
   13054             :                 }
   13055             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   13056             :                 {
   13057           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   13058           6 :                                         $5,
   13059           6 :                                         $1,
   13060             :                                         yyscanner);
   13061           6 :                     $$ = $2;
   13062             :                 }
   13063             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   13064             :                 {
   13065          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   13066          64 :                                         $4,
   13067          64 :                                         $1,
   13068             :                                         yyscanner);
   13069          64 :                     $$ = $2;
   13070             :                 }
   13071             :         ;
   13072             : 
   13073             : select_clause:
   13074      130540 :             simple_select                           { $$ = $1; }
   13075         590 :             | select_with_parens                    { $$ = $1; }
   13076             :         ;
   13077             : 
   13078             : /*
   13079             :  * This rule parses SELECT statements that can appear within set operations,
   13080             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   13081             :  * the ordering of the set operations.  Without '(' and ')' we want the
   13082             :  * operations to be ordered per the precedence specs at the head of this file.
   13083             :  *
   13084             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   13085             :  * but can have parenthesized subclauses.
   13086             :  *
   13087             :  * It might appear that we could fold the first two alternatives into one
   13088             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   13089             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   13090             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   13091             :  *
   13092             :  * Note that sort clauses cannot be included at this level --- SQL requires
   13093             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   13094             :  * to be parsed as
   13095             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   13096             :  * not
   13097             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   13098             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   13099             :  * described as part of the select_no_parens production, not simple_select.
   13100             :  * This does not limit functionality, because you can reintroduce these
   13101             :  * clauses inside parentheses.
   13102             :  *
   13103             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   13104             :  * However, this is not checked by the grammar; parse analysis must check it.
   13105             :  */
   13106             : simple_select:
   13107             :             SELECT opt_all_clause opt_target_list
   13108             :             into_clause from_clause where_clause
   13109             :             group_clause having_clause window_clause
   13110             :                 {
   13111      449786 :                     SelectStmt *n = makeNode(SelectStmt);
   13112             : 
   13113      449786 :                     n->targetList = $3;
   13114      449786 :                     n->intoClause = $4;
   13115      449786 :                     n->fromClause = $5;
   13116      449786 :                     n->whereClause = $6;
   13117      449786 :                     n->groupClause = ($7)->list;
   13118      449786 :                     n->groupDistinct = ($7)->distinct;
   13119      449786 :                     n->groupByAll = ($7)->all;
   13120      449786 :                     n->havingClause = $8;
   13121      449786 :                     n->windowClause = $9;
   13122      449786 :                     $$ = (Node *) n;
   13123             :                 }
   13124             :             | SELECT distinct_clause target_list
   13125             :             into_clause from_clause where_clause
   13126             :             group_clause having_clause window_clause
   13127             :                 {
   13128        4080 :                     SelectStmt *n = makeNode(SelectStmt);
   13129             : 
   13130        4080 :                     n->distinctClause = $2;
   13131        4080 :                     n->targetList = $3;
   13132        4080 :                     n->intoClause = $4;
   13133        4080 :                     n->fromClause = $5;
   13134        4080 :                     n->whereClause = $6;
   13135        4080 :                     n->groupClause = ($7)->list;
   13136        4080 :                     n->groupDistinct = ($7)->distinct;
   13137        4080 :                     n->groupByAll = ($7)->all;
   13138        4080 :                     n->havingClause = $8;
   13139        4080 :                     n->windowClause = $9;
   13140        4080 :                     $$ = (Node *) n;
   13141             :                 }
   13142       60628 :             | values_clause                         { $$ = $1; }
   13143             :             | TABLE relation_expr
   13144             :                 {
   13145             :                     /* same as SELECT * FROM relation_expr */
   13146         314 :                     ColumnRef  *cr = makeNode(ColumnRef);
   13147         314 :                     ResTarget  *rt = makeNode(ResTarget);
   13148         314 :                     SelectStmt *n = makeNode(SelectStmt);
   13149             : 
   13150         314 :                     cr->fields = list_make1(makeNode(A_Star));
   13151         314 :                     cr->location = -1;
   13152             : 
   13153         314 :                     rt->name = NULL;
   13154         314 :                     rt->indirection = NIL;
   13155         314 :                     rt->val = (Node *) cr;
   13156         314 :                     rt->location = -1;
   13157             : 
   13158         314 :                     n->targetList = list_make1(rt);
   13159         314 :                     n->fromClause = list_make1($2);
   13160         314 :                     $$ = (Node *) n;
   13161             :                 }
   13162             :             | select_clause UNION set_quantifier select_clause
   13163             :                 {
   13164       19366 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13165             :                 }
   13166             :             | select_clause INTERSECT set_quantifier select_clause
   13167             :                 {
   13168         276 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13169             :                 }
   13170             :             | select_clause EXCEPT set_quantifier select_clause
   13171             :                 {
   13172         494 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13173             :                 }
   13174             :         ;
   13175             : 
   13176             : /*
   13177             :  * SQL standard WITH clause looks like:
   13178             :  *
   13179             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13180             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13181             :  *
   13182             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13183             :  */
   13184             : with_clause:
   13185             :         WITH cte_list
   13186             :             {
   13187        2140 :                 $$ = makeNode(WithClause);
   13188        2140 :                 $$->ctes = $2;
   13189        2140 :                 $$->recursive = false;
   13190        2140 :                 $$->location = @1;
   13191             :             }
   13192             :         | WITH_LA cte_list
   13193             :             {
   13194           6 :                 $$ = makeNode(WithClause);
   13195           6 :                 $$->ctes = $2;
   13196           6 :                 $$->recursive = false;
   13197           6 :                 $$->location = @1;
   13198             :             }
   13199             :         | WITH RECURSIVE cte_list
   13200             :             {
   13201        1254 :                 $$ = makeNode(WithClause);
   13202        1254 :                 $$->ctes = $3;
   13203        1254 :                 $$->recursive = true;
   13204        1254 :                 $$->location = @1;
   13205             :             }
   13206             :         ;
   13207             : 
   13208             : cte_list:
   13209        3400 :         common_table_expr                       { $$ = list_make1($1); }
   13210        1310 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13211             :         ;
   13212             : 
   13213             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13214             :             {
   13215        4710 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13216             : 
   13217        4710 :                 n->ctename = $1;
   13218        4710 :                 n->aliascolnames = $2;
   13219        4710 :                 n->ctematerialized = $4;
   13220        4710 :                 n->ctequery = $6;
   13221        4710 :                 n->search_clause = castNode(CTESearchClause, $8);
   13222        4710 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13223        4710 :                 n->location = @1;
   13224        4710 :                 $$ = (Node *) n;
   13225             :             }
   13226             :         ;
   13227             : 
   13228             : opt_materialized:
   13229         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13230          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13231        4484 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13232             :         ;
   13233             : 
   13234             : opt_search_clause:
   13235             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13236             :             {
   13237          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13238             : 
   13239          90 :                 n->search_col_list = $5;
   13240          90 :                 n->search_breadth_first = false;
   13241          90 :                 n->search_seq_column = $7;
   13242          90 :                 n->location = @1;
   13243          90 :                 $$ = (Node *) n;
   13244             :             }
   13245             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13246             :             {
   13247          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13248             : 
   13249          36 :                 n->search_col_list = $5;
   13250          36 :                 n->search_breadth_first = true;
   13251          36 :                 n->search_seq_column = $7;
   13252          36 :                 n->location = @1;
   13253          36 :                 $$ = (Node *) n;
   13254             :             }
   13255             :         | /*EMPTY*/
   13256             :             {
   13257        4584 :                 $$ = NULL;
   13258             :             }
   13259             :         ;
   13260             : 
   13261             : opt_cycle_clause:
   13262             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13263             :             {
   13264          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13265             : 
   13266          66 :                 n->cycle_col_list = $2;
   13267          66 :                 n->cycle_mark_column = $4;
   13268          66 :                 n->cycle_mark_value = $6;
   13269          66 :                 n->cycle_mark_default = $8;
   13270          66 :                 n->cycle_path_column = $10;
   13271          66 :                 n->location = @1;
   13272          66 :                 $$ = (Node *) n;
   13273             :             }
   13274             :         | CYCLE columnList SET ColId USING ColId
   13275             :             {
   13276          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13277             : 
   13278          60 :                 n->cycle_col_list = $2;
   13279          60 :                 n->cycle_mark_column = $4;
   13280          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13281          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13282          60 :                 n->cycle_path_column = $6;
   13283          60 :                 n->location = @1;
   13284          60 :                 $$ = (Node *) n;
   13285             :             }
   13286             :         | /*EMPTY*/
   13287             :             {
   13288        4584 :                 $$ = NULL;
   13289             :             }
   13290             :         ;
   13291             : 
   13292             : opt_with_clause:
   13293         478 :         with_clause                             { $$ = $1; }
   13294       91652 :         | /*EMPTY*/                             { $$ = NULL; }
   13295             :         ;
   13296             : 
   13297             : into_clause:
   13298             :             INTO OptTempTableName
   13299             :                 {
   13300         138 :                     $$ = makeNode(IntoClause);
   13301         138 :                     $$->rel = $2;
   13302         138 :                     $$->colNames = NIL;
   13303         138 :                     $$->options = NIL;
   13304         138 :                     $$->onCommit = ONCOMMIT_NOOP;
   13305         138 :                     $$->tableSpaceName = NULL;
   13306         138 :                     $$->viewQuery = NULL;
   13307         138 :                     $$->skipData = false;
   13308             :                 }
   13309             :             | /*EMPTY*/
   13310      453758 :                 { $$ = NULL; }
   13311             :         ;
   13312             : 
   13313             : /*
   13314             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13315             :  * since TEMP is not a reserved word.  See also OptTemp.
   13316             :  */
   13317             : OptTempTableName:
   13318             :             TEMPORARY opt_table qualified_name
   13319             :                 {
   13320           0 :                     $$ = $3;
   13321           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13322             :                 }
   13323             :             | TEMP opt_table qualified_name
   13324             :                 {
   13325           6 :                     $$ = $3;
   13326           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13327             :                 }
   13328             :             | LOCAL TEMPORARY opt_table qualified_name
   13329             :                 {
   13330           0 :                     $$ = $4;
   13331           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13332             :                 }
   13333             :             | LOCAL TEMP opt_table qualified_name
   13334             :                 {
   13335           0 :                     $$ = $4;
   13336           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13337             :                 }
   13338             :             | GLOBAL TEMPORARY opt_table qualified_name
   13339             :                 {
   13340           0 :                     ereport(WARNING,
   13341             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13342             :                              parser_errposition(@1)));
   13343           0 :                     $$ = $4;
   13344           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13345             :                 }
   13346             :             | GLOBAL TEMP opt_table qualified_name
   13347             :                 {
   13348           0 :                     ereport(WARNING,
   13349             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13350             :                              parser_errposition(@1)));
   13351           0 :                     $$ = $4;
   13352           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13353             :                 }
   13354             :             | UNLOGGED opt_table qualified_name
   13355             :                 {
   13356           0 :                     $$ = $3;
   13357           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13358             :                 }
   13359             :             | TABLE qualified_name
   13360             :                 {
   13361          30 :                     $$ = $2;
   13362          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13363             :                 }
   13364             :             | qualified_name
   13365             :                 {
   13366         102 :                     $$ = $1;
   13367         102 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13368             :                 }
   13369             :         ;
   13370             : 
   13371             : opt_table:  TABLE
   13372             :             | /*EMPTY*/
   13373             :         ;
   13374             : 
   13375             : set_quantifier:
   13376       11308 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13377          38 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13378       13860 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13379             :         ;
   13380             : 
   13381             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13382             :  * should be placed in the DISTINCT list during parsetree analysis.
   13383             :  */
   13384             : distinct_clause:
   13385        3824 :             DISTINCT                                { $$ = list_make1(NIL); }
   13386         262 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13387             :         ;
   13388             : 
   13389             : opt_all_clause:
   13390             :             ALL
   13391             :             | /*EMPTY*/
   13392             :         ;
   13393             : 
   13394             : opt_distinct_clause:
   13395           0 :             distinct_clause                         { $$ = $1; }
   13396       41514 :             | opt_all_clause                        { $$ = NIL; }
   13397             :         ;
   13398             : 
   13399             : opt_sort_clause:
   13400        7584 :             sort_clause                             { $$ = $1; }
   13401      378460 :             | /*EMPTY*/                             { $$ = NIL; }
   13402             :         ;
   13403             : 
   13404             : sort_clause:
   13405       80882 :             ORDER BY sortby_list                    { $$ = $3; }
   13406             :         ;
   13407             : 
   13408             : sortby_list:
   13409       80900 :             sortby                                  { $$ = list_make1($1); }
   13410       29444 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13411             :         ;
   13412             : 
   13413             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13414             :                 {
   13415         220 :                     $$ = makeNode(SortBy);
   13416         220 :                     $$->node = $1;
   13417         220 :                     $$->sortby_dir = SORTBY_USING;
   13418         220 :                     $$->sortby_nulls = $4;
   13419         220 :                     $$->useOp = $3;
   13420         220 :                     $$->location = @3;
   13421             :                 }
   13422             :             | a_expr opt_asc_desc opt_nulls_order
   13423             :                 {
   13424      110124 :                     $$ = makeNode(SortBy);
   13425      110124 :                     $$->node = $1;
   13426      110124 :                     $$->sortby_dir = $2;
   13427      110124 :                     $$->sortby_nulls = $3;
   13428      110124 :                     $$->useOp = NIL;
   13429      110124 :                     $$->location = -1;       /* no operator */
   13430             :                 }
   13431             :         ;
   13432             : 
   13433             : 
   13434             : select_limit:
   13435             :             limit_clause offset_clause
   13436             :                 {
   13437         172 :                     $$ = $1;
   13438         172 :                     ($$)->limitOffset = $2;
   13439         172 :                     ($$)->offsetLoc = @2;
   13440             :                 }
   13441             :             | offset_clause limit_clause
   13442             :                 {
   13443         222 :                     $$ = $2;
   13444         222 :                     ($$)->limitOffset = $1;
   13445         222 :                     ($$)->offsetLoc = @1;
   13446             :                 }
   13447             :             | limit_clause
   13448             :                 {
   13449        4426 :                     $$ = $1;
   13450             :                 }
   13451             :             | offset_clause
   13452             :                 {
   13453         468 :                     SelectLimit *n = palloc_object(SelectLimit);
   13454             : 
   13455         468 :                     n->limitOffset = $1;
   13456         468 :                     n->limitCount = NULL;
   13457         468 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13458         468 :                     n->offsetLoc = @1;
   13459         468 :                     n->countLoc = -1;
   13460         468 :                     n->optionLoc = -1;
   13461         468 :                     $$ = n;
   13462             :                 }
   13463             :         ;
   13464             : 
   13465             : opt_select_limit:
   13466         190 :             select_limit                        { $$ = $1; }
   13467       51896 :             | /* EMPTY */                       { $$ = NULL; }
   13468             :         ;
   13469             : 
   13470             : limit_clause:
   13471             :             LIMIT select_limit_value
   13472             :                 {
   13473        4724 :                     SelectLimit *n = palloc_object(SelectLimit);
   13474             : 
   13475        4724 :                     n->limitOffset = NULL;
   13476        4724 :                     n->limitCount = $2;
   13477        4724 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13478        4724 :                     n->offsetLoc = -1;
   13479        4724 :                     n->countLoc = @1;
   13480        4724 :                     n->optionLoc = -1;
   13481        4724 :                     $$ = n;
   13482             :                 }
   13483             :             | LIMIT select_limit_value ',' select_offset_value
   13484             :                 {
   13485             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13486           0 :                     ereport(ERROR,
   13487             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13488             :                              errmsg("LIMIT #,# syntax is not supported"),
   13489             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13490             :                              parser_errposition(@1)));
   13491             :                 }
   13492             :             /* SQL:2008 syntax */
   13493             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13494             :              * a separate production rather than an opt_ expression.  The fact
   13495             :              * that ONLY is fully reserved means that this way, we defer any
   13496             :              * decision about what rule reduces ROW or ROWS to the point where
   13497             :              * we can see the ONLY token in the lookahead slot.
   13498             :              */
   13499             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13500             :                 {
   13501          24 :                     SelectLimit *n = palloc_object(SelectLimit);
   13502             : 
   13503          24 :                     n->limitOffset = NULL;
   13504          24 :                     n->limitCount = $3;
   13505          24 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13506          24 :                     n->offsetLoc = -1;
   13507          24 :                     n->countLoc = @1;
   13508          24 :                     n->optionLoc = -1;
   13509          24 :                     $$ = n;
   13510             :                 }
   13511             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13512             :                 {
   13513          66 :                     SelectLimit *n = palloc_object(SelectLimit);
   13514             : 
   13515          66 :                     n->limitOffset = NULL;
   13516          66 :                     n->limitCount = $3;
   13517          66 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13518          66 :                     n->offsetLoc = -1;
   13519          66 :                     n->countLoc = @1;
   13520          66 :                     n->optionLoc = @5;
   13521          66 :                     $$ = n;
   13522             :                 }
   13523             :             | FETCH first_or_next row_or_rows ONLY
   13524             :                 {
   13525           0 :                     SelectLimit *n = palloc_object(SelectLimit);
   13526             : 
   13527           0 :                     n->limitOffset = NULL;
   13528           0 :                     n->limitCount = makeIntConst(1, -1);
   13529           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13530           0 :                     n->offsetLoc = -1;
   13531           0 :                     n->countLoc = @1;
   13532           0 :                     n->optionLoc = -1;
   13533           0 :                     $$ = n;
   13534             :                 }
   13535             :             | FETCH first_or_next row_or_rows WITH TIES
   13536             :                 {
   13537           6 :                     SelectLimit *n = palloc_object(SelectLimit);
   13538             : 
   13539           6 :                     n->limitOffset = NULL;
   13540           6 :                     n->limitCount = makeIntConst(1, -1);
   13541           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13542           6 :                     n->offsetLoc = -1;
   13543           6 :                     n->countLoc = @1;
   13544           6 :                     n->optionLoc = @4;
   13545           6 :                     $$ = n;
   13546             :                 }
   13547             :         ;
   13548             : 
   13549             : offset_clause:
   13550             :             OFFSET select_offset_value
   13551         862 :                 { $$ = $2; }
   13552             :             /* SQL:2008 syntax */
   13553             :             | OFFSET select_fetch_first_value row_or_rows
   13554           0 :                 { $$ = $2; }
   13555             :         ;
   13556             : 
   13557             : select_limit_value:
   13558        4722 :             a_expr                                  { $$ = $1; }
   13559             :             | ALL
   13560             :                 {
   13561             :                     /* LIMIT ALL is represented as a NULL constant */
   13562           2 :                     $$ = makeNullAConst(@1);
   13563             :                 }
   13564             :         ;
   13565             : 
   13566             : select_offset_value:
   13567         862 :             a_expr                                  { $$ = $1; }
   13568             :         ;
   13569             : 
   13570             : /*
   13571             :  * Allowing full expressions without parentheses causes various parsing
   13572             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13573             :  * <simple value specification>, which is either a literal or a parameter (but
   13574             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13575             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13576             :  * to determine whether the expression is missing rather than trying to make it
   13577             :  * optional in this rule.
   13578             :  *
   13579             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13580             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13581             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13582             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13583             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13584             :  * builds.)
   13585             :  */
   13586             : select_fetch_first_value:
   13587          90 :             c_expr                                  { $$ = $1; }
   13588             :             | '+' I_or_F_const
   13589           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13590             :             | '-' I_or_F_const
   13591           0 :                 { $$ = doNegate($2, @1); }
   13592             :         ;
   13593             : 
   13594             : I_or_F_const:
   13595           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13596           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13597             :         ;
   13598             : 
   13599             : /* noise words */
   13600          36 : row_or_rows: ROW                                    { $$ = 0; }
   13601          60 :             | ROWS                                  { $$ = 0; }
   13602             :         ;
   13603             : 
   13604          96 : first_or_next: FIRST_P                              { $$ = 0; }
   13605           0 :             | NEXT                                  { $$ = 0; }
   13606             :         ;
   13607             : 
   13608             : 
   13609             : /*
   13610             :  * This syntax for group_clause tries to follow the spec quite closely.
   13611             :  * However, the spec allows only column references, not expressions,
   13612             :  * which introduces an ambiguity between implicit row constructors
   13613             :  * (a,b) and lists of column references.
   13614             :  *
   13615             :  * We handle this by using the a_expr production for what the spec calls
   13616             :  * <ordinary grouping set>, which in the spec represents either one column
   13617             :  * reference or a parenthesized list of column references. Then, we check the
   13618             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13619             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13620             :  * not here)
   13621             :  *
   13622             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13623             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13624             :  * in a group clause, but if they have a reason to, we make it possible.)
   13625             :  *
   13626             :  * Each item in the group_clause list is either an expression tree or a
   13627             :  * GroupingSet node of some type.
   13628             :  */
   13629             : group_clause:
   13630             :             GROUP_P BY set_quantifier group_by_list
   13631             :                 {
   13632        5058 :                     GroupClause *n = palloc_object(GroupClause);
   13633             : 
   13634        5058 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13635        5058 :                     n->all = false;
   13636        5058 :                     n->list = $4;
   13637        5058 :                     $$ = n;
   13638             :                 }
   13639             :             | GROUP_P BY ALL
   13640             :                 {
   13641          66 :                     GroupClause *n = palloc_object(GroupClause);
   13642          66 :                     n->distinct = false;
   13643          66 :                     n->all = true;
   13644          66 :                     n->list = NIL;
   13645          66 :                     $$ = n;
   13646             :                 }
   13647             :             | /*EMPTY*/
   13648             :                 {
   13649      490256 :                     GroupClause *n = palloc_object(GroupClause);
   13650             : 
   13651      490256 :                     n->distinct = false;
   13652      490256 :                     n->all = false;
   13653      490256 :                     n->list = NIL;
   13654      490256 :                     $$ = n;
   13655             :                 }
   13656             :         ;
   13657             : 
   13658             : group_by_list:
   13659        5774 :             group_by_item                           { $$ = list_make1($1); }
   13660        3156 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13661             :         ;
   13662             : 
   13663             : group_by_item:
   13664        7392 :             a_expr                                  { $$ = $1; }
   13665         310 :             | empty_grouping_set                    { $$ = $1; }
   13666         184 :             | cube_clause                           { $$ = $1; }
   13667         328 :             | rollup_clause                         { $$ = $1; }
   13668         716 :             | grouping_sets_clause                  { $$ = $1; }
   13669             :         ;
   13670             : 
   13671             : empty_grouping_set:
   13672             :             '(' ')'
   13673             :                 {
   13674         310 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13675             :                 }
   13676             :         ;
   13677             : 
   13678             : /*
   13679             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13680             :  * so that they shift in these rules rather than reducing the conflicting
   13681             :  * unreserved_keyword rule.
   13682             :  */
   13683             : 
   13684             : rollup_clause:
   13685             :             ROLLUP '(' expr_list ')'
   13686             :                 {
   13687         328 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13688             :                 }
   13689             :         ;
   13690             : 
   13691             : cube_clause:
   13692             :             CUBE '(' expr_list ')'
   13693             :                 {
   13694         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13695             :                 }
   13696             :         ;
   13697             : 
   13698             : grouping_sets_clause:
   13699             :             GROUPING SETS '(' group_by_list ')'
   13700             :                 {
   13701         716 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13702             :                 }
   13703             :         ;
   13704             : 
   13705             : having_clause:
   13706         792 :             HAVING a_expr                           { $$ = $2; }
   13707      494588 :             | /*EMPTY*/                             { $$ = NULL; }
   13708             :         ;
   13709             : 
   13710             : for_locking_clause:
   13711       10912 :             for_locking_items                       { $$ = $1; }
   13712           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13713             :         ;
   13714             : 
   13715             : opt_for_locking_clause:
   13716         340 :             for_locking_clause                      { $$ = $1; }
   13717       46272 :             | /* EMPTY */                           { $$ = NIL; }
   13718             :         ;
   13719             : 
   13720             : for_locking_items:
   13721       10912 :             for_locking_item                        { $$ = list_make1($1); }
   13722         102 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13723             :         ;
   13724             : 
   13725             : for_locking_item:
   13726             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13727             :                 {
   13728       11014 :                     LockingClause *n = makeNode(LockingClause);
   13729             : 
   13730       11014 :                     n->lockedRels = $2;
   13731       11014 :                     n->strength = $1;
   13732       11014 :                     n->waitPolicy = $3;
   13733       11014 :                     $$ = (Node *) n;
   13734             :                 }
   13735             :         ;
   13736             : 
   13737             : for_locking_strength:
   13738        1562 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13739          82 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13740         220 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13741        9150 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13742             :         ;
   13743             : 
   13744             : locked_rels_list:
   13745        3640 :             OF qualified_name_list                  { $$ = $2; }
   13746        7374 :             | /* EMPTY */                           { $$ = NIL; }
   13747             :         ;
   13748             : 
   13749             : 
   13750             : /*
   13751             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13752             :  * making VALUES a fully reserved word, which will probably break more apps
   13753             :  * than allowing the noise-word is worth.
   13754             :  */
   13755             : values_clause:
   13756             :             VALUES '(' expr_list ')'
   13757             :                 {
   13758       60628 :                     SelectStmt *n = makeNode(SelectStmt);
   13759             : 
   13760       60628 :                     n->valuesLists = list_make1($3);
   13761       60628 :                     $$ = (Node *) n;
   13762             :                 }
   13763             :             | values_clause ',' '(' expr_list ')'
   13764             :                 {
   13765       26526 :                     SelectStmt *n = (SelectStmt *) $1;
   13766             : 
   13767       26526 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13768       26526 :                     $$ = (Node *) n;
   13769             :                 }
   13770             :         ;
   13771             : 
   13772             : 
   13773             : /*****************************************************************************
   13774             :  *
   13775             :  *  clauses common to all Optimizable Stmts:
   13776             :  *      from_clause     - allow list of both JOIN expressions and table names
   13777             :  *      where_clause    - qualifications for joins or restrictions
   13778             :  *
   13779             :  *****************************************************************************/
   13780             : 
   13781             : from_clause:
   13782      332096 :             FROM from_list                          { $$ = $2; }
   13783      178236 :             | /*EMPTY*/                             { $$ = NIL; }
   13784             :         ;
   13785             : 
   13786             : from_list:
   13787      333078 :             table_ref                               { $$ = list_make1($1); }
   13788       62362 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13789             :         ;
   13790             : 
   13791             : /*
   13792             :  * table_ref is where an alias clause can be attached.
   13793             :  */
   13794             : table_ref:  relation_expr opt_alias_clause
   13795             :                 {
   13796      410668 :                     $1->alias = $2;
   13797      410668 :                     $$ = (Node *) $1;
   13798             :                 }
   13799             :             | relation_expr opt_alias_clause tablesample_clause
   13800             :                 {
   13801         266 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13802             : 
   13803         266 :                     $1->alias = $2;
   13804             :                     /* relation_expr goes inside the RangeTableSample node */
   13805         266 :                     n->relation = (Node *) $1;
   13806         266 :                     $$ = (Node *) n;
   13807             :                 }
   13808             :             | func_table func_alias_clause
   13809             :                 {
   13810       47918 :                     RangeFunction *n = (RangeFunction *) $1;
   13811             : 
   13812       47918 :                     n->alias = linitial($2);
   13813       47918 :                     n->coldeflist = lsecond($2);
   13814       47918 :                     $$ = (Node *) n;
   13815             :                 }
   13816             :             | LATERAL_P func_table func_alias_clause
   13817             :                 {
   13818        1324 :                     RangeFunction *n = (RangeFunction *) $2;
   13819             : 
   13820        1324 :                     n->lateral = true;
   13821        1324 :                     n->alias = linitial($3);
   13822        1324 :                     n->coldeflist = lsecond($3);
   13823        1324 :                     $$ = (Node *) n;
   13824             :                 }
   13825             :             | xmltable opt_alias_clause
   13826             :                 {
   13827          86 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13828             : 
   13829          86 :                     n->alias = $2;
   13830          86 :                     $$ = (Node *) n;
   13831             :                 }
   13832             :             | LATERAL_P xmltable opt_alias_clause
   13833             :                 {
   13834         140 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13835             : 
   13836         140 :                     n->lateral = true;
   13837         140 :                     n->alias = $3;
   13838         140 :                     $$ = (Node *) n;
   13839             :                 }
   13840             :             | select_with_parens opt_alias_clause
   13841             :                 {
   13842       19988 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13843             : 
   13844       19988 :                     n->lateral = false;
   13845       19988 :                     n->subquery = $1;
   13846       19988 :                     n->alias = $2;
   13847       19988 :                     $$ = (Node *) n;
   13848             :                 }
   13849             :             | LATERAL_P select_with_parens opt_alias_clause
   13850             :                 {
   13851        1936 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13852             : 
   13853        1936 :                     n->lateral = true;
   13854        1936 :                     n->subquery = $2;
   13855        1936 :                     n->alias = $3;
   13856        1936 :                     $$ = (Node *) n;
   13857             :                 }
   13858             :             | joined_table
   13859             :                 {
   13860       85028 :                     $$ = (Node *) $1;
   13861             :                 }
   13862             :             | '(' joined_table ')' alias_clause
   13863             :                 {
   13864         174 :                     $2->alias = $4;
   13865         174 :                     $$ = (Node *) $2;
   13866             :                 }
   13867             :             | json_table opt_alias_clause
   13868             :                 {
   13869         530 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13870             : 
   13871         530 :                     jt->alias = $2;
   13872         530 :                     $$ = (Node *) jt;
   13873             :                 }
   13874             :             | LATERAL_P json_table opt_alias_clause
   13875             :                 {
   13876           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13877             : 
   13878           0 :                     jt->alias = $3;
   13879           0 :                     jt->lateral = true;
   13880           0 :                     $$ = (Node *) jt;
   13881             :                 }
   13882             :         ;
   13883             : 
   13884             : 
   13885             : /*
   13886             :  * It may seem silly to separate joined_table from table_ref, but there is
   13887             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13888             :  * reduce conflicts, because it's not clear to the parser generator whether
   13889             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13890             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13891             :  * join_type to expand to empty; if we try it, the parser generator can't
   13892             :  * figure out when to reduce an empty join_type right after table_ref.
   13893             :  *
   13894             :  * Note that a CROSS JOIN is the same as an unqualified
   13895             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13896             :  * but a qualification expression to limit membership.
   13897             :  * A NATURAL JOIN implicitly matches column names between
   13898             :  * tables and the shape is determined by which columns are
   13899             :  * in common. We'll collect columns during the later transformations.
   13900             :  */
   13901             : 
   13902             : joined_table:
   13903             :             '(' joined_table ')'
   13904             :                 {
   13905        4024 :                     $$ = $2;
   13906             :                 }
   13907             :             | table_ref CROSS JOIN table_ref
   13908             :                 {
   13909             :                     /* CROSS JOIN is same as unqualified inner join */
   13910         524 :                     JoinExpr   *n = makeNode(JoinExpr);
   13911             : 
   13912         524 :                     n->jointype = JOIN_INNER;
   13913         524 :                     n->isNatural = false;
   13914         524 :                     n->larg = $1;
   13915         524 :                     n->rarg = $4;
   13916         524 :                     n->usingClause = NIL;
   13917         524 :                     n->join_using_alias = NULL;
   13918         524 :                     n->quals = NULL;
   13919         524 :                     $$ = n;
   13920             :                 }
   13921             :             | table_ref join_type JOIN table_ref join_qual
   13922             :                 {
   13923       47884 :                     JoinExpr   *n = makeNode(JoinExpr);
   13924             : 
   13925       47884 :                     n->jointype = $2;
   13926       47884 :                     n->isNatural = false;
   13927       47884 :                     n->larg = $1;
   13928       47884 :                     n->rarg = $4;
   13929       47884 :                     if ($5 != NULL && IsA($5, List))
   13930             :                     {
   13931             :                          /* USING clause */
   13932         498 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13933         498 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13934             :                     }
   13935             :                     else
   13936             :                     {
   13937             :                         /* ON clause */
   13938       47386 :                         n->quals = $5;
   13939             :                     }
   13940       47884 :                     $$ = n;
   13941             :                 }
   13942             :             | table_ref JOIN table_ref join_qual
   13943             :                 {
   13944             :                     /* letting join_type reduce to empty doesn't work */
   13945       36530 :                     JoinExpr   *n = makeNode(JoinExpr);
   13946             : 
   13947       36530 :                     n->jointype = JOIN_INNER;
   13948       36530 :                     n->isNatural = false;
   13949       36530 :                     n->larg = $1;
   13950       36530 :                     n->rarg = $3;
   13951       36530 :                     if ($4 != NULL && IsA($4, List))
   13952             :                     {
   13953             :                         /* USING clause */
   13954         744 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13955         744 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13956             :                     }
   13957             :                     else
   13958             :                     {
   13959             :                         /* ON clause */
   13960       35786 :                         n->quals = $4;
   13961             :                     }
   13962       36530 :                     $$ = n;
   13963             :                 }
   13964             :             | table_ref NATURAL join_type JOIN table_ref
   13965             :                 {
   13966          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13967             : 
   13968          78 :                     n->jointype = $3;
   13969          78 :                     n->isNatural = true;
   13970          78 :                     n->larg = $1;
   13971          78 :                     n->rarg = $5;
   13972          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13973          78 :                     n->join_using_alias = NULL;
   13974          78 :                     n->quals = NULL; /* fill later */
   13975          78 :                     $$ = n;
   13976             :                 }
   13977             :             | table_ref NATURAL JOIN table_ref
   13978             :                 {
   13979             :                     /* letting join_type reduce to empty doesn't work */
   13980         186 :                     JoinExpr   *n = makeNode(JoinExpr);
   13981             : 
   13982         186 :                     n->jointype = JOIN_INNER;
   13983         186 :                     n->isNatural = true;
   13984         186 :                     n->larg = $1;
   13985         186 :                     n->rarg = $4;
   13986         186 :                     n->usingClause = NIL; /* figure out which columns later... */
   13987         186 :                     n->join_using_alias = NULL;
   13988         186 :                     n->quals = NULL; /* fill later */
   13989         186 :                     $$ = n;
   13990             :                 }
   13991             :         ;
   13992             : 
   13993             : alias_clause:
   13994             :             AS ColId '(' name_list ')'
   13995             :                 {
   13996        6852 :                     $$ = makeNode(Alias);
   13997        6852 :                     $$->aliasname = $2;
   13998        6852 :                     $$->colnames = $4;
   13999             :                 }
   14000             :             | AS ColId
   14001             :                 {
   14002       16640 :                     $$ = makeNode(Alias);
   14003       16640 :                     $$->aliasname = $2;
   14004             :                 }
   14005             :             | ColId '(' name_list ')'
   14006             :                 {
   14007        5906 :                     $$ = makeNode(Alias);
   14008        5906 :                     $$->aliasname = $1;
   14009        5906 :                     $$->colnames = $3;
   14010             :                 }
   14011             :             | ColId
   14012             :                 {
   14013      268350 :                     $$ = makeNode(Alias);
   14014      268350 :                     $$->aliasname = $1;
   14015             :                 }
   14016             :         ;
   14017             : 
   14018      268264 : opt_alias_clause: alias_clause                      { $$ = $1; }
   14019      165350 :             | /*EMPTY*/                             { $$ = NULL; }
   14020             :         ;
   14021             : 
   14022             : /*
   14023             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   14024             :  * per SQL standard.  (The grammar could parse the other variants, but they
   14025             :  * don't seem to be useful, and it might lead to parser problems in the
   14026             :  * future.)
   14027             :  */
   14028             : opt_alias_clause_for_join_using:
   14029             :             AS ColId
   14030             :                 {
   14031          84 :                     $$ = makeNode(Alias);
   14032          84 :                     $$->aliasname = $2;
   14033             :                     /* the column name list will be inserted later */
   14034             :                 }
   14035        1158 :             | /*EMPTY*/                             { $$ = NULL; }
   14036             :         ;
   14037             : 
   14038             : /*
   14039             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   14040             :  * return a 2-element list that gets disassembled by calling production.
   14041             :  */
   14042             : func_alias_clause:
   14043             :             alias_clause
   14044             :                 {
   14045       29310 :                     $$ = list_make2($1, NIL);
   14046             :                 }
   14047             :             | AS '(' TableFuncElementList ')'
   14048             :                 {
   14049         114 :                     $$ = list_make2(NULL, $3);
   14050             :                 }
   14051             :             | AS ColId '(' TableFuncElementList ')'
   14052             :                 {
   14053         596 :                     Alias      *a = makeNode(Alias);
   14054             : 
   14055         596 :                     a->aliasname = $2;
   14056         596 :                     $$ = list_make2(a, $4);
   14057             :                 }
   14058             :             | ColId '(' TableFuncElementList ')'
   14059             :                 {
   14060          50 :                     Alias      *a = makeNode(Alias);
   14061             : 
   14062          50 :                     a->aliasname = $1;
   14063          50 :                     $$ = list_make2(a, $3);
   14064             :                 }
   14065             :             | /*EMPTY*/
   14066             :                 {
   14067       19172 :                     $$ = list_make2(NULL, NIL);
   14068             :                 }
   14069             :         ;
   14070             : 
   14071        1042 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   14072       42482 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   14073         390 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   14074        4048 :             | INNER_P                               { $$ = JOIN_INNER; }
   14075             :         ;
   14076             : 
   14077             : /* OUTER is just noise... */
   14078             : opt_outer: OUTER_P
   14079             :             | /*EMPTY*/
   14080             :         ;
   14081             : 
   14082             : /* JOIN qualification clauses
   14083             :  * Possibilities are:
   14084             :  *  USING ( column list ) [ AS alias ]
   14085             :  *                        allows only unqualified column names,
   14086             :  *                        which must match between tables.
   14087             :  *  ON expr allows more general qualifications.
   14088             :  *
   14089             :  * We return USING as a two-element List (the first item being a sub-List
   14090             :  * of the common column names, and the second either an Alias item or NULL).
   14091             :  * An ON-expr will not be a List, so it can be told apart that way.
   14092             :  */
   14093             : 
   14094             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   14095             :                 {
   14096        1242 :                     $$ = (Node *) list_make2($3, $5);
   14097             :                 }
   14098             :             | ON a_expr
   14099             :                 {
   14100       83172 :                     $$ = $2;
   14101             :                 }
   14102             :         ;
   14103             : 
   14104             : 
   14105             : relation_expr:
   14106             :             qualified_name
   14107             :                 {
   14108             :                     /* inheritance query, implicitly */
   14109      494640 :                     $$ = $1;
   14110      494640 :                     $$->inh = true;
   14111      494640 :                     $$->alias = NULL;
   14112             :                 }
   14113             :             | extended_relation_expr
   14114             :                 {
   14115        7378 :                     $$ = $1;
   14116             :                 }
   14117             :         ;
   14118             : 
   14119             : extended_relation_expr:
   14120             :             qualified_name '*'
   14121             :                 {
   14122             :                     /* inheritance query, explicitly */
   14123         204 :                     $$ = $1;
   14124         204 :                     $$->inh = true;
   14125         204 :                     $$->alias = NULL;
   14126             :                 }
   14127             :             | ONLY qualified_name
   14128             :                 {
   14129             :                     /* no inheritance */
   14130        7180 :                     $$ = $2;
   14131        7180 :                     $$->inh = false;
   14132        7180 :                     $$->alias = NULL;
   14133             :                 }
   14134             :             | ONLY '(' qualified_name ')'
   14135             :                 {
   14136             :                     /* no inheritance, SQL99-style syntax */
   14137           0 :                     $$ = $3;
   14138           0 :                     $$->inh = false;
   14139           0 :                     $$->alias = NULL;
   14140             :                 }
   14141             :         ;
   14142             : 
   14143             : 
   14144             : relation_expr_list:
   14145        2874 :             relation_expr                           { $$ = list_make1($1); }
   14146       11230 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   14147             :         ;
   14148             : 
   14149             : 
   14150             : /*
   14151             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   14152             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   14153             :  * keyword.  Since "set" is allowed as a column name both interpretations
   14154             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   14155             :  * relation_expr_opt_alias production a higher precedence than the SET token
   14156             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   14157             :  * SET is not an alias.
   14158             :  */
   14159             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   14160             :                 {
   14161       19492 :                     $$ = $1;
   14162             :                 }
   14163             :             | relation_expr ColId
   14164             :                 {
   14165        2304 :                     Alias      *alias = makeNode(Alias);
   14166             : 
   14167        2304 :                     alias->aliasname = $2;
   14168        2304 :                     $1->alias = alias;
   14169        2304 :                     $$ = $1;
   14170             :                 }
   14171             :             | relation_expr AS ColId
   14172             :                 {
   14173          90 :                     Alias      *alias = makeNode(Alias);
   14174             : 
   14175          90 :                     alias->aliasname = $3;
   14176          90 :                     $1->alias = alias;
   14177          90 :                     $$ = $1;
   14178             :                 }
   14179             :         ;
   14180             : 
   14181             : /*
   14182             :  * TABLESAMPLE decoration in a FROM item
   14183             :  */
   14184             : tablesample_clause:
   14185             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14186             :                 {
   14187         266 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14188             : 
   14189             :                     /* n->relation will be filled in later */
   14190         266 :                     n->method = $2;
   14191         266 :                     n->args = $4;
   14192         266 :                     n->repeatable = $6;
   14193         266 :                     n->location = @2;
   14194         266 :                     $$ = (Node *) n;
   14195             :                 }
   14196             :         ;
   14197             : 
   14198             : opt_repeatable_clause:
   14199         108 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14200         158 :             | /*EMPTY*/                 { $$ = NULL; }
   14201             :         ;
   14202             : 
   14203             : /*
   14204             :  * func_table represents a function invocation in a FROM list. It can be
   14205             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14206             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14207             :  * optionally with WITH ORDINALITY attached.
   14208             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14209             :  * function, for example:
   14210             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14211             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14212             :  * It's also possible to attach a column definition list to the RangeFunction
   14213             :  * as a whole, but that's handled by the table_ref production.
   14214             :  */
   14215             : func_table: func_expr_windowless opt_ordinality
   14216             :                 {
   14217       49116 :                     RangeFunction *n = makeNode(RangeFunction);
   14218             : 
   14219       49116 :                     n->lateral = false;
   14220       49116 :                     n->ordinality = $2;
   14221       49116 :                     n->is_rowsfrom = false;
   14222       49116 :                     n->functions = list_make1(list_make2($1, NIL));
   14223             :                     /* alias and coldeflist are set by table_ref production */
   14224       49116 :                     $$ = (Node *) n;
   14225             :                 }
   14226             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14227             :                 {
   14228         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14229             : 
   14230         132 :                     n->lateral = false;
   14231         132 :                     n->ordinality = $6;
   14232         132 :                     n->is_rowsfrom = true;
   14233         132 :                     n->functions = $4;
   14234             :                     /* alias and coldeflist are set by table_ref production */
   14235         132 :                     $$ = (Node *) n;
   14236             :                 }
   14237             :         ;
   14238             : 
   14239             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14240         318 :                 { $$ = list_make2($1, $2); }
   14241             :         ;
   14242             : 
   14243             : rowsfrom_list:
   14244         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14245         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14246             :         ;
   14247             : 
   14248          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14249         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14250             :         ;
   14251             : 
   14252         956 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14253       48292 :             | /*EMPTY*/                             { $$ = false; }
   14254             :         ;
   14255             : 
   14256             : 
   14257             : where_clause:
   14258      221314 :             WHERE a_expr                            { $$ = $2; }
   14259      295724 :             | /*EMPTY*/                             { $$ = NULL; }
   14260             :         ;
   14261             : 
   14262             : /* variant for UPDATE and DELETE */
   14263             : where_or_current_clause:
   14264       14270 :             WHERE a_expr                            { $$ = $2; }
   14265             :             | WHERE CURRENT_P OF cursor_name
   14266             :                 {
   14267         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14268             : 
   14269             :                     /* cvarno is filled in by parse analysis */
   14270         266 :                     n->cursor_name = $4;
   14271         266 :                     n->cursor_param = 0;
   14272         266 :                     $$ = (Node *) n;
   14273             :                 }
   14274        5124 :             | /*EMPTY*/                             { $$ = NULL; }
   14275             :         ;
   14276             : 
   14277             : 
   14278             : OptTableFuncElementList:
   14279         716 :             TableFuncElementList                { $$ = $1; }
   14280        3786 :             | /*EMPTY*/                         { $$ = NIL; }
   14281             :         ;
   14282             : 
   14283             : TableFuncElementList:
   14284             :             TableFuncElement
   14285             :                 {
   14286        1530 :                     $$ = list_make1($1);
   14287             :                 }
   14288             :             | TableFuncElementList ',' TableFuncElement
   14289             :                 {
   14290        2064 :                     $$ = lappend($1, $3);
   14291             :                 }
   14292             :         ;
   14293             : 
   14294             : TableFuncElement:   ColId Typename opt_collate_clause
   14295             :                 {
   14296        3658 :                     ColumnDef *n = makeNode(ColumnDef);
   14297             : 
   14298        3658 :                     n->colname = $1;
   14299        3658 :                     n->typeName = $2;
   14300        3658 :                     n->inhcount = 0;
   14301        3658 :                     n->is_local = true;
   14302        3658 :                     n->is_not_null = false;
   14303        3658 :                     n->is_from_type = false;
   14304        3658 :                     n->storage = 0;
   14305        3658 :                     n->raw_default = NULL;
   14306        3658 :                     n->cooked_default = NULL;
   14307        3658 :                     n->collClause = (CollateClause *) $3;
   14308        3658 :                     n->collOid = InvalidOid;
   14309        3658 :                     n->constraints = NIL;
   14310        3658 :                     n->location = @1;
   14311        3658 :                     $$ = (Node *) n;
   14312             :                 }
   14313             :         ;
   14314             : 
   14315             : /*
   14316             :  * XMLTABLE
   14317             :  */
   14318             : xmltable:
   14319             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14320             :                 {
   14321         206 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14322             : 
   14323         206 :                     n->rowexpr = $3;
   14324         206 :                     n->docexpr = $4;
   14325         206 :                     n->columns = $6;
   14326         206 :                     n->namespaces = NIL;
   14327         206 :                     n->location = @1;
   14328         206 :                     $$ = (Node *) n;
   14329             :                 }
   14330             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14331             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14332             :                 {
   14333          20 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14334             : 
   14335          20 :                     n->rowexpr = $8;
   14336          20 :                     n->docexpr = $9;
   14337          20 :                     n->columns = $11;
   14338          20 :                     n->namespaces = $5;
   14339          20 :                     n->location = @1;
   14340          20 :                     $$ = (Node *) n;
   14341             :                 }
   14342             :         ;
   14343             : 
   14344         226 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14345         530 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14346             :         ;
   14347             : 
   14348             : xmltable_column_el:
   14349             :             ColId Typename
   14350             :                 {
   14351         204 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14352             : 
   14353         204 :                     fc->colname = $1;
   14354         204 :                     fc->for_ordinality = false;
   14355         204 :                     fc->typeName = $2;
   14356         204 :                     fc->is_not_null = false;
   14357         204 :                     fc->colexpr = NULL;
   14358         204 :                     fc->coldefexpr = NULL;
   14359         204 :                     fc->location = @1;
   14360             : 
   14361         204 :                     $$ = (Node *) fc;
   14362             :                 }
   14363             :             | ColId Typename xmltable_column_option_list
   14364             :                 {
   14365         490 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14366             :                     ListCell   *option;
   14367         490 :                     bool        nullability_seen = false;
   14368             : 
   14369         490 :                     fc->colname = $1;
   14370         490 :                     fc->typeName = $2;
   14371         490 :                     fc->for_ordinality = false;
   14372         490 :                     fc->is_not_null = false;
   14373         490 :                     fc->colexpr = NULL;
   14374         490 :                     fc->coldefexpr = NULL;
   14375         490 :                     fc->location = @1;
   14376             : 
   14377        1092 :                     foreach(option, $3)
   14378             :                     {
   14379         602 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14380             : 
   14381         602 :                         if (strcmp(defel->defname, "default") == 0)
   14382             :                         {
   14383          56 :                             if (fc->coldefexpr != NULL)
   14384           0 :                                 ereport(ERROR,
   14385             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14386             :                                          errmsg("only one DEFAULT value is allowed"),
   14387             :                                          parser_errposition(defel->location)));
   14388          56 :                             fc->coldefexpr = defel->arg;
   14389             :                         }
   14390         546 :                         else if (strcmp(defel->defname, "path") == 0)
   14391             :                         {
   14392         490 :                             if (fc->colexpr != NULL)
   14393           0 :                                 ereport(ERROR,
   14394             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14395             :                                          errmsg("only one PATH value per column is allowed"),
   14396             :                                          parser_errposition(defel->location)));
   14397         490 :                             fc->colexpr = defel->arg;
   14398             :                         }
   14399          56 :                         else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
   14400             :                         {
   14401          56 :                             if (nullability_seen)
   14402           0 :                                 ereport(ERROR,
   14403             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14404             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14405             :                                          parser_errposition(defel->location)));
   14406          56 :                             fc->is_not_null = boolVal(defel->arg);
   14407          56 :                             nullability_seen = true;
   14408             :                         }
   14409             :                         else
   14410             :                         {
   14411           0 :                             ereport(ERROR,
   14412             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14413             :                                      errmsg("unrecognized column option \"%s\"",
   14414             :                                             defel->defname),
   14415             :                                      parser_errposition(defel->location)));
   14416             :                         }
   14417             :                     }
   14418         490 :                     $$ = (Node *) fc;
   14419             :                 }
   14420             :             | ColId FOR ORDINALITY
   14421             :                 {
   14422          62 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14423             : 
   14424          62 :                     fc->colname = $1;
   14425          62 :                     fc->for_ordinality = true;
   14426             :                     /* other fields are ignored, initialized by makeNode */
   14427          62 :                     fc->location = @1;
   14428             : 
   14429          62 :                     $$ = (Node *) fc;
   14430             :                 }
   14431             :         ;
   14432             : 
   14433             : xmltable_column_option_list:
   14434             :             xmltable_column_option_el
   14435         490 :                 { $$ = list_make1($1); }
   14436             :             | xmltable_column_option_list xmltable_column_option_el
   14437         112 :                 { $$ = lappend($1, $2); }
   14438             :         ;
   14439             : 
   14440             : xmltable_column_option_el:
   14441             :             IDENT b_expr
   14442             :                 {
   14443           6 :                     if (strcmp($1, "__pg__is_not_null") == 0)
   14444           6 :                         ereport(ERROR,
   14445             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14446             :                                  errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
   14447             :                                  parser_errposition(@1)));
   14448           0 :                     $$ = makeDefElem($1, $2, @1);
   14449             :                 }
   14450             :             | DEFAULT b_expr
   14451          56 :                 { $$ = makeDefElem("default", $2, @1); }
   14452             :             | NOT NULL_P
   14453          56 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
   14454             :             | NULL_P
   14455           0 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
   14456             :             | PATH b_expr
   14457         490 :                 { $$ = makeDefElem("path", $2, @1); }
   14458             :         ;
   14459             : 
   14460             : xml_namespace_list:
   14461             :             xml_namespace_el
   14462          20 :                 { $$ = list_make1($1); }
   14463             :             | xml_namespace_list ',' xml_namespace_el
   14464           0 :                 { $$ = lappend($1, $3); }
   14465             :         ;
   14466             : 
   14467             : xml_namespace_el:
   14468             :             b_expr AS ColLabel
   14469             :                 {
   14470          14 :                     $$ = makeNode(ResTarget);
   14471          14 :                     $$->name = $3;
   14472          14 :                     $$->indirection = NIL;
   14473          14 :                     $$->val = $1;
   14474          14 :                     $$->location = @1;
   14475             :                 }
   14476             :             | DEFAULT b_expr
   14477             :                 {
   14478           6 :                     $$ = makeNode(ResTarget);
   14479           6 :                     $$->name = NULL;
   14480           6 :                     $$->indirection = NIL;
   14481           6 :                     $$->val = $2;
   14482           6 :                     $$->location = @1;
   14483             :                 }
   14484             :         ;
   14485             : 
   14486             : json_table:
   14487             :             JSON_TABLE '('
   14488             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14489             :                 json_passing_clause_opt
   14490             :                 COLUMNS '(' json_table_column_definition_list ')'
   14491             :                 json_on_error_clause_opt
   14492             :             ')'
   14493             :                 {
   14494         536 :                     JsonTable *n = makeNode(JsonTable);
   14495             :                     char      *pathstring;
   14496             : 
   14497         536 :                     n->context_item = (JsonValueExpr *) $3;
   14498         536 :                     if (!IsA($5, A_Const) ||
   14499         530 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14500           6 :                         ereport(ERROR,
   14501             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14502             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14503             :                                 parser_errposition(@5));
   14504         530 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14505         530 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14506         530 :                     n->passing = $7;
   14507         530 :                     n->columns = $10;
   14508         530 :                     n->on_error = (JsonBehavior *) $12;
   14509         530 :                     n->location = @1;
   14510         530 :                     $$ = (Node *) n;
   14511             :                 }
   14512             :         ;
   14513             : 
   14514             : json_table_path_name_opt:
   14515          62 :             AS name         { $$ = $2; }
   14516         486 :             | /* empty */   { $$ = NULL; }
   14517             :         ;
   14518             : 
   14519             : json_table_column_definition_list:
   14520             :             json_table_column_definition
   14521         826 :                 { $$ = list_make1($1); }
   14522             :             | json_table_column_definition_list ',' json_table_column_definition
   14523         528 :                 { $$ = lappend($1, $3); }
   14524             :         ;
   14525             : 
   14526             : json_table_column_definition:
   14527             :             ColId FOR ORDINALITY
   14528             :                 {
   14529          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14530             : 
   14531          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14532          84 :                     n->name = $1;
   14533          84 :                     n->location = @1;
   14534          84 :                     $$ = (Node *) n;
   14535             :                 }
   14536             :             | ColId Typename
   14537             :                 json_table_column_path_clause_opt
   14538             :                 json_wrapper_behavior
   14539             :                 json_quotes_clause_opt
   14540             :                 json_behavior_clause_opt
   14541             :                 {
   14542         734 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14543             : 
   14544         734 :                     n->coltype = JTC_REGULAR;
   14545         734 :                     n->name = $1;
   14546         734 :                     n->typeName = $2;
   14547         734 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14548         734 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14549         734 :                     n->wrapper = $4;
   14550         734 :                     n->quotes = $5;
   14551         734 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14552         734 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14553         734 :                     n->location = @1;
   14554         734 :                     $$ = (Node *) n;
   14555             :                 }
   14556             :             | ColId Typename json_format_clause
   14557             :                 json_table_column_path_clause_opt
   14558             :                 json_wrapper_behavior
   14559             :                 json_quotes_clause_opt
   14560             :                 json_behavior_clause_opt
   14561             :                 {
   14562         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14563             : 
   14564         108 :                     n->coltype = JTC_FORMATTED;
   14565         108 :                     n->name = $1;
   14566         108 :                     n->typeName = $2;
   14567         108 :                     n->format = (JsonFormat *) $3;
   14568         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14569         108 :                     n->wrapper = $5;
   14570         108 :                     n->quotes = $6;
   14571         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14572         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14573         108 :                     n->location = @1;
   14574         108 :                     $$ = (Node *) n;
   14575             :                 }
   14576             :             | ColId Typename
   14577             :                 EXISTS json_table_column_path_clause_opt
   14578             :                 json_on_error_clause_opt
   14579             :                 {
   14580         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14581             : 
   14582         138 :                     n->coltype = JTC_EXISTS;
   14583         138 :                     n->name = $1;
   14584         138 :                     n->typeName = $2;
   14585         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14586         138 :                     n->wrapper = JSW_NONE;
   14587         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14588         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14589         138 :                     n->on_empty = NULL;
   14590         138 :                     n->on_error = (JsonBehavior *) $5;
   14591         138 :                     n->location = @1;
   14592         138 :                     $$ = (Node *) n;
   14593             :                 }
   14594             :             | NESTED path_opt Sconst
   14595             :                 COLUMNS '(' json_table_column_definition_list ')'
   14596             :                 {
   14597         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14598             : 
   14599         144 :                     n->coltype = JTC_NESTED;
   14600         288 :                     n->pathspec = (JsonTablePathSpec *)
   14601         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14602         144 :                     n->columns = $6;
   14603         144 :                     n->location = @1;
   14604         144 :                     $$ = (Node *) n;
   14605             :                 }
   14606             :             | NESTED path_opt Sconst AS name
   14607             :                 COLUMNS '(' json_table_column_definition_list ')'
   14608             :                 {
   14609         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14610             : 
   14611         146 :                     n->coltype = JTC_NESTED;
   14612         292 :                     n->pathspec = (JsonTablePathSpec *)
   14613         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14614         146 :                     n->columns = $8;
   14615         146 :                     n->location = @1;
   14616         146 :                     $$ = (Node *) n;
   14617             :                 }
   14618             :         ;
   14619             : 
   14620             : path_opt:
   14621             :             PATH
   14622             :             | /* EMPTY */
   14623             :         ;
   14624             : 
   14625             : json_table_column_path_clause_opt:
   14626             :             PATH Sconst
   14627         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14628             :             | /* EMPTY */
   14629         158 :                 { $$ = NULL; }
   14630             :         ;
   14631             : 
   14632             : /*****************************************************************************
   14633             :  *
   14634             :  *  Type syntax
   14635             :  *      SQL introduces a large amount of type-specific syntax.
   14636             :  *      Define individual clauses to handle these cases, and use
   14637             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14638             :  *      - thomas 1997-10-10
   14639             :  *
   14640             :  *****************************************************************************/
   14641             : 
   14642             : Typename:   SimpleTypename opt_array_bounds
   14643             :                 {
   14644      529014 :                     $$ = $1;
   14645      529014 :                     $$->arrayBounds = $2;
   14646             :                 }
   14647             :             | SETOF SimpleTypename opt_array_bounds
   14648             :                 {
   14649        2434 :                     $$ = $2;
   14650        2434 :                     $$->arrayBounds = $3;
   14651        2434 :                     $$->setof = true;
   14652             :                 }
   14653             :             /* SQL standard syntax, currently only one-dimensional */
   14654             :             | SimpleTypename ARRAY '[' Iconst ']'
   14655             :                 {
   14656           6 :                     $$ = $1;
   14657           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14658             :                 }
   14659             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14660             :                 {
   14661           0 :                     $$ = $2;
   14662           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14663           0 :                     $$->setof = true;
   14664             :                 }
   14665             :             | SimpleTypename ARRAY
   14666             :                 {
   14667           0 :                     $$ = $1;
   14668           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14669             :                 }
   14670             :             | SETOF SimpleTypename ARRAY
   14671             :                 {
   14672           0 :                     $$ = $2;
   14673           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14674           0 :                     $$->setof = true;
   14675             :                 }
   14676             :         ;
   14677             : 
   14678             : opt_array_bounds:
   14679             :             opt_array_bounds '[' ']'
   14680       14846 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14681             :             | opt_array_bounds '[' Iconst ']'
   14682          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14683             :             | /*EMPTY*/
   14684      531448 :                     {  $$ = NIL; }
   14685             :         ;
   14686             : 
   14687             : SimpleTypename:
   14688      414962 :             GenericType                             { $$ = $1; }
   14689      100652 :             | Numeric                               { $$ = $1; }
   14690        1974 :             | Bit                                   { $$ = $1; }
   14691        3270 :             | Character                             { $$ = $1; }
   14692        5276 :             | ConstDatetime                         { $$ = $1; }
   14693             :             | ConstInterval opt_interval
   14694             :                 {
   14695        3824 :                     $$ = $1;
   14696        3824 :                     $$->typmods = $2;
   14697             :                 }
   14698             :             | ConstInterval '(' Iconst ')'
   14699             :                 {
   14700           0 :                     $$ = $1;
   14701           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14702             :                                              makeIntConst($3, @3));
   14703             :                 }
   14704        1904 :             | JsonType                              { $$ = $1; }
   14705             :         ;
   14706             : 
   14707             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14708             :  * types such as CHAR() and BIT() to an unspecified length.
   14709             :  * SQL9x requires that these default to a length of one, but this
   14710             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14711             :  * where there is an obvious better choice to make.
   14712             :  * Note that ConstInterval is not included here since it must
   14713             :  * be pushed up higher in the rules to accommodate the postfix
   14714             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14715             :  * the generic-type-name case in AexprConst to avoid premature
   14716             :  * reduce/reduce conflicts against function names.
   14717             :  */
   14718             : ConstTypename:
   14719          78 :             Numeric                                 { $$ = $1; }
   14720           0 :             | ConstBit                              { $$ = $1; }
   14721          34 :             | ConstCharacter                        { $$ = $1; }
   14722        2800 :             | ConstDatetime                         { $$ = $1; }
   14723         264 :             | JsonType                              { $$ = $1; }
   14724             :         ;
   14725             : 
   14726             : /*
   14727             :  * GenericType covers all type names that don't have special syntax mandated
   14728             :  * by the standard, including qualified names.  We also allow type modifiers.
   14729             :  * To avoid parsing conflicts against function invocations, the modifiers
   14730             :  * have to be shown as expr_list here, but parse analysis will only accept
   14731             :  * constants for them.
   14732             :  */
   14733             : GenericType:
   14734             :             type_function_name opt_type_modifiers
   14735             :                 {
   14736      296836 :                     $$ = makeTypeName($1);
   14737      296836 :                     $$->typmods = $2;
   14738      296836 :                     $$->location = @1;
   14739             :                 }
   14740             :             | type_function_name attrs opt_type_modifiers
   14741             :                 {
   14742      118126 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14743      118126 :                     $$->typmods = $3;
   14744      118126 :                     $$->location = @1;
   14745             :                 }
   14746             :         ;
   14747             : 
   14748        1350 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14749      419868 :                     | /* EMPTY */                   { $$ = NIL; }
   14750             :         ;
   14751             : 
   14752             : /*
   14753             :  * SQL numeric data types
   14754             :  */
   14755             : Numeric:    INT_P
   14756             :                 {
   14757       40220 :                     $$ = SystemTypeName("int4");
   14758       40220 :                     $$->location = @1;
   14759             :                 }
   14760             :             | INTEGER
   14761             :                 {
   14762       25954 :                     $$ = SystemTypeName("int4");
   14763       25954 :                     $$->location = @1;
   14764             :                 }
   14765             :             | SMALLINT
   14766             :                 {
   14767        1196 :                     $$ = SystemTypeName("int2");
   14768        1196 :                     $$->location = @1;
   14769             :                 }
   14770             :             | BIGINT
   14771             :                 {
   14772        5284 :                     $$ = SystemTypeName("int8");
   14773        5284 :                     $$->location = @1;
   14774             :                 }
   14775             :             | REAL
   14776             :                 {
   14777        7500 :                     $$ = SystemTypeName("float4");
   14778        7500 :                     $$->location = @1;
   14779             :                 }
   14780             :             | FLOAT_P opt_float
   14781             :                 {
   14782         538 :                     $$ = $2;
   14783         538 :                     $$->location = @1;
   14784             :                 }
   14785             :             | DOUBLE_P PRECISION
   14786             :                 {
   14787         768 :                     $$ = SystemTypeName("float8");
   14788         768 :                     $$->location = @1;
   14789             :                 }
   14790             :             | DECIMAL_P opt_type_modifiers
   14791             :                 {
   14792          36 :                     $$ = SystemTypeName("numeric");
   14793          36 :                     $$->typmods = $2;
   14794          36 :                     $$->location = @1;
   14795             :                 }
   14796             :             | DEC opt_type_modifiers
   14797             :                 {
   14798           0 :                     $$ = SystemTypeName("numeric");
   14799           0 :                     $$->typmods = $2;
   14800           0 :                     $$->location = @1;
   14801             :                 }
   14802             :             | NUMERIC opt_type_modifiers
   14803             :                 {
   14804        6220 :                     $$ = SystemTypeName("numeric");
   14805        6220 :                     $$->typmods = $2;
   14806        6220 :                     $$->location = @1;
   14807             :                 }
   14808             :             | BOOLEAN_P
   14809             :                 {
   14810       13014 :                     $$ = SystemTypeName("bool");
   14811       13014 :                     $$->location = @1;
   14812             :                 }
   14813             :         ;
   14814             : 
   14815             : opt_float:  '(' Iconst ')'
   14816             :                 {
   14817             :                     /*
   14818             :                      * Check FLOAT() precision limits assuming IEEE floating
   14819             :                      * types - thomas 1997-09-18
   14820             :                      */
   14821           2 :                     if ($2 < 1)
   14822           0 :                         ereport(ERROR,
   14823             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14824             :                                  errmsg("precision for type float must be at least 1 bit"),
   14825             :                                  parser_errposition(@2)));
   14826           2 :                     else if ($2 <= 24)
   14827           2 :                         $$ = SystemTypeName("float4");
   14828           0 :                     else if ($2 <= 53)
   14829           0 :                         $$ = SystemTypeName("float8");
   14830             :                     else
   14831           0 :                         ereport(ERROR,
   14832             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14833             :                                  errmsg("precision for type float must be less than 54 bits"),
   14834             :                                  parser_errposition(@2)));
   14835             :                 }
   14836             :             | /*EMPTY*/
   14837             :                 {
   14838         536 :                     $$ = SystemTypeName("float8");
   14839             :                 }
   14840             :         ;
   14841             : 
   14842             : /*
   14843             :  * SQL bit-field data types
   14844             :  * The following implements BIT() and BIT VARYING().
   14845             :  */
   14846             : Bit:        BitWithLength
   14847             :                 {
   14848        1738 :                     $$ = $1;
   14849             :                 }
   14850             :             | BitWithoutLength
   14851             :                 {
   14852         236 :                     $$ = $1;
   14853             :                 }
   14854             :         ;
   14855             : 
   14856             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14857             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14858             : ConstBit:   BitWithLength
   14859             :                 {
   14860           0 :                     $$ = $1;
   14861             :                 }
   14862             :             | BitWithoutLength
   14863             :                 {
   14864           0 :                     $$ = $1;
   14865           0 :                     $$->typmods = NIL;
   14866             :                 }
   14867             :         ;
   14868             : 
   14869             : BitWithLength:
   14870             :             BIT opt_varying '(' expr_list ')'
   14871             :                 {
   14872             :                     char *typname;
   14873             : 
   14874        1738 :                     typname = $2 ? "varbit" : "bit";
   14875        1738 :                     $$ = SystemTypeName(typname);
   14876        1738 :                     $$->typmods = $4;
   14877        1738 :                     $$->location = @1;
   14878             :                 }
   14879             :         ;
   14880             : 
   14881             : BitWithoutLength:
   14882             :             BIT opt_varying
   14883             :                 {
   14884             :                     /* bit defaults to bit(1), varbit to no limit */
   14885         236 :                     if ($2)
   14886             :                     {
   14887          20 :                         $$ = SystemTypeName("varbit");
   14888             :                     }
   14889             :                     else
   14890             :                     {
   14891         216 :                         $$ = SystemTypeName("bit");
   14892         216 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14893             :                     }
   14894         236 :                     $$->location = @1;
   14895             :                 }
   14896             :         ;
   14897             : 
   14898             : 
   14899             : /*
   14900             :  * SQL character data types
   14901             :  * The following implements CHAR() and VARCHAR().
   14902             :  */
   14903             : Character:  CharacterWithLength
   14904             :                 {
   14905        1984 :                     $$ = $1;
   14906             :                 }
   14907             :             | CharacterWithoutLength
   14908             :                 {
   14909        1286 :                     $$ = $1;
   14910             :                 }
   14911             :         ;
   14912             : 
   14913             : ConstCharacter:  CharacterWithLength
   14914             :                 {
   14915          12 :                     $$ = $1;
   14916             :                 }
   14917             :             | CharacterWithoutLength
   14918             :                 {
   14919             :                     /* Length was not specified so allow to be unrestricted.
   14920             :                      * This handles problems with fixed-length (bpchar) strings
   14921             :                      * which in column definitions must default to a length
   14922             :                      * of one, but should not be constrained if the length
   14923             :                      * was not specified.
   14924             :                      */
   14925          22 :                     $$ = $1;
   14926          22 :                     $$->typmods = NIL;
   14927             :                 }
   14928             :         ;
   14929             : 
   14930             : CharacterWithLength:  character '(' Iconst ')'
   14931             :                 {
   14932        1996 :                     $$ = SystemTypeName($1);
   14933        1996 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14934        1996 :                     $$->location = @1;
   14935             :                 }
   14936             :         ;
   14937             : 
   14938             : CharacterWithoutLength:  character
   14939             :                 {
   14940        1308 :                     $$ = SystemTypeName($1);
   14941             :                     /* char defaults to char(1), varchar to no limit */
   14942        1308 :                     if (strcmp($1, "bpchar") == 0)
   14943         250 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14944        1308 :                     $$->location = @1;
   14945             :                 }
   14946             :         ;
   14947             : 
   14948             : character:  CHARACTER opt_varying
   14949         564 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14950             :             | CHAR_P opt_varying
   14951        1172 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14952             :             | VARCHAR
   14953        1564 :                                         { $$ = "varchar"; }
   14954             :             | NATIONAL CHARACTER opt_varying
   14955           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14956             :             | NATIONAL CHAR_P opt_varying
   14957           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14958             :             | NCHAR opt_varying
   14959           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14960             :         ;
   14961             : 
   14962             : opt_varying:
   14963         462 :             VARYING                                 { $$ = true; }
   14964        3252 :             | /*EMPTY*/                             { $$ = false; }
   14965             :         ;
   14966             : 
   14967             : /*
   14968             :  * SQL date/time types
   14969             :  */
   14970             : ConstDatetime:
   14971             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14972             :                 {
   14973         136 :                     if ($5)
   14974         112 :                         $$ = SystemTypeName("timestamptz");
   14975             :                     else
   14976          24 :                         $$ = SystemTypeName("timestamp");
   14977         136 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14978         136 :                     $$->location = @1;
   14979             :                 }
   14980             :             | TIMESTAMP opt_timezone
   14981             :                 {
   14982        5392 :                     if ($2)
   14983        1434 :                         $$ = SystemTypeName("timestamptz");
   14984             :                     else
   14985        3958 :                         $$ = SystemTypeName("timestamp");
   14986        5392 :                     $$->location = @1;
   14987             :                 }
   14988             :             | TIME '(' Iconst ')' opt_timezone
   14989             :                 {
   14990          22 :                     if ($5)
   14991           8 :                         $$ = SystemTypeName("timetz");
   14992             :                     else
   14993          14 :                         $$ = SystemTypeName("time");
   14994          22 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14995          22 :                     $$->location = @1;
   14996             :                 }
   14997             :             | TIME opt_timezone
   14998             :                 {
   14999        2526 :                     if ($2)
   15000         342 :                         $$ = SystemTypeName("timetz");
   15001             :                     else
   15002        2184 :                         $$ = SystemTypeName("time");
   15003        2526 :                     $$->location = @1;
   15004             :                 }
   15005             :         ;
   15006             : 
   15007             : ConstInterval:
   15008             :             INTERVAL
   15009             :                 {
   15010        7134 :                     $$ = SystemTypeName("interval");
   15011        7134 :                     $$->location = @1;
   15012             :                 }
   15013             :         ;
   15014             : 
   15015             : opt_timezone:
   15016        1896 :             WITH_LA TIME ZONE                       { $$ = true; }
   15017         576 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   15018        5604 :             | /*EMPTY*/                             { $$ = false; }
   15019             :         ;
   15020             : 
   15021             : opt_interval:
   15022             :             YEAR_P
   15023          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   15024             :             | MONTH_P
   15025          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   15026             :             | DAY_P
   15027          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   15028             :             | HOUR_P
   15029          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   15030             :             | MINUTE_P
   15031          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   15032             :             | interval_second
   15033          36 :                 { $$ = $1; }
   15034             :             | YEAR_P TO MONTH_P
   15035             :                 {
   15036          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   15037             :                                                  INTERVAL_MASK(MONTH), @1));
   15038             :                 }
   15039             :             | DAY_P TO HOUR_P
   15040             :                 {
   15041          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   15042             :                                                  INTERVAL_MASK(HOUR), @1));
   15043             :                 }
   15044             :             | DAY_P TO MINUTE_P
   15045             :                 {
   15046          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   15047             :                                                  INTERVAL_MASK(HOUR) |
   15048             :                                                  INTERVAL_MASK(MINUTE), @1));
   15049             :                 }
   15050             :             | DAY_P TO interval_second
   15051             :                 {
   15052          48 :                     $$ = $3;
   15053          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   15054             :                                                 INTERVAL_MASK(HOUR) |
   15055             :                                                 INTERVAL_MASK(MINUTE) |
   15056          48 :                                                 INTERVAL_MASK(SECOND), @1);
   15057             :                 }
   15058             :             | HOUR_P TO MINUTE_P
   15059             :                 {
   15060          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   15061             :                                                  INTERVAL_MASK(MINUTE), @1));
   15062             :                 }
   15063             :             | HOUR_P TO interval_second
   15064             :                 {
   15065          36 :                     $$ = $3;
   15066          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   15067             :                                                 INTERVAL_MASK(MINUTE) |
   15068          36 :                                                 INTERVAL_MASK(SECOND), @1);
   15069             :                 }
   15070             :             | MINUTE_P TO interval_second
   15071             :                 {
   15072          66 :                     $$ = $3;
   15073          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   15074          66 :                                                 INTERVAL_MASK(SECOND), @1);
   15075             :                 }
   15076             :             | /*EMPTY*/
   15077        6780 :                 { $$ = NIL; }
   15078             :         ;
   15079             : 
   15080             : interval_second:
   15081             :             SECOND_P
   15082             :                 {
   15083         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   15084             :                 }
   15085             :             | SECOND_P '(' Iconst ')'
   15086             :                 {
   15087          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   15088             :                                     makeIntConst($3, @3));
   15089             :                 }
   15090             :         ;
   15091             : 
   15092             : JsonType:
   15093             :             JSON
   15094             :                 {
   15095        2168 :                     $$ = SystemTypeName("json");
   15096        2168 :                     $$->location = @1;
   15097             :                 }
   15098             :         ;
   15099             : 
   15100             : /*****************************************************************************
   15101             :  *
   15102             :  *  expression grammar
   15103             :  *
   15104             :  *****************************************************************************/
   15105             : 
   15106             : /*
   15107             :  * General expressions
   15108             :  * This is the heart of the expression syntax.
   15109             :  *
   15110             :  * We have two expression types: a_expr is the unrestricted kind, and
   15111             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   15112             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   15113             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   15114             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   15115             :  *
   15116             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   15117             :  * always be used by surrounding it with parens.
   15118             :  *
   15119             :  * c_expr is all the productions that are common to a_expr and b_expr;
   15120             :  * it's factored out just to eliminate redundant coding.
   15121             :  *
   15122             :  * Be careful of productions involving more than one terminal token.
   15123             :  * By default, bison will assign such productions the precedence of their
   15124             :  * last terminal, but in nearly all cases you want it to be the precedence
   15125             :  * of the first terminal instead; otherwise you will not get the behavior
   15126             :  * you expect!  So we use %prec annotations freely to set precedences.
   15127             :  */
   15128     3769588 : a_expr:     c_expr                                  { $$ = $1; }
   15129             :             | a_expr TYPECAST Typename
   15130      240822 :                     { $$ = makeTypeCast($1, $3, @2); }
   15131             :             | a_expr COLLATE any_name
   15132             :                 {
   15133        9492 :                     CollateClause *n = makeNode(CollateClause);
   15134             : 
   15135        9492 :                     n->arg = $1;
   15136        9492 :                     n->collname = $3;
   15137        9492 :                     n->location = @2;
   15138        9492 :                     $$ = (Node *) n;
   15139             :                 }
   15140             :             | a_expr AT TIME ZONE a_expr            %prec AT
   15141             :                 {
   15142         408 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15143         408 :                                                list_make2($5, $1),
   15144             :                                                COERCE_SQL_SYNTAX,
   15145         408 :                                                @2);
   15146             :                 }
   15147             :             | a_expr AT LOCAL                       %prec AT
   15148             :                 {
   15149          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15150          42 :                                                list_make1($1),
   15151             :                                                COERCE_SQL_SYNTAX,
   15152             :                                                -1);
   15153             :                 }
   15154             :         /*
   15155             :          * These operators must be called out explicitly in order to make use
   15156             :          * of bison's automatic operator-precedence handling.  All other
   15157             :          * operator names are handled by the generic productions using "Op",
   15158             :          * below; and all those operators will have the same precedence.
   15159             :          *
   15160             :          * If you add more explicitly-known operators, be sure to add them
   15161             :          * also to b_expr and to the MathOp list below.
   15162             :          */
   15163             :             | '+' a_expr                    %prec UMINUS
   15164          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15165             :             | '-' a_expr                    %prec UMINUS
   15166        9328 :                 { $$ = doNegate($2, @1); }
   15167             :             | a_expr '+' a_expr
   15168       15068 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15169             :             | a_expr '-' a_expr
   15170        4556 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15171             :             | a_expr '*' a_expr
   15172        6446 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15173             :             | a_expr '/' a_expr
   15174        3482 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15175             :             | a_expr '%' a_expr
   15176        3414 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15177             :             | a_expr '^' a_expr
   15178         478 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15179             :             | a_expr '<' a_expr
   15180       10702 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15181             :             | a_expr '>' a_expr
   15182       17052 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15183             :             | a_expr '=' a_expr
   15184      397142 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15185             :             | a_expr LESS_EQUALS a_expr
   15186        5594 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15187             :             | a_expr GREATER_EQUALS a_expr
   15188       12744 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15189             :             | a_expr NOT_EQUALS a_expr
   15190       40204 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15191             : 
   15192             :             | a_expr qual_Op a_expr             %prec Op
   15193       60290 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15194             :             | qual_Op a_expr                    %prec Op
   15195         246 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15196             : 
   15197             :             | a_expr AND a_expr
   15198      236534 :                 { $$ = makeAndExpr($1, $3, @2); }
   15199             :             | a_expr OR a_expr
   15200       16336 :                 { $$ = makeOrExpr($1, $3, @2); }
   15201             :             | NOT a_expr
   15202       16402 :                 { $$ = makeNotExpr($2, @1); }
   15203             :             | NOT_LA a_expr                     %prec NOT
   15204           0 :                 { $$ = makeNotExpr($2, @1); }
   15205             : 
   15206             :             | a_expr LIKE a_expr
   15207             :                 {
   15208        1970 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15209        1970 :                                                    $1, $3, @2);
   15210             :                 }
   15211             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15212             :                 {
   15213          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15214          96 :                                                  list_make2($3, $5),
   15215             :                                                  COERCE_EXPLICIT_CALL,
   15216          96 :                                                  @2);
   15217          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15218          96 :                                                    $1, (Node *) n, @2);
   15219             :                 }
   15220             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15221             :                 {
   15222         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15223         198 :                                                    $1, $4, @2);
   15224             :                 }
   15225             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15226             :                 {
   15227          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15228          96 :                                                  list_make2($4, $6),
   15229             :                                                  COERCE_EXPLICIT_CALL,
   15230          96 :                                                  @2);
   15231          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15232          96 :                                                    $1, (Node *) n, @2);
   15233             :                 }
   15234             :             | a_expr ILIKE a_expr
   15235             :                 {
   15236         172 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15237         172 :                                                    $1, $3, @2);
   15238             :                 }
   15239             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15240             :                 {
   15241           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15242           0 :                                                  list_make2($3, $5),
   15243             :                                                  COERCE_EXPLICIT_CALL,
   15244           0 :                                                  @2);
   15245           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15246           0 :                                                    $1, (Node *) n, @2);
   15247             :                 }
   15248             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15249             :                 {
   15250          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15251          30 :                                                    $1, $4, @2);
   15252             :                 }
   15253             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15254             :                 {
   15255           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15256           0 :                                                  list_make2($4, $6),
   15257             :                                                  COERCE_EXPLICIT_CALL,
   15258           0 :                                                  @2);
   15259           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15260           0 :                                                    $1, (Node *) n, @2);
   15261             :                 }
   15262             : 
   15263             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15264             :                 {
   15265          88 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15266          88 :                                                  list_make1($4),
   15267             :                                                  COERCE_EXPLICIT_CALL,
   15268          88 :                                                  @2);
   15269          88 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15270          88 :                                                    $1, (Node *) n, @2);
   15271             :                 }
   15272             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15273             :                 {
   15274          36 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15275          36 :                                                  list_make2($4, $6),
   15276             :                                                  COERCE_EXPLICIT_CALL,
   15277          36 :                                                  @2);
   15278          36 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15279          36 :                                                    $1, (Node *) n, @2);
   15280             :                 }
   15281             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15282             :                 {
   15283           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15284           0 :                                                  list_make1($5),
   15285             :                                                  COERCE_EXPLICIT_CALL,
   15286           0 :                                                  @2);
   15287           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15288           0 :                                                    $1, (Node *) n, @2);
   15289             :                 }
   15290             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15291             :                 {
   15292           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15293           0 :                                                  list_make2($5, $7),
   15294             :                                                  COERCE_EXPLICIT_CALL,
   15295           0 :                                                  @2);
   15296           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15297           0 :                                                    $1, (Node *) n, @2);
   15298             :                 }
   15299             : 
   15300             :             /* NullTest clause
   15301             :              * Define SQL-style Null test clause.
   15302             :              * Allow two forms described in the standard:
   15303             :              *  a IS NULL
   15304             :              *  a IS NOT NULL
   15305             :              * Allow two SQL extensions
   15306             :              *  a ISNULL
   15307             :              *  a NOTNULL
   15308             :              */
   15309             :             | a_expr IS NULL_P                          %prec IS
   15310             :                 {
   15311        5428 :                     NullTest   *n = makeNode(NullTest);
   15312             : 
   15313        5428 :                     n->arg = (Expr *) $1;
   15314        5428 :                     n->nulltesttype = IS_NULL;
   15315        5428 :                     n->location = @2;
   15316        5428 :                     $$ = (Node *) n;
   15317             :                 }
   15318             :             | a_expr ISNULL
   15319             :                 {
   15320          96 :                     NullTest   *n = makeNode(NullTest);
   15321             : 
   15322          96 :                     n->arg = (Expr *) $1;
   15323          96 :                     n->nulltesttype = IS_NULL;
   15324          96 :                     n->location = @2;
   15325          96 :                     $$ = (Node *) n;
   15326             :                 }
   15327             :             | a_expr IS NOT NULL_P                      %prec IS
   15328             :                 {
   15329       13254 :                     NullTest   *n = makeNode(NullTest);
   15330             : 
   15331       13254 :                     n->arg = (Expr *) $1;
   15332       13254 :                     n->nulltesttype = IS_NOT_NULL;
   15333       13254 :                     n->location = @2;
   15334       13254 :                     $$ = (Node *) n;
   15335             :                 }
   15336             :             | a_expr NOTNULL
   15337             :                 {
   15338           6 :                     NullTest   *n = makeNode(NullTest);
   15339             : 
   15340           6 :                     n->arg = (Expr *) $1;
   15341           6 :                     n->nulltesttype = IS_NOT_NULL;
   15342           6 :                     n->location = @2;
   15343           6 :                     $$ = (Node *) n;
   15344             :                 }
   15345             :             | row OVERLAPS row
   15346             :                 {
   15347         984 :                     if (list_length($1) != 2)
   15348           0 :                         ereport(ERROR,
   15349             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15350             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15351             :                                  parser_errposition(@1)));
   15352         984 :                     if (list_length($3) != 2)
   15353           0 :                         ereport(ERROR,
   15354             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15355             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15356             :                                  parser_errposition(@3)));
   15357         984 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15358         984 :                                                list_concat($1, $3),
   15359             :                                                COERCE_SQL_SYNTAX,
   15360         984 :                                                @2);
   15361             :                 }
   15362             :             | a_expr IS TRUE_P                          %prec IS
   15363             :                 {
   15364         456 :                     BooleanTest *b = makeNode(BooleanTest);
   15365             : 
   15366         456 :                     b->arg = (Expr *) $1;
   15367         456 :                     b->booltesttype = IS_TRUE;
   15368         456 :                     b->location = @2;
   15369         456 :                     $$ = (Node *) b;
   15370             :                 }
   15371             :             | a_expr IS NOT TRUE_P                      %prec IS
   15372             :                 {
   15373         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15374             : 
   15375         140 :                     b->arg = (Expr *) $1;
   15376         140 :                     b->booltesttype = IS_NOT_TRUE;
   15377         140 :                     b->location = @2;
   15378         140 :                     $$ = (Node *) b;
   15379             :                 }
   15380             :             | a_expr IS FALSE_P                         %prec IS
   15381             :                 {
   15382         158 :                     BooleanTest *b = makeNode(BooleanTest);
   15383             : 
   15384         158 :                     b->arg = (Expr *) $1;
   15385         158 :                     b->booltesttype = IS_FALSE;
   15386         158 :                     b->location = @2;
   15387         158 :                     $$ = (Node *) b;
   15388             :                 }
   15389             :             | a_expr IS NOT FALSE_P                     %prec IS
   15390             :                 {
   15391          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15392             : 
   15393          92 :                     b->arg = (Expr *) $1;
   15394          92 :                     b->booltesttype = IS_NOT_FALSE;
   15395          92 :                     b->location = @2;
   15396          92 :                     $$ = (Node *) b;
   15397             :                 }
   15398             :             | a_expr IS UNKNOWN                         %prec IS
   15399             :                 {
   15400          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15401             : 
   15402          52 :                     b->arg = (Expr *) $1;
   15403          52 :                     b->booltesttype = IS_UNKNOWN;
   15404          52 :                     b->location = @2;
   15405          52 :                     $$ = (Node *) b;
   15406             :                 }
   15407             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15408             :                 {
   15409          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15410             : 
   15411          48 :                     b->arg = (Expr *) $1;
   15412          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15413          48 :                     b->location = @2;
   15414          48 :                     $$ = (Node *) b;
   15415             :                 }
   15416             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15417             :                 {
   15418        1100 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15419             :                 }
   15420             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15421             :                 {
   15422          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15423             :                 }
   15424             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15425             :                 {
   15426         470 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15427             :                                                    "BETWEEN",
   15428         470 :                                                    $1,
   15429         470 :                                                    (Node *) list_make2($4, $6),
   15430         470 :                                                    @2);
   15431             :                 }
   15432             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15433             :                 {
   15434          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15435             :                                                    "NOT BETWEEN",
   15436          12 :                                                    $1,
   15437          12 :                                                    (Node *) list_make2($5, $7),
   15438          12 :                                                    @2);
   15439             :                 }
   15440             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15441             :                 {
   15442          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15443             :                                                    "BETWEEN SYMMETRIC",
   15444          12 :                                                    $1,
   15445          12 :                                                    (Node *) list_make2($4, $6),
   15446          12 :                                                    @2);
   15447             :                 }
   15448             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15449             :                 {
   15450          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15451             :                                                    "NOT BETWEEN SYMMETRIC",
   15452          12 :                                                    $1,
   15453          12 :                                                    (Node *) list_make2($5, $7),
   15454          12 :                                                    @2);
   15455             :                 }
   15456             :             | a_expr IN_P select_with_parens
   15457             :                 {
   15458             :                     /* generate foo = ANY (subquery) */
   15459        5726 :                     SubLink    *n = makeNode(SubLink);
   15460             : 
   15461        5726 :                     n->subselect = $3;
   15462        5726 :                     n->subLinkType = ANY_SUBLINK;
   15463        5726 :                     n->subLinkId = 0;
   15464        5726 :                     n->testexpr = $1;
   15465        5726 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15466        5726 :                     n->location = @2;
   15467        5726 :                     $$ = (Node *) n;
   15468             :                 }
   15469             :             | a_expr IN_P '(' expr_list ')'
   15470             :                 {
   15471             :                     /* generate scalar IN expression */
   15472       19654 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
   15473             : 
   15474       19654 :                     n->rexpr_list_start = @3;
   15475       19654 :                     n->rexpr_list_end = @5;
   15476       19654 :                     $$ = (Node *) n;
   15477             :                 }
   15478             :             | a_expr NOT_LA IN_P select_with_parens         %prec NOT_LA
   15479             :                 {
   15480             :                     /* generate NOT (foo = ANY (subquery)) */
   15481         120 :                     SubLink    *n = makeNode(SubLink);
   15482             : 
   15483         120 :                     n->subselect = $4;
   15484         120 :                     n->subLinkType = ANY_SUBLINK;
   15485         120 :                     n->subLinkId = 0;
   15486         120 :                     n->testexpr = $1;
   15487         120 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15488         120 :                     n->location = @2;
   15489             :                     /* Stick a NOT on top; must have same parse location */
   15490         120 :                     $$ = makeNotExpr((Node *) n, @2);
   15491             :                 }
   15492             :             | a_expr NOT_LA IN_P '(' expr_list ')'
   15493             :                 {
   15494             :                     /* generate scalar NOT IN expression */
   15495        2790 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
   15496             : 
   15497        2790 :                     n->rexpr_list_start = @4;
   15498        2790 :                     n->rexpr_list_end = @6;
   15499        2790 :                     $$ = (Node *) n;
   15500             :                 }
   15501             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15502             :                 {
   15503         180 :                     SubLink    *n = makeNode(SubLink);
   15504             : 
   15505         180 :                     n->subLinkType = $3;
   15506         180 :                     n->subLinkId = 0;
   15507         180 :                     n->testexpr = $1;
   15508         180 :                     n->operName = $2;
   15509         180 :                     n->subselect = $4;
   15510         180 :                     n->location = @2;
   15511         180 :                     $$ = (Node *) n;
   15512             :                 }
   15513             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15514             :                 {
   15515       17192 :                     if ($3 == ANY_SUBLINK)
   15516       16892 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15517             :                     else
   15518         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15519             :                 }
   15520             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15521             :                 {
   15522             :                     /* Not sure how to get rid of the parentheses
   15523             :                      * but there are lots of shift/reduce errors without them.
   15524             :                      *
   15525             :                      * Should be able to implement this by plopping the entire
   15526             :                      * select into a node, then transforming the target expressions
   15527             :                      * from whatever they are into count(*), and testing the
   15528             :                      * entire result equal to one.
   15529             :                      * But, will probably implement a separate node in the executor.
   15530             :                      */
   15531           0 :                     ereport(ERROR,
   15532             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15533             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15534             :                              parser_errposition(@1)));
   15535             :                 }
   15536             :             | a_expr IS DOCUMENT_P                  %prec IS
   15537             :                 {
   15538          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15539          18 :                                      list_make1($1), @2);
   15540             :                 }
   15541             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15542             :                 {
   15543          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15544          18 :                                                  list_make1($1), @2),
   15545          18 :                                      @2);
   15546             :                 }
   15547             :             | a_expr IS NORMALIZED                              %prec IS
   15548             :                 {
   15549          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15550          12 :                                                list_make1($1),
   15551             :                                                COERCE_SQL_SYNTAX,
   15552          12 :                                                @2);
   15553             :                 }
   15554             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15555             :                 {
   15556          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15557          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15558             :                                                COERCE_SQL_SYNTAX,
   15559          36 :                                                @2);
   15560             :                 }
   15561             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15562             :                 {
   15563           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15564           0 :                                                            list_make1($1),
   15565             :                                                            COERCE_SQL_SYNTAX,
   15566           0 :                                                            @2),
   15567           0 :                                      @2);
   15568             :                 }
   15569             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15570             :                 {
   15571           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15572           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15573             :                                                            COERCE_SQL_SYNTAX,
   15574           0 :                                                            @2),
   15575           0 :                                      @2);
   15576             :                 }
   15577             :             | a_expr IS json_predicate_type_constraint
   15578             :                     json_key_uniqueness_constraint_opt      %prec IS
   15579             :                 {
   15580         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15581             : 
   15582         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15583             :                 }
   15584             :             /*
   15585             :              * Required by SQL/JSON, but there are conflicts
   15586             :             | a_expr
   15587             :                 json_format_clause
   15588             :                 IS  json_predicate_type_constraint
   15589             :                     json_key_uniqueness_constraint_opt      %prec IS
   15590             :                 {
   15591             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15592             :                 }
   15593             :             */
   15594             :             | a_expr IS NOT
   15595             :                     json_predicate_type_constraint
   15596             :                     json_key_uniqueness_constraint_opt      %prec IS
   15597             :                 {
   15598          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15599             : 
   15600          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15601             :                 }
   15602             :             /*
   15603             :              * Required by SQL/JSON, but there are conflicts
   15604             :             | a_expr
   15605             :                 json_format_clause
   15606             :                 IS NOT
   15607             :                     json_predicate_type_constraint
   15608             :                     json_key_uniqueness_constraint_opt      %prec IS
   15609             :                 {
   15610             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15611             :                 }
   15612             :             */
   15613             :             | DEFAULT
   15614             :                 {
   15615             :                     /*
   15616             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15617             :                      * expressions", but for us, it's easier to allow it in
   15618             :                      * any a_expr and then throw error during parse analysis
   15619             :                      * if it's in an inappropriate context.  This way also
   15620             :                      * lets us say something smarter than "syntax error".
   15621             :                      */
   15622        1556 :                     SetToDefault *n = makeNode(SetToDefault);
   15623             : 
   15624             :                     /* parse analysis will fill in the rest */
   15625        1556 :                     n->location = @1;
   15626        1556 :                     $$ = (Node *) n;
   15627             :                 }
   15628             :         ;
   15629             : 
   15630             : /*
   15631             :  * Restricted expressions
   15632             :  *
   15633             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15634             :  *
   15635             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15636             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15637             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15638             :  */
   15639             : b_expr:     c_expr
   15640        3866 :                 { $$ = $1; }
   15641             :             | b_expr TYPECAST Typename
   15642         212 :                 { $$ = makeTypeCast($1, $3, @2); }
   15643             :             | '+' b_expr                    %prec UMINUS
   15644           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15645             :             | '-' b_expr                    %prec UMINUS
   15646          66 :                 { $$ = doNegate($2, @1); }
   15647             :             | b_expr '+' b_expr
   15648          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15649             :             | b_expr '-' b_expr
   15650          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15651             :             | b_expr '*' b_expr
   15652          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15653             :             | b_expr '/' b_expr
   15654           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15655             :             | b_expr '%' b_expr
   15656           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15657             :             | b_expr '^' b_expr
   15658           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15659             :             | b_expr '<' b_expr
   15660           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15661             :             | b_expr '>' b_expr
   15662           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15663             :             | b_expr '=' b_expr
   15664           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15665             :             | b_expr LESS_EQUALS b_expr
   15666           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15667             :             | b_expr GREATER_EQUALS b_expr
   15668           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15669             :             | b_expr NOT_EQUALS b_expr
   15670           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15671             :             | b_expr qual_Op b_expr             %prec Op
   15672          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15673             :             | qual_Op b_expr                    %prec Op
   15674           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15675             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15676             :                 {
   15677           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15678             :                 }
   15679             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15680             :                 {
   15681           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15682             :                 }
   15683             :             | b_expr IS DOCUMENT_P                  %prec IS
   15684             :                 {
   15685           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15686           0 :                                      list_make1($1), @2);
   15687             :                 }
   15688             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15689             :                 {
   15690           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15691           0 :                                                  list_make1($1), @2),
   15692           0 :                                      @2);
   15693             :                 }
   15694             :         ;
   15695             : 
   15696             : /*
   15697             :  * Productions that can be used in both a_expr and b_expr.
   15698             :  *
   15699             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15700             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15701             :  * inside parentheses, such as function arguments; that cannot introduce
   15702             :  * ambiguity to the b_expr syntax.
   15703             :  */
   15704     1847722 : c_expr:     columnref                               { $$ = $1; }
   15705     1284384 :             | AexprConst                            { $$ = $1; }
   15706             :             | PARAM opt_indirection
   15707             :                 {
   15708       46906 :                     ParamRef   *p = makeNode(ParamRef);
   15709             : 
   15710       46906 :                     p->number = $1;
   15711       46906 :                     p->location = @1;
   15712       46906 :                     if ($2)
   15713             :                     {
   15714        1096 :                         A_Indirection *n = makeNode(A_Indirection);
   15715             : 
   15716        1096 :                         n->arg = (Node *) p;
   15717        1096 :                         n->indirection = check_indirection($2, yyscanner);
   15718        1096 :                         $$ = (Node *) n;
   15719             :                     }
   15720             :                     else
   15721       45810 :                         $$ = (Node *) p;
   15722             :                 }
   15723             :             | '(' a_expr ')' opt_indirection
   15724             :                 {
   15725       91628 :                     if ($4)
   15726             :                     {
   15727       12650 :                         A_Indirection *n = makeNode(A_Indirection);
   15728             : 
   15729       12650 :                         n->arg = $2;
   15730       12650 :                         n->indirection = check_indirection($4, yyscanner);
   15731       12650 :                         $$ = (Node *) n;
   15732             :                     }
   15733             :                     else
   15734       78978 :                         $$ = $2;
   15735             :                 }
   15736             :             | case_expr
   15737       40216 :                 { $$ = $1; }
   15738             :             | func_expr
   15739      405912 :                 { $$ = $1; }
   15740             :             | select_with_parens            %prec UMINUS
   15741             :                 {
   15742       27964 :                     SubLink    *n = makeNode(SubLink);
   15743             : 
   15744       27964 :                     n->subLinkType = EXPR_SUBLINK;
   15745       27964 :                     n->subLinkId = 0;
   15746       27964 :                     n->testexpr = NULL;
   15747       27964 :                     n->operName = NIL;
   15748       27964 :                     n->subselect = $1;
   15749       27964 :                     n->location = @1;
   15750       27964 :                     $$ = (Node *) n;
   15751             :                 }
   15752             :             | select_with_parens indirection
   15753             :                 {
   15754             :                     /*
   15755             :                      * Because the select_with_parens nonterminal is designed
   15756             :                      * to "eat" as many levels of parens as possible, the
   15757             :                      * '(' a_expr ')' opt_indirection production above will
   15758             :                      * fail to match a sub-SELECT with indirection decoration;
   15759             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15760             :                      * as there are parens around it.  To support applying
   15761             :                      * subscripting or field selection to a sub-SELECT result,
   15762             :                      * we need this redundant-looking production.
   15763             :                      */
   15764          18 :                     SubLink    *n = makeNode(SubLink);
   15765          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15766             : 
   15767          18 :                     n->subLinkType = EXPR_SUBLINK;
   15768          18 :                     n->subLinkId = 0;
   15769          18 :                     n->testexpr = NULL;
   15770          18 :                     n->operName = NIL;
   15771          18 :                     n->subselect = $1;
   15772          18 :                     n->location = @1;
   15773          18 :                     a->arg = (Node *) n;
   15774          18 :                     a->indirection = check_indirection($2, yyscanner);
   15775          18 :                     $$ = (Node *) a;
   15776             :                 }
   15777             :             | EXISTS select_with_parens
   15778             :                 {
   15779        6288 :                     SubLink    *n = makeNode(SubLink);
   15780             : 
   15781        6288 :                     n->subLinkType = EXISTS_SUBLINK;
   15782        6288 :                     n->subLinkId = 0;
   15783        6288 :                     n->testexpr = NULL;
   15784        6288 :                     n->operName = NIL;
   15785        6288 :                     n->subselect = $2;
   15786        6288 :                     n->location = @1;
   15787        6288 :                     $$ = (Node *) n;
   15788             :                 }
   15789             :             | ARRAY select_with_parens
   15790             :                 {
   15791        8602 :                     SubLink    *n = makeNode(SubLink);
   15792             : 
   15793        8602 :                     n->subLinkType = ARRAY_SUBLINK;
   15794        8602 :                     n->subLinkId = 0;
   15795        8602 :                     n->testexpr = NULL;
   15796        8602 :                     n->operName = NIL;
   15797        8602 :                     n->subselect = $2;
   15798        8602 :                     n->location = @1;
   15799        8602 :                     $$ = (Node *) n;
   15800             :                 }
   15801             :             | ARRAY array_expr
   15802             :                 {
   15803        7546 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15804             : 
   15805             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15806        7546 :                     n->location = @1;
   15807        7546 :                     $$ = (Node *) n;
   15808             :                 }
   15809             :             | explicit_row
   15810             :                 {
   15811        3856 :                     RowExpr    *r = makeNode(RowExpr);
   15812             : 
   15813        3856 :                     r->args = $1;
   15814        3856 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15815        3856 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15816        3856 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15817        3856 :                     r->location = @1;
   15818        3856 :                     $$ = (Node *) r;
   15819             :                 }
   15820             :             | implicit_row
   15821             :                 {
   15822        2728 :                     RowExpr    *r = makeNode(RowExpr);
   15823             : 
   15824        2728 :                     r->args = $1;
   15825        2728 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15826        2728 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15827        2728 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15828        2728 :                     r->location = @1;
   15829        2728 :                     $$ = (Node *) r;
   15830             :                 }
   15831             :             | GROUPING '(' expr_list ')'
   15832             :               {
   15833         370 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15834             : 
   15835         370 :                   g->args = $3;
   15836         370 :                   g->location = @1;
   15837         370 :                   $$ = (Node *) g;
   15838             :               }
   15839             :         ;
   15840             : 
   15841             : func_application: func_name '(' ')'
   15842             :                 {
   15843       33732 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15844             :                                                COERCE_EXPLICIT_CALL,
   15845       33732 :                                                @1);
   15846             :                 }
   15847             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15848             :                 {
   15849      324098 :                     FuncCall   *n = makeFuncCall($1, $3,
   15850             :                                                  COERCE_EXPLICIT_CALL,
   15851      324098 :                                                  @1);
   15852             : 
   15853      324098 :                     n->agg_order = $4;
   15854      324098 :                     $$ = (Node *) n;
   15855             :                 }
   15856             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15857             :                 {
   15858         634 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15859             :                                                  COERCE_EXPLICIT_CALL,
   15860         634 :                                                  @1);
   15861             : 
   15862         634 :                     n->func_variadic = true;
   15863         634 :                     n->agg_order = $5;
   15864         634 :                     $$ = (Node *) n;
   15865             :                 }
   15866             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15867             :                 {
   15868         168 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15869             :                                                  COERCE_EXPLICIT_CALL,
   15870         168 :                                                  @1);
   15871             : 
   15872         168 :                     n->func_variadic = true;
   15873         168 :                     n->agg_order = $7;
   15874         168 :                     $$ = (Node *) n;
   15875             :                 }
   15876             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15877             :                 {
   15878           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15879             :                                                  COERCE_EXPLICIT_CALL,
   15880           0 :                                                  @1);
   15881             : 
   15882           0 :                     n->agg_order = $5;
   15883             :                     /* Ideally we'd mark the FuncCall node to indicate
   15884             :                      * "must be an aggregate", but there's no provision
   15885             :                      * for that in FuncCall at the moment.
   15886             :                      */
   15887           0 :                     $$ = (Node *) n;
   15888             :                 }
   15889             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15890             :                 {
   15891         556 :                     FuncCall   *n = makeFuncCall($1, $4,
   15892             :                                                  COERCE_EXPLICIT_CALL,
   15893         556 :                                                  @1);
   15894             : 
   15895         556 :                     n->agg_order = $5;
   15896         556 :                     n->agg_distinct = true;
   15897         556 :                     $$ = (Node *) n;
   15898             :                 }
   15899             :             | func_name '(' '*' ')'
   15900             :                 {
   15901             :                     /*
   15902             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15903             :                      * aggregate.  This does the right thing for COUNT(*),
   15904             :                      * and there are no other aggregates in SQL that accept
   15905             :                      * '*' as parameter.
   15906             :                      *
   15907             :                      * The FuncCall node is also marked agg_star = true,
   15908             :                      * so that later processing can detect what the argument
   15909             :                      * really was.
   15910             :                      */
   15911       18992 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15912             :                                                  COERCE_EXPLICIT_CALL,
   15913       18992 :                                                  @1);
   15914             : 
   15915       18992 :                     n->agg_star = true;
   15916       18992 :                     $$ = (Node *) n;
   15917             :                 }
   15918             :         ;
   15919             : 
   15920             : 
   15921             : /*
   15922             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15923             :  * so that we have classifications for "everything that is a function call or
   15924             :  * looks like one".  This isn't very important, but it saves us having to
   15925             :  * document which variants are legal in places like "FROM function()" or the
   15926             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15927             :  * (Note that many of the special SQL functions wouldn't actually make any
   15928             :  * sense as functional index entries, but we ignore that consideration here.)
   15929             :  */
   15930             : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
   15931             :                 {
   15932      327714 :                     FuncCall   *n = (FuncCall *) $1;
   15933             : 
   15934             :                     /*
   15935             :                      * The order clause for WITHIN GROUP and the one for
   15936             :                      * plain-aggregate ORDER BY share a field, so we have to
   15937             :                      * check here that at most one is present.  We also check
   15938             :                      * for DISTINCT and VARIADIC here to give a better error
   15939             :                      * location.  Other consistency checks are deferred to
   15940             :                      * parse analysis.
   15941             :                      */
   15942      327714 :                     if ($2 != NIL)
   15943             :                     {
   15944         348 :                         if (n->agg_order != NIL)
   15945           6 :                             ereport(ERROR,
   15946             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15947             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15948             :                                      parser_errposition(@2)));
   15949         342 :                         if (n->agg_distinct)
   15950           0 :                             ereport(ERROR,
   15951             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15952             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15953             :                                      parser_errposition(@2)));
   15954         342 :                         if (n->func_variadic)
   15955           0 :                             ereport(ERROR,
   15956             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15957             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15958             :                                      parser_errposition(@2)));
   15959         342 :                         n->agg_order = $2;
   15960         342 :                         n->agg_within_group = true;
   15961             :                     }
   15962      327708 :                     n->agg_filter = $3;
   15963      327708 :                     n->ignore_nulls = $4;
   15964      327708 :                     n->over = $5;
   15965      327708 :                     $$ = (Node *) n;
   15966             :                 }
   15967             :             | json_aggregate_func filter_clause over_clause
   15968             :                 {
   15969         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15970         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15971         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15972             : 
   15973         360 :                     n->agg_filter = $2;
   15974         360 :                     n->over = $3;
   15975         360 :                     $$ = (Node *) $1;
   15976             :                 }
   15977             :             | func_expr_common_subexpr
   15978       77844 :                 { $$ = $1; }
   15979             :         ;
   15980             : 
   15981             : /*
   15982             :  * Like func_expr but does not accept WINDOW functions directly
   15983             :  * (but they can still be contained in arguments for functions etc).
   15984             :  * Use this when window expressions are not allowed, where needed to
   15985             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15986             :  */
   15987             : func_expr_windowless:
   15988       49832 :             func_application                        { $$ = $1; }
   15989         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15990           0 :             | json_aggregate_func                   { $$ = $1; }
   15991             :         ;
   15992             : 
   15993             : /*
   15994             :  * Special expressions that are considered to be functions.
   15995             :  */
   15996             : func_expr_common_subexpr:
   15997             :             COLLATION FOR '(' a_expr ')'
   15998             :                 {
   15999          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   16000          30 :                                                list_make1($4),
   16001             :                                                COERCE_SQL_SYNTAX,
   16002          30 :                                                @1);
   16003             :                 }
   16004             :             | CURRENT_DATE
   16005             :                 {
   16006         312 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   16007             :                 }
   16008             :             | CURRENT_TIME
   16009             :                 {
   16010          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   16011             :                 }
   16012             :             | CURRENT_TIME '(' Iconst ')'
   16013             :                 {
   16014          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   16015             :                 }
   16016             :             | CURRENT_TIMESTAMP
   16017             :                 {
   16018         286 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   16019             :                 }
   16020             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   16021             :                 {
   16022         176 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   16023             :                 }
   16024             :             | LOCALTIME
   16025             :                 {
   16026          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   16027             :                 }
   16028             :             | LOCALTIME '(' Iconst ')'
   16029             :                 {
   16030          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   16031             :                 }
   16032             :             | LOCALTIMESTAMP
   16033             :                 {
   16034          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   16035             :                 }
   16036             :             | LOCALTIMESTAMP '(' Iconst ')'
   16037             :                 {
   16038          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   16039             :                 }
   16040             :             | CURRENT_ROLE
   16041             :                 {
   16042          68 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   16043             :                 }
   16044             :             | CURRENT_USER
   16045             :                 {
   16046        1086 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   16047             :                 }
   16048             :             | SESSION_USER
   16049             :                 {
   16050         570 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   16051             :                 }
   16052             :             | SYSTEM_USER
   16053             :                 {
   16054          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   16055             :                                                NIL,
   16056             :                                                COERCE_SQL_SYNTAX,
   16057             :                                                @1);
   16058             :                 }
   16059             :             | USER
   16060             :                 {
   16061          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   16062             :                 }
   16063             :             | CURRENT_CATALOG
   16064             :                 {
   16065          60 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   16066             :                 }
   16067             :             | CURRENT_SCHEMA
   16068             :                 {
   16069          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   16070             :                 }
   16071             :             | CAST '(' a_expr AS Typename ')'
   16072       63758 :                 { $$ = makeTypeCast($3, $5, @1); }
   16073             :             | EXTRACT '(' extract_list ')'
   16074             :                 {
   16075        1390 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   16076        1390 :                                                $3,
   16077             :                                                COERCE_SQL_SYNTAX,
   16078        1390 :                                                @1);
   16079             :                 }
   16080             :             | NORMALIZE '(' a_expr ')'
   16081             :                 {
   16082          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   16083          18 :                                                list_make1($3),
   16084             :                                                COERCE_SQL_SYNTAX,
   16085          18 :                                                @1);
   16086             :                 }
   16087             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   16088             :                 {
   16089          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   16090          42 :                                                list_make2($3, makeStringConst($5, @5)),
   16091             :                                                COERCE_SQL_SYNTAX,
   16092          42 :                                                @1);
   16093             :                 }
   16094             :             | OVERLAY '(' overlay_list ')'
   16095             :                 {
   16096          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   16097          82 :                                                $3,
   16098             :                                                COERCE_SQL_SYNTAX,
   16099          82 :                                                @1);
   16100             :                 }
   16101             :             | OVERLAY '(' func_arg_list_opt ')'
   16102             :                 {
   16103             :                     /*
   16104             :                      * allow functions named overlay() to be called without
   16105             :                      * special syntax
   16106             :                      */
   16107           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   16108           0 :                                                $3,
   16109             :                                                COERCE_EXPLICIT_CALL,
   16110           0 :                                                @1);
   16111             :                 }
   16112             :             | POSITION '(' position_list ')'
   16113             :                 {
   16114             :                     /*
   16115             :                      * position(A in B) is converted to position(B, A)
   16116             :                      *
   16117             :                      * We deliberately don't offer a "plain syntax" option
   16118             :                      * for position(), because the reversal of the arguments
   16119             :                      * creates too much risk of confusion.
   16120             :                      */
   16121         402 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   16122         402 :                                                $3,
   16123             :                                                COERCE_SQL_SYNTAX,
   16124         402 :                                                @1);
   16125             :                 }
   16126             :             | SUBSTRING '(' substr_list ')'
   16127             :                 {
   16128             :                     /* substring(A from B for C) is converted to
   16129             :                      * substring(A, B, C) - thomas 2000-11-28
   16130             :                      */
   16131         718 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   16132         718 :                                                $3,
   16133             :                                                COERCE_SQL_SYNTAX,
   16134         718 :                                                @1);
   16135             :                 }
   16136             :             | SUBSTRING '(' func_arg_list_opt ')'
   16137             :                 {
   16138             :                     /*
   16139             :                      * allow functions named substring() to be called without
   16140             :                      * special syntax
   16141             :                      */
   16142         254 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   16143         254 :                                                $3,
   16144             :                                                COERCE_EXPLICIT_CALL,
   16145         254 :                                                @1);
   16146             :                 }
   16147             :             | TREAT '(' a_expr AS Typename ')'
   16148             :                 {
   16149             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   16150             :                      * which is defined to be a subtype of the original expression.
   16151             :                      * In SQL99, this is intended for use with structured UDTs,
   16152             :                      * but let's make this a generally useful form allowing stronger
   16153             :                      * coercions than are handled by implicit casting.
   16154             :                      *
   16155             :                      * Convert SystemTypeName() to SystemFuncName() even though
   16156             :                      * at the moment they result in the same thing.
   16157             :                      */
   16158           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   16159           0 :                                                list_make1($3),
   16160             :                                                COERCE_EXPLICIT_CALL,
   16161           0 :                                                @1);
   16162             :                 }
   16163             :             | TRIM '(' BOTH trim_list ')'
   16164             :                 {
   16165             :                     /* various trim expressions are defined in SQL
   16166             :                      * - thomas 1997-07-19
   16167             :                      */
   16168          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16169          12 :                                                $4,
   16170             :                                                COERCE_SQL_SYNTAX,
   16171          12 :                                                @1);
   16172             :                 }
   16173             :             | TRIM '(' LEADING trim_list ')'
   16174             :                 {
   16175          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   16176          24 :                                                $4,
   16177             :                                                COERCE_SQL_SYNTAX,
   16178          24 :                                                @1);
   16179             :                 }
   16180             :             | TRIM '(' TRAILING trim_list ')'
   16181             :                 {
   16182         584 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16183         584 :                                                $4,
   16184             :                                                COERCE_SQL_SYNTAX,
   16185         584 :                                                @1);
   16186             :                 }
   16187             :             | TRIM '(' trim_list ')'
   16188             :                 {
   16189          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16190          98 :                                                $3,
   16191             :                                                COERCE_SQL_SYNTAX,
   16192          98 :                                                @1);
   16193             :                 }
   16194             :             | NULLIF '(' a_expr ',' a_expr ')'
   16195             :                 {
   16196         388 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16197             :                 }
   16198             :             | COALESCE '(' expr_list ')'
   16199             :                 {
   16200        3336 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16201             : 
   16202        3336 :                     c->args = $3;
   16203        3336 :                     c->location = @1;
   16204        3336 :                     $$ = (Node *) c;
   16205             :                 }
   16206             :             | GREATEST '(' expr_list ')'
   16207             :                 {
   16208         158 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16209             : 
   16210         158 :                     v->args = $3;
   16211         158 :                     v->op = IS_GREATEST;
   16212         158 :                     v->location = @1;
   16213         158 :                     $$ = (Node *) v;
   16214             :                 }
   16215             :             | LEAST '(' expr_list ')'
   16216             :                 {
   16217         148 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16218             : 
   16219         148 :                     v->args = $3;
   16220         148 :                     v->op = IS_LEAST;
   16221         148 :                     v->location = @1;
   16222         148 :                     $$ = (Node *) v;
   16223             :                 }
   16224             :             | XMLCONCAT '(' expr_list ')'
   16225             :                 {
   16226          62 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16227             :                 }
   16228             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16229             :                 {
   16230           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16231             :                 }
   16232             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16233             :                 {
   16234          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16235             :                 }
   16236             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16237             :                 {
   16238         116 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16239             :                 }
   16240             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16241             :                 {
   16242          20 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16243             :                 }
   16244             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16245             :                 {
   16246             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16247             :                      * converted to xmlexists(A, B)*/
   16248          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16249          54 :                                                list_make2($3, $4),
   16250             :                                                COERCE_SQL_SYNTAX,
   16251          54 :                                                @1);
   16252             :                 }
   16253             :             | XMLFOREST '(' xml_attribute_list ')'
   16254             :                 {
   16255          32 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16256             :                 }
   16257             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16258             :                 {
   16259             :                     XmlExpr *x = (XmlExpr *)
   16260         140 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16261         140 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16262         140 :                                     @1);
   16263             : 
   16264         140 :                     x->xmloption = $3;
   16265         140 :                     $$ = (Node *) x;
   16266             :                 }
   16267             :             | XMLPI '(' NAME_P ColLabel ')'
   16268             :                 {
   16269          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16270             :                 }
   16271             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16272             :                 {
   16273          50 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16274             :                 }
   16275             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16276             :                 {
   16277          68 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16278          68 :                                      list_make3($3, $5, $6), @1);
   16279             :                 }
   16280             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16281             :                 {
   16282         218 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16283             : 
   16284         218 :                     n->xmloption = $3;
   16285         218 :                     n->expr = $4;
   16286         218 :                     n->typeName = $6;
   16287         218 :                     n->indent = $7;
   16288         218 :                     n->location = @1;
   16289         218 :                     $$ = (Node *) n;
   16290             :                 }
   16291             :             | JSON_OBJECT '(' func_arg_list ')'
   16292             :                 {
   16293             :                     /* Support for legacy (non-standard) json_object() */
   16294          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16295          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16296             :                 }
   16297             :             | JSON_OBJECT '(' json_name_and_value_list
   16298             :                 json_object_constructor_null_clause_opt
   16299             :                 json_key_uniqueness_constraint_opt
   16300             :                 json_returning_clause_opt ')'
   16301             :                 {
   16302         348 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16303             : 
   16304         348 :                     n->exprs = $3;
   16305         348 :                     n->absent_on_null = $4;
   16306         348 :                     n->unique = $5;
   16307         348 :                     n->output = (JsonOutput *) $6;
   16308         348 :                     n->location = @1;
   16309         348 :                     $$ = (Node *) n;
   16310             :                 }
   16311             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16312             :                 {
   16313          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16314             : 
   16315          92 :                     n->exprs = NULL;
   16316          92 :                     n->absent_on_null = false;
   16317          92 :                     n->unique = false;
   16318          92 :                     n->output = (JsonOutput *) $3;
   16319          92 :                     n->location = @1;
   16320          92 :                     $$ = (Node *) n;
   16321             :                 }
   16322             :             | JSON_ARRAY '('
   16323             :                 json_value_expr_list
   16324             :                 json_array_constructor_null_clause_opt
   16325             :                 json_returning_clause_opt
   16326             :             ')'
   16327             :                 {
   16328         120 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16329             : 
   16330         120 :                     n->exprs = $3;
   16331         120 :                     n->absent_on_null = $4;
   16332         120 :                     n->output = (JsonOutput *) $5;
   16333         120 :                     n->location = @1;
   16334         120 :                     $$ = (Node *) n;
   16335             :                 }
   16336             :             | JSON_ARRAY '('
   16337             :                 select_no_parens
   16338             :                 json_format_clause_opt
   16339             :                 /* json_array_constructor_null_clause_opt */
   16340             :                 json_returning_clause_opt
   16341             :             ')'
   16342             :                 {
   16343          60 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16344             : 
   16345          60 :                     n->query = $3;
   16346          60 :                     n->format = (JsonFormat *) $4;
   16347          60 :                     n->absent_on_null = true;    /* XXX */
   16348          60 :                     n->output = (JsonOutput *) $5;
   16349          60 :                     n->location = @1;
   16350          60 :                     $$ = (Node *) n;
   16351             :                 }
   16352             :             | JSON_ARRAY '('
   16353             :                 json_returning_clause_opt
   16354             :             ')'
   16355             :                 {
   16356          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16357             : 
   16358          86 :                     n->exprs = NIL;
   16359          86 :                     n->absent_on_null = true;
   16360          86 :                     n->output = (JsonOutput *) $3;
   16361          86 :                     n->location = @1;
   16362          86 :                     $$ = (Node *) n;
   16363             :                 }
   16364             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16365             :                 {
   16366         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16367             : 
   16368         164 :                     n->expr = (JsonValueExpr *) $3;
   16369         164 :                     n->unique_keys = $4;
   16370         164 :                     n->output = NULL;
   16371         164 :                     n->location = @1;
   16372         164 :                     $$ = (Node *) n;
   16373             :                 }
   16374             :             | JSON_SCALAR '(' a_expr ')'
   16375             :                 {
   16376         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16377             : 
   16378         112 :                     n->expr = (Expr *) $3;
   16379         112 :                     n->output = NULL;
   16380         112 :                     n->location = @1;
   16381         112 :                     $$ = (Node *) n;
   16382             :                 }
   16383             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16384             :                 {
   16385         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16386             : 
   16387         108 :                     n->expr = (JsonValueExpr *) $3;
   16388         108 :                     n->output = (JsonOutput *) $4;
   16389         108 :                     n->location = @1;
   16390         108 :                     $$ = (Node *) n;
   16391             :                 }
   16392             :             | MERGE_ACTION '(' ')'
   16393             :                 {
   16394         216 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16395             : 
   16396         216 :                     m->msftype = TEXTOID;
   16397         216 :                     m->location = @1;
   16398         216 :                     $$ = (Node *) m;
   16399             :                 }
   16400             :             | JSON_QUERY '('
   16401             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16402             :                 json_returning_clause_opt
   16403             :                 json_wrapper_behavior
   16404             :                 json_quotes_clause_opt
   16405             :                 json_behavior_clause_opt
   16406             :             ')'
   16407             :                 {
   16408         990 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16409             : 
   16410         990 :                     n->op = JSON_QUERY_OP;
   16411         990 :                     n->context_item = (JsonValueExpr *) $3;
   16412         990 :                     n->pathspec = $5;
   16413         990 :                     n->passing = $6;
   16414         990 :                     n->output = (JsonOutput *) $7;
   16415         990 :                     n->wrapper = $8;
   16416         990 :                     n->quotes = $9;
   16417         990 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16418         990 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16419         990 :                     n->location = @1;
   16420         990 :                     $$ = (Node *) n;
   16421             :                 }
   16422             :             | JSON_EXISTS '('
   16423             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16424             :                 json_on_error_clause_opt
   16425             :             ')'
   16426             :                 {
   16427         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16428             : 
   16429         168 :                     n->op = JSON_EXISTS_OP;
   16430         168 :                     n->context_item = (JsonValueExpr *) $3;
   16431         168 :                     n->pathspec = $5;
   16432         168 :                     n->passing = $6;
   16433         168 :                     n->output = NULL;
   16434         168 :                     n->on_error = (JsonBehavior *) $7;
   16435         168 :                     n->location = @1;
   16436         168 :                     $$ = (Node *) n;
   16437             :                 }
   16438             :             | JSON_VALUE '('
   16439             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16440             :                 json_returning_clause_opt
   16441             :                 json_behavior_clause_opt
   16442             :             ')'
   16443             :                 {
   16444         630 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16445             : 
   16446         630 :                     n->op = JSON_VALUE_OP;
   16447         630 :                     n->context_item = (JsonValueExpr *) $3;
   16448         630 :                     n->pathspec = $5;
   16449         630 :                     n->passing = $6;
   16450         630 :                     n->output = (JsonOutput *) $7;
   16451         630 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16452         630 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16453         630 :                     n->location = @1;
   16454         630 :                     $$ = (Node *) n;
   16455             :                 }
   16456             :             ;
   16457             : 
   16458             : 
   16459             : /*
   16460             :  * SQL/XML support
   16461             :  */
   16462             : xml_root_version: VERSION_P a_expr
   16463          24 :                 { $$ = $2; }
   16464             :             | VERSION_P NO VALUE_P
   16465          44 :                 { $$ = makeNullAConst(-1); }
   16466             :         ;
   16467             : 
   16468             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16469          26 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16470             :             | ',' STANDALONE_P NO
   16471          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16472             :             | ',' STANDALONE_P NO VALUE_P
   16473          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16474             :             | /*EMPTY*/
   16475          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16476             :         ;
   16477             : 
   16478          56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16479             :         ;
   16480             : 
   16481          88 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16482         144 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16483             :         ;
   16484             : 
   16485             : xml_attribute_el: a_expr AS ColLabel
   16486             :                 {
   16487         106 :                     $$ = makeNode(ResTarget);
   16488         106 :                     $$->name = $3;
   16489         106 :                     $$->indirection = NIL;
   16490         106 :                     $$->val = (Node *) $1;
   16491         106 :                     $$->location = @1;
   16492             :                 }
   16493             :             | a_expr
   16494             :                 {
   16495         126 :                     $$ = makeNode(ResTarget);
   16496         126 :                     $$->name = NULL;
   16497         126 :                     $$->indirection = NIL;
   16498         126 :                     $$->val = (Node *) $1;
   16499         126 :                     $$->location = @1;
   16500             :                 }
   16501             :         ;
   16502             : 
   16503         186 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16504         188 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16505             :         ;
   16506             : 
   16507         140 : xml_indent_option: INDENT                           { $$ = true; }
   16508          36 :             | NO INDENT                             { $$ = false; }
   16509          42 :             | /*EMPTY*/                             { $$ = false; }
   16510             :         ;
   16511             : 
   16512           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16513           2 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16514         138 :             | /*EMPTY*/                             { $$ = false; }
   16515             :         ;
   16516             : 
   16517             : /* We allow several variants for SQL and other compatibility. */
   16518             : xmlexists_argument:
   16519             :             PASSING c_expr
   16520             :                 {
   16521         238 :                     $$ = $2;
   16522             :                 }
   16523             :             | PASSING c_expr xml_passing_mech
   16524             :                 {
   16525           0 :                     $$ = $2;
   16526             :                 }
   16527             :             | PASSING xml_passing_mech c_expr
   16528             :                 {
   16529          42 :                     $$ = $3;
   16530             :                 }
   16531             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16532             :                 {
   16533           6 :                     $$ = $3;
   16534             :                 }
   16535             :         ;
   16536             : 
   16537             : xml_passing_mech:
   16538             :             BY REF_P
   16539             :             | BY VALUE_P
   16540             :         ;
   16541             : 
   16542             : /*****************************************************************************
   16543             :  *
   16544             :  * WAIT FOR LSN
   16545             :  *
   16546             :  *****************************************************************************/
   16547             : 
   16548             : WaitStmt:
   16549             :             WAIT FOR LSN_P Sconst opt_wait_with_clause
   16550             :                 {
   16551         112 :                     WaitStmt *n = makeNode(WaitStmt);
   16552         112 :                     n->lsn_literal = $4;
   16553         112 :                     n->options = $5;
   16554         112 :                     $$ = (Node *) n;
   16555             :                 }
   16556             :             ;
   16557             : 
   16558             : opt_wait_with_clause:
   16559          90 :             WITH '(' utility_option_list ')'        { $$ = $3; }
   16560          22 :             | /*EMPTY*/                             { $$ = NIL; }
   16561             :             ;
   16562             : 
   16563             : /*
   16564             :  * Aggregate decoration clauses
   16565             :  */
   16566             : within_group_clause:
   16567         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16568      327372 :             | /*EMPTY*/                             { $$ = NIL; }
   16569             :         ;
   16570             : 
   16571             : filter_clause:
   16572         862 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16573      327218 :             | /*EMPTY*/                             { $$ = NULL; }
   16574             :         ;
   16575             : 
   16576             : 
   16577             : /*
   16578             :  * Window Definitions
   16579             :  */
   16580             : null_treatment:
   16581         198 :             IGNORE_P NULLS_P                        { $$ = PARSER_IGNORE_NULLS; }
   16582          96 :             | RESPECT_P NULLS_P                     { $$ = PARSER_RESPECT_NULLS; }
   16583      327426 :             | /*EMPTY*/                             { $$ = NO_NULLTREATMENT; }
   16584             :         ;
   16585             : 
   16586             : window_clause:
   16587         606 :             WINDOW window_definition_list           { $$ = $2; }
   16588      494774 :             | /*EMPTY*/                             { $$ = NIL; }
   16589             :         ;
   16590             : 
   16591             : window_definition_list:
   16592         606 :             window_definition                       { $$ = list_make1($1); }
   16593             :             | window_definition_list ',' window_definition
   16594          30 :                                                     { $$ = lappend($1, $3); }
   16595             :         ;
   16596             : 
   16597             : window_definition:
   16598             :             ColId AS window_specification
   16599             :                 {
   16600         636 :                     WindowDef  *n = $3;
   16601             : 
   16602         636 :                     n->name = $1;
   16603         636 :                     $$ = n;
   16604             :                 }
   16605             :         ;
   16606             : 
   16607             : over_clause: OVER window_specification
   16608        2768 :                 { $$ = $2; }
   16609             :             | OVER ColId
   16610             :                 {
   16611        1182 :                     WindowDef  *n = makeNode(WindowDef);
   16612             : 
   16613        1182 :                     n->name = $2;
   16614        1182 :                     n->refname = NULL;
   16615        1182 :                     n->partitionClause = NIL;
   16616        1182 :                     n->orderClause = NIL;
   16617        1182 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16618        1182 :                     n->startOffset = NULL;
   16619        1182 :                     n->endOffset = NULL;
   16620        1182 :                     n->location = @2;
   16621        1182 :                     $$ = n;
   16622             :                 }
   16623             :             | /*EMPTY*/
   16624      324124 :                 { $$ = NULL; }
   16625             :         ;
   16626             : 
   16627             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16628             :                         opt_sort_clause opt_frame_clause ')'
   16629             :                 {
   16630        3404 :                     WindowDef  *n = makeNode(WindowDef);
   16631             : 
   16632        3404 :                     n->name = NULL;
   16633        3404 :                     n->refname = $2;
   16634        3404 :                     n->partitionClause = $3;
   16635        3404 :                     n->orderClause = $4;
   16636             :                     /* copy relevant fields of opt_frame_clause */
   16637        3404 :                     n->frameOptions = $5->frameOptions;
   16638        3404 :                     n->startOffset = $5->startOffset;
   16639        3404 :                     n->endOffset = $5->endOffset;
   16640        3404 :                     n->location = @1;
   16641        3404 :                     $$ = n;
   16642             :                 }
   16643             :         ;
   16644             : 
   16645             : /*
   16646             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16647             :  * of a window_specification, we want the assumption to be that there is
   16648             :  * no existing_window_name; but those keywords are unreserved and so could
   16649             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16650             :  * and giving the empty production here a slightly higher precedence, so
   16651             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16652             :  * These keywords are thus precluded from being an existing_window_name but
   16653             :  * are not reserved for any other purpose.
   16654             :  */
   16655          54 : opt_existing_window_name: ColId                     { $$ = $1; }
   16656        3356 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16657             :         ;
   16658             : 
   16659         934 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16660        2470 :             | /*EMPTY*/                             { $$ = NIL; }
   16661             :         ;
   16662             : 
   16663             : /*
   16664             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16665             :  * frameOptions, startOffset, and endOffset.
   16666             :  */
   16667             : opt_frame_clause:
   16668             :             RANGE frame_extent opt_window_exclusion_clause
   16669             :                 {
   16670         796 :                     WindowDef  *n = $2;
   16671             : 
   16672         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16673         796 :                     n->frameOptions |= $3;
   16674         796 :                     $$ = n;
   16675             :                 }
   16676             :             | ROWS frame_extent opt_window_exclusion_clause
   16677             :                 {
   16678         690 :                     WindowDef  *n = $2;
   16679             : 
   16680         690 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16681         690 :                     n->frameOptions |= $3;
   16682         690 :                     $$ = n;
   16683             :                 }
   16684             :             | GROUPS frame_extent opt_window_exclusion_clause
   16685             :                 {
   16686         204 :                     WindowDef  *n = $2;
   16687             : 
   16688         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16689         204 :                     n->frameOptions |= $3;
   16690         204 :                     $$ = n;
   16691             :                 }
   16692             :             | /*EMPTY*/
   16693             :                 {
   16694        1714 :                     WindowDef  *n = makeNode(WindowDef);
   16695             : 
   16696        1714 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16697        1714 :                     n->startOffset = NULL;
   16698        1714 :                     n->endOffset = NULL;
   16699        1714 :                     $$ = n;
   16700             :                 }
   16701             :         ;
   16702             : 
   16703             : frame_extent: frame_bound
   16704             :                 {
   16705          12 :                     WindowDef  *n = $1;
   16706             : 
   16707             :                     /* reject invalid cases */
   16708          12 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16709           0 :                         ereport(ERROR,
   16710             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16711             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16712             :                                  parser_errposition(@1)));
   16713          12 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16714           0 :                         ereport(ERROR,
   16715             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16716             :                                  errmsg("frame starting from following row cannot end with current row"),
   16717             :                                  parser_errposition(@1)));
   16718          12 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16719          12 :                     $$ = n;
   16720             :                 }
   16721             :             | BETWEEN frame_bound AND frame_bound
   16722             :                 {
   16723        1678 :                     WindowDef  *n1 = $2;
   16724        1678 :                     WindowDef  *n2 = $4;
   16725             : 
   16726             :                     /* form merged options */
   16727        1678 :                     int     frameOptions = n1->frameOptions;
   16728             :                     /* shift converts START_ options to END_ options */
   16729        1678 :                     frameOptions |= n2->frameOptions << 1;
   16730        1678 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16731             :                     /* reject invalid cases */
   16732        1678 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16733           0 :                         ereport(ERROR,
   16734             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16735             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16736             :                                  parser_errposition(@2)));
   16737        1678 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16738           0 :                         ereport(ERROR,
   16739             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16740             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16741             :                                  parser_errposition(@4)));
   16742        1678 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16743         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16744           0 :                         ereport(ERROR,
   16745             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16746             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16747             :                                  parser_errposition(@4)));
   16748        1678 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16749         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16750             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16751           0 :                         ereport(ERROR,
   16752             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16753             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16754             :                                  parser_errposition(@4)));
   16755        1678 :                     n1->frameOptions = frameOptions;
   16756        1678 :                     n1->endOffset = n2->startOffset;
   16757        1678 :                     $$ = n1;
   16758             :                 }
   16759             :         ;
   16760             : 
   16761             : /*
   16762             :  * This is used for both frame start and frame end, with output set up on
   16763             :  * the assumption it's frame start; the frame_extent productions must reject
   16764             :  * invalid cases.
   16765             :  */
   16766             : frame_bound:
   16767             :             UNBOUNDED PRECEDING
   16768             :                 {
   16769         216 :                     WindowDef  *n = makeNode(WindowDef);
   16770             : 
   16771         216 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16772         216 :                     n->startOffset = NULL;
   16773         216 :                     n->endOffset = NULL;
   16774         216 :                     $$ = n;
   16775             :                 }
   16776             :             | UNBOUNDED FOLLOWING
   16777             :                 {
   16778         394 :                     WindowDef  *n = makeNode(WindowDef);
   16779             : 
   16780         394 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16781         394 :                     n->startOffset = NULL;
   16782         394 :                     n->endOffset = NULL;
   16783         394 :                     $$ = n;
   16784             :                 }
   16785             :             | CURRENT_P ROW
   16786             :                 {
   16787         604 :                     WindowDef  *n = makeNode(WindowDef);
   16788             : 
   16789         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16790         604 :                     n->startOffset = NULL;
   16791         604 :                     n->endOffset = NULL;
   16792         604 :                     $$ = n;
   16793             :                 }
   16794             :             | a_expr PRECEDING
   16795             :                 {
   16796         954 :                     WindowDef  *n = makeNode(WindowDef);
   16797             : 
   16798         954 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16799         954 :                     n->startOffset = $1;
   16800         954 :                     n->endOffset = NULL;
   16801         954 :                     $$ = n;
   16802             :                 }
   16803             :             | a_expr FOLLOWING
   16804             :                 {
   16805        1200 :                     WindowDef  *n = makeNode(WindowDef);
   16806             : 
   16807        1200 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16808        1200 :                     n->startOffset = $1;
   16809        1200 :                     n->endOffset = NULL;
   16810        1200 :                     $$ = n;
   16811             :                 }
   16812             :         ;
   16813             : 
   16814             : opt_window_exclusion_clause:
   16815          96 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16816          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16817         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16818          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16819        1330 :             | /*EMPTY*/             { $$ = 0; }
   16820             :         ;
   16821             : 
   16822             : 
   16823             : /*
   16824             :  * Supporting nonterminals for expressions.
   16825             :  */
   16826             : 
   16827             : /* Explicit row production.
   16828             :  *
   16829             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16830             :  * without conflicting with the parenthesized a_expr production.  Without the
   16831             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16832             :  */
   16833           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16834           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16835        1968 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16836             :         ;
   16837             : 
   16838        3820 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16839          36 :             | ROW '(' ')'                           { $$ = NIL; }
   16840             :         ;
   16841             : 
   16842        2728 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16843             :         ;
   16844             : 
   16845       17048 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16846           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16847         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16848             :         ;
   16849             : 
   16850       11546 : all_Op:     Op                                      { $$ = $1; }
   16851       29780 :             | MathOp                                { $$ = $1; }
   16852             :         ;
   16853             : 
   16854          40 : MathOp:      '+'                                    { $$ = "+"; }
   16855          68 :             | '-'                                   { $$ = "-"; }
   16856         150 :             | '*'                                   { $$ = "*"; }
   16857           0 :             | '/'                                   { $$ = "/"; }
   16858           8 :             | '%'                                   { $$ = "%"; }
   16859           0 :             | '^'                                   { $$ = "^"; }
   16860         978 :             | '<'                                    { $$ = "<"; }
   16861         886 :             | '>'                                    { $$ = ">"; }
   16862       25166 :             | '='                                   { $$ = "="; }
   16863         844 :             | LESS_EQUALS                           { $$ = "<="; }
   16864         836 :             | GREATER_EQUALS                        { $$ = ">="; }
   16865         804 :             | NOT_EQUALS                            { $$ = "<>"; }
   16866             :         ;
   16867             : 
   16868             : qual_Op:    Op
   16869       44410 :                     { $$ = list_make1(makeString($1)); }
   16870             :             | OPERATOR '(' any_operator ')'
   16871       16144 :                     { $$ = $3; }
   16872             :         ;
   16873             : 
   16874             : qual_all_Op:
   16875             :             all_Op
   16876        1416 :                     { $$ = list_make1(makeString($1)); }
   16877             :             | OPERATOR '(' any_operator ')'
   16878          34 :                     { $$ = $3; }
   16879             :         ;
   16880             : 
   16881             : subquery_Op:
   16882             :             all_Op
   16883       17054 :                     { $$ = list_make1(makeString($1)); }
   16884             :             | OPERATOR '(' any_operator ')'
   16885         286 :                     { $$ = $3; }
   16886             :             | LIKE
   16887          24 :                     { $$ = list_make1(makeString("~~")); }
   16888             :             | NOT_LA LIKE
   16889          12 :                     { $$ = list_make1(makeString("!~~")); }
   16890             :             | ILIKE
   16891          12 :                     { $$ = list_make1(makeString("~~*")); }
   16892             :             | NOT_LA ILIKE
   16893           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16894             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16895             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16896             :  * and the ~ operator for posix regular expressions is used.
   16897             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16898             :  * this transformation is made on the fly by the parser upwards.
   16899             :  * however the SubLink structure which handles any/some/all stuff
   16900             :  * is not ready for such a thing.
   16901             :  */
   16902             :             ;
   16903             : 
   16904             : expr_list:  a_expr
   16905             :                 {
   16906      169342 :                     $$ = list_make1($1);
   16907             :                 }
   16908             :             | expr_list ',' a_expr
   16909             :                 {
   16910      153484 :                     $$ = lappend($1, $3);
   16911             :                 }
   16912             :         ;
   16913             : 
   16914             : /* function arguments can have names */
   16915             : func_arg_list:  func_arg_expr
   16916             :                 {
   16917      325166 :                     $$ = list_make1($1);
   16918             :                 }
   16919             :             | func_arg_list ',' func_arg_expr
   16920             :                 {
   16921      289202 :                     $$ = lappend($1, $3);
   16922             :                 }
   16923             :         ;
   16924             : 
   16925             : func_arg_expr:  a_expr
   16926             :                 {
   16927      567968 :                     $$ = $1;
   16928             :                 }
   16929             :             | param_name COLON_EQUALS a_expr
   16930             :                 {
   16931       45504 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16932             : 
   16933       45504 :                     na->name = $1;
   16934       45504 :                     na->arg = (Expr *) $3;
   16935       45504 :                     na->argnumber = -1;      /* until determined */
   16936       45504 :                     na->location = @1;
   16937       45504 :                     $$ = (Node *) na;
   16938             :                 }
   16939             :             | param_name EQUALS_GREATER a_expr
   16940             :                 {
   16941        1698 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16942             : 
   16943        1698 :                     na->name = $1;
   16944        1698 :                     na->arg = (Expr *) $3;
   16945        1698 :                     na->argnumber = -1;      /* until determined */
   16946        1698 :                     na->location = @1;
   16947        1698 :                     $$ = (Node *) na;
   16948             :                 }
   16949             :         ;
   16950             : 
   16951         254 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16952           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16953             :         ;
   16954             : 
   16955        1948 : type_list:  Typename                                { $$ = list_make1($1); }
   16956         586 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16957             :         ;
   16958             : 
   16959             : array_expr: '[' expr_list ']'
   16960             :                 {
   16961        7790 :                     $$ = makeAArrayExpr($2, @1, @3);
   16962             :                 }
   16963             :             | '[' array_expr_list ']'
   16964             :                 {
   16965         412 :                     $$ = makeAArrayExpr($2, @1, @3);
   16966             :                 }
   16967             :             | '[' ']'
   16968             :                 {
   16969          98 :                     $$ = makeAArrayExpr(NIL, @1, @2);
   16970             :                 }
   16971             :         ;
   16972             : 
   16973         412 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16974         342 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16975             :         ;
   16976             : 
   16977             : 
   16978             : extract_list:
   16979             :             extract_arg FROM a_expr
   16980             :                 {
   16981        1390 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16982             :                 }
   16983             :         ;
   16984             : 
   16985             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16986             :  * - thomas 2001-04-12
   16987             :  */
   16988             : extract_arg:
   16989        1132 :             IDENT                                   { $$ = $1; }
   16990          72 :             | YEAR_P                                { $$ = "year"; }
   16991          42 :             | MONTH_P                               { $$ = "month"; }
   16992          54 :             | DAY_P                                 { $$ = "day"; }
   16993          30 :             | HOUR_P                                { $$ = "hour"; }
   16994          30 :             | MINUTE_P                              { $$ = "minute"; }
   16995          30 :             | SECOND_P                              { $$ = "second"; }
   16996           0 :             | Sconst                                { $$ = $1; }
   16997             :         ;
   16998             : 
   16999             : unicode_normal_form:
   17000          24 :             NFC                                     { $$ = "NFC"; }
   17001          18 :             | NFD                                   { $$ = "NFD"; }
   17002          18 :             | NFKC                                  { $$ = "NFKC"; }
   17003          18 :             | NFKD                                  { $$ = "NFKD"; }
   17004             :         ;
   17005             : 
   17006             : /* OVERLAY() arguments */
   17007             : overlay_list:
   17008             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   17009             :                 {
   17010             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   17011          34 :                     $$ = list_make4($1, $3, $5, $7);
   17012             :                 }
   17013             :             | a_expr PLACING a_expr FROM a_expr
   17014             :                 {
   17015             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   17016          48 :                     $$ = list_make3($1, $3, $5);
   17017             :                 }
   17018             :         ;
   17019             : 
   17020             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   17021             : position_list:
   17022         402 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   17023             :         ;
   17024             : 
   17025             : /*
   17026             :  * SUBSTRING() arguments
   17027             :  *
   17028             :  * Note that SQL:1999 has both
   17029             :  *     text FROM int FOR int
   17030             :  * and
   17031             :  *     text FROM pattern FOR escape
   17032             :  *
   17033             :  * In the parser we map them both to a call to the substring() function and
   17034             :  * rely on type resolution to pick the right one.
   17035             :  *
   17036             :  * In SQL:2003, the second variant was changed to
   17037             :  *     text SIMILAR pattern ESCAPE escape
   17038             :  * We could in theory map that to a different function internally, but
   17039             :  * since we still support the SQL:1999 version, we don't.  However,
   17040             :  * ruleutils.c will reverse-list the call in the newer style.
   17041             :  */
   17042             : substr_list:
   17043             :             a_expr FROM a_expr FOR a_expr
   17044             :                 {
   17045         122 :                     $$ = list_make3($1, $3, $5);
   17046             :                 }
   17047             :             | a_expr FOR a_expr FROM a_expr
   17048             :                 {
   17049             :                     /* not legal per SQL, but might as well allow it */
   17050           0 :                     $$ = list_make3($1, $5, $3);
   17051             :                 }
   17052             :             | a_expr FROM a_expr
   17053             :                 {
   17054             :                     /*
   17055             :                      * Because we aren't restricting data types here, this
   17056             :                      * syntax can end up resolving to textregexsubstr().
   17057             :                      * We've historically allowed that to happen, so continue
   17058             :                      * to accept it.  However, ruleutils.c will reverse-list
   17059             :                      * such a call in regular function call syntax.
   17060             :                      */
   17061         376 :                     $$ = list_make2($1, $3);
   17062             :                 }
   17063             :             | a_expr FOR a_expr
   17064             :                 {
   17065             :                     /* not legal per SQL */
   17066             : 
   17067             :                     /*
   17068             :                      * Since there are no cases where this syntax allows
   17069             :                      * a textual FOR value, we forcibly cast the argument
   17070             :                      * to int4.  The possible matches in pg_proc are
   17071             :                      * substring(text,int4) and substring(text,text),
   17072             :                      * and we don't want the parser to choose the latter,
   17073             :                      * which it is likely to do if the second argument
   17074             :                      * is unknown or doesn't have an implicit cast to int4.
   17075             :                      */
   17076          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   17077             :                                     makeTypeCast($3,
   17078             :                                                  SystemTypeName("int4"), -1));
   17079             :                 }
   17080             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   17081             :                 {
   17082         184 :                     $$ = list_make3($1, $3, $5);
   17083             :                 }
   17084             :         ;
   17085             : 
   17086         608 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   17087          24 :             | FROM expr_list                        { $$ = $2; }
   17088          86 :             | expr_list                             { $$ = $1; }
   17089             :         ;
   17090             : 
   17091             : /*
   17092             :  * Define SQL-style CASE clause.
   17093             :  * - Full specification
   17094             :  *  CASE WHEN a = b THEN c ... ELSE d END
   17095             :  * - Implicit argument
   17096             :  *  CASE a WHEN b THEN c ... ELSE d END
   17097             :  */
   17098             : case_expr:  CASE case_arg when_clause_list case_default END_P
   17099             :                 {
   17100       40216 :                     CaseExpr   *c = makeNode(CaseExpr);
   17101             : 
   17102       40216 :                     c->casetype = InvalidOid; /* not analyzed yet */
   17103       40216 :                     c->arg = (Expr *) $2;
   17104       40216 :                     c->args = $3;
   17105       40216 :                     c->defresult = (Expr *) $4;
   17106       40216 :                     c->location = @1;
   17107       40216 :                     $$ = (Node *) c;
   17108             :                 }
   17109             :         ;
   17110             : 
   17111             : when_clause_list:
   17112             :             /* There must be at least one */
   17113       40216 :             when_clause                             { $$ = list_make1($1); }
   17114       30330 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   17115             :         ;
   17116             : 
   17117             : when_clause:
   17118             :             WHEN a_expr THEN a_expr
   17119             :                 {
   17120       70546 :                     CaseWhen   *w = makeNode(CaseWhen);
   17121             : 
   17122       70546 :                     w->expr = (Expr *) $2;
   17123       70546 :                     w->result = (Expr *) $4;
   17124       70546 :                     w->location = @1;
   17125       70546 :                     $$ = (Node *) w;
   17126             :                 }
   17127             :         ;
   17128             : 
   17129             : case_default:
   17130       30228 :             ELSE a_expr                             { $$ = $2; }
   17131        9988 :             | /*EMPTY*/                             { $$ = NULL; }
   17132             :         ;
   17133             : 
   17134        7208 : case_arg:   a_expr                                  { $$ = $1; }
   17135       33008 :             | /*EMPTY*/                             { $$ = NULL; }
   17136             :         ;
   17137             : 
   17138             : columnref:  ColId
   17139             :                 {
   17140      766676 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   17141             :                 }
   17142             :             | ColId indirection
   17143             :                 {
   17144     1081046 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   17145             :                 }
   17146             :         ;
   17147             : 
   17148             : indirection_el:
   17149             :             '.' attr_name
   17150             :                 {
   17151     1458504 :                     $$ = (Node *) makeString($2);
   17152             :                 }
   17153             :             | '.' '*'
   17154             :                 {
   17155        7164 :                     $$ = (Node *) makeNode(A_Star);
   17156             :                 }
   17157             :             | '[' a_expr ']'
   17158             :                 {
   17159       13208 :                     A_Indices *ai = makeNode(A_Indices);
   17160             : 
   17161       13208 :                     ai->is_slice = false;
   17162       13208 :                     ai->lidx = NULL;
   17163       13208 :                     ai->uidx = $2;
   17164       13208 :                     $$ = (Node *) ai;
   17165             :                 }
   17166             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   17167             :                 {
   17168         612 :                     A_Indices *ai = makeNode(A_Indices);
   17169             : 
   17170         612 :                     ai->is_slice = true;
   17171         612 :                     ai->lidx = $2;
   17172         612 :                     ai->uidx = $4;
   17173         612 :                     $$ = (Node *) ai;
   17174             :                 }
   17175             :         ;
   17176             : 
   17177             : opt_slice_bound:
   17178        1044 :             a_expr                                  { $$ = $1; }
   17179         180 :             | /*EMPTY*/                             { $$ = NULL; }
   17180             :         ;
   17181             : 
   17182             : indirection:
   17183     1458560 :             indirection_el                          { $$ = list_make1($1); }
   17184        3188 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   17185             :         ;
   17186             : 
   17187             : opt_indirection:
   17188      199524 :             /*EMPTY*/                               { $$ = NIL; }
   17189       17740 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   17190             :         ;
   17191             : 
   17192             : opt_asymmetric: ASYMMETRIC
   17193             :             | /*EMPTY*/
   17194             :         ;
   17195             : 
   17196             : /* SQL/JSON support */
   17197             : json_passing_clause_opt:
   17198         336 :             PASSING json_arguments                  { $$ = $2; }
   17199        2000 :             | /*EMPTY*/                             { $$ = NIL; }
   17200             :         ;
   17201             : 
   17202             : json_arguments:
   17203         336 :             json_argument                           { $$ = list_make1($1); }
   17204         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17205             :         ;
   17206             : 
   17207             : json_argument:
   17208             :             json_value_expr AS ColLabel
   17209             :             {
   17210         462 :                 JsonArgument *n = makeNode(JsonArgument);
   17211             : 
   17212         462 :                 n->val = (JsonValueExpr *) $1;
   17213         462 :                 n->name = $3;
   17214         462 :                 $$ = (Node *) n;
   17215             :             }
   17216             :         ;
   17217             : 
   17218             : /* ARRAY is a noise word */
   17219             : json_wrapper_behavior:
   17220          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17221           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17222          84 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17223          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17224           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17225          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17226          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17227           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17228        1640 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17229             :         ;
   17230             : 
   17231             : json_behavior:
   17232             :             DEFAULT a_expr
   17233         432 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17234             :             | json_behavior_type
   17235         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17236             :         ;
   17237             : 
   17238             : json_behavior_type:
   17239         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17240          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17241          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17242          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17243          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17244          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17245          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17246             :             /* non-standard, for Oracle compatibility only */
   17247          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17248             :         ;
   17249             : 
   17250             : json_behavior_clause_opt:
   17251             :             json_behavior ON EMPTY_P
   17252         222 :                 { $$ = list_make2($1, NULL); }
   17253             :             | json_behavior ON ERROR_P
   17254         552 :                 { $$ = list_make2(NULL, $1); }
   17255             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17256         102 :                 { $$ = list_make2($1, $4); }
   17257             :             | /* EMPTY */
   17258        1586 :                 { $$ = list_make2(NULL, NULL); }
   17259             :         ;
   17260             : 
   17261             : json_on_error_clause_opt:
   17262             :             json_behavior ON ERROR_P
   17263         150 :                 { $$ = $1; }
   17264             :             | /* EMPTY */
   17265         692 :                 { $$ = NULL; }
   17266             :         ;
   17267             : 
   17268             : json_value_expr:
   17269             :             a_expr json_format_clause_opt
   17270             :             {
   17271             :                 /* formatted_expr will be set during parse-analysis. */
   17272        4292 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17273        4292 :                                                 castNode(JsonFormat, $2));
   17274             :             }
   17275             :         ;
   17276             : 
   17277             : json_format_clause:
   17278             :             FORMAT_LA JSON ENCODING name
   17279             :                 {
   17280             :                     int     encoding;
   17281             : 
   17282         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17283          64 :                         encoding = JS_ENC_UTF8;
   17284          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17285          12 :                         encoding = JS_ENC_UTF16;
   17286          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17287          12 :                         encoding = JS_ENC_UTF32;
   17288             :                     else
   17289          12 :                         ereport(ERROR,
   17290             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17291             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17292             :                                  parser_errposition(@4)));
   17293             : 
   17294          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17295             :                 }
   17296             :             | FORMAT_LA JSON
   17297             :                 {
   17298         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17299             :                 }
   17300             :         ;
   17301             : 
   17302             : json_format_clause_opt:
   17303             :             json_format_clause
   17304             :                 {
   17305         392 :                     $$ = $1;
   17306             :                 }
   17307             :             | /* EMPTY */
   17308             :                 {
   17309        5458 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17310             :                 }
   17311             :         ;
   17312             : 
   17313             : json_quotes_clause_opt:
   17314          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17315          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17316          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17317         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17318        1550 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17319             :         ;
   17320             : 
   17321             : json_returning_clause_opt:
   17322             :             RETURNING Typename json_format_clause_opt
   17323             :                 {
   17324        1498 :                     JsonOutput *n = makeNode(JsonOutput);
   17325             : 
   17326        1498 :                     n->typeName = $2;
   17327        1498 :                     n->returning = makeNode(JsonReturning);
   17328        1498 :                     n->returning->format = (JsonFormat *) $3;
   17329        1498 :                     $$ = (Node *) n;
   17330             :                 }
   17331        1296 :             | /* EMPTY */                           { $$ = NULL; }
   17332             :         ;
   17333             : 
   17334             : /*
   17335             :  * We must assign the only-JSON production a precedence less than IDENT in
   17336             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17337             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17338             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17339             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17340             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17341             :  * really related to this syntax, but it's a convenient choice because it
   17342             :  * already has a precedence less than IDENT for other reasons.
   17343             :  */
   17344             : json_predicate_type_constraint:
   17345         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17346          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17347          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17348          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17349          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17350             :         ;
   17351             : 
   17352             : /*
   17353             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17354             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17355             :  * This prevents reducing them when the next token is KEYS.
   17356             :  */
   17357             : json_key_uniqueness_constraint_opt:
   17358         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17359         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17360          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17361          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17362         798 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17363             :         ;
   17364             : 
   17365             : json_name_and_value_list:
   17366             :             json_name_and_value
   17367         348 :                 { $$ = list_make1($1); }
   17368             :             | json_name_and_value_list ',' json_name_and_value
   17369         256 :                 { $$ = lappend($1, $3); }
   17370             :         ;
   17371             : 
   17372             : json_name_and_value:
   17373             : /* Supporting this syntax seems to require major surgery
   17374             :             KEY c_expr VALUE_P json_value_expr
   17375             :                 { $$ = makeJsonKeyValue($2, $4); }
   17376             :             |
   17377             : */
   17378             :             c_expr VALUE_P json_value_expr
   17379          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17380             :             |
   17381             :             a_expr ':' json_value_expr
   17382         784 :                 { $$ = makeJsonKeyValue($1, $3); }
   17383             :         ;
   17384             : 
   17385             : /* empty means false for objects, true for arrays */
   17386             : json_object_constructor_null_clause_opt:
   17387          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17388         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17389         412 :             | /* EMPTY */                       { $$ = false; }
   17390             :         ;
   17391             : 
   17392             : json_array_constructor_null_clause_opt:
   17393          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17394          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17395         180 :             | /* EMPTY */                           { $$ = true; }
   17396             :         ;
   17397             : 
   17398             : json_value_expr_list:
   17399         120 :             json_value_expr                             { $$ = list_make1($1); }
   17400         138 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17401             :         ;
   17402             : 
   17403             : json_aggregate_func:
   17404             :             JSON_OBJECTAGG '('
   17405             :                 json_name_and_value
   17406             :                 json_object_constructor_null_clause_opt
   17407             :                 json_key_uniqueness_constraint_opt
   17408             :                 json_returning_clause_opt
   17409             :             ')'
   17410             :                 {
   17411         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17412             : 
   17413         204 :                     n->arg = (JsonKeyValue *) $3;
   17414         204 :                     n->absent_on_null = $4;
   17415         204 :                     n->unique = $5;
   17416         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17417         204 :                     n->constructor->output = (JsonOutput *) $6;
   17418         204 :                     n->constructor->agg_order = NULL;
   17419         204 :                     n->constructor->location = @1;
   17420         204 :                     $$ = (Node *) n;
   17421             :                 }
   17422             :             | JSON_ARRAYAGG '('
   17423             :                 json_value_expr
   17424             :                 json_array_aggregate_order_by_clause_opt
   17425             :                 json_array_constructor_null_clause_opt
   17426             :                 json_returning_clause_opt
   17427             :             ')'
   17428             :                 {
   17429         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17430             : 
   17431         156 :                     n->arg = (JsonValueExpr *) $3;
   17432         156 :                     n->absent_on_null = $5;
   17433         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17434         156 :                     n->constructor->agg_order = $4;
   17435         156 :                     n->constructor->output = (JsonOutput *) $6;
   17436         156 :                     n->constructor->location = @1;
   17437         156 :                     $$ = (Node *) n;
   17438             :                 }
   17439             :         ;
   17440             : 
   17441             : json_array_aggregate_order_by_clause_opt:
   17442          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17443         138 :             | /* EMPTY */                           { $$ = NIL; }
   17444             :         ;
   17445             : 
   17446             : /*****************************************************************************
   17447             :  *
   17448             :  *  target list for SELECT
   17449             :  *
   17450             :  *****************************************************************************/
   17451             : 
   17452      490762 : opt_target_list: target_list                        { $$ = $1; }
   17453         568 :             | /* EMPTY */                           { $$ = NIL; }
   17454             :         ;
   17455             : 
   17456             : target_list:
   17457      498144 :             target_el                               { $$ = list_make1($1); }
   17458      689724 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17459             :         ;
   17460             : 
   17461             : target_el:  a_expr AS ColLabel
   17462             :                 {
   17463      241522 :                     $$ = makeNode(ResTarget);
   17464      241522 :                     $$->name = $3;
   17465      241522 :                     $$->indirection = NIL;
   17466      241522 :                     $$->val = (Node *) $1;
   17467      241522 :                     $$->location = @1;
   17468             :                 }
   17469             :             | a_expr BareColLabel
   17470             :                 {
   17471        3598 :                     $$ = makeNode(ResTarget);
   17472        3598 :                     $$->name = $2;
   17473        3598 :                     $$->indirection = NIL;
   17474        3598 :                     $$->val = (Node *) $1;
   17475        3598 :                     $$->location = @1;
   17476             :                 }
   17477             :             | a_expr
   17478             :                 {
   17479      879248 :                     $$ = makeNode(ResTarget);
   17480      879248 :                     $$->name = NULL;
   17481      879248 :                     $$->indirection = NIL;
   17482      879248 :                     $$->val = (Node *) $1;
   17483      879248 :                     $$->location = @1;
   17484             :                 }
   17485             :             | '*'
   17486             :                 {
   17487       63500 :                     ColumnRef  *n = makeNode(ColumnRef);
   17488             : 
   17489       63500 :                     n->fields = list_make1(makeNode(A_Star));
   17490       63500 :                     n->location = @1;
   17491             : 
   17492       63500 :                     $$ = makeNode(ResTarget);
   17493       63500 :                     $$->name = NULL;
   17494       63500 :                     $$->indirection = NIL;
   17495       63500 :                     $$->val = (Node *) n;
   17496       63500 :                     $$->location = @1;
   17497             :                 }
   17498             :         ;
   17499             : 
   17500             : 
   17501             : /*****************************************************************************
   17502             :  *
   17503             :  *  Names and constants
   17504             :  *
   17505             :  *****************************************************************************/
   17506             : 
   17507             : qualified_name_list:
   17508       18338 :             qualified_name                          { $$ = list_make1($1); }
   17509         808 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17510             :         ;
   17511             : 
   17512             : /*
   17513             :  * The production for a qualified relation name has to exactly match the
   17514             :  * production for a qualified func_name, because in a FROM clause we cannot
   17515             :  * tell which we are parsing until we see what comes after it ('(' for a
   17516             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17517             :  * which may contain subscripts, and reject that case in the C code.
   17518             :  */
   17519             : qualified_name:
   17520             :             ColId
   17521             :                 {
   17522      441386 :                     $$ = makeRangeVar(NULL, $1, @1);
   17523             :                 }
   17524             :             | ColId indirection
   17525             :                 {
   17526      248564 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17527             :                 }
   17528             :         ;
   17529             : 
   17530             : name_list:  name
   17531       29586 :                     { $$ = list_make1(makeString($1)); }
   17532             :             | name_list ',' name
   17533       66086 :                     { $$ = lappend($1, makeString($3)); }
   17534             :         ;
   17535             : 
   17536             : 
   17537      182874 : name:       ColId                                   { $$ = $1; };
   17538             : 
   17539     1585920 : attr_name:  ColLabel                                { $$ = $1; };
   17540             : 
   17541          64 : file_name:  Sconst                                  { $$ = $1; };
   17542             : 
   17543             : /*
   17544             :  * The production for a qualified func_name has to exactly match the
   17545             :  * production for a qualified columnref, because we cannot tell which we
   17546             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17547             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17548             :  * may contain subscripts, and reject that case in the C code.  (If we
   17549             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17550             :  */
   17551             : func_name:  type_function_name
   17552      307366 :                     { $$ = list_make1(makeString($1)); }
   17553             :             | ColId indirection
   17554             :                     {
   17555      128872 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17556             :                                              yyscanner);
   17557             :                     }
   17558             :         ;
   17559             : 
   17560             : 
   17561             : /*
   17562             :  * Constants
   17563             :  */
   17564             : AexprConst: Iconst
   17565             :                 {
   17566      397340 :                     $$ = makeIntConst($1, @1);
   17567             :                 }
   17568             :             | FCONST
   17569             :                 {
   17570       12044 :                     $$ = makeFloatConst($1, @1);
   17571             :                 }
   17572             :             | Sconst
   17573             :                 {
   17574      717638 :                     $$ = makeStringConst($1, @1);
   17575             :                 }
   17576             :             | BCONST
   17577             :                 {
   17578         754 :                     $$ = makeBitStringConst($1, @1);
   17579             :                 }
   17580             :             | XCONST
   17581             :                 {
   17582             :                     /* This is a bit constant per SQL99:
   17583             :                      * Without Feature F511, "BIT data type",
   17584             :                      * a <general literal> shall not be a
   17585             :                      * <bit string literal> or a <hex string literal>.
   17586             :                      */
   17587        3302 :                     $$ = makeBitStringConst($1, @1);
   17588             :                 }
   17589             :             | func_name Sconst
   17590             :                 {
   17591             :                     /* generic type 'literal' syntax */
   17592        9848 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17593             : 
   17594        9848 :                     t->location = @1;
   17595        9848 :                     $$ = makeStringConstCast($2, @2, t);
   17596             :                 }
   17597             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17598             :                 {
   17599             :                     /* generic syntax with a type modifier */
   17600           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17601             :                     ListCell   *lc;
   17602             : 
   17603             :                     /*
   17604             :                      * We must use func_arg_list and opt_sort_clause in the
   17605             :                      * production to avoid reduce/reduce conflicts, but we
   17606             :                      * don't actually wish to allow NamedArgExpr in this
   17607             :                      * context, nor ORDER BY.
   17608             :                      */
   17609           0 :                     foreach(lc, $3)
   17610             :                     {
   17611           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17612             : 
   17613           0 :                         if (IsA(arg, NamedArgExpr))
   17614           0 :                             ereport(ERROR,
   17615             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17616             :                                      errmsg("type modifier cannot have parameter name"),
   17617             :                                      parser_errposition(arg->location)));
   17618             :                     }
   17619           0 :                     if ($4 != NIL)
   17620           0 :                             ereport(ERROR,
   17621             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17622             :                                      errmsg("type modifier cannot have ORDER BY"),
   17623             :                                      parser_errposition(@4)));
   17624             : 
   17625           0 :                     t->typmods = $3;
   17626           0 :                     t->location = @1;
   17627           0 :                     $$ = makeStringConstCast($6, @6, t);
   17628             :                 }
   17629             :             | ConstTypename Sconst
   17630             :                 {
   17631        3176 :                     $$ = makeStringConstCast($2, @2, $1);
   17632             :                 }
   17633             :             | ConstInterval Sconst opt_interval
   17634             :                 {
   17635        3298 :                     TypeName   *t = $1;
   17636             : 
   17637        3298 :                     t->typmods = $3;
   17638        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17639             :                 }
   17640             :             | ConstInterval '(' Iconst ')' Sconst
   17641             :                 {
   17642          12 :                     TypeName   *t = $1;
   17643             : 
   17644          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17645             :                                             makeIntConst($3, @3));
   17646          12 :                     $$ = makeStringConstCast($5, @5, t);
   17647             :                 }
   17648             :             | TRUE_P
   17649             :                 {
   17650       31540 :                     $$ = makeBoolAConst(true, @1);
   17651             :                 }
   17652             :             | FALSE_P
   17653             :                 {
   17654       36386 :                     $$ = makeBoolAConst(false, @1);
   17655             :                 }
   17656             :             | NULL_P
   17657             :                 {
   17658       69178 :                     $$ = makeNullAConst(@1);
   17659             :                 }
   17660             :         ;
   17661             : 
   17662      426250 : Iconst:     ICONST                                  { $$ = $1; };
   17663      792406 : Sconst:     SCONST                                  { $$ = $1; };
   17664             : 
   17665       17802 : SignedIconst: Iconst                                { $$ = $1; }
   17666           0 :             | '+' Iconst                            { $$ = + $2; }
   17667         288 :             | '-' Iconst                            { $$ = - $2; }
   17668             :         ;
   17669             : 
   17670             : /* Role specifications */
   17671             : RoleId:     RoleSpec
   17672             :                 {
   17673        1974 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17674             : 
   17675        1974 :                     switch (spc->roletype)
   17676             :                     {
   17677        1964 :                         case ROLESPEC_CSTRING:
   17678        1964 :                             $$ = spc->rolename;
   17679        1964 :                             break;
   17680           4 :                         case ROLESPEC_PUBLIC:
   17681           4 :                             ereport(ERROR,
   17682             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17683             :                                      errmsg("role name \"%s\" is reserved",
   17684             :                                             "public"),
   17685             :                                      parser_errposition(@1)));
   17686             :                             break;
   17687           2 :                         case ROLESPEC_SESSION_USER:
   17688           2 :                             ereport(ERROR,
   17689             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17690             :                                      errmsg("%s cannot be used as a role name here",
   17691             :                                             "SESSION_USER"),
   17692             :                                      parser_errposition(@1)));
   17693             :                             break;
   17694           2 :                         case ROLESPEC_CURRENT_USER:
   17695           2 :                             ereport(ERROR,
   17696             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17697             :                                      errmsg("%s cannot be used as a role name here",
   17698             :                                             "CURRENT_USER"),
   17699             :                                      parser_errposition(@1)));
   17700             :                             break;
   17701           2 :                         case ROLESPEC_CURRENT_ROLE:
   17702           2 :                             ereport(ERROR,
   17703             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17704             :                                      errmsg("%s cannot be used as a role name here",
   17705             :                                             "CURRENT_ROLE"),
   17706             :                                      parser_errposition(@1)));
   17707             :                             break;
   17708             :                     }
   17709             :                 }
   17710             :             ;
   17711             : 
   17712             : RoleSpec:   NonReservedWord
   17713             :                 {
   17714             :                     /*
   17715             :                      * "public" and "none" are not keywords, but they must
   17716             :                      * be treated specially here.
   17717             :                      */
   17718             :                     RoleSpec   *n;
   17719             : 
   17720       33390 :                     if (strcmp($1, "public") == 0)
   17721             :                     {
   17722       18216 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17723       18216 :                         n->roletype = ROLESPEC_PUBLIC;
   17724             :                     }
   17725       15174 :                     else if (strcmp($1, "none") == 0)
   17726             :                     {
   17727          26 :                         ereport(ERROR,
   17728             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17729             :                                  errmsg("role name \"%s\" is reserved",
   17730             :                                         "none"),
   17731             :                                  parser_errposition(@1)));
   17732             :                     }
   17733             :                     else
   17734             :                     {
   17735       15148 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17736       15148 :                         n->rolename = pstrdup($1);
   17737             :                     }
   17738       33364 :                     $$ = n;
   17739             :                 }
   17740             :             | CURRENT_ROLE
   17741             :                 {
   17742         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17743             :                 }
   17744             :             | CURRENT_USER
   17745             :                 {
   17746         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17747             :                 }
   17748             :             | SESSION_USER
   17749             :                 {
   17750          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17751             :                 }
   17752             :         ;
   17753             : 
   17754             : role_list:  RoleSpec
   17755        3290 :                 { $$ = list_make1($1); }
   17756             :             | role_list ',' RoleSpec
   17757         270 :                 { $$ = lappend($1, $3); }
   17758             :         ;
   17759             : 
   17760             : 
   17761             : /*****************************************************************************
   17762             :  *
   17763             :  * PL/pgSQL extensions
   17764             :  *
   17765             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17766             :  * historically it can include just about anything that can follow SELECT.
   17767             :  * Therefore the returned struct is a SelectStmt.
   17768             :  *****************************************************************************/
   17769             : 
   17770             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17771             :             from_clause where_clause
   17772             :             group_clause having_clause window_clause
   17773             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17774             :                 {
   17775       41514 :                     SelectStmt *n = makeNode(SelectStmt);
   17776             : 
   17777       41514 :                     n->distinctClause = $1;
   17778       41514 :                     n->targetList = $2;
   17779       41514 :                     n->fromClause = $3;
   17780       41514 :                     n->whereClause = $4;
   17781       41514 :                     n->groupClause = ($5)->list;
   17782       41514 :                     n->groupDistinct = ($5)->distinct;
   17783       41514 :                     n->groupByAll = ($5)->all;
   17784       41514 :                     n->havingClause = $6;
   17785       41514 :                     n->windowClause = $7;
   17786       41514 :                     n->sortClause = $8;
   17787       41514 :                     if ($9)
   17788             :                     {
   17789           4 :                         n->limitOffset = $9->limitOffset;
   17790           4 :                         n->limitCount = $9->limitCount;
   17791           4 :                         if (!n->sortClause &&
   17792           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17793           0 :                             ereport(ERROR,
   17794             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17795             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17796             :                                      parser_errposition($9->optionLoc)));
   17797           4 :                         n->limitOption = $9->limitOption;
   17798             :                     }
   17799       41514 :                     n->lockingClause = $10;
   17800       41514 :                     $$ = (Node *) n;
   17801             :                 }
   17802             :         ;
   17803             : 
   17804             : /*
   17805             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17806             :  */
   17807             : 
   17808             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17809             :                 {
   17810        7096 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17811             : 
   17812        7096 :                     n->name = $1;
   17813        7096 :                     n->indirection = check_indirection($2, yyscanner);
   17814             :                     /* nnames will be filled by calling production */
   17815        7044 :                     n->val = (SelectStmt *) $4;
   17816        7044 :                     n->location = @1;
   17817        7044 :                     $$ = (Node *) n;
   17818             :                 }
   17819             :         ;
   17820             : 
   17821        7072 : plassign_target: ColId                          { $$ = $1; }
   17822          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17823             :         ;
   17824             : 
   17825             : plassign_equals: COLON_EQUALS
   17826             :             | '='
   17827             :         ;
   17828             : 
   17829             : 
   17830             : /*
   17831             :  * Name classification hierarchy.
   17832             :  *
   17833             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17834             :  * no known keyword.  In most cases, we can accept certain keywords as
   17835             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17836             :  * as possible to minimize the impact of "reserved words" on programmers.
   17837             :  * So, we divide names into several possible classes.  The classification
   17838             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17839             :  */
   17840             : 
   17841             : /* Column identifier --- names that can be column, table, etc names.
   17842             :  */
   17843     3459540 : ColId:      IDENT                                   { $$ = $1; }
   17844       59684 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17845        6684 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17846             :         ;
   17847             : 
   17848             : /* Type/function identifier --- names that can be type or function names.
   17849             :  */
   17850      726404 : type_function_name: IDENT                           { $$ = $1; }
   17851       77336 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17852          66 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17853             :         ;
   17854             : 
   17855             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17856             :  */
   17857       86528 : NonReservedWord:    IDENT                           { $$ = $1; }
   17858       31344 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17859         220 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17860        6046 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17861             :         ;
   17862             : 
   17863             : /* Column label --- allowed labels in "AS" clauses.
   17864             :  * This presently includes *all* Postgres keywords.
   17865             :  */
   17866     1810590 : ColLabel:   IDENT                                   { $$ = $1; }
   17867       41564 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17868         290 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17869        1772 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17870        7638 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17871             :         ;
   17872             : 
   17873             : /* Bare column label --- names that can be column labels without writing "AS".
   17874             :  * This classification is orthogonal to the other keyword categories.
   17875             :  */
   17876        3584 : BareColLabel:   IDENT                               { $$ = $1; }
   17877          14 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17878             :         ;
   17879             : 
   17880             : 
   17881             : /*
   17882             :  * Keyword category lists.  Generally, every keyword present in
   17883             :  * the Postgres grammar should appear in exactly one of these lists.
   17884             :  *
   17885             :  * Put a new keyword into the first list that it can go into without causing
   17886             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17887             :  * categories of keywords.
   17888             :  *
   17889             :  * Make sure that each keyword's category in kwlist.h matches where
   17890             :  * it is listed here.  (Someday we may be able to generate these lists and
   17891             :  * kwlist.h's table from one source of truth.)
   17892             :  */
   17893             : 
   17894             : /* "Unreserved" keywords --- available for use as any kind of name.
   17895             :  */
   17896             : unreserved_keyword:
   17897             :               ABORT_P
   17898             :             | ABSENT
   17899             :             | ABSOLUTE_P
   17900             :             | ACCESS
   17901             :             | ACTION
   17902             :             | ADD_P
   17903             :             | ADMIN
   17904             :             | AFTER
   17905             :             | AGGREGATE
   17906             :             | ALSO
   17907             :             | ALTER
   17908             :             | ALWAYS
   17909             :             | ASENSITIVE
   17910             :             | ASSERTION
   17911             :             | ASSIGNMENT
   17912             :             | AT
   17913             :             | ATOMIC
   17914             :             | ATTACH
   17915             :             | ATTRIBUTE
   17916             :             | BACKWARD
   17917             :             | BEFORE
   17918             :             | BEGIN_P
   17919             :             | BREADTH
   17920             :             | BY
   17921             :             | CACHE
   17922             :             | CALL
   17923             :             | CALLED
   17924             :             | CASCADE
   17925             :             | CASCADED
   17926             :             | CATALOG_P
   17927             :             | CHAIN
   17928             :             | CHARACTERISTICS
   17929             :             | CHECKPOINT
   17930             :             | CLASS
   17931             :             | CLOSE
   17932             :             | CLUSTER
   17933             :             | COLUMNS
   17934             :             | COMMENT
   17935             :             | COMMENTS
   17936             :             | COMMIT
   17937             :             | COMMITTED
   17938             :             | COMPRESSION
   17939             :             | CONDITIONAL
   17940             :             | CONFIGURATION
   17941             :             | CONFLICT
   17942             :             | CONNECTION
   17943             :             | CONSTRAINTS
   17944             :             | CONTENT_P
   17945             :             | CONTINUE_P
   17946             :             | CONVERSION_P
   17947             :             | COPY
   17948             :             | COST
   17949             :             | CSV
   17950             :             | CUBE
   17951             :             | CURRENT_P
   17952             :             | CURSOR
   17953             :             | CYCLE
   17954             :             | DATA_P
   17955             :             | DATABASE
   17956             :             | DAY_P
   17957             :             | DEALLOCATE
   17958             :             | DECLARE
   17959             :             | DEFAULTS
   17960             :             | DEFERRED
   17961             :             | DEFINER
   17962             :             | DELETE_P
   17963             :             | DELIMITER
   17964             :             | DELIMITERS
   17965             :             | DEPENDS
   17966             :             | DEPTH
   17967             :             | DETACH
   17968             :             | DICTIONARY
   17969             :             | DISABLE_P
   17970             :             | DISCARD
   17971             :             | DOCUMENT_P
   17972             :             | DOMAIN_P
   17973             :             | DOUBLE_P
   17974             :             | DROP
   17975             :             | EACH
   17976             :             | EMPTY_P
   17977             :             | ENABLE_P
   17978             :             | ENCODING
   17979             :             | ENCRYPTED
   17980             :             | ENFORCED
   17981             :             | ENUM_P
   17982             :             | ERROR_P
   17983             :             | ESCAPE
   17984             :             | EVENT
   17985             :             | EXCLUDE
   17986             :             | EXCLUDING
   17987             :             | EXCLUSIVE
   17988             :             | EXECUTE
   17989             :             | EXPLAIN
   17990             :             | EXPRESSION
   17991             :             | EXTENSION
   17992             :             | EXTERNAL
   17993             :             | FAMILY
   17994             :             | FILTER
   17995             :             | FINALIZE
   17996             :             | FIRST_P
   17997             :             | FOLLOWING
   17998             :             | FORCE
   17999             :             | FORMAT
   18000             :             | FORWARD
   18001             :             | FUNCTION
   18002             :             | FUNCTIONS
   18003             :             | GENERATED
   18004             :             | GLOBAL
   18005             :             | GRANTED
   18006             :             | GROUPS
   18007             :             | HANDLER
   18008             :             | HEADER_P
   18009             :             | HOLD
   18010             :             | HOUR_P
   18011             :             | IDENTITY_P
   18012             :             | IF_P
   18013             :             | IGNORE_P
   18014             :             | IMMEDIATE
   18015             :             | IMMUTABLE
   18016             :             | IMPLICIT_P
   18017             :             | IMPORT_P
   18018             :             | INCLUDE
   18019             :             | INCLUDING
   18020             :             | INCREMENT
   18021             :             | INDENT
   18022             :             | INDEX
   18023             :             | INDEXES
   18024             :             | INHERIT
   18025             :             | INHERITS
   18026             :             | INLINE_P
   18027             :             | INPUT_P
   18028             :             | INSENSITIVE
   18029             :             | INSERT
   18030             :             | INSTEAD
   18031             :             | INVOKER
   18032             :             | ISOLATION
   18033             :             | KEEP
   18034             :             | KEY
   18035             :             | KEYS
   18036             :             | LABEL
   18037             :             | LANGUAGE
   18038             :             | LARGE_P
   18039             :             | LAST_P
   18040             :             | LEAKPROOF
   18041             :             | LEVEL
   18042             :             | LISTEN
   18043             :             | LOAD
   18044             :             | LOCAL
   18045             :             | LOCATION
   18046             :             | LOCK_P
   18047             :             | LOCKED
   18048             :             | LOGGED
   18049             :             | LSN_P
   18050             :             | MAPPING
   18051             :             | MATCH
   18052             :             | MATCHED
   18053             :             | MATERIALIZED
   18054             :             | MAXVALUE
   18055             :             | MERGE
   18056             :             | METHOD
   18057             :             | MINUTE_P
   18058             :             | MINVALUE
   18059             :             | MODE
   18060             :             | MONTH_P
   18061             :             | MOVE
   18062             :             | NAME_P
   18063             :             | NAMES
   18064             :             | NESTED
   18065             :             | NEW
   18066             :             | NEXT
   18067             :             | NFC
   18068             :             | NFD
   18069             :             | NFKC
   18070             :             | NFKD
   18071             :             | NO
   18072             :             | NORMALIZED
   18073             :             | NOTHING
   18074             :             | NOTIFY
   18075             :             | NOWAIT
   18076             :             | NULLS_P
   18077             :             | OBJECT_P
   18078             :             | OBJECTS_P
   18079             :             | OF
   18080             :             | OFF
   18081             :             | OIDS
   18082             :             | OLD
   18083             :             | OMIT
   18084             :             | OPERATOR
   18085             :             | OPTION
   18086             :             | OPTIONS
   18087             :             | ORDINALITY
   18088             :             | OTHERS
   18089             :             | OVER
   18090             :             | OVERRIDING
   18091             :             | OWNED
   18092             :             | OWNER
   18093             :             | PARALLEL
   18094             :             | PARAMETER
   18095             :             | PARSER
   18096             :             | PARTIAL
   18097             :             | PARTITION
   18098             :             | PARTITIONS
   18099             :             | PASSING
   18100             :             | PASSWORD
   18101             :             | PATH
   18102             :             | PERIOD
   18103             :             | PLAN
   18104             :             | PLANS
   18105             :             | POLICY
   18106             :             | PRECEDING
   18107             :             | PREPARE
   18108             :             | PREPARED
   18109             :             | PRESERVE
   18110             :             | PRIOR
   18111             :             | PRIVILEGES
   18112             :             | PROCEDURAL
   18113             :             | PROCEDURE
   18114             :             | PROCEDURES
   18115             :             | PROGRAM
   18116             :             | PUBLICATION
   18117             :             | QUOTE
   18118             :             | QUOTES
   18119             :             | RANGE
   18120             :             | READ
   18121             :             | REASSIGN
   18122             :             | RECURSIVE
   18123             :             | REF_P
   18124             :             | REFERENCING
   18125             :             | REFRESH
   18126             :             | REINDEX
   18127             :             | RELATIVE_P
   18128             :             | RELEASE
   18129             :             | RENAME
   18130             :             | REPEATABLE
   18131             :             | REPLACE
   18132             :             | REPLICA
   18133             :             | RESET
   18134             :             | RESPECT_P
   18135             :             | RESTART
   18136             :             | RESTRICT
   18137             :             | RETURN
   18138             :             | RETURNS
   18139             :             | REVOKE
   18140             :             | ROLE
   18141             :             | ROLLBACK
   18142             :             | ROLLUP
   18143             :             | ROUTINE
   18144             :             | ROUTINES
   18145             :             | ROWS
   18146             :             | RULE
   18147             :             | SAVEPOINT
   18148             :             | SCALAR
   18149             :             | SCHEMA
   18150             :             | SCHEMAS
   18151             :             | SCROLL
   18152             :             | SEARCH
   18153             :             | SECOND_P
   18154             :             | SECURITY
   18155             :             | SEQUENCE
   18156             :             | SEQUENCES
   18157             :             | SERIALIZABLE
   18158             :             | SERVER
   18159             :             | SESSION
   18160             :             | SET
   18161             :             | SETS
   18162             :             | SHARE
   18163             :             | SHOW
   18164             :             | SIMPLE
   18165             :             | SKIP
   18166             :             | SNAPSHOT
   18167             :             | SOURCE
   18168             :             | SPLIT
   18169             :             | SQL_P
   18170             :             | STABLE
   18171             :             | STANDALONE_P
   18172             :             | START
   18173             :             | STATEMENT
   18174             :             | STATISTICS
   18175             :             | STDIN
   18176             :             | STDOUT
   18177             :             | STORAGE
   18178             :             | STORED
   18179             :             | STRICT_P
   18180             :             | STRING_P
   18181             :             | STRIP_P
   18182             :             | SUBSCRIPTION
   18183             :             | SUPPORT
   18184             :             | SYSID
   18185             :             | SYSTEM_P
   18186             :             | TABLES
   18187             :             | TABLESPACE
   18188             :             | TARGET
   18189             :             | TEMP
   18190             :             | TEMPLATE
   18191             :             | TEMPORARY
   18192             :             | TEXT_P
   18193             :             | TIES
   18194             :             | TRANSACTION
   18195             :             | TRANSFORM
   18196             :             | TRIGGER
   18197             :             | TRUNCATE
   18198             :             | TRUSTED
   18199             :             | TYPE_P
   18200             :             | TYPES_P
   18201             :             | UESCAPE
   18202             :             | UNBOUNDED
   18203             :             | UNCOMMITTED
   18204             :             | UNCONDITIONAL
   18205             :             | UNENCRYPTED
   18206             :             | UNKNOWN
   18207             :             | UNLISTEN
   18208             :             | UNLOGGED
   18209             :             | UNTIL
   18210             :             | UPDATE
   18211             :             | VACUUM
   18212             :             | VALID
   18213             :             | VALIDATE
   18214             :             | VALIDATOR
   18215             :             | VALUE_P
   18216             :             | VARYING
   18217             :             | VERSION_P
   18218             :             | VIEW
   18219             :             | VIEWS
   18220             :             | VIRTUAL
   18221             :             | VOLATILE
   18222             :             | WAIT
   18223             :             | WHITESPACE_P
   18224             :             | WITHIN
   18225             :             | WITHOUT
   18226             :             | WORK
   18227             :             | WRAPPER
   18228             :             | WRITE
   18229             :             | XML_P
   18230             :             | YEAR_P
   18231             :             | YES_P
   18232             :             | ZONE
   18233             :         ;
   18234             : 
   18235             : /* Column identifier --- keywords that can be column, table, etc names.
   18236             :  *
   18237             :  * Many of these keywords will in fact be recognized as type or function
   18238             :  * names too; but they have special productions for the purpose, and so
   18239             :  * can't be treated as "generic" type or function names.
   18240             :  *
   18241             :  * The type names appearing here are not usable as function names
   18242             :  * because they can be followed by '(' in typename productions, which
   18243             :  * looks too much like a function call for an LR(1) parser.
   18244             :  */
   18245             : col_name_keyword:
   18246             :               BETWEEN
   18247             :             | BIGINT
   18248             :             | BIT
   18249             :             | BOOLEAN_P
   18250             :             | CHAR_P
   18251             :             | CHARACTER
   18252             :             | COALESCE
   18253             :             | DEC
   18254             :             | DECIMAL_P
   18255             :             | EXISTS
   18256             :             | EXTRACT
   18257             :             | FLOAT_P
   18258             :             | GREATEST
   18259             :             | GROUPING
   18260             :             | INOUT
   18261             :             | INT_P
   18262             :             | INTEGER
   18263             :             | INTERVAL
   18264             :             | JSON
   18265             :             | JSON_ARRAY
   18266             :             | JSON_ARRAYAGG
   18267             :             | JSON_EXISTS
   18268             :             | JSON_OBJECT
   18269             :             | JSON_OBJECTAGG
   18270             :             | JSON_QUERY
   18271             :             | JSON_SCALAR
   18272             :             | JSON_SERIALIZE
   18273             :             | JSON_TABLE
   18274             :             | JSON_VALUE
   18275             :             | LEAST
   18276             :             | MERGE_ACTION
   18277             :             | NATIONAL
   18278             :             | NCHAR
   18279             :             | NONE
   18280             :             | NORMALIZE
   18281             :             | NULLIF
   18282             :             | NUMERIC
   18283             :             | OUT_P
   18284             :             | OVERLAY
   18285             :             | POSITION
   18286             :             | PRECISION
   18287             :             | REAL
   18288             :             | ROW
   18289             :             | SETOF
   18290             :             | SMALLINT
   18291             :             | SUBSTRING
   18292             :             | TIME
   18293             :             | TIMESTAMP
   18294             :             | TREAT
   18295             :             | TRIM
   18296             :             | VALUES
   18297             :             | VARCHAR
   18298             :             | XMLATTRIBUTES
   18299             :             | XMLCONCAT
   18300             :             | XMLELEMENT
   18301             :             | XMLEXISTS
   18302             :             | XMLFOREST
   18303             :             | XMLNAMESPACES
   18304             :             | XMLPARSE
   18305             :             | XMLPI
   18306             :             | XMLROOT
   18307             :             | XMLSERIALIZE
   18308             :             | XMLTABLE
   18309             :         ;
   18310             : 
   18311             : /* Type/function identifier --- keywords that can be type or function names.
   18312             :  *
   18313             :  * Most of these are keywords that are used as operators in expressions;
   18314             :  * in general such keywords can't be column names because they would be
   18315             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18316             :  *
   18317             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18318             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18319             :  * - thomas 2000-11-28
   18320             :  */
   18321             : type_func_name_keyword:
   18322             :               AUTHORIZATION
   18323             :             | BINARY
   18324             :             | COLLATION
   18325             :             | CONCURRENTLY
   18326             :             | CROSS
   18327             :             | CURRENT_SCHEMA
   18328             :             | FREEZE
   18329             :             | FULL
   18330             :             | ILIKE
   18331             :             | INNER_P
   18332             :             | IS
   18333             :             | ISNULL
   18334             :             | JOIN
   18335             :             | LEFT
   18336             :             | LIKE
   18337             :             | NATURAL
   18338             :             | NOTNULL
   18339             :             | OUTER_P
   18340             :             | OVERLAPS
   18341             :             | RIGHT
   18342             :             | SIMILAR
   18343             :             | TABLESAMPLE
   18344             :             | VERBOSE
   18345             :         ;
   18346             : 
   18347             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18348             :  *
   18349             :  * Keywords appear here if they could not be distinguished from variable,
   18350             :  * type, or function names in some contexts.  Don't put things here unless
   18351             :  * forced to.
   18352             :  */
   18353             : reserved_keyword:
   18354             :               ALL
   18355             :             | ANALYSE
   18356             :             | ANALYZE
   18357             :             | AND
   18358             :             | ANY
   18359             :             | ARRAY
   18360             :             | AS
   18361             :             | ASC
   18362             :             | ASYMMETRIC
   18363             :             | BOTH
   18364             :             | CASE
   18365             :             | CAST
   18366             :             | CHECK
   18367             :             | COLLATE
   18368             :             | COLUMN
   18369             :             | CONSTRAINT
   18370             :             | CREATE
   18371             :             | CURRENT_CATALOG
   18372             :             | CURRENT_DATE
   18373             :             | CURRENT_ROLE
   18374             :             | CURRENT_TIME
   18375             :             | CURRENT_TIMESTAMP
   18376             :             | CURRENT_USER
   18377             :             | DEFAULT
   18378             :             | DEFERRABLE
   18379             :             | DESC
   18380             :             | DISTINCT
   18381             :             | DO
   18382             :             | ELSE
   18383             :             | END_P
   18384             :             | EXCEPT
   18385             :             | FALSE_P
   18386             :             | FETCH
   18387             :             | FOR
   18388             :             | FOREIGN
   18389             :             | FROM
   18390             :             | GRANT
   18391             :             | GROUP_P
   18392             :             | HAVING
   18393             :             | IN_P
   18394             :             | INITIALLY
   18395             :             | INTERSECT
   18396             :             | INTO
   18397             :             | LATERAL_P
   18398             :             | LEADING
   18399             :             | LIMIT
   18400             :             | LOCALTIME
   18401             :             | LOCALTIMESTAMP
   18402             :             | NOT
   18403             :             | NULL_P
   18404             :             | OFFSET
   18405             :             | ON
   18406             :             | ONLY
   18407             :             | OR
   18408             :             | ORDER
   18409             :             | PLACING
   18410             :             | PRIMARY
   18411             :             | REFERENCES
   18412             :             | RETURNING
   18413             :             | SELECT
   18414             :             | SESSION_USER
   18415             :             | SOME
   18416             :             | SYMMETRIC
   18417             :             | SYSTEM_USER
   18418             :             | TABLE
   18419             :             | THEN
   18420             :             | TO
   18421             :             | TRAILING
   18422             :             | TRUE_P
   18423             :             | UNION
   18424             :             | UNIQUE
   18425             :             | USER
   18426             :             | USING
   18427             :             | VARIADIC
   18428             :             | WHEN
   18429             :             | WHERE
   18430             :             | WINDOW
   18431             :             | WITH
   18432             :         ;
   18433             : 
   18434             : /*
   18435             :  * While all keywords can be used as column labels when preceded by AS,
   18436             :  * not all of them can be used as a "bare" column label without AS.
   18437             :  * Those that can be used as a bare label must be listed here,
   18438             :  * in addition to appearing in one of the category lists above.
   18439             :  *
   18440             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18441             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18442             :  */
   18443             : bare_label_keyword:
   18444             :               ABORT_P
   18445             :             | ABSENT
   18446             :             | ABSOLUTE_P
   18447             :             | ACCESS
   18448             :             | ACTION
   18449             :             | ADD_P
   18450             :             | ADMIN
   18451             :             | AFTER
   18452             :             | AGGREGATE
   18453             :             | ALL
   18454             :             | ALSO
   18455             :             | ALTER
   18456             :             | ALWAYS
   18457             :             | ANALYSE
   18458             :             | ANALYZE
   18459             :             | AND
   18460             :             | ANY
   18461             :             | ASC
   18462             :             | ASENSITIVE
   18463             :             | ASSERTION
   18464             :             | ASSIGNMENT
   18465             :             | ASYMMETRIC
   18466             :             | AT
   18467             :             | ATOMIC
   18468             :             | ATTACH
   18469             :             | ATTRIBUTE
   18470             :             | AUTHORIZATION
   18471             :             | BACKWARD
   18472             :             | BEFORE
   18473             :             | BEGIN_P
   18474             :             | BETWEEN
   18475             :             | BIGINT
   18476             :             | BINARY
   18477             :             | BIT
   18478             :             | BOOLEAN_P
   18479             :             | BOTH
   18480             :             | BREADTH
   18481             :             | BY
   18482             :             | CACHE
   18483             :             | CALL
   18484             :             | CALLED
   18485             :             | CASCADE
   18486             :             | CASCADED
   18487             :             | CASE
   18488             :             | CAST
   18489             :             | CATALOG_P
   18490             :             | CHAIN
   18491             :             | CHARACTERISTICS
   18492             :             | CHECK
   18493             :             | CHECKPOINT
   18494             :             | CLASS
   18495             :             | CLOSE
   18496             :             | CLUSTER
   18497             :             | COALESCE
   18498             :             | COLLATE
   18499             :             | COLLATION
   18500             :             | COLUMN
   18501             :             | COLUMNS
   18502             :             | COMMENT
   18503             :             | COMMENTS
   18504             :             | COMMIT
   18505             :             | COMMITTED
   18506             :             | COMPRESSION
   18507             :             | CONCURRENTLY
   18508             :             | CONDITIONAL
   18509             :             | CONFIGURATION
   18510             :             | CONFLICT
   18511             :             | CONNECTION
   18512             :             | CONSTRAINT
   18513             :             | CONSTRAINTS
   18514             :             | CONTENT_P
   18515             :             | CONTINUE_P
   18516             :             | CONVERSION_P
   18517             :             | COPY
   18518             :             | COST
   18519             :             | CROSS
   18520             :             | CSV
   18521             :             | CUBE
   18522             :             | CURRENT_P
   18523             :             | CURRENT_CATALOG
   18524             :             | CURRENT_DATE
   18525             :             | CURRENT_ROLE
   18526             :             | CURRENT_SCHEMA
   18527             :             | CURRENT_TIME
   18528             :             | CURRENT_TIMESTAMP
   18529             :             | CURRENT_USER
   18530             :             | CURSOR
   18531             :             | CYCLE
   18532             :             | DATA_P
   18533             :             | DATABASE
   18534             :             | DEALLOCATE
   18535             :             | DEC
   18536             :             | DECIMAL_P
   18537             :             | DECLARE
   18538             :             | DEFAULT
   18539             :             | DEFAULTS
   18540             :             | DEFERRABLE
   18541             :             | DEFERRED
   18542             :             | DEFINER
   18543             :             | DELETE_P
   18544             :             | DELIMITER
   18545             :             | DELIMITERS
   18546             :             | DEPENDS
   18547             :             | DEPTH
   18548             :             | DESC
   18549             :             | DETACH
   18550             :             | DICTIONARY
   18551             :             | DISABLE_P
   18552             :             | DISCARD
   18553             :             | DISTINCT
   18554             :             | DO
   18555             :             | DOCUMENT_P
   18556             :             | DOMAIN_P
   18557             :             | DOUBLE_P
   18558             :             | DROP
   18559             :             | EACH
   18560             :             | ELSE
   18561             :             | EMPTY_P
   18562             :             | ENABLE_P
   18563             :             | ENCODING
   18564             :             | ENCRYPTED
   18565             :             | END_P
   18566             :             | ENFORCED
   18567             :             | ENUM_P
   18568             :             | ERROR_P
   18569             :             | ESCAPE
   18570             :             | EVENT
   18571             :             | EXCLUDE
   18572             :             | EXCLUDING
   18573             :             | EXCLUSIVE
   18574             :             | EXECUTE
   18575             :             | EXISTS
   18576             :             | EXPLAIN
   18577             :             | EXPRESSION
   18578             :             | EXTENSION
   18579             :             | EXTERNAL
   18580             :             | EXTRACT
   18581             :             | FALSE_P
   18582             :             | FAMILY
   18583             :             | FINALIZE
   18584             :             | FIRST_P
   18585             :             | FLOAT_P
   18586             :             | FOLLOWING
   18587             :             | FORCE
   18588             :             | FOREIGN
   18589             :             | FORMAT
   18590             :             | FORWARD
   18591             :             | FREEZE
   18592             :             | FULL
   18593             :             | FUNCTION
   18594             :             | FUNCTIONS
   18595             :             | GENERATED
   18596             :             | GLOBAL
   18597             :             | GRANTED
   18598             :             | GREATEST
   18599             :             | GROUPING
   18600             :             | GROUPS
   18601             :             | HANDLER
   18602             :             | HEADER_P
   18603             :             | HOLD
   18604             :             | IDENTITY_P
   18605             :             | IF_P
   18606             :             | ILIKE
   18607             :             | IMMEDIATE
   18608             :             | IMMUTABLE
   18609             :             | IMPLICIT_P
   18610             :             | IMPORT_P
   18611             :             | IN_P
   18612             :             | INCLUDE
   18613             :             | INCLUDING
   18614             :             | INCREMENT
   18615             :             | INDENT
   18616             :             | INDEX
   18617             :             | INDEXES
   18618             :             | INHERIT
   18619             :             | INHERITS
   18620             :             | INITIALLY
   18621             :             | INLINE_P
   18622             :             | INNER_P
   18623             :             | INOUT
   18624             :             | INPUT_P
   18625             :             | INSENSITIVE
   18626             :             | INSERT
   18627             :             | INSTEAD
   18628             :             | INT_P
   18629             :             | INTEGER
   18630             :             | INTERVAL
   18631             :             | INVOKER
   18632             :             | IS
   18633             :             | ISOLATION
   18634             :             | JOIN
   18635             :             | JSON
   18636             :             | JSON_ARRAY
   18637             :             | JSON_ARRAYAGG
   18638             :             | JSON_EXISTS
   18639             :             | JSON_OBJECT
   18640             :             | JSON_OBJECTAGG
   18641             :             | JSON_QUERY
   18642             :             | JSON_SCALAR
   18643             :             | JSON_SERIALIZE
   18644             :             | JSON_TABLE
   18645             :             | JSON_VALUE
   18646             :             | KEEP
   18647             :             | KEY
   18648             :             | KEYS
   18649             :             | LABEL
   18650             :             | LANGUAGE
   18651             :             | LARGE_P
   18652             :             | LAST_P
   18653             :             | LATERAL_P
   18654             :             | LEADING
   18655             :             | LEAKPROOF
   18656             :             | LEAST
   18657             :             | LEFT
   18658             :             | LEVEL
   18659             :             | LIKE
   18660             :             | LISTEN
   18661             :             | LOAD
   18662             :             | LOCAL
   18663             :             | LOCALTIME
   18664             :             | LOCALTIMESTAMP
   18665             :             | LOCATION
   18666             :             | LOCK_P
   18667             :             | LOCKED
   18668             :             | LOGGED
   18669             :             | LSN_P
   18670             :             | MAPPING
   18671             :             | MATCH
   18672             :             | MATCHED
   18673             :             | MATERIALIZED
   18674             :             | MAXVALUE
   18675             :             | MERGE
   18676             :             | MERGE_ACTION
   18677             :             | METHOD
   18678             :             | MINVALUE
   18679             :             | MODE
   18680             :             | MOVE
   18681             :             | NAME_P
   18682             :             | NAMES
   18683             :             | NATIONAL
   18684             :             | NATURAL
   18685             :             | NCHAR
   18686             :             | NESTED
   18687             :             | NEW
   18688             :             | NEXT
   18689             :             | NFC
   18690             :             | NFD
   18691             :             | NFKC
   18692             :             | NFKD
   18693             :             | NO
   18694             :             | NONE
   18695             :             | NORMALIZE
   18696             :             | NORMALIZED
   18697             :             | NOT
   18698             :             | NOTHING
   18699             :             | NOTIFY
   18700             :             | NOWAIT
   18701             :             | NULL_P
   18702             :             | NULLIF
   18703             :             | NULLS_P
   18704             :             | NUMERIC
   18705             :             | OBJECT_P
   18706             :             | OBJECTS_P
   18707             :             | OF
   18708             :             | OFF
   18709             :             | OIDS
   18710             :             | OLD
   18711             :             | OMIT
   18712             :             | ONLY
   18713             :             | OPERATOR
   18714             :             | OPTION
   18715             :             | OPTIONS
   18716             :             | OR
   18717             :             | ORDINALITY
   18718             :             | OTHERS
   18719             :             | OUT_P
   18720             :             | OUTER_P
   18721             :             | OVERLAY
   18722             :             | OVERRIDING
   18723             :             | OWNED
   18724             :             | OWNER
   18725             :             | PARALLEL
   18726             :             | PARAMETER
   18727             :             | PARSER
   18728             :             | PARTIAL
   18729             :             | PARTITION
   18730             :             | PARTITIONS
   18731             :             | PASSING
   18732             :             | PASSWORD
   18733             :             | PATH
   18734             :             | PERIOD
   18735             :             | PLACING
   18736             :             | PLAN
   18737             :             | PLANS
   18738             :             | POLICY
   18739             :             | POSITION
   18740             :             | PRECEDING
   18741             :             | PREPARE
   18742             :             | PREPARED
   18743             :             | PRESERVE
   18744             :             | PRIMARY
   18745             :             | PRIOR
   18746             :             | PRIVILEGES
   18747             :             | PROCEDURAL
   18748             :             | PROCEDURE
   18749             :             | PROCEDURES
   18750             :             | PROGRAM
   18751             :             | PUBLICATION
   18752             :             | QUOTE
   18753             :             | QUOTES
   18754             :             | RANGE
   18755             :             | READ
   18756             :             | REAL
   18757             :             | REASSIGN
   18758             :             | RECURSIVE
   18759             :             | REF_P
   18760             :             | REFERENCES
   18761             :             | REFERENCING
   18762             :             | REFRESH
   18763             :             | REINDEX
   18764             :             | RELATIVE_P
   18765             :             | RELEASE
   18766             :             | RENAME
   18767             :             | REPEATABLE
   18768             :             | REPLACE
   18769             :             | REPLICA
   18770             :             | RESET
   18771             :             | RESTART
   18772             :             | RESTRICT
   18773             :             | RETURN
   18774             :             | RETURNS
   18775             :             | REVOKE
   18776             :             | RIGHT
   18777             :             | ROLE
   18778             :             | ROLLBACK
   18779             :             | ROLLUP
   18780             :             | ROUTINE
   18781             :             | ROUTINES
   18782             :             | ROW
   18783             :             | ROWS
   18784             :             | RULE
   18785             :             | SAVEPOINT
   18786             :             | SCALAR
   18787             :             | SCHEMA
   18788             :             | SCHEMAS
   18789             :             | SCROLL
   18790             :             | SEARCH
   18791             :             | SECURITY
   18792             :             | SELECT
   18793             :             | SEQUENCE
   18794             :             | SEQUENCES
   18795             :             | SERIALIZABLE
   18796             :             | SERVER
   18797             :             | SESSION
   18798             :             | SESSION_USER
   18799             :             | SET
   18800             :             | SETOF
   18801             :             | SETS
   18802             :             | SHARE
   18803             :             | SHOW
   18804             :             | SIMILAR
   18805             :             | SIMPLE
   18806             :             | SKIP
   18807             :             | SMALLINT
   18808             :             | SNAPSHOT
   18809             :             | SOME
   18810             :             | SOURCE
   18811             :             | SPLIT
   18812             :             | SQL_P
   18813             :             | STABLE
   18814             :             | STANDALONE_P
   18815             :             | START
   18816             :             | STATEMENT
   18817             :             | STATISTICS
   18818             :             | STDIN
   18819             :             | STDOUT
   18820             :             | STORAGE
   18821             :             | STORED
   18822             :             | STRICT_P
   18823             :             | STRING_P
   18824             :             | STRIP_P
   18825             :             | SUBSCRIPTION
   18826             :             | SUBSTRING
   18827             :             | SUPPORT
   18828             :             | SYMMETRIC
   18829             :             | SYSID
   18830             :             | SYSTEM_P
   18831             :             | SYSTEM_USER
   18832             :             | TABLE
   18833             :             | TABLES
   18834             :             | TABLESAMPLE
   18835             :             | TABLESPACE
   18836             :             | TARGET
   18837             :             | TEMP
   18838             :             | TEMPLATE
   18839             :             | TEMPORARY
   18840             :             | TEXT_P
   18841             :             | THEN
   18842             :             | TIES
   18843             :             | TIME
   18844             :             | TIMESTAMP
   18845             :             | TRAILING
   18846             :             | TRANSACTION
   18847             :             | TRANSFORM
   18848             :             | TREAT
   18849             :             | TRIGGER
   18850             :             | TRIM
   18851             :             | TRUE_P
   18852             :             | TRUNCATE
   18853             :             | TRUSTED
   18854             :             | TYPE_P
   18855             :             | TYPES_P
   18856             :             | UESCAPE
   18857             :             | UNBOUNDED
   18858             :             | UNCOMMITTED
   18859             :             | UNCONDITIONAL
   18860             :             | UNENCRYPTED
   18861             :             | UNIQUE
   18862             :             | UNKNOWN
   18863             :             | UNLISTEN
   18864             :             | UNLOGGED
   18865             :             | UNTIL
   18866             :             | UPDATE
   18867             :             | USER
   18868             :             | USING
   18869             :             | VACUUM
   18870             :             | VALID
   18871             :             | VALIDATE
   18872             :             | VALIDATOR
   18873             :             | VALUE_P
   18874             :             | VALUES
   18875             :             | VARCHAR
   18876             :             | VARIADIC
   18877             :             | VERBOSE
   18878             :             | VERSION_P
   18879             :             | VIEW
   18880             :             | VIEWS
   18881             :             | VIRTUAL
   18882             :             | VOLATILE
   18883             :             | WAIT
   18884             :             | WHEN
   18885             :             | WHITESPACE_P
   18886             :             | WORK
   18887             :             | WRAPPER
   18888             :             | WRITE
   18889             :             | XML_P
   18890             :             | XMLATTRIBUTES
   18891             :             | XMLCONCAT
   18892             :             | XMLELEMENT
   18893             :             | XMLEXISTS
   18894             :             | XMLFOREST
   18895             :             | XMLNAMESPACES
   18896             :             | XMLPARSE
   18897             :             | XMLPI
   18898             :             | XMLROOT
   18899             :             | XMLSERIALIZE
   18900             :             | XMLTABLE
   18901             :             | YES_P
   18902             :             | ZONE
   18903             :         ;
   18904             : 
   18905             : %%
   18906             : 
   18907             : /*
   18908             :  * The signature of this function is required by bison.  However, we
   18909             :  * ignore the passed yylloc and instead use the last token position
   18910             :  * available from the scanner.
   18911             :  */
   18912             : static void
   18913         706 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18914             : {
   18915         706 :     parser_yyerror(msg);
   18916             : }
   18917             : 
   18918             : static RawStmt *
   18919      850246 : makeRawStmt(Node *stmt, int stmt_location)
   18920             : {
   18921      850246 :     RawStmt    *rs = makeNode(RawStmt);
   18922             : 
   18923      850246 :     rs->stmt = stmt;
   18924      850246 :     rs->stmt_location = stmt_location;
   18925      850246 :     rs->stmt_len = 0;            /* might get changed later */
   18926      850246 :     return rs;
   18927             : }
   18928             : 
   18929             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18930             : static void
   18931      617228 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18932             : {
   18933             :     /*
   18934             :      * If we already set the length, don't change it.  This is for situations
   18935             :      * like "select foo ;; select bar" where the same statement will be last
   18936             :      * in the string for more than one semicolon.
   18937             :      */
   18938      617228 :     if (rs->stmt_len > 0)
   18939         674 :         return;
   18940             : 
   18941             :     /* OK, update length of RawStmt */
   18942      616554 :     rs->stmt_len = end_location - rs->stmt_location;
   18943             : }
   18944             : 
   18945             : static Node *
   18946     1847738 : makeColumnRef(char *colname, List *indirection,
   18947             :               int location, core_yyscan_t yyscanner)
   18948             : {
   18949             :     /*
   18950             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18951             :      * any subscripting in the specified indirection list.  However, any field
   18952             :      * selection at the start of the indirection list must be transposed into
   18953             :      * the "fields" part of the ColumnRef node.
   18954             :      */
   18955     1847738 :     ColumnRef  *c = makeNode(ColumnRef);
   18956     1847738 :     int         nfields = 0;
   18957             :     ListCell   *l;
   18958             : 
   18959     1847738 :     c->location = location;
   18960     2921442 :     foreach(l, indirection)
   18961             :     {
   18962     1083924 :         if (IsA(lfirst(l), A_Indices))
   18963             :         {
   18964       10220 :             A_Indirection *i = makeNode(A_Indirection);
   18965             : 
   18966       10220 :             if (nfields == 0)
   18967             :             {
   18968             :                 /* easy case - all indirection goes to A_Indirection */
   18969        7428 :                 c->fields = list_make1(makeString(colname));
   18970        7428 :                 i->indirection = check_indirection(indirection, yyscanner);
   18971             :             }
   18972             :             else
   18973             :             {
   18974             :                 /* got to split the list in two */
   18975        2792 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18976             :                                                                   nfields),
   18977             :                                                    yyscanner);
   18978        2792 :                 indirection = list_truncate(indirection, nfields);
   18979        2792 :                 c->fields = lcons(makeString(colname), indirection);
   18980             :             }
   18981       10220 :             i->arg = (Node *) c;
   18982       10220 :             return (Node *) i;
   18983             :         }
   18984     1073704 :         else if (IsA(lfirst(l), A_Star))
   18985             :         {
   18986             :             /* We only allow '*' at the end of a ColumnRef */
   18987        5656 :             if (lnext(indirection, l) != NULL)
   18988           0 :                 parser_yyerror("improper use of \"*\"");
   18989             :         }
   18990     1073704 :         nfields++;
   18991             :     }
   18992             :     /* No subscripting, so all indirection gets added to field list */
   18993     1837518 :     c->fields = lcons(makeString(colname), indirection);
   18994     1837518 :     return (Node *) c;
   18995             : }
   18996             : 
   18997             : static Node *
   18998      321162 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18999             : {
   19000      321162 :     TypeCast   *n = makeNode(TypeCast);
   19001             : 
   19002      321162 :     n->arg = arg;
   19003      321162 :     n->typeName = typename;
   19004      321162 :     n->location = location;
   19005      321162 :     return (Node *) n;
   19006             : }
   19007             : 
   19008             : static Node *
   19009       16334 : makeStringConstCast(char *str, int location, TypeName *typename)
   19010             : {
   19011       16334 :     Node       *s = makeStringConst(str, location);
   19012             : 
   19013       16334 :     return makeTypeCast(s, typename, -1);
   19014             : }
   19015             : 
   19016             : static Node *
   19017      407490 : makeIntConst(int val, int location)
   19018             : {
   19019      407490 :     A_Const    *n = makeNode(A_Const);
   19020             : 
   19021      407490 :     n->val.ival.type = T_Integer;
   19022      407490 :     n->val.ival.ival = val;
   19023      407490 :     n->location = location;
   19024             : 
   19025      407490 :     return (Node *) n;
   19026             : }
   19027             : 
   19028             : static Node *
   19029       12262 : makeFloatConst(char *str, int location)
   19030             : {
   19031       12262 :     A_Const    *n = makeNode(A_Const);
   19032             : 
   19033       12262 :     n->val.fval.type = T_Float;
   19034       12262 :     n->val.fval.fval = str;
   19035       12262 :     n->location = location;
   19036             : 
   19037       12262 :     return (Node *) n;
   19038             : }
   19039             : 
   19040             : static Node *
   19041       68186 : makeBoolAConst(bool state, int location)
   19042             : {
   19043       68186 :     A_Const    *n = makeNode(A_Const);
   19044             : 
   19045       68186 :     n->val.boolval.type = T_Boolean;
   19046       68186 :     n->val.boolval.boolval = state;
   19047       68186 :     n->location = location;
   19048             : 
   19049       68186 :     return (Node *) n;
   19050             : }
   19051             : 
   19052             : static Node *
   19053        4056 : makeBitStringConst(char *str, int location)
   19054             : {
   19055        4056 :     A_Const    *n = makeNode(A_Const);
   19056             : 
   19057        4056 :     n->val.bsval.type = T_BitString;
   19058        4056 :     n->val.bsval.bsval = str;
   19059        4056 :     n->location = location;
   19060             : 
   19061        4056 :     return (Node *) n;
   19062             : }
   19063             : 
   19064             : static Node *
   19065       69250 : makeNullAConst(int location)
   19066             : {
   19067       69250 :     A_Const    *n = makeNode(A_Const);
   19068             : 
   19069       69250 :     n->isnull = true;
   19070       69250 :     n->location = location;
   19071             : 
   19072       69250 :     return (Node *) n;
   19073             : }
   19074             : 
   19075             : static Node *
   19076        5470 : makeAConst(Node *v, int location)
   19077             : {
   19078             :     Node       *n;
   19079             : 
   19080        5470 :     switch (v->type)
   19081             :     {
   19082         218 :         case T_Float:
   19083         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   19084         218 :             break;
   19085             : 
   19086        5252 :         case T_Integer:
   19087        5252 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   19088        5252 :             break;
   19089             : 
   19090           0 :         default:
   19091             :             /* currently not used */
   19092             :             Assert(false);
   19093           0 :             n = NULL;
   19094             :     }
   19095             : 
   19096        5470 :     return n;
   19097             : }
   19098             : 
   19099             : /* makeRoleSpec
   19100             :  * Create a RoleSpec with the given type
   19101             :  */
   19102             : static RoleSpec *
   19103       34446 : makeRoleSpec(RoleSpecType type, int location)
   19104             : {
   19105       34446 :     RoleSpec   *spec = makeNode(RoleSpec);
   19106             : 
   19107       34446 :     spec->roletype = type;
   19108       34446 :     spec->location = location;
   19109             : 
   19110       34446 :     return spec;
   19111             : }
   19112             : 
   19113             : /* check_qualified_name --- check the result of qualified_name production
   19114             :  *
   19115             :  * It's easiest to let the grammar production for qualified_name allow
   19116             :  * subscripts and '*', which we then must reject here.
   19117             :  */
   19118             : static void
   19119      248596 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   19120             : {
   19121             :     ListCell   *i;
   19122             : 
   19123      497192 :     foreach(i, names)
   19124             :     {
   19125      248596 :         if (!IsA(lfirst(i), String))
   19126           0 :             parser_yyerror("syntax error");
   19127             :     }
   19128      248596 : }
   19129             : 
   19130             : /* check_func_name --- check the result of func_name production
   19131             :  *
   19132             :  * It's easiest to let the grammar production for func_name allow subscripts
   19133             :  * and '*', which we then must reject here.
   19134             :  */
   19135             : static List *
   19136      128900 : check_func_name(List *names, core_yyscan_t yyscanner)
   19137             : {
   19138             :     ListCell   *i;
   19139             : 
   19140      386700 :     foreach(i, names)
   19141             :     {
   19142      257800 :         if (!IsA(lfirst(i), String))
   19143           0 :             parser_yyerror("syntax error");
   19144             :     }
   19145      128900 :     return names;
   19146             : }
   19147             : 
   19148             : /* check_indirection --- check the result of indirection production
   19149             :  *
   19150             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   19151             :  * in the grammar, so do it here.
   19152             :  */
   19153             : static List *
   19154       84974 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   19155             : {
   19156             :     ListCell   *l;
   19157             : 
   19158      113262 :     foreach(l, indirection)
   19159             :     {
   19160       28288 :         if (IsA(lfirst(l), A_Star))
   19161             :         {
   19162        1508 :             if (lnext(indirection, l) != NULL)
   19163           0 :                 parser_yyerror("improper use of \"*\"");
   19164             :         }
   19165             :     }
   19166       84974 :     return indirection;
   19167             : }
   19168             : 
   19169             : /* extractArgTypes()
   19170             :  * Given a list of FunctionParameter nodes, extract a list of just the
   19171             :  * argument types (TypeNames) for input parameters only.  This is what
   19172             :  * is needed to look up an existing function, which is what is wanted by
   19173             :  * the productions that use this call.
   19174             :  */
   19175             : static List *
   19176       17538 : extractArgTypes(List *parameters)
   19177             : {
   19178       17538 :     List       *result = NIL;
   19179             :     ListCell   *i;
   19180             : 
   19181       38878 :     foreach(i, parameters)
   19182             :     {
   19183       21340 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19184             : 
   19185       21340 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19186       21184 :             result = lappend(result, p->argType);
   19187             :     }
   19188       17538 :     return result;
   19189             : }
   19190             : 
   19191             : /* extractAggrArgTypes()
   19192             :  * As above, but work from the output of the aggr_args production.
   19193             :  */
   19194             : static List *
   19195         362 : extractAggrArgTypes(List *aggrargs)
   19196             : {
   19197             :     Assert(list_length(aggrargs) == 2);
   19198         362 :     return extractArgTypes((List *) linitial(aggrargs));
   19199             : }
   19200             : 
   19201             : /* makeOrderedSetArgs()
   19202             :  * Build the result of the aggr_args production (which see the comments for).
   19203             :  * This handles only the case where both given lists are nonempty, so that
   19204             :  * we have to deal with multiple VARIADIC arguments.
   19205             :  */
   19206             : static List *
   19207          32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19208             :                    core_yyscan_t yyscanner)
   19209             : {
   19210          32 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19211             :     Integer    *ndirectargs;
   19212             : 
   19213             :     /* No restriction unless last direct arg is VARIADIC */
   19214          32 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19215             :     {
   19216          16 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19217             : 
   19218             :         /*
   19219             :          * We ignore the names, though the aggr_arg production allows them; it
   19220             :          * doesn't allow default values, so those need not be checked.
   19221             :          */
   19222          16 :         if (list_length(orderedargs) != 1 ||
   19223          16 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19224          16 :             !equal(lastd->argType, firsto->argType))
   19225           0 :             ereport(ERROR,
   19226             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19227             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19228             :                      parser_errposition(firsto->location)));
   19229             : 
   19230             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19231          16 :         orderedargs = NIL;
   19232             :     }
   19233             : 
   19234             :     /* don't merge into the next line, as list_concat changes directargs */
   19235          32 :     ndirectargs = makeInteger(list_length(directargs));
   19236             : 
   19237          32 :     return list_make2(list_concat(directargs, orderedargs),
   19238             :                       ndirectargs);
   19239             : }
   19240             : 
   19241             : /* insertSelectOptions()
   19242             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19243             :  *
   19244             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19245             :  */
   19246             : static void
   19247       90846 : insertSelectOptions(SelectStmt *stmt,
   19248             :                     List *sortClause, List *lockingClause,
   19249             :                     SelectLimit *limitClause,
   19250             :                     WithClause *withClause,
   19251             :                     core_yyscan_t yyscanner)
   19252             : {
   19253             :     Assert(IsA(stmt, SelectStmt));
   19254             : 
   19255             :     /*
   19256             :      * Tests here are to reject constructs like
   19257             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19258             :      */
   19259       90846 :     if (sortClause)
   19260             :     {
   19261       75600 :         if (stmt->sortClause)
   19262           0 :             ereport(ERROR,
   19263             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19264             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19265             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19266       75600 :         stmt->sortClause = sortClause;
   19267             :     }
   19268             :     /* We can handle multiple locking clauses, though */
   19269       90846 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19270       90846 :     if (limitClause && limitClause->limitOffset)
   19271             :     {
   19272         862 :         if (stmt->limitOffset)
   19273           0 :             ereport(ERROR,
   19274             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19275             :                      errmsg("multiple OFFSET clauses not allowed"),
   19276             :                      parser_errposition(limitClause->offsetLoc)));
   19277         862 :         stmt->limitOffset = limitClause->limitOffset;
   19278             :     }
   19279       90846 :     if (limitClause && limitClause->limitCount)
   19280             :     {
   19281        4816 :         if (stmt->limitCount)
   19282           0 :             ereport(ERROR,
   19283             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19284             :                      errmsg("multiple LIMIT clauses not allowed"),
   19285             :                      parser_errposition(limitClause->countLoc)));
   19286        4816 :         stmt->limitCount = limitClause->limitCount;
   19287             :     }
   19288       90846 :     if (limitClause)
   19289             :     {
   19290             :         /* If there was a conflict, we must have detected it above */
   19291             :         Assert(!stmt->limitOption);
   19292        5284 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19293           6 :             ereport(ERROR,
   19294             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19295             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19296             :                      parser_errposition(limitClause->optionLoc)));
   19297        5278 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19298             :         {
   19299             :             ListCell   *lc;
   19300             : 
   19301           6 :             foreach(lc, stmt->lockingClause)
   19302             :             {
   19303           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19304             : 
   19305           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19306           6 :                     ereport(ERROR,
   19307             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19308             :                              errmsg("%s and %s options cannot be used together",
   19309             :                                     "SKIP LOCKED", "WITH TIES"),
   19310             :                              parser_errposition(limitClause->optionLoc)));
   19311             :             }
   19312             :         }
   19313        5272 :         stmt->limitOption = limitClause->limitOption;
   19314             :     }
   19315       90834 :     if (withClause)
   19316             :     {
   19317        2922 :         if (stmt->withClause)
   19318           0 :             ereport(ERROR,
   19319             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19320             :                      errmsg("multiple WITH clauses not allowed"),
   19321             :                      parser_errposition(exprLocation((Node *) withClause))));
   19322        2922 :         stmt->withClause = withClause;
   19323             :     }
   19324       90834 : }
   19325             : 
   19326             : static Node *
   19327       20136 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   19328             : {
   19329       20136 :     SelectStmt *n = makeNode(SelectStmt);
   19330             : 
   19331       20136 :     n->op = op;
   19332       20136 :     n->all = all;
   19333       20136 :     n->larg = (SelectStmt *) larg;
   19334       20136 :     n->rarg = (SelectStmt *) rarg;
   19335       20136 :     return (Node *) n;
   19336             : }
   19337             : 
   19338             : /* SystemFuncName()
   19339             :  * Build a properly-qualified reference to a built-in function.
   19340             :  */
   19341             : List *
   19342       19822 : SystemFuncName(char *name)
   19343             : {
   19344       19822 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19345             : }
   19346             : 
   19347             : /* SystemTypeName()
   19348             :  * Build a properly-qualified reference to a built-in type.
   19349             :  *
   19350             :  * typmod is defaulted, but may be changed afterwards by caller.
   19351             :  * Likewise for the location.
   19352             :  */
   19353             : TypeName *
   19354      124420 : SystemTypeName(char *name)
   19355             : {
   19356      124420 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19357             :                                                makeString(name)));
   19358             : }
   19359             : 
   19360             : /* doNegate()
   19361             :  * Handle negation of a numeric constant.
   19362             :  *
   19363             :  * Formerly, we did this here because the optimizer couldn't cope with
   19364             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19365             :  * and a unary minus operator applied to a constant didn't qualify.
   19366             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19367             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19368             :  * there's still a good reason for doing this here, which is that we can
   19369             :  * postpone committing to a particular internal representation for simple
   19370             :  * negative constants.  It's better to leave "-123.456" in string form
   19371             :  * until we know what the desired type is.
   19372             :  */
   19373             : static Node *
   19374        9394 : doNegate(Node *n, int location)
   19375             : {
   19376        9394 :     if (IsA(n, A_Const))
   19377             :     {
   19378        8384 :         A_Const    *con = (A_Const *) n;
   19379             : 
   19380             :         /* report the constant's location as that of the '-' sign */
   19381        8384 :         con->location = location;
   19382             : 
   19383        8384 :         if (IsA(&con->val, Integer))
   19384             :         {
   19385        7426 :             con->val.ival.ival = -con->val.ival.ival;
   19386        7426 :             return n;
   19387             :         }
   19388         958 :         if (IsA(&con->val, Float))
   19389             :         {
   19390         958 :             doNegateFloat(&con->val.fval);
   19391         958 :             return n;
   19392             :         }
   19393             :     }
   19394             : 
   19395        1010 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19396             : }
   19397             : 
   19398             : static void
   19399         978 : doNegateFloat(Float *v)
   19400             : {
   19401         978 :     char       *oldval = v->fval;
   19402             : 
   19403         978 :     if (*oldval == '+')
   19404           0 :         oldval++;
   19405         978 :     if (*oldval == '-')
   19406           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19407             :     else
   19408         978 :         v->fval = psprintf("-%s", oldval);
   19409         978 : }
   19410             : 
   19411             : static Node *
   19412      236534 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19413             : {
   19414             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19415      236534 :     if (IsA(lexpr, BoolExpr))
   19416             :     {
   19417      111960 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19418             : 
   19419      111960 :         if (blexpr->boolop == AND_EXPR)
   19420             :         {
   19421      109404 :             blexpr->args = lappend(blexpr->args, rexpr);
   19422      109404 :             return (Node *) blexpr;
   19423             :         }
   19424             :     }
   19425      127130 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19426             : }
   19427             : 
   19428             : static Node *
   19429       16336 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19430             : {
   19431             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19432       16336 :     if (IsA(lexpr, BoolExpr))
   19433             :     {
   19434        5762 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19435             : 
   19436        5762 :         if (blexpr->boolop == OR_EXPR)
   19437             :         {
   19438        4196 :             blexpr->args = lappend(blexpr->args, rexpr);
   19439        4196 :             return (Node *) blexpr;
   19440             :         }
   19441             :     }
   19442       12140 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19443             : }
   19444             : 
   19445             : static Node *
   19446       16586 : makeNotExpr(Node *expr, int location)
   19447             : {
   19448       16586 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19449             : }
   19450             : 
   19451             : static Node *
   19452        8300 : makeAArrayExpr(List *elements, int location, int location_end)
   19453             : {
   19454        8300 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19455             : 
   19456        8300 :     n->elements = elements;
   19457        8300 :     n->location = location;
   19458        8300 :     n->list_start = location;
   19459        8300 :     n->list_end = location_end;
   19460        8300 :     return (Node *) n;
   19461             : }
   19462             : 
   19463             : static Node *
   19464        2768 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19465             : {
   19466        2768 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19467             : 
   19468        2768 :     svf->op = op;
   19469             :     /* svf->type will be filled during parse analysis */
   19470        2768 :     svf->typmod = typmod;
   19471        2768 :     svf->location = location;
   19472        2768 :     return (Node *) svf;
   19473             : }
   19474             : 
   19475             : static Node *
   19476         596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19477             :             int location)
   19478             : {
   19479         596 :     XmlExpr    *x = makeNode(XmlExpr);
   19480             : 
   19481         596 :     x->op = op;
   19482         596 :     x->name = name;
   19483             : 
   19484             :     /*
   19485             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19486             :      * expression and name lists in transformXmlExpr().
   19487             :      */
   19488         596 :     x->named_args = named_args;
   19489         596 :     x->arg_names = NIL;
   19490         596 :     x->args = args;
   19491             :     /* xmloption, if relevant, must be filled in by caller */
   19492             :     /* type and typmod will be filled in during parse analysis */
   19493         596 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19494         596 :     x->location = location;
   19495         596 :     return (Node *) x;
   19496             : }
   19497             : 
   19498             : /*
   19499             :  * Merge the input and output parameters of a table function.
   19500             :  */
   19501             : static List *
   19502         194 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19503             : {
   19504             :     ListCell   *lc;
   19505             : 
   19506             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19507         394 :     foreach(lc, func_args)
   19508             :     {
   19509         200 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19510             : 
   19511         200 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19512           0 :             p->mode != FUNC_PARAM_IN &&
   19513           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19514           0 :             ereport(ERROR,
   19515             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19516             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19517             :                      parser_errposition(p->location)));
   19518             :     }
   19519             : 
   19520         194 :     return list_concat(func_args, columns);
   19521             : }
   19522             : 
   19523             : /*
   19524             :  * Determine return type of a TABLE function.  A single result column
   19525             :  * returns setof that column's type; otherwise return setof record.
   19526             :  */
   19527             : static TypeName *
   19528         194 : TableFuncTypeName(List *columns)
   19529             : {
   19530             :     TypeName   *result;
   19531             : 
   19532         194 :     if (list_length(columns) == 1)
   19533             :     {
   19534          62 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19535             : 
   19536          62 :         result = copyObject(p->argType);
   19537             :     }
   19538             :     else
   19539         132 :         result = SystemTypeName("record");
   19540             : 
   19541         194 :     result->setof = true;
   19542             : 
   19543         194 :     return result;
   19544             : }
   19545             : 
   19546             : /*
   19547             :  * Convert a list of (dotted) names to a RangeVar (like
   19548             :  * makeRangeVarFromNameList, but with position support).  The
   19549             :  * "AnyName" refers to the any_name production in the grammar.
   19550             :  */
   19551             : static RangeVar *
   19552        4736 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19553             : {
   19554        4736 :     RangeVar   *r = makeNode(RangeVar);
   19555             : 
   19556        4736 :     switch (list_length(names))
   19557             :     {
   19558        4646 :         case 1:
   19559        4646 :             r->catalogname = NULL;
   19560        4646 :             r->schemaname = NULL;
   19561        4646 :             r->relname = strVal(linitial(names));
   19562        4646 :             break;
   19563          90 :         case 2:
   19564          90 :             r->catalogname = NULL;
   19565          90 :             r->schemaname = strVal(linitial(names));
   19566          90 :             r->relname = strVal(lsecond(names));
   19567          90 :             break;
   19568           0 :         case 3:
   19569           0 :             r->catalogname = strVal(linitial(names));
   19570           0 :             r->schemaname = strVal(lsecond(names));
   19571           0 :             r->relname = strVal(lthird(names));
   19572           0 :             break;
   19573           0 :         default:
   19574           0 :             ereport(ERROR,
   19575             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19576             :                      errmsg("improper qualified name (too many dotted names): %s",
   19577             :                             NameListToString(names)),
   19578             :                      parser_errposition(position)));
   19579             :             break;
   19580             :     }
   19581             : 
   19582        4736 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19583        4736 :     r->location = position;
   19584             : 
   19585        4736 :     return r;
   19586             : }
   19587             : 
   19588             : /*
   19589             :  * Convert a relation_name with name and namelist to a RangeVar using
   19590             :  * makeRangeVar.
   19591             :  */
   19592             : static RangeVar *
   19593      248596 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19594             :                               core_yyscan_t yyscanner)
   19595             : {
   19596             :     RangeVar   *r;
   19597             : 
   19598      248596 :     check_qualified_name(namelist, yyscanner);
   19599      248596 :     r = makeRangeVar(NULL, NULL, location);
   19600             : 
   19601      248596 :     switch (list_length(namelist))
   19602             :     {
   19603      248596 :         case 1:
   19604      248596 :             r->catalogname = NULL;
   19605      248596 :             r->schemaname = name;
   19606      248596 :             r->relname = strVal(linitial(namelist));
   19607      248596 :             break;
   19608           0 :         case 2:
   19609           0 :             r->catalogname = name;
   19610           0 :             r->schemaname = strVal(linitial(namelist));
   19611           0 :             r->relname = strVal(lsecond(namelist));
   19612           0 :             break;
   19613           0 :         default:
   19614           0 :             ereport(ERROR,
   19615             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19616             :                     errmsg("improper qualified name (too many dotted names): %s",
   19617             :                            NameListToString(lcons(makeString(name), namelist))),
   19618             :                     parser_errposition(location));
   19619             :             break;
   19620             :     }
   19621             : 
   19622      248596 :     return r;
   19623             : }
   19624             : 
   19625             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19626             : static void
   19627       72074 : SplitColQualList(List *qualList,
   19628             :                  List **constraintList, CollateClause **collClause,
   19629             :                  core_yyscan_t yyscanner)
   19630             : {
   19631             :     ListCell   *cell;
   19632             : 
   19633       72074 :     *collClause = NULL;
   19634       92764 :     foreach(cell, qualList)
   19635             :     {
   19636       20690 :         Node       *n = (Node *) lfirst(cell);
   19637             : 
   19638       20690 :         if (IsA(n, Constraint))
   19639             :         {
   19640             :             /* keep it in list */
   19641       19912 :             continue;
   19642             :         }
   19643         778 :         if (IsA(n, CollateClause))
   19644             :         {
   19645         778 :             CollateClause *c = (CollateClause *) n;
   19646             : 
   19647         778 :             if (*collClause)
   19648           0 :                 ereport(ERROR,
   19649             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19650             :                          errmsg("multiple COLLATE clauses not allowed"),
   19651             :                          parser_errposition(c->location)));
   19652         778 :             *collClause = c;
   19653             :         }
   19654             :         else
   19655           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19656             :         /* remove non-Constraint nodes from qualList */
   19657         778 :         qualList = foreach_delete_current(qualList, cell);
   19658             :     }
   19659       72074 :     *constraintList = qualList;
   19660       72074 : }
   19661             : 
   19662             : /*
   19663             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19664             :  * in the output command node.  Pass NULL for any flags the particular
   19665             :  * command doesn't support.
   19666             :  */
   19667             : static void
   19668       18202 : processCASbits(int cas_bits, int location, const char *constrType,
   19669             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19670             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19671             : {
   19672             :     /* defaults */
   19673       18202 :     if (deferrable)
   19674       16070 :         *deferrable = false;
   19675       18202 :     if (initdeferred)
   19676       16070 :         *initdeferred = false;
   19677       18202 :     if (not_valid)
   19678        3970 :         *not_valid = false;
   19679       18202 :     if (is_enforced)
   19680        3492 :         *is_enforced = true;
   19681             : 
   19682       18202 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19683             :     {
   19684         230 :         if (deferrable)
   19685         230 :             *deferrable = true;
   19686             :         else
   19687           0 :             ereport(ERROR,
   19688             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19689             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19690             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19691             :                             constrType),
   19692             :                      parser_errposition(location)));
   19693             :     }
   19694             : 
   19695       18202 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19696             :     {
   19697         146 :         if (initdeferred)
   19698         146 :             *initdeferred = true;
   19699             :         else
   19700           0 :             ereport(ERROR,
   19701             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19702             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19703             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19704             :                             constrType),
   19705             :                      parser_errposition(location)));
   19706             :     }
   19707             : 
   19708       18202 :     if (cas_bits & CAS_NOT_VALID)
   19709             :     {
   19710         744 :         if (not_valid)
   19711         744 :             *not_valid = true;
   19712             :         else
   19713           0 :             ereport(ERROR,
   19714             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19715             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19716             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19717             :                             constrType),
   19718             :                      parser_errposition(location)));
   19719             :     }
   19720             : 
   19721       18202 :     if (cas_bits & CAS_NO_INHERIT)
   19722             :     {
   19723         244 :         if (no_inherit)
   19724         244 :             *no_inherit = true;
   19725             :         else
   19726           0 :             ereport(ERROR,
   19727             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19728             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19729             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19730             :                             constrType),
   19731             :                      parser_errposition(location)));
   19732             :     }
   19733             : 
   19734       18202 :     if (cas_bits & CAS_NOT_ENFORCED)
   19735             :     {
   19736         174 :         if (is_enforced)
   19737         168 :             *is_enforced = false;
   19738             :         else
   19739           6 :             ereport(ERROR,
   19740             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19741             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19742             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19743             :                             constrType),
   19744             :                      parser_errposition(location)));
   19745             : 
   19746             :         /*
   19747             :          * NB: The validated status is irrelevant when the constraint is set to
   19748             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19749             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19750             :          * will automatically be in the correct NOT VALIDATED state.
   19751             :          */
   19752         168 :         if (not_valid)
   19753         132 :             *not_valid = true;
   19754             :     }
   19755             : 
   19756       18196 :     if (cas_bits & CAS_ENFORCED)
   19757             :     {
   19758         108 :         if (is_enforced)
   19759         102 :             *is_enforced = true;
   19760             :         else
   19761           6 :             ereport(ERROR,
   19762             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19763             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19764             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19765             :                             constrType),
   19766             :                      parser_errposition(location)));
   19767             :     }
   19768       18190 : }
   19769             : 
   19770             : /*
   19771             :  * Parse a user-supplied partition strategy string into parse node
   19772             :  * PartitionStrategy representation, or die trying.
   19773             :  */
   19774             : static PartitionStrategy
   19775        5600 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19776             : {
   19777        5600 :     if (pg_strcasecmp(strategy, "list") == 0)
   19778        2624 :         return PARTITION_STRATEGY_LIST;
   19779        2976 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19780        2692 :         return PARTITION_STRATEGY_RANGE;
   19781         284 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19782         278 :         return PARTITION_STRATEGY_HASH;
   19783             : 
   19784           6 :     ereport(ERROR,
   19785             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19786             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19787             :              parser_errposition(location)));
   19788             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19789             : 
   19790             : }
   19791             : 
   19792             : /*
   19793             :  * Process all_objects_list to set all_tables and/or all_sequences.
   19794             :  * Also, checks if the pub_object_type has been specified more than once.
   19795             :  */
   19796             : static void
   19797         138 : preprocess_pub_all_objtype_list(List *all_objects_list, bool *all_tables,
   19798             :                                 bool *all_sequences, core_yyscan_t yyscanner)
   19799             : {
   19800         138 :     if (!all_objects_list)
   19801           0 :         return;
   19802             : 
   19803         138 :     *all_tables = false;
   19804         138 :     *all_sequences = false;
   19805             : 
   19806         422 :     foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
   19807             :     {
   19808         170 :         if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
   19809             :         {
   19810         124 :             if (*all_tables)
   19811           6 :                 ereport(ERROR,
   19812             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19813             :                         errmsg("invalid publication object list"),
   19814             :                         errdetail("ALL TABLES can be specified only once."),
   19815             :                         parser_errposition(obj->location));
   19816             : 
   19817         118 :             *all_tables = true;
   19818             :         }
   19819          46 :         else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
   19820             :         {
   19821          46 :             if (*all_sequences)
   19822           6 :                 ereport(ERROR,
   19823             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19824             :                         errmsg("invalid publication object list"),
   19825             :                         errdetail("ALL SEQUENCES can be specified only once."),
   19826             :                         parser_errposition(obj->location));
   19827             : 
   19828          40 :             *all_sequences = true;
   19829             :         }
   19830             :     }
   19831             : }
   19832             : 
   19833             : /*
   19834             :  * Process pubobjspec_list to check for errors in any of the objects and
   19835             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19836             :  */
   19837             : static void
   19838        1650 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19839             : {
   19840             :     ListCell   *cell;
   19841             :     PublicationObjSpec *pubobj;
   19842        1650 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19843             : 
   19844        1650 :     if (!pubobjspec_list)
   19845           0 :         return;
   19846             : 
   19847        1650 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19848        1650 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19849          12 :         ereport(ERROR,
   19850             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19851             :                 errmsg("invalid publication object list"),
   19852             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19853             :                 parser_errposition(pubobj->location));
   19854             : 
   19855        3508 :     foreach(cell, pubobjspec_list)
   19856             :     {
   19857        1894 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19858             : 
   19859        1894 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19860         176 :             pubobj->pubobjtype = prevobjtype;
   19861             : 
   19862        1894 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19863             :         {
   19864             :             /* relation name or pubtable must be set for this type of object */
   19865        1450 :             if (!pubobj->name && !pubobj->pubtable)
   19866           6 :                 ereport(ERROR,
   19867             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19868             :                         errmsg("invalid table name"),
   19869             :                         parser_errposition(pubobj->location));
   19870             : 
   19871        1444 :             if (pubobj->name)
   19872             :             {
   19873             :                 /* convert it to PublicationTable */
   19874          60 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19875             : 
   19876          60 :                 pubtable->relation =
   19877          60 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19878          60 :                 pubobj->pubtable = pubtable;
   19879          60 :                 pubobj->name = NULL;
   19880             :             }
   19881             :         }
   19882         444 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19883          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19884             :         {
   19885             :             /* WHERE clause is not allowed on a schema object */
   19886         444 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19887           6 :                 ereport(ERROR,
   19888             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19889             :                         errmsg("WHERE clause not allowed for schema"),
   19890             :                         parser_errposition(pubobj->location));
   19891             : 
   19892             :             /* Column list is not allowed on a schema object */
   19893         438 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19894           6 :                 ereport(ERROR,
   19895             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19896             :                         errmsg("column specification not allowed for schema"),
   19897             :                         parser_errposition(pubobj->location));
   19898             : 
   19899             :             /*
   19900             :              * We can distinguish between the different type of schema objects
   19901             :              * based on whether name and pubtable is set.
   19902             :              */
   19903         432 :             if (pubobj->name)
   19904         402 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19905          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19906          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19907             :             else
   19908           6 :                 ereport(ERROR,
   19909             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19910             :                         errmsg("invalid schema name"),
   19911             :                         parser_errposition(pubobj->location));
   19912             :         }
   19913             : 
   19914        1870 :         prevobjtype = pubobj->pubobjtype;
   19915             :     }
   19916             : }
   19917             : 
   19918             : /*----------
   19919             :  * Recursive view transformation
   19920             :  *
   19921             :  * Convert
   19922             :  *
   19923             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19924             :  *
   19925             :  * to
   19926             :  *
   19927             :  *     CREATE VIEW relname (aliases) AS
   19928             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19929             :  *         SELECT aliases FROM relname
   19930             :  *
   19931             :  * Actually, just the WITH ... part, which is then inserted into the original
   19932             :  * view definition as the query.
   19933             :  * ----------
   19934             :  */
   19935             : static Node *
   19936          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19937             : {
   19938          14 :     SelectStmt *s = makeNode(SelectStmt);
   19939          14 :     WithClause *w = makeNode(WithClause);
   19940          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19941          14 :     List       *tl = NIL;
   19942             :     ListCell   *lc;
   19943             : 
   19944             :     /* create common table expression */
   19945          14 :     cte->ctename = relname;
   19946          14 :     cte->aliascolnames = aliases;
   19947          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19948          14 :     cte->ctequery = query;
   19949          14 :     cte->location = -1;
   19950             : 
   19951             :     /* create WITH clause and attach CTE */
   19952          14 :     w->recursive = true;
   19953          14 :     w->ctes = list_make1(cte);
   19954          14 :     w->location = -1;
   19955             : 
   19956             :     /*
   19957             :      * create target list for the new SELECT from the alias list of the
   19958             :      * recursive view specification
   19959             :      */
   19960          28 :     foreach(lc, aliases)
   19961             :     {
   19962          14 :         ResTarget  *rt = makeNode(ResTarget);
   19963             : 
   19964          14 :         rt->name = NULL;
   19965          14 :         rt->indirection = NIL;
   19966          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19967          14 :         rt->location = -1;
   19968             : 
   19969          14 :         tl = lappend(tl, rt);
   19970             :     }
   19971             : 
   19972             :     /*
   19973             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19974             :      * clause
   19975             :      */
   19976          14 :     s->withClause = w;
   19977          14 :     s->targetList = tl;
   19978          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19979             : 
   19980          14 :     return (Node *) s;
   19981             : }
   19982             : 
   19983             : /* parser_init()
   19984             :  * Initialize to parse one query string
   19985             :  */
   19986             : void
   19987      804410 : parser_init(base_yy_extra_type *yyext)
   19988             : {
   19989      804410 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19990      804410 : }

Generated by: LCOV version 1.16