LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 6774 7483 90.5 %
Date: 2025-04-24 12:15:10 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-2025, 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             :     List       *list;
     124             : } GroupClause;
     125             : 
     126             : /* Private structs for the result of key_actions and key_action productions */
     127             : typedef struct KeyAction
     128             : {
     129             :     char        action;
     130             :     List       *cols;
     131             : } KeyAction;
     132             : 
     133             : typedef struct KeyActions
     134             : {
     135             :     KeyAction *updateAction;
     136             :     KeyAction *deleteAction;
     137             : } KeyActions;
     138             : 
     139             : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
     140             : #define CAS_NOT_DEFERRABLE          0x01
     141             : #define CAS_DEFERRABLE              0x02
     142             : #define CAS_INITIALLY_IMMEDIATE     0x04
     143             : #define CAS_INITIALLY_DEFERRED      0x08
     144             : #define CAS_NOT_VALID               0x10
     145             : #define CAS_NO_INHERIT              0x20
     146             : #define CAS_NOT_ENFORCED            0x40
     147             : #define CAS_ENFORCED                0x80
     148             : 
     149             : 
     150             : #define parser_yyerror(msg)  scanner_yyerror(msg, yyscanner)
     151             : #define parser_errposition(pos)  scanner_errposition(pos, yyscanner)
     152             : 
     153             : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
     154             :                          const char *msg);
     155             : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
     156             : static void updateRawStmtEnd(RawStmt *rs, int end_location);
     157             : static void updatePreparableStmtEnd(Node *n, 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, int location);
     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);
     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_pubobj_list(List *pubobjspec_list,
     206             :                                    core_yyscan_t yyscanner);
     207             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     208             : 
     209             : %}
     210             : 
     211             : %pure-parser
     212             : %expect 0
     213             : %name-prefix="base_yy"
     214             : %locations
     215             : 
     216             : %parse-param {core_yyscan_t yyscanner}
     217             : %lex-param   {core_yyscan_t yyscanner}
     218             : 
     219             : %union
     220             : {
     221             :     core_YYSTYPE core_yystype;
     222             :     /* these fields must match core_YYSTYPE: */
     223             :     int         ival;
     224             :     char       *str;
     225             :     const char *keyword;
     226             : 
     227             :     char        chr;
     228             :     bool        boolean;
     229             :     JoinType    jtype;
     230             :     DropBehavior dbehavior;
     231             :     OnCommitAction oncommit;
     232             :     List       *list;
     233             :     Node       *node;
     234             :     ObjectType  objtype;
     235             :     TypeName   *typnam;
     236             :     FunctionParameter *fun_param;
     237             :     FunctionParameterMode fun_param_mode;
     238             :     ObjectWithArgs *objwithargs;
     239             :     DefElem    *defelt;
     240             :     SortBy     *sortby;
     241             :     WindowDef  *windef;
     242             :     JoinExpr   *jexpr;
     243             :     IndexElem  *ielem;
     244             :     StatsElem  *selem;
     245             :     Alias      *alias;
     246             :     RangeVar   *range;
     247             :     IntoClause *into;
     248             :     WithClause *with;
     249             :     InferClause *infer;
     250             :     OnConflictClause *onconflict;
     251             :     A_Indices  *aind;
     252             :     ResTarget  *target;
     253             :     struct PrivTarget *privtarget;
     254             :     AccessPriv *accesspriv;
     255             :     struct ImportQual *importqual;
     256             :     InsertStmt *istmt;
     257             :     VariableSetStmt *vsetstmt;
     258             :     PartitionElem *partelem;
     259             :     PartitionSpec *partspec;
     260             :     PartitionBoundSpec *partboundspec;
     261             :     RoleSpec   *rolespec;
     262             :     PublicationObjSpec *publicationobjectspec;
     263             :     struct SelectLimit *selectlimit;
     264             :     SetQuantifier setquantifier;
     265             :     struct GroupClause *groupclause;
     266             :     MergeMatchKind mergematch;
     267             :     MergeWhenClause *mergewhen;
     268             :     struct KeyActions *keyactions;
     269             :     struct KeyAction *keyaction;
     270             :     ReturningClause *retclause;
     271             :     ReturningOptionKind retoptionkind;
     272             : }
     273             : 
     274             : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     275             :         AlterEventTrigStmt AlterCollationStmt
     276             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     277             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     278             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     279             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     280             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     281             :         AlterCompositeTypeStmt AlterUserMappingStmt
     282             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     283             :         AlterDefaultPrivilegesStmt DefACLAction
     284             :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     285             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     286             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     287             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     288             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     289             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     290             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     291             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     292             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     293             :         DropOpClassStmt DropOpFamilyStmt DropStmt
     294             :         DropCastStmt DropRoleStmt
     295             :         DropdbStmt DropTableSpaceStmt
     296             :         DropTransformStmt
     297             :         DropUserMappingStmt ExplainStmt FetchStmt
     298             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     299             :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     300             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     301             :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     302             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     303             :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     304             :         UnlistenStmt UpdateStmt VacuumStmt
     305             :         VariableResetStmt VariableSetStmt VariableShowStmt
     306             :         ViewStmt CheckPointStmt CreateConversionStmt
     307             :         DeallocateStmt PrepareStmt ExecuteStmt
     308             :         DropOwnedStmt ReassignOwnedStmt
     309             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     310             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     311             :         CreatePublicationStmt AlterPublicationStmt
     312             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     313             : 
     314             : %type <node>  select_no_parens select_with_parens select_clause
     315             :                 simple_select values_clause
     316             :                 PLpgSQL_Expr PLAssignStmt
     317             : 
     318             : %type <str>           opt_single_name
     319             : %type <list>      opt_qualified_name
     320             : %type <boolean>       opt_concurrently
     321             : %type <dbehavior> opt_drop_behavior
     322             : 
     323             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     324             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     325             : 
     326             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     327             :        replica_identity partition_cmd index_partition_cmd
     328             : %type <list>  alter_table_cmds alter_type_cmds
     329             : %type <list>    alter_identity_column_option_list
     330             : %type <defelt>  alter_identity_column_option
     331             : %type <node>  set_statistics_value
     332             : %type <str>       set_access_method_name
     333             : 
     334             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     335             :                 transaction_mode_list
     336             :                 create_extension_opt_list alter_extension_opt_list
     337             : %type <defelt>    createdb_opt_item copy_opt_item
     338             :                 transaction_mode_item
     339             :                 create_extension_opt_item alter_extension_opt_item
     340             : 
     341             : %type <ival>  opt_lock lock_type cast_context
     342             : %type <str>       utility_option_name
     343             : %type <defelt>    utility_option_elem
     344             : %type <list>  utility_option_list
     345             : %type <node>  utility_option_arg
     346             : %type <defelt>    drop_option
     347             : %type <boolean>   opt_or_replace opt_no
     348             :                 opt_grant_grant_option
     349             :                 opt_nowait opt_if_exists opt_with_data
     350             :                 opt_transaction_chain
     351             : %type <list>  grant_role_opt_list
     352             : %type <defelt>    grant_role_opt
     353             : %type <node>  grant_role_opt_value
     354             : %type <ival>  opt_nowait_or_skip
     355             : 
     356             : %type <list>  OptRoleList AlterOptRoleList
     357             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     358             : 
     359             : %type <str>       opt_type
     360             : %type <str>       foreign_server_version opt_foreign_server_version
     361             : %type <str>       opt_in_database
     362             : 
     363             : %type <str>       parameter_name
     364             : %type <list>  OptSchemaEltList parameter_name_list
     365             : 
     366             : %type <chr>       am_type
     367             : 
     368             : %type <boolean> TriggerForSpec TriggerForType
     369             : %type <ival>  TriggerActionTime
     370             : %type <list>  TriggerEvents TriggerOneEvent
     371             : %type <node>  TriggerFuncArg
     372             : %type <node>  TriggerWhen
     373             : %type <str>       TransitionRelName
     374             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     375             : %type <node>  TriggerTransition
     376             : 
     377             : %type <list>  event_trigger_when_list event_trigger_value_list
     378             : %type <defelt>    event_trigger_when_item
     379             : %type <chr>       enable_trigger
     380             : 
     381             : %type <str>       copy_file_name
     382             :                 access_method_clause attr_name
     383             :                 table_access_method_clause name cursor_name file_name
     384             :                 cluster_index_specification
     385             : 
     386             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     387             :                 opt_inline_handler opt_validator validator_clause
     388             :                 opt_collate
     389             : 
     390             : %type <range> qualified_name insert_target OptConstrFromTable
     391             : 
     392             : %type <str>       all_Op MathOp
     393             : 
     394             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     395             : %type <boolean> RowSecurityDefaultPermissive
     396             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     397             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     398             : 
     399             : %type <str>       iso_level opt_encoding
     400             : %type <rolespec> grantee
     401             : %type <list>  grantee_list
     402             : %type <accesspriv> privilege
     403             : %type <list>  privileges privilege_list
     404             : %type <privtarget> privilege_target
     405             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     406             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     407             : %type <ival>  defacl_privilege_target
     408             : %type <defelt>    DefACLOption
     409             : %type <list>  DefACLOptionList
     410             : %type <ival>  import_qualification_type
     411             : %type <importqual> import_qualification
     412             : %type <node>  vacuum_relation
     413             : %type <selectlimit> opt_select_limit select_limit limit_clause
     414             : 
     415             : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     416             :                 OptTableElementList TableElementList OptInherit definition
     417             :                 OptTypedTableElementList TypedTableElementList
     418             :                 reloptions opt_reloptions
     419             :                 OptWith opt_definition func_args func_args_list
     420             :                 func_args_with_defaults func_args_with_defaults_list
     421             :                 aggr_args aggr_args_list
     422             :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     423             :                 old_aggr_definition old_aggr_list
     424             :                 oper_argtypes RuleActionList RuleActionMulti
     425             :                 opt_column_list columnList opt_name_list
     426             :                 sort_clause opt_sort_clause sortby_list index_params
     427             :                 stats_params
     428             :                 opt_include opt_c_include index_including_params
     429             :                 name_list role_list from_clause from_list opt_array_bounds
     430             :                 qualified_name_list any_name any_name_list type_name_list
     431             :                 any_operator expr_list attrs
     432             :                 distinct_clause opt_distinct_clause
     433             :                 target_list opt_target_list insert_column_list set_target_list
     434             :                 merge_values_clause
     435             :                 set_clause_list set_clause
     436             :                 def_list operator_def_list indirection opt_indirection
     437             :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     438             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     439             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     440             :                 prep_type_clause
     441             :                 execute_param_clause using_clause
     442             :                 returning_with_clause returning_options
     443             :                 opt_enum_val_list enum_val_list table_func_column_list
     444             :                 create_generic_options alter_generic_options
     445             :                 relation_expr_list dostmt_opt_list
     446             :                 transform_element_list transform_type_list
     447             :                 TriggerTransitions TriggerReferencing
     448             :                 vacuum_relation_list opt_vacuum_relation_list
     449             :                 drop_option_list pub_obj_list
     450             : 
     451             : %type <retclause> returning_clause
     452             : %type <node>  returning_option
     453             : %type <retoptionkind> returning_option_kind
     454             : %type <node>  opt_routine_body
     455             : %type <groupclause> group_clause
     456             : %type <list>  group_by_list
     457             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     458             : %type <node>  grouping_sets_clause
     459             : 
     460             : %type <list>  opt_fdw_options fdw_options
     461             : %type <defelt>    fdw_option
     462             : 
     463             : %type <range> OptTempTableName
     464             : %type <into>  into_clause create_as_target create_mv_target
     465             : 
     466             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     467             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     468             : %type <fun_param_mode> arg_class
     469             : %type <typnam>    func_return func_type
     470             : 
     471             : %type <boolean>  opt_trusted opt_restart_seqs
     472             : %type <ival>   OptTemp
     473             : %type <ival>   OptNoLog
     474             : %type <oncommit> OnCommitOption
     475             : 
     476             : %type <ival>  for_locking_strength
     477             : %type <node>  for_locking_item
     478             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     479             : %type <list>  locked_rels_list
     480             : %type <setquantifier> set_quantifier
     481             : 
     482             : %type <node>  join_qual
     483             : %type <jtype> join_type
     484             : 
     485             : %type <list>  extract_list overlay_list position_list
     486             : %type <list>  substr_list trim_list
     487             : %type <list>  opt_interval interval_second
     488             : %type <str>       unicode_normal_form
     489             : 
     490             : %type <boolean> opt_instead
     491             : %type <boolean> opt_unique opt_verbose opt_full
     492             : %type <boolean> opt_freeze opt_analyze opt_default
     493             : %type <defelt>    opt_binary copy_delimiter
     494             : 
     495             : %type <boolean> copy_from opt_program
     496             : 
     497             : %type <ival>  event cursor_options opt_hold opt_set_data
     498             : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     499             :                 drop_type_name
     500             : 
     501             : %type <node>  fetch_args select_limit_value
     502             :                 offset_clause select_offset_value
     503             :                 select_fetch_first_value I_or_F_const
     504             : %type <ival>  row_or_rows first_or_next
     505             : 
     506             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     507             : %type <defelt>    SeqOptElem
     508             : 
     509             : %type <istmt> insert_rest
     510             : %type <infer> opt_conf_expr
     511             : %type <onconflict> opt_on_conflict
     512             : %type <mergewhen> merge_insert merge_update merge_delete
     513             : 
     514             : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
     515             : %type <node>  merge_when_clause opt_merge_when_condition
     516             : %type <list>  merge_when_list
     517             : 
     518             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     519             :                  SetResetClause FunctionSetResetClause
     520             : 
     521             : %type <node>  TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
     522             : %type <node>  columnDef columnOptions optionalPeriodName
     523             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     524             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     525             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     526             :                 columnref in_expr having_clause func_table xmltable array_expr
     527             :                 OptWhereClause operator_def_arg
     528             : %type <list>  opt_column_and_period_list
     529             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     530             : %type <boolean> opt_ordinality opt_without_overlaps
     531             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     532             : %type <list>  func_arg_list func_arg_list_opt
     533             : %type <node>  func_arg_expr
     534             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     535             : %type <node>  case_expr case_arg when_clause case_default
     536             : %type <list>  when_clause_list
     537             : %type <node>  opt_search_clause opt_cycle_clause
     538             : %type <ival>  sub_type opt_materialized
     539             : %type <node>  NumericOnly
     540             : %type <list>  NumericOnly_list
     541             : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     542             : %type <list>  func_alias_clause
     543             : %type <sortby>    sortby
     544             : %type <ielem> index_elem index_elem_options
     545             : %type <selem> stats_param
     546             : %type <node>  table_ref
     547             : %type <jexpr> joined_table
     548             : %type <range> relation_expr
     549             : %type <range> extended_relation_expr
     550             : %type <range> relation_expr_opt_alias
     551             : %type <node>  tablesample_clause opt_repeatable_clause
     552             : %type <target>    target_el set_target insert_column_item
     553             : 
     554             : %type <str>       generic_option_name
     555             : %type <node>  generic_option_arg
     556             : %type <defelt>    generic_option_elem alter_generic_option_elem
     557             : %type <list>  generic_option_list alter_generic_option_list
     558             : 
     559             : %type <ival>  reindex_target_relation reindex_target_all
     560             : %type <list>  opt_reindex_option_list
     561             : 
     562             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     563             : %type <defelt>    copy_generic_opt_elem
     564             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     565             : %type <list>  copy_options
     566             : 
     567             : %type <typnam>    Typename SimpleTypename ConstTypename
     568             :                 GenericType Numeric opt_float JsonType
     569             :                 Character ConstCharacter
     570             :                 CharacterWithLength CharacterWithoutLength
     571             :                 ConstDatetime ConstInterval
     572             :                 Bit ConstBit BitWithLength BitWithoutLength
     573             : %type <str>       character
     574             : %type <str>       extract_arg
     575             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     576             : 
     577             : %type <ival>  Iconst SignedIconst
     578             : %type <str>       Sconst comment_text notify_payload
     579             : %type <str>       RoleId opt_boolean_or_string
     580             : %type <list>  var_list
     581             : %type <str>       ColId ColLabel BareColLabel
     582             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     583             : %type <str>       var_name type_function_name param_name
     584             : %type <str>       createdb_opt_name plassign_target
     585             : %type <node>  var_value zone_value
     586             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     587             : %type <publicationobjectspec> PublicationObjSpec
     588             : 
     589             : %type <keyword> unreserved_keyword type_func_name_keyword
     590             : %type <keyword> col_name_keyword reserved_keyword
     591             : %type <keyword> bare_label_keyword
     592             : 
     593             : %type <node>  DomainConstraint TableConstraint TableLikeClause
     594             : %type <ival>  TableLikeOptionList TableLikeOption
     595             : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     596             : %type <list>  ColQualList
     597             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     598             : %type <ival>  key_match
     599             : %type <keyaction> key_delete key_update key_action
     600             : %type <keyactions> key_actions
     601             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     602             : %type <str>       ExistingIndex
     603             : 
     604             : %type <list>  constraints_set_list
     605             : %type <boolean> constraints_set_mode
     606             : %type <str>       OptTableSpace OptConsTableSpace
     607             : %type <rolespec> OptTableSpaceOwner
     608             : %type <ival>  opt_check_option
     609             : 
     610             : %type <str>       opt_provider security_label
     611             : 
     612             : %type <target>    xml_attribute_el
     613             : %type <list>  xml_attribute_list xml_attributes
     614             : %type <node>  xml_root_version opt_xml_root_standalone
     615             : %type <node>  xmlexists_argument
     616             : %type <ival>  document_or_content
     617             : %type <boolean>   xml_indent_option xml_whitespace_option
     618             : %type <list>  xmltable_column_list xmltable_column_option_list
     619             : %type <node>  xmltable_column_el
     620             : %type <defelt>    xmltable_column_option_el
     621             : %type <list>  xml_namespace_list
     622             : %type <target>    xml_namespace_el
     623             : 
     624             : %type <node>  func_application func_expr_common_subexpr
     625             : %type <node>  func_expr func_expr_windowless
     626             : %type <node>  common_table_expr
     627             : %type <with>  with_clause opt_with_clause
     628             : %type <list>  cte_list
     629             : 
     630             : %type <list>  within_group_clause
     631             : %type <node>  filter_clause
     632             : %type <list>  window_clause window_definition_list opt_partition_clause
     633             : %type <windef>    window_definition over_clause window_specification
     634             :                 opt_frame_clause frame_extent frame_bound
     635             : %type <ival>  opt_window_exclusion_clause
     636             : %type <str>       opt_existing_window_name
     637             : %type <boolean> opt_if_not_exists
     638             : %type <boolean> opt_unique_null_treatment
     639             : %type <ival>  generated_when override_kind opt_virtual_or_stored
     640             : %type <partspec>  PartitionSpec OptPartitionSpec
     641             : %type <partelem>  part_elem
     642             : %type <list>      part_params
     643             : %type <partboundspec> PartitionBoundSpec
     644             : %type <list>      hash_partbound
     645             : %type <defelt>        hash_partbound_elem
     646             : 
     647             : %type <node>  json_format_clause
     648             :                 json_format_clause_opt
     649             :                 json_value_expr
     650             :                 json_returning_clause_opt
     651             :                 json_name_and_value
     652             :                 json_aggregate_func
     653             :                 json_argument
     654             :                 json_behavior
     655             :                 json_on_error_clause_opt
     656             :                 json_table
     657             :                 json_table_column_definition
     658             :                 json_table_column_path_clause_opt
     659             : %type <list>  json_name_and_value_list
     660             :                 json_value_expr_list
     661             :                 json_array_aggregate_order_by_clause_opt
     662             :                 json_arguments
     663             :                 json_behavior_clause_opt
     664             :                 json_passing_clause_opt
     665             :                 json_table_column_definition_list
     666             : %type <str>       json_table_path_name_opt
     667             : %type <ival>  json_behavior_type
     668             :                 json_predicate_type_constraint
     669             :                 json_quotes_clause_opt
     670             :                 json_wrapper_behavior
     671             : %type <boolean>   json_key_uniqueness_constraint_opt
     672             :                 json_object_constructor_null_clause_opt
     673             :                 json_array_constructor_null_clause_opt
     674             : 
     675             : 
     676             : /*
     677             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     678             :  * They must be listed first so that their numeric codes do not depend on
     679             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     680             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     681             :  *
     682             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     683             :  * they need no productions here; but we must assign token codes to them.
     684             :  *
     685             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     686             :  * parse errors.  It is needed by PL/pgSQL.
     687             :  */
     688             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     689             : %token <ival> ICONST PARAM
     690             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     691             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     692             : 
     693             : /*
     694             :  * If you want to make any keyword changes, update the keyword table in
     695             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     696             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     697             :  * this file for "Keyword category lists".
     698             :  */
     699             : 
     700             : /* ordinary key words in alphabetical order */
     701             : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     702             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     703             :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     704             : 
     705             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     706             :     BOOLEAN_P BOTH BREADTH BY
     707             : 
     708             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     709             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     710             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     711             :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     712             :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     713             :     COST CREATE CROSS CSV CUBE CURRENT_P
     714             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     715             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     716             : 
     717             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     718             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     719             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     720             :     DOUBLE_P DROP
     721             : 
     722             :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
     723             :     ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
     724             :     EXPRESSION EXTENSION EXTERNAL EXTRACT
     725             : 
     726             :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     727             :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     728             : 
     729             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     730             : 
     731             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     732             : 
     733             :     IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     734             :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     735             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     736             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     737             : 
     738             :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     739             :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
     740             : 
     741             :     KEEP KEY KEYS
     742             : 
     743             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     744             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     745             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     746             : 
     747             :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     748             :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     749             : 
     750             :     NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
     751             :     NONE NORMALIZE NORMALIZED
     752             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     753             :     NULLS_P NUMERIC
     754             : 
     755             :     OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     756             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     757             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     758             : 
     759             :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
     760             :     PERIOD PLACING PLAN PLANS POLICY
     761             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     762             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     763             : 
     764             :     QUOTE QUOTES
     765             : 
     766             :     RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
     767             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     768             :     RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     769             :     ROUTINE ROUTINES ROW ROWS RULE
     770             : 
     771             :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     772             :     SEQUENCE SEQUENCES
     773             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     774             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
     775             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     776             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     777             : 
     778             :     TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
     779             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     780             :     TREAT TRIGGER TRIM TRUE_P
     781             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     782             : 
     783             :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     784             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     785             : 
     786             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     787             :     VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
     788             : 
     789             :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     790             : 
     791             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     792             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     793             : 
     794             :     YEAR_P YES_P
     795             : 
     796             :     ZONE
     797             : 
     798             : /*
     799             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     800             :  * list and so can never be entered directly.  The filter in parser.c
     801             :  * creates these tokens when required (based on looking one token ahead).
     802             :  *
     803             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     804             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     805             :  * as NOT, at least with respect to their left-hand subexpression.
     806             :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     807             :  * LALR(1).
     808             :  */
     809             : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     810             : 
     811             : /*
     812             :  * The grammar likewise thinks these tokens are keywords, but they are never
     813             :  * generated by the scanner.  Rather, they can be injected by parser.c as
     814             :  * the initial token of the string (using the lookahead-token mechanism
     815             :  * implemented there).  This provides a way to tell the grammar to parse
     816             :  * something other than the usual list of SQL commands.
     817             :  */
     818             : %token      MODE_TYPE_NAME
     819             : %token      MODE_PLPGSQL_EXPR
     820             : %token      MODE_PLPGSQL_ASSIGN1
     821             : %token      MODE_PLPGSQL_ASSIGN2
     822             : %token      MODE_PLPGSQL_ASSIGN3
     823             : 
     824             : 
     825             : /* Precedence: lowest to highest */
     826             : %left       UNION EXCEPT
     827             : %left       INTERSECT
     828             : %left       OR
     829             : %left       AND
     830             : %right      NOT
     831             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     832             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     833             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     834             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     835             : 
     836             : /*
     837             :  * Sometimes it is necessary to assign precedence to keywords that are not
     838             :  * really part of the operator hierarchy, in order to resolve grammar
     839             :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     840             :  * assignments have global effect and may hide ambiguities besides the one
     841             :  * you intended to solve.  (Attaching a precedence to a single rule with
     842             :  * %prec is far safer and should be preferred.)  If you must give precedence
     843             :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     844             :  * If the keyword has IDENT's precedence then it clearly acts the same as
     845             :  * non-keywords and other similar keywords, thus reducing the risk of
     846             :  * unexpected precedence effects.
     847             :  *
     848             :  * We used to need to assign IDENT an explicit precedence just less than Op,
     849             :  * to support target_el without AS.  While that's not really necessary since
     850             :  * we removed postfix operators, we continue to do so because it provides a
     851             :  * reference point for a precedence level that we can assign to other
     852             :  * keywords that lack a natural precedence level.
     853             :  *
     854             :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     855             :  * opt_existing_window_name (see comment there).
     856             :  *
     857             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     858             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     859             :  * there is no principled way to distinguish these from the productions
     860             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     861             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     862             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     863             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     864             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     865             :  *
     866             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     867             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     868             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     869             :  * Using the same precedence as IDENT seems right for the reasons given above.
     870             :  *
     871             :  * SET is likewise assigned the same precedence as IDENT, to support the
     872             :  * relation_expr_opt_alias production (see comment there).
     873             :  *
     874             :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     875             :  * the same precedence as IDENT.  This allows resolving conflicts in the
     876             :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     877             :  * productions (see comments there).
     878             :  *
     879             :  * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
     880             :  * precedence than PATH to fix ambiguity in the json_table production.
     881             :  */
     882             : %nonassoc   UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
     883             : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     884             :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
     885             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     886             : %left       '+' '-'
     887             : %left       '*' '/' '%'
     888             : %left       '^'
     889             : /* Unary Operators */
     890             : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     891             : %left       COLLATE
     892             : %right      UMINUS
     893             : %left       '[' ']'
     894             : %left       '(' ')'
     895             : %left       TYPECAST
     896             : %left       '.'
     897             : /*
     898             :  * These might seem to be low-precedence, but actually they are not part
     899             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     900             :  * We make them high-precedence to support their use as function names.
     901             :  * They wouldn't be given a precedence at all, were it not that we need
     902             :  * left-associativity among the JOIN rules themselves.
     903             :  */
     904             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     905             : 
     906             : %%
     907             : 
     908             : /*
     909             :  *  The target production for the whole parse.
     910             :  *
     911             :  * Ordinarily we parse a list of statements, but if we see one of the
     912             :  * special MODE_XXX symbols as first token, we parse something else.
     913             :  * The options here correspond to enum RawParseMode, which see for details.
     914             :  */
     915             : parse_toplevel:
     916             :             stmtmulti
     917             :             {
     918      741818 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     919             :                 (void) yynerrs;     /* suppress compiler warning */
     920             :             }
     921             :             | MODE_TYPE_NAME Typename
     922             :             {
     923        9648 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     924             :             }
     925             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     926             :             {
     927       33236 :                 pg_yyget_extra(yyscanner)->parsetree =
     928       33236 :                     list_make1(makeRawStmt($2, @2));
     929             :             }
     930             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     931             :             {
     932        6326 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     933             : 
     934        6326 :                 n->nnames = 1;
     935        6326 :                 pg_yyget_extra(yyscanner)->parsetree =
     936        6326 :                     list_make1(makeRawStmt((Node *) n, @2));
     937             :             }
     938             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     939             :             {
     940         674 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     941             : 
     942         674 :                 n->nnames = 2;
     943         674 :                 pg_yyget_extra(yyscanner)->parsetree =
     944         674 :                     list_make1(makeRawStmt((Node *) n, @2));
     945             :             }
     946             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     947             :             {
     948          28 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     949             : 
     950          28 :                 n->nnames = 3;
     951          28 :                 pg_yyget_extra(yyscanner)->parsetree =
     952          28 :                     list_make1(makeRawStmt((Node *) n, @2));
     953             :             }
     954             :         ;
     955             : 
     956             : /*
     957             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     958             :  * and length of the stmt's text.
     959             :  * We also take care to discard empty statements entirely (which among other
     960             :  * things dodges the problem of assigning them a location).
     961             :  */
     962             : stmtmulti:  stmtmulti ';' toplevel_stmt
     963             :                 {
     964      592030 :                     if ($1 != NIL)
     965             :                     {
     966             :                         /* update length of previous stmt */
     967      591468 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     968             :                     }
     969      592030 :                     if ($3 != NULL)
     970       56058 :                         $$ = lappend($1, makeRawStmt($3, @3));
     971             :                     else
     972      535972 :                         $$ = $1;
     973             :                 }
     974             :             | toplevel_stmt
     975             :                 {
     976      741826 :                     if ($1 != NULL)
     977      740554 :                         $$ = list_make1(makeRawStmt($1, @1));
     978             :                     else
     979        1272 :                         $$ = NIL;
     980             :                 }
     981             :         ;
     982             : 
     983             : /*
     984             :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     985             :  * those words have different meanings in function bodies.
     986             :  */
     987             : toplevel_stmt:
     988             :             stmt
     989             :             | TransactionStmtLegacy
     990             :         ;
     991             : 
     992             : stmt:
     993             :             AlterEventTrigStmt
     994             :             | AlterCollationStmt
     995             :             | AlterDatabaseStmt
     996             :             | AlterDatabaseSetStmt
     997             :             | AlterDefaultPrivilegesStmt
     998             :             | AlterDomainStmt
     999             :             | AlterEnumStmt
    1000             :             | AlterExtensionStmt
    1001             :             | AlterExtensionContentsStmt
    1002             :             | AlterFdwStmt
    1003             :             | AlterForeignServerStmt
    1004             :             | AlterFunctionStmt
    1005             :             | AlterGroupStmt
    1006             :             | AlterObjectDependsStmt
    1007             :             | AlterObjectSchemaStmt
    1008             :             | AlterOwnerStmt
    1009             :             | AlterOperatorStmt
    1010             :             | AlterTypeStmt
    1011             :             | AlterPolicyStmt
    1012             :             | AlterSeqStmt
    1013             :             | AlterSystemStmt
    1014             :             | AlterTableStmt
    1015             :             | AlterTblSpcStmt
    1016             :             | AlterCompositeTypeStmt
    1017             :             | AlterPublicationStmt
    1018             :             | AlterRoleSetStmt
    1019             :             | AlterRoleStmt
    1020             :             | AlterSubscriptionStmt
    1021             :             | AlterStatsStmt
    1022             :             | AlterTSConfigurationStmt
    1023             :             | AlterTSDictionaryStmt
    1024             :             | AlterUserMappingStmt
    1025             :             | AnalyzeStmt
    1026             :             | CallStmt
    1027             :             | CheckPointStmt
    1028             :             | ClosePortalStmt
    1029             :             | ClusterStmt
    1030             :             | CommentStmt
    1031             :             | ConstraintsSetStmt
    1032             :             | CopyStmt
    1033             :             | CreateAmStmt
    1034             :             | CreateAsStmt
    1035             :             | CreateAssertionStmt
    1036             :             | CreateCastStmt
    1037             :             | CreateConversionStmt
    1038             :             | CreateDomainStmt
    1039             :             | CreateExtensionStmt
    1040             :             | CreateFdwStmt
    1041             :             | CreateForeignServerStmt
    1042             :             | CreateForeignTableStmt
    1043             :             | CreateFunctionStmt
    1044             :             | CreateGroupStmt
    1045             :             | CreateMatViewStmt
    1046             :             | CreateOpClassStmt
    1047             :             | CreateOpFamilyStmt
    1048             :             | CreatePublicationStmt
    1049             :             | AlterOpFamilyStmt
    1050             :             | CreatePolicyStmt
    1051             :             | CreatePLangStmt
    1052             :             | CreateSchemaStmt
    1053             :             | CreateSeqStmt
    1054             :             | CreateStmt
    1055             :             | CreateSubscriptionStmt
    1056             :             | CreateStatsStmt
    1057             :             | CreateTableSpaceStmt
    1058             :             | CreateTransformStmt
    1059             :             | CreateTrigStmt
    1060             :             | CreateEventTrigStmt
    1061             :             | CreateRoleStmt
    1062             :             | CreateUserStmt
    1063             :             | CreateUserMappingStmt
    1064             :             | CreatedbStmt
    1065             :             | DeallocateStmt
    1066             :             | DeclareCursorStmt
    1067             :             | DefineStmt
    1068             :             | DeleteStmt
    1069             :             | DiscardStmt
    1070             :             | DoStmt
    1071             :             | DropCastStmt
    1072             :             | DropOpClassStmt
    1073             :             | DropOpFamilyStmt
    1074             :             | DropOwnedStmt
    1075             :             | DropStmt
    1076             :             | DropSubscriptionStmt
    1077             :             | DropTableSpaceStmt
    1078             :             | DropTransformStmt
    1079             :             | DropRoleStmt
    1080             :             | DropUserMappingStmt
    1081             :             | DropdbStmt
    1082             :             | ExecuteStmt
    1083             :             | ExplainStmt
    1084             :             | FetchStmt
    1085             :             | GrantStmt
    1086             :             | GrantRoleStmt
    1087             :             | ImportForeignSchemaStmt
    1088             :             | IndexStmt
    1089             :             | InsertStmt
    1090             :             | ListenStmt
    1091             :             | RefreshMatViewStmt
    1092             :             | LoadStmt
    1093             :             | LockStmt
    1094             :             | MergeStmt
    1095             :             | NotifyStmt
    1096             :             | PrepareStmt
    1097             :             | ReassignOwnedStmt
    1098             :             | ReindexStmt
    1099             :             | RemoveAggrStmt
    1100             :             | RemoveFuncStmt
    1101             :             | RemoveOperStmt
    1102             :             | RenameStmt
    1103             :             | RevokeStmt
    1104             :             | RevokeRoleStmt
    1105             :             | RuleStmt
    1106             :             | SecLabelStmt
    1107             :             | SelectStmt
    1108             :             | TransactionStmt
    1109             :             | TruncateStmt
    1110             :             | UnlistenStmt
    1111             :             | UpdateStmt
    1112             :             | VacuumStmt
    1113             :             | VariableResetStmt
    1114             :             | VariableSetStmt
    1115             :             | VariableShowStmt
    1116             :             | ViewStmt
    1117             :             | /*EMPTY*/
    1118      537262 :                 { $$ = NULL; }
    1119             :         ;
    1120             : 
    1121             : /*
    1122             :  * Generic supporting productions for DDL
    1123             :  */
    1124             : opt_single_name:
    1125        5608 :             ColId                           { $$ = $1; }
    1126        1516 :             | /* EMPTY */                   { $$ = NULL; }
    1127             :         ;
    1128             : 
    1129             : opt_qualified_name:
    1130        1900 :             any_name                        { $$ = $1; }
    1131       15650 :             | /*EMPTY*/                     { $$ = NIL; }
    1132             :         ;
    1133             : 
    1134             : opt_concurrently:
    1135        1056 :             CONCURRENTLY                    { $$ = true; }
    1136        7814 :             | /*EMPTY*/                     { $$ = false; }
    1137             :         ;
    1138             : 
    1139             : opt_drop_behavior:
    1140        1958 :             CASCADE                         { $$ = DROP_CASCADE; }
    1141         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1142       39702 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1143             :         ;
    1144             : 
    1145             : /*****************************************************************************
    1146             :  *
    1147             :  * CALL statement
    1148             :  *
    1149             :  *****************************************************************************/
    1150             : 
    1151             : CallStmt:   CALL func_application
    1152             :                 {
    1153         620 :                     CallStmt   *n = makeNode(CallStmt);
    1154             : 
    1155         620 :                     n->funccall = castNode(FuncCall, $2);
    1156         620 :                     $$ = (Node *) n;
    1157             :                 }
    1158             :         ;
    1159             : 
    1160             : /*****************************************************************************
    1161             :  *
    1162             :  * Create a new Postgres DBMS role
    1163             :  *
    1164             :  *****************************************************************************/
    1165             : 
    1166             : CreateRoleStmt:
    1167             :             CREATE ROLE RoleId opt_with OptRoleList
    1168             :                 {
    1169        1366 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1170             : 
    1171        1366 :                     n->stmt_type = ROLESTMT_ROLE;
    1172        1366 :                     n->role = $3;
    1173        1366 :                     n->options = $5;
    1174        1366 :                     $$ = (Node *) n;
    1175             :                 }
    1176             :         ;
    1177             : 
    1178             : 
    1179             : opt_with:   WITH
    1180             :             | WITH_LA
    1181             :             | /*EMPTY*/
    1182             :         ;
    1183             : 
    1184             : /*
    1185             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1186             :  * for backwards compatibility).  Note: the only option required by SQL99
    1187             :  * is "WITH ADMIN name".
    1188             :  */
    1189             : OptRoleList:
    1190        1196 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1191        1846 :             | /* EMPTY */                           { $$ = NIL; }
    1192             :         ;
    1193             : 
    1194             : AlterOptRoleList:
    1195         658 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1196         418 :             | /* EMPTY */                           { $$ = NIL; }
    1197             :         ;
    1198             : 
    1199             : AlterOptRoleElem:
    1200             :             PASSWORD Sconst
    1201             :                 {
    1202         188 :                     $$ = makeDefElem("password",
    1203         188 :                                      (Node *) makeString($2), @1);
    1204             :                 }
    1205             :             | PASSWORD NULL_P
    1206             :                 {
    1207          12 :                     $$ = makeDefElem("password", NULL, @1);
    1208             :                 }
    1209             :             | ENCRYPTED PASSWORD Sconst
    1210             :                 {
    1211             :                     /*
    1212             :                      * These days, passwords are always stored in encrypted
    1213             :                      * form, so there is no difference between PASSWORD and
    1214             :                      * ENCRYPTED PASSWORD.
    1215             :                      */
    1216          18 :                     $$ = makeDefElem("password",
    1217          18 :                                      (Node *) makeString($3), @1);
    1218             :                 }
    1219             :             | UNENCRYPTED PASSWORD Sconst
    1220             :                 {
    1221           0 :                     ereport(ERROR,
    1222             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1223             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1224             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1225             :                              parser_errposition(@1)));
    1226             :                 }
    1227             :             | INHERIT
    1228             :                 {
    1229          96 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1230             :                 }
    1231             :             | CONNECTION LIMIT SignedIconst
    1232             :                 {
    1233          26 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1234             :                 }
    1235             :             | VALID UNTIL Sconst
    1236             :                 {
    1237           2 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1238             :                 }
    1239             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1240             :             | USER role_list
    1241             :                 {
    1242           6 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1243             :                 }
    1244             :             | IDENT
    1245             :                 {
    1246             :                     /*
    1247             :                      * We handle identifiers that aren't parser keywords with
    1248             :                      * the following special-case codes, to avoid bloating the
    1249             :                      * size of the main parser.
    1250             :                      */
    1251        1356 :                     if (strcmp($1, "superuser") == 0)
    1252         194 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1253        1162 :                     else if (strcmp($1, "nosuperuser") == 0)
    1254         100 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1255        1062 :                     else if (strcmp($1, "createrole") == 0)
    1256         102 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1257         960 :                     else if (strcmp($1, "nocreaterole") == 0)
    1258          38 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1259         922 :                     else if (strcmp($1, "replication") == 0)
    1260         132 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1261         790 :                     else if (strcmp($1, "noreplication") == 0)
    1262          96 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1263         694 :                     else if (strcmp($1, "createdb") == 0)
    1264          92 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1265         602 :                     else if (strcmp($1, "nocreatedb") == 0)
    1266          46 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1267         556 :                     else if (strcmp($1, "login") == 0)
    1268         284 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1269         272 :                     else if (strcmp($1, "nologin") == 0)
    1270          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1271         186 :                     else if (strcmp($1, "bypassrls") == 0)
    1272          82 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1273         104 :                     else if (strcmp($1, "nobypassrls") == 0)
    1274          68 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1275          36 :                     else if (strcmp($1, "noinherit") == 0)
    1276             :                     {
    1277             :                         /*
    1278             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1279             :                          * NOINHERIT is handled here.
    1280             :                          */
    1281          36 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1282             :                     }
    1283             :                     else
    1284           0 :                         ereport(ERROR,
    1285             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1286             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1287             :                                      parser_errposition(@1)));
    1288             :                 }
    1289             :         ;
    1290             : 
    1291             : CreateOptRoleElem:
    1292        1046 :             AlterOptRoleElem            { $$ = $1; }
    1293             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1294             :             | SYSID Iconst
    1295             :                 {
    1296           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1297             :                 }
    1298             :             | ADMIN role_list
    1299             :                 {
    1300          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1301             :                 }
    1302             :             | ROLE role_list
    1303             :                 {
    1304          22 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1305             :                 }
    1306             :             | IN_P ROLE role_list
    1307             :                 {
    1308         100 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1309             :                 }
    1310             :             | IN_P GROUP_P role_list
    1311             :                 {
    1312           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1313             :                 }
    1314             :         ;
    1315             : 
    1316             : 
    1317             : /*****************************************************************************
    1318             :  *
    1319             :  * Create a new Postgres DBMS user (role with implied login ability)
    1320             :  *
    1321             :  *****************************************************************************/
    1322             : 
    1323             : CreateUserStmt:
    1324             :             CREATE USER RoleId opt_with OptRoleList
    1325             :                 {
    1326         456 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1327             : 
    1328         456 :                     n->stmt_type = ROLESTMT_USER;
    1329         456 :                     n->role = $3;
    1330         456 :                     n->options = $5;
    1331         456 :                     $$ = (Node *) n;
    1332             :                 }
    1333             :         ;
    1334             : 
    1335             : 
    1336             : /*****************************************************************************
    1337             :  *
    1338             :  * Alter a postgresql DBMS role
    1339             :  *
    1340             :  *****************************************************************************/
    1341             : 
    1342             : AlterRoleStmt:
    1343             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1344             :                  {
    1345         326 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1346             : 
    1347         326 :                     n->role = $3;
    1348         326 :                     n->action = +1;  /* add, if there are members */
    1349         326 :                     n->options = $5;
    1350         326 :                     $$ = (Node *) n;
    1351             :                  }
    1352             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1353             :                  {
    1354          92 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1355             : 
    1356          92 :                     n->role = $3;
    1357          92 :                     n->action = +1;  /* add, if there are members */
    1358          92 :                     n->options = $5;
    1359          92 :                     $$ = (Node *) n;
    1360             :                  }
    1361             :         ;
    1362             : 
    1363             : opt_in_database:
    1364          86 :                /* EMPTY */                  { $$ = NULL; }
    1365           0 :             | IN_P DATABASE name    { $$ = $3; }
    1366             :         ;
    1367             : 
    1368             : AlterRoleSetStmt:
    1369             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1370             :                 {
    1371          48 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1372             : 
    1373          48 :                     n->role = $3;
    1374          48 :                     n->database = $4;
    1375          48 :                     n->setstmt = $5;
    1376          48 :                     $$ = (Node *) n;
    1377             :                 }
    1378             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1379             :                 {
    1380           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1381             : 
    1382           4 :                     n->role = NULL;
    1383           4 :                     n->database = $4;
    1384           4 :                     n->setstmt = $5;
    1385           4 :                     $$ = (Node *) n;
    1386             :                 }
    1387             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1388             :                 {
    1389          26 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1390             : 
    1391          26 :                     n->role = $3;
    1392          26 :                     n->database = $4;
    1393          26 :                     n->setstmt = $5;
    1394          26 :                     $$ = (Node *) n;
    1395             :                 }
    1396             :             | ALTER USER ALL opt_in_database SetResetClause
    1397             :                 {
    1398           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1399             : 
    1400           4 :                     n->role = NULL;
    1401           4 :                     n->database = $4;
    1402           4 :                     n->setstmt = $5;
    1403           4 :                     $$ = (Node *) n;
    1404             :                 }
    1405             :         ;
    1406             : 
    1407             : 
    1408             : /*****************************************************************************
    1409             :  *
    1410             :  * Drop a postgresql DBMS role
    1411             :  *
    1412             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1413             :  * might own objects in multiple databases, and there is presently no way to
    1414             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1415             :  *****************************************************************************/
    1416             : 
    1417             : DropRoleStmt:
    1418             :             DROP ROLE role_list
    1419             :                 {
    1420        1100 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1421             : 
    1422        1100 :                     n->missing_ok = false;
    1423        1100 :                     n->roles = $3;
    1424        1100 :                     $$ = (Node *) n;
    1425             :                 }
    1426             :             | DROP ROLE IF_P EXISTS role_list
    1427             :                 {
    1428         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1429             : 
    1430         134 :                     n->missing_ok = true;
    1431         134 :                     n->roles = $5;
    1432         134 :                     $$ = (Node *) n;
    1433             :                 }
    1434             :             | DROP USER role_list
    1435             :                 {
    1436         406 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1437             : 
    1438         406 :                     n->missing_ok = false;
    1439         406 :                     n->roles = $3;
    1440         406 :                     $$ = (Node *) n;
    1441             :                 }
    1442             :             | DROP USER IF_P EXISTS role_list
    1443             :                 {
    1444          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1445             : 
    1446          36 :                     n->roles = $5;
    1447          36 :                     n->missing_ok = true;
    1448          36 :                     $$ = (Node *) n;
    1449             :                 }
    1450             :             | DROP GROUP_P role_list
    1451             :                 {
    1452          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1453             : 
    1454          36 :                     n->missing_ok = false;
    1455          36 :                     n->roles = $3;
    1456          36 :                     $$ = (Node *) n;
    1457             :                 }
    1458             :             | DROP GROUP_P IF_P EXISTS role_list
    1459             :                 {
    1460           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1461             : 
    1462           6 :                     n->missing_ok = true;
    1463           6 :                     n->roles = $5;
    1464           6 :                     $$ = (Node *) n;
    1465             :                 }
    1466             :             ;
    1467             : 
    1468             : 
    1469             : /*****************************************************************************
    1470             :  *
    1471             :  * Create a postgresql group (role without login ability)
    1472             :  *
    1473             :  *****************************************************************************/
    1474             : 
    1475             : CreateGroupStmt:
    1476             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1477             :                 {
    1478          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1479             : 
    1480          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1481          24 :                     n->role = $3;
    1482          24 :                     n->options = $5;
    1483          24 :                     $$ = (Node *) n;
    1484             :                 }
    1485             :         ;
    1486             : 
    1487             : 
    1488             : /*****************************************************************************
    1489             :  *
    1490             :  * Alter a postgresql group
    1491             :  *
    1492             :  *****************************************************************************/
    1493             : 
    1494             : AlterGroupStmt:
    1495             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1496             :                 {
    1497          42 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1498             : 
    1499          42 :                     n->role = $3;
    1500          42 :                     n->action = $4;
    1501          42 :                     n->options = list_make1(makeDefElem("rolemembers",
    1502             :                                                         (Node *) $6, @6));
    1503          42 :                     $$ = (Node *) n;
    1504             :                 }
    1505             :         ;
    1506             : 
    1507          86 : add_drop:   ADD_P                                   { $$ = +1; }
    1508         198 :             | DROP                                  { $$ = -1; }
    1509             :         ;
    1510             : 
    1511             : 
    1512             : /*****************************************************************************
    1513             :  *
    1514             :  * Manipulate a schema
    1515             :  *
    1516             :  *****************************************************************************/
    1517             : 
    1518             : CreateSchemaStmt:
    1519             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1520             :                 {
    1521         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1522             : 
    1523             :                     /* One can omit the schema name or the authorization id. */
    1524         158 :                     n->schemaname = $3;
    1525         158 :                     n->authrole = $5;
    1526         158 :                     n->schemaElts = $6;
    1527         158 :                     n->if_not_exists = false;
    1528         158 :                     $$ = (Node *) n;
    1529             :                 }
    1530             :             | CREATE SCHEMA ColId OptSchemaEltList
    1531             :                 {
    1532         864 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1533             : 
    1534             :                     /* ...but not both */
    1535         864 :                     n->schemaname = $3;
    1536         864 :                     n->authrole = NULL;
    1537         864 :                     n->schemaElts = $4;
    1538         864 :                     n->if_not_exists = false;
    1539         864 :                     $$ = (Node *) n;
    1540             :                 }
    1541             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1542             :                 {
    1543          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1544             : 
    1545             :                     /* schema name can be omitted here, too */
    1546          18 :                     n->schemaname = $6;
    1547          18 :                     n->authrole = $8;
    1548          18 :                     if ($9 != NIL)
    1549           0 :                         ereport(ERROR,
    1550             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1551             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1552             :                                  parser_errposition(@9)));
    1553          18 :                     n->schemaElts = $9;
    1554          18 :                     n->if_not_exists = true;
    1555          18 :                     $$ = (Node *) n;
    1556             :                 }
    1557             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1558             :                 {
    1559          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1560             : 
    1561             :                     /* ...but not here */
    1562          34 :                     n->schemaname = $6;
    1563          34 :                     n->authrole = NULL;
    1564          34 :                     if ($7 != NIL)
    1565           6 :                         ereport(ERROR,
    1566             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1567             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1568             :                                  parser_errposition(@7)));
    1569          28 :                     n->schemaElts = $7;
    1570          28 :                     n->if_not_exists = true;
    1571          28 :                     $$ = (Node *) n;
    1572             :                 }
    1573             :         ;
    1574             : 
    1575             : OptSchemaEltList:
    1576             :             OptSchemaEltList schema_stmt
    1577             :                 {
    1578         546 :                     $$ = lappend($1, $2);
    1579             :                 }
    1580             :             | /* EMPTY */
    1581        1074 :                 { $$ = NIL; }
    1582             :         ;
    1583             : 
    1584             : /*
    1585             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1586             :  *  statement (in addition to by themselves).
    1587             :  */
    1588             : schema_stmt:
    1589             :             CreateStmt
    1590             :             | IndexStmt
    1591             :             | CreateSeqStmt
    1592             :             | CreateTrigStmt
    1593             :             | GrantStmt
    1594             :             | ViewStmt
    1595             :         ;
    1596             : 
    1597             : 
    1598             : /*****************************************************************************
    1599             :  *
    1600             :  * Set PG internal variable
    1601             :  *    SET name TO 'var_value'
    1602             :  * Include SQL syntax (thomas 1997-10-22):
    1603             :  *    SET TIME ZONE 'var_value'
    1604             :  *
    1605             :  *****************************************************************************/
    1606             : 
    1607             : VariableSetStmt:
    1608             :             SET set_rest
    1609             :                 {
    1610       22270 :                     VariableSetStmt *n = $2;
    1611             : 
    1612       22270 :                     n->is_local = false;
    1613       22270 :                     $$ = (Node *) n;
    1614             :                 }
    1615             :             | SET LOCAL set_rest
    1616             :                 {
    1617        1230 :                     VariableSetStmt *n = $3;
    1618             : 
    1619        1230 :                     n->is_local = true;
    1620        1230 :                     $$ = (Node *) n;
    1621             :                 }
    1622             :             | SET SESSION set_rest
    1623             :                 {
    1624          84 :                     VariableSetStmt *n = $3;
    1625             : 
    1626          84 :                     n->is_local = false;
    1627          84 :                     $$ = (Node *) n;
    1628             :                 }
    1629             :         ;
    1630             : 
    1631             : set_rest:
    1632             :             TRANSACTION transaction_mode_list
    1633             :                 {
    1634         684 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1635             : 
    1636         684 :                     n->kind = VAR_SET_MULTI;
    1637         684 :                     n->name = "TRANSACTION";
    1638         684 :                     n->args = $2;
    1639         684 :                     n->jumble_args = true;
    1640         684 :                     n->location = -1;
    1641         684 :                     $$ = n;
    1642             :                 }
    1643             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1644             :                 {
    1645          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1646             : 
    1647          18 :                     n->kind = VAR_SET_MULTI;
    1648          18 :                     n->name = "SESSION CHARACTERISTICS";
    1649          18 :                     n->args = $5;
    1650          18 :                     n->jumble_args = true;
    1651          18 :                     n->location = -1;
    1652          18 :                     $$ = n;
    1653             :                 }
    1654             :             | set_rest_more
    1655             :             ;
    1656             : 
    1657             : generic_set:
    1658             :             var_name TO var_list
    1659             :                 {
    1660        5204 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1661             : 
    1662        5204 :                     n->kind = VAR_SET_VALUE;
    1663        5204 :                     n->name = $1;
    1664        5204 :                     n->args = $3;
    1665        5204 :                     n->location = @3;
    1666        5204 :                     $$ = n;
    1667             :                 }
    1668             :             | var_name '=' var_list
    1669             :                 {
    1670       15340 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1671             : 
    1672       15340 :                     n->kind = VAR_SET_VALUE;
    1673       15340 :                     n->name = $1;
    1674       15340 :                     n->args = $3;
    1675       15340 :                     n->location = @3;
    1676       15340 :                     $$ = n;
    1677             :                 }
    1678             :             | var_name TO DEFAULT
    1679             :                 {
    1680         136 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1681             : 
    1682         136 :                     n->kind = VAR_SET_DEFAULT;
    1683         136 :                     n->name = $1;
    1684         136 :                     n->location = -1;
    1685         136 :                     $$ = n;
    1686             :                 }
    1687             :             | var_name '=' DEFAULT
    1688             :                 {
    1689          10 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1690             : 
    1691          10 :                     n->kind = VAR_SET_DEFAULT;
    1692          10 :                     n->name = $1;
    1693          10 :                     n->location = -1;
    1694          10 :                     $$ = n;
    1695             :                 }
    1696             :         ;
    1697             : 
    1698             : set_rest_more:  /* Generic SET syntaxes: */
    1699       20562 :             generic_set                         {$$ = $1;}
    1700             :             | var_name FROM CURRENT_P
    1701             :                 {
    1702           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1703             : 
    1704           4 :                     n->kind = VAR_SET_CURRENT;
    1705           4 :                     n->name = $1;
    1706           4 :                     n->location = -1;
    1707           4 :                     $$ = n;
    1708             :                 }
    1709             :             /* Special syntaxes mandated by SQL standard: */
    1710             :             | TIME ZONE zone_value
    1711             :                 {
    1712         104 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1713             : 
    1714         104 :                     n->kind = VAR_SET_VALUE;
    1715         104 :                     n->name = "timezone";
    1716         104 :                     n->location = -1;
    1717         104 :                     n->jumble_args = true;
    1718         104 :                     if ($3 != NULL)
    1719          88 :                         n->args = list_make1($3);
    1720             :                     else
    1721          16 :                         n->kind = VAR_SET_DEFAULT;
    1722         104 :                     $$ = n;
    1723             :                 }
    1724             :             | CATALOG_P Sconst
    1725             :                 {
    1726           0 :                     ereport(ERROR,
    1727             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1728             :                              errmsg("current database cannot be changed"),
    1729             :                              parser_errposition(@2)));
    1730             :                     $$ = NULL; /*not reached*/
    1731             :                 }
    1732             :             | SCHEMA Sconst
    1733             :                 {
    1734           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1735             : 
    1736           4 :                     n->kind = VAR_SET_VALUE;
    1737           4 :                     n->name = "search_path";
    1738           4 :                     n->args = list_make1(makeStringConst($2, @2));
    1739           4 :                     n->location = @2;
    1740           4 :                     $$ = n;
    1741             :                 }
    1742             :             | NAMES opt_encoding
    1743             :                 {
    1744           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1745             : 
    1746           0 :                     n->kind = VAR_SET_VALUE;
    1747           0 :                     n->name = "client_encoding";
    1748           0 :                     n->location = @2;
    1749           0 :                     if ($2 != NULL)
    1750           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1751             :                     else
    1752           0 :                         n->kind = VAR_SET_DEFAULT;
    1753           0 :                     $$ = n;
    1754             :                 }
    1755             :             | ROLE NonReservedWord_or_Sconst
    1756             :                 {
    1757         962 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1758             : 
    1759         962 :                     n->kind = VAR_SET_VALUE;
    1760         962 :                     n->name = "role";
    1761         962 :                     n->args = list_make1(makeStringConst($2, @2));
    1762         962 :                     n->location = @2;
    1763         962 :                     $$ = n;
    1764             :                 }
    1765             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1766             :                 {
    1767        2550 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1768             : 
    1769        2550 :                     n->kind = VAR_SET_VALUE;
    1770        2550 :                     n->name = "session_authorization";
    1771        2550 :                     n->args = list_make1(makeStringConst($3, @3));
    1772        2550 :                     n->location = @3;
    1773        2550 :                     $$ = n;
    1774             :                 }
    1775             :             | SESSION AUTHORIZATION DEFAULT
    1776             :                 {
    1777           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1778             : 
    1779           4 :                     n->kind = VAR_SET_DEFAULT;
    1780           4 :                     n->name = "session_authorization";
    1781           4 :                     n->location = -1;
    1782           4 :                     $$ = n;
    1783             :                 }
    1784             :             | XML_P OPTION document_or_content
    1785             :                 {
    1786          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1787             : 
    1788          16 :                     n->kind = VAR_SET_VALUE;
    1789          16 :                     n->name = "xmloption";
    1790          16 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1791          16 :                     n->jumble_args = true;
    1792          16 :                     n->location = -1;
    1793          16 :                     $$ = n;
    1794             :                 }
    1795             :             /* Special syntaxes invented by PostgreSQL: */
    1796             :             | TRANSACTION SNAPSHOT Sconst
    1797             :                 {
    1798          48 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1799             : 
    1800          48 :                     n->kind = VAR_SET_MULTI;
    1801          48 :                     n->name = "TRANSACTION SNAPSHOT";
    1802          48 :                     n->args = list_make1(makeStringConst($3, @3));
    1803          48 :                     n->location = @3;
    1804          48 :                     $$ = n;
    1805             :                 }
    1806             :         ;
    1807             : 
    1808       25314 : var_name:   ColId                               { $$ = $1; }
    1809             :             | var_name '.' ColId
    1810         466 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1811             :         ;
    1812             : 
    1813       20544 : var_list:   var_value                               { $$ = list_make1($1); }
    1814         176 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1815             :         ;
    1816             : 
    1817             : var_value:  opt_boolean_or_string
    1818       15016 :                 { $$ = makeStringConst($1, @1); }
    1819             :             | NumericOnly
    1820        5704 :                 { $$ = makeAConst($1, @1); }
    1821             :         ;
    1822             : 
    1823           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1824         908 :             | READ COMMITTED                        { $$ = "read committed"; }
    1825        2672 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1826        3196 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1827             :         ;
    1828             : 
    1829             : opt_boolean_or_string:
    1830         674 :             TRUE_P                                  { $$ = "true"; }
    1831        1452 :             | FALSE_P                               { $$ = "false"; }
    1832        2206 :             | ON                                    { $$ = "on"; }
    1833             :             /*
    1834             :              * OFF is also accepted as a boolean value, but is handled by
    1835             :              * the NonReservedWord rule.  The action for booleans and strings
    1836             :              * is the same, so we don't need to distinguish them here.
    1837             :              */
    1838       30134 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1839             :         ;
    1840             : 
    1841             : /* Timezone values can be:
    1842             :  * - a string such as 'pst8pdt'
    1843             :  * - an identifier such as "pst8pdt"
    1844             :  * - an integer or floating point number
    1845             :  * - a time interval per SQL99
    1846             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1847             :  * so use IDENT (meaning we reject anything that is a key word).
    1848             :  */
    1849             : zone_value:
    1850             :             Sconst
    1851             :                 {
    1852          60 :                     $$ = makeStringConst($1, @1);
    1853             :                 }
    1854             :             | IDENT
    1855             :                 {
    1856           4 :                     $$ = makeStringConst($1, @1);
    1857             :                 }
    1858             :             | ConstInterval Sconst opt_interval
    1859             :                 {
    1860           0 :                     TypeName   *t = $1;
    1861             : 
    1862           0 :                     if ($3 != NIL)
    1863             :                     {
    1864           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1865             : 
    1866           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1867           0 :                             ereport(ERROR,
    1868             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1869             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1870             :                                      parser_errposition(@3)));
    1871             :                     }
    1872           0 :                     t->typmods = $3;
    1873           0 :                     $$ = makeStringConstCast($2, @2, t);
    1874             :                 }
    1875             :             | ConstInterval '(' Iconst ')' Sconst
    1876             :                 {
    1877           0 :                     TypeName   *t = $1;
    1878             : 
    1879           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1880             :                                             makeIntConst($3, @3));
    1881           0 :                     $$ = makeStringConstCast($5, @5, t);
    1882             :                 }
    1883          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1884          14 :             | DEFAULT                               { $$ = NULL; }
    1885           2 :             | LOCAL                                 { $$ = NULL; }
    1886             :         ;
    1887             : 
    1888             : opt_encoding:
    1889           0 :             Sconst                                  { $$ = $1; }
    1890           0 :             | DEFAULT                               { $$ = NULL; }
    1891           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1892             :         ;
    1893             : 
    1894             : NonReservedWord_or_Sconst:
    1895       52864 :             NonReservedWord                         { $$ = $1; }
    1896        5484 :             | Sconst                                { $$ = $1; }
    1897             :         ;
    1898             : 
    1899             : VariableResetStmt:
    1900        4502 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1901             :         ;
    1902             : 
    1903             : reset_rest:
    1904        3722 :             generic_reset                           { $$ = $1; }
    1905             :             | TIME ZONE
    1906             :                 {
    1907          14 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1908             : 
    1909          14 :                     n->kind = VAR_RESET;
    1910          14 :                     n->name = "timezone";
    1911          14 :                     n->location = -1;
    1912          14 :                     $$ = n;
    1913             :                 }
    1914             :             | TRANSACTION ISOLATION LEVEL
    1915             :                 {
    1916           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1917             : 
    1918           0 :                     n->kind = VAR_RESET;
    1919           0 :                     n->name = "transaction_isolation";
    1920           0 :                     n->location = -1;
    1921           0 :                     $$ = n;
    1922             :                 }
    1923             :             | SESSION AUTHORIZATION
    1924             :                 {
    1925         766 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1926             : 
    1927         766 :                     n->kind = VAR_RESET;
    1928         766 :                     n->name = "session_authorization";
    1929         766 :                     n->location = -1;
    1930         766 :                     $$ = n;
    1931             :                 }
    1932             :         ;
    1933             : 
    1934             : generic_reset:
    1935             :             var_name
    1936             :                 {
    1937        3758 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1938             : 
    1939        3758 :                     n->kind = VAR_RESET;
    1940        3758 :                     n->name = $1;
    1941        3758 :                     n->location = -1;
    1942        3758 :                     $$ = n;
    1943             :                 }
    1944             :             | ALL
    1945             :                 {
    1946          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1947             : 
    1948          18 :                     n->kind = VAR_RESET_ALL;
    1949          18 :                     n->location = -1;
    1950          18 :                     $$ = n;
    1951             :                 }
    1952             :         ;
    1953             : 
    1954             : /* SetResetClause allows SET or RESET without LOCAL */
    1955             : SetResetClause:
    1956        1224 :             SET set_rest                    { $$ = $2; }
    1957          44 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1958             :         ;
    1959             : 
    1960             : /* SetResetClause allows SET or RESET without LOCAL */
    1961             : FunctionSetResetClause:
    1962         148 :             SET set_rest_more               { $$ = $2; }
    1963          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1964             :         ;
    1965             : 
    1966             : 
    1967             : VariableShowStmt:
    1968             :             SHOW var_name
    1969             :                 {
    1970         862 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1971             : 
    1972         862 :                     n->name = $2;
    1973         862 :                     $$ = (Node *) n;
    1974             :                 }
    1975             :             | SHOW TIME ZONE
    1976             :                 {
    1977          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1978             : 
    1979          10 :                     n->name = "timezone";
    1980          10 :                     $$ = (Node *) n;
    1981             :                 }
    1982             :             | SHOW TRANSACTION ISOLATION LEVEL
    1983             :                 {
    1984           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1985             : 
    1986           4 :                     n->name = "transaction_isolation";
    1987           4 :                     $$ = (Node *) n;
    1988             :                 }
    1989             :             | SHOW SESSION AUTHORIZATION
    1990             :                 {
    1991           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1992             : 
    1993           0 :                     n->name = "session_authorization";
    1994           0 :                     $$ = (Node *) n;
    1995             :                 }
    1996             :             | SHOW ALL
    1997             :                 {
    1998           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1999             : 
    2000           0 :                     n->name = "all";
    2001           0 :                     $$ = (Node *) n;
    2002             :                 }
    2003             :         ;
    2004             : 
    2005             : 
    2006             : ConstraintsSetStmt:
    2007             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    2008             :                 {
    2009         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2010             : 
    2011         104 :                     n->constraints = $3;
    2012         104 :                     n->deferred = $4;
    2013         104 :                     $$ = (Node *) n;
    2014             :                 }
    2015             :         ;
    2016             : 
    2017             : constraints_set_list:
    2018          56 :             ALL                                     { $$ = NIL; }
    2019          48 :             | qualified_name_list                   { $$ = $1; }
    2020             :         ;
    2021             : 
    2022             : constraints_set_mode:
    2023          68 :             DEFERRED                                { $$ = true; }
    2024          36 :             | IMMEDIATE                             { $$ = false; }
    2025             :         ;
    2026             : 
    2027             : 
    2028             : /*
    2029             :  * Checkpoint statement
    2030             :  */
    2031             : CheckPointStmt:
    2032             :             CHECKPOINT
    2033             :                 {
    2034         224 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2035             : 
    2036         224 :                     $$ = (Node *) n;
    2037             :                 }
    2038             :         ;
    2039             : 
    2040             : 
    2041             : /*****************************************************************************
    2042             :  *
    2043             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2044             :  *
    2045             :  *****************************************************************************/
    2046             : 
    2047             : DiscardStmt:
    2048             :             DISCARD ALL
    2049             :                 {
    2050           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2051             : 
    2052           6 :                     n->target = DISCARD_ALL;
    2053           6 :                     $$ = (Node *) n;
    2054             :                 }
    2055             :             | DISCARD TEMP
    2056             :                 {
    2057           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2058             : 
    2059           8 :                     n->target = DISCARD_TEMP;
    2060           8 :                     $$ = (Node *) n;
    2061             :                 }
    2062             :             | DISCARD TEMPORARY
    2063             :                 {
    2064           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2065             : 
    2066           0 :                     n->target = DISCARD_TEMP;
    2067           0 :                     $$ = (Node *) n;
    2068             :                 }
    2069             :             | DISCARD PLANS
    2070             :                 {
    2071           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2072             : 
    2073           4 :                     n->target = DISCARD_PLANS;
    2074           4 :                     $$ = (Node *) n;
    2075             :                 }
    2076             :             | DISCARD SEQUENCES
    2077             :                 {
    2078          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2079             : 
    2080          12 :                     n->target = DISCARD_SEQUENCES;
    2081          12 :                     $$ = (Node *) n;
    2082             :                 }
    2083             : 
    2084             :         ;
    2085             : 
    2086             : 
    2087             : /*****************************************************************************
    2088             :  *
    2089             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2090             :  *
    2091             :  * Note: we accept all subcommands for each of the variants, and sort
    2092             :  * out what's really legal at execution time.
    2093             :  *****************************************************************************/
    2094             : 
    2095             : AlterTableStmt:
    2096             :             ALTER TABLE relation_expr alter_table_cmds
    2097             :                 {
    2098       27652 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2099             : 
    2100       27652 :                     n->relation = $3;
    2101       27652 :                     n->cmds = $4;
    2102       27652 :                     n->objtype = OBJECT_TABLE;
    2103       27652 :                     n->missing_ok = false;
    2104       27652 :                     $$ = (Node *) n;
    2105             :                 }
    2106             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2107             :                 {
    2108          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2109             : 
    2110          54 :                     n->relation = $5;
    2111          54 :                     n->cmds = $6;
    2112          54 :                     n->objtype = OBJECT_TABLE;
    2113          54 :                     n->missing_ok = true;
    2114          54 :                     $$ = (Node *) n;
    2115             :                 }
    2116             :         |   ALTER TABLE relation_expr partition_cmd
    2117             :                 {
    2118        3422 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2119             : 
    2120        3422 :                     n->relation = $3;
    2121        3422 :                     n->cmds = list_make1($4);
    2122        3422 :                     n->objtype = OBJECT_TABLE;
    2123        3422 :                     n->missing_ok = false;
    2124        3422 :                     $$ = (Node *) n;
    2125             :                 }
    2126             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2127             :                 {
    2128           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2129             : 
    2130           0 :                     n->relation = $5;
    2131           0 :                     n->cmds = list_make1($6);
    2132           0 :                     n->objtype = OBJECT_TABLE;
    2133           0 :                     n->missing_ok = true;
    2134           0 :                     $$ = (Node *) n;
    2135             :                 }
    2136             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2137             :                 {
    2138             :                     AlterTableMoveAllStmt *n =
    2139          12 :                         makeNode(AlterTableMoveAllStmt);
    2140             : 
    2141          12 :                     n->orig_tablespacename = $6;
    2142          12 :                     n->objtype = OBJECT_TABLE;
    2143          12 :                     n->roles = NIL;
    2144          12 :                     n->new_tablespacename = $9;
    2145          12 :                     n->nowait = $10;
    2146          12 :                     $$ = (Node *) n;
    2147             :                 }
    2148             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2149             :                 {
    2150             :                     AlterTableMoveAllStmt *n =
    2151           0 :                         makeNode(AlterTableMoveAllStmt);
    2152             : 
    2153           0 :                     n->orig_tablespacename = $6;
    2154           0 :                     n->objtype = OBJECT_TABLE;
    2155           0 :                     n->roles = $9;
    2156           0 :                     n->new_tablespacename = $12;
    2157           0 :                     n->nowait = $13;
    2158           0 :                     $$ = (Node *) n;
    2159             :                 }
    2160             :         |   ALTER INDEX qualified_name alter_table_cmds
    2161             :                 {
    2162         228 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2163             : 
    2164         228 :                     n->relation = $3;
    2165         228 :                     n->cmds = $4;
    2166         228 :                     n->objtype = OBJECT_INDEX;
    2167         228 :                     n->missing_ok = false;
    2168         228 :                     $$ = (Node *) n;
    2169             :                 }
    2170             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2171             :                 {
    2172           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2173             : 
    2174           0 :                     n->relation = $5;
    2175           0 :                     n->cmds = $6;
    2176           0 :                     n->objtype = OBJECT_INDEX;
    2177           0 :                     n->missing_ok = true;
    2178           0 :                     $$ = (Node *) n;
    2179             :                 }
    2180             :         |   ALTER INDEX qualified_name index_partition_cmd
    2181             :                 {
    2182         494 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2183             : 
    2184         494 :                     n->relation = $3;
    2185         494 :                     n->cmds = list_make1($4);
    2186         494 :                     n->objtype = OBJECT_INDEX;
    2187         494 :                     n->missing_ok = false;
    2188         494 :                     $$ = (Node *) n;
    2189             :                 }
    2190             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2191             :                 {
    2192             :                     AlterTableMoveAllStmt *n =
    2193           6 :                         makeNode(AlterTableMoveAllStmt);
    2194             : 
    2195           6 :                     n->orig_tablespacename = $6;
    2196           6 :                     n->objtype = OBJECT_INDEX;
    2197           6 :                     n->roles = NIL;
    2198           6 :                     n->new_tablespacename = $9;
    2199           6 :                     n->nowait = $10;
    2200           6 :                     $$ = (Node *) n;
    2201             :                 }
    2202             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2203             :                 {
    2204             :                     AlterTableMoveAllStmt *n =
    2205           0 :                         makeNode(AlterTableMoveAllStmt);
    2206             : 
    2207           0 :                     n->orig_tablespacename = $6;
    2208           0 :                     n->objtype = OBJECT_INDEX;
    2209           0 :                     n->roles = $9;
    2210           0 :                     n->new_tablespacename = $12;
    2211           0 :                     n->nowait = $13;
    2212           0 :                     $$ = (Node *) n;
    2213             :                 }
    2214             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2215             :                 {
    2216         156 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2217             : 
    2218         156 :                     n->relation = $3;
    2219         156 :                     n->cmds = $4;
    2220         156 :                     n->objtype = OBJECT_SEQUENCE;
    2221         156 :                     n->missing_ok = false;
    2222         156 :                     $$ = (Node *) n;
    2223             :                 }
    2224             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2225             :                 {
    2226           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2227             : 
    2228           0 :                     n->relation = $5;
    2229           0 :                     n->cmds = $6;
    2230           0 :                     n->objtype = OBJECT_SEQUENCE;
    2231           0 :                     n->missing_ok = true;
    2232           0 :                     $$ = (Node *) n;
    2233             :                 }
    2234             :         |   ALTER VIEW qualified_name alter_table_cmds
    2235             :                 {
    2236         352 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2237             : 
    2238         352 :                     n->relation = $3;
    2239         352 :                     n->cmds = $4;
    2240         352 :                     n->objtype = OBJECT_VIEW;
    2241         352 :                     n->missing_ok = false;
    2242         352 :                     $$ = (Node *) n;
    2243             :                 }
    2244             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2245             :                 {
    2246           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2247             : 
    2248           0 :                     n->relation = $5;
    2249           0 :                     n->cmds = $6;
    2250           0 :                     n->objtype = OBJECT_VIEW;
    2251           0 :                     n->missing_ok = true;
    2252           0 :                     $$ = (Node *) n;
    2253             :                 }
    2254             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2255             :                 {
    2256          64 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2257             : 
    2258          64 :                     n->relation = $4;
    2259          64 :                     n->cmds = $5;
    2260          64 :                     n->objtype = OBJECT_MATVIEW;
    2261          64 :                     n->missing_ok = false;
    2262          64 :                     $$ = (Node *) n;
    2263             :                 }
    2264             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2265             :                 {
    2266           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2267             : 
    2268           0 :                     n->relation = $6;
    2269           0 :                     n->cmds = $7;
    2270           0 :                     n->objtype = OBJECT_MATVIEW;
    2271           0 :                     n->missing_ok = true;
    2272           0 :                     $$ = (Node *) n;
    2273             :                 }
    2274             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2275             :                 {
    2276             :                     AlterTableMoveAllStmt *n =
    2277          12 :                         makeNode(AlterTableMoveAllStmt);
    2278             : 
    2279          12 :                     n->orig_tablespacename = $7;
    2280          12 :                     n->objtype = OBJECT_MATVIEW;
    2281          12 :                     n->roles = NIL;
    2282          12 :                     n->new_tablespacename = $10;
    2283          12 :                     n->nowait = $11;
    2284          12 :                     $$ = (Node *) n;
    2285             :                 }
    2286             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2287             :                 {
    2288             :                     AlterTableMoveAllStmt *n =
    2289           0 :                         makeNode(AlterTableMoveAllStmt);
    2290             : 
    2291           0 :                     n->orig_tablespacename = $7;
    2292           0 :                     n->objtype = OBJECT_MATVIEW;
    2293           0 :                     n->roles = $10;
    2294           0 :                     n->new_tablespacename = $13;
    2295           0 :                     n->nowait = $14;
    2296           0 :                     $$ = (Node *) n;
    2297             :                 }
    2298             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2299             :                 {
    2300         374 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2301             : 
    2302         374 :                     n->relation = $4;
    2303         374 :                     n->cmds = $5;
    2304         374 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2305         374 :                     n->missing_ok = false;
    2306         374 :                     $$ = (Node *) n;
    2307             :                 }
    2308             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2309             :                 {
    2310         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2311             : 
    2312         108 :                     n->relation = $6;
    2313         108 :                     n->cmds = $7;
    2314         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2315         108 :                     n->missing_ok = true;
    2316         108 :                     $$ = (Node *) n;
    2317             :                 }
    2318             :         ;
    2319             : 
    2320             : alter_table_cmds:
    2321       28988 :             alter_table_cmd                         { $$ = list_make1($1); }
    2322        1020 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2323             :         ;
    2324             : 
    2325             : partition_cmd:
    2326             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2327             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2328             :                 {
    2329        2820 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2330        2820 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2331             : 
    2332        2820 :                     n->subtype = AT_AttachPartition;
    2333        2820 :                     cmd->name = $3;
    2334        2820 :                     cmd->bound = $4;
    2335        2820 :                     cmd->concurrent = false;
    2336        2820 :                     n->def = (Node *) cmd;
    2337             : 
    2338        2820 :                     $$ = (Node *) n;
    2339             :                 }
    2340             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2341             :             | DETACH PARTITION qualified_name opt_concurrently
    2342             :                 {
    2343         582 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2344         582 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2345             : 
    2346         582 :                     n->subtype = AT_DetachPartition;
    2347         582 :                     cmd->name = $3;
    2348         582 :                     cmd->bound = NULL;
    2349         582 :                     cmd->concurrent = $4;
    2350         582 :                     n->def = (Node *) cmd;
    2351             : 
    2352         582 :                     $$ = (Node *) n;
    2353             :                 }
    2354             :             | DETACH PARTITION qualified_name FINALIZE
    2355             :                 {
    2356          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2357          20 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2358             : 
    2359          20 :                     n->subtype = AT_DetachPartitionFinalize;
    2360          20 :                     cmd->name = $3;
    2361          20 :                     cmd->bound = NULL;
    2362          20 :                     cmd->concurrent = false;
    2363          20 :                     n->def = (Node *) cmd;
    2364          20 :                     $$ = (Node *) n;
    2365             :                 }
    2366             :         ;
    2367             : 
    2368             : index_partition_cmd:
    2369             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2370             :             ATTACH PARTITION qualified_name
    2371             :                 {
    2372         494 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2373         494 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2374             : 
    2375         494 :                     n->subtype = AT_AttachPartition;
    2376         494 :                     cmd->name = $3;
    2377         494 :                     cmd->bound = NULL;
    2378         494 :                     cmd->concurrent = false;
    2379         494 :                     n->def = (Node *) cmd;
    2380             : 
    2381         494 :                     $$ = (Node *) n;
    2382             :                 }
    2383             :         ;
    2384             : 
    2385             : alter_table_cmd:
    2386             :             /* ALTER TABLE <name> ADD <coldef> */
    2387             :             ADD_P columnDef
    2388             :                 {
    2389         192 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2390             : 
    2391         192 :                     n->subtype = AT_AddColumn;
    2392         192 :                     n->def = $2;
    2393         192 :                     n->missing_ok = false;
    2394         192 :                     $$ = (Node *) n;
    2395             :                 }
    2396             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2397             :             | ADD_P IF_P NOT EXISTS columnDef
    2398             :                 {
    2399           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2400             : 
    2401           0 :                     n->subtype = AT_AddColumn;
    2402           0 :                     n->def = $5;
    2403           0 :                     n->missing_ok = true;
    2404           0 :                     $$ = (Node *) n;
    2405             :                 }
    2406             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2407             :             | ADD_P COLUMN columnDef
    2408             :                 {
    2409        1890 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2410             : 
    2411        1890 :                     n->subtype = AT_AddColumn;
    2412        1890 :                     n->def = $3;
    2413        1890 :                     n->missing_ok = false;
    2414        1890 :                     $$ = (Node *) n;
    2415             :                 }
    2416             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2417             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2418             :                 {
    2419          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2420             : 
    2421          60 :                     n->subtype = AT_AddColumn;
    2422          60 :                     n->def = $6;
    2423          60 :                     n->missing_ok = true;
    2424          60 :                     $$ = (Node *) n;
    2425             :                 }
    2426             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2427             :             | ALTER opt_column ColId alter_column_default
    2428             :                 {
    2429         578 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2430             : 
    2431         578 :                     n->subtype = AT_ColumnDefault;
    2432         578 :                     n->name = $3;
    2433         578 :                     n->def = $4;
    2434         578 :                     $$ = (Node *) n;
    2435             :                 }
    2436             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2437             :             | ALTER opt_column ColId DROP NOT NULL_P
    2438             :                 {
    2439         294 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2440             : 
    2441         294 :                     n->subtype = AT_DropNotNull;
    2442         294 :                     n->name = $3;
    2443         294 :                     $$ = (Node *) n;
    2444             :                 }
    2445             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2446             :             | ALTER opt_column ColId SET NOT NULL_P
    2447             :                 {
    2448         434 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2449             : 
    2450         434 :                     n->subtype = AT_SetNotNull;
    2451         434 :                     n->name = $3;
    2452         434 :                     $$ = (Node *) n;
    2453             :                 }
    2454             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2455             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2456             :                 {
    2457         132 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2458             : 
    2459         132 :                     n->subtype = AT_SetExpression;
    2460         132 :                     n->name = $3;
    2461         132 :                     n->def = $8;
    2462         132 :                     $$ = (Node *) n;
    2463             :                 }
    2464             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2465             :             | ALTER opt_column ColId DROP EXPRESSION
    2466             :                 {
    2467          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2468             : 
    2469          62 :                     n->subtype = AT_DropExpression;
    2470          62 :                     n->name = $3;
    2471          62 :                     $$ = (Node *) n;
    2472             :                 }
    2473             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2474             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2475             :                 {
    2476          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2477             : 
    2478          12 :                     n->subtype = AT_DropExpression;
    2479          12 :                     n->name = $3;
    2480          12 :                     n->missing_ok = true;
    2481          12 :                     $$ = (Node *) n;
    2482             :                 }
    2483             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2484             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2485             :                 {
    2486          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2487             : 
    2488          62 :                     n->subtype = AT_SetStatistics;
    2489          62 :                     n->name = $3;
    2490          62 :                     n->def = $6;
    2491          62 :                     $$ = (Node *) n;
    2492             :                 }
    2493             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2494             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2495             :                 {
    2496          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2497             : 
    2498          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2499           6 :                         ereport(ERROR,
    2500             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2501             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2502             :                                  parser_errposition(@3)));
    2503             : 
    2504          64 :                     n->subtype = AT_SetStatistics;
    2505          64 :                     n->num = (int16) $3;
    2506          64 :                     n->def = $6;
    2507          64 :                     $$ = (Node *) n;
    2508             :                 }
    2509             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2510             :             | ALTER opt_column ColId SET reloptions
    2511             :                 {
    2512          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2513             : 
    2514          38 :                     n->subtype = AT_SetOptions;
    2515          38 :                     n->name = $3;
    2516          38 :                     n->def = (Node *) $5;
    2517          38 :                     $$ = (Node *) n;
    2518             :                 }
    2519             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2520             :             | ALTER opt_column ColId RESET reloptions
    2521             :                 {
    2522           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2523             : 
    2524           6 :                     n->subtype = AT_ResetOptions;
    2525           6 :                     n->name = $3;
    2526           6 :                     n->def = (Node *) $5;
    2527           6 :                     $$ = (Node *) n;
    2528             :                 }
    2529             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2530             :             | ALTER opt_column ColId SET column_storage
    2531             :                 {
    2532         224 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2533             : 
    2534         224 :                     n->subtype = AT_SetStorage;
    2535         224 :                     n->name = $3;
    2536         224 :                     n->def = (Node *) makeString($5);
    2537         224 :                     $$ = (Node *) n;
    2538             :                 }
    2539             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2540             :             | ALTER opt_column ColId SET column_compression
    2541             :                 {
    2542          90 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2543             : 
    2544          90 :                     n->subtype = AT_SetCompression;
    2545          90 :                     n->name = $3;
    2546          90 :                     n->def = (Node *) makeString($5);
    2547          90 :                     $$ = (Node *) n;
    2548             :                 }
    2549             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2550             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2551             :                 {
    2552         210 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2553         210 :                     Constraint *c = makeNode(Constraint);
    2554             : 
    2555         210 :                     c->contype = CONSTR_IDENTITY;
    2556         210 :                     c->generated_when = $6;
    2557         210 :                     c->options = $9;
    2558         210 :                     c->location = @5;
    2559             : 
    2560         210 :                     n->subtype = AT_AddIdentity;
    2561         210 :                     n->name = $3;
    2562         210 :                     n->def = (Node *) c;
    2563             : 
    2564         210 :                     $$ = (Node *) n;
    2565             :                 }
    2566             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2567             :             | ALTER opt_column ColId alter_identity_column_option_list
    2568             :                 {
    2569          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2570             : 
    2571          62 :                     n->subtype = AT_SetIdentity;
    2572          62 :                     n->name = $3;
    2573          62 :                     n->def = (Node *) $4;
    2574          62 :                     $$ = (Node *) n;
    2575             :                 }
    2576             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2577             :             | ALTER opt_column ColId DROP IDENTITY_P
    2578             :                 {
    2579          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2580             : 
    2581          50 :                     n->subtype = AT_DropIdentity;
    2582          50 :                     n->name = $3;
    2583          50 :                     n->missing_ok = false;
    2584          50 :                     $$ = (Node *) n;
    2585             :                 }
    2586             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2587             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2588             :                 {
    2589           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2590             : 
    2591           6 :                     n->subtype = AT_DropIdentity;
    2592           6 :                     n->name = $3;
    2593           6 :                     n->missing_ok = true;
    2594           6 :                     $$ = (Node *) n;
    2595             :                 }
    2596             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2597             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2598             :                 {
    2599          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2600             : 
    2601          18 :                     n->subtype = AT_DropColumn;
    2602          18 :                     n->name = $5;
    2603          18 :                     n->behavior = $6;
    2604          18 :                     n->missing_ok = true;
    2605          18 :                     $$ = (Node *) n;
    2606             :                 }
    2607             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2608             :             | DROP opt_column ColId opt_drop_behavior
    2609             :                 {
    2610        1574 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2611             : 
    2612        1574 :                     n->subtype = AT_DropColumn;
    2613        1574 :                     n->name = $3;
    2614        1574 :                     n->behavior = $4;
    2615        1574 :                     n->missing_ok = false;
    2616        1574 :                     $$ = (Node *) n;
    2617             :                 }
    2618             :             /*
    2619             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2620             :              *      [ USING <expression> ]
    2621             :              */
    2622             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2623             :                 {
    2624         994 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2625         994 :                     ColumnDef *def = makeNode(ColumnDef);
    2626             : 
    2627         994 :                     n->subtype = AT_AlterColumnType;
    2628         994 :                     n->name = $3;
    2629         994 :                     n->def = (Node *) def;
    2630             :                     /* We only use these fields of the ColumnDef node */
    2631         994 :                     def->typeName = $6;
    2632         994 :                     def->collClause = (CollateClause *) $7;
    2633         994 :                     def->raw_default = $8;
    2634         994 :                     def->location = @3;
    2635         994 :                     $$ = (Node *) n;
    2636             :                 }
    2637             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2638             :             | ALTER opt_column ColId alter_generic_options
    2639             :                 {
    2640          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2641             : 
    2642          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2643          50 :                     n->name = $3;
    2644          50 :                     n->def = (Node *) $4;
    2645          50 :                     $$ = (Node *) n;
    2646             :                 }
    2647             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2648             :             | ADD_P TableConstraint
    2649             :                 {
    2650       14616 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2651             : 
    2652       14616 :                     n->subtype = AT_AddConstraint;
    2653       14616 :                     n->def = $2;
    2654       14616 :                     $$ = (Node *) n;
    2655             :                 }
    2656             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2657             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2658             :                 {
    2659         228 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2660         228 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2661             : 
    2662         228 :                     n->subtype = AT_AlterConstraint;
    2663         228 :                     n->def = (Node *) c;
    2664         228 :                     c->conname = $3;
    2665         228 :                     if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
    2666          78 :                         c->alterEnforceability = true;
    2667         228 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2668             :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2669         120 :                         c->alterDeferrability = true;
    2670         228 :                     if ($4 & CAS_NO_INHERIT)
    2671          30 :                         c->alterInheritability = true;
    2672         228 :                     processCASbits($4, @4, "FOREIGN KEY",
    2673             :                                     &c->deferrable,
    2674             :                                     &c->initdeferred,
    2675             :                                     &c->is_enforced,
    2676             :                                     NULL,
    2677             :                                     &c->noinherit,
    2678             :                                     yyscanner);
    2679         222 :                     $$ = (Node *) n;
    2680             :                 }
    2681             :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2682             :             | ALTER CONSTRAINT name INHERIT
    2683             :                 {
    2684          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2685          66 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2686             : 
    2687          66 :                     n->subtype = AT_AlterConstraint;
    2688          66 :                     n->def = (Node *) c;
    2689          66 :                     c->conname = $3;
    2690          66 :                     c->alterInheritability = true;
    2691          66 :                     c->noinherit = false;
    2692             : 
    2693          66 :                     $$ = (Node *) n;
    2694             :                 }
    2695             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2696             :             | VALIDATE CONSTRAINT name
    2697             :                 {
    2698         448 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2699             : 
    2700         448 :                     n->subtype = AT_ValidateConstraint;
    2701         448 :                     n->name = $3;
    2702         448 :                     $$ = (Node *) n;
    2703             :                 }
    2704             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2705             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2706             :                 {
    2707          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2708             : 
    2709          18 :                     n->subtype = AT_DropConstraint;
    2710          18 :                     n->name = $5;
    2711          18 :                     n->behavior = $6;
    2712          18 :                     n->missing_ok = true;
    2713          18 :                     $$ = (Node *) n;
    2714             :                 }
    2715             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2716             :             | DROP CONSTRAINT name opt_drop_behavior
    2717             :                 {
    2718         798 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2719             : 
    2720         798 :                     n->subtype = AT_DropConstraint;
    2721         798 :                     n->name = $3;
    2722         798 :                     n->behavior = $4;
    2723         798 :                     n->missing_ok = false;
    2724         798 :                     $$ = (Node *) n;
    2725             :                 }
    2726             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2727             :             | SET WITHOUT OIDS
    2728             :                 {
    2729           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2730             : 
    2731           6 :                     n->subtype = AT_DropOids;
    2732           6 :                     $$ = (Node *) n;
    2733             :                 }
    2734             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2735             :             | CLUSTER ON name
    2736             :                 {
    2737          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2738             : 
    2739          46 :                     n->subtype = AT_ClusterOn;
    2740          46 :                     n->name = $3;
    2741          46 :                     $$ = (Node *) n;
    2742             :                 }
    2743             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2744             :             | SET WITHOUT CLUSTER
    2745             :                 {
    2746          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2747             : 
    2748          18 :                     n->subtype = AT_DropCluster;
    2749          18 :                     n->name = NULL;
    2750          18 :                     $$ = (Node *) n;
    2751             :                 }
    2752             :             /* ALTER TABLE <name> SET LOGGED */
    2753             :             | SET LOGGED
    2754             :                 {
    2755          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2756             : 
    2757          50 :                     n->subtype = AT_SetLogged;
    2758          50 :                     $$ = (Node *) n;
    2759             :                 }
    2760             :             /* ALTER TABLE <name> SET UNLOGGED */
    2761             :             | SET UNLOGGED
    2762             :                 {
    2763          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2764             : 
    2765          62 :                     n->subtype = AT_SetUnLogged;
    2766          62 :                     $$ = (Node *) n;
    2767             :                 }
    2768             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2769             :             | ENABLE_P TRIGGER name
    2770             :                 {
    2771         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2772             : 
    2773         122 :                     n->subtype = AT_EnableTrig;
    2774         122 :                     n->name = $3;
    2775         122 :                     $$ = (Node *) n;
    2776             :                 }
    2777             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2778             :             | ENABLE_P ALWAYS TRIGGER name
    2779             :                 {
    2780          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2781             : 
    2782          44 :                     n->subtype = AT_EnableAlwaysTrig;
    2783          44 :                     n->name = $4;
    2784          44 :                     $$ = (Node *) n;
    2785             :                 }
    2786             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2787             :             | ENABLE_P REPLICA TRIGGER name
    2788             :                 {
    2789          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2790             : 
    2791          16 :                     n->subtype = AT_EnableReplicaTrig;
    2792          16 :                     n->name = $4;
    2793          16 :                     $$ = (Node *) n;
    2794             :                 }
    2795             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2796             :             | ENABLE_P TRIGGER ALL
    2797             :                 {
    2798           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2799             : 
    2800           0 :                     n->subtype = AT_EnableTrigAll;
    2801           0 :                     $$ = (Node *) n;
    2802             :                 }
    2803             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2804             :             | ENABLE_P TRIGGER USER
    2805             :                 {
    2806           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2807             : 
    2808           0 :                     n->subtype = AT_EnableTrigUser;
    2809           0 :                     $$ = (Node *) n;
    2810             :                 }
    2811             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2812             :             | DISABLE_P TRIGGER name
    2813             :                 {
    2814         140 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2815             : 
    2816         140 :                     n->subtype = AT_DisableTrig;
    2817         140 :                     n->name = $3;
    2818         140 :                     $$ = (Node *) n;
    2819             :                 }
    2820             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2821             :             | DISABLE_P TRIGGER ALL
    2822             :                 {
    2823          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2824             : 
    2825          12 :                     n->subtype = AT_DisableTrigAll;
    2826          12 :                     $$ = (Node *) n;
    2827             :                 }
    2828             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2829             :             | DISABLE_P TRIGGER USER
    2830             :                 {
    2831          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2832             : 
    2833          12 :                     n->subtype = AT_DisableTrigUser;
    2834          12 :                     $$ = (Node *) n;
    2835             :                 }
    2836             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2837             :             | ENABLE_P RULE name
    2838             :                 {
    2839           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2840             : 
    2841           8 :                     n->subtype = AT_EnableRule;
    2842           8 :                     n->name = $3;
    2843           8 :                     $$ = (Node *) n;
    2844             :                 }
    2845             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2846             :             | ENABLE_P ALWAYS RULE name
    2847             :                 {
    2848           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2849             : 
    2850           0 :                     n->subtype = AT_EnableAlwaysRule;
    2851           0 :                     n->name = $4;
    2852           0 :                     $$ = (Node *) n;
    2853             :                 }
    2854             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2855             :             | ENABLE_P REPLICA RULE name
    2856             :                 {
    2857           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2858             : 
    2859           6 :                     n->subtype = AT_EnableReplicaRule;
    2860           6 :                     n->name = $4;
    2861           6 :                     $$ = (Node *) n;
    2862             :                 }
    2863             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2864             :             | DISABLE_P RULE name
    2865             :                 {
    2866          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2867             : 
    2868          38 :                     n->subtype = AT_DisableRule;
    2869          38 :                     n->name = $3;
    2870          38 :                     $$ = (Node *) n;
    2871             :                 }
    2872             :             /* ALTER TABLE <name> INHERIT <parent> */
    2873             :             | INHERIT qualified_name
    2874             :                 {
    2875         436 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2876             : 
    2877         436 :                     n->subtype = AT_AddInherit;
    2878         436 :                     n->def = (Node *) $2;
    2879         436 :                     $$ = (Node *) n;
    2880             :                 }
    2881             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2882             :             | NO INHERIT qualified_name
    2883             :                 {
    2884          86 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2885             : 
    2886          86 :                     n->subtype = AT_DropInherit;
    2887          86 :                     n->def = (Node *) $3;
    2888          86 :                     $$ = (Node *) n;
    2889             :                 }
    2890             :             /* ALTER TABLE <name> OF <type_name> */
    2891             :             | OF any_name
    2892             :                 {
    2893          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2894          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2895             : 
    2896          66 :                     def->location = @2;
    2897          66 :                     n->subtype = AT_AddOf;
    2898          66 :                     n->def = (Node *) def;
    2899          66 :                     $$ = (Node *) n;
    2900             :                 }
    2901             :             /* ALTER TABLE <name> NOT OF */
    2902             :             | NOT OF
    2903             :                 {
    2904           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2905             : 
    2906           6 :                     n->subtype = AT_DropOf;
    2907           6 :                     $$ = (Node *) n;
    2908             :                 }
    2909             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2910             :             | OWNER TO RoleSpec
    2911             :                 {
    2912        3574 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2913             : 
    2914        3574 :                     n->subtype = AT_ChangeOwner;
    2915        3574 :                     n->newowner = $3;
    2916        3574 :                     $$ = (Node *) n;
    2917             :                 }
    2918             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2919             :             | SET ACCESS METHOD set_access_method_name
    2920             :                 {
    2921         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2922             : 
    2923         128 :                     n->subtype = AT_SetAccessMethod;
    2924         128 :                     n->name = $4;
    2925         128 :                     $$ = (Node *) n;
    2926             :                 }
    2927             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2928             :             | SET TABLESPACE name
    2929             :                 {
    2930         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2931             : 
    2932         104 :                     n->subtype = AT_SetTableSpace;
    2933         104 :                     n->name = $3;
    2934         104 :                     $$ = (Node *) n;
    2935             :                 }
    2936             :             /* ALTER TABLE <name> SET (...) */
    2937             :             | SET reloptions
    2938             :                 {
    2939         594 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2940             : 
    2941         594 :                     n->subtype = AT_SetRelOptions;
    2942         594 :                     n->def = (Node *) $2;
    2943         594 :                     $$ = (Node *) n;
    2944             :                 }
    2945             :             /* ALTER TABLE <name> RESET (...) */
    2946             :             | RESET reloptions
    2947             :                 {
    2948         170 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2949             : 
    2950         170 :                     n->subtype = AT_ResetRelOptions;
    2951         170 :                     n->def = (Node *) $2;
    2952         170 :                     $$ = (Node *) n;
    2953             :                 }
    2954             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2955             :             | REPLICA IDENTITY_P replica_identity
    2956             :                 {
    2957         490 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2958             : 
    2959         490 :                     n->subtype = AT_ReplicaIdentity;
    2960         490 :                     n->def = $3;
    2961         490 :                     $$ = (Node *) n;
    2962             :                 }
    2963             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2964             :             | ENABLE_P ROW LEVEL SECURITY
    2965             :                 {
    2966         302 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2967             : 
    2968         302 :                     n->subtype = AT_EnableRowSecurity;
    2969         302 :                     $$ = (Node *) n;
    2970             :                 }
    2971             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2972             :             | DISABLE_P ROW LEVEL SECURITY
    2973             :                 {
    2974          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2975             : 
    2976          10 :                     n->subtype = AT_DisableRowSecurity;
    2977          10 :                     $$ = (Node *) n;
    2978             :                 }
    2979             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2980             :             | FORCE ROW LEVEL SECURITY
    2981             :                 {
    2982          96 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2983             : 
    2984          96 :                     n->subtype = AT_ForceRowSecurity;
    2985          96 :                     $$ = (Node *) n;
    2986             :                 }
    2987             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    2988             :             | NO FORCE ROW LEVEL SECURITY
    2989             :                 {
    2990          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2991             : 
    2992          32 :                     n->subtype = AT_NoForceRowSecurity;
    2993          32 :                     $$ = (Node *) n;
    2994             :                 }
    2995             :             | alter_generic_options
    2996             :                 {
    2997          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2998             : 
    2999          64 :                     n->subtype = AT_GenericOptions;
    3000          64 :                     n->def = (Node *) $1;
    3001          64 :                     $$ = (Node *) n;
    3002             :                 }
    3003             :         ;
    3004             : 
    3005             : alter_column_default:
    3006         406 :             SET DEFAULT a_expr          { $$ = $3; }
    3007         186 :             | DROP DEFAULT              { $$ = NULL; }
    3008             :         ;
    3009             : 
    3010             : opt_collate_clause:
    3011             :             COLLATE any_name
    3012             :                 {
    3013          18 :                     CollateClause *n = makeNode(CollateClause);
    3014             : 
    3015          18 :                     n->arg = NULL;
    3016          18 :                     n->collname = $2;
    3017          18 :                     n->location = @1;
    3018          18 :                     $$ = (Node *) n;
    3019             :                 }
    3020        4772 :             | /* EMPTY */               { $$ = NULL; }
    3021             :         ;
    3022             : 
    3023             : alter_using:
    3024         174 :             USING a_expr                { $$ = $2; }
    3025         820 :             | /* EMPTY */               { $$ = NULL; }
    3026             :         ;
    3027             : 
    3028             : replica_identity:
    3029             :             NOTHING
    3030             :                 {
    3031          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3032             : 
    3033          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3034          48 :                     n->name = NULL;
    3035          48 :                     $$ = (Node *) n;
    3036             :                 }
    3037             :             | FULL
    3038             :                 {
    3039         166 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3040             : 
    3041         166 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3042         166 :                     n->name = NULL;
    3043         166 :                     $$ = (Node *) n;
    3044             :                 }
    3045             :             | DEFAULT
    3046             :                 {
    3047           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3048             : 
    3049           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3050           6 :                     n->name = NULL;
    3051           6 :                     $$ = (Node *) n;
    3052             :                 }
    3053             :             | USING INDEX name
    3054             :                 {
    3055         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3056             : 
    3057         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3058         270 :                     n->name = $3;
    3059         270 :                     $$ = (Node *) n;
    3060             :                 }
    3061             : ;
    3062             : 
    3063             : reloptions:
    3064        2774 :             '(' reloption_list ')'                  { $$ = $2; }
    3065             :         ;
    3066             : 
    3067        1010 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3068       23250 :              |      /* EMPTY */                     { $$ = NIL; }
    3069             :         ;
    3070             : 
    3071             : reloption_list:
    3072        2774 :             reloption_elem                          { $$ = list_make1($1); }
    3073         244 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3074             :         ;
    3075             : 
    3076             : /* This should match def_elem and also allow qualified names */
    3077             : reloption_elem:
    3078             :             ColLabel '=' def_arg
    3079             :                 {
    3080        2370 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3081             :                 }
    3082             :             | ColLabel
    3083             :                 {
    3084         578 :                     $$ = makeDefElem($1, NULL, @1);
    3085             :                 }
    3086             :             | ColLabel '.' ColLabel '=' def_arg
    3087             :                 {
    3088          64 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3089          64 :                                              DEFELEM_UNSPEC, @1);
    3090             :                 }
    3091             :             | ColLabel '.' ColLabel
    3092             :                 {
    3093           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3094             :                 }
    3095             :         ;
    3096             : 
    3097             : alter_identity_column_option_list:
    3098             :             alter_identity_column_option
    3099          62 :                 { $$ = list_make1($1); }
    3100             :             | alter_identity_column_option_list alter_identity_column_option
    3101          60 :                 { $$ = lappend($1, $2); }
    3102             :         ;
    3103             : 
    3104             : alter_identity_column_option:
    3105             :             RESTART
    3106             :                 {
    3107          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3108             :                 }
    3109             :             | RESTART opt_with NumericOnly
    3110             :                 {
    3111           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3112             :                 }
    3113             :             | SET SeqOptElem
    3114             :                 {
    3115          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3116          54 :                         strcmp($2->defname, "restart") == 0 ||
    3117          54 :                         strcmp($2->defname, "owned_by") == 0)
    3118           0 :                         ereport(ERROR,
    3119             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3120             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3121             :                                  parser_errposition(@2)));
    3122          54 :                     $$ = $2;
    3123             :                 }
    3124             :             | SET GENERATED generated_when
    3125             :                 {
    3126          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3127             :                 }
    3128             :         ;
    3129             : 
    3130             : set_statistics_value:
    3131         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3132           0 :             | DEFAULT                       { $$ = NULL; }
    3133             :         ;
    3134             : 
    3135             : set_access_method_name:
    3136          92 :             ColId                           { $$ = $1; }
    3137          36 :             | DEFAULT                       { $$ = NULL; }
    3138             :         ;
    3139             : 
    3140             : PartitionBoundSpec:
    3141             :             /* a HASH partition */
    3142             :             FOR VALUES WITH '(' hash_partbound ')'
    3143             :                 {
    3144             :                     ListCell   *lc;
    3145         738 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3146             : 
    3147         738 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3148         738 :                     n->modulus = n->remainder = -1;
    3149             : 
    3150        2214 :                     foreach (lc, $5)
    3151             :                     {
    3152        1476 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3153             : 
    3154        1476 :                         if (strcmp(opt->defname, "modulus") == 0)
    3155             :                         {
    3156         738 :                             if (n->modulus != -1)
    3157           0 :                                 ereport(ERROR,
    3158             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3159             :                                          errmsg("modulus for hash partition provided more than once"),
    3160             :                                          parser_errposition(opt->location)));
    3161         738 :                             n->modulus = defGetInt32(opt);
    3162             :                         }
    3163         738 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3164             :                         {
    3165         738 :                             if (n->remainder != -1)
    3166           0 :                                 ereport(ERROR,
    3167             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3168             :                                          errmsg("remainder for hash partition provided more than once"),
    3169             :                                          parser_errposition(opt->location)));
    3170         738 :                             n->remainder = defGetInt32(opt);
    3171             :                         }
    3172             :                         else
    3173           0 :                             ereport(ERROR,
    3174             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3175             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3176             :                                             opt->defname),
    3177             :                                      parser_errposition(opt->location)));
    3178             :                     }
    3179             : 
    3180         738 :                     if (n->modulus == -1)
    3181           0 :                         ereport(ERROR,
    3182             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3183             :                                  errmsg("modulus for hash partition must be specified"),
    3184             :                                  parser_errposition(@3)));
    3185         738 :                     if (n->remainder == -1)
    3186           0 :                         ereport(ERROR,
    3187             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3188             :                                  errmsg("remainder for hash partition must be specified"),
    3189             :                                  parser_errposition(@3)));
    3190             : 
    3191         738 :                     n->location = @3;
    3192             : 
    3193         738 :                     $$ = n;
    3194             :                 }
    3195             : 
    3196             :             /* a LIST partition */
    3197             :             | FOR VALUES IN_P '(' expr_list ')'
    3198             :                 {
    3199        5068 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3200             : 
    3201        5068 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3202        5068 :                     n->is_default = false;
    3203        5068 :                     n->listdatums = $5;
    3204        5068 :                     n->location = @3;
    3205             : 
    3206        5068 :                     $$ = n;
    3207             :                 }
    3208             : 
    3209             :             /* a RANGE partition */
    3210             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3211             :                 {
    3212        4350 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3213             : 
    3214        4350 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3215        4350 :                     n->is_default = false;
    3216        4350 :                     n->lowerdatums = $5;
    3217        4350 :                     n->upperdatums = $9;
    3218        4350 :                     n->location = @3;
    3219             : 
    3220        4350 :                     $$ = n;
    3221             :                 }
    3222             : 
    3223             :             /* a DEFAULT partition */
    3224             :             | DEFAULT
    3225             :                 {
    3226         622 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3227             : 
    3228         622 :                     n->is_default = true;
    3229         622 :                     n->location = @1;
    3230             : 
    3231         622 :                     $$ = n;
    3232             :                 }
    3233             :         ;
    3234             : 
    3235             : hash_partbound_elem:
    3236             :         NonReservedWord Iconst
    3237             :             {
    3238        1476 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3239             :             }
    3240             :         ;
    3241             : 
    3242             : hash_partbound:
    3243             :         hash_partbound_elem
    3244             :             {
    3245         738 :                 $$ = list_make1($1);
    3246             :             }
    3247             :         | hash_partbound ',' hash_partbound_elem
    3248             :             {
    3249         738 :                 $$ = lappend($1, $3);
    3250             :             }
    3251             :         ;
    3252             : 
    3253             : /*****************************************************************************
    3254             :  *
    3255             :  *  ALTER TYPE
    3256             :  *
    3257             :  * really variants of the ALTER TABLE subcommands with different spellings
    3258             :  *****************************************************************************/
    3259             : 
    3260             : AlterCompositeTypeStmt:
    3261             :             ALTER TYPE_P any_name alter_type_cmds
    3262             :                 {
    3263         208 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3264             : 
    3265             :                     /* can't use qualified_name, sigh */
    3266         208 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3267         208 :                     n->cmds = $4;
    3268         208 :                     n->objtype = OBJECT_TYPE;
    3269         208 :                     $$ = (Node *) n;
    3270             :                 }
    3271             :             ;
    3272             : 
    3273             : alter_type_cmds:
    3274         208 :             alter_type_cmd                          { $$ = list_make1($1); }
    3275          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3276             :         ;
    3277             : 
    3278             : alter_type_cmd:
    3279             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3280             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3281             :                 {
    3282          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3283             : 
    3284          64 :                     n->subtype = AT_AddColumn;
    3285          64 :                     n->def = $3;
    3286          64 :                     n->behavior = $4;
    3287          64 :                     $$ = (Node *) n;
    3288             :                 }
    3289             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3290             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3291             :                 {
    3292           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3293             : 
    3294           6 :                     n->subtype = AT_DropColumn;
    3295           6 :                     n->name = $5;
    3296           6 :                     n->behavior = $6;
    3297           6 :                     n->missing_ok = true;
    3298           6 :                     $$ = (Node *) n;
    3299             :                 }
    3300             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3301             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3302             :                 {
    3303          76 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3304             : 
    3305          76 :                     n->subtype = AT_DropColumn;
    3306          76 :                     n->name = $3;
    3307          76 :                     n->behavior = $4;
    3308          76 :                     n->missing_ok = false;
    3309          76 :                     $$ = (Node *) n;
    3310             :                 }
    3311             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3312             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3313             :                 {
    3314          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3315          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3316             : 
    3317          74 :                     n->subtype = AT_AlterColumnType;
    3318          74 :                     n->name = $3;
    3319          74 :                     n->def = (Node *) def;
    3320          74 :                     n->behavior = $8;
    3321             :                     /* We only use these fields of the ColumnDef node */
    3322          74 :                     def->typeName = $6;
    3323          74 :                     def->collClause = (CollateClause *) $7;
    3324          74 :                     def->raw_default = NULL;
    3325          74 :                     def->location = @3;
    3326          74 :                     $$ = (Node *) n;
    3327             :                 }
    3328             :         ;
    3329             : 
    3330             : 
    3331             : /*****************************************************************************
    3332             :  *
    3333             :  *      QUERY :
    3334             :  *              close <portalname>
    3335             :  *
    3336             :  *****************************************************************************/
    3337             : 
    3338             : ClosePortalStmt:
    3339             :             CLOSE cursor_name
    3340             :                 {
    3341        2192 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3342             : 
    3343        2192 :                     n->portalname = $2;
    3344        2192 :                     $$ = (Node *) n;
    3345             :                 }
    3346             :             | CLOSE ALL
    3347             :                 {
    3348          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3349             : 
    3350          12 :                     n->portalname = NULL;
    3351          12 :                     $$ = (Node *) n;
    3352             :                 }
    3353             :         ;
    3354             : 
    3355             : 
    3356             : /*****************************************************************************
    3357             :  *
    3358             :  *      QUERY :
    3359             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3360             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3361             :  *
    3362             :  *              where 'query' can be one of:
    3363             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3364             :  *
    3365             :  *              and 'file' can be one of:
    3366             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3367             :  *
    3368             :  *              In the preferred syntax the options are comma-separated
    3369             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3370             :  *              syntax had a hard-wired, space-separated set of options.
    3371             :  *
    3372             :  *              Really old syntax, from versions 7.2 and prior:
    3373             :  *              COPY [ BINARY ] table FROM/TO file
    3374             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3375             :  *                  [ WITH NULL AS 'null string' ]
    3376             :  *              This option placement is not supported with COPY (query...).
    3377             :  *
    3378             :  *****************************************************************************/
    3379             : 
    3380             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3381             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3382             :             copy_options where_clause
    3383             :                 {
    3384       15578 :                     CopyStmt *n = makeNode(CopyStmt);
    3385             : 
    3386       15578 :                     n->relation = $3;
    3387       15578 :                     n->query = NULL;
    3388       15578 :                     n->attlist = $4;
    3389       15578 :                     n->is_from = $5;
    3390       15578 :                     n->is_program = $6;
    3391       15578 :                     n->filename = $7;
    3392       15578 :                     n->whereClause = $11;
    3393             : 
    3394       15578 :                     if (n->is_program && n->filename == NULL)
    3395           0 :                         ereport(ERROR,
    3396             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3397             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3398             :                                  parser_errposition(@8)));
    3399             : 
    3400       15578 :                     if (!n->is_from && n->whereClause != NULL)
    3401           6 :                         ereport(ERROR,
    3402             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3403             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3404             :                                  parser_errposition(@11)));
    3405             : 
    3406       15572 :                     n->options = NIL;
    3407             :                     /* Concatenate user-supplied flags */
    3408       15572 :                     if ($2)
    3409          12 :                         n->options = lappend(n->options, $2);
    3410       15572 :                     if ($8)
    3411           0 :                         n->options = lappend(n->options, $8);
    3412       15572 :                     if ($10)
    3413         926 :                         n->options = list_concat(n->options, $10);
    3414       15572 :                     $$ = (Node *) n;
    3415             :                 }
    3416             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3417             :                 {
    3418         464 :                     CopyStmt *n = makeNode(CopyStmt);
    3419             : 
    3420         464 :                     updatePreparableStmtEnd($3, @4);
    3421         464 :                     n->relation = NULL;
    3422         464 :                     n->query = $3;
    3423         464 :                     n->attlist = NIL;
    3424         464 :                     n->is_from = false;
    3425         464 :                     n->is_program = $6;
    3426         464 :                     n->filename = $7;
    3427         464 :                     n->options = $9;
    3428             : 
    3429         464 :                     if (n->is_program && n->filename == NULL)
    3430           0 :                         ereport(ERROR,
    3431             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3432             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3433             :                                  parser_errposition(@5)));
    3434             : 
    3435         464 :                     $$ = (Node *) n;
    3436             :                 }
    3437             :         ;
    3438             : 
    3439             : copy_from:
    3440        2994 :             FROM                                    { $$ = true; }
    3441       12584 :             | TO                                    { $$ = false; }
    3442             :         ;
    3443             : 
    3444             : opt_program:
    3445           0 :             PROGRAM                                 { $$ = true; }
    3446       16042 :             | /* EMPTY */                           { $$ = false; }
    3447             :         ;
    3448             : 
    3449             : /*
    3450             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3451             :  * used depends on the direction. (It really doesn't make sense to copy from
    3452             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3453             :  */
    3454             : copy_file_name:
    3455         450 :             Sconst                                  { $$ = $1; }
    3456        2608 :             | STDIN                                 { $$ = NULL; }
    3457       12984 :             | STDOUT                                { $$ = NULL; }
    3458             :         ;
    3459             : 
    3460       15386 : copy_options: copy_opt_list                         { $$ = $1; }
    3461         656 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3462             :         ;
    3463             : 
    3464             : /* old COPY option syntax */
    3465             : copy_opt_list:
    3466         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3467       15386 :             | /* EMPTY */                           { $$ = NIL; }
    3468             :         ;
    3469             : 
    3470             : copy_opt_item:
    3471             :             BINARY
    3472             :                 {
    3473           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3474             :                 }
    3475             :             | FREEZE
    3476             :                 {
    3477          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3478             :                 }
    3479             :             | DELIMITER opt_as Sconst
    3480             :                 {
    3481         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3482             :                 }
    3483             :             | NULL_P opt_as Sconst
    3484             :                 {
    3485          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3486             :                 }
    3487             :             | CSV
    3488             :                 {
    3489         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3490             :                 }
    3491             :             | HEADER_P
    3492             :                 {
    3493          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3494             :                 }
    3495             :             | QUOTE opt_as Sconst
    3496             :                 {
    3497          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3498             :                 }
    3499             :             | ESCAPE opt_as Sconst
    3500             :                 {
    3501          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3502             :                 }
    3503             :             | FORCE QUOTE columnList
    3504             :                 {
    3505          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3506             :                 }
    3507             :             | FORCE QUOTE '*'
    3508             :                 {
    3509           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3510             :                 }
    3511             :             | FORCE NOT NULL_P columnList
    3512             :                 {
    3513           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3514             :                 }
    3515             :             | FORCE NOT NULL_P '*'
    3516             :                 {
    3517           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3518             :                 }
    3519             :             | FORCE NULL_P columnList
    3520             :                 {
    3521           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3522             :                 }
    3523             :             | FORCE NULL_P '*'
    3524             :                 {
    3525           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3526             :                 }
    3527             :             | ENCODING Sconst
    3528             :                 {
    3529          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3530             :                 }
    3531             :         ;
    3532             : 
    3533             : /* The following exist for backward compatibility with very old versions */
    3534             : 
    3535             : opt_binary:
    3536             :             BINARY
    3537             :                 {
    3538          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3539             :                 }
    3540       15566 :             | /*EMPTY*/                             { $$ = NULL; }
    3541             :         ;
    3542             : 
    3543             : copy_delimiter:
    3544             :             opt_using DELIMITERS Sconst
    3545             :                 {
    3546           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3547             :                 }
    3548       15578 :             | /*EMPTY*/                             { $$ = NULL; }
    3549             :         ;
    3550             : 
    3551             : opt_using:
    3552             :             USING
    3553             :             | /*EMPTY*/
    3554             :         ;
    3555             : 
    3556             : /* new COPY option syntax */
    3557             : copy_generic_opt_list:
    3558             :             copy_generic_opt_elem
    3559             :                 {
    3560         656 :                     $$ = list_make1($1);
    3561             :                 }
    3562             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3563             :                 {
    3564         450 :                     $$ = lappend($1, $3);
    3565             :                 }
    3566             :         ;
    3567             : 
    3568             : copy_generic_opt_elem:
    3569             :             ColLabel copy_generic_opt_arg
    3570             :                 {
    3571        1106 :                     $$ = makeDefElem($1, $2, @1);
    3572             :                 }
    3573             :         ;
    3574             : 
    3575             : copy_generic_opt_arg:
    3576         800 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3577          24 :             | NumericOnly                   { $$ = (Node *) $1; }
    3578          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3579           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3580         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3581          36 :             | /* EMPTY */                   { $$ = NULL; }
    3582             :         ;
    3583             : 
    3584             : copy_generic_opt_arg_list:
    3585             :               copy_generic_opt_arg_list_item
    3586             :                 {
    3587         150 :                     $$ = list_make1($1);
    3588             :                 }
    3589             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3590             :                 {
    3591          12 :                     $$ = lappend($1, $3);
    3592             :                 }
    3593             :         ;
    3594             : 
    3595             : /* beware of emitting non-string list elements here; see commands/define.c */
    3596             : copy_generic_opt_arg_list_item:
    3597         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3598             :         ;
    3599             : 
    3600             : 
    3601             : /*****************************************************************************
    3602             :  *
    3603             :  *      QUERY :
    3604             :  *              CREATE TABLE relname
    3605             :  *
    3606             :  *****************************************************************************/
    3607             : 
    3608             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3609             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3610             :             OnCommitOption OptTableSpace
    3611             :                 {
    3612       30622 :                     CreateStmt *n = makeNode(CreateStmt);
    3613             : 
    3614       30622 :                     $4->relpersistence = $2;
    3615       30622 :                     n->relation = $4;
    3616       30622 :                     n->tableElts = $6;
    3617       30622 :                     n->inhRelations = $8;
    3618       30622 :                     n->partspec = $9;
    3619       30622 :                     n->ofTypename = NULL;
    3620       30622 :                     n->constraints = NIL;
    3621       30622 :                     n->accessMethod = $10;
    3622       30622 :                     n->options = $11;
    3623       30622 :                     n->oncommit = $12;
    3624       30622 :                     n->tablespacename = $13;
    3625       30622 :                     n->if_not_exists = false;
    3626       30622 :                     $$ = (Node *) n;
    3627             :                 }
    3628             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3629             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3630             :             OptWith OnCommitOption OptTableSpace
    3631             :                 {
    3632          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3633             : 
    3634          30 :                     $7->relpersistence = $2;
    3635          30 :                     n->relation = $7;
    3636          30 :                     n->tableElts = $9;
    3637          30 :                     n->inhRelations = $11;
    3638          30 :                     n->partspec = $12;
    3639          30 :                     n->ofTypename = NULL;
    3640          30 :                     n->constraints = NIL;
    3641          30 :                     n->accessMethod = $13;
    3642          30 :                     n->options = $14;
    3643          30 :                     n->oncommit = $15;
    3644          30 :                     n->tablespacename = $16;
    3645          30 :                     n->if_not_exists = true;
    3646          30 :                     $$ = (Node *) n;
    3647             :                 }
    3648             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3649             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3650             :             OptWith OnCommitOption OptTableSpace
    3651             :                 {
    3652         134 :                     CreateStmt *n = makeNode(CreateStmt);
    3653             : 
    3654         134 :                     $4->relpersistence = $2;
    3655         134 :                     n->relation = $4;
    3656         134 :                     n->tableElts = $7;
    3657         134 :                     n->inhRelations = NIL;
    3658         134 :                     n->partspec = $8;
    3659         134 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3660         134 :                     n->ofTypename->location = @6;
    3661         134 :                     n->constraints = NIL;
    3662         134 :                     n->accessMethod = $9;
    3663         134 :                     n->options = $10;
    3664         134 :                     n->oncommit = $11;
    3665         134 :                     n->tablespacename = $12;
    3666         134 :                     n->if_not_exists = false;
    3667         134 :                     $$ = (Node *) n;
    3668             :                 }
    3669             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3670             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3671             :             OptWith OnCommitOption OptTableSpace
    3672             :                 {
    3673           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3674             : 
    3675           6 :                     $7->relpersistence = $2;
    3676           6 :                     n->relation = $7;
    3677           6 :                     n->tableElts = $10;
    3678           6 :                     n->inhRelations = NIL;
    3679           6 :                     n->partspec = $11;
    3680           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3681           6 :                     n->ofTypename->location = @9;
    3682           6 :                     n->constraints = NIL;
    3683           6 :                     n->accessMethod = $12;
    3684           6 :                     n->options = $13;
    3685           6 :                     n->oncommit = $14;
    3686           6 :                     n->tablespacename = $15;
    3687           6 :                     n->if_not_exists = true;
    3688           6 :                     $$ = (Node *) n;
    3689             :                 }
    3690             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3691             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3692             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3693             :                 {
    3694        7868 :                     CreateStmt *n = makeNode(CreateStmt);
    3695             : 
    3696        7868 :                     $4->relpersistence = $2;
    3697        7868 :                     n->relation = $4;
    3698        7868 :                     n->tableElts = $8;
    3699        7868 :                     n->inhRelations = list_make1($7);
    3700        7868 :                     n->partbound = $9;
    3701        7868 :                     n->partspec = $10;
    3702        7868 :                     n->ofTypename = NULL;
    3703        7868 :                     n->constraints = NIL;
    3704        7868 :                     n->accessMethod = $11;
    3705        7868 :                     n->options = $12;
    3706        7868 :                     n->oncommit = $13;
    3707        7868 :                     n->tablespacename = $14;
    3708        7868 :                     n->if_not_exists = false;
    3709        7868 :                     $$ = (Node *) n;
    3710             :                 }
    3711             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3712             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3713             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3714             :                 {
    3715           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3716             : 
    3717           0 :                     $7->relpersistence = $2;
    3718           0 :                     n->relation = $7;
    3719           0 :                     n->tableElts = $11;
    3720           0 :                     n->inhRelations = list_make1($10);
    3721           0 :                     n->partbound = $12;
    3722           0 :                     n->partspec = $13;
    3723           0 :                     n->ofTypename = NULL;
    3724           0 :                     n->constraints = NIL;
    3725           0 :                     n->accessMethod = $14;
    3726           0 :                     n->options = $15;
    3727           0 :                     n->oncommit = $16;
    3728           0 :                     n->tablespacename = $17;
    3729           0 :                     n->if_not_exists = true;
    3730           0 :                     $$ = (Node *) n;
    3731             :                 }
    3732             :         ;
    3733             : 
    3734             : /*
    3735             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3736             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3737             :  *
    3738             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3739             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3740             :  * temp table behavior, so warn about that.  Since we have no modules the
    3741             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3742             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3743             :  * so we'll probably continue to treat LOCAL as a noise word.
    3744             :  */
    3745         336 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3746        2720 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3747           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3748           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3749             :             | GLOBAL TEMPORARY
    3750             :                 {
    3751           0 :                     ereport(WARNING,
    3752             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3753             :                              parser_errposition(@1)));
    3754           0 :                     $$ = RELPERSISTENCE_TEMP;
    3755             :                 }
    3756             :             | GLOBAL TEMP
    3757             :                 {
    3758           0 :                     ereport(WARNING,
    3759             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3760             :                              parser_errposition(@1)));
    3761           0 :                     $$ = RELPERSISTENCE_TEMP;
    3762             :                 }
    3763         170 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3764       54292 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3765             :         ;
    3766             : 
    3767             : OptTableElementList:
    3768       29460 :             TableElementList                    { $$ = $1; }
    3769        1624 :             | /*EMPTY*/                         { $$ = NIL; }
    3770             :         ;
    3771             : 
    3772             : OptTypedTableElementList:
    3773         354 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3774        7750 :             | /*EMPTY*/                         { $$ = NIL; }
    3775             :         ;
    3776             : 
    3777             : TableElementList:
    3778             :             TableElement
    3779             :                 {
    3780       29514 :                     $$ = list_make1($1);
    3781             :                 }
    3782             :             | TableElementList ',' TableElement
    3783             :                 {
    3784       44296 :                     $$ = lappend($1, $3);
    3785             :                 }
    3786             :         ;
    3787             : 
    3788             : TypedTableElementList:
    3789             :             TypedTableElement
    3790             :                 {
    3791         354 :                     $$ = list_make1($1);
    3792             :                 }
    3793             :             | TypedTableElementList ',' TypedTableElement
    3794             :                 {
    3795          70 :                     $$ = lappend($1, $3);
    3796             :                 }
    3797             :         ;
    3798             : 
    3799             : TableElement:
    3800       70282 :             columnDef                           { $$ = $1; }
    3801         774 :             | TableLikeClause                   { $$ = $1; }
    3802        2754 :             | TableConstraint                   { $$ = $1; }
    3803             :         ;
    3804             : 
    3805             : TypedTableElement:
    3806         354 :             columnOptions                       { $$ = $1; }
    3807          70 :             | TableConstraint                   { $$ = $1; }
    3808             :         ;
    3809             : 
    3810             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3811             :                 {
    3812       72424 :                     ColumnDef *n = makeNode(ColumnDef);
    3813             : 
    3814       72424 :                     n->colname = $1;
    3815       72424 :                     n->typeName = $2;
    3816       72424 :                     n->storage_name = $3;
    3817       72424 :                     n->compression = $4;
    3818       72424 :                     n->inhcount = 0;
    3819       72424 :                     n->is_local = true;
    3820       72424 :                     n->is_not_null = false;
    3821       72424 :                     n->is_from_type = false;
    3822       72424 :                     n->storage = 0;
    3823       72424 :                     n->raw_default = NULL;
    3824       72424 :                     n->cooked_default = NULL;
    3825       72424 :                     n->collOid = InvalidOid;
    3826       72424 :                     n->fdwoptions = $5;
    3827       72424 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3828             :                                      yyscanner);
    3829       72424 :                     n->location = @1;
    3830       72424 :                     $$ = (Node *) n;
    3831             :                 }
    3832             :         ;
    3833             : 
    3834             : columnOptions:  ColId ColQualList
    3835             :                 {
    3836         146 :                     ColumnDef *n = makeNode(ColumnDef);
    3837             : 
    3838         146 :                     n->colname = $1;
    3839         146 :                     n->typeName = NULL;
    3840         146 :                     n->inhcount = 0;
    3841         146 :                     n->is_local = true;
    3842         146 :                     n->is_not_null = false;
    3843         146 :                     n->is_from_type = false;
    3844         146 :                     n->storage = 0;
    3845         146 :                     n->raw_default = NULL;
    3846         146 :                     n->cooked_default = NULL;
    3847         146 :                     n->collOid = InvalidOid;
    3848         146 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3849             :                                      yyscanner);
    3850         146 :                     n->location = @1;
    3851         146 :                     $$ = (Node *) n;
    3852             :                 }
    3853             :                 | ColId WITH OPTIONS ColQualList
    3854             :                 {
    3855         208 :                     ColumnDef *n = makeNode(ColumnDef);
    3856             : 
    3857         208 :                     n->colname = $1;
    3858         208 :                     n->typeName = NULL;
    3859         208 :                     n->inhcount = 0;
    3860         208 :                     n->is_local = true;
    3861         208 :                     n->is_not_null = false;
    3862         208 :                     n->is_from_type = false;
    3863         208 :                     n->storage = 0;
    3864         208 :                     n->raw_default = NULL;
    3865         208 :                     n->cooked_default = NULL;
    3866         208 :                     n->collOid = InvalidOid;
    3867         208 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3868             :                                      yyscanner);
    3869         208 :                     n->location = @1;
    3870         208 :                     $$ = (Node *) n;
    3871             :                 }
    3872             :         ;
    3873             : 
    3874             : column_compression:
    3875         166 :             COMPRESSION ColId                       { $$ = $2; }
    3876           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3877             :         ;
    3878             : 
    3879             : opt_column_compression:
    3880          82 :             column_compression                      { $$ = $1; }
    3881       72408 :             | /*EMPTY*/                             { $$ = NULL; }
    3882             :         ;
    3883             : 
    3884             : column_storage:
    3885         238 :             STORAGE ColId                           { $$ = $2; }
    3886           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3887             :         ;
    3888             : 
    3889             : opt_column_storage:
    3890          20 :             column_storage                          { $$ = $1; }
    3891       72470 :             | /*EMPTY*/                             { $$ = NULL; }
    3892             :         ;
    3893             : 
    3894             : ColQualList:
    3895       20348 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3896       74318 :             | /*EMPTY*/                             { $$ = NIL; }
    3897             :         ;
    3898             : 
    3899             : ColConstraint:
    3900             :             CONSTRAINT name ColConstraintElem
    3901             :                 {
    3902         930 :                     Constraint *n = castNode(Constraint, $3);
    3903             : 
    3904         930 :                     n->conname = $2;
    3905         930 :                     n->location = @1;
    3906         930 :                     $$ = (Node *) n;
    3907             :                 }
    3908       18364 :             | ColConstraintElem                     { $$ = $1; }
    3909         294 :             | ConstraintAttr                        { $$ = $1; }
    3910             :             | COLLATE any_name
    3911             :                 {
    3912             :                     /*
    3913             :                      * Note: the CollateClause is momentarily included in
    3914             :                      * the list built by ColQualList, but we split it out
    3915             :                      * again in SplitColQualList.
    3916             :                      */
    3917         760 :                     CollateClause *n = makeNode(CollateClause);
    3918             : 
    3919         760 :                     n->arg = NULL;
    3920         760 :                     n->collname = $2;
    3921         760 :                     n->location = @1;
    3922         760 :                     $$ = (Node *) n;
    3923             :                 }
    3924             :         ;
    3925             : 
    3926             : /* DEFAULT NULL is already the default for Postgres.
    3927             :  * But define it here and carry it forward into the system
    3928             :  * to make it explicit.
    3929             :  * - thomas 1998-09-13
    3930             :  *
    3931             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3932             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3933             :  * that a column may have that value. WITH NULL leads to
    3934             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3935             :  * - thomas 1999-01-08
    3936             :  *
    3937             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3938             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3939             :  * or be part of a_expr NOT LIKE or similar constructs).
    3940             :  */
    3941             : ColConstraintElem:
    3942             :             NOT NULL_P opt_no_inherit
    3943             :                 {
    3944        7106 :                     Constraint *n = makeNode(Constraint);
    3945             : 
    3946        7106 :                     n->contype = CONSTR_NOTNULL;
    3947        7106 :                     n->location = @1;
    3948        7106 :                     n->is_no_inherit = $3;
    3949        7106 :                     n->is_enforced = true;
    3950        7106 :                     n->skip_validation = false;
    3951        7106 :                     n->initially_valid = true;
    3952        7106 :                     $$ = (Node *) n;
    3953             :                 }
    3954             :             | NULL_P
    3955             :                 {
    3956          30 :                     Constraint *n = makeNode(Constraint);
    3957             : 
    3958          30 :                     n->contype = CONSTR_NULL;
    3959          30 :                     n->location = @1;
    3960          30 :                     $$ = (Node *) n;
    3961             :                 }
    3962             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3963             :                 {
    3964         446 :                     Constraint *n = makeNode(Constraint);
    3965             : 
    3966         446 :                     n->contype = CONSTR_UNIQUE;
    3967         446 :                     n->location = @1;
    3968         446 :                     n->nulls_not_distinct = !$2;
    3969         446 :                     n->keys = NULL;
    3970         446 :                     n->options = $3;
    3971         446 :                     n->indexname = NULL;
    3972         446 :                     n->indexspace = $4;
    3973         446 :                     $$ = (Node *) n;
    3974             :                 }
    3975             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3976             :                 {
    3977        5748 :                     Constraint *n = makeNode(Constraint);
    3978             : 
    3979        5748 :                     n->contype = CONSTR_PRIMARY;
    3980        5748 :                     n->location = @1;
    3981        5748 :                     n->keys = NULL;
    3982        5748 :                     n->options = $3;
    3983        5748 :                     n->indexname = NULL;
    3984        5748 :                     n->indexspace = $4;
    3985        5748 :                     $$ = (Node *) n;
    3986             :                 }
    3987             :             | CHECK '(' a_expr ')' opt_no_inherit
    3988             :                 {
    3989        1104 :                     Constraint *n = makeNode(Constraint);
    3990             : 
    3991        1104 :                     n->contype = CONSTR_CHECK;
    3992        1104 :                     n->location = @1;
    3993        1104 :                     n->is_no_inherit = $5;
    3994        1104 :                     n->raw_expr = $3;
    3995        1104 :                     n->cooked_expr = NULL;
    3996        1104 :                     n->is_enforced = true;
    3997        1104 :                     n->skip_validation = false;
    3998        1104 :                     n->initially_valid = true;
    3999        1104 :                     $$ = (Node *) n;
    4000             :                 }
    4001             :             | DEFAULT b_expr
    4002             :                 {
    4003        1882 :                     Constraint *n = makeNode(Constraint);
    4004             : 
    4005        1882 :                     n->contype = CONSTR_DEFAULT;
    4006        1882 :                     n->location = @1;
    4007        1882 :                     n->raw_expr = $2;
    4008        1882 :                     n->cooked_expr = NULL;
    4009        1882 :                     $$ = (Node *) n;
    4010             :                 }
    4011             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4012             :                 {
    4013         332 :                     Constraint *n = makeNode(Constraint);
    4014             : 
    4015         332 :                     n->contype = CONSTR_IDENTITY;
    4016         332 :                     n->generated_when = $2;
    4017         332 :                     n->options = $5;
    4018         332 :                     n->location = @1;
    4019         332 :                     $$ = (Node *) n;
    4020             :                 }
    4021             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4022             :                 {
    4023        1830 :                     Constraint *n = makeNode(Constraint);
    4024             : 
    4025        1830 :                     n->contype = CONSTR_GENERATED;
    4026        1830 :                     n->generated_when = $2;
    4027        1830 :                     n->raw_expr = $5;
    4028        1830 :                     n->cooked_expr = NULL;
    4029        1830 :                     n->generated_kind = $7;
    4030        1830 :                     n->location = @1;
    4031             : 
    4032             :                     /*
    4033             :                      * Can't do this in the grammar because of shift/reduce
    4034             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4035             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4036             :                      * can also give a more useful error message and location.
    4037             :                      */
    4038        1830 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4039          12 :                         ereport(ERROR,
    4040             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4041             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4042             :                                  parser_errposition(@2)));
    4043             : 
    4044        1818 :                     $$ = (Node *) n;
    4045             :                 }
    4046             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4047             :                 {
    4048         828 :                     Constraint *n = makeNode(Constraint);
    4049             : 
    4050         828 :                     n->contype = CONSTR_FOREIGN;
    4051         828 :                     n->location = @1;
    4052         828 :                     n->pktable = $2;
    4053         828 :                     n->fk_attrs = NIL;
    4054         828 :                     n->pk_attrs = $3;
    4055         828 :                     n->fk_matchtype = $4;
    4056         828 :                     n->fk_upd_action = ($5)->updateAction->action;
    4057         828 :                     n->fk_del_action = ($5)->deleteAction->action;
    4058         828 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4059         828 :                     n->is_enforced = true;
    4060         828 :                     n->skip_validation = false;
    4061         828 :                     n->initially_valid = true;
    4062         828 :                     $$ = (Node *) n;
    4063             :                 }
    4064             :         ;
    4065             : 
    4066             : opt_unique_null_treatment:
    4067          12 :             NULLS_P DISTINCT        { $$ = true; }
    4068          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4069        7918 :             | /*EMPTY*/             { $$ = true; }
    4070             :         ;
    4071             : 
    4072             : generated_when:
    4073        2218 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4074         198 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4075             :         ;
    4076             : 
    4077             : opt_virtual_or_stored:
    4078        1038 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4079         616 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4080         176 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4081             :         ;
    4082             : 
    4083             : /*
    4084             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4085             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4086             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4087             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4088             :  * attribute information to the preceding "real" constraint node, and for
    4089             :  * complaining if attribute clauses appear in the wrong place or wrong
    4090             :  * combinations.
    4091             :  *
    4092             :  * See also ConstraintAttributeSpec, which can be used in places where
    4093             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4094             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4095             :  * might need to allow them here too, but for the moment it doesn't seem
    4096             :  * useful in the statements that use ConstraintAttr.)
    4097             :  */
    4098             : ConstraintAttr:
    4099             :             DEFERRABLE
    4100             :                 {
    4101         102 :                     Constraint *n = makeNode(Constraint);
    4102             : 
    4103         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4104         102 :                     n->location = @1;
    4105         102 :                     $$ = (Node *) n;
    4106             :                 }
    4107             :             | NOT DEFERRABLE
    4108             :                 {
    4109           0 :                     Constraint *n = makeNode(Constraint);
    4110             : 
    4111           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4112           0 :                     n->location = @1;
    4113           0 :                     $$ = (Node *) n;
    4114             :                 }
    4115             :             | INITIALLY DEFERRED
    4116             :                 {
    4117          78 :                     Constraint *n = makeNode(Constraint);
    4118             : 
    4119          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4120          78 :                     n->location = @1;
    4121          78 :                     $$ = (Node *) n;
    4122             :                 }
    4123             :             | INITIALLY IMMEDIATE
    4124             :                 {
    4125           6 :                     Constraint *n = makeNode(Constraint);
    4126             : 
    4127           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4128           6 :                     n->location = @1;
    4129           6 :                     $$ = (Node *) n;
    4130             :                 }
    4131             :             | ENFORCED
    4132             :                 {
    4133          42 :                     Constraint *n = makeNode(Constraint);
    4134             : 
    4135          42 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4136          42 :                     n->location = @1;
    4137          42 :                     $$ = (Node *) n;
    4138             :                 }
    4139             :             | NOT ENFORCED
    4140             :                 {
    4141          66 :                     Constraint *n = makeNode(Constraint);
    4142             : 
    4143          66 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4144          66 :                     n->location = @1;
    4145          66 :                     $$ = (Node *) n;
    4146             :                 }
    4147             :         ;
    4148             : 
    4149             : 
    4150             : TableLikeClause:
    4151             :             LIKE qualified_name TableLikeOptionList
    4152             :                 {
    4153         774 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4154             : 
    4155         774 :                     n->relation = $2;
    4156         774 :                     n->options = $3;
    4157         774 :                     n->relationOid = InvalidOid;
    4158         774 :                     $$ = (Node *) n;
    4159             :                 }
    4160             :         ;
    4161             : 
    4162             : TableLikeOptionList:
    4163         282 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4164           8 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4165         774 :                 | /* EMPTY */                       { $$ = 0; }
    4166             :         ;
    4167             : 
    4168             : TableLikeOption:
    4169          24 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4170           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4171          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4172          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4173          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4174          30 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4175          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4176           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4177          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4178          68 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4179             :         ;
    4180             : 
    4181             : 
    4182             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4183             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4184             :  * - thomas 1997-12-03
    4185             :  */
    4186             : TableConstraint:
    4187             :             CONSTRAINT name ConstraintElem
    4188             :                 {
    4189        4458 :                     Constraint *n = castNode(Constraint, $3);
    4190             : 
    4191        4458 :                     n->conname = $2;
    4192        4458 :                     n->location = @1;
    4193        4458 :                     $$ = (Node *) n;
    4194             :                 }
    4195       12982 :             | ConstraintElem                        { $$ = $1; }
    4196             :         ;
    4197             : 
    4198             : ConstraintElem:
    4199             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4200             :                 {
    4201        1314 :                     Constraint *n = makeNode(Constraint);
    4202             : 
    4203        1314 :                     n->contype = CONSTR_CHECK;
    4204        1314 :                     n->location = @1;
    4205        1314 :                     n->raw_expr = $3;
    4206        1314 :                     n->cooked_expr = NULL;
    4207        1314 :                     processCASbits($5, @5, "CHECK",
    4208             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4209             :                                    &n->is_no_inherit, yyscanner);
    4210        1314 :                     n->initially_valid = !n->skip_validation;
    4211        1314 :                     $$ = (Node *) n;
    4212             :                 }
    4213             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4214             :                 {
    4215         600 :                     Constraint *n = makeNode(Constraint);
    4216             : 
    4217         600 :                     n->contype = CONSTR_NOTNULL;
    4218         600 :                     n->location = @1;
    4219         600 :                     n->keys = list_make1(makeString($3));
    4220         600 :                     processCASbits($4, @4, "NOT NULL",
    4221             :                                    NULL, NULL, NULL, &n->skip_validation,
    4222             :                                    &n->is_no_inherit, yyscanner);
    4223         600 :                     n->initially_valid = !n->skip_validation;
    4224         600 :                     $$ = (Node *) n;
    4225             :                 }
    4226             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4227             :                 ConstraintAttributeSpec
    4228             :                 {
    4229         630 :                     Constraint *n = makeNode(Constraint);
    4230             : 
    4231         630 :                     n->contype = CONSTR_UNIQUE;
    4232         630 :                     n->location = @1;
    4233         630 :                     n->nulls_not_distinct = !$2;
    4234         630 :                     n->keys = $4;
    4235         630 :                     n->without_overlaps = $5;
    4236         630 :                     n->including = $7;
    4237         630 :                     n->options = $8;
    4238         630 :                     n->indexname = NULL;
    4239         630 :                     n->indexspace = $9;
    4240         630 :                     processCASbits($10, @10, "UNIQUE",
    4241             :                                    &n->deferrable, &n->initdeferred, NULL,
    4242             :                                    NULL, NULL, yyscanner);
    4243         630 :                     $$ = (Node *) n;
    4244             :                 }
    4245             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4246             :                 {
    4247        4552 :                     Constraint *n = makeNode(Constraint);
    4248             : 
    4249        4552 :                     n->contype = CONSTR_UNIQUE;
    4250        4552 :                     n->location = @1;
    4251        4552 :                     n->keys = NIL;
    4252        4552 :                     n->including = NIL;
    4253        4552 :                     n->options = NIL;
    4254        4552 :                     n->indexname = $2;
    4255        4552 :                     n->indexspace = NULL;
    4256        4552 :                     processCASbits($3, @3, "UNIQUE",
    4257             :                                    &n->deferrable, &n->initdeferred, NULL,
    4258             :                                    NULL, NULL, yyscanner);
    4259        4552 :                     $$ = (Node *) n;
    4260             :                 }
    4261             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4262             :                 ConstraintAttributeSpec
    4263             :                 {
    4264        2378 :                     Constraint *n = makeNode(Constraint);
    4265             : 
    4266        2378 :                     n->contype = CONSTR_PRIMARY;
    4267        2378 :                     n->location = @1;
    4268        2378 :                     n->keys = $4;
    4269        2378 :                     n->without_overlaps = $5;
    4270        2378 :                     n->including = $7;
    4271        2378 :                     n->options = $8;
    4272        2378 :                     n->indexname = NULL;
    4273        2378 :                     n->indexspace = $9;
    4274        2378 :                     processCASbits($10, @10, "PRIMARY KEY",
    4275             :                                    &n->deferrable, &n->initdeferred, NULL,
    4276             :                                    NULL, NULL, yyscanner);
    4277        2378 :                     $$ = (Node *) n;
    4278             :                 }
    4279             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4280             :                 {
    4281        5894 :                     Constraint *n = makeNode(Constraint);
    4282             : 
    4283        5894 :                     n->contype = CONSTR_PRIMARY;
    4284        5894 :                     n->location = @1;
    4285        5894 :                     n->keys = NIL;
    4286        5894 :                     n->including = NIL;
    4287        5894 :                     n->options = NIL;
    4288        5894 :                     n->indexname = $3;
    4289        5894 :                     n->indexspace = NULL;
    4290        5894 :                     processCASbits($4, @4, "PRIMARY KEY",
    4291             :                                    &n->deferrable, &n->initdeferred, NULL,
    4292             :                                    NULL, NULL, yyscanner);
    4293        5894 :                     $$ = (Node *) n;
    4294             :                 }
    4295             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4296             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4297             :                 ConstraintAttributeSpec
    4298             :                 {
    4299         238 :                     Constraint *n = makeNode(Constraint);
    4300             : 
    4301         238 :                     n->contype = CONSTR_EXCLUSION;
    4302         238 :                     n->location = @1;
    4303         238 :                     n->access_method = $2;
    4304         238 :                     n->exclusions = $4;
    4305         238 :                     n->including = $6;
    4306         238 :                     n->options = $7;
    4307         238 :                     n->indexname = NULL;
    4308         238 :                     n->indexspace = $8;
    4309         238 :                     n->where_clause = $9;
    4310         238 :                     processCASbits($10, @10, "EXCLUDE",
    4311             :                                    &n->deferrable, &n->initdeferred, NULL,
    4312             :                                    NULL, NULL, yyscanner);
    4313         238 :                     $$ = (Node *) n;
    4314             :                 }
    4315             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4316             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4317             :                 {
    4318        1834 :                     Constraint *n = makeNode(Constraint);
    4319             : 
    4320        1834 :                     n->contype = CONSTR_FOREIGN;
    4321        1834 :                     n->location = @1;
    4322        1834 :                     n->pktable = $8;
    4323        1834 :                     n->fk_attrs = $4;
    4324        1834 :                     if ($5)
    4325             :                     {
    4326         296 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4327         296 :                         n->fk_with_period = true;
    4328             :                     }
    4329        1834 :                     n->pk_attrs = linitial($9);
    4330        1834 :                     if (lsecond($9))
    4331             :                     {
    4332         176 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4333         176 :                         n->pk_with_period = true;
    4334             :                     }
    4335        1834 :                     n->fk_matchtype = $10;
    4336        1834 :                     n->fk_upd_action = ($11)->updateAction->action;
    4337        1834 :                     n->fk_del_action = ($11)->deleteAction->action;
    4338        1834 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4339        1834 :                     processCASbits($12, @12, "FOREIGN KEY",
    4340             :                                    &n->deferrable, &n->initdeferred,
    4341             :                                    &n->is_enforced, &n->skip_validation, NULL,
    4342             :                                    yyscanner);
    4343        1834 :                     n->initially_valid = !n->skip_validation;
    4344        1834 :                     $$ = (Node *) n;
    4345             :                 }
    4346             :         ;
    4347             : 
    4348             : /*
    4349             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4350             :  * NOT NULL constraints is different.  For table constraints, we need to
    4351             :  * accept a column name, but for domain constraints, we don't.  (We could
    4352             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4353             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4354             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4355             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4356             :  * standard; we are just living with the bits of inconsistency that have built
    4357             :  * up over time.
    4358             :  */
    4359             : DomainConstraint:
    4360             :             CONSTRAINT name DomainConstraintElem
    4361             :                 {
    4362         156 :                     Constraint *n = castNode(Constraint, $3);
    4363             : 
    4364         156 :                     n->conname = $2;
    4365         156 :                     n->location = @1;
    4366         156 :                     $$ = (Node *) n;
    4367             :                 }
    4368          18 :             | DomainConstraintElem                  { $$ = $1; }
    4369             :         ;
    4370             : 
    4371             : DomainConstraintElem:
    4372             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4373             :                 {
    4374         156 :                     Constraint *n = makeNode(Constraint);
    4375             : 
    4376         156 :                     n->contype = CONSTR_CHECK;
    4377         156 :                     n->location = @1;
    4378         156 :                     n->raw_expr = $3;
    4379         156 :                     n->cooked_expr = NULL;
    4380         156 :                     processCASbits($5, @5, "CHECK",
    4381             :                                    NULL, NULL, NULL, &n->skip_validation,
    4382             :                                    &n->is_no_inherit, yyscanner);
    4383         144 :                     n->is_enforced = true;
    4384         144 :                     n->initially_valid = !n->skip_validation;
    4385         144 :                     $$ = (Node *) n;
    4386             :                 }
    4387             :             | NOT NULL_P ConstraintAttributeSpec
    4388             :                 {
    4389          30 :                     Constraint *n = makeNode(Constraint);
    4390             : 
    4391          30 :                     n->contype = CONSTR_NOTNULL;
    4392          30 :                     n->location = @1;
    4393          30 :                     n->keys = list_make1(makeString("value"));
    4394             :                     /* no NOT VALID, NO INHERIT support */
    4395          30 :                     processCASbits($3, @3, "NOT NULL",
    4396             :                                    NULL, NULL, NULL,
    4397             :                                    NULL, NULL, yyscanner);
    4398          30 :                     n->initially_valid = true;
    4399          30 :                     $$ = (Node *) n;
    4400             :                 }
    4401             :         ;
    4402             : 
    4403         138 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4404        8072 :             | /* EMPTY */                           {  $$ = false; }
    4405             :         ;
    4406             : 
    4407             : opt_without_overlaps:
    4408         570 :             WITHOUT OVERLAPS                        { $$ = true; }
    4409        2438 :             | /*EMPTY*/                             { $$ = false; }
    4410             :     ;
    4411             : 
    4412             : opt_column_list:
    4413       15054 :             '(' columnList ')'                      { $$ = $2; }
    4414       42280 :             | /*EMPTY*/                             { $$ = NIL; }
    4415             :         ;
    4416             : 
    4417             : columnList:
    4418       21644 :             columnElem                              { $$ = list_make1($1); }
    4419       44132 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4420             :         ;
    4421             : 
    4422             : optionalPeriodName:
    4423         472 :             ',' PERIOD columnElem { $$ = $3; }
    4424        2530 :             | /*EMPTY*/               { $$ = NULL; }
    4425             :     ;
    4426             : 
    4427             : opt_column_and_period_list:
    4428        1162 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4429         678 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4430             :         ;
    4431             : 
    4432             : columnElem: ColId
    4433             :                 {
    4434       66248 :                     $$ = (Node *) makeString($1);
    4435             :                 }
    4436             :         ;
    4437             : 
    4438         176 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4439        3070 :              |      /* EMPTY */                     { $$ = NIL; }
    4440             :         ;
    4441             : 
    4442             : key_match:  MATCH FULL
    4443             :             {
    4444         100 :                 $$ = FKCONSTR_MATCH_FULL;
    4445             :             }
    4446             :         | MATCH PARTIAL
    4447             :             {
    4448           0 :                 ereport(ERROR,
    4449             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4450             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4451             :                          parser_errposition(@1)));
    4452             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4453             :             }
    4454             :         | MATCH SIMPLE
    4455             :             {
    4456           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4457             :             }
    4458             :         | /*EMPTY*/
    4459             :             {
    4460        2562 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4461             :             }
    4462             :         ;
    4463             : 
    4464             : ExclusionConstraintList:
    4465         238 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4466             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4467         110 :                                                     { $$ = lappend($1, $3); }
    4468             :         ;
    4469             : 
    4470             : ExclusionConstraintElem: index_elem WITH any_operator
    4471             :             {
    4472         348 :                 $$ = list_make2($1, $3);
    4473             :             }
    4474             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4475             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4476             :             {
    4477           0 :                 $$ = list_make2($1, $5);
    4478             :             }
    4479             :         ;
    4480             : 
    4481             : OptWhereClause:
    4482         440 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4483        1242 :             | /*EMPTY*/                             { $$ = NULL; }
    4484             :         ;
    4485             : 
    4486             : key_actions:
    4487             :             key_update
    4488             :                 {
    4489          76 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4490             : 
    4491          76 :                     n->updateAction = $1;
    4492          76 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4493          76 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4494          76 :                     n->deleteAction->cols = NIL;
    4495          76 :                     $$ = n;
    4496             :                 }
    4497             :             | key_delete
    4498             :                 {
    4499         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4500             : 
    4501         150 :                     n->updateAction = palloc(sizeof(KeyAction));
    4502         150 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4503         150 :                     n->updateAction->cols = NIL;
    4504         150 :                     n->deleteAction = $1;
    4505         150 :                     $$ = n;
    4506             :                 }
    4507             :             | key_update key_delete
    4508             :                 {
    4509         162 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4510             : 
    4511         162 :                     n->updateAction = $1;
    4512         162 :                     n->deleteAction = $2;
    4513         162 :                     $$ = n;
    4514             :                 }
    4515             :             | key_delete key_update
    4516             :                 {
    4517         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4518             : 
    4519         150 :                     n->updateAction = $2;
    4520         150 :                     n->deleteAction = $1;
    4521         150 :                     $$ = n;
    4522             :                 }
    4523             :             | /*EMPTY*/
    4524             :                 {
    4525        2124 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4526             : 
    4527        2124 :                     n->updateAction = palloc(sizeof(KeyAction));
    4528        2124 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4529        2124 :                     n->updateAction->cols = NIL;
    4530        2124 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4531        2124 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4532        2124 :                     n->deleteAction->cols = NIL;
    4533        2124 :                     $$ = n;
    4534             :                 }
    4535             :         ;
    4536             : 
    4537             : key_update: ON UPDATE key_action
    4538             :                 {
    4539         394 :                     if (($3)->cols)
    4540           6 :                         ereport(ERROR,
    4541             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4542             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4543             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4544             :                                  parser_errposition(@1)));
    4545         388 :                     $$ = $3;
    4546             :                 }
    4547             :         ;
    4548             : 
    4549             : key_delete: ON DELETE_P key_action
    4550             :                 {
    4551         462 :                     $$ = $3;
    4552             :                 }
    4553             :         ;
    4554             : 
    4555             : key_action:
    4556             :             NO ACTION
    4557             :                 {
    4558          80 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4559             : 
    4560          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4561          80 :                     n->cols = NIL;
    4562          80 :                     $$ = n;
    4563             :                 }
    4564             :             | RESTRICT
    4565             :                 {
    4566          48 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4567             : 
    4568          48 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4569          48 :                     n->cols = NIL;
    4570          48 :                     $$ = n;
    4571             :                 }
    4572             :             | CASCADE
    4573             :                 {
    4574         434 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4575             : 
    4576         434 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4577         434 :                     n->cols = NIL;
    4578         434 :                     $$ = n;
    4579             :                 }
    4580             :             | SET NULL_P opt_column_list
    4581             :                 {
    4582         192 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4583             : 
    4584         192 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4585         192 :                     n->cols = $3;
    4586         192 :                     $$ = n;
    4587             :                 }
    4588             :             | SET DEFAULT opt_column_list
    4589             :                 {
    4590         102 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4591             : 
    4592         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4593         102 :                     n->cols = $3;
    4594         102 :                     $$ = n;
    4595             :                 }
    4596             :         ;
    4597             : 
    4598        2160 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4599       28906 :             | /*EMPTY*/                             { $$ = NIL; }
    4600             :         ;
    4601             : 
    4602             : /* Optional partition key specification */
    4603        5138 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4604       33534 :             | /*EMPTY*/         { $$ = NULL; }
    4605             :         ;
    4606             : 
    4607             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4608             :                 {
    4609        5144 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4610             : 
    4611        5144 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4612        5138 :                     n->partParams = $5;
    4613        5138 :                     n->location = @1;
    4614             : 
    4615        5138 :                     $$ = n;
    4616             :                 }
    4617             :         ;
    4618             : 
    4619        5144 : part_params:    part_elem                       { $$ = list_make1($1); }
    4620         466 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4621             :         ;
    4622             : 
    4623             : part_elem: ColId opt_collate opt_qualified_name
    4624             :                 {
    4625        5290 :                     PartitionElem *n = makeNode(PartitionElem);
    4626             : 
    4627        5290 :                     n->name = $1;
    4628        5290 :                     n->expr = NULL;
    4629        5290 :                     n->collation = $2;
    4630        5290 :                     n->opclass = $3;
    4631        5290 :                     n->location = @1;
    4632        5290 :                     $$ = n;
    4633             :                 }
    4634             :             | func_expr_windowless opt_collate opt_qualified_name
    4635             :                 {
    4636         134 :                     PartitionElem *n = makeNode(PartitionElem);
    4637             : 
    4638         134 :                     n->name = NULL;
    4639         134 :                     n->expr = $1;
    4640         134 :                     n->collation = $2;
    4641         134 :                     n->opclass = $3;
    4642         134 :                     n->location = @1;
    4643         134 :                     $$ = n;
    4644             :                 }
    4645             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4646             :                 {
    4647         186 :                     PartitionElem *n = makeNode(PartitionElem);
    4648             : 
    4649         186 :                     n->name = NULL;
    4650         186 :                     n->expr = $2;
    4651         186 :                     n->collation = $4;
    4652         186 :                     n->opclass = $5;
    4653         186 :                     n->location = @1;
    4654         186 :                     $$ = n;
    4655             :                 }
    4656             :         ;
    4657             : 
    4658             : table_access_method_clause:
    4659         122 :             USING name                          { $$ = $2; }
    4660       40474 :             | /*EMPTY*/                         { $$ = NULL; }
    4661             :         ;
    4662             : 
    4663             : /* WITHOUT OIDS is legacy only */
    4664             : OptWith:
    4665         790 :             WITH reloptions             { $$ = $2; }
    4666          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4667       39178 :             | /*EMPTY*/                 { $$ = NIL; }
    4668             :         ;
    4669             : 
    4670          60 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4671         104 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4672          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4673       39804 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4674             :         ;
    4675             : 
    4676         206 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4677       47274 :             | /*EMPTY*/                             { $$ = NULL; }
    4678             :         ;
    4679             : 
    4680          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4681        9374 :             | /*EMPTY*/                             { $$ = NULL; }
    4682             :         ;
    4683             : 
    4684       10446 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4685             :         ;
    4686             : 
    4687             : /*****************************************************************************
    4688             :  *
    4689             :  *      QUERY :
    4690             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4691             :  *                  ON expression-list FROM from_list
    4692             :  *
    4693             :  * Note: the expectation here is that the clauses after ON are a subset of
    4694             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4695             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4696             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4697             :  * errors as necessary at execution.
    4698             :  *
    4699             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4700             :  *
    4701             :  *****************************************************************************/
    4702             : 
    4703             : CreateStatsStmt:
    4704             :             CREATE STATISTICS opt_qualified_name
    4705             :             opt_name_list ON stats_params FROM from_list
    4706             :                 {
    4707         660 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4708             : 
    4709         660 :                     n->defnames = $3;
    4710         660 :                     n->stat_types = $4;
    4711         660 :                     n->exprs = $6;
    4712         660 :                     n->relations = $8;
    4713         660 :                     n->stxcomment = NULL;
    4714         660 :                     n->if_not_exists = false;
    4715         660 :                     $$ = (Node *) n;
    4716             :                 }
    4717             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4718             :             opt_name_list ON stats_params FROM from_list
    4719             :                 {
    4720          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4721             : 
    4722          12 :                     n->defnames = $6;
    4723          12 :                     n->stat_types = $7;
    4724          12 :                     n->exprs = $9;
    4725          12 :                     n->relations = $11;
    4726          12 :                     n->stxcomment = NULL;
    4727          12 :                     n->if_not_exists = true;
    4728          12 :                     $$ = (Node *) n;
    4729             :                 }
    4730             :             ;
    4731             : 
    4732             : /*
    4733             :  * Statistics attributes can be either simple column references, or arbitrary
    4734             :  * expressions in parens.  For compatibility with index attributes permitted
    4735             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4736             :  * written without parens.
    4737             :  */
    4738             : 
    4739         684 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4740         988 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4741             :         ;
    4742             : 
    4743             : stats_param:    ColId
    4744             :                 {
    4745        1192 :                     $$ = makeNode(StatsElem);
    4746        1192 :                     $$->name = $1;
    4747        1192 :                     $$->expr = NULL;
    4748             :                 }
    4749             :             | func_expr_windowless
    4750             :                 {
    4751          34 :                     $$ = makeNode(StatsElem);
    4752          34 :                     $$->name = NULL;
    4753          34 :                     $$->expr = $1;
    4754             :                 }
    4755             :             | '(' a_expr ')'
    4756             :                 {
    4757         446 :                     $$ = makeNode(StatsElem);
    4758         446 :                     $$->name = NULL;
    4759         446 :                     $$->expr = $2;
    4760             :                 }
    4761             :         ;
    4762             : 
    4763             : /*****************************************************************************
    4764             :  *
    4765             :  *      QUERY :
    4766             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4767             :  *                  SET STATISTICS  <SignedIconst>
    4768             :  *
    4769             :  *****************************************************************************/
    4770             : 
    4771             : AlterStatsStmt:
    4772             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4773             :                 {
    4774          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4775             : 
    4776          20 :                     n->defnames = $3;
    4777          20 :                     n->missing_ok = false;
    4778          20 :                     n->stxstattarget = $6;
    4779          20 :                     $$ = (Node *) n;
    4780             :                 }
    4781             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4782             :                 {
    4783           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4784             : 
    4785           6 :                     n->defnames = $5;
    4786           6 :                     n->missing_ok = true;
    4787           6 :                     n->stxstattarget = $8;
    4788           6 :                     $$ = (Node *) n;
    4789             :                 }
    4790             :             ;
    4791             : 
    4792             : /*****************************************************************************
    4793             :  *
    4794             :  *      QUERY :
    4795             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4796             :  *
    4797             :  *
    4798             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4799             :  *
    4800             :  *****************************************************************************/
    4801             : 
    4802             : CreateAsStmt:
    4803             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4804             :                 {
    4805        1192 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4806             : 
    4807        1192 :                     ctas->query = $6;
    4808        1192 :                     ctas->into = $4;
    4809        1192 :                     ctas->objtype = OBJECT_TABLE;
    4810        1192 :                     ctas->is_select_into = false;
    4811        1192 :                     ctas->if_not_exists = false;
    4812             :                     /* cram additional flags into the IntoClause */
    4813        1192 :                     $4->rel->relpersistence = $2;
    4814        1192 :                     $4->skipData = !($7);
    4815        1192 :                     $$ = (Node *) ctas;
    4816             :                 }
    4817             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4818             :                 {
    4819          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4820             : 
    4821          52 :                     ctas->query = $9;
    4822          52 :                     ctas->into = $7;
    4823          52 :                     ctas->objtype = OBJECT_TABLE;
    4824          52 :                     ctas->is_select_into = false;
    4825          52 :                     ctas->if_not_exists = true;
    4826             :                     /* cram additional flags into the IntoClause */
    4827          52 :                     $7->rel->relpersistence = $2;
    4828          52 :                     $7->skipData = !($10);
    4829          52 :                     $$ = (Node *) ctas;
    4830             :                 }
    4831             :         ;
    4832             : 
    4833             : create_as_target:
    4834             :             qualified_name opt_column_list table_access_method_clause
    4835             :             OptWith OnCommitOption OptTableSpace
    4836             :                 {
    4837        1332 :                     $$ = makeNode(IntoClause);
    4838        1332 :                     $$->rel = $1;
    4839        1332 :                     $$->colNames = $2;
    4840        1332 :                     $$->accessMethod = $3;
    4841        1332 :                     $$->options = $4;
    4842        1332 :                     $$->onCommit = $5;
    4843        1332 :                     $$->tableSpaceName = $6;
    4844        1332 :                     $$->viewQuery = NULL;
    4845        1332 :                     $$->skipData = false;        /* might get changed later */
    4846             :                 }
    4847             :         ;
    4848             : 
    4849             : opt_with_data:
    4850          36 :             WITH DATA_P                             { $$ = true; }
    4851         234 :             | WITH NO DATA_P                        { $$ = false; }
    4852        1944 :             | /*EMPTY*/                             { $$ = true; }
    4853             :         ;
    4854             : 
    4855             : 
    4856             : /*****************************************************************************
    4857             :  *
    4858             :  *      QUERY :
    4859             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4860             :  *
    4861             :  *****************************************************************************/
    4862             : 
    4863             : CreateMatViewStmt:
    4864             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4865             :                 {
    4866         550 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4867             : 
    4868         550 :                     ctas->query = $7;
    4869         550 :                     ctas->into = $5;
    4870         550 :                     ctas->objtype = OBJECT_MATVIEW;
    4871         550 :                     ctas->is_select_into = false;
    4872         550 :                     ctas->if_not_exists = false;
    4873             :                     /* cram additional flags into the IntoClause */
    4874         550 :                     $5->rel->relpersistence = $2;
    4875         550 :                     $5->skipData = !($8);
    4876         550 :                     $$ = (Node *) ctas;
    4877             :                 }
    4878             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4879             :                 {
    4880          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4881             : 
    4882          48 :                     ctas->query = $10;
    4883          48 :                     ctas->into = $8;
    4884          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4885          48 :                     ctas->is_select_into = false;
    4886          48 :                     ctas->if_not_exists = true;
    4887             :                     /* cram additional flags into the IntoClause */
    4888          48 :                     $8->rel->relpersistence = $2;
    4889          48 :                     $8->skipData = !($11);
    4890          48 :                     $$ = (Node *) ctas;
    4891             :                 }
    4892             :         ;
    4893             : 
    4894             : create_mv_target:
    4895             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4896             :                 {
    4897         598 :                     $$ = makeNode(IntoClause);
    4898         598 :                     $$->rel = $1;
    4899         598 :                     $$->colNames = $2;
    4900         598 :                     $$->accessMethod = $3;
    4901         598 :                     $$->options = $4;
    4902         598 :                     $$->onCommit = ONCOMMIT_NOOP;
    4903         598 :                     $$->tableSpaceName = $5;
    4904         598 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4905         598 :                     $$->skipData = false;        /* might get changed later */
    4906             :                 }
    4907             :         ;
    4908             : 
    4909           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4910         598 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4911             :         ;
    4912             : 
    4913             : 
    4914             : /*****************************************************************************
    4915             :  *
    4916             :  *      QUERY :
    4917             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4918             :  *
    4919             :  *****************************************************************************/
    4920             : 
    4921             : RefreshMatViewStmt:
    4922             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4923             :                 {
    4924         284 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4925             : 
    4926         284 :                     n->concurrent = $4;
    4927         284 :                     n->relation = $5;
    4928         284 :                     n->skipData = !($6);
    4929         284 :                     $$ = (Node *) n;
    4930             :                 }
    4931             :         ;
    4932             : 
    4933             : 
    4934             : /*****************************************************************************
    4935             :  *
    4936             :  *      QUERY :
    4937             :  *              CREATE SEQUENCE seqname
    4938             :  *              ALTER SEQUENCE seqname
    4939             :  *
    4940             :  *****************************************************************************/
    4941             : 
    4942             : CreateSeqStmt:
    4943             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4944             :                 {
    4945         720 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4946             : 
    4947         720 :                     $4->relpersistence = $2;
    4948         720 :                     n->sequence = $4;
    4949         720 :                     n->options = $5;
    4950         720 :                     n->ownerId = InvalidOid;
    4951         720 :                     n->if_not_exists = false;
    4952         720 :                     $$ = (Node *) n;
    4953             :                 }
    4954             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4955             :                 {
    4956          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4957             : 
    4958          24 :                     $7->relpersistence = $2;
    4959          24 :                     n->sequence = $7;
    4960          24 :                     n->options = $8;
    4961          24 :                     n->ownerId = InvalidOid;
    4962          24 :                     n->if_not_exists = true;
    4963          24 :                     $$ = (Node *) n;
    4964             :                 }
    4965             :         ;
    4966             : 
    4967             : AlterSeqStmt:
    4968             :             ALTER SEQUENCE qualified_name SeqOptList
    4969             :                 {
    4970         212 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4971             : 
    4972         212 :                     n->sequence = $3;
    4973         212 :                     n->options = $4;
    4974         212 :                     n->missing_ok = false;
    4975         212 :                     $$ = (Node *) n;
    4976             :                 }
    4977             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4978             :                 {
    4979          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4980             : 
    4981          12 :                     n->sequence = $5;
    4982          12 :                     n->options = $6;
    4983          12 :                     n->missing_ok = true;
    4984          12 :                     $$ = (Node *) n;
    4985             :                 }
    4986             : 
    4987             :         ;
    4988             : 
    4989         326 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4990         418 :             | /*EMPTY*/                             { $$ = NIL; }
    4991             :         ;
    4992             : 
    4993         118 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4994         424 :             | /*EMPTY*/                             { $$ = NIL; }
    4995             :         ;
    4996             : 
    4997         668 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    4998        1322 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    4999             :         ;
    5000             : 
    5001             : SeqOptElem: AS SimpleTypename
    5002             :                 {
    5003         236 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5004             :                 }
    5005             :             | CACHE NumericOnly
    5006             :                 {
    5007         236 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5008             :                 }
    5009             :             | CYCLE
    5010             :                 {
    5011          36 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5012             :                 }
    5013             :             | NO CYCLE
    5014             :                 {
    5015          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5016             :                 }
    5017             :             | INCREMENT opt_by NumericOnly
    5018             :                 {
    5019         352 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5020             :                 }
    5021             :             | LOGGED
    5022             :                 {
    5023           4 :                     $$ = makeDefElem("logged", NULL, @1);
    5024             :                 }
    5025             :             | MAXVALUE NumericOnly
    5026             :                 {
    5027          74 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5028             :                 }
    5029             :             | MINVALUE NumericOnly
    5030             :                 {
    5031          74 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5032             :                 }
    5033             :             | NO MAXVALUE
    5034             :                 {
    5035         208 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5036             :                 }
    5037             :             | NO MINVALUE
    5038             :                 {
    5039         208 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5040             :                 }
    5041             :             | OWNED BY any_name
    5042             :                 {
    5043         100 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5044             :                 }
    5045             :             | SEQUENCE NAME_P any_name
    5046             :                 {
    5047          88 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5048             :                 }
    5049             :             | START opt_with NumericOnly
    5050             :                 {
    5051         344 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5052             :                 }
    5053             :             | RESTART
    5054             :                 {
    5055           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5056             :                 }
    5057             :             | RESTART opt_with NumericOnly
    5058             :                 {
    5059          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5060             :                 }
    5061             :             | UNLOGGED
    5062             :                 {
    5063           4 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5064             :                 }
    5065             :         ;
    5066             : 
    5067             : opt_by:     BY
    5068             :             | /* EMPTY */
    5069             :       ;
    5070             : 
    5071             : NumericOnly:
    5072         322 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5073           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5074             :             | '-' FCONST
    5075             :                 {
    5076          22 :                     Float      *f = makeFloat($2);
    5077             : 
    5078          22 :                     doNegateFloat(f);
    5079          22 :                     $$ = (Node *) f;
    5080             :                 }
    5081       13476 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5082             :         ;
    5083             : 
    5084          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5085           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5086             :         ;
    5087             : 
    5088             : /*****************************************************************************
    5089             :  *
    5090             :  *      QUERIES :
    5091             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5092             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5093             :  *
    5094             :  *****************************************************************************/
    5095             : 
    5096             : CreatePLangStmt:
    5097             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5098             :             {
    5099             :                 /*
    5100             :                  * We now interpret parameterless CREATE LANGUAGE as
    5101             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5102             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5103             :                  * seems more useful than throwing an error.  We just
    5104             :                  * ignore TRUSTED, as the previous code would have too.
    5105             :                  */
    5106           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5107             : 
    5108           0 :                 n->if_not_exists = $2;
    5109           0 :                 n->extname = $6;
    5110           0 :                 n->options = NIL;
    5111           0 :                 $$ = (Node *) n;
    5112             :             }
    5113             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5114             :               HANDLER handler_name opt_inline_handler opt_validator
    5115             :             {
    5116         140 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5117             : 
    5118         140 :                 n->replace = $2;
    5119         140 :                 n->plname = $6;
    5120         140 :                 n->plhandler = $8;
    5121         140 :                 n->plinline = $9;
    5122         140 :                 n->plvalidator = $10;
    5123         140 :                 n->pltrusted = $3;
    5124         140 :                 $$ = (Node *) n;
    5125             :             }
    5126             :         ;
    5127             : 
    5128             : opt_trusted:
    5129         110 :             TRUSTED                                 { $$ = true; }
    5130          38 :             | /*EMPTY*/                             { $$ = false; }
    5131             :         ;
    5132             : 
    5133             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5134             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5135             :  * Work around by using simple names, instead.
    5136             :  */
    5137             : handler_name:
    5138         550 :             name                        { $$ = list_make1(makeString($1)); }
    5139           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5140             :         ;
    5141             : 
    5142             : opt_inline_handler:
    5143         122 :             INLINE_P handler_name                   { $$ = $2; }
    5144          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5145             :         ;
    5146             : 
    5147             : validator_clause:
    5148         122 :             VALIDATOR handler_name                  { $$ = $2; }
    5149           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5150             :         ;
    5151             : 
    5152             : opt_validator:
    5153         122 :             validator_clause                        { $$ = $1; }
    5154          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5155             :         ;
    5156             : 
    5157             : opt_procedural:
    5158             :             PROCEDURAL
    5159             :             | /*EMPTY*/
    5160             :         ;
    5161             : 
    5162             : /*****************************************************************************
    5163             :  *
    5164             :  *      QUERY:
    5165             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5166             :  *
    5167             :  *****************************************************************************/
    5168             : 
    5169             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5170             :                 {
    5171         116 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5172             : 
    5173         116 :                     n->tablespacename = $3;
    5174         116 :                     n->owner = $4;
    5175         116 :                     n->location = $6;
    5176         116 :                     n->options = $7;
    5177         116 :                     $$ = (Node *) n;
    5178             :                 }
    5179             :         ;
    5180             : 
    5181           6 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5182         110 :             | /*EMPTY */                { $$ = NULL; }
    5183             :         ;
    5184             : 
    5185             : /*****************************************************************************
    5186             :  *
    5187             :  *      QUERY :
    5188             :  *              DROP TABLESPACE <tablespace>
    5189             :  *
    5190             :  *      No need for drop behaviour as we cannot implement dependencies for
    5191             :  *      objects in other databases; we can only support RESTRICT.
    5192             :  *
    5193             :  ****************************************************************************/
    5194             : 
    5195             : DropTableSpaceStmt: DROP TABLESPACE name
    5196             :                 {
    5197          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5198             : 
    5199          64 :                     n->tablespacename = $3;
    5200          64 :                     n->missing_ok = false;
    5201          64 :                     $$ = (Node *) n;
    5202             :                 }
    5203             :                 |  DROP TABLESPACE IF_P EXISTS name
    5204             :                 {
    5205           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5206             : 
    5207           0 :                     n->tablespacename = $5;
    5208           0 :                     n->missing_ok = true;
    5209           0 :                     $$ = (Node *) n;
    5210             :                 }
    5211             :         ;
    5212             : 
    5213             : /*****************************************************************************
    5214             :  *
    5215             :  *      QUERY:
    5216             :  *             CREATE EXTENSION extension
    5217             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5218             :  *
    5219             :  *****************************************************************************/
    5220             : 
    5221             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5222             :                 {
    5223         502 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5224             : 
    5225         502 :                     n->extname = $3;
    5226         502 :                     n->if_not_exists = false;
    5227         502 :                     n->options = $5;
    5228         502 :                     $$ = (Node *) n;
    5229             :                 }
    5230             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5231             :                 {
    5232          18 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5233             : 
    5234          18 :                     n->extname = $6;
    5235          18 :                     n->if_not_exists = true;
    5236          18 :                     n->options = $8;
    5237          18 :                     $$ = (Node *) n;
    5238             :                 }
    5239             :         ;
    5240             : 
    5241             : create_extension_opt_list:
    5242             :             create_extension_opt_list create_extension_opt_item
    5243          98 :                 { $$ = lappend($1, $2); }
    5244             :             | /* EMPTY */
    5245         520 :                 { $$ = NIL; }
    5246             :         ;
    5247             : 
    5248             : create_extension_opt_item:
    5249             :             SCHEMA name
    5250             :                 {
    5251          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5252             :                 }
    5253             :             | VERSION_P NonReservedWord_or_Sconst
    5254             :                 {
    5255          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5256             :                 }
    5257             :             | FROM NonReservedWord_or_Sconst
    5258             :                 {
    5259           0 :                     ereport(ERROR,
    5260             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5261             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5262             :                              parser_errposition(@1)));
    5263             :                 }
    5264             :             | CASCADE
    5265             :                 {
    5266          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5267             :                 }
    5268             :         ;
    5269             : 
    5270             : /*****************************************************************************
    5271             :  *
    5272             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5273             :  *
    5274             :  *****************************************************************************/
    5275             : 
    5276             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5277             :                 {
    5278          38 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5279             : 
    5280          38 :                     n->extname = $3;
    5281          38 :                     n->options = $5;
    5282          38 :                     $$ = (Node *) n;
    5283             :                 }
    5284             :         ;
    5285             : 
    5286             : alter_extension_opt_list:
    5287             :             alter_extension_opt_list alter_extension_opt_item
    5288          38 :                 { $$ = lappend($1, $2); }
    5289             :             | /* EMPTY */
    5290          38 :                 { $$ = NIL; }
    5291             :         ;
    5292             : 
    5293             : alter_extension_opt_item:
    5294             :             TO NonReservedWord_or_Sconst
    5295             :                 {
    5296          38 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5297             :                 }
    5298             :         ;
    5299             : 
    5300             : /*****************************************************************************
    5301             :  *
    5302             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5303             :  *
    5304             :  *****************************************************************************/
    5305             : 
    5306             : AlterExtensionContentsStmt:
    5307             :             ALTER EXTENSION name add_drop object_type_name name
    5308             :                 {
    5309          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5310             : 
    5311          18 :                     n->extname = $3;
    5312          18 :                     n->action = $4;
    5313          18 :                     n->objtype = $5;
    5314          18 :                     n->object = (Node *) makeString($6);
    5315          18 :                     $$ = (Node *) n;
    5316             :                 }
    5317             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5318             :                 {
    5319          76 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5320             : 
    5321          76 :                     n->extname = $3;
    5322          76 :                     n->action = $4;
    5323          76 :                     n->objtype = $5;
    5324          76 :                     n->object = (Node *) $6;
    5325          76 :                     $$ = (Node *) n;
    5326             :                 }
    5327             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5328             :                 {
    5329           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5330             : 
    5331           8 :                     n->extname = $3;
    5332           8 :                     n->action = $4;
    5333           8 :                     n->objtype = OBJECT_AGGREGATE;
    5334           8 :                     n->object = (Node *) $6;
    5335           8 :                     $$ = (Node *) n;
    5336             :                 }
    5337             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5338             :                 {
    5339           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5340             : 
    5341           4 :                     n->extname = $3;
    5342           4 :                     n->action = $4;
    5343           4 :                     n->objtype = OBJECT_CAST;
    5344           4 :                     n->object = (Node *) list_make2($7, $9);
    5345           4 :                     $$ = (Node *) n;
    5346             :                 }
    5347             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5348             :                 {
    5349           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5350             : 
    5351           0 :                     n->extname = $3;
    5352           0 :                     n->action = $4;
    5353           0 :                     n->objtype = OBJECT_DOMAIN;
    5354           0 :                     n->object = (Node *) $6;
    5355           0 :                     $$ = (Node *) n;
    5356             :                 }
    5357             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5358             :                 {
    5359          98 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5360             : 
    5361          98 :                     n->extname = $3;
    5362          98 :                     n->action = $4;
    5363          98 :                     n->objtype = OBJECT_FUNCTION;
    5364          98 :                     n->object = (Node *) $6;
    5365          98 :                     $$ = (Node *) n;
    5366             :                 }
    5367             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5368             :                 {
    5369          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5370             : 
    5371          18 :                     n->extname = $3;
    5372          18 :                     n->action = $4;
    5373          18 :                     n->objtype = OBJECT_OPERATOR;
    5374          18 :                     n->object = (Node *) $6;
    5375          18 :                     $$ = (Node *) n;
    5376             :                 }
    5377             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5378             :                 {
    5379           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5380             : 
    5381           4 :                     n->extname = $3;
    5382           4 :                     n->action = $4;
    5383           4 :                     n->objtype = OBJECT_OPCLASS;
    5384           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5385           4 :                     $$ = (Node *) n;
    5386             :                 }
    5387             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5388             :                 {
    5389           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5390             : 
    5391           4 :                     n->extname = $3;
    5392           4 :                     n->action = $4;
    5393           4 :                     n->objtype = OBJECT_OPFAMILY;
    5394           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5395           4 :                     $$ = (Node *) n;
    5396             :                 }
    5397             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5398             :                 {
    5399           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5400             : 
    5401           0 :                     n->extname = $3;
    5402           0 :                     n->action = $4;
    5403           0 :                     n->objtype = OBJECT_PROCEDURE;
    5404           0 :                     n->object = (Node *) $6;
    5405           0 :                     $$ = (Node *) n;
    5406             :                 }
    5407             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5408             :                 {
    5409           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5410             : 
    5411           0 :                     n->extname = $3;
    5412           0 :                     n->action = $4;
    5413           0 :                     n->objtype = OBJECT_ROUTINE;
    5414           0 :                     n->object = (Node *) $6;
    5415           0 :                     $$ = (Node *) n;
    5416             :                 }
    5417             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5418             :                 {
    5419           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5420             : 
    5421           4 :                     n->extname = $3;
    5422           4 :                     n->action = $4;
    5423           4 :                     n->objtype = OBJECT_TRANSFORM;
    5424           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5425           4 :                     $$ = (Node *) n;
    5426             :                 }
    5427             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5428             :                 {
    5429           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5430             : 
    5431           8 :                     n->extname = $3;
    5432           8 :                     n->action = $4;
    5433           8 :                     n->objtype = OBJECT_TYPE;
    5434           8 :                     n->object = (Node *) $6;
    5435           8 :                     $$ = (Node *) n;
    5436             :                 }
    5437             :         ;
    5438             : 
    5439             : /*****************************************************************************
    5440             :  *
    5441             :  *      QUERY:
    5442             :  *             CREATE FOREIGN DATA WRAPPER name options
    5443             :  *
    5444             :  *****************************************************************************/
    5445             : 
    5446             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5447             :                 {
    5448         208 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5449             : 
    5450         208 :                     n->fdwname = $5;
    5451         208 :                     n->func_options = $6;
    5452         208 :                     n->options = $7;
    5453         208 :                     $$ = (Node *) n;
    5454             :                 }
    5455             :         ;
    5456             : 
    5457             : fdw_option:
    5458          56 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5459           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5460          48 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5461           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5462             :         ;
    5463             : 
    5464             : fdw_options:
    5465          90 :             fdw_option                          { $$ = list_make1($1); }
    5466          20 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5467             :         ;
    5468             : 
    5469             : opt_fdw_options:
    5470          54 :             fdw_options                         { $$ = $1; }
    5471         246 :             | /*EMPTY*/                         { $$ = NIL; }
    5472             :         ;
    5473             : 
    5474             : /*****************************************************************************
    5475             :  *
    5476             :  *      QUERY :
    5477             :  *              ALTER FOREIGN DATA WRAPPER name options
    5478             :  *
    5479             :  ****************************************************************************/
    5480             : 
    5481             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5482             :                 {
    5483          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5484             : 
    5485          86 :                     n->fdwname = $5;
    5486          86 :                     n->func_options = $6;
    5487          86 :                     n->options = $7;
    5488          86 :                     $$ = (Node *) n;
    5489             :                 }
    5490             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5491             :                 {
    5492          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5493             : 
    5494          36 :                     n->fdwname = $5;
    5495          36 :                     n->func_options = $6;
    5496          36 :                     n->options = NIL;
    5497          36 :                     $$ = (Node *) n;
    5498             :                 }
    5499             :         ;
    5500             : 
    5501             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5502             : create_generic_options:
    5503         734 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5504       73042 :             | /*EMPTY*/                                 { $$ = NIL; }
    5505             :         ;
    5506             : 
    5507             : generic_option_list:
    5508             :             generic_option_elem
    5509             :                 {
    5510         734 :                     $$ = list_make1($1);
    5511             :                 }
    5512             :             | generic_option_list ',' generic_option_elem
    5513             :                 {
    5514         480 :                     $$ = lappend($1, $3);
    5515             :                 }
    5516             :         ;
    5517             : 
    5518             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5519             : alter_generic_options:
    5520         488 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5521             :         ;
    5522             : 
    5523             : alter_generic_option_list:
    5524             :             alter_generic_option_elem
    5525             :                 {
    5526         488 :                     $$ = list_make1($1);
    5527             :                 }
    5528             :             | alter_generic_option_list ',' alter_generic_option_elem
    5529             :                 {
    5530         168 :                     $$ = lappend($1, $3);
    5531             :                 }
    5532             :         ;
    5533             : 
    5534             : alter_generic_option_elem:
    5535             :             generic_option_elem
    5536             :                 {
    5537         200 :                     $$ = $1;
    5538             :                 }
    5539             :             | SET generic_option_elem
    5540             :                 {
    5541         128 :                     $$ = $2;
    5542         128 :                     $$->defaction = DEFELEM_SET;
    5543             :                 }
    5544             :             | ADD_P generic_option_elem
    5545             :                 {
    5546         202 :                     $$ = $2;
    5547         202 :                     $$->defaction = DEFELEM_ADD;
    5548             :                 }
    5549             :             | DROP generic_option_name
    5550             :                 {
    5551         126 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5552             :                 }
    5553             :         ;
    5554             : 
    5555             : generic_option_elem:
    5556             :             generic_option_name generic_option_arg
    5557             :                 {
    5558        1744 :                     $$ = makeDefElem($1, $2, @1);
    5559             :                 }
    5560             :         ;
    5561             : 
    5562             : generic_option_name:
    5563        1870 :                 ColLabel            { $$ = $1; }
    5564             :         ;
    5565             : 
    5566             : /* We could use def_arg here, but the spec only requires string literals */
    5567             : generic_option_arg:
    5568        1744 :                 Sconst              { $$ = (Node *) makeString($1); }
    5569             :         ;
    5570             : 
    5571             : /*****************************************************************************
    5572             :  *
    5573             :  *      QUERY:
    5574             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5575             :  *
    5576             :  *****************************************************************************/
    5577             : 
    5578             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5579             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5580             :                 {
    5581         274 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5582             : 
    5583         274 :                     n->servername = $3;
    5584         274 :                     n->servertype = $4;
    5585         274 :                     n->version = $5;
    5586         274 :                     n->fdwname = $9;
    5587         274 :                     n->options = $10;
    5588         274 :                     n->if_not_exists = false;
    5589         274 :                     $$ = (Node *) n;
    5590             :                 }
    5591             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5592             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5593             :                 {
    5594          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5595             : 
    5596          24 :                     n->servername = $6;
    5597          24 :                     n->servertype = $7;
    5598          24 :                     n->version = $8;
    5599          24 :                     n->fdwname = $12;
    5600          24 :                     n->options = $13;
    5601          24 :                     n->if_not_exists = true;
    5602          24 :                     $$ = (Node *) n;
    5603             :                 }
    5604             :         ;
    5605             : 
    5606             : opt_type:
    5607          18 :             TYPE_P Sconst           { $$ = $2; }
    5608         280 :             | /*EMPTY*/             { $$ = NULL; }
    5609             :         ;
    5610             : 
    5611             : 
    5612             : foreign_server_version:
    5613          66 :             VERSION_P Sconst        { $$ = $2; }
    5614           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5615             :         ;
    5616             : 
    5617             : opt_foreign_server_version:
    5618          18 :             foreign_server_version  { $$ = $1; }
    5619         280 :             | /*EMPTY*/             { $$ = NULL; }
    5620             :         ;
    5621             : 
    5622             : /*****************************************************************************
    5623             :  *
    5624             :  *      QUERY :
    5625             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5626             :  *
    5627             :  ****************************************************************************/
    5628             : 
    5629             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5630             :                 {
    5631           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5632             : 
    5633           6 :                     n->servername = $3;
    5634           6 :                     n->version = $4;
    5635           6 :                     n->options = $5;
    5636           6 :                     n->has_version = true;
    5637           6 :                     $$ = (Node *) n;
    5638             :                 }
    5639             :             | ALTER SERVER name foreign_server_version
    5640             :                 {
    5641          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5642             : 
    5643          42 :                     n->servername = $3;
    5644          42 :                     n->version = $4;
    5645          42 :                     n->has_version = true;
    5646          42 :                     $$ = (Node *) n;
    5647             :                 }
    5648             :             | ALTER SERVER name alter_generic_options
    5649             :                 {
    5650         172 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5651             : 
    5652         172 :                     n->servername = $3;
    5653         172 :                     n->options = $4;
    5654         172 :                     $$ = (Node *) n;
    5655             :                 }
    5656             :         ;
    5657             : 
    5658             : /*****************************************************************************
    5659             :  *
    5660             :  *      QUERY:
    5661             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5662             :  *
    5663             :  *****************************************************************************/
    5664             : 
    5665             : CreateForeignTableStmt:
    5666             :         CREATE FOREIGN TABLE qualified_name
    5667             :             '(' OptTableElementList ')'
    5668             :             OptInherit SERVER name create_generic_options
    5669             :                 {
    5670         390 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5671             : 
    5672         390 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5673         390 :                     n->base.relation = $4;
    5674         390 :                     n->base.tableElts = $6;
    5675         390 :                     n->base.inhRelations = $8;
    5676         390 :                     n->base.ofTypename = NULL;
    5677         390 :                     n->base.constraints = NIL;
    5678         390 :                     n->base.options = NIL;
    5679         390 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5680         390 :                     n->base.tablespacename = NULL;
    5681         390 :                     n->base.if_not_exists = false;
    5682             :                     /* FDW-specific data */
    5683         390 :                     n->servername = $10;
    5684         390 :                     n->options = $11;
    5685         390 :                     $$ = (Node *) n;
    5686             :                 }
    5687             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5688             :             '(' OptTableElementList ')'
    5689             :             OptInherit SERVER name create_generic_options
    5690             :                 {
    5691           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5692             : 
    5693           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5694           0 :                     n->base.relation = $7;
    5695           0 :                     n->base.tableElts = $9;
    5696           0 :                     n->base.inhRelations = $11;
    5697           0 :                     n->base.ofTypename = NULL;
    5698           0 :                     n->base.constraints = NIL;
    5699           0 :                     n->base.options = NIL;
    5700           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5701           0 :                     n->base.tablespacename = NULL;
    5702           0 :                     n->base.if_not_exists = true;
    5703             :                     /* FDW-specific data */
    5704           0 :                     n->servername = $13;
    5705           0 :                     n->options = $14;
    5706           0 :                     $$ = (Node *) n;
    5707             :                 }
    5708             :         | CREATE FOREIGN TABLE qualified_name
    5709             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5710             :             SERVER name create_generic_options
    5711             :                 {
    5712          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5713             : 
    5714          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5715          90 :                     n->base.relation = $4;
    5716          90 :                     n->base.inhRelations = list_make1($7);
    5717          90 :                     n->base.tableElts = $8;
    5718          90 :                     n->base.partbound = $9;
    5719          90 :                     n->base.ofTypename = NULL;
    5720          90 :                     n->base.constraints = NIL;
    5721          90 :                     n->base.options = NIL;
    5722          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5723          90 :                     n->base.tablespacename = NULL;
    5724          90 :                     n->base.if_not_exists = false;
    5725             :                     /* FDW-specific data */
    5726          90 :                     n->servername = $11;
    5727          90 :                     n->options = $12;
    5728          90 :                     $$ = (Node *) n;
    5729             :                 }
    5730             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5731             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5732             :             SERVER name create_generic_options
    5733             :                 {
    5734           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5735             : 
    5736           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5737           0 :                     n->base.relation = $7;
    5738           0 :                     n->base.inhRelations = list_make1($10);
    5739           0 :                     n->base.tableElts = $11;
    5740           0 :                     n->base.partbound = $12;
    5741           0 :                     n->base.ofTypename = NULL;
    5742           0 :                     n->base.constraints = NIL;
    5743           0 :                     n->base.options = NIL;
    5744           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5745           0 :                     n->base.tablespacename = NULL;
    5746           0 :                     n->base.if_not_exists = true;
    5747             :                     /* FDW-specific data */
    5748           0 :                     n->servername = $14;
    5749           0 :                     n->options = $15;
    5750           0 :                     $$ = (Node *) n;
    5751             :                 }
    5752             :         ;
    5753             : 
    5754             : /*****************************************************************************
    5755             :  *
    5756             :  *      QUERY:
    5757             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5758             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5759             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5760             :  *
    5761             :  ****************************************************************************/
    5762             : 
    5763             : ImportForeignSchemaStmt:
    5764             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5765             :           FROM SERVER name INTO name create_generic_options
    5766             :             {
    5767          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5768             : 
    5769          48 :                 n->server_name = $8;
    5770          48 :                 n->remote_schema = $4;
    5771          48 :                 n->local_schema = $10;
    5772          48 :                 n->list_type = $5->type;
    5773          48 :                 n->table_list = $5->table_names;
    5774          48 :                 n->options = $11;
    5775          48 :                 $$ = (Node *) n;
    5776             :             }
    5777             :         ;
    5778             : 
    5779             : import_qualification_type:
    5780          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5781          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5782             :         ;
    5783             : 
    5784             : import_qualification:
    5785             :         import_qualification_type '(' relation_expr_list ')'
    5786             :             {
    5787          28 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5788             : 
    5789          28 :                 n->type = $1;
    5790          28 :                 n->table_names = $3;
    5791          28 :                 $$ = n;
    5792             :             }
    5793             :         | /*EMPTY*/
    5794             :             {
    5795          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5796          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5797          20 :                 n->table_names = NIL;
    5798          20 :                 $$ = n;
    5799             :             }
    5800             :         ;
    5801             : 
    5802             : /*****************************************************************************
    5803             :  *
    5804             :  *      QUERY:
    5805             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5806             :  *
    5807             :  *****************************************************************************/
    5808             : 
    5809             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5810             :                 {
    5811         246 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5812             : 
    5813         246 :                     n->user = $5;
    5814         246 :                     n->servername = $7;
    5815         246 :                     n->options = $8;
    5816         246 :                     n->if_not_exists = false;
    5817         246 :                     $$ = (Node *) n;
    5818             :                 }
    5819             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5820             :                 {
    5821           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5822             : 
    5823           6 :                     n->user = $8;
    5824           6 :                     n->servername = $10;
    5825           6 :                     n->options = $11;
    5826           6 :                     n->if_not_exists = true;
    5827           6 :                     $$ = (Node *) n;
    5828             :                 }
    5829             :         ;
    5830             : 
    5831             : /* User mapping authorization identifier */
    5832         442 : auth_ident: RoleSpec            { $$ = $1; }
    5833          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5834             :         ;
    5835             : 
    5836             : /*****************************************************************************
    5837             :  *
    5838             :  *      QUERY :
    5839             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5840             :  *
    5841             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5842             :  * only pro forma; but the SQL standard doesn't show one.
    5843             :  ****************************************************************************/
    5844             : 
    5845             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5846             :                 {
    5847          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5848             : 
    5849          88 :                     n->user = $5;
    5850          88 :                     n->servername = $7;
    5851          88 :                     n->missing_ok = false;
    5852          88 :                     $$ = (Node *) n;
    5853             :                 }
    5854             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5855             :                 {
    5856          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5857             : 
    5858          38 :                     n->user = $7;
    5859          38 :                     n->servername = $9;
    5860          38 :                     n->missing_ok = true;
    5861          38 :                     $$ = (Node *) n;
    5862             :                 }
    5863             :         ;
    5864             : 
    5865             : /*****************************************************************************
    5866             :  *
    5867             :  *      QUERY :
    5868             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5869             :  *
    5870             :  ****************************************************************************/
    5871             : 
    5872             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5873             :                 {
    5874         110 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5875             : 
    5876         110 :                     n->user = $5;
    5877         110 :                     n->servername = $7;
    5878         110 :                     n->options = $8;
    5879         110 :                     $$ = (Node *) n;
    5880             :                 }
    5881             :         ;
    5882             : 
    5883             : /*****************************************************************************
    5884             :  *
    5885             :  *      QUERIES:
    5886             :  *              CREATE POLICY name ON table
    5887             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5888             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5889             :  *                  [TO role, ...]
    5890             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5891             :  *              ALTER POLICY name ON table [TO role, ...]
    5892             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5893             :  *
    5894             :  *****************************************************************************/
    5895             : 
    5896             : CreatePolicyStmt:
    5897             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5898             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5899             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5900             :                 {
    5901         700 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5902             : 
    5903         700 :                     n->policy_name = $3;
    5904         700 :                     n->table = $5;
    5905         700 :                     n->permissive = $6;
    5906         700 :                     n->cmd_name = $7;
    5907         700 :                     n->roles = $8;
    5908         700 :                     n->qual = $9;
    5909         700 :                     n->with_check = $10;
    5910         700 :                     $$ = (Node *) n;
    5911             :                 }
    5912             :         ;
    5913             : 
    5914             : AlterPolicyStmt:
    5915             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5916             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5917             :                 {
    5918          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5919             : 
    5920          84 :                     n->policy_name = $3;
    5921          84 :                     n->table = $5;
    5922          84 :                     n->roles = $6;
    5923          84 :                     n->qual = $7;
    5924          84 :                     n->with_check = $8;
    5925          84 :                     $$ = (Node *) n;
    5926             :                 }
    5927             :         ;
    5928             : 
    5929             : RowSecurityOptionalExpr:
    5930         726 :             USING '(' a_expr ')'    { $$ = $3; }
    5931          58 :             | /* EMPTY */           { $$ = NULL; }
    5932             :         ;
    5933             : 
    5934             : RowSecurityOptionalWithCheck:
    5935         128 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5936         656 :             | /* EMPTY */                   { $$ = NULL; }
    5937             :         ;
    5938             : 
    5939             : RowSecurityDefaultToRole:
    5940         130 :             TO role_list            { $$ = $2; }
    5941         570 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5942             :         ;
    5943             : 
    5944             : RowSecurityOptionalToRole:
    5945          12 :             TO role_list            { $$ = $2; }
    5946          72 :             | /* EMPTY */           { $$ = NULL; }
    5947             :         ;
    5948             : 
    5949             : RowSecurityDefaultPermissive:
    5950             :             AS IDENT
    5951             :                 {
    5952          98 :                     if (strcmp($2, "permissive") == 0)
    5953          24 :                         $$ = true;
    5954          74 :                     else if (strcmp($2, "restrictive") == 0)
    5955          68 :                         $$ = false;
    5956             :                     else
    5957           6 :                         ereport(ERROR,
    5958             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5959             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5960             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5961             :                                  parser_errposition(@2)));
    5962             : 
    5963             :                 }
    5964         608 :             | /* EMPTY */           { $$ = true; }
    5965             :         ;
    5966             : 
    5967             : RowSecurityDefaultForCmd:
    5968         332 :             FOR row_security_cmd    { $$ = $2; }
    5969         368 :             | /* EMPTY */           { $$ = "all"; }
    5970             :         ;
    5971             : 
    5972             : row_security_cmd:
    5973          44 :             ALL             { $$ = "all"; }
    5974         116 :         |   SELECT          { $$ = "select"; }
    5975          44 :         |   INSERT          { $$ = "insert"; }
    5976          82 :         |   UPDATE          { $$ = "update"; }
    5977          46 :         |   DELETE_P        { $$ = "delete"; }
    5978             :         ;
    5979             : 
    5980             : /*****************************************************************************
    5981             :  *
    5982             :  *      QUERY:
    5983             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5984             :  *
    5985             :  *****************************************************************************/
    5986             : 
    5987             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5988             :                 {
    5989          64 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5990             : 
    5991          64 :                     n->amname = $4;
    5992          64 :                     n->handler_name = $8;
    5993          64 :                     n->amtype = $6;
    5994          64 :                     $$ = (Node *) n;
    5995             :                 }
    5996             :         ;
    5997             : 
    5998             : am_type:
    5999          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    6000          30 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    6001             :         ;
    6002             : 
    6003             : /*****************************************************************************
    6004             :  *
    6005             :  *      QUERIES :
    6006             :  *              CREATE TRIGGER ...
    6007             :  *
    6008             :  *****************************************************************************/
    6009             : 
    6010             : CreateTrigStmt:
    6011             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    6012             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    6013             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6014             :                 {
    6015        3260 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6016             : 
    6017        3260 :                     n->replace = $2;
    6018        3260 :                     n->isconstraint = false;
    6019        3260 :                     n->trigname = $4;
    6020        3260 :                     n->relation = $8;
    6021        3260 :                     n->funcname = $14;
    6022        3260 :                     n->args = $16;
    6023        3260 :                     n->row = $10;
    6024        3260 :                     n->timing = $5;
    6025        3260 :                     n->events = intVal(linitial($6));
    6026        3260 :                     n->columns = (List *) lsecond($6);
    6027        3260 :                     n->whenClause = $11;
    6028        3260 :                     n->transitionRels = $9;
    6029        3260 :                     n->deferrable = false;
    6030        3260 :                     n->initdeferred = false;
    6031        3260 :                     n->constrrel = NULL;
    6032        3260 :                     $$ = (Node *) n;
    6033             :                 }
    6034             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6035             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6036             :             FOR EACH ROW TriggerWhen
    6037             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6038             :                 {
    6039          62 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6040             : 
    6041          62 :                     n->replace = $2;
    6042          62 :                     if (n->replace) /* not supported, see CreateTrigger */
    6043           0 :                         ereport(ERROR,
    6044             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6045             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6046             :                                  parser_errposition(@1)));
    6047          62 :                     n->isconstraint = true;
    6048          62 :                     n->trigname = $5;
    6049          62 :                     n->relation = $9;
    6050          62 :                     n->funcname = $18;
    6051          62 :                     n->args = $20;
    6052          62 :                     n->row = true;
    6053          62 :                     n->timing = TRIGGER_TYPE_AFTER;
    6054          62 :                     n->events = intVal(linitial($7));
    6055          62 :                     n->columns = (List *) lsecond($7);
    6056          62 :                     n->whenClause = $15;
    6057          62 :                     n->transitionRels = NIL;
    6058          62 :                     processCASbits($11, @11, "TRIGGER",
    6059             :                                    &n->deferrable, &n->initdeferred, NULL,
    6060             :                                    NULL, NULL, yyscanner);
    6061          62 :                     n->constrrel = $10;
    6062          62 :                     $$ = (Node *) n;
    6063             :                 }
    6064             :         ;
    6065             : 
    6066             : TriggerActionTime:
    6067        1478 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6068        1650 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6069         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6070             :         ;
    6071             : 
    6072             : TriggerEvents:
    6073             :             TriggerOneEvent
    6074        3334 :                 { $$ = $1; }
    6075             :             | TriggerEvents OR TriggerOneEvent
    6076             :                 {
    6077        1212 :                     int         events1 = intVal(linitial($1));
    6078        1212 :                     int         events2 = intVal(linitial($3));
    6079        1212 :                     List       *columns1 = (List *) lsecond($1);
    6080        1212 :                     List       *columns2 = (List *) lsecond($3);
    6081             : 
    6082        1212 :                     if (events1 & events2)
    6083           6 :                         parser_yyerror("duplicate trigger events specified");
    6084             :                     /*
    6085             :                      * concat'ing the columns lists loses information about
    6086             :                      * which columns went with which event, but so long as
    6087             :                      * only UPDATE carries columns and we disallow multiple
    6088             :                      * UPDATE items, it doesn't matter.  Command execution
    6089             :                      * should just ignore the columns for non-UPDATE events.
    6090             :                      */
    6091        1206 :                     $$ = list_make2(makeInteger(events1 | events2),
    6092             :                                     list_concat(columns1, columns2));
    6093             :                 }
    6094             :         ;
    6095             : 
    6096             : TriggerOneEvent:
    6097             :             INSERT
    6098        1710 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6099             :             | DELETE_P
    6100         896 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6101             :             | UPDATE
    6102        1794 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6103             :             | UPDATE OF columnList
    6104         108 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6105             :             | TRUNCATE
    6106          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6107             :         ;
    6108             : 
    6109             : TriggerReferencing:
    6110         470 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6111        2790 :             | /*EMPTY*/                             { $$ = NIL; }
    6112             :         ;
    6113             : 
    6114             : TriggerTransitions:
    6115         470 :             TriggerTransition                       { $$ = list_make1($1); }
    6116         144 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6117             :         ;
    6118             : 
    6119             : TriggerTransition:
    6120             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6121             :                 {
    6122         614 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6123             : 
    6124         614 :                     n->name = $4;
    6125         614 :                     n->isNew = $1;
    6126         614 :                     n->isTable = $2;
    6127         614 :                     $$ = (Node *) n;
    6128             :                 }
    6129             :         ;
    6130             : 
    6131             : TransitionOldOrNew:
    6132         336 :             NEW                                     { $$ = true; }
    6133         278 :             | OLD                                   { $$ = false; }
    6134             :         ;
    6135             : 
    6136             : TransitionRowOrTable:
    6137         614 :             TABLE                                   { $$ = true; }
    6138             :             /*
    6139             :              * According to the standard, lack of a keyword here implies ROW.
    6140             :              * Support for that would require prohibiting ROW entirely here,
    6141             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6142             :              * allowing it to be optional, as the standard specifies) as the
    6143             :              * next token.  Requiring ROW seems cleanest and easiest to
    6144             :              * explain.
    6145             :              */
    6146           0 :             | ROW                                   { $$ = false; }
    6147             :         ;
    6148             : 
    6149             : TransitionRelName:
    6150         614 :             ColId                                   { $$ = $1; }
    6151             :         ;
    6152             : 
    6153             : TriggerForSpec:
    6154             :             FOR TriggerForOptEach TriggerForType
    6155             :                 {
    6156        3032 :                     $$ = $3;
    6157             :                 }
    6158             :             | /* EMPTY */
    6159             :                 {
    6160             :                     /*
    6161             :                      * If ROW/STATEMENT not specified, default to
    6162             :                      * STATEMENT, per SQL
    6163             :                      */
    6164         228 :                     $$ = false;
    6165             :                 }
    6166             :         ;
    6167             : 
    6168             : TriggerForOptEach:
    6169             :             EACH
    6170             :             | /*EMPTY*/
    6171             :         ;
    6172             : 
    6173             : TriggerForType:
    6174        2196 :             ROW                                     { $$ = true; }
    6175         836 :             | STATEMENT                             { $$ = false; }
    6176             :         ;
    6177             : 
    6178             : TriggerWhen:
    6179         194 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6180        3128 :             | /*EMPTY*/                             { $$ = NULL; }
    6181             :         ;
    6182             : 
    6183             : FUNCTION_or_PROCEDURE:
    6184             :             FUNCTION
    6185             :         |   PROCEDURE
    6186             :         ;
    6187             : 
    6188             : TriggerFuncArgs:
    6189         588 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6190         166 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6191        2734 :             | /*EMPTY*/                             { $$ = NIL; }
    6192             :         ;
    6193             : 
    6194             : TriggerFuncArg:
    6195             :             Iconst
    6196             :                 {
    6197          94 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6198             :                 }
    6199           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6200         638 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6201          22 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6202             :         ;
    6203             : 
    6204             : OptConstrFromTable:
    6205          12 :             FROM qualified_name                     { $$ = $2; }
    6206          50 :             | /*EMPTY*/                             { $$ = NULL; }
    6207             :         ;
    6208             : 
    6209             : ConstraintAttributeSpec:
    6210             :             /*EMPTY*/
    6211       17928 :                 { $$ = 0; }
    6212             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6213             :                 {
    6214             :                     /*
    6215             :                      * We must complain about conflicting options.
    6216             :                      * We could, but choose not to, complain about redundant
    6217             :                      * options (ie, where $2's bit is already set in $1).
    6218             :                      */
    6219        1644 :                     int     newspec = $1 | $2;
    6220             : 
    6221             :                     /* special message for this case */
    6222        1644 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6223           6 :                         ereport(ERROR,
    6224             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6225             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6226             :                                  parser_errposition(@2)));
    6227             :                     /* generic message for other conflicts */
    6228        1638 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6229        1638 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6230        1638 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6231           6 :                         ereport(ERROR,
    6232             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6233             :                                  errmsg("conflicting constraint properties"),
    6234             :                                  parser_errposition(@2)));
    6235        1632 :                     $$ = newspec;
    6236             :                 }
    6237             :         ;
    6238             : 
    6239             : ConstraintAttributeElem:
    6240          42 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6241         212 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6242          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6243         158 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6244         702 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6245         242 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6246         162 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6247          96 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6248             :         ;
    6249             : 
    6250             : 
    6251             : /*****************************************************************************
    6252             :  *
    6253             :  *      QUERIES :
    6254             :  *              CREATE EVENT TRIGGER ...
    6255             :  *              ALTER EVENT TRIGGER ...
    6256             :  *
    6257             :  *****************************************************************************/
    6258             : 
    6259             : CreateEventTrigStmt:
    6260             :             CREATE EVENT TRIGGER name ON ColLabel
    6261             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6262             :                 {
    6263          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6264             : 
    6265          98 :                     n->trigname = $4;
    6266          98 :                     n->eventname = $6;
    6267          98 :                     n->whenclause = NULL;
    6268          98 :                     n->funcname = $9;
    6269          98 :                     $$ = (Node *) n;
    6270             :                 }
    6271             :           | CREATE EVENT TRIGGER name ON ColLabel
    6272             :             WHEN event_trigger_when_list
    6273             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6274             :                 {
    6275         100 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6276             : 
    6277         100 :                     n->trigname = $4;
    6278         100 :                     n->eventname = $6;
    6279         100 :                     n->whenclause = $8;
    6280         100 :                     n->funcname = $11;
    6281         100 :                     $$ = (Node *) n;
    6282             :                 }
    6283             :         ;
    6284             : 
    6285             : event_trigger_when_list:
    6286             :           event_trigger_when_item
    6287         100 :             { $$ = list_make1($1); }
    6288             :         | event_trigger_when_list AND event_trigger_when_item
    6289           6 :             { $$ = lappend($1, $3); }
    6290             :         ;
    6291             : 
    6292             : event_trigger_when_item:
    6293             :         ColId IN_P '(' event_trigger_value_list ')'
    6294         106 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6295             :         ;
    6296             : 
    6297             : event_trigger_value_list:
    6298             :           SCONST
    6299         106 :             { $$ = list_make1(makeString($1)); }
    6300             :         | event_trigger_value_list ',' SCONST
    6301          66 :             { $$ = lappend($1, makeString($3)); }
    6302             :         ;
    6303             : 
    6304             : AlterEventTrigStmt:
    6305             :             ALTER EVENT TRIGGER name enable_trigger
    6306             :                 {
    6307          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6308             : 
    6309          48 :                     n->trigname = $4;
    6310          48 :                     n->tgenabled = $5;
    6311          48 :                     $$ = (Node *) n;
    6312             :                 }
    6313             :         ;
    6314             : 
    6315             : enable_trigger:
    6316           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6317           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6318          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6319          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6320             :         ;
    6321             : 
    6322             : /*****************************************************************************
    6323             :  *
    6324             :  *      QUERY :
    6325             :  *              CREATE ASSERTION ...
    6326             :  *
    6327             :  *****************************************************************************/
    6328             : 
    6329             : CreateAssertionStmt:
    6330             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6331             :                 {
    6332           0 :                     ereport(ERROR,
    6333             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6334             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6335             :                              parser_errposition(@1)));
    6336             : 
    6337             :                     $$ = NULL;
    6338             :                 }
    6339             :         ;
    6340             : 
    6341             : 
    6342             : /*****************************************************************************
    6343             :  *
    6344             :  *      QUERY :
    6345             :  *              define (aggregate,operator,type)
    6346             :  *
    6347             :  *****************************************************************************/
    6348             : 
    6349             : DefineStmt:
    6350             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6351             :                 {
    6352         638 :                     DefineStmt *n = makeNode(DefineStmt);
    6353             : 
    6354         638 :                     n->kind = OBJECT_AGGREGATE;
    6355         638 :                     n->oldstyle = false;
    6356         638 :                     n->replace = $2;
    6357         638 :                     n->defnames = $4;
    6358         638 :                     n->args = $5;
    6359         638 :                     n->definition = $6;
    6360         638 :                     $$ = (Node *) n;
    6361             :                 }
    6362             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6363             :                 {
    6364             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6365         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6366             : 
    6367         362 :                     n->kind = OBJECT_AGGREGATE;
    6368         362 :                     n->oldstyle = true;
    6369         362 :                     n->replace = $2;
    6370         362 :                     n->defnames = $4;
    6371         362 :                     n->args = NIL;
    6372         362 :                     n->definition = $5;
    6373         362 :                     $$ = (Node *) n;
    6374             :                 }
    6375             :             | CREATE OPERATOR any_operator definition
    6376             :                 {
    6377        1610 :                     DefineStmt *n = makeNode(DefineStmt);
    6378             : 
    6379        1610 :                     n->kind = OBJECT_OPERATOR;
    6380        1610 :                     n->oldstyle = false;
    6381        1610 :                     n->defnames = $3;
    6382        1610 :                     n->args = NIL;
    6383        1610 :                     n->definition = $4;
    6384        1610 :                     $$ = (Node *) n;
    6385             :                 }
    6386             :             | CREATE TYPE_P any_name definition
    6387             :                 {
    6388         230 :                     DefineStmt *n = makeNode(DefineStmt);
    6389             : 
    6390         230 :                     n->kind = OBJECT_TYPE;
    6391         230 :                     n->oldstyle = false;
    6392         230 :                     n->defnames = $3;
    6393         230 :                     n->args = NIL;
    6394         230 :                     n->definition = $4;
    6395         230 :                     $$ = (Node *) n;
    6396             :                 }
    6397             :             | CREATE TYPE_P any_name
    6398             :                 {
    6399             :                     /* Shell type (identified by lack of definition) */
    6400         172 :                     DefineStmt *n = makeNode(DefineStmt);
    6401             : 
    6402         172 :                     n->kind = OBJECT_TYPE;
    6403         172 :                     n->oldstyle = false;
    6404         172 :                     n->defnames = $3;
    6405         172 :                     n->args = NIL;
    6406         172 :                     n->definition = NIL;
    6407         172 :                     $$ = (Node *) n;
    6408             :                 }
    6409             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6410             :                 {
    6411        4532 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6412             : 
    6413             :                     /* can't use qualified_name, sigh */
    6414        4532 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6415        4532 :                     n->coldeflist = $6;
    6416        4532 :                     $$ = (Node *) n;
    6417             :                 }
    6418             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6419             :                 {
    6420         208 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6421             : 
    6422         208 :                     n->typeName = $3;
    6423         208 :                     n->vals = $7;
    6424         208 :                     $$ = (Node *) n;
    6425             :                 }
    6426             :             | CREATE TYPE_P any_name AS RANGE definition
    6427             :                 {
    6428         196 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6429             : 
    6430         196 :                     n->typeName = $3;
    6431         196 :                     n->params = $6;
    6432         196 :                     $$ = (Node *) n;
    6433             :                 }
    6434             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6435             :                 {
    6436          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6437             : 
    6438          40 :                     n->kind = OBJECT_TSPARSER;
    6439          40 :                     n->args = NIL;
    6440          40 :                     n->defnames = $5;
    6441          40 :                     n->definition = $6;
    6442          40 :                     $$ = (Node *) n;
    6443             :                 }
    6444             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6445             :                 {
    6446        2890 :                     DefineStmt *n = makeNode(DefineStmt);
    6447             : 
    6448        2890 :                     n->kind = OBJECT_TSDICTIONARY;
    6449        2890 :                     n->args = NIL;
    6450        2890 :                     n->defnames = $5;
    6451        2890 :                     n->definition = $6;
    6452        2890 :                     $$ = (Node *) n;
    6453             :                 }
    6454             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6455             :                 {
    6456         138 :                     DefineStmt *n = makeNode(DefineStmt);
    6457             : 
    6458         138 :                     n->kind = OBJECT_TSTEMPLATE;
    6459         138 :                     n->args = NIL;
    6460         138 :                     n->defnames = $5;
    6461         138 :                     n->definition = $6;
    6462         138 :                     $$ = (Node *) n;
    6463             :                 }
    6464             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6465             :                 {
    6466        2822 :                     DefineStmt *n = makeNode(DefineStmt);
    6467             : 
    6468        2822 :                     n->kind = OBJECT_TSCONFIGURATION;
    6469        2822 :                     n->args = NIL;
    6470        2822 :                     n->defnames = $5;
    6471        2822 :                     n->definition = $6;
    6472        2822 :                     $$ = (Node *) n;
    6473             :                 }
    6474             :             | CREATE COLLATION any_name definition
    6475             :                 {
    6476         298 :                     DefineStmt *n = makeNode(DefineStmt);
    6477             : 
    6478         298 :                     n->kind = OBJECT_COLLATION;
    6479         298 :                     n->args = NIL;
    6480         298 :                     n->defnames = $3;
    6481         298 :                     n->definition = $4;
    6482         298 :                     $$ = (Node *) n;
    6483             :                 }
    6484             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6485             :                 {
    6486          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6487             : 
    6488          18 :                     n->kind = OBJECT_COLLATION;
    6489          18 :                     n->args = NIL;
    6490          18 :                     n->defnames = $6;
    6491          18 :                     n->definition = $7;
    6492          18 :                     n->if_not_exists = true;
    6493          18 :                     $$ = (Node *) n;
    6494             :                 }
    6495             :             | CREATE COLLATION any_name FROM any_name
    6496             :                 {
    6497          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6498             : 
    6499          54 :                     n->kind = OBJECT_COLLATION;
    6500          54 :                     n->args = NIL;
    6501          54 :                     n->defnames = $3;
    6502          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6503          54 :                     $$ = (Node *) n;
    6504             :                 }
    6505             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6506             :                 {
    6507           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6508             : 
    6509           0 :                     n->kind = OBJECT_COLLATION;
    6510           0 :                     n->args = NIL;
    6511           0 :                     n->defnames = $6;
    6512           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6513           0 :                     n->if_not_exists = true;
    6514           0 :                     $$ = (Node *) n;
    6515             :                 }
    6516             :         ;
    6517             : 
    6518        9852 : definition: '(' def_list ')'                        { $$ = $2; }
    6519             :         ;
    6520             : 
    6521        9852 : def_list:   def_elem                                { $$ = list_make1($1); }
    6522       14934 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6523             :         ;
    6524             : 
    6525             : def_elem:   ColLabel '=' def_arg
    6526             :                 {
    6527       24428 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6528             :                 }
    6529             :             | ColLabel
    6530             :                 {
    6531         358 :                     $$ = makeDefElem($1, NULL, @1);
    6532             :                 }
    6533             :         ;
    6534             : 
    6535             : /* Note: any simple identifier will be returned as a type name! */
    6536       19826 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6537        3988 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6538        1186 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6539        1304 :             | NumericOnly                   { $$ = (Node *) $1; }
    6540        2048 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6541         164 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6542             :         ;
    6543             : 
    6544         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6545             :         ;
    6546             : 
    6547         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6548        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6549             :         ;
    6550             : 
    6551             : /*
    6552             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6553             :  * the item names needed in old aggregate definitions are likely to become
    6554             :  * SQL keywords.
    6555             :  */
    6556             : old_aggr_elem:  IDENT '=' def_arg
    6557             :                 {
    6558        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6559             :                 }
    6560             :         ;
    6561             : 
    6562             : opt_enum_val_list:
    6563         200 :         enum_val_list                           { $$ = $1; }
    6564           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6565             :         ;
    6566             : 
    6567             : enum_val_list:  Sconst
    6568         200 :                 { $$ = list_make1(makeString($1)); }
    6569             :             | enum_val_list ',' Sconst
    6570       10496 :                 { $$ = lappend($1, makeString($3)); }
    6571             :         ;
    6572             : 
    6573             : /*****************************************************************************
    6574             :  *
    6575             :  *  ALTER TYPE enumtype ADD ...
    6576             :  *
    6577             :  *****************************************************************************/
    6578             : 
    6579             : AlterEnumStmt:
    6580             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6581             :             {
    6582         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6583             : 
    6584         154 :                 n->typeName = $3;
    6585         154 :                 n->oldVal = NULL;
    6586         154 :                 n->newVal = $7;
    6587         154 :                 n->newValNeighbor = NULL;
    6588         154 :                 n->newValIsAfter = true;
    6589         154 :                 n->skipIfNewValExists = $6;
    6590         154 :                 $$ = (Node *) n;
    6591             :             }
    6592             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6593             :             {
    6594         196 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6595             : 
    6596         196 :                 n->typeName = $3;
    6597         196 :                 n->oldVal = NULL;
    6598         196 :                 n->newVal = $7;
    6599         196 :                 n->newValNeighbor = $9;
    6600         196 :                 n->newValIsAfter = false;
    6601         196 :                 n->skipIfNewValExists = $6;
    6602         196 :                 $$ = (Node *) n;
    6603             :             }
    6604             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6605             :             {
    6606          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6607             : 
    6608          22 :                 n->typeName = $3;
    6609          22 :                 n->oldVal = NULL;
    6610          22 :                 n->newVal = $7;
    6611          22 :                 n->newValNeighbor = $9;
    6612          22 :                 n->newValIsAfter = true;
    6613          22 :                 n->skipIfNewValExists = $6;
    6614          22 :                 $$ = (Node *) n;
    6615             :             }
    6616             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6617             :             {
    6618          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6619             : 
    6620          24 :                 n->typeName = $3;
    6621          24 :                 n->oldVal = $6;
    6622          24 :                 n->newVal = $8;
    6623          24 :                 n->newValNeighbor = NULL;
    6624          24 :                 n->newValIsAfter = false;
    6625          24 :                 n->skipIfNewValExists = false;
    6626          24 :                 $$ = (Node *) n;
    6627             :             }
    6628             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6629             :             {
    6630             :                 /*
    6631             :                  * The following problems must be solved before this can be
    6632             :                  * implemented:
    6633             :                  *
    6634             :                  * - There must be no instance of the target value in
    6635             :                  *   any table.
    6636             :                  *
    6637             :                  * - The value must not appear in any catalog metadata,
    6638             :                  *   such as stored view expressions or column defaults.
    6639             :                  *
    6640             :                  * - The value must not appear in any non-leaf page of a
    6641             :                  *   btree (and similar issues with other index types).
    6642             :                  *   This is problematic because a value could persist
    6643             :                  *   there long after it's gone from user-visible data.
    6644             :                  *
    6645             :                  * - Concurrent sessions must not be able to insert the
    6646             :                  *   value while the preceding conditions are being checked.
    6647             :                  *
    6648             :                  * - Possibly more...
    6649             :                  */
    6650           0 :                 ereport(ERROR,
    6651             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6652             :                          errmsg("dropping an enum value is not implemented"),
    6653             :                          parser_errposition(@4)));
    6654             :             }
    6655             :          ;
    6656             : 
    6657          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6658         360 :         | /* EMPTY */                          { $$ = false; }
    6659             :         ;
    6660             : 
    6661             : 
    6662             : /*****************************************************************************
    6663             :  *
    6664             :  *      QUERIES :
    6665             :  *              CREATE OPERATOR CLASS ...
    6666             :  *              CREATE OPERATOR FAMILY ...
    6667             :  *              ALTER OPERATOR FAMILY ...
    6668             :  *              DROP OPERATOR CLASS ...
    6669             :  *              DROP OPERATOR FAMILY ...
    6670             :  *
    6671             :  *****************************************************************************/
    6672             : 
    6673             : CreateOpClassStmt:
    6674             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6675             :             USING name opt_opfamily AS opclass_item_list
    6676             :                 {
    6677         394 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6678             : 
    6679         394 :                     n->opclassname = $4;
    6680         394 :                     n->isDefault = $5;
    6681         394 :                     n->datatype = $8;
    6682         394 :                     n->amname = $10;
    6683         394 :                     n->opfamilyname = $11;
    6684         394 :                     n->items = $13;
    6685         394 :                     $$ = (Node *) n;
    6686             :                 }
    6687             :         ;
    6688             : 
    6689             : opclass_item_list:
    6690         908 :             opclass_item                            { $$ = list_make1($1); }
    6691        3088 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6692             :         ;
    6693             : 
    6694             : opclass_item:
    6695             :             OPERATOR Iconst any_operator opclass_purpose
    6696             :                 {
    6697        1092 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6698        1092 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6699             : 
    6700        1092 :                     owa->objname = $3;
    6701        1092 :                     owa->objargs = NIL;
    6702        1092 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6703        1092 :                     n->name = owa;
    6704        1092 :                     n->number = $2;
    6705        1092 :                     n->order_family = $4;
    6706        1092 :                     $$ = (Node *) n;
    6707             :                 }
    6708             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6709             :                 {
    6710        1066 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6711             : 
    6712        1066 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6713        1066 :                     n->name = $3;
    6714        1066 :                     n->number = $2;
    6715        1066 :                     n->order_family = $4;
    6716        1066 :                     $$ = (Node *) n;
    6717             :                 }
    6718             :             | FUNCTION Iconst function_with_argtypes
    6719             :                 {
    6720        1386 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6721             : 
    6722        1386 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6723        1386 :                     n->name = $3;
    6724        1386 :                     n->number = $2;
    6725        1386 :                     $$ = (Node *) n;
    6726             :                 }
    6727             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6728             :                 {
    6729         252 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6730             : 
    6731         252 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6732         252 :                     n->name = $6;
    6733         252 :                     n->number = $2;
    6734         252 :                     n->class_args = $4;
    6735         252 :                     $$ = (Node *) n;
    6736             :                 }
    6737             :             | STORAGE Typename
    6738             :                 {
    6739         200 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6740             : 
    6741         200 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6742         200 :                     n->storedtype = $2;
    6743         200 :                     $$ = (Node *) n;
    6744             :                 }
    6745             :         ;
    6746             : 
    6747         290 : opt_default:    DEFAULT                     { $$ = true; }
    6748         168 :             | /*EMPTY*/                     { $$ = false; }
    6749             :         ;
    6750             : 
    6751          50 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6752         344 :             | /*EMPTY*/                     { $$ = NIL; }
    6753             :         ;
    6754             : 
    6755           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6756          72 :             | FOR ORDER BY any_name         { $$ = $4; }
    6757        2086 :             | /*EMPTY*/                     { $$ = NIL; }
    6758             :         ;
    6759             : 
    6760             : 
    6761             : CreateOpFamilyStmt:
    6762             :             CREATE OPERATOR FAMILY any_name USING name
    6763             :                 {
    6764         162 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6765             : 
    6766         162 :                     n->opfamilyname = $4;
    6767         162 :                     n->amname = $6;
    6768         162 :                     $$ = (Node *) n;
    6769             :                 }
    6770             :         ;
    6771             : 
    6772             : AlterOpFamilyStmt:
    6773             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6774             :                 {
    6775         514 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6776             : 
    6777         514 :                     n->opfamilyname = $4;
    6778         514 :                     n->amname = $6;
    6779         514 :                     n->isDrop = false;
    6780         514 :                     n->items = $8;
    6781         514 :                     $$ = (Node *) n;
    6782             :                 }
    6783             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6784             :                 {
    6785          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6786             : 
    6787          64 :                     n->opfamilyname = $4;
    6788          64 :                     n->amname = $6;
    6789          64 :                     n->isDrop = true;
    6790          64 :                     n->items = $8;
    6791          64 :                     $$ = (Node *) n;
    6792             :                 }
    6793             :         ;
    6794             : 
    6795             : opclass_drop_list:
    6796          64 :             opclass_drop                            { $$ = list_make1($1); }
    6797          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6798             :         ;
    6799             : 
    6800             : opclass_drop:
    6801             :             OPERATOR Iconst '(' type_list ')'
    6802             :                 {
    6803          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6804             : 
    6805          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6806          56 :                     n->number = $2;
    6807          56 :                     n->class_args = $4;
    6808          56 :                     $$ = (Node *) n;
    6809             :                 }
    6810             :             | FUNCTION Iconst '(' type_list ')'
    6811             :                 {
    6812          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6813             : 
    6814          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6815          38 :                     n->number = $2;
    6816          38 :                     n->class_args = $4;
    6817          38 :                     $$ = (Node *) n;
    6818             :                 }
    6819             :         ;
    6820             : 
    6821             : 
    6822             : DropOpClassStmt:
    6823             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6824             :                 {
    6825          38 :                     DropStmt *n = makeNode(DropStmt);
    6826             : 
    6827          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6828          38 :                     n->removeType = OBJECT_OPCLASS;
    6829          38 :                     n->behavior = $7;
    6830          38 :                     n->missing_ok = false;
    6831          38 :                     n->concurrent = false;
    6832          38 :                     $$ = (Node *) n;
    6833             :                 }
    6834             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6835             :                 {
    6836          18 :                     DropStmt *n = makeNode(DropStmt);
    6837             : 
    6838          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6839          18 :                     n->removeType = OBJECT_OPCLASS;
    6840          18 :                     n->behavior = $9;
    6841          18 :                     n->missing_ok = true;
    6842          18 :                     n->concurrent = false;
    6843          18 :                     $$ = (Node *) n;
    6844             :                 }
    6845             :         ;
    6846             : 
    6847             : DropOpFamilyStmt:
    6848             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6849             :                 {
    6850         110 :                     DropStmt *n = makeNode(DropStmt);
    6851             : 
    6852         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6853         110 :                     n->removeType = OBJECT_OPFAMILY;
    6854         110 :                     n->behavior = $7;
    6855         110 :                     n->missing_ok = false;
    6856         110 :                     n->concurrent = false;
    6857         110 :                     $$ = (Node *) n;
    6858             :                 }
    6859             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6860             :                 {
    6861          18 :                     DropStmt *n = makeNode(DropStmt);
    6862             : 
    6863          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6864          18 :                     n->removeType = OBJECT_OPFAMILY;
    6865          18 :                     n->behavior = $9;
    6866          18 :                     n->missing_ok = true;
    6867          18 :                     n->concurrent = false;
    6868          18 :                     $$ = (Node *) n;
    6869             :                 }
    6870             :         ;
    6871             : 
    6872             : 
    6873             : /*****************************************************************************
    6874             :  *
    6875             :  *      QUERY:
    6876             :  *
    6877             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6878             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6879             :  *
    6880             :  *****************************************************************************/
    6881             : DropOwnedStmt:
    6882             :             DROP OWNED BY role_list opt_drop_behavior
    6883             :                 {
    6884         154 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6885             : 
    6886         154 :                     n->roles = $4;
    6887         154 :                     n->behavior = $5;
    6888         154 :                     $$ = (Node *) n;
    6889             :                 }
    6890             :         ;
    6891             : 
    6892             : ReassignOwnedStmt:
    6893             :             REASSIGN OWNED BY role_list TO RoleSpec
    6894             :                 {
    6895          52 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6896             : 
    6897          52 :                     n->roles = $4;
    6898          52 :                     n->newrole = $6;
    6899          52 :                     $$ = (Node *) n;
    6900             :                 }
    6901             :         ;
    6902             : 
    6903             : /*****************************************************************************
    6904             :  *
    6905             :  *      QUERY:
    6906             :  *
    6907             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6908             :  *           [ RESTRICT | CASCADE ]
    6909             :  *
    6910             :  *****************************************************************************/
    6911             : 
    6912             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6913             :                 {
    6914        1312 :                     DropStmt *n = makeNode(DropStmt);
    6915             : 
    6916        1312 :                     n->removeType = $2;
    6917        1312 :                     n->missing_ok = true;
    6918        1312 :                     n->objects = $5;
    6919        1312 :                     n->behavior = $6;
    6920        1312 :                     n->concurrent = false;
    6921        1312 :                     $$ = (Node *) n;
    6922             :                 }
    6923             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6924             :                 {
    6925       15946 :                     DropStmt *n = makeNode(DropStmt);
    6926             : 
    6927       15946 :                     n->removeType = $2;
    6928       15946 :                     n->missing_ok = false;
    6929       15946 :                     n->objects = $3;
    6930       15946 :                     n->behavior = $4;
    6931       15946 :                     n->concurrent = false;
    6932       15946 :                     $$ = (Node *) n;
    6933             :                 }
    6934             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6935             :                 {
    6936          78 :                     DropStmt *n = makeNode(DropStmt);
    6937             : 
    6938          78 :                     n->removeType = $2;
    6939          78 :                     n->missing_ok = true;
    6940          78 :                     n->objects = $5;
    6941          78 :                     n->behavior = $6;
    6942          78 :                     n->concurrent = false;
    6943          78 :                     $$ = (Node *) n;
    6944             :                 }
    6945             :             | DROP drop_type_name name_list opt_drop_behavior
    6946             :                 {
    6947        1408 :                     DropStmt *n = makeNode(DropStmt);
    6948             : 
    6949        1408 :                     n->removeType = $2;
    6950        1408 :                     n->missing_ok = false;
    6951        1408 :                     n->objects = $3;
    6952        1408 :                     n->behavior = $4;
    6953        1408 :                     n->concurrent = false;
    6954        1408 :                     $$ = (Node *) n;
    6955             :                 }
    6956             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6957             :                 {
    6958        1124 :                     DropStmt *n = makeNode(DropStmt);
    6959             : 
    6960        1124 :                     n->removeType = $2;
    6961        1124 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6962        1124 :                     n->behavior = $6;
    6963        1124 :                     n->missing_ok = false;
    6964        1124 :                     n->concurrent = false;
    6965        1124 :                     $$ = (Node *) n;
    6966             :                 }
    6967             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6968             :                 {
    6969          48 :                     DropStmt *n = makeNode(DropStmt);
    6970             : 
    6971          48 :                     n->removeType = $2;
    6972          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6973          48 :                     n->behavior = $8;
    6974          48 :                     n->missing_ok = true;
    6975          48 :                     n->concurrent = false;
    6976          48 :                     $$ = (Node *) n;
    6977             :                 }
    6978             :             | DROP TYPE_P type_name_list opt_drop_behavior
    6979             :                 {
    6980         560 :                     DropStmt *n = makeNode(DropStmt);
    6981             : 
    6982         560 :                     n->removeType = OBJECT_TYPE;
    6983         560 :                     n->missing_ok = false;
    6984         560 :                     n->objects = $3;
    6985         560 :                     n->behavior = $4;
    6986         560 :                     n->concurrent = false;
    6987         560 :                     $$ = (Node *) n;
    6988             :                 }
    6989             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    6990             :                 {
    6991          22 :                     DropStmt *n = makeNode(DropStmt);
    6992             : 
    6993          22 :                     n->removeType = OBJECT_TYPE;
    6994          22 :                     n->missing_ok = true;
    6995          22 :                     n->objects = $5;
    6996          22 :                     n->behavior = $6;
    6997          22 :                     n->concurrent = false;
    6998          22 :                     $$ = (Node *) n;
    6999             :                 }
    7000             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    7001             :                 {
    7002         464 :                     DropStmt *n = makeNode(DropStmt);
    7003             : 
    7004         464 :                     n->removeType = OBJECT_DOMAIN;
    7005         464 :                     n->missing_ok = false;
    7006         464 :                     n->objects = $3;
    7007         464 :                     n->behavior = $4;
    7008         464 :                     n->concurrent = false;
    7009         464 :                     $$ = (Node *) n;
    7010             :                 }
    7011             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7012             :                 {
    7013          18 :                     DropStmt *n = makeNode(DropStmt);
    7014             : 
    7015          18 :                     n->removeType = OBJECT_DOMAIN;
    7016          18 :                     n->missing_ok = true;
    7017          18 :                     n->objects = $5;
    7018          18 :                     n->behavior = $6;
    7019          18 :                     n->concurrent = false;
    7020          18 :                     $$ = (Node *) n;
    7021             :                 }
    7022             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7023             :                 {
    7024         172 :                     DropStmt *n = makeNode(DropStmt);
    7025             : 
    7026         172 :                     n->removeType = OBJECT_INDEX;
    7027         172 :                     n->missing_ok = false;
    7028         172 :                     n->objects = $4;
    7029         172 :                     n->behavior = $5;
    7030         172 :                     n->concurrent = true;
    7031         172 :                     $$ = (Node *) n;
    7032             :                 }
    7033             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7034             :                 {
    7035          12 :                     DropStmt *n = makeNode(DropStmt);
    7036             : 
    7037          12 :                     n->removeType = OBJECT_INDEX;
    7038          12 :                     n->missing_ok = true;
    7039          12 :                     n->objects = $6;
    7040          12 :                     n->behavior = $7;
    7041          12 :                     n->concurrent = true;
    7042          12 :                     $$ = (Node *) n;
    7043             :                 }
    7044             :         ;
    7045             : 
    7046             : /* object types taking any_name/any_name_list */
    7047             : object_type_any_name:
    7048       14892 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7049         192 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7050        1010 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7051         130 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7052         784 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7053         184 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7054          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7055          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7056         192 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7057          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7058        2756 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7059         114 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7060        2760 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7061             :         ;
    7062             : 
    7063             : /*
    7064             :  * object types taking name/name_list
    7065             :  *
    7066             :  * DROP handles some of them separately
    7067             :  */
    7068             : 
    7069             : object_type_name:
    7070         230 :             drop_type_name                          { $$ = $1; }
    7071         234 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7072          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7073          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7074           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7075             :         ;
    7076             : 
    7077             : drop_type_name:
    7078          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7079         126 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7080         146 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7081         154 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7082         152 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7083         380 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7084         582 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7085         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7086             :         ;
    7087             : 
    7088             : /* object types attached to a table */
    7089             : object_type_name_on_any_name:
    7090         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7091         268 :             | RULE                                  { $$ = OBJECT_RULE; }
    7092         792 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7093             :         ;
    7094             : 
    7095             : any_name_list:
    7096       26102 :             any_name                                { $$ = list_make1($1); }
    7097        4238 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7098             :         ;
    7099             : 
    7100       66050 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7101        9548 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7102             :         ;
    7103             : 
    7104             : attrs:      '.' attr_name
    7105      130630 :                     { $$ = list_make1(makeString($2)); }
    7106             :             | attrs '.' attr_name
    7107          96 :                     { $$ = lappend($1, makeString($3)); }
    7108             :         ;
    7109             : 
    7110             : type_name_list:
    7111        1064 :             Typename                                { $$ = list_make1($1); }
    7112          96 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7113             :         ;
    7114             : 
    7115             : /*****************************************************************************
    7116             :  *
    7117             :  *      QUERY:
    7118             :  *              truncate table relname1, relname2, ...
    7119             :  *
    7120             :  *****************************************************************************/
    7121             : 
    7122             : TruncateStmt:
    7123             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7124             :                 {
    7125        2930 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7126             : 
    7127        2930 :                     n->relations = $3;
    7128        2930 :                     n->restart_seqs = $4;
    7129        2930 :                     n->behavior = $5;
    7130        2930 :                     $$ = (Node *) n;
    7131             :                 }
    7132             :         ;
    7133             : 
    7134             : opt_restart_seqs:
    7135          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7136          24 :             | RESTART IDENTITY_P        { $$ = true; }
    7137        2882 :             | /* EMPTY */               { $$ = false; }
    7138             :         ;
    7139             : 
    7140             : /*****************************************************************************
    7141             :  *
    7142             :  * COMMENT ON <object> IS <text>
    7143             :  *
    7144             :  *****************************************************************************/
    7145             : 
    7146             : CommentStmt:
    7147             :             COMMENT ON object_type_any_name any_name IS comment_text
    7148             :                 {
    7149        5786 :                     CommentStmt *n = makeNode(CommentStmt);
    7150             : 
    7151        5786 :                     n->objtype = $3;
    7152        5786 :                     n->object = (Node *) $4;
    7153        5786 :                     n->comment = $6;
    7154        5786 :                     $$ = (Node *) n;
    7155             :                 }
    7156             :             | COMMENT ON COLUMN any_name IS comment_text
    7157             :                 {
    7158         118 :                     CommentStmt *n = makeNode(CommentStmt);
    7159             : 
    7160         118 :                     n->objtype = OBJECT_COLUMN;
    7161         118 :                     n->object = (Node *) $4;
    7162         118 :                     n->comment = $6;
    7163         118 :                     $$ = (Node *) n;
    7164             :                 }
    7165             :             | COMMENT ON object_type_name name IS comment_text
    7166             :                 {
    7167         464 :                     CommentStmt *n = makeNode(CommentStmt);
    7168             : 
    7169         464 :                     n->objtype = $3;
    7170         464 :                     n->object = (Node *) makeString($4);
    7171         464 :                     n->comment = $6;
    7172         464 :                     $$ = (Node *) n;
    7173             :                 }
    7174             :             | COMMENT ON TYPE_P Typename IS comment_text
    7175             :                 {
    7176          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7177             : 
    7178          56 :                     n->objtype = OBJECT_TYPE;
    7179          56 :                     n->object = (Node *) $4;
    7180          56 :                     n->comment = $6;
    7181          56 :                     $$ = (Node *) n;
    7182             :                 }
    7183             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7184             :                 {
    7185           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7186             : 
    7187           8 :                     n->objtype = OBJECT_DOMAIN;
    7188           8 :                     n->object = (Node *) $4;
    7189           8 :                     n->comment = $6;
    7190           8 :                     $$ = (Node *) n;
    7191             :                 }
    7192             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7193             :                 {
    7194          44 :                     CommentStmt *n = makeNode(CommentStmt);
    7195             : 
    7196          44 :                     n->objtype = OBJECT_AGGREGATE;
    7197          44 :                     n->object = (Node *) $4;
    7198          44 :                     n->comment = $6;
    7199          44 :                     $$ = (Node *) n;
    7200             :                 }
    7201             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7202             :                 {
    7203         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7204             : 
    7205         170 :                     n->objtype = OBJECT_FUNCTION;
    7206         170 :                     n->object = (Node *) $4;
    7207         170 :                     n->comment = $6;
    7208         170 :                     $$ = (Node *) n;
    7209             :                 }
    7210             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7211             :                 {
    7212          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7213             : 
    7214          18 :                     n->objtype = OBJECT_OPERATOR;
    7215          18 :                     n->object = (Node *) $4;
    7216          18 :                     n->comment = $6;
    7217          18 :                     $$ = (Node *) n;
    7218             :                 }
    7219             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7220             :                 {
    7221         116 :                     CommentStmt *n = makeNode(CommentStmt);
    7222             : 
    7223         116 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7224         116 :                     n->object = (Node *) lappend($6, makeString($4));
    7225         116 :                     n->comment = $8;
    7226         116 :                     $$ = (Node *) n;
    7227             :                 }
    7228             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7229             :                 {
    7230          38 :                     CommentStmt *n = makeNode(CommentStmt);
    7231             : 
    7232          38 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7233             :                     /*
    7234             :                      * should use Typename not any_name in the production, but
    7235             :                      * there's a shift/reduce conflict if we do that, so fix it
    7236             :                      * up here.
    7237             :                      */
    7238          38 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7239          38 :                     n->comment = $9;
    7240          38 :                     $$ = (Node *) n;
    7241             :                 }
    7242             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7243             :                 {
    7244          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7245             : 
    7246          40 :                     n->objtype = $3;
    7247          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7248          40 :                     n->comment = $8;
    7249          40 :                     $$ = (Node *) n;
    7250             :                 }
    7251             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7252             :                 {
    7253           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7254             : 
    7255           0 :                     n->objtype = OBJECT_PROCEDURE;
    7256           0 :                     n->object = (Node *) $4;
    7257           0 :                     n->comment = $6;
    7258           0 :                     $$ = (Node *) n;
    7259             :                 }
    7260             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7261             :                 {
    7262           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7263             : 
    7264           0 :                     n->objtype = OBJECT_ROUTINE;
    7265           0 :                     n->object = (Node *) $4;
    7266           0 :                     n->comment = $6;
    7267           0 :                     $$ = (Node *) n;
    7268             :                 }
    7269             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7270             :                 {
    7271          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7272             : 
    7273          14 :                     n->objtype = OBJECT_TRANSFORM;
    7274          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7275          14 :                     n->comment = $9;
    7276          14 :                     $$ = (Node *) n;
    7277             :                 }
    7278             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7279             :                 {
    7280           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7281             : 
    7282           0 :                     n->objtype = OBJECT_OPCLASS;
    7283           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7284           0 :                     n->comment = $9;
    7285           0 :                     $$ = (Node *) n;
    7286             :                 }
    7287             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7288             :                 {
    7289           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7290             : 
    7291           0 :                     n->objtype = OBJECT_OPFAMILY;
    7292           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7293           0 :                     n->comment = $9;
    7294           0 :                     $$ = (Node *) n;
    7295             :                 }
    7296             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7297             :                 {
    7298          28 :                     CommentStmt *n = makeNode(CommentStmt);
    7299             : 
    7300          28 :                     n->objtype = OBJECT_LARGEOBJECT;
    7301          28 :                     n->object = (Node *) $5;
    7302          28 :                     n->comment = $7;
    7303          28 :                     $$ = (Node *) n;
    7304             :                 }
    7305             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7306             :                 {
    7307           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7308             : 
    7309           0 :                     n->objtype = OBJECT_CAST;
    7310           0 :                     n->object = (Node *) list_make2($5, $7);
    7311           0 :                     n->comment = $10;
    7312           0 :                     $$ = (Node *) n;
    7313             :                 }
    7314             :         ;
    7315             : 
    7316             : comment_text:
    7317        6796 :             Sconst                              { $$ = $1; }
    7318         104 :             | NULL_P                            { $$ = NULL; }
    7319             :         ;
    7320             : 
    7321             : 
    7322             : /*****************************************************************************
    7323             :  *
    7324             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7325             :  *
    7326             :  *  As with COMMENT ON, <object> can refer to various types of database
    7327             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7328             :  *
    7329             :  *****************************************************************************/
    7330             : 
    7331             : SecLabelStmt:
    7332             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7333             :             IS security_label
    7334             :                 {
    7335          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7336             : 
    7337          48 :                     n->provider = $3;
    7338          48 :                     n->objtype = $5;
    7339          48 :                     n->object = (Node *) $6;
    7340          48 :                     n->label = $8;
    7341          48 :                     $$ = (Node *) n;
    7342             :                 }
    7343             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7344             :               IS security_label
    7345             :                 {
    7346           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7347             : 
    7348           4 :                     n->provider = $3;
    7349           4 :                     n->objtype = OBJECT_COLUMN;
    7350           4 :                     n->object = (Node *) $6;
    7351           4 :                     n->label = $8;
    7352           4 :                     $$ = (Node *) n;
    7353             :                 }
    7354             :             | SECURITY LABEL opt_provider ON object_type_name name
    7355             :               IS security_label
    7356             :                 {
    7357          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7358             : 
    7359          44 :                     n->provider = $3;
    7360          44 :                     n->objtype = $5;
    7361          44 :                     n->object = (Node *) makeString($6);
    7362          44 :                     n->label = $8;
    7363          44 :                     $$ = (Node *) n;
    7364             :                 }
    7365             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7366             :               IS security_label
    7367             :                 {
    7368           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7369             : 
    7370           0 :                     n->provider = $3;
    7371           0 :                     n->objtype = OBJECT_TYPE;
    7372           0 :                     n->object = (Node *) $6;
    7373           0 :                     n->label = $8;
    7374           0 :                     $$ = (Node *) n;
    7375             :                 }
    7376             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7377             :               IS security_label
    7378             :                 {
    7379           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7380             : 
    7381           2 :                     n->provider = $3;
    7382           2 :                     n->objtype = OBJECT_DOMAIN;
    7383           2 :                     n->object = (Node *) $6;
    7384           2 :                     n->label = $8;
    7385           2 :                     $$ = (Node *) n;
    7386             :                 }
    7387             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7388             :               IS security_label
    7389             :                 {
    7390           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7391             : 
    7392           0 :                     n->provider = $3;
    7393           0 :                     n->objtype = OBJECT_AGGREGATE;
    7394           0 :                     n->object = (Node *) $6;
    7395           0 :                     n->label = $8;
    7396           0 :                     $$ = (Node *) n;
    7397             :                 }
    7398             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7399             :               IS security_label
    7400             :                 {
    7401           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7402             : 
    7403           2 :                     n->provider = $3;
    7404           2 :                     n->objtype = OBJECT_FUNCTION;
    7405           2 :                     n->object = (Node *) $6;
    7406           2 :                     n->label = $8;
    7407           2 :                     $$ = (Node *) n;
    7408             :                 }
    7409             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7410             :               IS security_label
    7411             :                 {
    7412           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7413             : 
    7414           0 :                     n->provider = $3;
    7415           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7416           0 :                     n->object = (Node *) $7;
    7417           0 :                     n->label = $9;
    7418           0 :                     $$ = (Node *) n;
    7419             :                 }
    7420             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7421             :               IS security_label
    7422             :                 {
    7423           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7424             : 
    7425           0 :                     n->provider = $3;
    7426           0 :                     n->objtype = OBJECT_PROCEDURE;
    7427           0 :                     n->object = (Node *) $6;
    7428           0 :                     n->label = $8;
    7429           0 :                     $$ = (Node *) n;
    7430             :                 }
    7431             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7432             :               IS security_label
    7433             :                 {
    7434           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7435             : 
    7436           0 :                     n->provider = $3;
    7437           0 :                     n->objtype = OBJECT_ROUTINE;
    7438           0 :                     n->object = (Node *) $6;
    7439           0 :                     n->label = $8;
    7440           0 :                     $$ = (Node *) n;
    7441             :                 }
    7442             :         ;
    7443             : 
    7444          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7445          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7446             :         ;
    7447             : 
    7448         100 : security_label: Sconst              { $$ = $1; }
    7449           0 :                 | NULL_P            { $$ = NULL; }
    7450             :         ;
    7451             : 
    7452             : /*****************************************************************************
    7453             :  *
    7454             :  *      QUERY:
    7455             :  *          fetch/move
    7456             :  *
    7457             :  *****************************************************************************/
    7458             : 
    7459             : FetchStmt:  FETCH fetch_args
    7460             :                 {
    7461        7446 :                     FetchStmt *n = (FetchStmt *) $2;
    7462             : 
    7463        7446 :                     n->ismove = false;
    7464        7446 :                     $$ = (Node *) n;
    7465             :                 }
    7466             :             | MOVE fetch_args
    7467             :                 {
    7468          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7469             : 
    7470          68 :                     n->ismove = true;
    7471          68 :                     $$ = (Node *) n;
    7472             :                 }
    7473             :         ;
    7474             : 
    7475             : fetch_args: cursor_name
    7476             :                 {
    7477         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7478             : 
    7479         266 :                     n->portalname = $1;
    7480         266 :                     n->direction = FETCH_FORWARD;
    7481         266 :                     n->howMany = 1;
    7482         266 :                     $$ = (Node *) n;
    7483             :                 }
    7484             :             | from_in cursor_name
    7485             :                 {
    7486         218 :                     FetchStmt *n = makeNode(FetchStmt);
    7487             : 
    7488         218 :                     n->portalname = $2;
    7489         218 :                     n->direction = FETCH_FORWARD;
    7490         218 :                     n->howMany = 1;
    7491         218 :                     $$ = (Node *) n;
    7492             :                 }
    7493             :             | NEXT opt_from_in cursor_name
    7494             :                 {
    7495        2008 :                     FetchStmt *n = makeNode(FetchStmt);
    7496             : 
    7497        2008 :                     n->portalname = $3;
    7498        2008 :                     n->direction = FETCH_FORWARD;
    7499        2008 :                     n->howMany = 1;
    7500        2008 :                     $$ = (Node *) n;
    7501             :                 }
    7502             :             | PRIOR opt_from_in cursor_name
    7503             :                 {
    7504          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7505             : 
    7506          30 :                     n->portalname = $3;
    7507          30 :                     n->direction = FETCH_BACKWARD;
    7508          30 :                     n->howMany = 1;
    7509          30 :                     $$ = (Node *) n;
    7510             :                 }
    7511             :             | FIRST_P opt_from_in cursor_name
    7512             :                 {
    7513          24 :                     FetchStmt *n = makeNode(FetchStmt);
    7514             : 
    7515          24 :                     n->portalname = $3;
    7516          24 :                     n->direction = FETCH_ABSOLUTE;
    7517          24 :                     n->howMany = 1;
    7518          24 :                     $$ = (Node *) n;
    7519             :                 }
    7520             :             | LAST_P opt_from_in cursor_name
    7521             :                 {
    7522          18 :                     FetchStmt *n = makeNode(FetchStmt);
    7523             : 
    7524          18 :                     n->portalname = $3;
    7525          18 :                     n->direction = FETCH_ABSOLUTE;
    7526          18 :                     n->howMany = -1;
    7527          18 :                     $$ = (Node *) n;
    7528             :                 }
    7529             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7530             :                 {
    7531          88 :                     FetchStmt *n = makeNode(FetchStmt);
    7532             : 
    7533          88 :                     n->portalname = $4;
    7534          88 :                     n->direction = FETCH_ABSOLUTE;
    7535          88 :                     n->howMany = $2;
    7536          88 :                     $$ = (Node *) n;
    7537             :                 }
    7538             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7539             :                 {
    7540          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7541             : 
    7542          30 :                     n->portalname = $4;
    7543          30 :                     n->direction = FETCH_RELATIVE;
    7544          30 :                     n->howMany = $2;
    7545          30 :                     $$ = (Node *) n;
    7546             :                 }
    7547             :             | SignedIconst opt_from_in cursor_name
    7548             :                 {
    7549        4128 :                     FetchStmt *n = makeNode(FetchStmt);
    7550             : 
    7551        4128 :                     n->portalname = $3;
    7552        4128 :                     n->direction = FETCH_FORWARD;
    7553        4128 :                     n->howMany = $1;
    7554        4128 :                     $$ = (Node *) n;
    7555             :                 }
    7556             :             | ALL opt_from_in cursor_name
    7557             :                 {
    7558         268 :                     FetchStmt *n = makeNode(FetchStmt);
    7559             : 
    7560         268 :                     n->portalname = $3;
    7561         268 :                     n->direction = FETCH_FORWARD;
    7562         268 :                     n->howMany = FETCH_ALL;
    7563         268 :                     $$ = (Node *) n;
    7564             :                 }
    7565             :             | FORWARD opt_from_in cursor_name
    7566             :                 {
    7567          28 :                     FetchStmt *n = makeNode(FetchStmt);
    7568             : 
    7569          28 :                     n->portalname = $3;
    7570          28 :                     n->direction = FETCH_FORWARD;
    7571          28 :                     n->howMany = 1;
    7572          28 :                     $$ = (Node *) n;
    7573             :                 }
    7574             :             | FORWARD SignedIconst opt_from_in cursor_name
    7575             :                 {
    7576           6 :                     FetchStmt *n = makeNode(FetchStmt);
    7577             : 
    7578           6 :                     n->portalname = $4;
    7579           6 :                     n->direction = FETCH_FORWARD;
    7580           6 :                     n->howMany = $2;
    7581           6 :                     $$ = (Node *) n;
    7582             :                 }
    7583             :             | FORWARD ALL opt_from_in cursor_name
    7584             :                 {
    7585          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7586             : 
    7587          14 :                     n->portalname = $4;
    7588          14 :                     n->direction = FETCH_FORWARD;
    7589          14 :                     n->howMany = FETCH_ALL;
    7590          14 :                     $$ = (Node *) n;
    7591             :                 }
    7592             :             | BACKWARD opt_from_in cursor_name
    7593             :                 {
    7594          78 :                     FetchStmt *n = makeNode(FetchStmt);
    7595             : 
    7596          78 :                     n->portalname = $3;
    7597          78 :                     n->direction = FETCH_BACKWARD;
    7598          78 :                     n->howMany = 1;
    7599          78 :                     $$ = (Node *) n;
    7600             :                 }
    7601             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7602             :                 {
    7603         220 :                     FetchStmt *n = makeNode(FetchStmt);
    7604             : 
    7605         220 :                     n->portalname = $4;
    7606         220 :                     n->direction = FETCH_BACKWARD;
    7607         220 :                     n->howMany = $2;
    7608         220 :                     $$ = (Node *) n;
    7609             :                 }
    7610             :             | BACKWARD ALL opt_from_in cursor_name
    7611             :                 {
    7612          90 :                     FetchStmt *n = makeNode(FetchStmt);
    7613             : 
    7614          90 :                     n->portalname = $4;
    7615          90 :                     n->direction = FETCH_BACKWARD;
    7616          90 :                     n->howMany = FETCH_ALL;
    7617          90 :                     $$ = (Node *) n;
    7618             :                 }
    7619             :         ;
    7620             : 
    7621             : from_in:    FROM
    7622             :             | IN_P
    7623             :         ;
    7624             : 
    7625             : opt_from_in:    from_in
    7626             :             | /* EMPTY */
    7627             :         ;
    7628             : 
    7629             : 
    7630             : /*****************************************************************************
    7631             :  *
    7632             :  * GRANT and REVOKE statements
    7633             :  *
    7634             :  *****************************************************************************/
    7635             : 
    7636             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7637             :             opt_grant_grant_option opt_granted_by
    7638             :                 {
    7639       11494 :                     GrantStmt *n = makeNode(GrantStmt);
    7640             : 
    7641       11494 :                     n->is_grant = true;
    7642       11494 :                     n->privileges = $2;
    7643       11494 :                     n->targtype = ($4)->targtype;
    7644       11494 :                     n->objtype = ($4)->objtype;
    7645       11494 :                     n->objects = ($4)->objs;
    7646       11494 :                     n->grantees = $6;
    7647       11494 :                     n->grant_option = $7;
    7648       11494 :                     n->grantor = $8;
    7649       11494 :                     $$ = (Node *) n;
    7650             :                 }
    7651             :         ;
    7652             : 
    7653             : RevokeStmt:
    7654             :             REVOKE privileges ON privilege_target
    7655             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7656             :                 {
    7657       10134 :                     GrantStmt *n = makeNode(GrantStmt);
    7658             : 
    7659       10134 :                     n->is_grant = false;
    7660       10134 :                     n->grant_option = false;
    7661       10134 :                     n->privileges = $2;
    7662       10134 :                     n->targtype = ($4)->targtype;
    7663       10134 :                     n->objtype = ($4)->objtype;
    7664       10134 :                     n->objects = ($4)->objs;
    7665       10134 :                     n->grantees = $6;
    7666       10134 :                     n->grantor = $7;
    7667       10134 :                     n->behavior = $8;
    7668       10134 :                     $$ = (Node *) n;
    7669             :                 }
    7670             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7671             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7672             :                 {
    7673          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7674             : 
    7675          16 :                     n->is_grant = false;
    7676          16 :                     n->grant_option = true;
    7677          16 :                     n->privileges = $5;
    7678          16 :                     n->targtype = ($7)->targtype;
    7679          16 :                     n->objtype = ($7)->objtype;
    7680          16 :                     n->objects = ($7)->objs;
    7681          16 :                     n->grantees = $9;
    7682          16 :                     n->grantor = $10;
    7683          16 :                     n->behavior = $11;
    7684          16 :                     $$ = (Node *) n;
    7685             :                 }
    7686             :         ;
    7687             : 
    7688             : 
    7689             : /*
    7690             :  * Privilege names are represented as strings; the validity of the privilege
    7691             :  * names gets checked at execution.  This is a bit annoying but we have little
    7692             :  * choice because of the syntactic conflict with lists of role names in
    7693             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7694             :  * production any reserved keywords that need to be usable as privilege names.
    7695             :  */
    7696             : 
    7697             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7698             : privileges: privilege_list
    7699       19158 :                 { $$ = $1; }
    7700             :             | ALL
    7701        2548 :                 { $$ = NIL; }
    7702             :             | ALL PRIVILEGES
    7703         122 :                 { $$ = NIL; }
    7704             :             | ALL '(' columnList ')'
    7705             :                 {
    7706          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7707             : 
    7708          18 :                     n->priv_name = NULL;
    7709          18 :                     n->cols = $3;
    7710          18 :                     $$ = list_make1(n);
    7711             :                 }
    7712             :             | ALL PRIVILEGES '(' columnList ')'
    7713             :                 {
    7714           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7715             : 
    7716           0 :                     n->priv_name = NULL;
    7717           0 :                     n->cols = $4;
    7718           0 :                     $$ = list_make1(n);
    7719             :                 }
    7720             :         ;
    7721             : 
    7722       20078 : privilege_list: privilege                           { $$ = list_make1($1); }
    7723         564 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7724             :         ;
    7725             : 
    7726             : privilege:  SELECT opt_column_list
    7727             :             {
    7728        9272 :                 AccessPriv *n = makeNode(AccessPriv);
    7729             : 
    7730        9272 :                 n->priv_name = pstrdup($1);
    7731        9272 :                 n->cols = $2;
    7732        9272 :                 $$ = n;
    7733             :             }
    7734             :         | REFERENCES opt_column_list
    7735             :             {
    7736          16 :                 AccessPriv *n = makeNode(AccessPriv);
    7737             : 
    7738          16 :                 n->priv_name = pstrdup($1);
    7739          16 :                 n->cols = $2;
    7740          16 :                 $$ = n;
    7741             :             }
    7742             :         | CREATE opt_column_list
    7743             :             {
    7744         290 :                 AccessPriv *n = makeNode(AccessPriv);
    7745             : 
    7746         290 :                 n->priv_name = pstrdup($1);
    7747         290 :                 n->cols = $2;
    7748         290 :                 $$ = n;
    7749             :             }
    7750             :         | ALTER SYSTEM_P
    7751             :             {
    7752          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7753          24 :                 n->priv_name = pstrdup("alter system");
    7754          24 :                 n->cols = NIL;
    7755          24 :                 $$ = n;
    7756             :             }
    7757             :         | ColId opt_column_list
    7758             :             {
    7759       11040 :                 AccessPriv *n = makeNode(AccessPriv);
    7760             : 
    7761       11040 :                 n->priv_name = $1;
    7762       11040 :                 n->cols = $2;
    7763       11040 :                 $$ = n;
    7764             :             }
    7765             :         ;
    7766             : 
    7767             : parameter_name_list:
    7768             :         parameter_name
    7769             :             {
    7770          76 :                 $$ = list_make1(makeString($1));
    7771             :             }
    7772             :         | parameter_name_list ',' parameter_name
    7773             :             {
    7774          50 :                 $$ = lappend($1, makeString($3));
    7775             :             }
    7776             :         ;
    7777             : 
    7778             : parameter_name:
    7779             :         ColId
    7780             :             {
    7781         126 :                 $$ = $1;
    7782             :             }
    7783             :         | parameter_name '.' ColId
    7784             :             {
    7785          32 :                 $$ = psprintf("%s.%s", $1, $3);
    7786             :             }
    7787             :         ;
    7788             : 
    7789             : 
    7790             : /* Don't bother trying to fold the first two rules into one using
    7791             :  * opt_table.  You're going to get conflicts.
    7792             :  */
    7793             : privilege_target:
    7794             :             qualified_name_list
    7795             :                 {
    7796       11164 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7797             : 
    7798       11164 :                     n->targtype = ACL_TARGET_OBJECT;
    7799       11164 :                     n->objtype = OBJECT_TABLE;
    7800       11164 :                     n->objs = $1;
    7801       11164 :                     $$ = n;
    7802             :                 }
    7803             :             | TABLE qualified_name_list
    7804             :                 {
    7805         412 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7806             : 
    7807         412 :                     n->targtype = ACL_TARGET_OBJECT;
    7808         412 :                     n->objtype = OBJECT_TABLE;
    7809         412 :                     n->objs = $2;
    7810         412 :                     $$ = n;
    7811             :                 }
    7812             :             | SEQUENCE qualified_name_list
    7813             :                 {
    7814          24 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7815             : 
    7816          24 :                     n->targtype = ACL_TARGET_OBJECT;
    7817          24 :                     n->objtype = OBJECT_SEQUENCE;
    7818          24 :                     n->objs = $2;
    7819          24 :                     $$ = n;
    7820             :                 }
    7821             :             | FOREIGN DATA_P WRAPPER name_list
    7822             :                 {
    7823          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7824             : 
    7825          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7826          92 :                     n->objtype = OBJECT_FDW;
    7827          92 :                     n->objs = $4;
    7828          92 :                     $$ = n;
    7829             :                 }
    7830             :             | FOREIGN SERVER name_list
    7831             :                 {
    7832          88 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7833             : 
    7834          88 :                     n->targtype = ACL_TARGET_OBJECT;
    7835          88 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7836          88 :                     n->objs = $3;
    7837          88 :                     $$ = n;
    7838             :                 }
    7839             :             | FUNCTION function_with_argtypes_list
    7840             :                 {
    7841        8750 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7842             : 
    7843        8750 :                     n->targtype = ACL_TARGET_OBJECT;
    7844        8750 :                     n->objtype = OBJECT_FUNCTION;
    7845        8750 :                     n->objs = $2;
    7846        8750 :                     $$ = n;
    7847             :                 }
    7848             :             | PROCEDURE function_with_argtypes_list
    7849             :                 {
    7850          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7851             : 
    7852          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7853          42 :                     n->objtype = OBJECT_PROCEDURE;
    7854          42 :                     n->objs = $2;
    7855          42 :                     $$ = n;
    7856             :                 }
    7857             :             | ROUTINE function_with_argtypes_list
    7858             :                 {
    7859           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7860             : 
    7861           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7862           0 :                     n->objtype = OBJECT_ROUTINE;
    7863           0 :                     n->objs = $2;
    7864           0 :                     $$ = n;
    7865             :                 }
    7866             :             | DATABASE name_list
    7867             :                 {
    7868         344 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7869             : 
    7870         344 :                     n->targtype = ACL_TARGET_OBJECT;
    7871         344 :                     n->objtype = OBJECT_DATABASE;
    7872         344 :                     n->objs = $2;
    7873         344 :                     $$ = n;
    7874             :                 }
    7875             :             | DOMAIN_P any_name_list
    7876             :                 {
    7877          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7878             : 
    7879          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7880          26 :                     n->objtype = OBJECT_DOMAIN;
    7881          26 :                     n->objs = $2;
    7882          26 :                     $$ = n;
    7883             :                 }
    7884             :             | LANGUAGE name_list
    7885             :                 {
    7886          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7887             : 
    7888          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7889          42 :                     n->objtype = OBJECT_LANGUAGE;
    7890          42 :                     n->objs = $2;
    7891          42 :                     $$ = n;
    7892             :                 }
    7893             :             | LARGE_P OBJECT_P NumericOnly_list
    7894             :                 {
    7895          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7896             : 
    7897          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7898          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7899          80 :                     n->objs = $3;
    7900          80 :                     $$ = n;
    7901             :                 }
    7902             :             | PARAMETER parameter_name_list
    7903             :                 {
    7904          76 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7905          76 :                     n->targtype = ACL_TARGET_OBJECT;
    7906          76 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7907          76 :                     n->objs = $2;
    7908          76 :                     $$ = n;
    7909             :                 }
    7910             :             | SCHEMA name_list
    7911             :                 {
    7912         368 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7913             : 
    7914         368 :                     n->targtype = ACL_TARGET_OBJECT;
    7915         368 :                     n->objtype = OBJECT_SCHEMA;
    7916         368 :                     n->objs = $2;
    7917         368 :                     $$ = n;
    7918             :                 }
    7919             :             | TABLESPACE name_list
    7920             :                 {
    7921           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7922             : 
    7923           6 :                     n->targtype = ACL_TARGET_OBJECT;
    7924           6 :                     n->objtype = OBJECT_TABLESPACE;
    7925           6 :                     n->objs = $2;
    7926           6 :                     $$ = n;
    7927             :                 }
    7928             :             | TYPE_P any_name_list
    7929             :                 {
    7930         112 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7931             : 
    7932         112 :                     n->targtype = ACL_TARGET_OBJECT;
    7933         112 :                     n->objtype = OBJECT_TYPE;
    7934         112 :                     n->objs = $2;
    7935         112 :                     $$ = n;
    7936             :                 }
    7937             :             | ALL TABLES IN_P SCHEMA name_list
    7938             :                 {
    7939          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7940             : 
    7941          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7942          12 :                     n->objtype = OBJECT_TABLE;
    7943          12 :                     n->objs = $5;
    7944          12 :                     $$ = n;
    7945             :                 }
    7946             :             | ALL SEQUENCES IN_P SCHEMA name_list
    7947             :                 {
    7948           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7949             : 
    7950           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7951           0 :                     n->objtype = OBJECT_SEQUENCE;
    7952           0 :                     n->objs = $5;
    7953           0 :                     $$ = n;
    7954             :                 }
    7955             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    7956             :                 {
    7957           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7958             : 
    7959           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7960           6 :                     n->objtype = OBJECT_FUNCTION;
    7961           6 :                     n->objs = $5;
    7962           6 :                     $$ = n;
    7963             :                 }
    7964             :             | ALL PROCEDURES IN_P SCHEMA name_list
    7965             :                 {
    7966           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7967             : 
    7968           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7969           6 :                     n->objtype = OBJECT_PROCEDURE;
    7970           6 :                     n->objs = $5;
    7971           6 :                     $$ = n;
    7972             :                 }
    7973             :             | ALL ROUTINES IN_P SCHEMA name_list
    7974             :                 {
    7975           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7976             : 
    7977           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7978           6 :                     n->objtype = OBJECT_ROUTINE;
    7979           6 :                     n->objs = $5;
    7980           6 :                     $$ = n;
    7981             :                 }
    7982             :         ;
    7983             : 
    7984             : 
    7985             : grantee_list:
    7986       21834 :             grantee                                 { $$ = list_make1($1); }
    7987         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    7988             :         ;
    7989             : 
    7990             : grantee:
    7991       21918 :             RoleSpec                                { $$ = $1; }
    7992          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    7993             :         ;
    7994             : 
    7995             : 
    7996             : opt_grant_grant_option:
    7997         102 :             WITH GRANT OPTION { $$ = true; }
    7998       11516 :             | /*EMPTY*/ { $$ = false; }
    7999             :         ;
    8000             : 
    8001             : /*****************************************************************************
    8002             :  *
    8003             :  * GRANT and REVOKE ROLE statements
    8004             :  *
    8005             :  *****************************************************************************/
    8006             : 
    8007             : GrantRoleStmt:
    8008             :             GRANT privilege_list TO role_list opt_granted_by
    8009             :                 {
    8010         586 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8011             : 
    8012         586 :                     n->is_grant = true;
    8013         586 :                     n->granted_roles = $2;
    8014         586 :                     n->grantee_roles = $4;
    8015         586 :                     n->opt = NIL;
    8016         586 :                     n->grantor = $5;
    8017         586 :                     $$ = (Node *) n;
    8018             :                 }
    8019             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8020             :                 {
    8021         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8022             : 
    8023         178 :                     n->is_grant = true;
    8024         178 :                     n->granted_roles = $2;
    8025         178 :                     n->grantee_roles = $4;
    8026         178 :                     n->opt = $6;
    8027         178 :                     n->grantor = $7;
    8028         178 :                     $$ = (Node *) n;
    8029             :                 }
    8030             :         ;
    8031             : 
    8032             : RevokeRoleStmt:
    8033             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8034             :                 {
    8035          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8036             : 
    8037          90 :                     n->is_grant = false;
    8038          90 :                     n->opt = NIL;
    8039          90 :                     n->granted_roles = $2;
    8040          90 :                     n->grantee_roles = $4;
    8041          90 :                     n->grantor = $5;
    8042          90 :                     n->behavior = $6;
    8043          90 :                     $$ = (Node *) n;
    8044             :                 }
    8045             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8046             :                 {
    8047          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8048             :                     DefElem *opt;
    8049             : 
    8050          66 :                     opt = makeDefElem(pstrdup($2),
    8051          66 :                                       (Node *) makeBoolean(false), @2);
    8052          66 :                     n->is_grant = false;
    8053          66 :                     n->opt = list_make1(opt);
    8054          66 :                     n->granted_roles = $5;
    8055          66 :                     n->grantee_roles = $7;
    8056          66 :                     n->grantor = $8;
    8057          66 :                     n->behavior = $9;
    8058          66 :                     $$ = (Node *) n;
    8059             :                 }
    8060             :         ;
    8061             : 
    8062             : grant_role_opt_list:
    8063         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8064         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8065             :         ;
    8066             : 
    8067             : grant_role_opt:
    8068             :         ColLabel grant_role_opt_value
    8069             :             {
    8070         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8071             :             }
    8072             :         ;
    8073             : 
    8074             : grant_role_opt_value:
    8075          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8076         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8077         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8078             :         ;
    8079             : 
    8080         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8081       22426 :             | /*EMPTY*/                                 { $$ = NULL; }
    8082             :         ;
    8083             : 
    8084             : /*****************************************************************************
    8085             :  *
    8086             :  * ALTER DEFAULT PRIVILEGES statement
    8087             :  *
    8088             :  *****************************************************************************/
    8089             : 
    8090             : AlterDefaultPrivilegesStmt:
    8091             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8092             :                 {
    8093         190 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8094             : 
    8095         190 :                     n->options = $4;
    8096         190 :                     n->action = (GrantStmt *) $5;
    8097         190 :                     $$ = (Node *) n;
    8098             :                 }
    8099             :         ;
    8100             : 
    8101             : DefACLOptionList:
    8102         128 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8103         190 :             | /* EMPTY */                           { $$ = NIL; }
    8104             :         ;
    8105             : 
    8106             : DefACLOption:
    8107             :             IN_P SCHEMA name_list
    8108             :                 {
    8109          60 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8110             :                 }
    8111             :             | FOR ROLE role_list
    8112             :                 {
    8113          68 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8114             :                 }
    8115             :             | FOR USER role_list
    8116             :                 {
    8117           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8118             :                 }
    8119             :         ;
    8120             : 
    8121             : /*
    8122             :  * This should match GRANT/REVOKE, except that individual target objects
    8123             :  * are not mentioned and we only allow a subset of object types.
    8124             :  */
    8125             : DefACLAction:
    8126             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8127             :             opt_grant_grant_option
    8128             :                 {
    8129         124 :                     GrantStmt *n = makeNode(GrantStmt);
    8130             : 
    8131         124 :                     n->is_grant = true;
    8132         124 :                     n->privileges = $2;
    8133         124 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8134         124 :                     n->objtype = $4;
    8135         124 :                     n->objects = NIL;
    8136         124 :                     n->grantees = $6;
    8137         124 :                     n->grant_option = $7;
    8138         124 :                     $$ = (Node *) n;
    8139             :                 }
    8140             :             | REVOKE privileges ON defacl_privilege_target
    8141             :             FROM grantee_list opt_drop_behavior
    8142             :                 {
    8143          66 :                     GrantStmt *n = makeNode(GrantStmt);
    8144             : 
    8145          66 :                     n->is_grant = false;
    8146          66 :                     n->grant_option = false;
    8147          66 :                     n->privileges = $2;
    8148          66 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8149          66 :                     n->objtype = $4;
    8150          66 :                     n->objects = NIL;
    8151          66 :                     n->grantees = $6;
    8152          66 :                     n->behavior = $7;
    8153          66 :                     $$ = (Node *) n;
    8154             :                 }
    8155             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8156             :             FROM grantee_list opt_drop_behavior
    8157             :                 {
    8158           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8159             : 
    8160           0 :                     n->is_grant = false;
    8161           0 :                     n->grant_option = true;
    8162           0 :                     n->privileges = $5;
    8163           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8164           0 :                     n->objtype = $7;
    8165           0 :                     n->objects = NIL;
    8166           0 :                     n->grantees = $9;
    8167           0 :                     n->behavior = $10;
    8168           0 :                     $$ = (Node *) n;
    8169             :                 }
    8170             :         ;
    8171             : 
    8172             : defacl_privilege_target:
    8173          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8174          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8175           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8176           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8177          18 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8178          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8179          30 :             | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
    8180             :         ;
    8181             : 
    8182             : 
    8183             : /*****************************************************************************
    8184             :  *
    8185             :  *      QUERY: CREATE INDEX
    8186             :  *
    8187             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8188             :  * willing to make TABLESPACE a fully reserved word.
    8189             :  *****************************************************************************/
    8190             : 
    8191             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8192             :             ON relation_expr access_method_clause '(' index_params ')'
    8193             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8194             :                 {
    8195        6872 :                     IndexStmt *n = makeNode(IndexStmt);
    8196             : 
    8197        6872 :                     n->unique = $2;
    8198        6872 :                     n->concurrent = $4;
    8199        6872 :                     n->idxname = $5;
    8200        6872 :                     n->relation = $7;
    8201        6872 :                     n->accessMethod = $8;
    8202        6872 :                     n->indexParams = $10;
    8203        6872 :                     n->indexIncludingParams = $12;
    8204        6872 :                     n->nulls_not_distinct = !$13;
    8205        6872 :                     n->options = $14;
    8206        6872 :                     n->tableSpace = $15;
    8207        6872 :                     n->whereClause = $16;
    8208        6872 :                     n->excludeOpNames = NIL;
    8209        6872 :                     n->idxcomment = NULL;
    8210        6872 :                     n->indexOid = InvalidOid;
    8211        6872 :                     n->oldNumber = InvalidRelFileNumber;
    8212        6872 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8213        6872 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8214        6872 :                     n->primary = false;
    8215        6872 :                     n->isconstraint = false;
    8216        6872 :                     n->deferrable = false;
    8217        6872 :                     n->initdeferred = false;
    8218        6872 :                     n->transformed = false;
    8219        6872 :                     n->if_not_exists = false;
    8220        6872 :                     n->reset_default_tblspc = false;
    8221        6872 :                     $$ = (Node *) n;
    8222             :                 }
    8223             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8224             :             ON relation_expr access_method_clause '(' index_params ')'
    8225             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8226             :                 {
    8227          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8228             : 
    8229          18 :                     n->unique = $2;
    8230          18 :                     n->concurrent = $4;
    8231          18 :                     n->idxname = $8;
    8232          18 :                     n->relation = $10;
    8233          18 :                     n->accessMethod = $11;
    8234          18 :                     n->indexParams = $13;
    8235          18 :                     n->indexIncludingParams = $15;
    8236          18 :                     n->nulls_not_distinct = !$16;
    8237          18 :                     n->options = $17;
    8238          18 :                     n->tableSpace = $18;
    8239          18 :                     n->whereClause = $19;
    8240          18 :                     n->excludeOpNames = NIL;
    8241          18 :                     n->idxcomment = NULL;
    8242          18 :                     n->indexOid = InvalidOid;
    8243          18 :                     n->oldNumber = InvalidRelFileNumber;
    8244          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8245          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8246          18 :                     n->primary = false;
    8247          18 :                     n->isconstraint = false;
    8248          18 :                     n->deferrable = false;
    8249          18 :                     n->initdeferred = false;
    8250          18 :                     n->transformed = false;
    8251          18 :                     n->if_not_exists = true;
    8252          18 :                     n->reset_default_tblspc = false;
    8253          18 :                     $$ = (Node *) n;
    8254             :                 }
    8255             :         ;
    8256             : 
    8257             : opt_unique:
    8258        1378 :             UNIQUE                                  { $$ = true; }
    8259        5518 :             | /*EMPTY*/                             { $$ = false; }
    8260             :         ;
    8261             : 
    8262             : access_method_clause:
    8263        3292 :             USING name                              { $$ = $2; }
    8264        3836 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8265             :         ;
    8266             : 
    8267        8320 : index_params:   index_elem                          { $$ = list_make1($1); }
    8268        2322 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8269             :         ;
    8270             : 
    8271             : 
    8272             : index_elem_options:
    8273             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8274             :         {
    8275       11250 :             $$ = makeNode(IndexElem);
    8276       11250 :             $$->name = NULL;
    8277       11250 :             $$->expr = NULL;
    8278       11250 :             $$->indexcolname = NULL;
    8279       11250 :             $$->collation = $1;
    8280       11250 :             $$->opclass = $2;
    8281       11250 :             $$->opclassopts = NIL;
    8282       11250 :             $$->ordering = $3;
    8283       11250 :             $$->nulls_ordering = $4;
    8284             :         }
    8285             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8286             :         {
    8287         142 :             $$ = makeNode(IndexElem);
    8288         142 :             $$->name = NULL;
    8289         142 :             $$->expr = NULL;
    8290         142 :             $$->indexcolname = NULL;
    8291         142 :             $$->collation = $1;
    8292         142 :             $$->opclass = $2;
    8293         142 :             $$->opclassopts = $3;
    8294         142 :             $$->ordering = $4;
    8295         142 :             $$->nulls_ordering = $5;
    8296             :         }
    8297             :     ;
    8298             : 
    8299             : /*
    8300             :  * Index attributes can be either simple column references, or arbitrary
    8301             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8302             :  * an expression that's just a function call to be written without parens.
    8303             :  */
    8304             : index_elem: ColId index_elem_options
    8305             :                 {
    8306       10268 :                     $$ = $2;
    8307       10268 :                     $$->name = $1;
    8308             :                 }
    8309             :             | func_expr_windowless index_elem_options
    8310             :                 {
    8311         612 :                     $$ = $2;
    8312         612 :                     $$->expr = $1;
    8313             :                 }
    8314             :             | '(' a_expr ')' index_elem_options
    8315             :                 {
    8316         512 :                     $$ = $4;
    8317         512 :                     $$->expr = $2;
    8318             :                 }
    8319             :         ;
    8320             : 
    8321         232 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8322        6658 :              |      /* EMPTY */                     { $$ = NIL; }
    8323             :         ;
    8324             : 
    8325         232 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8326         170 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8327             :         ;
    8328             : 
    8329         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8330       16810 :             | /*EMPTY*/                             { $$ = NIL; }
    8331             :         ;
    8332             : 
    8333             : 
    8334        1818 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8335        3518 :             | DESC                          { $$ = SORTBY_DESC; }
    8336      117262 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8337             :         ;
    8338             : 
    8339         346 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8340        1732 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8341      120740 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8342             :         ;
    8343             : 
    8344             : 
    8345             : /*****************************************************************************
    8346             :  *
    8347             :  *      QUERY:
    8348             :  *              create [or replace] function <fname>
    8349             :  *                      [(<type-1> { , <type-n>})]
    8350             :  *                      returns <type-r>
    8351             :  *                      as <filename or code in language as appropriate>
    8352             :  *                      language <lang> [with parameters]
    8353             :  *
    8354             :  *****************************************************************************/
    8355             : 
    8356             : CreateFunctionStmt:
    8357             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8358             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8359             :                 {
    8360       23426 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8361             : 
    8362       23426 :                     n->is_procedure = false;
    8363       23426 :                     n->replace = $2;
    8364       23426 :                     n->funcname = $4;
    8365       23426 :                     n->parameters = $5;
    8366       23426 :                     n->returnType = $7;
    8367       23426 :                     n->options = $8;
    8368       23426 :                     n->sql_body = $9;
    8369       23426 :                     $$ = (Node *) n;
    8370             :                 }
    8371             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8372             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8373             :                 {
    8374         202 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8375             : 
    8376         202 :                     n->is_procedure = false;
    8377         202 :                     n->replace = $2;
    8378         202 :                     n->funcname = $4;
    8379         202 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8380         202 :                     n->returnType = TableFuncTypeName($9);
    8381         202 :                     n->returnType->location = @7;
    8382         202 :                     n->options = $11;
    8383         202 :                     n->sql_body = $12;
    8384         202 :                     $$ = (Node *) n;
    8385             :                 }
    8386             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8387             :               opt_createfunc_opt_list opt_routine_body
    8388             :                 {
    8389         488 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8390             : 
    8391         488 :                     n->is_procedure = false;
    8392         488 :                     n->replace = $2;
    8393         488 :                     n->funcname = $4;
    8394         488 :                     n->parameters = $5;
    8395         488 :                     n->returnType = NULL;
    8396         488 :                     n->options = $6;
    8397         488 :                     n->sql_body = $7;
    8398         488 :                     $$ = (Node *) n;
    8399             :                 }
    8400             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8401             :               opt_createfunc_opt_list opt_routine_body
    8402             :                 {
    8403         392 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8404             : 
    8405         392 :                     n->is_procedure = true;
    8406         392 :                     n->replace = $2;
    8407         392 :                     n->funcname = $4;
    8408         392 :                     n->parameters = $5;
    8409         392 :                     n->returnType = NULL;
    8410         392 :                     n->options = $6;
    8411         392 :                     n->sql_body = $7;
    8412         392 :                     $$ = (Node *) n;
    8413             :                 }
    8414             :         ;
    8415             : 
    8416             : opt_or_replace:
    8417        9814 :             OR REPLACE                              { $$ = true; }
    8418       20394 :             | /*EMPTY*/                             { $$ = false; }
    8419             :         ;
    8420             : 
    8421       10424 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8422        5814 :             | '(' ')'                               { $$ = NIL; }
    8423             :         ;
    8424             : 
    8425             : func_args_list:
    8426       10424 :             func_arg                                { $$ = list_make1($1); }
    8427        8638 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8428             :         ;
    8429             : 
    8430             : function_with_argtypes_list:
    8431       12476 :             function_with_argtypes                  { $$ = list_make1($1); }
    8432             :             | function_with_argtypes_list ',' function_with_argtypes
    8433          84 :                                                     { $$ = lappend($1, $3); }
    8434             :         ;
    8435             : 
    8436             : function_with_argtypes:
    8437             :             func_name func_args
    8438             :                 {
    8439       16238 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8440             : 
    8441       16238 :                     n->objname = $1;
    8442       16238 :                     n->objargs = extractArgTypes($2);
    8443       16238 :                     n->objfuncargs = $2;
    8444       16238 :                     $$ = n;
    8445             :                 }
    8446             :             /*
    8447             :              * Because of reduce/reduce conflicts, we can't use func_name
    8448             :              * below, but we can write it out the long way, which actually
    8449             :              * allows more cases.
    8450             :              */
    8451             :             | type_func_name_keyword
    8452             :                 {
    8453           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8454             : 
    8455           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8456           0 :                     n->args_unspecified = true;
    8457           0 :                     $$ = n;
    8458             :                 }
    8459             :             | ColId
    8460             :                 {
    8461         346 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8462             : 
    8463         346 :                     n->objname = list_make1(makeString($1));
    8464         346 :                     n->args_unspecified = true;
    8465         346 :                     $$ = n;
    8466             :                 }
    8467             :             | ColId indirection
    8468             :                 {
    8469          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8470             : 
    8471          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8472             :                                                   yyscanner);
    8473          28 :                     n->args_unspecified = true;
    8474          28 :                     $$ = n;
    8475             :                 }
    8476             :         ;
    8477             : 
    8478             : /*
    8479             :  * func_args_with_defaults is separate because we only want to accept
    8480             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8481             :  */
    8482             : func_args_with_defaults:
    8483       19824 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8484        4684 :         | '(' ')'                                   { $$ = NIL; }
    8485             :         ;
    8486             : 
    8487             : func_args_with_defaults_list:
    8488       19824 :         func_arg_with_default                       { $$ = list_make1($1); }
    8489             :         | func_args_with_defaults_list ',' func_arg_with_default
    8490       33032 :                                                     { $$ = lappend($1, $3); }
    8491             :         ;
    8492             : 
    8493             : /*
    8494             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8495             :  * param_name first; accept both since it's likely people will try both
    8496             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8497             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8498             :  *
    8499             :  * We can catch over-specified arguments here if we want to,
    8500             :  * but for now better to silently swallow typmod, etc.
    8501             :  * - thomas 2000-03-22
    8502             :  */
    8503             : func_arg:
    8504             :             arg_class param_name func_type
    8505             :                 {
    8506       15984 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8507             : 
    8508       15984 :                     n->name = $2;
    8509       15984 :                     n->argType = $3;
    8510       15984 :                     n->mode = $1;
    8511       15984 :                     n->defexpr = NULL;
    8512       15984 :                     n->location = @1;
    8513       15984 :                     $$ = n;
    8514             :                 }
    8515             :             | param_name arg_class func_type
    8516             :                 {
    8517         412 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8518             : 
    8519         412 :                     n->name = $1;
    8520         412 :                     n->argType = $3;
    8521         412 :                     n->mode = $2;
    8522         412 :                     n->defexpr = NULL;
    8523         412 :                     n->location = @1;
    8524         412 :                     $$ = n;
    8525             :                 }
    8526             :             | param_name func_type
    8527             :                 {
    8528       15622 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8529             : 
    8530       15622 :                     n->name = $1;
    8531       15622 :                     n->argType = $2;
    8532       15622 :                     n->mode = FUNC_PARAM_DEFAULT;
    8533       15622 :                     n->defexpr = NULL;
    8534       15622 :                     n->location = @1;
    8535       15622 :                     $$ = n;
    8536             :                 }
    8537             :             | arg_class func_type
    8538             :                 {
    8539         354 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8540             : 
    8541         354 :                     n->name = NULL;
    8542         354 :                     n->argType = $2;
    8543         354 :                     n->mode = $1;
    8544         354 :                     n->defexpr = NULL;
    8545         354 :                     n->location = @1;
    8546         354 :                     $$ = n;
    8547             :                 }
    8548             :             | func_type
    8549             :                 {
    8550       40644 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8551             : 
    8552       40644 :                     n->name = NULL;
    8553       40644 :                     n->argType = $1;
    8554       40644 :                     n->mode = FUNC_PARAM_DEFAULT;
    8555       40644 :                     n->defexpr = NULL;
    8556       40644 :                     n->location = @1;
    8557       40644 :                     $$ = n;
    8558             :                 }
    8559             :         ;
    8560             : 
    8561             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8562        3852 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8563       12090 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8564         218 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8565           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8566         590 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8567             :         ;
    8568             : 
    8569             : /*
    8570             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8571             :  */
    8572             : param_name: type_function_name
    8573             :         ;
    8574             : 
    8575             : func_return:
    8576             :             func_type
    8577             :                 {
    8578             :                     /* We can catch over-specified results here if we want to,
    8579             :                      * but for now better to silently swallow typmod, etc.
    8580             :                      * - thomas 2000-03-22
    8581             :                      */
    8582       23426 :                     $$ = $1;
    8583             :                 }
    8584             :         ;
    8585             : 
    8586             : /*
    8587             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8588             :  * but that causes reduce/reduce conflicts.  type_function_name
    8589             :  * is next best choice.
    8590             :  */
    8591      117738 : func_type:  Typename                                { $$ = $1; }
    8592             :             | type_function_name attrs '%' TYPE_P
    8593             :                 {
    8594          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8595          18 :                     $$->pct_type = true;
    8596          18 :                     $$->location = @1;
    8597             :                 }
    8598             :             | SETOF type_function_name attrs '%' TYPE_P
    8599             :                 {
    8600           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8601           6 :                     $$->pct_type = true;
    8602           6 :                     $$->setof = true;
    8603           6 :                     $$->location = @2;
    8604             :                 }
    8605             :         ;
    8606             : 
    8607             : func_arg_with_default:
    8608             :         func_arg
    8609             :                 {
    8610       46676 :                     $$ = $1;
    8611             :                 }
    8612             :         | func_arg DEFAULT a_expr
    8613             :                 {
    8614        5984 :                     $$ = $1;
    8615        5984 :                     $$->defexpr = $3;
    8616             :                 }
    8617             :         | func_arg '=' a_expr
    8618             :                 {
    8619         196 :                     $$ = $1;
    8620         196 :                     $$->defexpr = $3;
    8621             :                 }
    8622             :         ;
    8623             : 
    8624             : /* Aggregate args can be most things that function args can be */
    8625             : aggr_arg:   func_arg
    8626             :                 {
    8627        1098 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8628          76 :                           $1->mode == FUNC_PARAM_IN ||
    8629          76 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8630           0 :                         ereport(ERROR,
    8631             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8632             :                                  errmsg("aggregates cannot have output arguments"),
    8633             :                                  parser_errposition(@1)));
    8634        1098 :                     $$ = $1;
    8635             :                 }
    8636             :         ;
    8637             : 
    8638             : /*
    8639             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8640             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8641             :  *
    8642             :  * (*)                                  - normal agg with no args
    8643             :  * (aggr_arg,...)                       - normal agg with args
    8644             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8645             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8646             :  *
    8647             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8648             :  *
    8649             :  * An additional restriction is that if the direct-args list ends in a
    8650             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8651             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8652             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8653             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8654             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8655             :  * in cases such as DROP AGGREGATE.
    8656             :  *
    8657             :  * The return value of this production is a two-element list, in which the
    8658             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8659             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8660             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8661             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8662             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8663             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8664             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8665             :  * sublist.
    8666             :  */
    8667             : aggr_args:  '(' '*' ')'
    8668             :                 {
    8669         170 :                     $$ = list_make2(NIL, makeInteger(-1));
    8670             :                 }
    8671             :             | '(' aggr_args_list ')'
    8672             :                 {
    8673         882 :                     $$ = list_make2($2, makeInteger(-1));
    8674             :                 }
    8675             :             | '(' ORDER BY aggr_args_list ')'
    8676             :                 {
    8677           6 :                     $$ = list_make2($4, makeInteger(0));
    8678             :                 }
    8679             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8680             :                 {
    8681             :                     /* this is the only case requiring consistency checking */
    8682          40 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8683             :                 }
    8684             :         ;
    8685             : 
    8686             : aggr_args_list:
    8687         968 :             aggr_arg                                { $$ = list_make1($1); }
    8688         130 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8689             :         ;
    8690             : 
    8691             : aggregate_with_argtypes:
    8692             :             func_name aggr_args
    8693             :                 {
    8694         460 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8695             : 
    8696         460 :                     n->objname = $1;
    8697         460 :                     n->objargs = extractAggrArgTypes($2);
    8698         460 :                     n->objfuncargs = (List *) linitial($2);
    8699         460 :                     $$ = n;
    8700             :                 }
    8701             :         ;
    8702             : 
    8703             : aggregate_with_argtypes_list:
    8704         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8705             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8706           0 :                                                     { $$ = lappend($1, $3); }
    8707             :         ;
    8708             : 
    8709             : opt_createfunc_opt_list:
    8710             :             createfunc_opt_list
    8711          54 :             | /*EMPTY*/ { $$ = NIL; }
    8712             :     ;
    8713             : 
    8714             : createfunc_opt_list:
    8715             :             /* Must be at least one to prevent conflict */
    8716       24454 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8717       63868 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8718             :     ;
    8719             : 
    8720             : /*
    8721             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8722             :  */
    8723             : common_func_opt_item:
    8724             :             CALLED ON NULL_P INPUT_P
    8725             :                 {
    8726         368 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8727             :                 }
    8728             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8729             :                 {
    8730         864 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8731             :                 }
    8732             :             | STRICT_P
    8733             :                 {
    8734       12668 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8735             :                 }
    8736             :             | IMMUTABLE
    8737             :                 {
    8738        9166 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8739             :                 }
    8740             :             | STABLE
    8741             :                 {
    8742        2486 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8743             :                 }
    8744             :             | VOLATILE
    8745             :                 {
    8746        1644 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8747             :                 }
    8748             :             | EXTERNAL SECURITY DEFINER
    8749             :                 {
    8750           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8751             :                 }
    8752             :             | EXTERNAL SECURITY INVOKER
    8753             :                 {
    8754           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8755             :                 }
    8756             :             | SECURITY DEFINER
    8757             :                 {
    8758          58 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8759             :                 }
    8760             :             | SECURITY INVOKER
    8761             :                 {
    8762          18 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8763             :                 }
    8764             :             | LEAKPROOF
    8765             :                 {
    8766          50 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8767             :                 }
    8768             :             | NOT LEAKPROOF
    8769             :                 {
    8770          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8771             :                 }
    8772             :             | COST NumericOnly
    8773             :                 {
    8774        4270 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8775             :                 }
    8776             :             | ROWS NumericOnly
    8777             :                 {
    8778         588 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8779             :                 }
    8780             :             | SUPPORT any_name
    8781             :                 {
    8782         116 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8783             :                 }
    8784             :             | FunctionSetResetClause
    8785             :                 {
    8786             :                     /* we abuse the normal content of a DefElem here */
    8787         160 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8788             :                 }
    8789             :             | PARALLEL ColId
    8790             :                 {
    8791       13016 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8792             :                 }
    8793             :         ;
    8794             : 
    8795             : createfunc_opt_item:
    8796             :             AS func_as
    8797             :                 {
    8798       18940 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8799             :                 }
    8800             :             | LANGUAGE NonReservedWord_or_Sconst
    8801             :                 {
    8802       24434 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8803             :                 }
    8804             :             | TRANSFORM transform_type_list
    8805             :                 {
    8806         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8807             :                 }
    8808             :             | WINDOW
    8809             :                 {
    8810          22 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8811             :                 }
    8812             :             | common_func_opt_item
    8813             :                 {
    8814       44808 :                     $$ = $1;
    8815             :                 }
    8816             :         ;
    8817             : 
    8818       15820 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8819             :             | Sconst ',' Sconst
    8820             :                 {
    8821        3120 :                     $$ = list_make2(makeString($1), makeString($3));
    8822             :                 }
    8823             :         ;
    8824             : 
    8825             : ReturnStmt: RETURN a_expr
    8826             :                 {
    8827        4784 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8828             : 
    8829        4784 :                     r->returnval = (Node *) $2;
    8830        4784 :                     $$ = (Node *) r;
    8831             :                 }
    8832             :         ;
    8833             : 
    8834             : opt_routine_body:
    8835             :             ReturnStmt
    8836             :                 {
    8837        4778 :                     $$ = $1;
    8838             :                 }
    8839             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8840             :                 {
    8841             :                     /*
    8842             :                      * A compound statement is stored as a single-item list
    8843             :                      * containing the list of statements as its member.  That
    8844             :                      * way, the parse analysis code can tell apart an empty
    8845             :                      * body from no body at all.
    8846             :                      */
    8847         796 :                     $$ = (Node *) list_make1($3);
    8848             :                 }
    8849             :             | /*EMPTY*/
    8850             :                 {
    8851       18934 :                     $$ = NULL;
    8852             :                 }
    8853             :         ;
    8854             : 
    8855             : routine_body_stmt_list:
    8856             :             routine_body_stmt_list routine_body_stmt ';'
    8857             :                 {
    8858             :                     /* As in stmtmulti, discard empty statements */
    8859         810 :                     if ($2 != NULL)
    8860         792 :                         $$ = lappend($1, $2);
    8861             :                     else
    8862          18 :                         $$ = $1;
    8863             :                 }
    8864             :             | /*EMPTY*/
    8865             :                 {
    8866         796 :                     $$ = NIL;
    8867             :                 }
    8868             :         ;
    8869             : 
    8870             : routine_body_stmt:
    8871             :             stmt
    8872             :             | ReturnStmt
    8873             :         ;
    8874             : 
    8875             : transform_type_list:
    8876         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8877           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8878             :         ;
    8879             : 
    8880             : opt_definition:
    8881         606 :             WITH definition                         { $$ = $2; }
    8882       10282 :             | /*EMPTY*/                             { $$ = NIL; }
    8883             :         ;
    8884             : 
    8885             : table_func_column:  param_name func_type
    8886             :                 {
    8887         462 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8888             : 
    8889         462 :                     n->name = $1;
    8890         462 :                     n->argType = $2;
    8891         462 :                     n->mode = FUNC_PARAM_TABLE;
    8892         462 :                     n->defexpr = NULL;
    8893         462 :                     n->location = @1;
    8894         462 :                     $$ = n;
    8895             :                 }
    8896             :         ;
    8897             : 
    8898             : table_func_column_list:
    8899             :             table_func_column
    8900             :                 {
    8901         202 :                     $$ = list_make1($1);
    8902             :                 }
    8903             :             | table_func_column_list ',' table_func_column
    8904             :                 {
    8905         260 :                     $$ = lappend($1, $3);
    8906             :                 }
    8907             :         ;
    8908             : 
    8909             : /*****************************************************************************
    8910             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8911             :  *
    8912             :  * RENAME and OWNER subcommands are already provided by the generic
    8913             :  * ALTER infrastructure, here we just specify alterations that can
    8914             :  * only be applied to functions.
    8915             :  *
    8916             :  *****************************************************************************/
    8917             : AlterFunctionStmt:
    8918             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8919             :                 {
    8920         654 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8921             : 
    8922         654 :                     n->objtype = OBJECT_FUNCTION;
    8923         654 :                     n->func = $3;
    8924         654 :                     n->actions = $4;
    8925         654 :                     $$ = (Node *) n;
    8926             :                 }
    8927             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8928             :                 {
    8929          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8930             : 
    8931          18 :                     n->objtype = OBJECT_PROCEDURE;
    8932          18 :                     n->func = $3;
    8933          18 :                     n->actions = $4;
    8934          18 :                     $$ = (Node *) n;
    8935             :                 }
    8936             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8937             :                 {
    8938           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8939             : 
    8940           0 :                     n->objtype = OBJECT_ROUTINE;
    8941           0 :                     n->func = $3;
    8942           0 :                     n->actions = $4;
    8943           0 :                     $$ = (Node *) n;
    8944             :                 }
    8945             :         ;
    8946             : 
    8947             : alterfunc_opt_list:
    8948             :             /* At least one option must be specified */
    8949         672 :             common_func_opt_item                    { $$ = list_make1($1); }
    8950           4 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    8951             :         ;
    8952             : 
    8953             : /* Ignored, merely for SQL compliance */
    8954             : opt_restrict:
    8955             :             RESTRICT
    8956             :             | /* EMPTY */
    8957             :         ;
    8958             : 
    8959             : 
    8960             : /*****************************************************************************
    8961             :  *
    8962             :  *      QUERY:
    8963             :  *
    8964             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8965             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8966             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8967             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    8968             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    8969             :  *
    8970             :  *****************************************************************************/
    8971             : 
    8972             : RemoveFuncStmt:
    8973             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    8974             :                 {
    8975        3262 :                     DropStmt *n = makeNode(DropStmt);
    8976             : 
    8977        3262 :                     n->removeType = OBJECT_FUNCTION;
    8978        3262 :                     n->objects = $3;
    8979        3262 :                     n->behavior = $4;
    8980        3262 :                     n->missing_ok = false;
    8981        3262 :                     n->concurrent = false;
    8982        3262 :                     $$ = (Node *) n;
    8983             :                 }
    8984             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8985             :                 {
    8986         260 :                     DropStmt *n = makeNode(DropStmt);
    8987             : 
    8988         260 :                     n->removeType = OBJECT_FUNCTION;
    8989         260 :                     n->objects = $5;
    8990         260 :                     n->behavior = $6;
    8991         260 :                     n->missing_ok = true;
    8992         260 :                     n->concurrent = false;
    8993         260 :                     $$ = (Node *) n;
    8994             :                 }
    8995             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    8996             :                 {
    8997         138 :                     DropStmt *n = makeNode(DropStmt);
    8998             : 
    8999         138 :                     n->removeType = OBJECT_PROCEDURE;
    9000         138 :                     n->objects = $3;
    9001         138 :                     n->behavior = $4;
    9002         138 :                     n->missing_ok = false;
    9003         138 :                     n->concurrent = false;
    9004         138 :                     $$ = (Node *) n;
    9005             :                 }
    9006             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9007             :                 {
    9008           6 :                     DropStmt *n = makeNode(DropStmt);
    9009             : 
    9010           6 :                     n->removeType = OBJECT_PROCEDURE;
    9011           6 :                     n->objects = $5;
    9012           6 :                     n->behavior = $6;
    9013           6 :                     n->missing_ok = true;
    9014           6 :                     n->concurrent = false;
    9015           6 :                     $$ = (Node *) n;
    9016             :                 }
    9017             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9018             :                 {
    9019          12 :                     DropStmt *n = makeNode(DropStmt);
    9020             : 
    9021          12 :                     n->removeType = OBJECT_ROUTINE;
    9022          12 :                     n->objects = $3;
    9023          12 :                     n->behavior = $4;
    9024          12 :                     n->missing_ok = false;
    9025          12 :                     n->concurrent = false;
    9026          12 :                     $$ = (Node *) n;
    9027             :                 }
    9028             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9029             :                 {
    9030           6 :                     DropStmt *n = makeNode(DropStmt);
    9031             : 
    9032           6 :                     n->removeType = OBJECT_ROUTINE;
    9033           6 :                     n->objects = $5;
    9034           6 :                     n->behavior = $6;
    9035           6 :                     n->missing_ok = true;
    9036           6 :                     n->concurrent = false;
    9037           6 :                     $$ = (Node *) n;
    9038             :                 }
    9039             :         ;
    9040             : 
    9041             : RemoveAggrStmt:
    9042             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9043             :                 {
    9044          74 :                     DropStmt *n = makeNode(DropStmt);
    9045             : 
    9046          74 :                     n->removeType = OBJECT_AGGREGATE;
    9047          74 :                     n->objects = $3;
    9048          74 :                     n->behavior = $4;
    9049          74 :                     n->missing_ok = false;
    9050          74 :                     n->concurrent = false;
    9051          74 :                     $$ = (Node *) n;
    9052             :                 }
    9053             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9054             :                 {
    9055          30 :                     DropStmt *n = makeNode(DropStmt);
    9056             : 
    9057          30 :                     n->removeType = OBJECT_AGGREGATE;
    9058          30 :                     n->objects = $5;
    9059          30 :                     n->behavior = $6;
    9060          30 :                     n->missing_ok = true;
    9061          30 :                     n->concurrent = false;
    9062          30 :                     $$ = (Node *) n;
    9063             :                 }
    9064             :         ;
    9065             : 
    9066             : RemoveOperStmt:
    9067             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9068             :                 {
    9069         194 :                     DropStmt *n = makeNode(DropStmt);
    9070             : 
    9071         194 :                     n->removeType = OBJECT_OPERATOR;
    9072         194 :                     n->objects = $3;
    9073         194 :                     n->behavior = $4;
    9074         194 :                     n->missing_ok = false;
    9075         194 :                     n->concurrent = false;
    9076         194 :                     $$ = (Node *) n;
    9077             :                 }
    9078             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9079             :                 {
    9080          30 :                     DropStmt *n = makeNode(DropStmt);
    9081             : 
    9082          30 :                     n->removeType = OBJECT_OPERATOR;
    9083          30 :                     n->objects = $5;
    9084          30 :                     n->behavior = $6;
    9085          30 :                     n->missing_ok = true;
    9086          30 :                     n->concurrent = false;
    9087          30 :                     $$ = (Node *) n;
    9088             :                 }
    9089             :         ;
    9090             : 
    9091             : oper_argtypes:
    9092             :             '(' Typename ')'
    9093             :                 {
    9094          12 :                    ereport(ERROR,
    9095             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9096             :                             errmsg("missing argument"),
    9097             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9098             :                             parser_errposition(@3)));
    9099             :                 }
    9100             :             | '(' Typename ',' Typename ')'
    9101        1968 :                     { $$ = list_make2($2, $4); }
    9102             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9103          40 :                     { $$ = list_make2(NULL, $4); }
    9104             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9105          12 :                     { $$ = list_make2($2, NULL); }
    9106             :         ;
    9107             : 
    9108             : any_operator:
    9109             :             all_Op
    9110       20860 :                     { $$ = list_make1(makeString($1)); }
    9111             :             | ColId '.' any_operator
    9112       15940 :                     { $$ = lcons(makeString($1), $3); }
    9113             :         ;
    9114             : 
    9115             : operator_with_argtypes_list:
    9116         224 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9117             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9118           0 :                                                     { $$ = lappend($1, $3); }
    9119             :         ;
    9120             : 
    9121             : operator_with_argtypes:
    9122             :             any_operator oper_argtypes
    9123             :                 {
    9124        2020 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9125             : 
    9126        2020 :                     n->objname = $1;
    9127        2020 :                     n->objargs = $2;
    9128        2020 :                     $$ = n;
    9129             :                 }
    9130             :         ;
    9131             : 
    9132             : /*****************************************************************************
    9133             :  *
    9134             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9135             :  *
    9136             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9137             :  * in the clause order.
    9138             :  *
    9139             :  *****************************************************************************/
    9140             : 
    9141             : DoStmt: DO dostmt_opt_list
    9142             :                 {
    9143        1140 :                     DoStmt *n = makeNode(DoStmt);
    9144             : 
    9145        1140 :                     n->args = $2;
    9146        1140 :                     $$ = (Node *) n;
    9147             :                 }
    9148             :         ;
    9149             : 
    9150             : dostmt_opt_list:
    9151        1140 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9152         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9153             :         ;
    9154             : 
    9155             : dostmt_opt_item:
    9156             :             Sconst
    9157             :                 {
    9158        1140 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9159             :                 }
    9160             :             | LANGUAGE NonReservedWord_or_Sconst
    9161             :                 {
    9162         198 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9163             :                 }
    9164             :         ;
    9165             : 
    9166             : /*****************************************************************************
    9167             :  *
    9168             :  *      CREATE CAST / DROP CAST
    9169             :  *
    9170             :  *****************************************************************************/
    9171             : 
    9172             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9173             :                     WITH FUNCTION function_with_argtypes cast_context
    9174             :                 {
    9175         110 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9176             : 
    9177         110 :                     n->sourcetype = $4;
    9178         110 :                     n->targettype = $6;
    9179         110 :                     n->func = $10;
    9180         110 :                     n->context = (CoercionContext) $11;
    9181         110 :                     n->inout = false;
    9182         110 :                     $$ = (Node *) n;
    9183             :                 }
    9184             :             | CREATE CAST '(' Typename AS Typename ')'
    9185             :                     WITHOUT FUNCTION cast_context
    9186             :                 {
    9187         172 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9188             : 
    9189         172 :                     n->sourcetype = $4;
    9190         172 :                     n->targettype = $6;
    9191         172 :                     n->func = NULL;
    9192         172 :                     n->context = (CoercionContext) $10;
    9193         172 :                     n->inout = false;
    9194         172 :                     $$ = (Node *) n;
    9195             :                 }
    9196             :             | CREATE CAST '(' Typename AS Typename ')'
    9197             :                     WITH INOUT cast_context
    9198             :                 {
    9199           8 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9200             : 
    9201           8 :                     n->sourcetype = $4;
    9202           8 :                     n->targettype = $6;
    9203           8 :                     n->func = NULL;
    9204           8 :                     n->context = (CoercionContext) $10;
    9205           8 :                     n->inout = true;
    9206           8 :                     $$ = (Node *) n;
    9207             :                 }
    9208             :         ;
    9209             : 
    9210          40 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9211          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9212         192 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9213             :         ;
    9214             : 
    9215             : 
    9216             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9217             :                 {
    9218          60 :                     DropStmt *n = makeNode(DropStmt);
    9219             : 
    9220          60 :                     n->removeType = OBJECT_CAST;
    9221          60 :                     n->objects = list_make1(list_make2($5, $7));
    9222          60 :                     n->behavior = $9;
    9223          60 :                     n->missing_ok = $3;
    9224          60 :                     n->concurrent = false;
    9225          60 :                     $$ = (Node *) n;
    9226             :                 }
    9227             :         ;
    9228             : 
    9229          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9230          38 :         | /*EMPTY*/                             { $$ = false; }
    9231             :         ;
    9232             : 
    9233             : 
    9234             : /*****************************************************************************
    9235             :  *
    9236             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9237             :  *
    9238             :  *****************************************************************************/
    9239             : 
    9240             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9241             :                 {
    9242          52 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9243             : 
    9244          52 :                     n->replace = $2;
    9245          52 :                     n->type_name = $5;
    9246          52 :                     n->lang = $7;
    9247          52 :                     n->fromsql = linitial($9);
    9248          52 :                     n->tosql = lsecond($9);
    9249          52 :                     $$ = (Node *) n;
    9250             :                 }
    9251             :         ;
    9252             : 
    9253             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9254             :                 {
    9255          46 :                     $$ = list_make2($5, $11);
    9256             :                 }
    9257             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9258             :                 {
    9259           0 :                     $$ = list_make2($11, $5);
    9260             :                 }
    9261             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9262             :                 {
    9263           4 :                     $$ = list_make2($5, NULL);
    9264             :                 }
    9265             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9266             :                 {
    9267           2 :                     $$ = list_make2(NULL, $5);
    9268             :                 }
    9269             :         ;
    9270             : 
    9271             : 
    9272             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9273             :                 {
    9274          14 :                     DropStmt *n = makeNode(DropStmt);
    9275             : 
    9276          14 :                     n->removeType = OBJECT_TRANSFORM;
    9277          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9278          14 :                     n->behavior = $8;
    9279          14 :                     n->missing_ok = $3;
    9280          14 :                     $$ = (Node *) n;
    9281             :                 }
    9282             :         ;
    9283             : 
    9284             : 
    9285             : /*****************************************************************************
    9286             :  *
    9287             :  *      QUERY:
    9288             :  *
    9289             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9290             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9291             :  *****************************************************************************/
    9292             : 
    9293             : ReindexStmt:
    9294             :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9295             :                 {
    9296         926 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9297             : 
    9298         926 :                     n->kind = $3;
    9299         926 :                     n->relation = $5;
    9300         926 :                     n->name = NULL;
    9301         926 :                     n->params = $2;
    9302         926 :                     if ($4)
    9303         522 :                         n->params = lappend(n->params,
    9304         522 :                                             makeDefElem("concurrently", NULL, @4));
    9305         926 :                     $$ = (Node *) n;
    9306             :                 }
    9307             :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9308             :                 {
    9309         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9310             : 
    9311         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9312         114 :                     n->relation = NULL;
    9313         114 :                     n->name = $5;
    9314         114 :                     n->params = $2;
    9315         114 :                     if ($4)
    9316          40 :                         n->params = lappend(n->params,
    9317          40 :                                             makeDefElem("concurrently", NULL, @4));
    9318         114 :                     $$ = (Node *) n;
    9319             :                 }
    9320             :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9321             :                 {
    9322          68 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9323             : 
    9324          68 :                     n->kind = $3;
    9325          68 :                     n->relation = NULL;
    9326          68 :                     n->name = $5;
    9327          68 :                     n->params = $2;
    9328          68 :                     if ($4)
    9329          10 :                         n->params = lappend(n->params,
    9330          10 :                                             makeDefElem("concurrently", NULL, @4));
    9331          68 :                     $$ = (Node *) n;
    9332             :                 }
    9333             :         ;
    9334             : reindex_target_relation:
    9335         398 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9336         528 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9337             :         ;
    9338             : reindex_target_all:
    9339          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9340          34 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9341             :         ;
    9342             : opt_reindex_option_list:
    9343         156 :             '(' utility_option_list ')'             { $$ = $2; }
    9344         952 :             | /* EMPTY */                           { $$ = NULL; }
    9345             :         ;
    9346             : 
    9347             : /*****************************************************************************
    9348             :  *
    9349             :  * ALTER TABLESPACE
    9350             :  *
    9351             :  *****************************************************************************/
    9352             : 
    9353             : AlterTblSpcStmt:
    9354             :             ALTER TABLESPACE name SET reloptions
    9355             :                 {
    9356             :                     AlterTableSpaceOptionsStmt *n =
    9357          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9358             : 
    9359          12 :                     n->tablespacename = $3;
    9360          12 :                     n->options = $5;
    9361          12 :                     n->isReset = false;
    9362          12 :                     $$ = (Node *) n;
    9363             :                 }
    9364             :             | ALTER TABLESPACE name RESET reloptions
    9365             :                 {
    9366             :                     AlterTableSpaceOptionsStmt *n =
    9367          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9368             : 
    9369          12 :                     n->tablespacename = $3;
    9370          12 :                     n->options = $5;
    9371          12 :                     n->isReset = true;
    9372          12 :                     $$ = (Node *) n;
    9373             :                 }
    9374             :         ;
    9375             : 
    9376             : /*****************************************************************************
    9377             :  *
    9378             :  * ALTER THING name RENAME TO newname
    9379             :  *
    9380             :  *****************************************************************************/
    9381             : 
    9382             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9383             :                 {
    9384          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9385             : 
    9386          42 :                     n->renameType = OBJECT_AGGREGATE;
    9387          42 :                     n->object = (Node *) $3;
    9388          42 :                     n->newname = $6;
    9389          42 :                     n->missing_ok = false;
    9390          42 :                     $$ = (Node *) n;
    9391             :                 }
    9392             :             | ALTER COLLATION any_name RENAME TO name
    9393             :                 {
    9394          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9395             : 
    9396          18 :                     n->renameType = OBJECT_COLLATION;
    9397          18 :                     n->object = (Node *) $3;
    9398          18 :                     n->newname = $6;
    9399          18 :                     n->missing_ok = false;
    9400          18 :                     $$ = (Node *) n;
    9401             :                 }
    9402             :             | ALTER CONVERSION_P any_name RENAME TO name
    9403             :                 {
    9404          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9405             : 
    9406          24 :                     n->renameType = OBJECT_CONVERSION;
    9407          24 :                     n->object = (Node *) $3;
    9408          24 :                     n->newname = $6;
    9409          24 :                     n->missing_ok = false;
    9410          24 :                     $$ = (Node *) n;
    9411             :                 }
    9412             :             | ALTER DATABASE name RENAME TO name
    9413             :                 {
    9414           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9415             : 
    9416           6 :                     n->renameType = OBJECT_DATABASE;
    9417           6 :                     n->subname = $3;
    9418           6 :                     n->newname = $6;
    9419           6 :                     n->missing_ok = false;
    9420           6 :                     $$ = (Node *) n;
    9421             :                 }
    9422             :             | ALTER DOMAIN_P any_name RENAME TO name
    9423             :                 {
    9424           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9425             : 
    9426           6 :                     n->renameType = OBJECT_DOMAIN;
    9427           6 :                     n->object = (Node *) $3;
    9428           6 :                     n->newname = $6;
    9429           6 :                     n->missing_ok = false;
    9430           6 :                     $$ = (Node *) n;
    9431             :                 }
    9432             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9433             :                 {
    9434           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9435             : 
    9436           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9437           6 :                     n->object = (Node *) $3;
    9438           6 :                     n->subname = $6;
    9439           6 :                     n->newname = $8;
    9440           6 :                     $$ = (Node *) n;
    9441             :                 }
    9442             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9443             :                 {
    9444          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9445             : 
    9446          24 :                     n->renameType = OBJECT_FDW;
    9447          24 :                     n->object = (Node *) makeString($5);
    9448          24 :                     n->newname = $8;
    9449          24 :                     n->missing_ok = false;
    9450          24 :                     $$ = (Node *) n;
    9451             :                 }
    9452             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9453             :                 {
    9454          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9455             : 
    9456          24 :                     n->renameType = OBJECT_FUNCTION;
    9457          24 :                     n->object = (Node *) $3;
    9458          24 :                     n->newname = $6;
    9459          24 :                     n->missing_ok = false;
    9460          24 :                     $$ = (Node *) n;
    9461             :                 }
    9462             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9463             :                 {
    9464           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9465             : 
    9466           0 :                     n->renameType = OBJECT_ROLE;
    9467           0 :                     n->subname = $3;
    9468           0 :                     n->newname = $6;
    9469           0 :                     n->missing_ok = false;
    9470           0 :                     $$ = (Node *) n;
    9471             :                 }
    9472             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9473             :                 {
    9474          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9475             : 
    9476          18 :                     n->renameType = OBJECT_LANGUAGE;
    9477          18 :                     n->object = (Node *) makeString($4);
    9478          18 :                     n->newname = $7;
    9479          18 :                     n->missing_ok = false;
    9480          18 :                     $$ = (Node *) n;
    9481             :                 }
    9482             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9483             :                 {
    9484          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9485             : 
    9486          24 :                     n->renameType = OBJECT_OPCLASS;
    9487          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9488          24 :                     n->newname = $9;
    9489          24 :                     n->missing_ok = false;
    9490          24 :                     $$ = (Node *) n;
    9491             :                 }
    9492             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9493             :                 {
    9494          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9495             : 
    9496          24 :                     n->renameType = OBJECT_OPFAMILY;
    9497          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9498          24 :                     n->newname = $9;
    9499          24 :                     n->missing_ok = false;
    9500          24 :                     $$ = (Node *) n;
    9501             :                 }
    9502             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9503             :                 {
    9504          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9505             : 
    9506          18 :                     n->renameType = OBJECT_POLICY;
    9507          18 :                     n->relation = $5;
    9508          18 :                     n->subname = $3;
    9509          18 :                     n->newname = $8;
    9510          18 :                     n->missing_ok = false;
    9511          18 :                     $$ = (Node *) n;
    9512             :                 }
    9513             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9514             :                 {
    9515           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9516             : 
    9517           0 :                     n->renameType = OBJECT_POLICY;
    9518           0 :                     n->relation = $7;
    9519           0 :                     n->subname = $5;
    9520           0 :                     n->newname = $10;
    9521           0 :                     n->missing_ok = true;
    9522           0 :                     $$ = (Node *) n;
    9523             :                 }
    9524             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9525             :                 {
    9526           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9527             : 
    9528           0 :                     n->renameType = OBJECT_PROCEDURE;
    9529           0 :                     n->object = (Node *) $3;
    9530           0 :                     n->newname = $6;
    9531           0 :                     n->missing_ok = false;
    9532           0 :                     $$ = (Node *) n;
    9533             :                 }
    9534             :             | ALTER PUBLICATION name RENAME TO name
    9535             :                 {
    9536          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9537             : 
    9538          42 :                     n->renameType = OBJECT_PUBLICATION;
    9539          42 :                     n->object = (Node *) makeString($3);
    9540          42 :                     n->newname = $6;
    9541          42 :                     n->missing_ok = false;
    9542          42 :                     $$ = (Node *) n;
    9543             :                 }
    9544             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9545             :                 {
    9546          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9547             : 
    9548          24 :                     n->renameType = OBJECT_ROUTINE;
    9549          24 :                     n->object = (Node *) $3;
    9550          24 :                     n->newname = $6;
    9551          24 :                     n->missing_ok = false;
    9552          24 :                     $$ = (Node *) n;
    9553             :                 }
    9554             :             | ALTER SCHEMA name RENAME TO name
    9555             :                 {
    9556          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9557             : 
    9558          20 :                     n->renameType = OBJECT_SCHEMA;
    9559          20 :                     n->subname = $3;
    9560          20 :                     n->newname = $6;
    9561          20 :                     n->missing_ok = false;
    9562          20 :                     $$ = (Node *) n;
    9563             :                 }
    9564             :             | ALTER SERVER name RENAME TO name
    9565             :                 {
    9566          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9567             : 
    9568          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9569          24 :                     n->object = (Node *) makeString($3);
    9570          24 :                     n->newname = $6;
    9571          24 :                     n->missing_ok = false;
    9572          24 :                     $$ = (Node *) n;
    9573             :                 }
    9574             :             | ALTER SUBSCRIPTION name RENAME TO name
    9575             :                 {
    9576          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9577             : 
    9578          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9579          38 :                     n->object = (Node *) makeString($3);
    9580          38 :                     n->newname = $6;
    9581          38 :                     n->missing_ok = false;
    9582          38 :                     $$ = (Node *) n;
    9583             :                 }
    9584             :             | ALTER TABLE relation_expr RENAME TO name
    9585             :                 {
    9586         286 :                     RenameStmt *n = makeNode(RenameStmt);
    9587             : 
    9588         286 :                     n->renameType = OBJECT_TABLE;
    9589         286 :                     n->relation = $3;
    9590         286 :                     n->subname = NULL;
    9591         286 :                     n->newname = $6;
    9592         286 :                     n->missing_ok = false;
    9593         286 :                     $$ = (Node *) n;
    9594             :                 }
    9595             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9596             :                 {
    9597           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9598             : 
    9599           0 :                     n->renameType = OBJECT_TABLE;
    9600           0 :                     n->relation = $5;
    9601           0 :                     n->subname = NULL;
    9602           0 :                     n->newname = $8;
    9603           0 :                     n->missing_ok = true;
    9604           0 :                     $$ = (Node *) n;
    9605             :                 }
    9606             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9607             :                 {
    9608           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9609             : 
    9610           2 :                     n->renameType = OBJECT_SEQUENCE;
    9611           2 :                     n->relation = $3;
    9612           2 :                     n->subname = NULL;
    9613           2 :                     n->newname = $6;
    9614           2 :                     n->missing_ok = false;
    9615           2 :                     $$ = (Node *) n;
    9616             :                 }
    9617             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9618             :                 {
    9619           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9620             : 
    9621           0 :                     n->renameType = OBJECT_SEQUENCE;
    9622           0 :                     n->relation = $5;
    9623           0 :                     n->subname = NULL;
    9624           0 :                     n->newname = $8;
    9625           0 :                     n->missing_ok = true;
    9626           0 :                     $$ = (Node *) n;
    9627             :                 }
    9628             :             | ALTER VIEW qualified_name RENAME TO name
    9629             :                 {
    9630           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9631             : 
    9632           6 :                     n->renameType = OBJECT_VIEW;
    9633           6 :                     n->relation = $3;
    9634           6 :                     n->subname = NULL;
    9635           6 :                     n->newname = $6;
    9636           6 :                     n->missing_ok = false;
    9637           6 :                     $$ = (Node *) n;
    9638             :                 }
    9639             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9640             :                 {
    9641           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9642             : 
    9643           0 :                     n->renameType = OBJECT_VIEW;
    9644           0 :                     n->relation = $5;
    9645           0 :                     n->subname = NULL;
    9646           0 :                     n->newname = $8;
    9647           0 :                     n->missing_ok = true;
    9648           0 :                     $$ = (Node *) n;
    9649             :                 }
    9650             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9651             :                 {
    9652           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9653             : 
    9654           0 :                     n->renameType = OBJECT_MATVIEW;
    9655           0 :                     n->relation = $4;
    9656           0 :                     n->subname = NULL;
    9657           0 :                     n->newname = $7;
    9658           0 :                     n->missing_ok = false;
    9659           0 :                     $$ = (Node *) n;
    9660             :                 }
    9661             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9662             :                 {
    9663           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9664             : 
    9665           0 :                     n->renameType = OBJECT_MATVIEW;
    9666           0 :                     n->relation = $6;
    9667           0 :                     n->subname = NULL;
    9668           0 :                     n->newname = $9;
    9669           0 :                     n->missing_ok = true;
    9670           0 :                     $$ = (Node *) n;
    9671             :                 }
    9672             :             | ALTER INDEX qualified_name RENAME TO name
    9673             :                 {
    9674         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9675             : 
    9676         192 :                     n->renameType = OBJECT_INDEX;
    9677         192 :                     n->relation = $3;
    9678         192 :                     n->subname = NULL;
    9679         192 :                     n->newname = $6;
    9680         192 :                     n->missing_ok = false;
    9681         192 :                     $$ = (Node *) n;
    9682             :                 }
    9683             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9684             :                 {
    9685          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9686             : 
    9687          12 :                     n->renameType = OBJECT_INDEX;
    9688          12 :                     n->relation = $5;
    9689          12 :                     n->subname = NULL;
    9690          12 :                     n->newname = $8;
    9691          12 :                     n->missing_ok = true;
    9692          12 :                     $$ = (Node *) n;
    9693             :                 }
    9694             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9695             :                 {
    9696           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9697             : 
    9698           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9699           6 :                     n->relation = $4;
    9700           6 :                     n->subname = NULL;
    9701           6 :                     n->newname = $7;
    9702           6 :                     n->missing_ok = false;
    9703           6 :                     $$ = (Node *) n;
    9704             :                 }
    9705             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9706             :                 {
    9707           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9708             : 
    9709           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9710           6 :                     n->relation = $6;
    9711           6 :                     n->subname = NULL;
    9712           6 :                     n->newname = $9;
    9713           6 :                     n->missing_ok = true;
    9714           6 :                     $$ = (Node *) n;
    9715             :                 }
    9716             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9717             :                 {
    9718         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9719             : 
    9720         238 :                     n->renameType = OBJECT_COLUMN;
    9721         238 :                     n->relationType = OBJECT_TABLE;
    9722         238 :                     n->relation = $3;
    9723         238 :                     n->subname = $6;
    9724         238 :                     n->newname = $8;
    9725         238 :                     n->missing_ok = false;
    9726         238 :                     $$ = (Node *) n;
    9727             :                 }
    9728             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9729             :                 {
    9730          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9731             : 
    9732          24 :                     n->renameType = OBJECT_COLUMN;
    9733          24 :                     n->relationType = OBJECT_TABLE;
    9734          24 :                     n->relation = $5;
    9735          24 :                     n->subname = $8;
    9736          24 :                     n->newname = $10;
    9737          24 :                     n->missing_ok = true;
    9738          24 :                     $$ = (Node *) n;
    9739             :                 }
    9740             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9741             :                 {
    9742          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9743             : 
    9744          18 :                     n->renameType = OBJECT_COLUMN;
    9745          18 :                     n->relationType = OBJECT_VIEW;
    9746          18 :                     n->relation = $3;
    9747          18 :                     n->subname = $6;
    9748          18 :                     n->newname = $8;
    9749          18 :                     n->missing_ok = false;
    9750          18 :                     $$ = (Node *) n;
    9751             :                 }
    9752             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9753             :                 {
    9754           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9755             : 
    9756           0 :                     n->renameType = OBJECT_COLUMN;
    9757           0 :                     n->relationType = OBJECT_VIEW;
    9758           0 :                     n->relation = $5;
    9759           0 :                     n->subname = $8;
    9760           0 :                     n->newname = $10;
    9761           0 :                     n->missing_ok = true;
    9762           0 :                     $$ = (Node *) n;
    9763             :                 }
    9764             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9765             :                 {
    9766           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9767             : 
    9768           0 :                     n->renameType = OBJECT_COLUMN;
    9769           0 :                     n->relationType = OBJECT_MATVIEW;
    9770           0 :                     n->relation = $4;
    9771           0 :                     n->subname = $7;
    9772           0 :                     n->newname = $9;
    9773           0 :                     n->missing_ok = false;
    9774           0 :                     $$ = (Node *) n;
    9775             :                 }
    9776             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9777             :                 {
    9778           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9779             : 
    9780           0 :                     n->renameType = OBJECT_COLUMN;
    9781           0 :                     n->relationType = OBJECT_MATVIEW;
    9782           0 :                     n->relation = $6;
    9783           0 :                     n->subname = $9;
    9784           0 :                     n->newname = $11;
    9785           0 :                     n->missing_ok = true;
    9786           0 :                     $$ = (Node *) n;
    9787             :                 }
    9788             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9789             :                 {
    9790          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9791             : 
    9792          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9793          72 :                     n->relation = $3;
    9794          72 :                     n->subname = $6;
    9795          72 :                     n->newname = $8;
    9796          72 :                     n->missing_ok = false;
    9797          72 :                     $$ = (Node *) n;
    9798             :                 }
    9799             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9800             :                 {
    9801           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9802             : 
    9803           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9804           6 :                     n->relation = $5;
    9805           6 :                     n->subname = $8;
    9806           6 :                     n->newname = $10;
    9807           6 :                     n->missing_ok = true;
    9808           6 :                     $$ = (Node *) n;
    9809             :                 }
    9810             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9811             :                 {
    9812           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9813             : 
    9814           6 :                     n->renameType = OBJECT_COLUMN;
    9815           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9816           6 :                     n->relation = $4;
    9817           6 :                     n->subname = $7;
    9818           6 :                     n->newname = $9;
    9819           6 :                     n->missing_ok = false;
    9820           6 :                     $$ = (Node *) n;
    9821             :                 }
    9822             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9823             :                 {
    9824           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9825             : 
    9826           6 :                     n->renameType = OBJECT_COLUMN;
    9827           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9828           6 :                     n->relation = $6;
    9829           6 :                     n->subname = $9;
    9830           6 :                     n->newname = $11;
    9831           6 :                     n->missing_ok = true;
    9832           6 :                     $$ = (Node *) n;
    9833             :                 }
    9834             :             | ALTER RULE name ON qualified_name RENAME TO name
    9835             :                 {
    9836          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9837             : 
    9838          34 :                     n->renameType = OBJECT_RULE;
    9839          34 :                     n->relation = $5;
    9840          34 :                     n->subname = $3;
    9841          34 :                     n->newname = $8;
    9842          34 :                     n->missing_ok = false;
    9843          34 :                     $$ = (Node *) n;
    9844             :                 }
    9845             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9846             :                 {
    9847          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9848             : 
    9849          40 :                     n->renameType = OBJECT_TRIGGER;
    9850          40 :                     n->relation = $5;
    9851          40 :                     n->subname = $3;
    9852          40 :                     n->newname = $8;
    9853          40 :                     n->missing_ok = false;
    9854          40 :                     $$ = (Node *) n;
    9855             :                 }
    9856             :             | ALTER EVENT TRIGGER name RENAME TO name
    9857             :                 {
    9858          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9859             : 
    9860          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9861          12 :                     n->object = (Node *) makeString($4);
    9862          12 :                     n->newname = $7;
    9863          12 :                     $$ = (Node *) n;
    9864             :                 }
    9865             :             | ALTER ROLE RoleId RENAME TO RoleId
    9866             :                 {
    9867          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9868             : 
    9869          30 :                     n->renameType = OBJECT_ROLE;
    9870          30 :                     n->subname = $3;
    9871          30 :                     n->newname = $6;
    9872          30 :                     n->missing_ok = false;
    9873          30 :                     $$ = (Node *) n;
    9874             :                 }
    9875             :             | ALTER USER RoleId RENAME TO RoleId
    9876             :                 {
    9877           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9878             : 
    9879           0 :                     n->renameType = OBJECT_ROLE;
    9880           0 :                     n->subname = $3;
    9881           0 :                     n->newname = $6;
    9882           0 :                     n->missing_ok = false;
    9883           0 :                     $$ = (Node *) n;
    9884             :                 }
    9885             :             | ALTER TABLESPACE name RENAME TO name
    9886             :                 {
    9887           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9888             : 
    9889           6 :                     n->renameType = OBJECT_TABLESPACE;
    9890           6 :                     n->subname = $3;
    9891           6 :                     n->newname = $6;
    9892           6 :                     n->missing_ok = false;
    9893           6 :                     $$ = (Node *) n;
    9894             :                 }
    9895             :             | ALTER STATISTICS any_name RENAME TO name
    9896             :                 {
    9897          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9898             : 
    9899          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9900          30 :                     n->object = (Node *) $3;
    9901          30 :                     n->newname = $6;
    9902          30 :                     n->missing_ok = false;
    9903          30 :                     $$ = (Node *) n;
    9904             :                 }
    9905             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9906             :                 {
    9907          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9908             : 
    9909          12 :                     n->renameType = OBJECT_TSPARSER;
    9910          12 :                     n->object = (Node *) $5;
    9911          12 :                     n->newname = $8;
    9912          12 :                     n->missing_ok = false;
    9913          12 :                     $$ = (Node *) n;
    9914             :                 }
    9915             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9916             :                 {
    9917          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9918             : 
    9919          24 :                     n->renameType = OBJECT_TSDICTIONARY;
    9920          24 :                     n->object = (Node *) $5;
    9921          24 :                     n->newname = $8;
    9922          24 :                     n->missing_ok = false;
    9923          24 :                     $$ = (Node *) n;
    9924             :                 }
    9925             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9926             :                 {
    9927          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9928             : 
    9929          12 :                     n->renameType = OBJECT_TSTEMPLATE;
    9930          12 :                     n->object = (Node *) $5;
    9931          12 :                     n->newname = $8;
    9932          12 :                     n->missing_ok = false;
    9933          12 :                     $$ = (Node *) n;
    9934             :                 }
    9935             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9936             :                 {
    9937          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9938             : 
    9939          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9940          24 :                     n->object = (Node *) $5;
    9941          24 :                     n->newname = $8;
    9942          24 :                     n->missing_ok = false;
    9943          24 :                     $$ = (Node *) n;
    9944             :                 }
    9945             :             | ALTER TYPE_P any_name RENAME TO name
    9946             :                 {
    9947          26 :                     RenameStmt *n = makeNode(RenameStmt);
    9948             : 
    9949          26 :                     n->renameType = OBJECT_TYPE;
    9950          26 :                     n->object = (Node *) $3;
    9951          26 :                     n->newname = $6;
    9952          26 :                     n->missing_ok = false;
    9953          26 :                     $$ = (Node *) n;
    9954             :                 }
    9955             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
    9956             :                 {
    9957          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9958             : 
    9959          24 :                     n->renameType = OBJECT_ATTRIBUTE;
    9960          24 :                     n->relationType = OBJECT_TYPE;
    9961          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    9962          24 :                     n->subname = $6;
    9963          24 :                     n->newname = $8;
    9964          24 :                     n->behavior = $9;
    9965          24 :                     n->missing_ok = false;
    9966          24 :                     $$ = (Node *) n;
    9967             :                 }
    9968             :         ;
    9969             : 
    9970             : opt_column: COLUMN
    9971             :             | /*EMPTY*/
    9972             :         ;
    9973             : 
    9974         184 : opt_set_data: SET DATA_P                            { $$ = 1; }
    9975         884 :             | /*EMPTY*/                             { $$ = 0; }
    9976             :         ;
    9977             : 
    9978             : /*****************************************************************************
    9979             :  *
    9980             :  * ALTER THING name DEPENDS ON EXTENSION name
    9981             :  *
    9982             :  *****************************************************************************/
    9983             : 
    9984             : AlterObjectDependsStmt:
    9985             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9986             :                 {
    9987          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9988             : 
    9989          12 :                     n->objectType = OBJECT_FUNCTION;
    9990          12 :                     n->object = (Node *) $3;
    9991          12 :                     n->extname = makeString($8);
    9992          12 :                     n->remove = $4;
    9993          12 :                     $$ = (Node *) n;
    9994             :                 }
    9995             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9996             :                 {
    9997           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9998             : 
    9999           0 :                     n->objectType = OBJECT_PROCEDURE;
   10000           0 :                     n->object = (Node *) $3;
   10001           0 :                     n->extname = makeString($8);
   10002           0 :                     n->remove = $4;
   10003           0 :                     $$ = (Node *) n;
   10004             :                 }
   10005             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10006             :                 {
   10007           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10008             : 
   10009           0 :                     n->objectType = OBJECT_ROUTINE;
   10010           0 :                     n->object = (Node *) $3;
   10011           0 :                     n->extname = makeString($8);
   10012           0 :                     n->remove = $4;
   10013           0 :                     $$ = (Node *) n;
   10014             :                 }
   10015             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10016             :                 {
   10017          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10018             : 
   10019          10 :                     n->objectType = OBJECT_TRIGGER;
   10020          10 :                     n->relation = $5;
   10021          10 :                     n->object = (Node *) list_make1(makeString($3));
   10022          10 :                     n->extname = makeString($10);
   10023          10 :                     n->remove = $6;
   10024          10 :                     $$ = (Node *) n;
   10025             :                 }
   10026             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10027             :                 {
   10028          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10029             : 
   10030          10 :                     n->objectType = OBJECT_MATVIEW;
   10031          10 :                     n->relation = $4;
   10032          10 :                     n->extname = makeString($9);
   10033          10 :                     n->remove = $5;
   10034          10 :                     $$ = (Node *) n;
   10035             :                 }
   10036             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10037             :                 {
   10038          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10039             : 
   10040          14 :                     n->objectType = OBJECT_INDEX;
   10041          14 :                     n->relation = $3;
   10042          14 :                     n->extname = makeString($8);
   10043          14 :                     n->remove = $4;
   10044          14 :                     $$ = (Node *) n;
   10045             :                 }
   10046             :         ;
   10047             : 
   10048           8 : opt_no:     NO              { $$ = true; }
   10049          38 :             | /* EMPTY */   { $$ = false;   }
   10050             :         ;
   10051             : 
   10052             : /*****************************************************************************
   10053             :  *
   10054             :  * ALTER THING name SET SCHEMA name
   10055             :  *
   10056             :  *****************************************************************************/
   10057             : 
   10058             : AlterObjectSchemaStmt:
   10059             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10060             :                 {
   10061          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10062             : 
   10063          24 :                     n->objectType = OBJECT_AGGREGATE;
   10064          24 :                     n->object = (Node *) $3;
   10065          24 :                     n->newschema = $6;
   10066          24 :                     n->missing_ok = false;
   10067          24 :                     $$ = (Node *) n;
   10068             :                 }
   10069             :             | ALTER COLLATION any_name SET SCHEMA name
   10070             :                 {
   10071           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10072             : 
   10073           6 :                     n->objectType = OBJECT_COLLATION;
   10074           6 :                     n->object = (Node *) $3;
   10075           6 :                     n->newschema = $6;
   10076           6 :                     n->missing_ok = false;
   10077           6 :                     $$ = (Node *) n;
   10078             :                 }
   10079             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10080             :                 {
   10081          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10082             : 
   10083          24 :                     n->objectType = OBJECT_CONVERSION;
   10084          24 :                     n->object = (Node *) $3;
   10085          24 :                     n->newschema = $6;
   10086          24 :                     n->missing_ok = false;
   10087          24 :                     $$ = (Node *) n;
   10088             :                 }
   10089             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10090             :                 {
   10091           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10092             : 
   10093           6 :                     n->objectType = OBJECT_DOMAIN;
   10094           6 :                     n->object = (Node *) $3;
   10095           6 :                     n->newschema = $6;
   10096           6 :                     n->missing_ok = false;
   10097           6 :                     $$ = (Node *) n;
   10098             :                 }
   10099             :             | ALTER EXTENSION name SET SCHEMA name
   10100             :                 {
   10101          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10102             : 
   10103          12 :                     n->objectType = OBJECT_EXTENSION;
   10104          12 :                     n->object = (Node *) makeString($3);
   10105          12 :                     n->newschema = $6;
   10106          12 :                     n->missing_ok = false;
   10107          12 :                     $$ = (Node *) n;
   10108             :                 }
   10109             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10110             :                 {
   10111          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10112             : 
   10113          42 :                     n->objectType = OBJECT_FUNCTION;
   10114          42 :                     n->object = (Node *) $3;
   10115          42 :                     n->newschema = $6;
   10116          42 :                     n->missing_ok = false;
   10117          42 :                     $$ = (Node *) n;
   10118             :                 }
   10119             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10120             :                 {
   10121          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10122             : 
   10123          18 :                     n->objectType = OBJECT_OPERATOR;
   10124          18 :                     n->object = (Node *) $3;
   10125          18 :                     n->newschema = $6;
   10126          18 :                     n->missing_ok = false;
   10127          18 :                     $$ = (Node *) n;
   10128             :                 }
   10129             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10130             :                 {
   10131          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10132             : 
   10133          24 :                     n->objectType = OBJECT_OPCLASS;
   10134          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10135          24 :                     n->newschema = $9;
   10136          24 :                     n->missing_ok = false;
   10137          24 :                     $$ = (Node *) n;
   10138             :                 }
   10139             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10140             :                 {
   10141          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10142             : 
   10143          24 :                     n->objectType = OBJECT_OPFAMILY;
   10144          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10145          24 :                     n->newschema = $9;
   10146          24 :                     n->missing_ok = false;
   10147          24 :                     $$ = (Node *) n;
   10148             :                 }
   10149             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10150             :                 {
   10151           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10152             : 
   10153           0 :                     n->objectType = OBJECT_PROCEDURE;
   10154           0 :                     n->object = (Node *) $3;
   10155           0 :                     n->newschema = $6;
   10156           0 :                     n->missing_ok = false;
   10157           0 :                     $$ = (Node *) n;
   10158             :                 }
   10159             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10160             :                 {
   10161           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10162             : 
   10163           0 :                     n->objectType = OBJECT_ROUTINE;
   10164           0 :                     n->object = (Node *) $3;
   10165           0 :                     n->newschema = $6;
   10166           0 :                     n->missing_ok = false;
   10167           0 :                     $$ = (Node *) n;
   10168             :                 }
   10169             :             | ALTER TABLE relation_expr SET SCHEMA name
   10170             :                 {
   10171          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10172             : 
   10173          66 :                     n->objectType = OBJECT_TABLE;
   10174          66 :                     n->relation = $3;
   10175          66 :                     n->newschema = $6;
   10176          66 :                     n->missing_ok = false;
   10177          66 :                     $$ = (Node *) n;
   10178             :                 }
   10179             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10180             :                 {
   10181          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10182             : 
   10183          12 :                     n->objectType = OBJECT_TABLE;
   10184          12 :                     n->relation = $5;
   10185          12 :                     n->newschema = $8;
   10186          12 :                     n->missing_ok = true;
   10187          12 :                     $$ = (Node *) n;
   10188             :                 }
   10189             :             | ALTER STATISTICS any_name SET SCHEMA name
   10190             :                 {
   10191          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10192             : 
   10193          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10194          18 :                     n->object = (Node *) $3;
   10195          18 :                     n->newschema = $6;
   10196          18 :                     n->missing_ok = false;
   10197          18 :                     $$ = (Node *) n;
   10198             :                 }
   10199             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10200             :                 {
   10201          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10202             : 
   10203          18 :                     n->objectType = OBJECT_TSPARSER;
   10204          18 :                     n->object = (Node *) $5;
   10205          18 :                     n->newschema = $8;
   10206          18 :                     n->missing_ok = false;
   10207          18 :                     $$ = (Node *) n;
   10208             :                 }
   10209             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10210             :                 {
   10211          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10212             : 
   10213          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10214          24 :                     n->object = (Node *) $5;
   10215          24 :                     n->newschema = $8;
   10216          24 :                     n->missing_ok = false;
   10217          24 :                     $$ = (Node *) n;
   10218             :                 }
   10219             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10220             :                 {
   10221          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10222             : 
   10223          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10224          18 :                     n->object = (Node *) $5;
   10225          18 :                     n->newschema = $8;
   10226          18 :                     n->missing_ok = false;
   10227          18 :                     $$ = (Node *) n;
   10228             :                 }
   10229             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10230             :                 {
   10231          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10232             : 
   10233          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10234          24 :                     n->object = (Node *) $5;
   10235          24 :                     n->newschema = $8;
   10236          24 :                     n->missing_ok = false;
   10237          24 :                     $$ = (Node *) n;
   10238             :                 }
   10239             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10240             :                 {
   10241           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10242             : 
   10243           8 :                     n->objectType = OBJECT_SEQUENCE;
   10244           8 :                     n->relation = $3;
   10245           8 :                     n->newschema = $6;
   10246           8 :                     n->missing_ok = false;
   10247           8 :                     $$ = (Node *) n;
   10248             :                 }
   10249             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10250             :                 {
   10251           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10252             : 
   10253           0 :                     n->objectType = OBJECT_SEQUENCE;
   10254           0 :                     n->relation = $5;
   10255           0 :                     n->newschema = $8;
   10256           0 :                     n->missing_ok = true;
   10257           0 :                     $$ = (Node *) n;
   10258             :                 }
   10259             :             | ALTER VIEW qualified_name SET SCHEMA name
   10260             :                 {
   10261           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10262             : 
   10263           0 :                     n->objectType = OBJECT_VIEW;
   10264           0 :                     n->relation = $3;
   10265           0 :                     n->newschema = $6;
   10266           0 :                     n->missing_ok = false;
   10267           0 :                     $$ = (Node *) n;
   10268             :                 }
   10269             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10270             :                 {
   10271           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10272             : 
   10273           0 :                     n->objectType = OBJECT_VIEW;
   10274           0 :                     n->relation = $5;
   10275           0 :                     n->newschema = $8;
   10276           0 :                     n->missing_ok = true;
   10277           0 :                     $$ = (Node *) n;
   10278             :                 }
   10279             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10280             :                 {
   10281           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10282             : 
   10283           6 :                     n->objectType = OBJECT_MATVIEW;
   10284           6 :                     n->relation = $4;
   10285           6 :                     n->newschema = $7;
   10286           6 :                     n->missing_ok = false;
   10287           6 :                     $$ = (Node *) n;
   10288             :                 }
   10289             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10290             :                 {
   10291           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10292             : 
   10293           0 :                     n->objectType = OBJECT_MATVIEW;
   10294           0 :                     n->relation = $6;
   10295           0 :                     n->newschema = $9;
   10296           0 :                     n->missing_ok = true;
   10297           0 :                     $$ = (Node *) n;
   10298             :                 }
   10299             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10300             :                 {
   10301           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10302             : 
   10303           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10304           6 :                     n->relation = $4;
   10305           6 :                     n->newschema = $7;
   10306           6 :                     n->missing_ok = false;
   10307           6 :                     $$ = (Node *) n;
   10308             :                 }
   10309             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10310             :                 {
   10311           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10312             : 
   10313           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10314           6 :                     n->relation = $6;
   10315           6 :                     n->newschema = $9;
   10316           6 :                     n->missing_ok = true;
   10317           6 :                     $$ = (Node *) n;
   10318             :                 }
   10319             :             | ALTER TYPE_P any_name SET SCHEMA name
   10320             :                 {
   10321          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10322             : 
   10323          12 :                     n->objectType = OBJECT_TYPE;
   10324          12 :                     n->object = (Node *) $3;
   10325          12 :                     n->newschema = $6;
   10326          12 :                     n->missing_ok = false;
   10327          12 :                     $$ = (Node *) n;
   10328             :                 }
   10329             :         ;
   10330             : 
   10331             : /*****************************************************************************
   10332             :  *
   10333             :  * ALTER OPERATOR name SET define
   10334             :  *
   10335             :  *****************************************************************************/
   10336             : 
   10337             : AlterOperatorStmt:
   10338             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10339             :                 {
   10340         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10341             : 
   10342         608 :                     n->opername = $3;
   10343         608 :                     n->options = $6;
   10344         608 :                     $$ = (Node *) n;
   10345             :                 }
   10346             :         ;
   10347             : 
   10348         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10349         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10350             :         ;
   10351             : 
   10352             : operator_def_elem: ColLabel '=' NONE
   10353          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10354             :                    | ColLabel '=' operator_def_arg
   10355        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10356             :                    | ColLabel
   10357          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10358             :         ;
   10359             : 
   10360             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10361             : operator_def_arg:
   10362        1032 :             func_type                       { $$ = (Node *) $1; }
   10363          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10364          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10365           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10366           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10367             :         ;
   10368             : 
   10369             : /*****************************************************************************
   10370             :  *
   10371             :  * ALTER TYPE name SET define
   10372             :  *
   10373             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10374             :  *
   10375             :  *****************************************************************************/
   10376             : 
   10377             : AlterTypeStmt:
   10378             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10379             :                 {
   10380          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10381             : 
   10382          60 :                     n->typeName = $3;
   10383          60 :                     n->options = $6;
   10384          60 :                     $$ = (Node *) n;
   10385             :                 }
   10386             :         ;
   10387             : 
   10388             : /*****************************************************************************
   10389             :  *
   10390             :  * ALTER THING name OWNER TO newname
   10391             :  *
   10392             :  *****************************************************************************/
   10393             : 
   10394             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10395             :                 {
   10396         236 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10397             : 
   10398         236 :                     n->objectType = OBJECT_AGGREGATE;
   10399         236 :                     n->object = (Node *) $3;
   10400         236 :                     n->newowner = $6;
   10401         236 :                     $$ = (Node *) n;
   10402             :                 }
   10403             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10404             :                 {
   10405          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10406             : 
   10407          24 :                     n->objectType = OBJECT_COLLATION;
   10408          24 :                     n->object = (Node *) $3;
   10409          24 :                     n->newowner = $6;
   10410          24 :                     $$ = (Node *) n;
   10411             :                 }
   10412             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10413             :                 {
   10414          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10415             : 
   10416          24 :                     n->objectType = OBJECT_CONVERSION;
   10417          24 :                     n->object = (Node *) $3;
   10418          24 :                     n->newowner = $6;
   10419          24 :                     $$ = (Node *) n;
   10420             :                 }
   10421             :             | ALTER DATABASE name OWNER TO RoleSpec
   10422             :                 {
   10423          80 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10424             : 
   10425          80 :                     n->objectType = OBJECT_DATABASE;
   10426          80 :                     n->object = (Node *) makeString($3);
   10427          80 :                     n->newowner = $6;
   10428          80 :                     $$ = (Node *) n;
   10429             :                 }
   10430             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10431             :                 {
   10432          92 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10433             : 
   10434          92 :                     n->objectType = OBJECT_DOMAIN;
   10435          92 :                     n->object = (Node *) $3;
   10436          92 :                     n->newowner = $6;
   10437          92 :                     $$ = (Node *) n;
   10438             :                 }
   10439             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10440             :                 {
   10441        1114 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10442             : 
   10443        1114 :                     n->objectType = OBJECT_FUNCTION;
   10444        1114 :                     n->object = (Node *) $3;
   10445        1114 :                     n->newowner = $6;
   10446        1114 :                     $$ = (Node *) n;
   10447             :                 }
   10448             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10449             :                 {
   10450         140 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10451             : 
   10452         140 :                     n->objectType = OBJECT_LANGUAGE;
   10453         140 :                     n->object = (Node *) makeString($4);
   10454         140 :                     n->newowner = $7;
   10455         140 :                     $$ = (Node *) n;
   10456             :                 }
   10457             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10458             :                 {
   10459          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10460             : 
   10461          18 :                     n->objectType = OBJECT_LARGEOBJECT;
   10462          18 :                     n->object = (Node *) $4;
   10463          18 :                     n->newowner = $7;
   10464          18 :                     $$ = (Node *) n;
   10465             :                 }
   10466             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10467             :                 {
   10468          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10469             : 
   10470          68 :                     n->objectType = OBJECT_OPERATOR;
   10471          68 :                     n->object = (Node *) $3;
   10472          68 :                     n->newowner = $6;
   10473          68 :                     $$ = (Node *) n;
   10474             :                 }
   10475             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10476             :                 {
   10477          60 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10478             : 
   10479          60 :                     n->objectType = OBJECT_OPCLASS;
   10480          60 :                     n->object = (Node *) lcons(makeString($6), $4);
   10481          60 :                     n->newowner = $9;
   10482          60 :                     $$ = (Node *) n;
   10483             :                 }
   10484             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10485             :                 {
   10486          76 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10487             : 
   10488          76 :                     n->objectType = OBJECT_OPFAMILY;
   10489          76 :                     n->object = (Node *) lcons(makeString($6), $4);
   10490          76 :                     n->newowner = $9;
   10491          76 :                     $$ = (Node *) n;
   10492             :                 }
   10493             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10494             :                 {
   10495          48 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10496             : 
   10497          48 :                     n->objectType = OBJECT_PROCEDURE;
   10498          48 :                     n->object = (Node *) $3;
   10499          48 :                     n->newowner = $6;
   10500          48 :                     $$ = (Node *) n;
   10501             :                 }
   10502             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10503             :                 {
   10504           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10505             : 
   10506           0 :                     n->objectType = OBJECT_ROUTINE;
   10507           0 :                     n->object = (Node *) $3;
   10508           0 :                     n->newowner = $6;
   10509           0 :                     $$ = (Node *) n;
   10510             :                 }
   10511             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10512             :                 {
   10513          78 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10514             : 
   10515          78 :                     n->objectType = OBJECT_SCHEMA;
   10516          78 :                     n->object = (Node *) makeString($3);
   10517          78 :                     n->newowner = $6;
   10518          78 :                     $$ = (Node *) n;
   10519             :                 }
   10520             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10521             :                 {
   10522         152 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10523             : 
   10524         152 :                     n->objectType = OBJECT_TYPE;
   10525         152 :                     n->object = (Node *) $3;
   10526         152 :                     n->newowner = $6;
   10527         152 :                     $$ = (Node *) n;
   10528             :                 }
   10529             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10530             :                 {
   10531           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10532             : 
   10533           6 :                     n->objectType = OBJECT_TABLESPACE;
   10534           6 :                     n->object = (Node *) makeString($3);
   10535           6 :                     n->newowner = $6;
   10536           6 :                     $$ = (Node *) n;
   10537             :                 }
   10538             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10539             :                 {
   10540          40 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10541             : 
   10542          40 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10543          40 :                     n->object = (Node *) $3;
   10544          40 :                     n->newowner = $6;
   10545          40 :                     $$ = (Node *) n;
   10546             :                 }
   10547             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10548             :                 {
   10549          60 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10550             : 
   10551          60 :                     n->objectType = OBJECT_TSDICTIONARY;
   10552          60 :                     n->object = (Node *) $5;
   10553          60 :                     n->newowner = $8;
   10554          60 :                     $$ = (Node *) n;
   10555             :                 }
   10556             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10557             :                 {
   10558          40 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10559             : 
   10560          40 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10561          40 :                     n->object = (Node *) $5;
   10562          40 :                     n->newowner = $8;
   10563          40 :                     $$ = (Node *) n;
   10564             :                 }
   10565             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10566             :                 {
   10567          22 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10568             : 
   10569          22 :                     n->objectType = OBJECT_FDW;
   10570          22 :                     n->object = (Node *) makeString($5);
   10571          22 :                     n->newowner = $8;
   10572          22 :                     $$ = (Node *) n;
   10573             :                 }
   10574             :             | ALTER SERVER name OWNER TO RoleSpec
   10575             :                 {
   10576          70 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10577             : 
   10578          70 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10579          70 :                     n->object = (Node *) makeString($3);
   10580          70 :                     n->newowner = $6;
   10581          70 :                     $$ = (Node *) n;
   10582             :                 }
   10583             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10584             :                 {
   10585          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10586             : 
   10587          16 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10588          16 :                     n->object = (Node *) makeString($4);
   10589          16 :                     n->newowner = $7;
   10590          16 :                     $$ = (Node *) n;
   10591             :                 }
   10592             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10593             :                 {
   10594          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10595             : 
   10596          26 :                     n->objectType = OBJECT_PUBLICATION;
   10597          26 :                     n->object = (Node *) makeString($3);
   10598          26 :                     n->newowner = $6;
   10599          26 :                     $$ = (Node *) n;
   10600             :                 }
   10601             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10602             :                 {
   10603          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10604             : 
   10605          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10606          18 :                     n->object = (Node *) makeString($3);
   10607          18 :                     n->newowner = $6;
   10608          18 :                     $$ = (Node *) n;
   10609             :                 }
   10610             :         ;
   10611             : 
   10612             : 
   10613             : /*****************************************************************************
   10614             :  *
   10615             :  * CREATE PUBLICATION name [WITH options]
   10616             :  *
   10617             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10618             :  *
   10619             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10620             :  *
   10621             :  * pub_obj is one of:
   10622             :  *
   10623             :  *      TABLE table [, ...]
   10624             :  *      TABLES IN SCHEMA schema [, ...]
   10625             :  *
   10626             :  *****************************************************************************/
   10627             : 
   10628             : CreatePublicationStmt:
   10629             :             CREATE PUBLICATION name opt_definition
   10630             :                 {
   10631         126 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10632             : 
   10633         126 :                     n->pubname = $3;
   10634         126 :                     n->options = $4;
   10635         126 :                     $$ = (Node *) n;
   10636             :                 }
   10637             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10638             :                 {
   10639          94 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10640             : 
   10641          94 :                     n->pubname = $3;
   10642          94 :                     n->options = $7;
   10643          94 :                     n->for_all_tables = true;
   10644          94 :                     $$ = (Node *) n;
   10645             :                 }
   10646             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10647             :                 {
   10648         624 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10649             : 
   10650         624 :                     n->pubname = $3;
   10651         624 :                     n->options = $6;
   10652         624 :                     n->pubobjects = (List *) $5;
   10653         624 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10654         594 :                     $$ = (Node *) n;
   10655             :                 }
   10656             :         ;
   10657             : 
   10658             : /*
   10659             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10660             :  *
   10661             :  * This rule parses publication objects with and without keyword prefixes.
   10662             :  *
   10663             :  * The actual type of the object without keyword prefix depends on the previous
   10664             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10665             :  *
   10666             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10667             :  * because some extended expressions in relation_expr cannot be used as a
   10668             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10669             :  * relation_expr here.
   10670             :  */
   10671             : PublicationObjSpec:
   10672             :             TABLE relation_expr opt_column_list OptWhereClause
   10673             :                 {
   10674        1276 :                     $$ = makeNode(PublicationObjSpec);
   10675        1276 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10676        1276 :                     $$->pubtable = makeNode(PublicationTable);
   10677        1276 :                     $$->pubtable->relation = $2;
   10678        1276 :                     $$->pubtable->columns = $3;
   10679        1276 :                     $$->pubtable->whereClause = $4;
   10680             :                 }
   10681             :             | TABLES IN_P SCHEMA ColId
   10682             :                 {
   10683         332 :                     $$ = makeNode(PublicationObjSpec);
   10684         332 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10685         332 :                     $$->name = $4;
   10686         332 :                     $$->location = @4;
   10687             :                 }
   10688             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10689             :                 {
   10690          18 :                     $$ = makeNode(PublicationObjSpec);
   10691          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10692          18 :                     $$->location = @4;
   10693             :                 }
   10694             :             | ColId opt_column_list OptWhereClause
   10695             :                 {
   10696         130 :                     $$ = makeNode(PublicationObjSpec);
   10697         130 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10698             :                     /*
   10699             :                      * If either a row filter or column list is specified, create
   10700             :                      * a PublicationTable object.
   10701             :                      */
   10702         130 :                     if ($2 || $3)
   10703             :                     {
   10704             :                         /*
   10705             :                          * The OptWhereClause must be stored here but it is
   10706             :                          * valid only for tables. For non-table objects, an
   10707             :                          * error will be thrown later via
   10708             :                          * preprocess_pubobj_list().
   10709             :                          */
   10710          42 :                         $$->pubtable = makeNode(PublicationTable);
   10711          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10712          42 :                         $$->pubtable->columns = $2;
   10713          42 :                         $$->pubtable->whereClause = $3;
   10714             :                     }
   10715             :                     else
   10716             :                     {
   10717          88 :                         $$->name = $1;
   10718             :                     }
   10719         130 :                     $$->location = @1;
   10720             :                 }
   10721             :             | ColId indirection opt_column_list OptWhereClause
   10722             :                 {
   10723          32 :                     $$ = makeNode(PublicationObjSpec);
   10724          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10725          32 :                     $$->pubtable = makeNode(PublicationTable);
   10726          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10727          32 :                     $$->pubtable->columns = $3;
   10728          32 :                     $$->pubtable->whereClause = $4;
   10729          32 :                     $$->location = @1;
   10730             :                 }
   10731             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10732             :             | extended_relation_expr opt_column_list OptWhereClause
   10733             :                 {
   10734           6 :                     $$ = makeNode(PublicationObjSpec);
   10735           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10736           6 :                     $$->pubtable = makeNode(PublicationTable);
   10737           6 :                     $$->pubtable->relation = $1;
   10738           6 :                     $$->pubtable->columns = $2;
   10739           6 :                     $$->pubtable->whereClause = $3;
   10740             :                 }
   10741             :             | CURRENT_SCHEMA
   10742             :                 {
   10743          18 :                     $$ = makeNode(PublicationObjSpec);
   10744          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10745          18 :                     $$->location = @1;
   10746             :                 }
   10747             :                 ;
   10748             : 
   10749             : pub_obj_list:   PublicationObjSpec
   10750        1588 :                     { $$ = list_make1($1); }
   10751             :             | pub_obj_list ',' PublicationObjSpec
   10752         224 :                     { $$ = lappend($1, $3); }
   10753             :     ;
   10754             : 
   10755             : /*****************************************************************************
   10756             :  *
   10757             :  * ALTER PUBLICATION name SET ( options )
   10758             :  *
   10759             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10760             :  *
   10761             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10762             :  *
   10763             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10764             :  *
   10765             :  * pub_obj is one of:
   10766             :  *
   10767             :  *      TABLE table_name [, ...]
   10768             :  *      TABLES IN SCHEMA schema_name [, ...]
   10769             :  *
   10770             :  *****************************************************************************/
   10771             : 
   10772             : AlterPublicationStmt:
   10773             :             ALTER PUBLICATION name SET definition
   10774             :                 {
   10775         116 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10776             : 
   10777         116 :                     n->pubname = $3;
   10778         116 :                     n->options = $5;
   10779         116 :                     $$ = (Node *) n;
   10780             :                 }
   10781             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10782             :                 {
   10783         346 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10784             : 
   10785         346 :                     n->pubname = $3;
   10786         346 :                     n->pubobjects = $5;
   10787         346 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10788         340 :                     n->action = AP_AddObjects;
   10789         340 :                     $$ = (Node *) n;
   10790             :                 }
   10791             :             | ALTER PUBLICATION name SET pub_obj_list
   10792             :                 {
   10793         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10794             : 
   10795         464 :                     n->pubname = $3;
   10796         464 :                     n->pubobjects = $5;
   10797         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10798         464 :                     n->action = AP_SetObjects;
   10799         464 :                     $$ = (Node *) n;
   10800             :                 }
   10801             :             | ALTER PUBLICATION name DROP pub_obj_list
   10802             :                 {
   10803         154 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10804             : 
   10805         154 :                     n->pubname = $3;
   10806         154 :                     n->pubobjects = $5;
   10807         154 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10808         154 :                     n->action = AP_DropObjects;
   10809         154 :                     $$ = (Node *) n;
   10810             :                 }
   10811             :         ;
   10812             : 
   10813             : /*****************************************************************************
   10814             :  *
   10815             :  * CREATE SUBSCRIPTION name ...
   10816             :  *
   10817             :  *****************************************************************************/
   10818             : 
   10819             : CreateSubscriptionStmt:
   10820             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10821             :                 {
   10822             :                     CreateSubscriptionStmt *n =
   10823         448 :                         makeNode(CreateSubscriptionStmt);
   10824         448 :                     n->subname = $3;
   10825         448 :                     n->conninfo = $5;
   10826         448 :                     n->publication = $7;
   10827         448 :                     n->options = $8;
   10828         448 :                     $$ = (Node *) n;
   10829             :                 }
   10830             :         ;
   10831             : 
   10832             : /*****************************************************************************
   10833             :  *
   10834             :  * ALTER SUBSCRIPTION name ...
   10835             :  *
   10836             :  *****************************************************************************/
   10837             : 
   10838             : AlterSubscriptionStmt:
   10839             :             ALTER SUBSCRIPTION name SET definition
   10840             :                 {
   10841             :                     AlterSubscriptionStmt *n =
   10842         186 :                         makeNode(AlterSubscriptionStmt);
   10843             : 
   10844         186 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10845         186 :                     n->subname = $3;
   10846         186 :                     n->options = $5;
   10847         186 :                     $$ = (Node *) n;
   10848             :                 }
   10849             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10850             :                 {
   10851             :                     AlterSubscriptionStmt *n =
   10852          26 :                         makeNode(AlterSubscriptionStmt);
   10853             : 
   10854          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10855          26 :                     n->subname = $3;
   10856          26 :                     n->conninfo = $5;
   10857          26 :                     $$ = (Node *) n;
   10858             :                 }
   10859             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10860             :                 {
   10861             :                     AlterSubscriptionStmt *n =
   10862          58 :                         makeNode(AlterSubscriptionStmt);
   10863             : 
   10864          58 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10865          58 :                     n->subname = $3;
   10866          58 :                     n->options = $6;
   10867          58 :                     $$ = (Node *) n;
   10868             :                 }
   10869             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10870             :                 {
   10871             :                     AlterSubscriptionStmt *n =
   10872          28 :                         makeNode(AlterSubscriptionStmt);
   10873             : 
   10874          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10875          28 :                     n->subname = $3;
   10876          28 :                     n->publication = $6;
   10877          28 :                     n->options = $7;
   10878          28 :                     $$ = (Node *) n;
   10879             :                 }
   10880             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10881             :                 {
   10882             :                     AlterSubscriptionStmt *n =
   10883          26 :                         makeNode(AlterSubscriptionStmt);
   10884             : 
   10885          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10886          26 :                     n->subname = $3;
   10887          26 :                     n->publication = $6;
   10888          26 :                     n->options = $7;
   10889          26 :                     $$ = (Node *) n;
   10890             :                 }
   10891             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10892             :                 {
   10893             :                     AlterSubscriptionStmt *n =
   10894          44 :                         makeNode(AlterSubscriptionStmt);
   10895             : 
   10896          44 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10897          44 :                     n->subname = $3;
   10898          44 :                     n->publication = $6;
   10899          44 :                     n->options = $7;
   10900          44 :                     $$ = (Node *) n;
   10901             :                 }
   10902             :             | ALTER SUBSCRIPTION name ENABLE_P
   10903             :                 {
   10904             :                     AlterSubscriptionStmt *n =
   10905          50 :                         makeNode(AlterSubscriptionStmt);
   10906             : 
   10907          50 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10908          50 :                     n->subname = $3;
   10909          50 :                     n->options = list_make1(makeDefElem("enabled",
   10910             :                                             (Node *) makeBoolean(true), @1));
   10911          50 :                     $$ = (Node *) n;
   10912             :                 }
   10913             :             | ALTER SUBSCRIPTION name DISABLE_P
   10914             :                 {
   10915             :                     AlterSubscriptionStmt *n =
   10916          34 :                         makeNode(AlterSubscriptionStmt);
   10917             : 
   10918          34 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10919          34 :                     n->subname = $3;
   10920          34 :                     n->options = list_make1(makeDefElem("enabled",
   10921             :                                             (Node *) makeBoolean(false), @1));
   10922          34 :                     $$ = (Node *) n;
   10923             :                 }
   10924             :             | ALTER SUBSCRIPTION name SKIP definition
   10925             :                 {
   10926             :                     AlterSubscriptionStmt *n =
   10927          24 :                         makeNode(AlterSubscriptionStmt);
   10928             : 
   10929          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10930          24 :                     n->subname = $3;
   10931          24 :                     n->options = $5;
   10932          24 :                     $$ = (Node *) n;
   10933             :                 }
   10934             :         ;
   10935             : 
   10936             : /*****************************************************************************
   10937             :  *
   10938             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   10939             :  *
   10940             :  *****************************************************************************/
   10941             : 
   10942             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   10943             :                 {
   10944         222 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10945             : 
   10946         222 :                     n->subname = $3;
   10947         222 :                     n->missing_ok = false;
   10948         222 :                     n->behavior = $4;
   10949         222 :                     $$ = (Node *) n;
   10950             :                 }
   10951             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   10952             :                 {
   10953           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10954             : 
   10955           6 :                     n->subname = $5;
   10956           6 :                     n->missing_ok = true;
   10957           6 :                     n->behavior = $6;
   10958           6 :                     $$ = (Node *) n;
   10959             :                 }
   10960             :         ;
   10961             : 
   10962             : /*****************************************************************************
   10963             :  *
   10964             :  *      QUERY:  Define Rewrite Rule
   10965             :  *
   10966             :  *****************************************************************************/
   10967             : 
   10968             : RuleStmt:   CREATE opt_or_replace RULE name AS
   10969             :             ON event TO qualified_name where_clause
   10970             :             DO opt_instead RuleActionList
   10971             :                 {
   10972        1166 :                     RuleStmt   *n = makeNode(RuleStmt);
   10973             : 
   10974        1166 :                     n->replace = $2;
   10975        1166 :                     n->relation = $9;
   10976        1166 :                     n->rulename = $4;
   10977        1166 :                     n->whereClause = $10;
   10978        1166 :                     n->event = $7;
   10979        1166 :                     n->instead = $12;
   10980        1166 :                     n->actions = $13;
   10981        1166 :                     $$ = (Node *) n;
   10982             :                 }
   10983             :         ;
   10984             : 
   10985             : RuleActionList:
   10986         166 :             NOTHING                                 { $$ = NIL; }
   10987         950 :             | RuleActionStmt                        { $$ = list_make1($1); }
   10988          50 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   10989             :         ;
   10990             : 
   10991             : /* the thrashing around here is to discard "empty" statements... */
   10992             : RuleActionMulti:
   10993             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   10994          70 :                 { if ($3 != NULL)
   10995          50 :                     $$ = lappend($1, $3);
   10996             :                   else
   10997          20 :                     $$ = $1;
   10998             :                 }
   10999             :             | RuleActionStmtOrEmpty
   11000          50 :                 { if ($1 != NULL)
   11001          50 :                     $$ = list_make1($1);
   11002             :                   else
   11003           0 :                     $$ = NIL;
   11004             :                 }
   11005             :         ;
   11006             : 
   11007             : RuleActionStmt:
   11008             :             SelectStmt
   11009             :             | InsertStmt
   11010             :             | UpdateStmt
   11011             :             | DeleteStmt
   11012             :             | NotifyStmt
   11013             :         ;
   11014             : 
   11015             : RuleActionStmtOrEmpty:
   11016         100 :             RuleActionStmt                          { $$ = $1; }
   11017          20 :             |   /*EMPTY*/                           { $$ = NULL; }
   11018             :         ;
   11019             : 
   11020          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11021         448 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11022         180 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11023         520 :             | INSERT                                { $$ = CMD_INSERT; }
   11024             :          ;
   11025             : 
   11026             : opt_instead:
   11027         798 :             INSTEAD                                 { $$ = true; }
   11028         156 :             | ALSO                                  { $$ = false; }
   11029         212 :             | /*EMPTY*/                             { $$ = false; }
   11030             :         ;
   11031             : 
   11032             : 
   11033             : /*****************************************************************************
   11034             :  *
   11035             :  *      QUERY:
   11036             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11037             :  *              as a query-level command
   11038             :  *
   11039             :  *****************************************************************************/
   11040             : 
   11041             : NotifyStmt: NOTIFY ColId notify_payload
   11042             :                 {
   11043         130 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11044             : 
   11045         130 :                     n->conditionname = $2;
   11046         130 :                     n->payload = $3;
   11047         130 :                     $$ = (Node *) n;
   11048             :                 }
   11049             :         ;
   11050             : 
   11051             : notify_payload:
   11052          62 :             ',' Sconst                          { $$ = $2; }
   11053          68 :             | /*EMPTY*/                         { $$ = NULL; }
   11054             :         ;
   11055             : 
   11056             : ListenStmt: LISTEN ColId
   11057             :                 {
   11058          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11059             : 
   11060          74 :                     n->conditionname = $2;
   11061          74 :                     $$ = (Node *) n;
   11062             :                 }
   11063             :         ;
   11064             : 
   11065             : UnlistenStmt:
   11066             :             UNLISTEN ColId
   11067             :                 {
   11068           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11069             : 
   11070           6 :                     n->conditionname = $2;
   11071           6 :                     $$ = (Node *) n;
   11072             :                 }
   11073             :             | UNLISTEN '*'
   11074             :                 {
   11075          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11076             : 
   11077          32 :                     n->conditionname = NULL;
   11078          32 :                     $$ = (Node *) n;
   11079             :                 }
   11080             :         ;
   11081             : 
   11082             : 
   11083             : /*****************************************************************************
   11084             :  *
   11085             :  *      Transactions:
   11086             :  *
   11087             :  *      BEGIN / COMMIT / ROLLBACK
   11088             :  *      (also older versions END / ABORT)
   11089             :  *
   11090             :  *****************************************************************************/
   11091             : 
   11092             : TransactionStmt:
   11093             :             ABORT_P opt_transaction opt_transaction_chain
   11094             :                 {
   11095         216 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11096             : 
   11097         216 :                     n->kind = TRANS_STMT_ROLLBACK;
   11098         216 :                     n->options = NIL;
   11099         216 :                     n->chain = $3;
   11100         216 :                     n->location = -1;
   11101         216 :                     $$ = (Node *) n;
   11102             :                 }
   11103             :             | START TRANSACTION transaction_mode_list_or_empty
   11104             :                 {
   11105        1604 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11106             : 
   11107        1604 :                     n->kind = TRANS_STMT_START;
   11108        1604 :                     n->options = $3;
   11109        1604 :                     n->location = -1;
   11110        1604 :                     $$ = (Node *) n;
   11111             :                 }
   11112             :             | COMMIT opt_transaction opt_transaction_chain
   11113             :                 {
   11114       13050 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11115             : 
   11116       13050 :                     n->kind = TRANS_STMT_COMMIT;
   11117       13050 :                     n->options = NIL;
   11118       13050 :                     n->chain = $3;
   11119       13050 :                     n->location = -1;
   11120       13050 :                     $$ = (Node *) n;
   11121             :                 }
   11122             :             | ROLLBACK opt_transaction opt_transaction_chain
   11123             :                 {
   11124        2630 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11125             : 
   11126        2630 :                     n->kind = TRANS_STMT_ROLLBACK;
   11127        2630 :                     n->options = NIL;
   11128        2630 :                     n->chain = $3;
   11129        2630 :                     n->location = -1;
   11130        2630 :                     $$ = (Node *) n;
   11131             :                 }
   11132             :             | SAVEPOINT ColId
   11133             :                 {
   11134        1972 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11135             : 
   11136        1972 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11137        1972 :                     n->savepoint_name = $2;
   11138        1972 :                     n->location = @2;
   11139        1972 :                     $$ = (Node *) n;
   11140             :                 }
   11141             :             | RELEASE SAVEPOINT ColId
   11142             :                 {
   11143         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11144             : 
   11145         208 :                     n->kind = TRANS_STMT_RELEASE;
   11146         208 :                     n->savepoint_name = $3;
   11147         208 :                     n->location = @3;
   11148         208 :                     $$ = (Node *) n;
   11149             :                 }
   11150             :             | RELEASE ColId
   11151             :                 {
   11152          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11153             : 
   11154          86 :                     n->kind = TRANS_STMT_RELEASE;
   11155          86 :                     n->savepoint_name = $2;
   11156          86 :                     n->location = @2;
   11157          86 :                     $$ = (Node *) n;
   11158             :                 }
   11159             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11160             :                 {
   11161         228 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11162             : 
   11163         228 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11164         228 :                     n->savepoint_name = $5;
   11165         228 :                     n->location = @5;
   11166         228 :                     $$ = (Node *) n;
   11167             :                 }
   11168             :             | ROLLBACK opt_transaction TO ColId
   11169             :                 {
   11170         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11171             : 
   11172         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11173         496 :                     n->savepoint_name = $4;
   11174         496 :                     n->location = @4;
   11175         496 :                     $$ = (Node *) n;
   11176             :                 }
   11177             :             | PREPARE TRANSACTION Sconst
   11178             :                 {
   11179         634 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11180             : 
   11181         634 :                     n->kind = TRANS_STMT_PREPARE;
   11182         634 :                     n->gid = $3;
   11183         634 :                     n->location = @3;
   11184         634 :                     $$ = (Node *) n;
   11185             :                 }
   11186             :             | COMMIT PREPARED Sconst
   11187             :                 {
   11188         476 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11189             : 
   11190         476 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11191         476 :                     n->gid = $3;
   11192         476 :                     n->location = @3;
   11193         476 :                     $$ = (Node *) n;
   11194             :                 }
   11195             :             | ROLLBACK PREPARED Sconst
   11196             :                 {
   11197          76 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11198             : 
   11199          76 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11200          76 :                     n->gid = $3;
   11201          76 :                     n->location = @3;
   11202          76 :                     $$ = (Node *) n;
   11203             :                 }
   11204             :         ;
   11205             : 
   11206             : TransactionStmtLegacy:
   11207             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11208             :                 {
   11209       15744 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11210             : 
   11211       15744 :                     n->kind = TRANS_STMT_BEGIN;
   11212       15744 :                     n->options = $3;
   11213       15744 :                     n->location = -1;
   11214       15744 :                     $$ = (Node *) n;
   11215             :                 }
   11216             :             | END_P opt_transaction opt_transaction_chain
   11217             :                 {
   11218         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11219             : 
   11220         360 :                     n->kind = TRANS_STMT_COMMIT;
   11221         360 :                     n->options = NIL;
   11222         360 :                     n->chain = $3;
   11223         360 :                     n->location = -1;
   11224         360 :                     $$ = (Node *) n;
   11225             :                 }
   11226             :         ;
   11227             : 
   11228             : opt_transaction:    WORK
   11229             :             | TRANSACTION
   11230             :             | /*EMPTY*/
   11231             :         ;
   11232             : 
   11233             : transaction_mode_item:
   11234             :             ISOLATION LEVEL iso_level
   11235        6776 :                     { $$ = makeDefElem("transaction_isolation",
   11236        6776 :                                        makeStringConst($3, @3), @1); }
   11237             :             | READ ONLY
   11238        1508 :                     { $$ = makeDefElem("transaction_read_only",
   11239        1508 :                                        makeIntConst(true, @1), @1); }
   11240             :             | READ WRITE
   11241          90 :                     { $$ = makeDefElem("transaction_read_only",
   11242          90 :                                        makeIntConst(false, @1), @1); }
   11243             :             | DEFERRABLE
   11244          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11245             :                                        makeIntConst(true, @1), @1); }
   11246             :             | NOT DEFERRABLE
   11247          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11248          10 :                                        makeIntConst(false, @1), @1); }
   11249             :         ;
   11250             : 
   11251             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11252             : transaction_mode_list:
   11253             :             transaction_mode_item
   11254        6992 :                     { $$ = list_make1($1); }
   11255             :             | transaction_mode_list ',' transaction_mode_item
   11256        1042 :                     { $$ = lappend($1, $3); }
   11257             :             | transaction_mode_list transaction_mode_item
   11258         394 :                     { $$ = lappend($1, $2); }
   11259             :         ;
   11260             : 
   11261             : transaction_mode_list_or_empty:
   11262             :             transaction_mode_list
   11263             :             | /* EMPTY */
   11264       11058 :                     { $$ = NIL; }
   11265             :         ;
   11266             : 
   11267             : opt_transaction_chain:
   11268         120 :             AND CHAIN       { $$ = true; }
   11269           2 :             | AND NO CHAIN  { $$ = false; }
   11270       16134 :             | /* EMPTY */   { $$ = false; }
   11271             :         ;
   11272             : 
   11273             : 
   11274             : /*****************************************************************************
   11275             :  *
   11276             :  *  QUERY:
   11277             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11278             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11279             :  *
   11280             :  *****************************************************************************/
   11281             : 
   11282             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11283             :                 AS SelectStmt opt_check_option
   11284             :                 {
   11285       16388 :                     ViewStmt   *n = makeNode(ViewStmt);
   11286             : 
   11287       16388 :                     n->view = $4;
   11288       16388 :                     n->view->relpersistence = $2;
   11289       16388 :                     n->aliases = $5;
   11290       16388 :                     n->query = $8;
   11291       16388 :                     n->replace = false;
   11292       16388 :                     n->options = $6;
   11293       16388 :                     n->withCheckOption = $9;
   11294       16388 :                     $$ = (Node *) n;
   11295             :                 }
   11296             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11297             :                 AS SelectStmt opt_check_option
   11298             :                 {
   11299         248 :                     ViewStmt   *n = makeNode(ViewStmt);
   11300             : 
   11301         248 :                     n->view = $6;
   11302         248 :                     n->view->relpersistence = $4;
   11303         248 :                     n->aliases = $7;
   11304         248 :                     n->query = $10;
   11305         248 :                     n->replace = true;
   11306         248 :                     n->options = $8;
   11307         248 :                     n->withCheckOption = $11;
   11308         248 :                     $$ = (Node *) n;
   11309             :                 }
   11310             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11311             :                 AS SelectStmt opt_check_option
   11312             :                 {
   11313           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11314             : 
   11315           8 :                     n->view = $5;
   11316           8 :                     n->view->relpersistence = $2;
   11317           8 :                     n->aliases = $7;
   11318           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11319           8 :                     n->replace = false;
   11320           8 :                     n->options = $9;
   11321           8 :                     n->withCheckOption = $12;
   11322           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11323           0 :                         ereport(ERROR,
   11324             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11325             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11326             :                                  parser_errposition(@12)));
   11327           8 :                     $$ = (Node *) n;
   11328             :                 }
   11329             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11330             :                 AS SelectStmt opt_check_option
   11331             :                 {
   11332           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11333             : 
   11334           6 :                     n->view = $7;
   11335           6 :                     n->view->relpersistence = $4;
   11336           6 :                     n->aliases = $9;
   11337           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11338           6 :                     n->replace = true;
   11339           6 :                     n->options = $11;
   11340           6 :                     n->withCheckOption = $14;
   11341           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11342           0 :                         ereport(ERROR,
   11343             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11344             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11345             :                                  parser_errposition(@14)));
   11346           6 :                     $$ = (Node *) n;
   11347             :                 }
   11348             :         ;
   11349             : 
   11350             : opt_check_option:
   11351          96 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11352           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11353          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11354       16524 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11355             :         ;
   11356             : 
   11357             : /*****************************************************************************
   11358             :  *
   11359             :  *      QUERY:
   11360             :  *              LOAD "filename"
   11361             :  *
   11362             :  *****************************************************************************/
   11363             : 
   11364             : LoadStmt:   LOAD file_name
   11365             :                 {
   11366          52 :                     LoadStmt   *n = makeNode(LoadStmt);
   11367             : 
   11368          52 :                     n->filename = $2;
   11369          52 :                     $$ = (Node *) n;
   11370             :                 }
   11371             :         ;
   11372             : 
   11373             : 
   11374             : /*****************************************************************************
   11375             :  *
   11376             :  *      CREATE DATABASE
   11377             :  *
   11378             :  *****************************************************************************/
   11379             : 
   11380             : CreatedbStmt:
   11381             :             CREATE DATABASE name opt_with createdb_opt_list
   11382             :                 {
   11383         780 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11384             : 
   11385         780 :                     n->dbname = $3;
   11386         780 :                     n->options = $5;
   11387         780 :                     $$ = (Node *) n;
   11388             :                 }
   11389             :         ;
   11390             : 
   11391             : createdb_opt_list:
   11392         624 :             createdb_opt_items                      { $$ = $1; }
   11393         216 :             | /* EMPTY */                           { $$ = NIL; }
   11394             :         ;
   11395             : 
   11396             : createdb_opt_items:
   11397         624 :             createdb_opt_item                       { $$ = list_make1($1); }
   11398         934 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11399             :         ;
   11400             : 
   11401             : createdb_opt_item:
   11402             :             createdb_opt_name opt_equal NumericOnly
   11403             :                 {
   11404         254 :                     $$ = makeDefElem($1, $3, @1);
   11405             :                 }
   11406             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11407             :                 {
   11408        1304 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11409             :                 }
   11410             :             | createdb_opt_name opt_equal DEFAULT
   11411             :                 {
   11412           0 :                     $$ = makeDefElem($1, NULL, @1);
   11413             :                 }
   11414             :         ;
   11415             : 
   11416             : /*
   11417             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11418             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11419             :  * we need, and allow IDENT so that database option names don't have to be
   11420             :  * parser keywords unless they are already keywords for other reasons.
   11421             :  *
   11422             :  * XXX this coding technique is fragile since if someone makes a formerly
   11423             :  * non-keyword option name into a keyword and forgets to add it here, the
   11424             :  * option will silently break.  Best defense is to provide a regression test
   11425             :  * exercising every such option, at least at the syntax level.
   11426             :  */
   11427             : createdb_opt_name:
   11428        1098 :             IDENT                           { $$ = $1; }
   11429           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11430          98 :             | ENCODING                      { $$ = pstrdup($1); }
   11431           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11432           2 :             | OWNER                         { $$ = pstrdup($1); }
   11433          16 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11434         342 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11435             :         ;
   11436             : 
   11437             : /*
   11438             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11439             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11440             :  */
   11441             : opt_equal:  '='
   11442             :             | /*EMPTY*/
   11443             :         ;
   11444             : 
   11445             : 
   11446             : /*****************************************************************************
   11447             :  *
   11448             :  *      ALTER DATABASE
   11449             :  *
   11450             :  *****************************************************************************/
   11451             : 
   11452             : AlterDatabaseStmt:
   11453             :             ALTER DATABASE name WITH createdb_opt_list
   11454             :                  {
   11455           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11456             : 
   11457           0 :                     n->dbname = $3;
   11458           0 :                     n->options = $5;
   11459           0 :                     $$ = (Node *) n;
   11460             :                  }
   11461             :             | ALTER DATABASE name createdb_opt_list
   11462             :                  {
   11463          60 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11464             : 
   11465          60 :                     n->dbname = $3;
   11466          60 :                     n->options = $4;
   11467          60 :                     $$ = (Node *) n;
   11468             :                  }
   11469             :             | ALTER DATABASE name SET TABLESPACE name
   11470             :                  {
   11471          16 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11472             : 
   11473          16 :                     n->dbname = $3;
   11474          16 :                     n->options = list_make1(makeDefElem("tablespace",
   11475             :                                                         (Node *) makeString($6), @6));
   11476          16 :                     $$ = (Node *) n;
   11477             :                  }
   11478             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11479             :                  {
   11480           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11481             : 
   11482           6 :                     n->dbname = $3;
   11483           6 :                     $$ = (Node *) n;
   11484             :                  }
   11485             :         ;
   11486             : 
   11487             : AlterDatabaseSetStmt:
   11488             :             ALTER DATABASE name SetResetClause
   11489             :                 {
   11490        1186 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11491             : 
   11492        1186 :                     n->dbname = $3;
   11493        1186 :                     n->setstmt = $4;
   11494        1186 :                     $$ = (Node *) n;
   11495             :                 }
   11496             :         ;
   11497             : 
   11498             : 
   11499             : /*****************************************************************************
   11500             :  *
   11501             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11502             :  *
   11503             :  * This is implicitly CASCADE, no need for drop behavior
   11504             :  *****************************************************************************/
   11505             : 
   11506             : DropdbStmt: DROP DATABASE name
   11507             :                 {
   11508          92 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11509             : 
   11510          92 :                     n->dbname = $3;
   11511          92 :                     n->missing_ok = false;
   11512          92 :                     n->options = NULL;
   11513          92 :                     $$ = (Node *) n;
   11514             :                 }
   11515             :             | DROP DATABASE IF_P EXISTS name
   11516             :                 {
   11517           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11518             : 
   11519           4 :                     n->dbname = $5;
   11520           4 :                     n->missing_ok = true;
   11521           4 :                     n->options = NULL;
   11522           4 :                     $$ = (Node *) n;
   11523             :                 }
   11524             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11525             :                 {
   11526          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11527             : 
   11528          14 :                     n->dbname = $3;
   11529          14 :                     n->missing_ok = false;
   11530          14 :                     n->options = $6;
   11531          14 :                     $$ = (Node *) n;
   11532             :                 }
   11533             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11534             :                 {
   11535          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11536             : 
   11537          12 :                     n->dbname = $5;
   11538          12 :                     n->missing_ok = true;
   11539          12 :                     n->options = $8;
   11540          12 :                     $$ = (Node *) n;
   11541             :                 }
   11542             :         ;
   11543             : 
   11544             : drop_option_list:
   11545             :             drop_option
   11546             :                 {
   11547          26 :                     $$ = list_make1((Node *) $1);
   11548             :                 }
   11549             :             | drop_option_list ',' drop_option
   11550             :                 {
   11551           0 :                     $$ = lappend($1, (Node *) $3);
   11552             :                 }
   11553             :         ;
   11554             : 
   11555             : /*
   11556             :  * Currently only the FORCE option is supported, but the syntax is designed
   11557             :  * to be extensible so that we can add more options in the future if required.
   11558             :  */
   11559             : drop_option:
   11560             :             FORCE
   11561             :                 {
   11562          26 :                     $$ = makeDefElem("force", NULL, @1);
   11563             :                 }
   11564             :         ;
   11565             : 
   11566             : /*****************************************************************************
   11567             :  *
   11568             :  *      ALTER COLLATION
   11569             :  *
   11570             :  *****************************************************************************/
   11571             : 
   11572             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11573             :                 {
   11574           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11575             : 
   11576           6 :                     n->collname = $3;
   11577           6 :                     $$ = (Node *) n;
   11578             :                 }
   11579             :         ;
   11580             : 
   11581             : 
   11582             : /*****************************************************************************
   11583             :  *
   11584             :  *      ALTER SYSTEM
   11585             :  *
   11586             :  * This is used to change configuration parameters persistently.
   11587             :  *****************************************************************************/
   11588             : 
   11589             : AlterSystemStmt:
   11590             :             ALTER SYSTEM_P SET generic_set
   11591             :                 {
   11592         128 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11593             : 
   11594         128 :                     n->setstmt = $4;
   11595         128 :                     $$ = (Node *) n;
   11596             :                 }
   11597             :             | ALTER SYSTEM_P RESET generic_reset
   11598             :                 {
   11599          54 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11600             : 
   11601          54 :                     n->setstmt = $4;
   11602          54 :                     $$ = (Node *) n;
   11603             :                 }
   11604             :         ;
   11605             : 
   11606             : 
   11607             : /*****************************************************************************
   11608             :  *
   11609             :  * Manipulate a domain
   11610             :  *
   11611             :  *****************************************************************************/
   11612             : 
   11613             : CreateDomainStmt:
   11614             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11615             :                 {
   11616        1474 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11617             : 
   11618        1474 :                     n->domainname = $3;
   11619        1474 :                     n->typeName = $5;
   11620        1474 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11621             :                                      yyscanner);
   11622        1474 :                     $$ = (Node *) n;
   11623             :                 }
   11624             :         ;
   11625             : 
   11626             : AlterDomainStmt:
   11627             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11628             :             ALTER DOMAIN_P any_name alter_column_default
   11629             :                 {
   11630          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11631             : 
   11632          14 :                     n->subtype = 'T';
   11633          14 :                     n->typeName = $3;
   11634          14 :                     n->def = $4;
   11635          14 :                     $$ = (Node *) n;
   11636             :                 }
   11637             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11638             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11639             :                 {
   11640          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11641             : 
   11642          12 :                     n->subtype = 'N';
   11643          12 :                     n->typeName = $3;
   11644          12 :                     $$ = (Node *) n;
   11645             :                 }
   11646             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11647             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11648             :                 {
   11649          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11650             : 
   11651          24 :                     n->subtype = 'O';
   11652          24 :                     n->typeName = $3;
   11653          24 :                     $$ = (Node *) n;
   11654             :                 }
   11655             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11656             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11657             :                 {
   11658         174 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11659             : 
   11660         174 :                     n->subtype = 'C';
   11661         174 :                     n->typeName = $3;
   11662         174 :                     n->def = $5;
   11663         174 :                     $$ = (Node *) n;
   11664             :                 }
   11665             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11666             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11667             :                 {
   11668          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11669             : 
   11670          54 :                     n->subtype = 'X';
   11671          54 :                     n->typeName = $3;
   11672          54 :                     n->name = $6;
   11673          54 :                     n->behavior = $7;
   11674          54 :                     n->missing_ok = false;
   11675          54 :                     $$ = (Node *) n;
   11676             :                 }
   11677             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11678             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11679             :                 {
   11680           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11681             : 
   11682           6 :                     n->subtype = 'X';
   11683           6 :                     n->typeName = $3;
   11684           6 :                     n->name = $8;
   11685           6 :                     n->behavior = $9;
   11686           6 :                     n->missing_ok = true;
   11687           6 :                     $$ = (Node *) n;
   11688             :                 }
   11689             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11690             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11691             :                 {
   11692          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11693             : 
   11694          12 :                     n->subtype = 'V';
   11695          12 :                     n->typeName = $3;
   11696          12 :                     n->name = $6;
   11697          12 :                     $$ = (Node *) n;
   11698             :                 }
   11699             :             ;
   11700             : 
   11701             : opt_as:     AS
   11702             :             | /* EMPTY */
   11703             :         ;
   11704             : 
   11705             : 
   11706             : /*****************************************************************************
   11707             :  *
   11708             :  * Manipulate a text search dictionary or configuration
   11709             :  *
   11710             :  *****************************************************************************/
   11711             : 
   11712             : AlterTSDictionaryStmt:
   11713             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11714             :                 {
   11715          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11716             : 
   11717          40 :                     n->dictname = $5;
   11718          40 :                     n->options = $6;
   11719          40 :                     $$ = (Node *) n;
   11720             :                 }
   11721             :         ;
   11722             : 
   11723             : AlterTSConfigurationStmt:
   11724             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11725             :                 {
   11726        8496 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11727             : 
   11728        8496 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11729        8496 :                     n->cfgname = $5;
   11730        8496 :                     n->tokentype = $9;
   11731        8496 :                     n->dicts = $11;
   11732        8496 :                     n->override = false;
   11733        8496 :                     n->replace = false;
   11734        8496 :                     $$ = (Node *) n;
   11735             :                 }
   11736             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11737             :                 {
   11738          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11739             : 
   11740          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11741          26 :                     n->cfgname = $5;
   11742          26 :                     n->tokentype = $9;
   11743          26 :                     n->dicts = $11;
   11744          26 :                     n->override = true;
   11745          26 :                     n->replace = false;
   11746          26 :                     $$ = (Node *) n;
   11747             :                 }
   11748             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11749             :                 {
   11750          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11751             : 
   11752          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11753          18 :                     n->cfgname = $5;
   11754          18 :                     n->tokentype = NIL;
   11755          18 :                     n->dicts = list_make2($9,$11);
   11756          18 :                     n->override = false;
   11757          18 :                     n->replace = true;
   11758          18 :                     $$ = (Node *) n;
   11759             :                 }
   11760             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11761             :                 {
   11762           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11763             : 
   11764           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11765           0 :                     n->cfgname = $5;
   11766           0 :                     n->tokentype = $9;
   11767           0 :                     n->dicts = list_make2($11,$13);
   11768           0 :                     n->override = false;
   11769           0 :                     n->replace = true;
   11770           0 :                     $$ = (Node *) n;
   11771             :                 }
   11772             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11773             :                 {
   11774          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11775             : 
   11776          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11777          18 :                     n->cfgname = $5;
   11778          18 :                     n->tokentype = $9;
   11779          18 :                     n->missing_ok = false;
   11780          18 :                     $$ = (Node *) n;
   11781             :                 }
   11782             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11783             :                 {
   11784          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11785             : 
   11786          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11787          12 :                     n->cfgname = $5;
   11788          12 :                     n->tokentype = $11;
   11789          12 :                     n->missing_ok = true;
   11790          12 :                     $$ = (Node *) n;
   11791             :                 }
   11792             :         ;
   11793             : 
   11794             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11795             : any_with:   WITH
   11796             :             | WITH_LA
   11797             :         ;
   11798             : 
   11799             : 
   11800             : /*****************************************************************************
   11801             :  *
   11802             :  * Manipulate a conversion
   11803             :  *
   11804             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11805             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11806             :  *
   11807             :  *****************************************************************************/
   11808             : 
   11809             : CreateConversionStmt:
   11810             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11811             :             TO Sconst FROM any_name
   11812             :             {
   11813          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11814             : 
   11815          64 :                 n->conversion_name = $4;
   11816          64 :                 n->for_encoding_name = $6;
   11817          64 :                 n->to_encoding_name = $8;
   11818          64 :                 n->func_name = $10;
   11819          64 :                 n->def = $2;
   11820          64 :                 $$ = (Node *) n;
   11821             :             }
   11822             :         ;
   11823             : 
   11824             : /*****************************************************************************
   11825             :  *
   11826             :  *      QUERY:
   11827             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11828             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11829             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11830             :  *
   11831             :  *****************************************************************************/
   11832             : 
   11833             : ClusterStmt:
   11834             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11835             :                 {
   11836           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11837             : 
   11838           0 :                     n->relation = $5;
   11839           0 :                     n->indexname = $6;
   11840           0 :                     n->params = $3;
   11841           0 :                     $$ = (Node *) n;
   11842             :                 }
   11843             :             | CLUSTER '(' utility_option_list ')'
   11844             :                 {
   11845           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11846             : 
   11847           0 :                     n->relation = NULL;
   11848           0 :                     n->indexname = NULL;
   11849           0 :                     n->params = $3;
   11850           0 :                     $$ = (Node *) n;
   11851             :                 }
   11852             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11853             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11854             :                 {
   11855         190 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11856             : 
   11857         190 :                     n->relation = $3;
   11858         190 :                     n->indexname = $4;
   11859         190 :                     n->params = NIL;
   11860         190 :                     if ($2)
   11861           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11862         190 :                     $$ = (Node *) n;
   11863             :                 }
   11864             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11865             :             | CLUSTER opt_verbose
   11866             :                 {
   11867          28 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11868             : 
   11869          28 :                     n->relation = NULL;
   11870          28 :                     n->indexname = NULL;
   11871          28 :                     n->params = NIL;
   11872          28 :                     if ($2)
   11873          12 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11874          28 :                     $$ = (Node *) n;
   11875             :                 }
   11876             :             /* kept for pre-8.3 compatibility */
   11877             :             | CLUSTER opt_verbose name ON qualified_name
   11878             :                 {
   11879          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11880             : 
   11881          18 :                     n->relation = $5;
   11882          18 :                     n->indexname = $3;
   11883          18 :                     n->params = NIL;
   11884          18 :                     if ($2)
   11885           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11886          18 :                     $$ = (Node *) n;
   11887             :                 }
   11888             :         ;
   11889             : 
   11890             : cluster_index_specification:
   11891         156 :             USING name              { $$ = $2; }
   11892          34 :             | /*EMPTY*/             { $$ = NULL; }
   11893             :         ;
   11894             : 
   11895             : 
   11896             : /*****************************************************************************
   11897             :  *
   11898             :  *      QUERY:
   11899             :  *              VACUUM
   11900             :  *              ANALYZE
   11901             :  *
   11902             :  *****************************************************************************/
   11903             : 
   11904             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11905             :                 {
   11906        1210 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11907             : 
   11908        1210 :                     n->options = NIL;
   11909        1210 :                     if ($2)
   11910         146 :                         n->options = lappend(n->options,
   11911         146 :                                              makeDefElem("full", NULL, @2));
   11912        1210 :                     if ($3)
   11913         160 :                         n->options = lappend(n->options,
   11914         160 :                                              makeDefElem("freeze", NULL, @3));
   11915        1210 :                     if ($4)
   11916          18 :                         n->options = lappend(n->options,
   11917          18 :                                              makeDefElem("verbose", NULL, @4));
   11918        1210 :                     if ($5)
   11919         286 :                         n->options = lappend(n->options,
   11920         286 :                                              makeDefElem("analyze", NULL, @5));
   11921        1210 :                     n->rels = $6;
   11922        1210 :                     n->is_vacuumcmd = true;
   11923        1210 :                     $$ = (Node *) n;
   11924             :                 }
   11925             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11926             :                 {
   11927        7782 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11928             : 
   11929        7782 :                     n->options = $3;
   11930        7782 :                     n->rels = $5;
   11931        7782 :                     n->is_vacuumcmd = true;
   11932        7782 :                     $$ = (Node *) n;
   11933             :                 }
   11934             :         ;
   11935             : 
   11936             : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   11937             :                 {
   11938        4488 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11939             : 
   11940        4488 :                     n->options = NIL;
   11941        4488 :                     if ($2)
   11942           0 :                         n->options = lappend(n->options,
   11943           0 :                                              makeDefElem("verbose", NULL, @2));
   11944        4488 :                     n->rels = $3;
   11945        4488 :                     n->is_vacuumcmd = false;
   11946        4488 :                     $$ = (Node *) n;
   11947             :                 }
   11948             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   11949             :                 {
   11950         186 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11951             : 
   11952         186 :                     n->options = $3;
   11953         186 :                     n->rels = $5;
   11954         186 :                     n->is_vacuumcmd = false;
   11955         186 :                     $$ = (Node *) n;
   11956             :                 }
   11957             :         ;
   11958             : 
   11959             : utility_option_list:
   11960             :             utility_option_elem
   11961             :                 {
   11962       21838 :                     $$ = list_make1($1);
   11963             :                 }
   11964             :             | utility_option_list ',' utility_option_elem
   11965             :                 {
   11966       12276 :                     $$ = lappend($1, $3);
   11967             :                 }
   11968             :         ;
   11969             : 
   11970             : analyze_keyword:
   11971             :             ANALYZE
   11972             :             | ANALYSE /* British */
   11973             :         ;
   11974             : 
   11975             : utility_option_elem:
   11976             :             utility_option_name utility_option_arg
   11977             :                 {
   11978       34114 :                     $$ = makeDefElem($1, $2, @1);
   11979             :                 }
   11980             :         ;
   11981             : 
   11982             : utility_option_name:
   11983       30370 :             NonReservedWord                         { $$ = $1; }
   11984        3602 :             | analyze_keyword                       { $$ = "analyze"; }
   11985         148 :             | FORMAT_LA                             { $$ = "format"; }
   11986             :         ;
   11987             : 
   11988             : utility_option_arg:
   11989       17184 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   11990         380 :             | NumericOnly                           { $$ = (Node *) $1; }
   11991       16550 :             | /* EMPTY */                           { $$ = NULL; }
   11992             :         ;
   11993             : 
   11994             : opt_analyze:
   11995         286 :             analyze_keyword                         { $$ = true; }
   11996         924 :             | /*EMPTY*/                             { $$ = false; }
   11997             :         ;
   11998             : 
   11999             : opt_verbose:
   12000          30 :             VERBOSE                                 { $$ = true; }
   12001        8208 :             | /*EMPTY*/                             { $$ = false; }
   12002             :         ;
   12003             : 
   12004         146 : opt_full:   FULL                                    { $$ = true; }
   12005        1064 :             | /*EMPTY*/                             { $$ = false; }
   12006             :         ;
   12007             : 
   12008         160 : opt_freeze: FREEZE                                  { $$ = true; }
   12009        1050 :             | /*EMPTY*/                             { $$ = false; }
   12010             :         ;
   12011             : 
   12012             : opt_name_list:
   12013        2804 :             '(' name_list ')'                       { $$ = $2; }
   12014       15900 :             | /*EMPTY*/                             { $$ = NIL; }
   12015             :         ;
   12016             : 
   12017             : vacuum_relation:
   12018             :             relation_expr opt_name_list
   12019             :                 {
   12020       13438 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12021             :                 }
   12022             :         ;
   12023             : 
   12024             : vacuum_relation_list:
   12025             :             vacuum_relation
   12026       13282 :                     { $$ = list_make1($1); }
   12027             :             | vacuum_relation_list ',' vacuum_relation
   12028         156 :                     { $$ = lappend($1, $3); }
   12029             :         ;
   12030             : 
   12031             : opt_vacuum_relation_list:
   12032       13282 :             vacuum_relation_list                    { $$ = $1; }
   12033         384 :             | /*EMPTY*/                             { $$ = NIL; }
   12034             :         ;
   12035             : 
   12036             : 
   12037             : /*****************************************************************************
   12038             :  *
   12039             :  *      QUERY:
   12040             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12041             :  *              EXPLAIN ( options ) query
   12042             :  *
   12043             :  *****************************************************************************/
   12044             : 
   12045             : ExplainStmt:
   12046             :         EXPLAIN ExplainableStmt
   12047             :                 {
   12048        7714 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12049             : 
   12050        7714 :                     n->query = $2;
   12051        7714 :                     n->options = NIL;
   12052        7714 :                     $$ = (Node *) n;
   12053             :                 }
   12054             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12055             :                 {
   12056        2304 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12057             : 
   12058        2304 :                     n->query = $4;
   12059        2304 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12060        2304 :                     if ($3)
   12061           0 :                         n->options = lappend(n->options,
   12062           0 :                                              makeDefElem("verbose", NULL, @3));
   12063        2304 :                     $$ = (Node *) n;
   12064             :                 }
   12065             :         | EXPLAIN VERBOSE ExplainableStmt
   12066             :                 {
   12067          12 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12068             : 
   12069          12 :                     n->query = $3;
   12070          12 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12071          12 :                     $$ = (Node *) n;
   12072             :                 }
   12073             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12074             :                 {
   12075       13714 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12076             : 
   12077       13714 :                     n->query = $5;
   12078       13714 :                     n->options = $3;
   12079       13714 :                     $$ = (Node *) n;
   12080             :                 }
   12081             :         ;
   12082             : 
   12083             : ExplainableStmt:
   12084             :             SelectStmt
   12085             :             | InsertStmt
   12086             :             | UpdateStmt
   12087             :             | DeleteStmt
   12088             :             | MergeStmt
   12089             :             | DeclareCursorStmt
   12090             :             | CreateAsStmt
   12091             :             | CreateMatViewStmt
   12092             :             | RefreshMatViewStmt
   12093             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12094             :         ;
   12095             : 
   12096             : /*****************************************************************************
   12097             :  *
   12098             :  *      QUERY:
   12099             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12100             :  *
   12101             :  *****************************************************************************/
   12102             : 
   12103             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12104             :                 {
   12105        2320 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12106             : 
   12107        2320 :                     n->name = $2;
   12108        2320 :                     n->argtypes = $3;
   12109        2320 :                     n->query = $5;
   12110        2320 :                     $$ = (Node *) n;
   12111             :                 }
   12112             :         ;
   12113             : 
   12114        2012 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12115         326 :                 | /* EMPTY */               { $$ = NIL; }
   12116             :         ;
   12117             : 
   12118             : PreparableStmt:
   12119             :             SelectStmt
   12120             :             | InsertStmt
   12121             :             | UpdateStmt
   12122             :             | DeleteStmt
   12123             :             | MergeStmt                     /* by default all are $$=$1 */
   12124             :         ;
   12125             : 
   12126             : /*****************************************************************************
   12127             :  *
   12128             :  * EXECUTE <plan_name> [(params, ...)]
   12129             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12130             :  *
   12131             :  *****************************************************************************/
   12132             : 
   12133             : ExecuteStmt: EXECUTE name execute_param_clause
   12134             :                 {
   12135       20222 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12136             : 
   12137       20222 :                     n->name = $2;
   12138       20222 :                     n->params = $3;
   12139       20222 :                     $$ = (Node *) n;
   12140             :                 }
   12141             :             | CREATE OptTemp TABLE create_as_target AS
   12142             :                 EXECUTE name execute_param_clause opt_with_data
   12143             :                 {
   12144          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12145          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12146             : 
   12147          76 :                     n->name = $7;
   12148          76 :                     n->params = $8;
   12149          76 :                     ctas->query = (Node *) n;
   12150          76 :                     ctas->into = $4;
   12151          76 :                     ctas->objtype = OBJECT_TABLE;
   12152          76 :                     ctas->is_select_into = false;
   12153          76 :                     ctas->if_not_exists = false;
   12154             :                     /* cram additional flags into the IntoClause */
   12155          76 :                     $4->rel->relpersistence = $2;
   12156          76 :                     $4->skipData = !($9);
   12157          76 :                     $$ = (Node *) ctas;
   12158             :                 }
   12159             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12160             :                 EXECUTE name execute_param_clause opt_with_data
   12161             :                 {
   12162          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12163          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12164             : 
   12165          12 :                     n->name = $10;
   12166          12 :                     n->params = $11;
   12167          12 :                     ctas->query = (Node *) n;
   12168          12 :                     ctas->into = $7;
   12169          12 :                     ctas->objtype = OBJECT_TABLE;
   12170          12 :                     ctas->is_select_into = false;
   12171          12 :                     ctas->if_not_exists = true;
   12172             :                     /* cram additional flags into the IntoClause */
   12173          12 :                     $7->rel->relpersistence = $2;
   12174          12 :                     $7->skipData = !($12);
   12175          12 :                     $$ = (Node *) ctas;
   12176             :                 }
   12177             :         ;
   12178             : 
   12179       19168 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12180        1142 :                     | /* EMPTY */                   { $$ = NIL; }
   12181             :                     ;
   12182             : 
   12183             : /*****************************************************************************
   12184             :  *
   12185             :  *      QUERY:
   12186             :  *              DEALLOCATE [PREPARE] <plan_name>
   12187             :  *
   12188             :  *****************************************************************************/
   12189             : 
   12190             : DeallocateStmt: DEALLOCATE name
   12191             :                     {
   12192        3984 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12193             : 
   12194        3984 :                         n->name = $2;
   12195        3984 :                         n->isall = false;
   12196        3984 :                         n->location = @2;
   12197        3984 :                         $$ = (Node *) n;
   12198             :                     }
   12199             :                 | DEALLOCATE PREPARE name
   12200             :                     {
   12201          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12202             : 
   12203          20 :                         n->name = $3;
   12204          20 :                         n->isall = false;
   12205          20 :                         n->location = @3;
   12206          20 :                         $$ = (Node *) n;
   12207             :                     }
   12208             :                 | DEALLOCATE ALL
   12209             :                     {
   12210          54 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12211             : 
   12212          54 :                         n->name = NULL;
   12213          54 :                         n->isall = true;
   12214          54 :                         n->location = -1;
   12215          54 :                         $$ = (Node *) n;
   12216             :                     }
   12217             :                 | DEALLOCATE PREPARE ALL
   12218             :                     {
   12219           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12220             : 
   12221           2 :                         n->name = NULL;
   12222           2 :                         n->isall = true;
   12223           2 :                         n->location = -1;
   12224           2 :                         $$ = (Node *) n;
   12225             :                     }
   12226             :         ;
   12227             : 
   12228             : /*****************************************************************************
   12229             :  *
   12230             :  *      QUERY:
   12231             :  *              INSERT STATEMENTS
   12232             :  *
   12233             :  *****************************************************************************/
   12234             : 
   12235             : InsertStmt:
   12236             :             opt_with_clause INSERT INTO insert_target insert_rest
   12237             :             opt_on_conflict returning_clause
   12238             :                 {
   12239       74178 :                     $5->relation = $4;
   12240       74178 :                     $5->onConflictClause = $6;
   12241       74178 :                     $5->returningClause = $7;
   12242       74178 :                     $5->withClause = $1;
   12243       74178 :                     $5->stmt_location = @$;
   12244       74178 :                     $$ = (Node *) $5;
   12245             :                 }
   12246             :         ;
   12247             : 
   12248             : /*
   12249             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12250             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12251             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12252             :  * divergence from other places.  So just require AS for now.
   12253             :  */
   12254             : insert_target:
   12255             :             qualified_name
   12256             :                 {
   12257       74046 :                     $$ = $1;
   12258             :                 }
   12259             :             | qualified_name AS ColId
   12260             :                 {
   12261         138 :                     $1->alias = makeAlias($3, NIL);
   12262         138 :                     $$ = $1;
   12263             :                 }
   12264             :         ;
   12265             : 
   12266             : insert_rest:
   12267             :             SelectStmt
   12268             :                 {
   12269       49050 :                     $$ = makeNode(InsertStmt);
   12270       49050 :                     $$->cols = NIL;
   12271       49050 :                     $$->selectStmt = $1;
   12272             :                 }
   12273             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12274             :                 {
   12275          96 :                     $$ = makeNode(InsertStmt);
   12276          96 :                     $$->cols = NIL;
   12277          96 :                     $$->override = $2;
   12278          96 :                     $$->selectStmt = $4;
   12279             :                 }
   12280             :             | '(' insert_column_list ')' SelectStmt
   12281             :                 {
   12282       14230 :                     $$ = makeNode(InsertStmt);
   12283       14230 :                     $$->cols = $2;
   12284       14230 :                     $$->selectStmt = $4;
   12285             :                 }
   12286             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12287             :                 {
   12288           0 :                     $$ = makeNode(InsertStmt);
   12289           0 :                     $$->cols = $2;
   12290           0 :                     $$->override = $5;
   12291           0 :                     $$->selectStmt = $7;
   12292             :                 }
   12293             :             | DEFAULT VALUES
   12294             :                 {
   12295       10808 :                     $$ = makeNode(InsertStmt);
   12296       10808 :                     $$->cols = NIL;
   12297       10808 :                     $$->selectStmt = NULL;
   12298             :                 }
   12299             :         ;
   12300             : 
   12301             : override_kind:
   12302          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12303          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12304             :         ;
   12305             : 
   12306             : insert_column_list:
   12307             :             insert_column_item
   12308       14528 :                     { $$ = list_make1($1); }
   12309             :             | insert_column_list ',' insert_column_item
   12310       16032 :                     { $$ = lappend($1, $3); }
   12311             :         ;
   12312             : 
   12313             : insert_column_item:
   12314             :             ColId opt_indirection
   12315             :                 {
   12316       30560 :                     $$ = makeNode(ResTarget);
   12317       30560 :                     $$->name = $1;
   12318       30560 :                     $$->indirection = check_indirection($2, yyscanner);
   12319       30560 :                     $$->val = NULL;
   12320       30560 :                     $$->location = @1;
   12321             :                 }
   12322             :         ;
   12323             : 
   12324             : opt_on_conflict:
   12325             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12326             :                 {
   12327        1306 :                     $$ = makeNode(OnConflictClause);
   12328        1306 :                     $$->action = ONCONFLICT_UPDATE;
   12329        1306 :                     $$->infer = $3;
   12330        1306 :                     $$->targetList = $7;
   12331        1306 :                     $$->whereClause = $8;
   12332        1306 :                     $$->location = @1;
   12333             :                 }
   12334             :             |
   12335             :             ON CONFLICT opt_conf_expr DO NOTHING
   12336             :                 {
   12337         550 :                     $$ = makeNode(OnConflictClause);
   12338         550 :                     $$->action = ONCONFLICT_NOTHING;
   12339         550 :                     $$->infer = $3;
   12340         550 :                     $$->targetList = NIL;
   12341         550 :                     $$->whereClause = NULL;
   12342         550 :                     $$->location = @1;
   12343             :                 }
   12344             :             | /*EMPTY*/
   12345             :                 {
   12346       72328 :                     $$ = NULL;
   12347             :                 }
   12348             :         ;
   12349             : 
   12350             : opt_conf_expr:
   12351             :             '(' index_params ')' where_clause
   12352             :                 {
   12353        1430 :                     $$ = makeNode(InferClause);
   12354        1430 :                     $$->indexElems = $2;
   12355        1430 :                     $$->whereClause = $4;
   12356        1430 :                     $$->conname = NULL;
   12357        1430 :                     $$->location = @1;
   12358             :                 }
   12359             :             |
   12360             :             ON CONSTRAINT name
   12361             :                 {
   12362         192 :                     $$ = makeNode(InferClause);
   12363         192 :                     $$->indexElems = NIL;
   12364         192 :                     $$->whereClause = NULL;
   12365         192 :                     $$->conname = $3;
   12366         192 :                     $$->location = @1;
   12367             :                 }
   12368             :             | /*EMPTY*/
   12369             :                 {
   12370         234 :                     $$ = NULL;
   12371             :                 }
   12372             :         ;
   12373             : 
   12374             : returning_clause:
   12375             :             RETURNING returning_with_clause target_list
   12376             :                 {
   12377        3138 :                     ReturningClause *n = makeNode(ReturningClause);
   12378             : 
   12379        3138 :                     n->options = $2;
   12380        3138 :                     n->exprs = $3;
   12381        3138 :                     $$ = n;
   12382             :                 }
   12383             :             | /* EMPTY */
   12384             :                 {
   12385       91698 :                     $$ = NULL;
   12386             :                 }
   12387             :         ;
   12388             : 
   12389             : returning_with_clause:
   12390          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12391        3066 :             | /* EMPTY */                       { $$ = NIL; }
   12392             :         ;
   12393             : 
   12394             : returning_options:
   12395          72 :             returning_option                            { $$ = list_make1($1); }
   12396          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12397             :         ;
   12398             : 
   12399             : returning_option:
   12400             :             returning_option_kind AS ColId
   12401             :                 {
   12402         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12403             : 
   12404         126 :                     n->option = $1;
   12405         126 :                     n->value = $3;
   12406         126 :                     n->location = @1;
   12407         126 :                     $$ = (Node *) n;
   12408             :                 }
   12409             :         ;
   12410             : 
   12411             : returning_option_kind:
   12412          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12413          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12414             :         ;
   12415             : 
   12416             : 
   12417             : /*****************************************************************************
   12418             :  *
   12419             :  *      QUERY:
   12420             :  *              DELETE STATEMENTS
   12421             :  *
   12422             :  *****************************************************************************/
   12423             : 
   12424             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12425             :             using_clause where_or_current_clause returning_clause
   12426             :                 {
   12427        4608 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12428             : 
   12429        4608 :                     n->relation = $4;
   12430        4608 :                     n->usingClause = $5;
   12431        4608 :                     n->whereClause = $6;
   12432        4608 :                     n->returningClause = $7;
   12433        4608 :                     n->withClause = $1;
   12434        4608 :                     n->stmt_location = @$;
   12435        4608 :                     $$ = (Node *) n;
   12436             :                 }
   12437             :         ;
   12438             : 
   12439             : using_clause:
   12440         108 :                 USING from_list                     { $$ = $2; }
   12441        4500 :             | /*EMPTY*/                             { $$ = NIL; }
   12442             :         ;
   12443             : 
   12444             : 
   12445             : /*****************************************************************************
   12446             :  *
   12447             :  *      QUERY:
   12448             :  *              LOCK TABLE
   12449             :  *
   12450             :  *****************************************************************************/
   12451             : 
   12452             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12453             :                 {
   12454        2478 :                     LockStmt   *n = makeNode(LockStmt);
   12455             : 
   12456        2478 :                     n->relations = $3;
   12457        2478 :                     n->mode = $4;
   12458        2478 :                     n->nowait = $5;
   12459        2478 :                     $$ = (Node *) n;
   12460             :                 }
   12461             :         ;
   12462             : 
   12463        2370 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12464         108 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12465             :         ;
   12466             : 
   12467        1880 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12468          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12469          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12470          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12471          80 :             | SHARE                         { $$ = ShareLock; }
   12472          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12473         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12474         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12475             :         ;
   12476             : 
   12477        1546 : opt_nowait: NOWAIT                          { $$ = true; }
   12478         962 :             | /*EMPTY*/                     { $$ = false; }
   12479             :         ;
   12480             : 
   12481             : opt_nowait_or_skip:
   12482          50 :             NOWAIT                          { $$ = LockWaitError; }
   12483         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12484        4872 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12485             :         ;
   12486             : 
   12487             : 
   12488             : /*****************************************************************************
   12489             :  *
   12490             :  *      QUERY:
   12491             :  *              UpdateStmt (UPDATE)
   12492             :  *
   12493             :  *****************************************************************************/
   12494             : 
   12495             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12496             :             SET set_clause_list
   12497             :             from_clause
   12498             :             where_or_current_clause
   12499             :             returning_clause
   12500             :                 {
   12501       13998 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12502             : 
   12503       13998 :                     n->relation = $3;
   12504       13998 :                     n->targetList = $5;
   12505       13998 :                     n->fromClause = $6;
   12506       13998 :                     n->whereClause = $7;
   12507       13998 :                     n->returningClause = $8;
   12508       13998 :                     n->withClause = $1;
   12509       13998 :                     n->stmt_location = @$;
   12510       13998 :                     $$ = (Node *) n;
   12511             :                 }
   12512             :         ;
   12513             : 
   12514             : set_clause_list:
   12515       16854 :             set_clause                          { $$ = $1; }
   12516        4098 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12517             :         ;
   12518             : 
   12519             : set_clause:
   12520             :             set_target '=' a_expr
   12521             :                 {
   12522       20768 :                     $1->val = (Node *) $3;
   12523       20768 :                     $$ = list_make1($1);
   12524             :                 }
   12525             :             | '(' set_target_list ')' '=' a_expr
   12526             :                 {
   12527         184 :                     int         ncolumns = list_length($2);
   12528         184 :                     int         i = 1;
   12529             :                     ListCell   *col_cell;
   12530             : 
   12531             :                     /* Create a MultiAssignRef source for each target */
   12532         568 :                     foreach(col_cell, $2)
   12533             :                     {
   12534         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12535         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12536             : 
   12537         384 :                         r->source = (Node *) $5;
   12538         384 :                         r->colno = i;
   12539         384 :                         r->ncolumns = ncolumns;
   12540         384 :                         res_col->val = (Node *) r;
   12541         384 :                         i++;
   12542             :                     }
   12543             : 
   12544         184 :                     $$ = $2;
   12545             :                 }
   12546             :         ;
   12547             : 
   12548             : set_target:
   12549             :             ColId opt_indirection
   12550             :                 {
   12551       21158 :                     $$ = makeNode(ResTarget);
   12552       21158 :                     $$->name = $1;
   12553       21158 :                     $$->indirection = check_indirection($2, yyscanner);
   12554       21158 :                     $$->val = NULL;  /* upper production sets this */
   12555       21158 :                     $$->location = @1;
   12556             :                 }
   12557             :         ;
   12558             : 
   12559             : set_target_list:
   12560         190 :             set_target                              { $$ = list_make1($1); }
   12561         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12562             :         ;
   12563             : 
   12564             : 
   12565             : /*****************************************************************************
   12566             :  *
   12567             :  *      QUERY:
   12568             :  *              MERGE
   12569             :  *
   12570             :  *****************************************************************************/
   12571             : 
   12572             : MergeStmt:
   12573             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12574             :             USING table_ref
   12575             :             ON a_expr
   12576             :             merge_when_list
   12577             :             returning_clause
   12578             :                 {
   12579        2052 :                     MergeStmt  *m = makeNode(MergeStmt);
   12580             : 
   12581        2052 :                     m->withClause = $1;
   12582        2052 :                     m->relation = $4;
   12583        2052 :                     m->sourceRelation = $6;
   12584        2052 :                     m->joinCondition = $8;
   12585        2052 :                     m->mergeWhenClauses = $9;
   12586        2052 :                     m->returningClause = $10;
   12587        2052 :                     m->stmt_location = @$;
   12588             : 
   12589        2052 :                     $$ = (Node *) m;
   12590             :                 }
   12591             :         ;
   12592             : 
   12593             : merge_when_list:
   12594        2052 :             merge_when_clause                       { $$ = list_make1($1); }
   12595        1164 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12596             :         ;
   12597             : 
   12598             : /*
   12599             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12600             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12601             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12602             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12603             :  */
   12604             : merge_when_clause:
   12605             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12606             :                 {
   12607        1550 :                     $4->matchKind = $1;
   12608        1550 :                     $4->condition = $2;
   12609             : 
   12610        1550 :                     $$ = (Node *) $4;
   12611             :                 }
   12612             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12613             :                 {
   12614         518 :                     $4->matchKind = $1;
   12615         518 :                     $4->condition = $2;
   12616             : 
   12617         518 :                     $$ = (Node *) $4;
   12618             :                 }
   12619             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12620             :                 {
   12621        1064 :                     $4->matchKind = $1;
   12622        1064 :                     $4->condition = $2;
   12623             : 
   12624        1064 :                     $$ = (Node *) $4;
   12625             :                 }
   12626             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12627             :                 {
   12628          64 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12629             : 
   12630          64 :                     m->matchKind = $1;
   12631          64 :                     m->commandType = CMD_NOTHING;
   12632          64 :                     m->condition = $2;
   12633             : 
   12634          64 :                     $$ = (Node *) m;
   12635             :                 }
   12636             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12637             :                 {
   12638          20 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12639             : 
   12640          20 :                     m->matchKind = $1;
   12641          20 :                     m->commandType = CMD_NOTHING;
   12642          20 :                     m->condition = $2;
   12643             : 
   12644          20 :                     $$ = (Node *) m;
   12645             :                 }
   12646             :         ;
   12647             : 
   12648             : merge_when_tgt_matched:
   12649        1970 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12650         180 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12651             :         ;
   12652             : 
   12653             : merge_when_tgt_not_matched:
   12654        1090 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12655          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12656             :         ;
   12657             : 
   12658             : opt_merge_when_condition:
   12659         808 :             AND a_expr              { $$ = $2; }
   12660        2450 :             |                       { $$ = NULL; }
   12661             :         ;
   12662             : 
   12663             : merge_update:
   12664             :             UPDATE SET set_clause_list
   12665             :                 {
   12666        1550 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12667        1550 :                     n->commandType = CMD_UPDATE;
   12668        1550 :                     n->override = OVERRIDING_NOT_SET;
   12669        1550 :                     n->targetList = $3;
   12670        1550 :                     n->values = NIL;
   12671             : 
   12672        1550 :                     $$ = n;
   12673             :                 }
   12674             :         ;
   12675             : 
   12676             : merge_delete:
   12677             :             DELETE_P
   12678             :                 {
   12679         518 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12680         518 :                     n->commandType = CMD_DELETE;
   12681         518 :                     n->override = OVERRIDING_NOT_SET;
   12682         518 :                     n->targetList = NIL;
   12683         518 :                     n->values = NIL;
   12684             : 
   12685         518 :                     $$ = n;
   12686             :                 }
   12687             :         ;
   12688             : 
   12689             : merge_insert:
   12690             :             INSERT merge_values_clause
   12691             :                 {
   12692         730 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12693         730 :                     n->commandType = CMD_INSERT;
   12694         730 :                     n->override = OVERRIDING_NOT_SET;
   12695         730 :                     n->targetList = NIL;
   12696         730 :                     n->values = $2;
   12697         730 :                     $$ = n;
   12698             :                 }
   12699             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12700             :                 {
   12701           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12702           0 :                     n->commandType = CMD_INSERT;
   12703           0 :                     n->override = $3;
   12704           0 :                     n->targetList = NIL;
   12705           0 :                     n->values = $5;
   12706           0 :                     $$ = n;
   12707             :                 }
   12708             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12709             :                 {
   12710         268 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12711         268 :                     n->commandType = CMD_INSERT;
   12712         268 :                     n->override = OVERRIDING_NOT_SET;
   12713         268 :                     n->targetList = $3;
   12714         268 :                     n->values = $5;
   12715         268 :                     $$ = n;
   12716             :                 }
   12717             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12718             :                 {
   12719          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12720          30 :                     n->commandType = CMD_INSERT;
   12721          30 :                     n->override = $6;
   12722          30 :                     n->targetList = $3;
   12723          30 :                     n->values = $8;
   12724          30 :                     $$ = n;
   12725             :                 }
   12726             :             | INSERT DEFAULT VALUES
   12727             :                 {
   12728          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12729          36 :                     n->commandType = CMD_INSERT;
   12730          36 :                     n->override = OVERRIDING_NOT_SET;
   12731          36 :                     n->targetList = NIL;
   12732          36 :                     n->values = NIL;
   12733          36 :                     $$ = n;
   12734             :                 }
   12735             :         ;
   12736             : 
   12737             : merge_values_clause:
   12738             :             VALUES '(' expr_list ')'
   12739             :                 {
   12740        1028 :                     $$ = $3;
   12741             :                 }
   12742             :         ;
   12743             : 
   12744             : /*****************************************************************************
   12745             :  *
   12746             :  *      QUERY:
   12747             :  *              CURSOR STATEMENTS
   12748             :  *
   12749             :  *****************************************************************************/
   12750             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12751             :                 {
   12752        4558 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12753             : 
   12754        4558 :                     n->portalname = $2;
   12755             :                     /* currently we always set FAST_PLAN option */
   12756        4558 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12757        4558 :                     n->query = $7;
   12758        4558 :                     $$ = (Node *) n;
   12759             :                 }
   12760             :         ;
   12761             : 
   12762       14530 : cursor_name:    name                        { $$ = $1; }
   12763             :         ;
   12764             : 
   12765        4558 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12766          28 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12767         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12768          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12769           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12770           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12771             :         ;
   12772             : 
   12773        4460 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12774          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12775           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12776             :         ;
   12777             : 
   12778             : /*****************************************************************************
   12779             :  *
   12780             :  *      QUERY:
   12781             :  *              SELECT STATEMENTS
   12782             :  *
   12783             :  *****************************************************************************/
   12784             : 
   12785             : /* A complete SELECT statement looks like this.
   12786             :  *
   12787             :  * The rule returns either a single SelectStmt node or a tree of them,
   12788             :  * representing a set-operation tree.
   12789             :  *
   12790             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12791             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12792             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12793             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12794             :  * the decision is staved off as long as possible: as long as we can keep
   12795             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12796             :  * it's no longer possible to do that will we decide that parens belong to
   12797             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12798             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12799             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12800             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12801             :  * SELECT viewpoint when we see the UNION.
   12802             :  *
   12803             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12804             :  * which represents a SELECT with at least one outer layer of parentheses,
   12805             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12806             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12807             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12808             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12809             :  * conflict with the select_with_parens productions are manually given
   12810             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12811             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12812             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12813             :  * precedence for this, which is a fairly arbitrary choice.
   12814             :  *
   12815             :  * To be able to define select_with_parens itself without ambiguity, we need
   12816             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12817             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12818             :  *
   12819             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12820             :  * with or without outer parentheses.
   12821             :  */
   12822             : 
   12823             : SelectStmt: select_no_parens            %prec UMINUS
   12824             :             | select_with_parens        %prec UMINUS
   12825             :         ;
   12826             : 
   12827             : select_with_parens:
   12828             :             '(' select_no_parens ')'
   12829             :                 {
   12830       66486 :                     SelectStmt *n = (SelectStmt *) $2;
   12831             : 
   12832             :                     /*
   12833             :                      * As SelectStmt's location starts at the SELECT keyword,
   12834             :                      * we need to track the length of the SelectStmt within
   12835             :                      * parentheses to be able to extract the relevant part
   12836             :                      * of the query.  Without this, the RawStmt's length would
   12837             :                      * be used and would include the closing parenthesis.
   12838             :                      */
   12839       66486 :                     n->stmt_len = @3 - @2;
   12840       66486 :                     $$ = $2;
   12841             :                 }
   12842         156 :             | '(' select_with_parens ')'            { $$ = $2; }
   12843             :         ;
   12844             : 
   12845             : /*
   12846             :  * This rule parses the equivalent of the standard's <query expression>.
   12847             :  * The duplicative productions are annoying, but hard to get rid of without
   12848             :  * creating shift/reduce conflicts.
   12849             :  *
   12850             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12851             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12852             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12853             :  * clause.
   12854             :  *  2002-08-28 bjm
   12855             :  */
   12856             : select_no_parens:
   12857      402166 :             simple_select                       { $$ = $1; }
   12858             :             | select_clause sort_clause
   12859             :                 {
   12860       72482 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12861             :                                         NULL, NULL,
   12862             :                                         yyscanner);
   12863       72482 :                     $$ = $1;
   12864             :                 }
   12865             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12866             :                 {
   12867        4668 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12868        4668 :                                         $4,
   12869             :                                         NULL,
   12870             :                                         yyscanner);
   12871        4668 :                     $$ = $1;
   12872             :                 }
   12873             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12874             :                 {
   12875        4840 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12876        4840 :                                         $3,
   12877             :                                         NULL,
   12878             :                                         yyscanner);
   12879        4828 :                     $$ = $1;
   12880             :                 }
   12881             :             | with_clause select_clause
   12882             :                 {
   12883        2244 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12884             :                                         NULL,
   12885        2244 :                                         $1,
   12886             :                                         yyscanner);
   12887        2244 :                     $$ = $2;
   12888             :                 }
   12889             :             | with_clause select_clause sort_clause
   12890             :                 {
   12891         582 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12892             :                                         NULL,
   12893         582 :                                         $1,
   12894             :                                         yyscanner);
   12895         582 :                     $$ = $2;
   12896             :                 }
   12897             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12898             :                 {
   12899           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12900           6 :                                         $5,
   12901           6 :                                         $1,
   12902             :                                         yyscanner);
   12903           6 :                     $$ = $2;
   12904             :                 }
   12905             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12906             :                 {
   12907          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12908          64 :                                         $4,
   12909          64 :                                         $1,
   12910             :                                         yyscanner);
   12911          64 :                     $$ = $2;
   12912             :                 }
   12913             :         ;
   12914             : 
   12915             : select_clause:
   12916      122980 :             simple_select                           { $$ = $1; }
   12917         586 :             | select_with_parens                    { $$ = $1; }
   12918             :         ;
   12919             : 
   12920             : /*
   12921             :  * This rule parses SELECT statements that can appear within set operations,
   12922             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12923             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12924             :  * operations to be ordered per the precedence specs at the head of this file.
   12925             :  *
   12926             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12927             :  * but can have parenthesized subclauses.
   12928             :  *
   12929             :  * It might appear that we could fold the first two alternatives into one
   12930             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12931             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12932             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12933             :  *
   12934             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12935             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12936             :  * to be parsed as
   12937             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12938             :  * not
   12939             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12940             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12941             :  * described as part of the select_no_parens production, not simple_select.
   12942             :  * This does not limit functionality, because you can reintroduce these
   12943             :  * clauses inside parentheses.
   12944             :  *
   12945             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12946             :  * However, this is not checked by the grammar; parse analysis must check it.
   12947             :  */
   12948             : simple_select:
   12949             :             SELECT opt_all_clause opt_target_list
   12950             :             into_clause from_clause where_clause
   12951             :             group_clause having_clause window_clause
   12952             :                 {
   12953      437144 :                     SelectStmt *n = makeNode(SelectStmt);
   12954             : 
   12955      437144 :                     n->targetList = $3;
   12956      437144 :                     n->intoClause = $4;
   12957      437144 :                     n->fromClause = $5;
   12958      437144 :                     n->whereClause = $6;
   12959      437144 :                     n->groupClause = ($7)->list;
   12960      437144 :                     n->groupDistinct = ($7)->distinct;
   12961      437144 :                     n->havingClause = $8;
   12962      437144 :                     n->windowClause = $9;
   12963      437144 :                     n->stmt_location = @1;
   12964      437144 :                     $$ = (Node *) n;
   12965             :                 }
   12966             :             | SELECT distinct_clause target_list
   12967             :             into_clause from_clause where_clause
   12968             :             group_clause having_clause window_clause
   12969             :                 {
   12970        3696 :                     SelectStmt *n = makeNode(SelectStmt);
   12971             : 
   12972        3696 :                     n->distinctClause = $2;
   12973        3696 :                     n->targetList = $3;
   12974        3696 :                     n->intoClause = $4;
   12975        3696 :                     n->fromClause = $5;
   12976        3696 :                     n->whereClause = $6;
   12977        3696 :                     n->groupClause = ($7)->list;
   12978        3696 :                     n->groupDistinct = ($7)->distinct;
   12979        3696 :                     n->havingClause = $8;
   12980        3696 :                     n->windowClause = $9;
   12981        3696 :                     n->stmt_location = @1;
   12982        3696 :                     $$ = (Node *) n;
   12983             :                 }
   12984       64664 :             | values_clause                         { $$ = $1; }
   12985             :             | TABLE relation_expr
   12986             :                 {
   12987             :                     /* same as SELECT * FROM relation_expr */
   12988         308 :                     ColumnRef  *cr = makeNode(ColumnRef);
   12989         308 :                     ResTarget  *rt = makeNode(ResTarget);
   12990         308 :                     SelectStmt *n = makeNode(SelectStmt);
   12991             : 
   12992         308 :                     cr->fields = list_make1(makeNode(A_Star));
   12993         308 :                     cr->location = -1;
   12994             : 
   12995         308 :                     rt->name = NULL;
   12996         308 :                     rt->indirection = NIL;
   12997         308 :                     rt->val = (Node *) cr;
   12998         308 :                     rt->location = -1;
   12999             : 
   13000         308 :                     n->targetList = list_make1(rt);
   13001         308 :                     n->fromClause = list_make1($2);
   13002         308 :                     n->stmt_location = @1;
   13003         308 :                     $$ = (Node *) n;
   13004             :                 }
   13005             :             | select_clause UNION set_quantifier select_clause
   13006             :                 {
   13007       18600 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   13008             :                 }
   13009             :             | select_clause INTERSECT set_quantifier select_clause
   13010             :                 {
   13011         258 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   13012             :                 }
   13013             :             | select_clause EXCEPT set_quantifier select_clause
   13014             :                 {
   13015         476 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   13016             :                 }
   13017             :         ;
   13018             : 
   13019             : /*
   13020             :  * SQL standard WITH clause looks like:
   13021             :  *
   13022             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13023             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13024             :  *
   13025             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13026             :  */
   13027             : with_clause:
   13028             :         WITH cte_list
   13029             :             {
   13030        2010 :                 $$ = makeNode(WithClause);
   13031        2010 :                 $$->ctes = $2;
   13032        2010 :                 $$->recursive = false;
   13033        2010 :                 $$->location = @1;
   13034             :             }
   13035             :         | WITH_LA cte_list
   13036             :             {
   13037           6 :                 $$ = makeNode(WithClause);
   13038           6 :                 $$->ctes = $2;
   13039           6 :                 $$->recursive = false;
   13040           6 :                 $$->location = @1;
   13041             :             }
   13042             :         | WITH RECURSIVE cte_list
   13043             :             {
   13044        1330 :                 $$ = makeNode(WithClause);
   13045        1330 :                 $$->ctes = $3;
   13046        1330 :                 $$->recursive = true;
   13047        1330 :                 $$->location = @1;
   13048             :             }
   13049             :         ;
   13050             : 
   13051             : cte_list:
   13052        3346 :         common_table_expr                       { $$ = list_make1($1); }
   13053        1218 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13054             :         ;
   13055             : 
   13056             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13057             :             {
   13058        4564 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13059             : 
   13060        4564 :                 n->ctename = $1;
   13061        4564 :                 n->aliascolnames = $2;
   13062        4564 :                 n->ctematerialized = $4;
   13063        4564 :                 n->ctequery = $6;
   13064        4564 :                 n->search_clause = castNode(CTESearchClause, $8);
   13065        4564 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13066        4564 :                 n->location = @1;
   13067        4564 :                 $$ = (Node *) n;
   13068             :             }
   13069             :         ;
   13070             : 
   13071             : opt_materialized:
   13072         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13073          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13074        4338 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13075             :         ;
   13076             : 
   13077             : opt_search_clause:
   13078             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13079             :             {
   13080          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13081             : 
   13082          90 :                 n->search_col_list = $5;
   13083          90 :                 n->search_breadth_first = false;
   13084          90 :                 n->search_seq_column = $7;
   13085          90 :                 n->location = @1;
   13086          90 :                 $$ = (Node *) n;
   13087             :             }
   13088             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13089             :             {
   13090          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13091             : 
   13092          36 :                 n->search_col_list = $5;
   13093          36 :                 n->search_breadth_first = true;
   13094          36 :                 n->search_seq_column = $7;
   13095          36 :                 n->location = @1;
   13096          36 :                 $$ = (Node *) n;
   13097             :             }
   13098             :         | /*EMPTY*/
   13099             :             {
   13100        4438 :                 $$ = NULL;
   13101             :             }
   13102             :         ;
   13103             : 
   13104             : opt_cycle_clause:
   13105             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13106             :             {
   13107          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13108             : 
   13109          66 :                 n->cycle_col_list = $2;
   13110          66 :                 n->cycle_mark_column = $4;
   13111          66 :                 n->cycle_mark_value = $6;
   13112          66 :                 n->cycle_mark_default = $8;
   13113          66 :                 n->cycle_path_column = $10;
   13114          66 :                 n->location = @1;
   13115          66 :                 $$ = (Node *) n;
   13116             :             }
   13117             :         | CYCLE columnList SET ColId USING ColId
   13118             :             {
   13119          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13120             : 
   13121          60 :                 n->cycle_col_list = $2;
   13122          60 :                 n->cycle_mark_column = $4;
   13123          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13124          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13125          60 :                 n->cycle_path_column = $6;
   13126          60 :                 n->location = @1;
   13127          60 :                 $$ = (Node *) n;
   13128             :             }
   13129             :         | /*EMPTY*/
   13130             :             {
   13131        4438 :                 $$ = NULL;
   13132             :             }
   13133             :         ;
   13134             : 
   13135             : opt_with_clause:
   13136         450 :         with_clause                             { $$ = $1; }
   13137       94502 :         | /*EMPTY*/                             { $$ = NULL; }
   13138             :         ;
   13139             : 
   13140             : into_clause:
   13141             :             INTO OptTempTableName
   13142             :                 {
   13143         132 :                     $$ = makeNode(IntoClause);
   13144         132 :                     $$->rel = $2;
   13145         132 :                     $$->colNames = NIL;
   13146         132 :                     $$->options = NIL;
   13147         132 :                     $$->onCommit = ONCOMMIT_NOOP;
   13148         132 :                     $$->tableSpaceName = NULL;
   13149         132 :                     $$->viewQuery = NULL;
   13150         132 :                     $$->skipData = false;
   13151             :                 }
   13152             :             | /*EMPTY*/
   13153      440732 :                 { $$ = NULL; }
   13154             :         ;
   13155             : 
   13156             : /*
   13157             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13158             :  * since TEMP is not a reserved word.  See also OptTemp.
   13159             :  */
   13160             : OptTempTableName:
   13161             :             TEMPORARY opt_table qualified_name
   13162             :                 {
   13163           0 :                     $$ = $3;
   13164           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13165             :                 }
   13166             :             | TEMP opt_table qualified_name
   13167             :                 {
   13168           6 :                     $$ = $3;
   13169           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13170             :                 }
   13171             :             | LOCAL TEMPORARY opt_table qualified_name
   13172             :                 {
   13173           0 :                     $$ = $4;
   13174           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13175             :                 }
   13176             :             | LOCAL TEMP opt_table qualified_name
   13177             :                 {
   13178           0 :                     $$ = $4;
   13179           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13180             :                 }
   13181             :             | GLOBAL TEMPORARY opt_table qualified_name
   13182             :                 {
   13183           0 :                     ereport(WARNING,
   13184             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13185             :                              parser_errposition(@1)));
   13186           0 :                     $$ = $4;
   13187           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13188             :                 }
   13189             :             | GLOBAL TEMP opt_table qualified_name
   13190             :                 {
   13191           0 :                     ereport(WARNING,
   13192             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13193             :                              parser_errposition(@1)));
   13194           0 :                     $$ = $4;
   13195           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13196             :                 }
   13197             :             | UNLOGGED opt_table qualified_name
   13198             :                 {
   13199           0 :                     $$ = $3;
   13200           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13201             :                 }
   13202             :             | TABLE qualified_name
   13203             :                 {
   13204          30 :                     $$ = $2;
   13205          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13206             :                 }
   13207             :             | qualified_name
   13208             :                 {
   13209          96 :                     $$ = $1;
   13210          96 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13211             :                 }
   13212             :         ;
   13213             : 
   13214             : opt_table:  TABLE
   13215             :             | /*EMPTY*/
   13216             :         ;
   13217             : 
   13218             : set_quantifier:
   13219       10676 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13220          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13221       13268 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13222             :         ;
   13223             : 
   13224             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13225             :  * should be placed in the DISTINCT list during parsetree analysis.
   13226             :  */
   13227             : distinct_clause:
   13228        3452 :             DISTINCT                                { $$ = list_make1(NIL); }
   13229         250 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13230             :         ;
   13231             : 
   13232             : opt_all_clause:
   13233             :             ALL
   13234             :             | /*EMPTY*/
   13235             :         ;
   13236             : 
   13237             : opt_distinct_clause:
   13238           0 :             distinct_clause                         { $$ = $1; }
   13239       40264 :             | opt_all_clause                        { $$ = NIL; }
   13240             :         ;
   13241             : 
   13242             : opt_sort_clause:
   13243        7674 :             sort_clause                             { $$ = $1; }
   13244      370648 :             | /*EMPTY*/                             { $$ = NIL; }
   13245             :         ;
   13246             : 
   13247             : sort_clause:
   13248       81086 :             ORDER BY sortby_list                    { $$ = $3; }
   13249             :         ;
   13250             : 
   13251             : sortby_list:
   13252       81104 :             sortby                                  { $$ = list_make1($1); }
   13253       30322 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13254             :         ;
   13255             : 
   13256             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13257             :                 {
   13258         220 :                     $$ = makeNode(SortBy);
   13259         220 :                     $$->node = $1;
   13260         220 :                     $$->sortby_dir = SORTBY_USING;
   13261         220 :                     $$->sortby_nulls = $4;
   13262         220 :                     $$->useOp = $3;
   13263         220 :                     $$->location = @3;
   13264             :                 }
   13265             :             | a_expr opt_asc_desc opt_nulls_order
   13266             :                 {
   13267      111206 :                     $$ = makeNode(SortBy);
   13268      111206 :                     $$->node = $1;
   13269      111206 :                     $$->sortby_dir = $2;
   13270      111206 :                     $$->sortby_nulls = $3;
   13271      111206 :                     $$->useOp = NIL;
   13272      111206 :                     $$->location = -1;       /* no operator */
   13273             :                 }
   13274             :         ;
   13275             : 
   13276             : 
   13277             : select_limit:
   13278             :             limit_clause offset_clause
   13279             :                 {
   13280         172 :                     $$ = $1;
   13281         172 :                     ($$)->limitOffset = $2;
   13282         172 :                     ($$)->offsetLoc = @2;
   13283             :                 }
   13284             :             | offset_clause limit_clause
   13285             :                 {
   13286         226 :                     $$ = $2;
   13287         226 :                     ($$)->limitOffset = $1;
   13288         226 :                     ($$)->offsetLoc = @1;
   13289             :                 }
   13290             :             | limit_clause
   13291             :                 {
   13292        4258 :                     $$ = $1;
   13293             :                 }
   13294             :             | offset_clause
   13295             :                 {
   13296         438 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13297             : 
   13298         438 :                     n->limitOffset = $1;
   13299         438 :                     n->limitCount = NULL;
   13300         438 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13301         438 :                     n->offsetLoc = @1;
   13302         438 :                     n->countLoc = -1;
   13303         438 :                     n->optionLoc = -1;
   13304         438 :                     $$ = n;
   13305             :                 }
   13306             :         ;
   13307             : 
   13308             : opt_select_limit:
   13309         190 :             select_limit                        { $$ = $1; }
   13310       44748 :             | /* EMPTY */                       { $$ = NULL; }
   13311             :         ;
   13312             : 
   13313             : limit_clause:
   13314             :             LIMIT select_limit_value
   13315             :                 {
   13316        4564 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13317             : 
   13318        4564 :                     n->limitOffset = NULL;
   13319        4564 :                     n->limitCount = $2;
   13320        4564 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13321        4564 :                     n->offsetLoc = -1;
   13322        4564 :                     n->countLoc = @1;
   13323        4564 :                     n->optionLoc = -1;
   13324        4564 :                     $$ = n;
   13325             :                 }
   13326             :             | LIMIT select_limit_value ',' select_offset_value
   13327             :                 {
   13328             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13329           0 :                     ereport(ERROR,
   13330             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13331             :                              errmsg("LIMIT #,# syntax is not supported"),
   13332             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13333             :                              parser_errposition(@1)));
   13334             :                 }
   13335             :             /* SQL:2008 syntax */
   13336             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13337             :              * a separate production rather than an opt_ expression.  The fact
   13338             :              * that ONLY is fully reserved means that this way, we defer any
   13339             :              * decision about what rule reduces ROW or ROWS to the point where
   13340             :              * we can see the ONLY token in the lookahead slot.
   13341             :              */
   13342             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13343             :                 {
   13344          24 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13345             : 
   13346          24 :                     n->limitOffset = NULL;
   13347          24 :                     n->limitCount = $3;
   13348          24 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13349          24 :                     n->offsetLoc = -1;
   13350          24 :                     n->countLoc = @1;
   13351          24 :                     n->optionLoc = -1;
   13352          24 :                     $$ = n;
   13353             :                 }
   13354             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13355             :                 {
   13356          62 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13357             : 
   13358          62 :                     n->limitOffset = NULL;
   13359          62 :                     n->limitCount = $3;
   13360          62 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13361          62 :                     n->offsetLoc = -1;
   13362          62 :                     n->countLoc = @1;
   13363          62 :                     n->optionLoc = @5;
   13364          62 :                     $$ = n;
   13365             :                 }
   13366             :             | FETCH first_or_next row_or_rows ONLY
   13367             :                 {
   13368           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13369             : 
   13370           0 :                     n->limitOffset = NULL;
   13371           0 :                     n->limitCount = makeIntConst(1, -1);
   13372           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13373           0 :                     n->offsetLoc = -1;
   13374           0 :                     n->countLoc = @1;
   13375           0 :                     n->optionLoc = -1;
   13376           0 :                     $$ = n;
   13377             :                 }
   13378             :             | FETCH first_or_next row_or_rows WITH TIES
   13379             :                 {
   13380           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13381             : 
   13382           6 :                     n->limitOffset = NULL;
   13383           6 :                     n->limitCount = makeIntConst(1, -1);
   13384           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13385           6 :                     n->offsetLoc = -1;
   13386           6 :                     n->countLoc = @1;
   13387           6 :                     n->optionLoc = @4;
   13388           6 :                     $$ = n;
   13389             :                 }
   13390             :         ;
   13391             : 
   13392             : offset_clause:
   13393             :             OFFSET select_offset_value
   13394         836 :                 { $$ = $2; }
   13395             :             /* SQL:2008 syntax */
   13396             :             | OFFSET select_fetch_first_value row_or_rows
   13397           0 :                 { $$ = $2; }
   13398             :         ;
   13399             : 
   13400             : select_limit_value:
   13401        4560 :             a_expr                                  { $$ = $1; }
   13402             :             | ALL
   13403             :                 {
   13404             :                     /* LIMIT ALL is represented as a NULL constant */
   13405           4 :                     $$ = makeNullAConst(@1);
   13406             :                 }
   13407             :         ;
   13408             : 
   13409             : select_offset_value:
   13410         836 :             a_expr                                  { $$ = $1; }
   13411             :         ;
   13412             : 
   13413             : /*
   13414             :  * Allowing full expressions without parentheses causes various parsing
   13415             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13416             :  * <simple value specification>, which is either a literal or a parameter (but
   13417             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13418             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13419             :  * to determine whether the expression is missing rather than trying to make it
   13420             :  * optional in this rule.
   13421             :  *
   13422             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13423             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13424             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13425             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13426             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13427             :  * builds.)
   13428             :  */
   13429             : select_fetch_first_value:
   13430          86 :             c_expr                                  { $$ = $1; }
   13431             :             | '+' I_or_F_const
   13432           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13433             :             | '-' I_or_F_const
   13434           0 :                 { $$ = doNegate($2, @1); }
   13435             :         ;
   13436             : 
   13437             : I_or_F_const:
   13438           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13439           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13440             :         ;
   13441             : 
   13442             : /* noise words */
   13443          36 : row_or_rows: ROW                                    { $$ = 0; }
   13444          56 :             | ROWS                                  { $$ = 0; }
   13445             :         ;
   13446             : 
   13447          92 : first_or_next: FIRST_P                              { $$ = 0; }
   13448           0 :             | NEXT                                  { $$ = 0; }
   13449             :         ;
   13450             : 
   13451             : 
   13452             : /*
   13453             :  * This syntax for group_clause tries to follow the spec quite closely.
   13454             :  * However, the spec allows only column references, not expressions,
   13455             :  * which introduces an ambiguity between implicit row constructors
   13456             :  * (a,b) and lists of column references.
   13457             :  *
   13458             :  * We handle this by using the a_expr production for what the spec calls
   13459             :  * <ordinary grouping set>, which in the spec represents either one column
   13460             :  * reference or a parenthesized list of column references. Then, we check the
   13461             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13462             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13463             :  * not here)
   13464             :  *
   13465             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13466             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13467             :  * in a group clause, but if they have a reason to, we make it possible.)
   13468             :  *
   13469             :  * Each item in the group_clause list is either an expression tree or a
   13470             :  * GroupingSet node of some type.
   13471             :  */
   13472             : group_clause:
   13473             :             GROUP_P BY set_quantifier group_by_list
   13474             :                 {
   13475        4630 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13476             : 
   13477        4630 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13478        4630 :                     n->list = $4;
   13479        4630 :                     $$ = n;
   13480             :                 }
   13481             :             | /*EMPTY*/
   13482             :                 {
   13483      476474 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13484             : 
   13485      476474 :                     n->distinct = false;
   13486      476474 :                     n->list = NIL;
   13487      476474 :                     $$ = n;
   13488             :                 }
   13489             :         ;
   13490             : 
   13491             : group_by_list:
   13492        5228 :             group_by_item                           { $$ = list_make1($1); }
   13493        3008 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13494             :         ;
   13495             : 
   13496             : group_by_item:
   13497        6946 :             a_expr                                  { $$ = $1; }
   13498         222 :             | empty_grouping_set                    { $$ = $1; }
   13499         184 :             | cube_clause                           { $$ = $1; }
   13500         286 :             | rollup_clause                         { $$ = $1; }
   13501         598 :             | grouping_sets_clause                  { $$ = $1; }
   13502             :         ;
   13503             : 
   13504             : empty_grouping_set:
   13505             :             '(' ')'
   13506             :                 {
   13507         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13508             :                 }
   13509             :         ;
   13510             : 
   13511             : /*
   13512             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13513             :  * so that they shift in these rules rather than reducing the conflicting
   13514             :  * unreserved_keyword rule.
   13515             :  */
   13516             : 
   13517             : rollup_clause:
   13518             :             ROLLUP '(' expr_list ')'
   13519             :                 {
   13520         286 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13521             :                 }
   13522             :         ;
   13523             : 
   13524             : cube_clause:
   13525             :             CUBE '(' expr_list ')'
   13526             :                 {
   13527         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13528             :                 }
   13529             :         ;
   13530             : 
   13531             : grouping_sets_clause:
   13532             :             GROUPING SETS '(' group_by_list ')'
   13533             :                 {
   13534         598 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13535             :                 }
   13536             :         ;
   13537             : 
   13538             : having_clause:
   13539         682 :             HAVING a_expr                           { $$ = $2; }
   13540      480422 :             | /*EMPTY*/                             { $$ = NULL; }
   13541             :         ;
   13542             : 
   13543             : for_locking_clause:
   13544        5014 :             for_locking_items                       { $$ = $1; }
   13545           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13546             :         ;
   13547             : 
   13548             : opt_for_locking_clause:
   13549         340 :             for_locking_clause                      { $$ = $1; }
   13550       44828 :             | /* EMPTY */                           { $$ = NIL; }
   13551             :         ;
   13552             : 
   13553             : for_locking_items:
   13554        5014 :             for_locking_item                        { $$ = list_make1($1); }
   13555          98 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13556             :         ;
   13557             : 
   13558             : for_locking_item:
   13559             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13560             :                 {
   13561        5112 :                     LockingClause *n = makeNode(LockingClause);
   13562             : 
   13563        5112 :                     n->lockedRels = $2;
   13564        5112 :                     n->strength = $1;
   13565        5112 :                     n->waitPolicy = $3;
   13566        5112 :                     $$ = (Node *) n;
   13567             :                 }
   13568             :         ;
   13569             : 
   13570             : for_locking_strength:
   13571        1516 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13572          76 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13573         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13574        3306 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13575             :         ;
   13576             : 
   13577             : locked_rels_list:
   13578        3326 :             OF qualified_name_list                  { $$ = $2; }
   13579        1786 :             | /* EMPTY */                           { $$ = NIL; }
   13580             :         ;
   13581             : 
   13582             : 
   13583             : /*
   13584             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13585             :  * making VALUES a fully reserved word, which will probably break more apps
   13586             :  * than allowing the noise-word is worth.
   13587             :  */
   13588             : values_clause:
   13589             :             VALUES '(' expr_list ')'
   13590             :                 {
   13591       64664 :                     SelectStmt *n = makeNode(SelectStmt);
   13592             : 
   13593       64664 :                     n->stmt_location = @1;
   13594       64664 :                     n->valuesLists = list_make1($3);
   13595       64664 :                     $$ = (Node *) n;
   13596             :                 }
   13597             :             | values_clause ',' '(' expr_list ')'
   13598             :                 {
   13599       25166 :                     SelectStmt *n = (SelectStmt *) $1;
   13600             : 
   13601       25166 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13602       25166 :                     $$ = (Node *) n;
   13603             :                 }
   13604             :         ;
   13605             : 
   13606             : 
   13607             : /*****************************************************************************
   13608             :  *
   13609             :  *  clauses common to all Optimizable Stmts:
   13610             :  *      from_clause     - allow list of both JOIN expressions and table names
   13611             :  *      where_clause    - qualifications for joins or restrictions
   13612             :  *
   13613             :  *****************************************************************************/
   13614             : 
   13615             : from_clause:
   13616      322508 :             FROM from_list                          { $$ = $2; }
   13617      172594 :             | /*EMPTY*/                             { $$ = NIL; }
   13618             :         ;
   13619             : 
   13620             : from_list:
   13621      323288 :             table_ref                               { $$ = list_make1($1); }
   13622       61250 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13623             :         ;
   13624             : 
   13625             : /*
   13626             :  * table_ref is where an alias clause can be attached.
   13627             :  */
   13628             : table_ref:  relation_expr opt_alias_clause
   13629             :                 {
   13630      403894 :                     $1->alias = $2;
   13631      403894 :                     $$ = (Node *) $1;
   13632             :                 }
   13633             :             | relation_expr opt_alias_clause tablesample_clause
   13634             :                 {
   13635         264 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13636             : 
   13637         264 :                     $1->alias = $2;
   13638             :                     /* relation_expr goes inside the RangeTableSample node */
   13639         264 :                     n->relation = (Node *) $1;
   13640         264 :                     $$ = (Node *) n;
   13641             :                 }
   13642             :             | func_table func_alias_clause
   13643             :                 {
   13644       50596 :                     RangeFunction *n = (RangeFunction *) $1;
   13645             : 
   13646       50596 :                     n->alias = linitial($2);
   13647       50596 :                     n->coldeflist = lsecond($2);
   13648       50596 :                     $$ = (Node *) n;
   13649             :                 }
   13650             :             | LATERAL_P func_table func_alias_clause
   13651             :                 {
   13652        1142 :                     RangeFunction *n = (RangeFunction *) $2;
   13653             : 
   13654        1142 :                     n->lateral = true;
   13655        1142 :                     n->alias = linitial($3);
   13656        1142 :                     n->coldeflist = lsecond($3);
   13657        1142 :                     $$ = (Node *) n;
   13658             :                 }
   13659             :             | xmltable opt_alias_clause
   13660             :                 {
   13661          82 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13662             : 
   13663          82 :                     n->alias = $2;
   13664          82 :                     $$ = (Node *) n;
   13665             :                 }
   13666             :             | LATERAL_P xmltable opt_alias_clause
   13667             :                 {
   13668         142 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13669             : 
   13670         142 :                     n->lateral = true;
   13671         142 :                     n->alias = $3;
   13672         142 :                     $$ = (Node *) n;
   13673             :                 }
   13674             :             | select_with_parens opt_alias_clause
   13675             :                 {
   13676       13798 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13677             : 
   13678       13798 :                     n->lateral = false;
   13679       13798 :                     n->subquery = $1;
   13680       13798 :                     n->alias = $2;
   13681       13798 :                     $$ = (Node *) n;
   13682             :                 }
   13683             :             | LATERAL_P select_with_parens opt_alias_clause
   13684             :                 {
   13685        1830 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13686             : 
   13687        1830 :                     n->lateral = true;
   13688        1830 :                     n->subquery = $2;
   13689        1830 :                     n->alias = $3;
   13690        1830 :                     $$ = (Node *) n;
   13691             :                 }
   13692             :             | joined_table
   13693             :                 {
   13694       85466 :                     $$ = (Node *) $1;
   13695             :                 }
   13696             :             | '(' joined_table ')' alias_clause
   13697             :                 {
   13698         174 :                     $2->alias = $4;
   13699         174 :                     $$ = (Node *) $2;
   13700             :                 }
   13701             :             | json_table opt_alias_clause
   13702             :                 {
   13703         524 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13704             : 
   13705         524 :                     jt->alias = $2;
   13706         524 :                     $$ = (Node *) jt;
   13707             :                 }
   13708             :             | LATERAL_P json_table opt_alias_clause
   13709             :                 {
   13710           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13711             : 
   13712           0 :                     jt->alias = $3;
   13713           0 :                     jt->lateral = true;
   13714           0 :                     $$ = (Node *) jt;
   13715             :                 }
   13716             :         ;
   13717             : 
   13718             : 
   13719             : /*
   13720             :  * It may seem silly to separate joined_table from table_ref, but there is
   13721             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13722             :  * reduce conflicts, because it's not clear to the parser generator whether
   13723             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13724             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13725             :  * join_type to expand to empty; if we try it, the parser generator can't
   13726             :  * figure out when to reduce an empty join_type right after table_ref.
   13727             :  *
   13728             :  * Note that a CROSS JOIN is the same as an unqualified
   13729             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13730             :  * but a qualification expression to limit membership.
   13731             :  * A NATURAL JOIN implicitly matches column names between
   13732             :  * tables and the shape is determined by which columns are
   13733             :  * in common. We'll collect columns during the later transformations.
   13734             :  */
   13735             : 
   13736             : joined_table:
   13737             :             '(' joined_table ')'
   13738             :                 {
   13739        3922 :                     $$ = $2;
   13740             :                 }
   13741             :             | table_ref CROSS JOIN table_ref
   13742             :                 {
   13743             :                     /* CROSS JOIN is same as unqualified inner join */
   13744         506 :                     JoinExpr   *n = makeNode(JoinExpr);
   13745             : 
   13746         506 :                     n->jointype = JOIN_INNER;
   13747         506 :                     n->isNatural = false;
   13748         506 :                     n->larg = $1;
   13749         506 :                     n->rarg = $4;
   13750         506 :                     n->usingClause = NIL;
   13751         506 :                     n->join_using_alias = NULL;
   13752         506 :                     n->quals = NULL;
   13753         506 :                     $$ = n;
   13754             :                 }
   13755             :             | table_ref join_type JOIN table_ref join_qual
   13756             :                 {
   13757       47826 :                     JoinExpr   *n = makeNode(JoinExpr);
   13758             : 
   13759       47826 :                     n->jointype = $2;
   13760       47826 :                     n->isNatural = false;
   13761       47826 :                     n->larg = $1;
   13762       47826 :                     n->rarg = $4;
   13763       47826 :                     if ($5 != NULL && IsA($5, List))
   13764             :                     {
   13765             :                          /* USING clause */
   13766         492 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13767         492 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13768             :                     }
   13769             :                     else
   13770             :                     {
   13771             :                         /* ON clause */
   13772       47334 :                         n->quals = $5;
   13773             :                     }
   13774       47826 :                     $$ = n;
   13775             :                 }
   13776             :             | table_ref JOIN table_ref join_qual
   13777             :                 {
   13778             :                     /* letting join_type reduce to empty doesn't work */
   13779       37050 :                     JoinExpr   *n = makeNode(JoinExpr);
   13780             : 
   13781       37050 :                     n->jointype = JOIN_INNER;
   13782       37050 :                     n->isNatural = false;
   13783       37050 :                     n->larg = $1;
   13784       37050 :                     n->rarg = $3;
   13785       37050 :                     if ($4 != NULL && IsA($4, List))
   13786             :                     {
   13787             :                         /* USING clause */
   13788         752 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13789         752 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13790             :                     }
   13791             :                     else
   13792             :                     {
   13793             :                         /* ON clause */
   13794       36298 :                         n->quals = $4;
   13795             :                     }
   13796       37050 :                     $$ = n;
   13797             :                 }
   13798             :             | table_ref NATURAL join_type JOIN table_ref
   13799             :                 {
   13800          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13801             : 
   13802          78 :                     n->jointype = $3;
   13803          78 :                     n->isNatural = true;
   13804          78 :                     n->larg = $1;
   13805          78 :                     n->rarg = $5;
   13806          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13807          78 :                     n->join_using_alias = NULL;
   13808          78 :                     n->quals = NULL; /* fill later */
   13809          78 :                     $$ = n;
   13810             :                 }
   13811             :             | table_ref NATURAL JOIN table_ref
   13812             :                 {
   13813             :                     /* letting join_type reduce to empty doesn't work */
   13814         180 :                     JoinExpr   *n = makeNode(JoinExpr);
   13815             : 
   13816         180 :                     n->jointype = JOIN_INNER;
   13817         180 :                     n->isNatural = true;
   13818         180 :                     n->larg = $1;
   13819         180 :                     n->rarg = $4;
   13820         180 :                     n->usingClause = NIL; /* figure out which columns later... */
   13821         180 :                     n->join_using_alias = NULL;
   13822         180 :                     n->quals = NULL; /* fill later */
   13823         180 :                     $$ = n;
   13824             :                 }
   13825             :         ;
   13826             : 
   13827             : alias_clause:
   13828             :             AS ColId '(' name_list ')'
   13829             :                 {
   13830        7416 :                     $$ = makeNode(Alias);
   13831        7416 :                     $$->aliasname = $2;
   13832        7416 :                     $$->colnames = $4;
   13833             :                 }
   13834             :             | AS ColId
   13835             :                 {
   13836       10802 :                     $$ = makeNode(Alias);
   13837       10802 :                     $$->aliasname = $2;
   13838             :                 }
   13839             :             | ColId '(' name_list ')'
   13840             :                 {
   13841        5754 :                     $$ = makeNode(Alias);
   13842        5754 :                     $$->aliasname = $1;
   13843        5754 :                     $$->colnames = $3;
   13844             :                 }
   13845             :             | ColId
   13846             :                 {
   13847      266060 :                     $$ = makeNode(Alias);
   13848      266060 :                     $$->aliasname = $1;
   13849             :                 }
   13850             :         ;
   13851             : 
   13852      260448 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13853      160086 :             | /*EMPTY*/                             { $$ = NULL; }
   13854             :         ;
   13855             : 
   13856             : /*
   13857             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13858             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13859             :  * don't seem to be useful, and it might lead to parser problems in the
   13860             :  * future.)
   13861             :  */
   13862             : opt_alias_clause_for_join_using:
   13863             :             AS ColId
   13864             :                 {
   13865          84 :                     $$ = makeNode(Alias);
   13866          84 :                     $$->aliasname = $2;
   13867             :                     /* the column name list will be inserted later */
   13868             :                 }
   13869        1160 :             | /*EMPTY*/                             { $$ = NULL; }
   13870             :         ;
   13871             : 
   13872             : /*
   13873             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13874             :  * return a 2-element list that gets disassembled by calling production.
   13875             :  */
   13876             : func_alias_clause:
   13877             :             alias_clause
   13878             :                 {
   13879       29410 :                     $$ = list_make2($1, NIL);
   13880             :                 }
   13881             :             | AS '(' TableFuncElementList ')'
   13882             :                 {
   13883         114 :                     $$ = list_make2(NULL, $3);
   13884             :                 }
   13885             :             | AS ColId '(' TableFuncElementList ')'
   13886             :                 {
   13887         596 :                     Alias      *a = makeNode(Alias);
   13888             : 
   13889         596 :                     a->aliasname = $2;
   13890         596 :                     $$ = list_make2(a, $4);
   13891             :                 }
   13892             :             | ColId '(' TableFuncElementList ')'
   13893             :                 {
   13894          50 :                     Alias      *a = makeNode(Alias);
   13895             : 
   13896          50 :                     a->aliasname = $1;
   13897          50 :                     $$ = list_make2(a, $3);
   13898             :                 }
   13899             :             | /*EMPTY*/
   13900             :                 {
   13901       21568 :                     $$ = list_make2(NULL, NIL);
   13902             :                 }
   13903             :         ;
   13904             : 
   13905        1042 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13906       42574 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13907         360 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13908        3928 :             | INNER_P                               { $$ = JOIN_INNER; }
   13909             :         ;
   13910             : 
   13911             : /* OUTER is just noise... */
   13912             : opt_outer: OUTER_P
   13913             :             | /*EMPTY*/
   13914             :         ;
   13915             : 
   13916             : /* JOIN qualification clauses
   13917             :  * Possibilities are:
   13918             :  *  USING ( column list ) [ AS alias ]
   13919             :  *                        allows only unqualified column names,
   13920             :  *                        which must match between tables.
   13921             :  *  ON expr allows more general qualifications.
   13922             :  *
   13923             :  * We return USING as a two-element List (the first item being a sub-List
   13924             :  * of the common column names, and the second either an Alias item or NULL).
   13925             :  * An ON-expr will not be a List, so it can be told apart that way.
   13926             :  */
   13927             : 
   13928             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13929             :                 {
   13930        1244 :                     $$ = (Node *) list_make2($3, $5);
   13931             :                 }
   13932             :             | ON a_expr
   13933             :                 {
   13934       83632 :                     $$ = $2;
   13935             :                 }
   13936             :         ;
   13937             : 
   13938             : 
   13939             : relation_expr:
   13940             :             qualified_name
   13941             :                 {
   13942             :                     /* inheritance query, implicitly */
   13943      490762 :                     $$ = $1;
   13944      490762 :                     $$->inh = true;
   13945      490762 :                     $$->alias = NULL;
   13946             :                 }
   13947             :             | extended_relation_expr
   13948             :                 {
   13949        9136 :                     $$ = $1;
   13950             :                 }
   13951             :         ;
   13952             : 
   13953             : extended_relation_expr:
   13954             :             qualified_name '*'
   13955             :                 {
   13956             :                     /* inheritance query, explicitly */
   13957         204 :                     $$ = $1;
   13958         204 :                     $$->inh = true;
   13959         204 :                     $$->alias = NULL;
   13960             :                 }
   13961             :             | ONLY qualified_name
   13962             :                 {
   13963             :                     /* no inheritance */
   13964        8938 :                     $$ = $2;
   13965        8938 :                     $$->inh = false;
   13966        8938 :                     $$->alias = NULL;
   13967             :                 }
   13968             :             | ONLY '(' qualified_name ')'
   13969             :                 {
   13970             :                     /* no inheritance, SQL99-style syntax */
   13971           0 :                     $$ = $3;
   13972           0 :                     $$->inh = false;
   13973           0 :                     $$->alias = NULL;
   13974             :                 }
   13975             :         ;
   13976             : 
   13977             : 
   13978             : relation_expr_list:
   13979        5436 :             relation_expr                           { $$ = list_make1($1); }
   13980       15298 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   13981             :         ;
   13982             : 
   13983             : 
   13984             : /*
   13985             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   13986             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   13987             :  * keyword.  Since "set" is allowed as a column name both interpretations
   13988             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   13989             :  * relation_expr_opt_alias production a higher precedence than the SET token
   13990             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   13991             :  * SET is not an alias.
   13992             :  */
   13993             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   13994             :                 {
   13995       18430 :                     $$ = $1;
   13996             :                 }
   13997             :             | relation_expr ColId
   13998             :                 {
   13999        2192 :                     Alias      *alias = makeNode(Alias);
   14000             : 
   14001        2192 :                     alias->aliasname = $2;
   14002        2192 :                     $1->alias = alias;
   14003        2192 :                     $$ = $1;
   14004             :                 }
   14005             :             | relation_expr AS ColId
   14006             :                 {
   14007          90 :                     Alias      *alias = makeNode(Alias);
   14008             : 
   14009          90 :                     alias->aliasname = $3;
   14010          90 :                     $1->alias = alias;
   14011          90 :                     $$ = $1;
   14012             :                 }
   14013             :         ;
   14014             : 
   14015             : /*
   14016             :  * TABLESAMPLE decoration in a FROM item
   14017             :  */
   14018             : tablesample_clause:
   14019             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14020             :                 {
   14021         264 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14022             : 
   14023             :                     /* n->relation will be filled in later */
   14024         264 :                     n->method = $2;
   14025         264 :                     n->args = $4;
   14026         264 :                     n->repeatable = $6;
   14027         264 :                     n->location = @2;
   14028         264 :                     $$ = (Node *) n;
   14029             :                 }
   14030             :         ;
   14031             : 
   14032             : opt_repeatable_clause:
   14033         110 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14034         154 :             | /*EMPTY*/                 { $$ = NULL; }
   14035             :         ;
   14036             : 
   14037             : /*
   14038             :  * func_table represents a function invocation in a FROM list. It can be
   14039             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14040             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14041             :  * optionally with WITH ORDINALITY attached.
   14042             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14043             :  * function, for example:
   14044             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14045             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14046             :  * It's also possible to attach a column definition list to the RangeFunction
   14047             :  * as a whole, but that's handled by the table_ref production.
   14048             :  */
   14049             : func_table: func_expr_windowless opt_ordinality
   14050             :                 {
   14051       51612 :                     RangeFunction *n = makeNode(RangeFunction);
   14052             : 
   14053       51612 :                     n->lateral = false;
   14054       51612 :                     n->ordinality = $2;
   14055       51612 :                     n->is_rowsfrom = false;
   14056       51612 :                     n->functions = list_make1(list_make2($1, NIL));
   14057             :                     /* alias and coldeflist are set by table_ref production */
   14058       51612 :                     $$ = (Node *) n;
   14059             :                 }
   14060             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14061             :                 {
   14062         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14063             : 
   14064         132 :                     n->lateral = false;
   14065         132 :                     n->ordinality = $6;
   14066         132 :                     n->is_rowsfrom = true;
   14067         132 :                     n->functions = $4;
   14068             :                     /* alias and coldeflist are set by table_ref production */
   14069         132 :                     $$ = (Node *) n;
   14070             :                 }
   14071             :         ;
   14072             : 
   14073             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14074         318 :                 { $$ = list_make2($1, $2); }
   14075             :         ;
   14076             : 
   14077             : rowsfrom_list:
   14078         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14079         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14080             :         ;
   14081             : 
   14082          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14083         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14084             :         ;
   14085             : 
   14086        1086 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14087       50658 :             | /*EMPTY*/                             { $$ = false; }
   14088             :         ;
   14089             : 
   14090             : 
   14091             : where_clause:
   14092      214610 :             WHERE a_expr                            { $$ = $2; }
   14093      292864 :             | /*EMPTY*/                             { $$ = NULL; }
   14094             :         ;
   14095             : 
   14096             : /* variant for UPDATE and DELETE */
   14097             : where_or_current_clause:
   14098       13324 :             WHERE a_expr                            { $$ = $2; }
   14099             :             | WHERE CURRENT_P OF cursor_name
   14100             :                 {
   14101         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14102             : 
   14103             :                     /* cvarno is filled in by parse analysis */
   14104         266 :                     n->cursor_name = $4;
   14105         266 :                     n->cursor_param = 0;
   14106         266 :                     $$ = (Node *) n;
   14107             :                 }
   14108        5016 :             | /*EMPTY*/                             { $$ = NULL; }
   14109             :         ;
   14110             : 
   14111             : 
   14112             : OptTableFuncElementList:
   14113         746 :             TableFuncElementList                { $$ = $1; }
   14114        3786 :             | /*EMPTY*/                         { $$ = NIL; }
   14115             :         ;
   14116             : 
   14117             : TableFuncElementList:
   14118             :             TableFuncElement
   14119             :                 {
   14120        1560 :                     $$ = list_make1($1);
   14121             :                 }
   14122             :             | TableFuncElementList ',' TableFuncElement
   14123             :                 {
   14124        2098 :                     $$ = lappend($1, $3);
   14125             :                 }
   14126             :         ;
   14127             : 
   14128             : TableFuncElement:   ColId Typename opt_collate_clause
   14129             :                 {
   14130        3722 :                     ColumnDef *n = makeNode(ColumnDef);
   14131             : 
   14132        3722 :                     n->colname = $1;
   14133        3722 :                     n->typeName = $2;
   14134        3722 :                     n->inhcount = 0;
   14135        3722 :                     n->is_local = true;
   14136        3722 :                     n->is_not_null = false;
   14137        3722 :                     n->is_from_type = false;
   14138        3722 :                     n->storage = 0;
   14139        3722 :                     n->raw_default = NULL;
   14140        3722 :                     n->cooked_default = NULL;
   14141        3722 :                     n->collClause = (CollateClause *) $3;
   14142        3722 :                     n->collOid = InvalidOid;
   14143        3722 :                     n->constraints = NIL;
   14144        3722 :                     n->location = @1;
   14145        3722 :                     $$ = (Node *) n;
   14146             :                 }
   14147             :         ;
   14148             : 
   14149             : /*
   14150             :  * XMLTABLE
   14151             :  */
   14152             : xmltable:
   14153             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14154             :                 {
   14155         202 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14156             : 
   14157         202 :                     n->rowexpr = $3;
   14158         202 :                     n->docexpr = $4;
   14159         202 :                     n->columns = $6;
   14160         202 :                     n->namespaces = NIL;
   14161         202 :                     n->location = @1;
   14162         202 :                     $$ = (Node *) n;
   14163             :                 }
   14164             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14165             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14166             :                 {
   14167          22 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14168             : 
   14169          22 :                     n->rowexpr = $8;
   14170          22 :                     n->docexpr = $9;
   14171          22 :                     n->columns = $11;
   14172          22 :                     n->namespaces = $5;
   14173          22 :                     n->location = @1;
   14174          22 :                     $$ = (Node *) n;
   14175             :                 }
   14176             :         ;
   14177             : 
   14178         224 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14179         544 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14180             :         ;
   14181             : 
   14182             : xmltable_column_el:
   14183             :             ColId Typename
   14184             :                 {
   14185         198 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14186             : 
   14187         198 :                     fc->colname = $1;
   14188         198 :                     fc->for_ordinality = false;
   14189         198 :                     fc->typeName = $2;
   14190         198 :                     fc->is_not_null = false;
   14191         198 :                     fc->colexpr = NULL;
   14192         198 :                     fc->coldefexpr = NULL;
   14193         198 :                     fc->location = @1;
   14194             : 
   14195         198 :                     $$ = (Node *) fc;
   14196             :                 }
   14197             :             | ColId Typename xmltable_column_option_list
   14198             :                 {
   14199         506 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14200             :                     ListCell   *option;
   14201         506 :                     bool        nullability_seen = false;
   14202             : 
   14203         506 :                     fc->colname = $1;
   14204         506 :                     fc->typeName = $2;
   14205         506 :                     fc->for_ordinality = false;
   14206         506 :                     fc->is_not_null = false;
   14207         506 :                     fc->colexpr = NULL;
   14208         506 :                     fc->coldefexpr = NULL;
   14209         506 :                     fc->location = @1;
   14210             : 
   14211        1128 :                     foreach(option, $3)
   14212             :                     {
   14213         622 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14214             : 
   14215         622 :                         if (strcmp(defel->defname, "default") == 0)
   14216             :                         {
   14217          58 :                             if (fc->coldefexpr != NULL)
   14218           0 :                                 ereport(ERROR,
   14219             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14220             :                                          errmsg("only one DEFAULT value is allowed"),
   14221             :                                          parser_errposition(defel->location)));
   14222          58 :                             fc->coldefexpr = defel->arg;
   14223             :                         }
   14224         564 :                         else if (strcmp(defel->defname, "path") == 0)
   14225             :                         {
   14226         506 :                             if (fc->colexpr != NULL)
   14227           0 :                                 ereport(ERROR,
   14228             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14229             :                                          errmsg("only one PATH value per column is allowed"),
   14230             :                                          parser_errposition(defel->location)));
   14231         506 :                             fc->colexpr = defel->arg;
   14232             :                         }
   14233          58 :                         else if (strcmp(defel->defname, "is_not_null") == 0)
   14234             :                         {
   14235          58 :                             if (nullability_seen)
   14236           0 :                                 ereport(ERROR,
   14237             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14238             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14239             :                                          parser_errposition(defel->location)));
   14240          58 :                             fc->is_not_null = boolVal(defel->arg);
   14241          58 :                             nullability_seen = true;
   14242             :                         }
   14243             :                         else
   14244             :                         {
   14245           0 :                             ereport(ERROR,
   14246             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14247             :                                      errmsg("unrecognized column option \"%s\"",
   14248             :                                             defel->defname),
   14249             :                                      parser_errposition(defel->location)));
   14250             :                         }
   14251             :                     }
   14252         506 :                     $$ = (Node *) fc;
   14253             :                 }
   14254             :             | ColId FOR ORDINALITY
   14255             :                 {
   14256          64 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14257             : 
   14258          64 :                     fc->colname = $1;
   14259          64 :                     fc->for_ordinality = true;
   14260             :                     /* other fields are ignored, initialized by makeNode */
   14261          64 :                     fc->location = @1;
   14262             : 
   14263          64 :                     $$ = (Node *) fc;
   14264             :                 }
   14265             :         ;
   14266             : 
   14267             : xmltable_column_option_list:
   14268             :             xmltable_column_option_el
   14269         506 :                 { $$ = list_make1($1); }
   14270             :             | xmltable_column_option_list xmltable_column_option_el
   14271         116 :                 { $$ = lappend($1, $2); }
   14272             :         ;
   14273             : 
   14274             : xmltable_column_option_el:
   14275             :             IDENT b_expr
   14276           0 :                 { $$ = makeDefElem($1, $2, @1); }
   14277             :             | DEFAULT b_expr
   14278          58 :                 { $$ = makeDefElem("default", $2, @1); }
   14279             :             | NOT NULL_P
   14280          58 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
   14281             :             | NULL_P
   14282           0 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
   14283             :             | PATH b_expr
   14284         506 :                 { $$ = makeDefElem("path", $2, @1); }
   14285             :         ;
   14286             : 
   14287             : xml_namespace_list:
   14288             :             xml_namespace_el
   14289          22 :                 { $$ = list_make1($1); }
   14290             :             | xml_namespace_list ',' xml_namespace_el
   14291           0 :                 { $$ = lappend($1, $3); }
   14292             :         ;
   14293             : 
   14294             : xml_namespace_el:
   14295             :             b_expr AS ColLabel
   14296             :                 {
   14297          16 :                     $$ = makeNode(ResTarget);
   14298          16 :                     $$->name = $3;
   14299          16 :                     $$->indirection = NIL;
   14300          16 :                     $$->val = $1;
   14301          16 :                     $$->location = @1;
   14302             :                 }
   14303             :             | DEFAULT b_expr
   14304             :                 {
   14305           6 :                     $$ = makeNode(ResTarget);
   14306           6 :                     $$->name = NULL;
   14307           6 :                     $$->indirection = NIL;
   14308           6 :                     $$->val = $2;
   14309           6 :                     $$->location = @1;
   14310             :                 }
   14311             :         ;
   14312             : 
   14313             : json_table:
   14314             :             JSON_TABLE '('
   14315             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14316             :                 json_passing_clause_opt
   14317             :                 COLUMNS '(' json_table_column_definition_list ')'
   14318             :                 json_on_error_clause_opt
   14319             :             ')'
   14320             :                 {
   14321         530 :                     JsonTable *n = makeNode(JsonTable);
   14322             :                     char      *pathstring;
   14323             : 
   14324         530 :                     n->context_item = (JsonValueExpr *) $3;
   14325         530 :                     if (!IsA($5, A_Const) ||
   14326         524 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14327           6 :                         ereport(ERROR,
   14328             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14329             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14330             :                                 parser_errposition(@5));
   14331         524 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14332         524 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14333         524 :                     n->passing = $7;
   14334         524 :                     n->columns = $10;
   14335         524 :                     n->on_error = (JsonBehavior *) $12;
   14336         524 :                     n->location = @1;
   14337         524 :                     $$ = (Node *) n;
   14338             :                 }
   14339             :         ;
   14340             : 
   14341             : json_table_path_name_opt:
   14342          62 :             AS name         { $$ = $2; }
   14343         480 :             | /* empty */   { $$ = NULL; }
   14344             :         ;
   14345             : 
   14346             : json_table_column_definition_list:
   14347             :             json_table_column_definition
   14348         820 :                 { $$ = list_make1($1); }
   14349             :             | json_table_column_definition_list ',' json_table_column_definition
   14350         528 :                 { $$ = lappend($1, $3); }
   14351             :         ;
   14352             : 
   14353             : json_table_column_definition:
   14354             :             ColId FOR ORDINALITY
   14355             :                 {
   14356          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14357             : 
   14358          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14359          84 :                     n->name = $1;
   14360          84 :                     n->location = @1;
   14361          84 :                     $$ = (Node *) n;
   14362             :                 }
   14363             :             | ColId Typename
   14364             :                 json_table_column_path_clause_opt
   14365             :                 json_wrapper_behavior
   14366             :                 json_quotes_clause_opt
   14367             :                 json_behavior_clause_opt
   14368             :                 {
   14369         728 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14370             : 
   14371         728 :                     n->coltype = JTC_REGULAR;
   14372         728 :                     n->name = $1;
   14373         728 :                     n->typeName = $2;
   14374         728 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14375         728 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14376         728 :                     n->wrapper = $4;
   14377         728 :                     n->quotes = $5;
   14378         728 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14379         728 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14380         728 :                     n->location = @1;
   14381         728 :                     $$ = (Node *) n;
   14382             :                 }
   14383             :             | ColId Typename json_format_clause
   14384             :                 json_table_column_path_clause_opt
   14385             :                 json_wrapper_behavior
   14386             :                 json_quotes_clause_opt
   14387             :                 json_behavior_clause_opt
   14388             :                 {
   14389         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14390             : 
   14391         108 :                     n->coltype = JTC_FORMATTED;
   14392         108 :                     n->name = $1;
   14393         108 :                     n->typeName = $2;
   14394         108 :                     n->format = (JsonFormat *) $3;
   14395         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14396         108 :                     n->wrapper = $5;
   14397         108 :                     n->quotes = $6;
   14398         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14399         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14400         108 :                     n->location = @1;
   14401         108 :                     $$ = (Node *) n;
   14402             :                 }
   14403             :             | ColId Typename
   14404             :                 EXISTS json_table_column_path_clause_opt
   14405             :                 json_on_error_clause_opt
   14406             :                 {
   14407         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14408             : 
   14409         138 :                     n->coltype = JTC_EXISTS;
   14410         138 :                     n->name = $1;
   14411         138 :                     n->typeName = $2;
   14412         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14413         138 :                     n->wrapper = JSW_NONE;
   14414         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14415         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14416         138 :                     n->on_empty = NULL;
   14417         138 :                     n->on_error = (JsonBehavior *) $5;
   14418         138 :                     n->location = @1;
   14419         138 :                     $$ = (Node *) n;
   14420             :                 }
   14421             :             | NESTED path_opt Sconst
   14422             :                 COLUMNS '(' json_table_column_definition_list ')'
   14423             :                 {
   14424         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14425             : 
   14426         144 :                     n->coltype = JTC_NESTED;
   14427         288 :                     n->pathspec = (JsonTablePathSpec *)
   14428         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14429         144 :                     n->columns = $6;
   14430         144 :                     n->location = @1;
   14431         144 :                     $$ = (Node *) n;
   14432             :                 }
   14433             :             | NESTED path_opt Sconst AS name
   14434             :                 COLUMNS '(' json_table_column_definition_list ')'
   14435             :                 {
   14436         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14437             : 
   14438         146 :                     n->coltype = JTC_NESTED;
   14439         292 :                     n->pathspec = (JsonTablePathSpec *)
   14440         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14441         146 :                     n->columns = $8;
   14442         146 :                     n->location = @1;
   14443         146 :                     $$ = (Node *) n;
   14444             :                 }
   14445             :         ;
   14446             : 
   14447             : path_opt:
   14448             :             PATH
   14449             :             | /* EMPTY */
   14450             :         ;
   14451             : 
   14452             : json_table_column_path_clause_opt:
   14453             :             PATH Sconst
   14454         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14455             :             | /* EMPTY */
   14456         152 :                 { $$ = NULL; }
   14457             :         ;
   14458             : 
   14459             : /*****************************************************************************
   14460             :  *
   14461             :  *  Type syntax
   14462             :  *      SQL introduces a large amount of type-specific syntax.
   14463             :  *      Define individual clauses to handle these cases, and use
   14464             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14465             :  *      - thomas 1997-10-10
   14466             :  *
   14467             :  *****************************************************************************/
   14468             : 
   14469             : Typename:   SimpleTypename opt_array_bounds
   14470             :                 {
   14471      537748 :                     $$ = $1;
   14472      537748 :                     $$->arrayBounds = $2;
   14473             :                 }
   14474             :             | SETOF SimpleTypename opt_array_bounds
   14475             :                 {
   14476        2308 :                     $$ = $2;
   14477        2308 :                     $$->arrayBounds = $3;
   14478        2308 :                     $$->setof = true;
   14479             :                 }
   14480             :             /* SQL standard syntax, currently only one-dimensional */
   14481             :             | SimpleTypename ARRAY '[' Iconst ']'
   14482             :                 {
   14483           6 :                     $$ = $1;
   14484           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14485             :                 }
   14486             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14487             :                 {
   14488           0 :                     $$ = $2;
   14489           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14490           0 :                     $$->setof = true;
   14491             :                 }
   14492             :             | SimpleTypename ARRAY
   14493             :                 {
   14494           0 :                     $$ = $1;
   14495           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14496             :                 }
   14497             :             | SETOF SimpleTypename ARRAY
   14498             :                 {
   14499           0 :                     $$ = $2;
   14500           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14501           0 :                     $$->setof = true;
   14502             :                 }
   14503             :         ;
   14504             : 
   14505             : opt_array_bounds:
   14506             :             opt_array_bounds '[' ']'
   14507       16784 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14508             :             | opt_array_bounds '[' Iconst ']'
   14509          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14510             :             | /*EMPTY*/
   14511      540056 :                     {  $$ = NIL; }
   14512             :         ;
   14513             : 
   14514             : SimpleTypename:
   14515      405512 :             GenericType                             { $$ = $1; }
   14516      119368 :             | Numeric                               { $$ = $1; }
   14517        1922 :             | Bit                                   { $$ = $1; }
   14518        3222 :             | Character                             { $$ = $1; }
   14519        4904 :             | ConstDatetime                         { $$ = $1; }
   14520             :             | ConstInterval opt_interval
   14521             :                 {
   14522        3704 :                     $$ = $1;
   14523        3704 :                     $$->typmods = $2;
   14524             :                 }
   14525             :             | ConstInterval '(' Iconst ')'
   14526             :                 {
   14527           0 :                     $$ = $1;
   14528           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14529             :                                              makeIntConst($3, @3));
   14530             :                 }
   14531        1892 :             | JsonType                              { $$ = $1; }
   14532             :         ;
   14533             : 
   14534             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14535             :  * types such as CHAR() and BIT() to an unspecified length.
   14536             :  * SQL9x requires that these default to a length of one, but this
   14537             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14538             :  * where there is an obvious better choice to make.
   14539             :  * Note that ConstInterval is not included here since it must
   14540             :  * be pushed up higher in the rules to accommodate the postfix
   14541             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14542             :  * the generic-type-name case in AexprConst to avoid premature
   14543             :  * reduce/reduce conflicts against function names.
   14544             :  */
   14545             : ConstTypename:
   14546          78 :             Numeric                                 { $$ = $1; }
   14547           0 :             | ConstBit                              { $$ = $1; }
   14548          34 :             | ConstCharacter                        { $$ = $1; }
   14549        2738 :             | ConstDatetime                         { $$ = $1; }
   14550         264 :             | JsonType                              { $$ = $1; }
   14551             :         ;
   14552             : 
   14553             : /*
   14554             :  * GenericType covers all type names that don't have special syntax mandated
   14555             :  * by the standard, including qualified names.  We also allow type modifiers.
   14556             :  * To avoid parsing conflicts against function invocations, the modifiers
   14557             :  * have to be shown as expr_list here, but parse analysis will only accept
   14558             :  * constants for them.
   14559             :  */
   14560             : GenericType:
   14561             :             type_function_name opt_type_modifiers
   14562             :                 {
   14563      284456 :                     $$ = makeTypeName($1);
   14564      284456 :                     $$->typmods = $2;
   14565      284456 :                     $$->location = @1;
   14566             :                 }
   14567             :             | type_function_name attrs opt_type_modifiers
   14568             :                 {
   14569      121056 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14570      121056 :                     $$->typmods = $3;
   14571      121056 :                     $$->location = @1;
   14572             :                 }
   14573             :         ;
   14574             : 
   14575        1396 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14576      410284 :                     | /* EMPTY */                   { $$ = NIL; }
   14577             :         ;
   14578             : 
   14579             : /*
   14580             :  * SQL numeric data types
   14581             :  */
   14582             : Numeric:    INT_P
   14583             :                 {
   14584       37972 :                     $$ = SystemTypeName("int4");
   14585       37972 :                     $$->location = @1;
   14586             :                 }
   14587             :             | INTEGER
   14588             :                 {
   14589       37954 :                     $$ = SystemTypeName("int4");
   14590       37954 :                     $$->location = @1;
   14591             :                 }
   14592             :             | SMALLINT
   14593             :                 {
   14594        1310 :                     $$ = SystemTypeName("int2");
   14595        1310 :                     $$->location = @1;
   14596             :                 }
   14597             :             | BIGINT
   14598             :                 {
   14599        5168 :                     $$ = SystemTypeName("int8");
   14600        5168 :                     $$->location = @1;
   14601             :                 }
   14602             :             | REAL
   14603             :                 {
   14604       13094 :                     $$ = SystemTypeName("float4");
   14605       13094 :                     $$->location = @1;
   14606             :                 }
   14607             :             | FLOAT_P opt_float
   14608             :                 {
   14609         726 :                     $$ = $2;
   14610         726 :                     $$->location = @1;
   14611             :                 }
   14612             :             | DOUBLE_P PRECISION
   14613             :                 {
   14614         906 :                     $$ = SystemTypeName("float8");
   14615         906 :                     $$->location = @1;
   14616             :                 }
   14617             :             | DECIMAL_P opt_type_modifiers
   14618             :                 {
   14619          36 :                     $$ = SystemTypeName("numeric");
   14620          36 :                     $$->typmods = $2;
   14621          36 :                     $$->location = @1;
   14622             :                 }
   14623             :             | DEC opt_type_modifiers
   14624             :                 {
   14625           0 :                     $$ = SystemTypeName("numeric");
   14626           0 :                     $$->typmods = $2;
   14627           0 :                     $$->location = @1;
   14628             :                 }
   14629             :             | NUMERIC opt_type_modifiers
   14630             :                 {
   14631        6132 :                     $$ = SystemTypeName("numeric");
   14632        6132 :                     $$->typmods = $2;
   14633        6132 :                     $$->location = @1;
   14634             :                 }
   14635             :             | BOOLEAN_P
   14636             :                 {
   14637       16148 :                     $$ = SystemTypeName("bool");
   14638       16148 :                     $$->location = @1;
   14639             :                 }
   14640             :         ;
   14641             : 
   14642             : opt_float:  '(' Iconst ')'
   14643             :                 {
   14644             :                     /*
   14645             :                      * Check FLOAT() precision limits assuming IEEE floating
   14646             :                      * types - thomas 1997-09-18
   14647             :                      */
   14648           2 :                     if ($2 < 1)
   14649           0 :                         ereport(ERROR,
   14650             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14651             :                                  errmsg("precision for type float must be at least 1 bit"),
   14652             :                                  parser_errposition(@2)));
   14653           2 :                     else if ($2 <= 24)
   14654           2 :                         $$ = SystemTypeName("float4");
   14655           0 :                     else if ($2 <= 53)
   14656           0 :                         $$ = SystemTypeName("float8");
   14657             :                     else
   14658           0 :                         ereport(ERROR,
   14659             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14660             :                                  errmsg("precision for type float must be less than 54 bits"),
   14661             :                                  parser_errposition(@2)));
   14662             :                 }
   14663             :             | /*EMPTY*/
   14664             :                 {
   14665         724 :                     $$ = SystemTypeName("float8");
   14666             :                 }
   14667             :         ;
   14668             : 
   14669             : /*
   14670             :  * SQL bit-field data types
   14671             :  * The following implements BIT() and BIT VARYING().
   14672             :  */
   14673             : Bit:        BitWithLength
   14674             :                 {
   14675        1710 :                     $$ = $1;
   14676             :                 }
   14677             :             | BitWithoutLength
   14678             :                 {
   14679         212 :                     $$ = $1;
   14680             :                 }
   14681             :         ;
   14682             : 
   14683             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14684             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14685             : ConstBit:   BitWithLength
   14686             :                 {
   14687           0 :                     $$ = $1;
   14688             :                 }
   14689             :             | BitWithoutLength
   14690             :                 {
   14691           0 :                     $$ = $1;
   14692           0 :                     $$->typmods = NIL;
   14693             :                 }
   14694             :         ;
   14695             : 
   14696             : BitWithLength:
   14697             :             BIT opt_varying '(' expr_list ')'
   14698             :                 {
   14699             :                     char *typname;
   14700             : 
   14701        1710 :                     typname = $2 ? "varbit" : "bit";
   14702        1710 :                     $$ = SystemTypeName(typname);
   14703        1710 :                     $$->typmods = $4;
   14704        1710 :                     $$->location = @1;
   14705             :                 }
   14706             :         ;
   14707             : 
   14708             : BitWithoutLength:
   14709             :             BIT opt_varying
   14710             :                 {
   14711             :                     /* bit defaults to bit(1), varbit to no limit */
   14712         212 :                     if ($2)
   14713             :                     {
   14714          26 :                         $$ = SystemTypeName("varbit");
   14715             :                     }
   14716             :                     else
   14717             :                     {
   14718         186 :                         $$ = SystemTypeName("bit");
   14719         186 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14720             :                     }
   14721         212 :                     $$->location = @1;
   14722             :                 }
   14723             :         ;
   14724             : 
   14725             : 
   14726             : /*
   14727             :  * SQL character data types
   14728             :  * The following implements CHAR() and VARCHAR().
   14729             :  */
   14730             : Character:  CharacterWithLength
   14731             :                 {
   14732        1834 :                     $$ = $1;
   14733             :                 }
   14734             :             | CharacterWithoutLength
   14735             :                 {
   14736        1388 :                     $$ = $1;
   14737             :                 }
   14738             :         ;
   14739             : 
   14740             : ConstCharacter:  CharacterWithLength
   14741             :                 {
   14742          12 :                     $$ = $1;
   14743             :                 }
   14744             :             | CharacterWithoutLength
   14745             :                 {
   14746             :                     /* Length was not specified so allow to be unrestricted.
   14747             :                      * This handles problems with fixed-length (bpchar) strings
   14748             :                      * which in column definitions must default to a length
   14749             :                      * of one, but should not be constrained if the length
   14750             :                      * was not specified.
   14751             :                      */
   14752          22 :                     $$ = $1;
   14753          22 :                     $$->typmods = NIL;
   14754             :                 }
   14755             :         ;
   14756             : 
   14757             : CharacterWithLength:  character '(' Iconst ')'
   14758             :                 {
   14759        1846 :                     $$ = SystemTypeName($1);
   14760        1846 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14761        1846 :                     $$->location = @1;
   14762             :                 }
   14763             :         ;
   14764             : 
   14765             : CharacterWithoutLength:  character
   14766             :                 {
   14767        1410 :                     $$ = SystemTypeName($1);
   14768             :                     /* char defaults to char(1), varchar to no limit */
   14769        1410 :                     if (strcmp($1, "bpchar") == 0)
   14770         300 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14771        1410 :                     $$->location = @1;
   14772             :                 }
   14773             :         ;
   14774             : 
   14775             : character:  CHARACTER opt_varying
   14776         780 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14777             :             | CHAR_P opt_varying
   14778        1172 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14779             :             | VARCHAR
   14780        1300 :                                         { $$ = "varchar"; }
   14781             :             | NATIONAL CHARACTER opt_varying
   14782           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14783             :             | NATIONAL CHAR_P opt_varying
   14784           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14785             :             | NCHAR opt_varying
   14786           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14787             :         ;
   14788             : 
   14789             : opt_varying:
   14790         546 :             VARYING                                 { $$ = true; }
   14791        3332 :             | /*EMPTY*/                             { $$ = false; }
   14792             :         ;
   14793             : 
   14794             : /*
   14795             :  * SQL date/time types
   14796             :  */
   14797             : ConstDatetime:
   14798             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14799             :                 {
   14800         136 :                     if ($5)
   14801         110 :                         $$ = SystemTypeName("timestamptz");
   14802             :                     else
   14803          26 :                         $$ = SystemTypeName("timestamp");
   14804         136 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14805         136 :                     $$->location = @1;
   14806             :                 }
   14807             :             | TIMESTAMP opt_timezone
   14808             :                 {
   14809        5012 :                     if ($2)
   14810        1382 :                         $$ = SystemTypeName("timestamptz");
   14811             :                     else
   14812        3630 :                         $$ = SystemTypeName("timestamp");
   14813        5012 :                     $$->location = @1;
   14814             :                 }
   14815             :             | TIME '(' Iconst ')' opt_timezone
   14816             :                 {
   14817          26 :                     if ($5)
   14818          10 :                         $$ = SystemTypeName("timetz");
   14819             :                     else
   14820          16 :                         $$ = SystemTypeName("time");
   14821          26 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14822          26 :                     $$->location = @1;
   14823             :                 }
   14824             :             | TIME opt_timezone
   14825             :                 {
   14826        2468 :                     if ($2)
   14827         354 :                         $$ = SystemTypeName("timetz");
   14828             :                     else
   14829        2114 :                         $$ = SystemTypeName("time");
   14830        2468 :                     $$->location = @1;
   14831             :                 }
   14832             :         ;
   14833             : 
   14834             : ConstInterval:
   14835             :             INTERVAL
   14836             :                 {
   14837        7014 :                     $$ = SystemTypeName("interval");
   14838        7014 :                     $$->location = @1;
   14839             :                 }
   14840             :         ;
   14841             : 
   14842             : opt_timezone:
   14843        1856 :             WITH_LA TIME ZONE                       { $$ = true; }
   14844         628 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14845        5158 :             | /*EMPTY*/                             { $$ = false; }
   14846             :         ;
   14847             : 
   14848             : opt_interval:
   14849             :             YEAR_P
   14850          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14851             :             | MONTH_P
   14852          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14853             :             | DAY_P
   14854          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14855             :             | HOUR_P
   14856          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14857             :             | MINUTE_P
   14858          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14859             :             | interval_second
   14860          36 :                 { $$ = $1; }
   14861             :             | YEAR_P TO MONTH_P
   14862             :                 {
   14863          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14864             :                                                  INTERVAL_MASK(MONTH), @1));
   14865             :                 }
   14866             :             | DAY_P TO HOUR_P
   14867             :                 {
   14868          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14869             :                                                  INTERVAL_MASK(HOUR), @1));
   14870             :                 }
   14871             :             | DAY_P TO MINUTE_P
   14872             :                 {
   14873          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14874             :                                                  INTERVAL_MASK(HOUR) |
   14875             :                                                  INTERVAL_MASK(MINUTE), @1));
   14876             :                 }
   14877             :             | DAY_P TO interval_second
   14878             :                 {
   14879          48 :                     $$ = $3;
   14880          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14881             :                                                 INTERVAL_MASK(HOUR) |
   14882             :                                                 INTERVAL_MASK(MINUTE) |
   14883          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14884             :                 }
   14885             :             | HOUR_P TO MINUTE_P
   14886             :                 {
   14887          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14888             :                                                  INTERVAL_MASK(MINUTE), @1));
   14889             :                 }
   14890             :             | HOUR_P TO interval_second
   14891             :                 {
   14892          36 :                     $$ = $3;
   14893          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14894             :                                                 INTERVAL_MASK(MINUTE) |
   14895          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14896             :                 }
   14897             :             | MINUTE_P TO interval_second
   14898             :                 {
   14899          66 :                     $$ = $3;
   14900          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14901          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14902             :                 }
   14903             :             | /*EMPTY*/
   14904        6660 :                 { $$ = NIL; }
   14905             :         ;
   14906             : 
   14907             : interval_second:
   14908             :             SECOND_P
   14909             :                 {
   14910         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14911             :                 }
   14912             :             | SECOND_P '(' Iconst ')'
   14913             :                 {
   14914          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14915             :                                     makeIntConst($3, @3));
   14916             :                 }
   14917             :         ;
   14918             : 
   14919             : JsonType:
   14920             :             JSON
   14921             :                 {
   14922        2156 :                     $$ = SystemTypeName("json");
   14923        2156 :                     $$->location = @1;
   14924             :                 }
   14925             :         ;
   14926             : 
   14927             : /*****************************************************************************
   14928             :  *
   14929             :  *  expression grammar
   14930             :  *
   14931             :  *****************************************************************************/
   14932             : 
   14933             : /*
   14934             :  * General expressions
   14935             :  * This is the heart of the expression syntax.
   14936             :  *
   14937             :  * We have two expression types: a_expr is the unrestricted kind, and
   14938             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14939             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14940             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14941             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14942             :  *
   14943             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14944             :  * always be used by surrounding it with parens.
   14945             :  *
   14946             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14947             :  * it's factored out just to eliminate redundant coding.
   14948             :  *
   14949             :  * Be careful of productions involving more than one terminal token.
   14950             :  * By default, bison will assign such productions the precedence of their
   14951             :  * last terminal, but in nearly all cases you want it to be the precedence
   14952             :  * of the first terminal instead; otherwise you will not get the behavior
   14953             :  * you expect!  So we use %prec annotations freely to set precedences.
   14954             :  */
   14955     3798168 : a_expr:     c_expr                                  { $$ = $1; }
   14956             :             | a_expr TYPECAST Typename
   14957      259494 :                     { $$ = makeTypeCast($1, $3, @2); }
   14958             :             | a_expr COLLATE any_name
   14959             :                 {
   14960        8954 :                     CollateClause *n = makeNode(CollateClause);
   14961             : 
   14962        8954 :                     n->arg = $1;
   14963        8954 :                     n->collname = $3;
   14964        8954 :                     n->location = @2;
   14965        8954 :                     $$ = (Node *) n;
   14966             :                 }
   14967             :             | a_expr AT TIME ZONE a_expr            %prec AT
   14968             :                 {
   14969         408 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14970         408 :                                                list_make2($5, $1),
   14971             :                                                COERCE_SQL_SYNTAX,
   14972         408 :                                                @2);
   14973             :                 }
   14974             :             | a_expr AT LOCAL                       %prec AT
   14975             :                 {
   14976          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14977          42 :                                                list_make1($1),
   14978             :                                                COERCE_SQL_SYNTAX,
   14979             :                                                -1);
   14980             :                 }
   14981             :         /*
   14982             :          * These operators must be called out explicitly in order to make use
   14983             :          * of bison's automatic operator-precedence handling.  All other
   14984             :          * operator names are handled by the generic productions using "Op",
   14985             :          * below; and all those operators will have the same precedence.
   14986             :          *
   14987             :          * If you add more explicitly-known operators, be sure to add them
   14988             :          * also to b_expr and to the MathOp list below.
   14989             :          */
   14990             :             | '+' a_expr                    %prec UMINUS
   14991          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   14992             :             | '-' a_expr                    %prec UMINUS
   14993        9116 :                 { $$ = doNegate($2, @1); }
   14994             :             | a_expr '+' a_expr
   14995       14028 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   14996             :             | a_expr '-' a_expr
   14997        4434 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   14998             :             | a_expr '*' a_expr
   14999        6314 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15000             :             | a_expr '/' a_expr
   15001        3424 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15002             :             | a_expr '%' a_expr
   15003        2824 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15004             :             | a_expr '^' a_expr
   15005         474 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15006             :             | a_expr '<' a_expr
   15007       10400 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15008             :             | a_expr '>' a_expr
   15009       16720 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15010             :             | a_expr '=' a_expr
   15011      398822 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15012             :             | a_expr LESS_EQUALS a_expr
   15013        5272 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15014             :             | a_expr GREATER_EQUALS a_expr
   15015        7174 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15016             :             | a_expr NOT_EQUALS a_expr
   15017       41008 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15018             : 
   15019             :             | a_expr qual_Op a_expr             %prec Op
   15020       58874 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15021             :             | qual_Op a_expr                    %prec Op
   15022         210 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15023             : 
   15024             :             | a_expr AND a_expr
   15025      237716 :                 { $$ = makeAndExpr($1, $3, @2); }
   15026             :             | a_expr OR a_expr
   15027       16590 :                 { $$ = makeOrExpr($1, $3, @2); }
   15028             :             | NOT a_expr
   15029       16736 :                 { $$ = makeNotExpr($2, @1); }
   15030             :             | NOT_LA a_expr                     %prec NOT
   15031           0 :                 { $$ = makeNotExpr($2, @1); }
   15032             : 
   15033             :             | a_expr LIKE a_expr
   15034             :                 {
   15035        1960 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15036        1960 :                                                    $1, $3, @2);
   15037             :                 }
   15038             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15039             :                 {
   15040          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15041          96 :                                                  list_make2($3, $5),
   15042             :                                                  COERCE_EXPLICIT_CALL,
   15043          96 :                                                  @2);
   15044          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15045          96 :                                                    $1, (Node *) n, @2);
   15046             :                 }
   15047             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15048             :                 {
   15049         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15050         198 :                                                    $1, $4, @2);
   15051             :                 }
   15052             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15053             :                 {
   15054          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15055          96 :                                                  list_make2($4, $6),
   15056             :                                                  COERCE_EXPLICIT_CALL,
   15057          96 :                                                  @2);
   15058          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15059          96 :                                                    $1, (Node *) n, @2);
   15060             :                 }
   15061             :             | a_expr ILIKE a_expr
   15062             :                 {
   15063         174 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15064         174 :                                                    $1, $3, @2);
   15065             :                 }
   15066             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15067             :                 {
   15068           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15069           0 :                                                  list_make2($3, $5),
   15070             :                                                  COERCE_EXPLICIT_CALL,
   15071           0 :                                                  @2);
   15072           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15073           0 :                                                    $1, (Node *) n, @2);
   15074             :                 }
   15075             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15076             :                 {
   15077          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15078          30 :                                                    $1, $4, @2);
   15079             :                 }
   15080             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15081             :                 {
   15082           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15083           0 :                                                  list_make2($4, $6),
   15084             :                                                  COERCE_EXPLICIT_CALL,
   15085           0 :                                                  @2);
   15086           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15087           0 :                                                    $1, (Node *) n, @2);
   15088             :                 }
   15089             : 
   15090             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15091             :                 {
   15092          40 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15093          40 :                                                  list_make1($4),
   15094             :                                                  COERCE_EXPLICIT_CALL,
   15095          40 :                                                  @2);
   15096          40 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15097          40 :                                                    $1, (Node *) n, @2);
   15098             :                 }
   15099             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15100             :                 {
   15101          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15102          30 :                                                  list_make2($4, $6),
   15103             :                                                  COERCE_EXPLICIT_CALL,
   15104          30 :                                                  @2);
   15105          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15106          30 :                                                    $1, (Node *) n, @2);
   15107             :                 }
   15108             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15109             :                 {
   15110           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15111           0 :                                                  list_make1($5),
   15112             :                                                  COERCE_EXPLICIT_CALL,
   15113           0 :                                                  @2);
   15114           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15115           0 :                                                    $1, (Node *) n, @2);
   15116             :                 }
   15117             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15118             :                 {
   15119           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15120           0 :                                                  list_make2($5, $7),
   15121             :                                                  COERCE_EXPLICIT_CALL,
   15122           0 :                                                  @2);
   15123           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15124           0 :                                                    $1, (Node *) n, @2);
   15125             :                 }
   15126             : 
   15127             :             /* NullTest clause
   15128             :              * Define SQL-style Null test clause.
   15129             :              * Allow two forms described in the standard:
   15130             :              *  a IS NULL
   15131             :              *  a IS NOT NULL
   15132             :              * Allow two SQL extensions
   15133             :              *  a ISNULL
   15134             :              *  a NOTNULL
   15135             :              */
   15136             :             | a_expr IS NULL_P                          %prec IS
   15137             :                 {
   15138        5268 :                     NullTest   *n = makeNode(NullTest);
   15139             : 
   15140        5268 :                     n->arg = (Expr *) $1;
   15141        5268 :                     n->nulltesttype = IS_NULL;
   15142        5268 :                     n->location = @2;
   15143        5268 :                     $$ = (Node *) n;
   15144             :                 }
   15145             :             | a_expr ISNULL
   15146             :                 {
   15147          96 :                     NullTest   *n = makeNode(NullTest);
   15148             : 
   15149          96 :                     n->arg = (Expr *) $1;
   15150          96 :                     n->nulltesttype = IS_NULL;
   15151          96 :                     n->location = @2;
   15152          96 :                     $$ = (Node *) n;
   15153             :                 }
   15154             :             | a_expr IS NOT NULL_P                      %prec IS
   15155             :                 {
   15156       13152 :                     NullTest   *n = makeNode(NullTest);
   15157             : 
   15158       13152 :                     n->arg = (Expr *) $1;
   15159       13152 :                     n->nulltesttype = IS_NOT_NULL;
   15160       13152 :                     n->location = @2;
   15161       13152 :                     $$ = (Node *) n;
   15162             :                 }
   15163             :             | a_expr NOTNULL
   15164             :                 {
   15165           6 :                     NullTest   *n = makeNode(NullTest);
   15166             : 
   15167           6 :                     n->arg = (Expr *) $1;
   15168           6 :                     n->nulltesttype = IS_NOT_NULL;
   15169           6 :                     n->location = @2;
   15170           6 :                     $$ = (Node *) n;
   15171             :                 }
   15172             :             | row OVERLAPS row
   15173             :                 {
   15174         948 :                     if (list_length($1) != 2)
   15175           0 :                         ereport(ERROR,
   15176             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15177             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15178             :                                  parser_errposition(@1)));
   15179         948 :                     if (list_length($3) != 2)
   15180           0 :                         ereport(ERROR,
   15181             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15182             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15183             :                                  parser_errposition(@3)));
   15184         948 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15185         948 :                                                list_concat($1, $3),
   15186             :                                                COERCE_SQL_SYNTAX,
   15187         948 :                                                @2);
   15188             :                 }
   15189             :             | a_expr IS TRUE_P                          %prec IS
   15190             :                 {
   15191         532 :                     BooleanTest *b = makeNode(BooleanTest);
   15192             : 
   15193         532 :                     b->arg = (Expr *) $1;
   15194         532 :                     b->booltesttype = IS_TRUE;
   15195         532 :                     b->location = @2;
   15196         532 :                     $$ = (Node *) b;
   15197             :                 }
   15198             :             | a_expr IS NOT TRUE_P                      %prec IS
   15199             :                 {
   15200         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15201             : 
   15202         140 :                     b->arg = (Expr *) $1;
   15203         140 :                     b->booltesttype = IS_NOT_TRUE;
   15204         140 :                     b->location = @2;
   15205         140 :                     $$ = (Node *) b;
   15206             :                 }
   15207             :             | a_expr IS FALSE_P                         %prec IS
   15208             :                 {
   15209         136 :                     BooleanTest *b = makeNode(BooleanTest);
   15210             : 
   15211         136 :                     b->arg = (Expr *) $1;
   15212         136 :                     b->booltesttype = IS_FALSE;
   15213         136 :                     b->location = @2;
   15214         136 :                     $$ = (Node *) b;
   15215             :                 }
   15216             :             | a_expr IS NOT FALSE_P                     %prec IS
   15217             :                 {
   15218          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15219             : 
   15220          92 :                     b->arg = (Expr *) $1;
   15221          92 :                     b->booltesttype = IS_NOT_FALSE;
   15222          92 :                     b->location = @2;
   15223          92 :                     $$ = (Node *) b;
   15224             :                 }
   15225             :             | a_expr IS UNKNOWN                         %prec IS
   15226             :                 {
   15227          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15228             : 
   15229          52 :                     b->arg = (Expr *) $1;
   15230          52 :                     b->booltesttype = IS_UNKNOWN;
   15231          52 :                     b->location = @2;
   15232          52 :                     $$ = (Node *) b;
   15233             :                 }
   15234             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15235             :                 {
   15236          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15237             : 
   15238          48 :                     b->arg = (Expr *) $1;
   15239          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15240          48 :                     b->location = @2;
   15241          48 :                     $$ = (Node *) b;
   15242             :                 }
   15243             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15244             :                 {
   15245        1262 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15246             :                 }
   15247             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15248             :                 {
   15249          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15250             :                 }
   15251             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15252             :                 {
   15253         466 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15254             :                                                    "BETWEEN",
   15255         466 :                                                    $1,
   15256         466 :                                                    (Node *) list_make2($4, $6),
   15257         466 :                                                    @2);
   15258             :                 }
   15259             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15260             :                 {
   15261          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15262             :                                                    "NOT BETWEEN",
   15263          12 :                                                    $1,
   15264          12 :                                                    (Node *) list_make2($5, $7),
   15265          12 :                                                    @2);
   15266             :                 }
   15267             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15268             :                 {
   15269          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15270             :                                                    "BETWEEN SYMMETRIC",
   15271          12 :                                                    $1,
   15272          12 :                                                    (Node *) list_make2($4, $6),
   15273          12 :                                                    @2);
   15274             :                 }
   15275             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15276             :                 {
   15277          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15278             :                                                    "NOT BETWEEN SYMMETRIC",
   15279          12 :                                                    $1,
   15280          12 :                                                    (Node *) list_make2($5, $7),
   15281          12 :                                                    @2);
   15282             :                 }
   15283             :             | a_expr IN_P in_expr
   15284             :                 {
   15285             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15286       24236 :                     if (IsA($3, SubLink))
   15287             :                     {
   15288             :                         /* generate foo = ANY (subquery) */
   15289        5394 :                         SubLink    *n = (SubLink *) $3;
   15290             : 
   15291        5394 :                         n->subLinkType = ANY_SUBLINK;
   15292        5394 :                         n->subLinkId = 0;
   15293        5394 :                         n->testexpr = $1;
   15294        5394 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15295        5394 :                         n->location = @2;
   15296        5394 :                         $$ = (Node *) n;
   15297             :                     }
   15298             :                     else
   15299             :                     {
   15300             :                         /* generate scalar IN expression */
   15301       18842 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
   15302             :                     }
   15303             :                 }
   15304             :             | a_expr NOT_LA IN_P in_expr                        %prec NOT_LA
   15305             :                 {
   15306             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15307        2910 :                     if (IsA($4, SubLink))
   15308             :                     {
   15309             :                         /* generate NOT (foo = ANY (subquery)) */
   15310             :                         /* Make an = ANY node */
   15311         120 :                         SubLink    *n = (SubLink *) $4;
   15312             : 
   15313         120 :                         n->subLinkType = ANY_SUBLINK;
   15314         120 :                         n->subLinkId = 0;
   15315         120 :                         n->testexpr = $1;
   15316         120 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15317         120 :                         n->location = @2;
   15318             :                         /* Stick a NOT on top; must have same parse location */
   15319         120 :                         $$ = makeNotExpr((Node *) n, @2);
   15320             :                     }
   15321             :                     else
   15322             :                     {
   15323             :                         /* generate scalar NOT IN expression */
   15324        2790 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
   15325             :                     }
   15326             :                 }
   15327             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15328             :                 {
   15329         168 :                     SubLink    *n = makeNode(SubLink);
   15330             : 
   15331         168 :                     n->subLinkType = $3;
   15332         168 :                     n->subLinkId = 0;
   15333         168 :                     n->testexpr = $1;
   15334         168 :                     n->operName = $2;
   15335         168 :                     n->subselect = $4;
   15336         168 :                     n->location = @2;
   15337         168 :                     $$ = (Node *) n;
   15338             :                 }
   15339             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15340             :                 {
   15341       17370 :                     if ($3 == ANY_SUBLINK)
   15342       17070 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15343             :                     else
   15344         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15345             :                 }
   15346             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15347             :                 {
   15348             :                     /* Not sure how to get rid of the parentheses
   15349             :                      * but there are lots of shift/reduce errors without them.
   15350             :                      *
   15351             :                      * Should be able to implement this by plopping the entire
   15352             :                      * select into a node, then transforming the target expressions
   15353             :                      * from whatever they are into count(*), and testing the
   15354             :                      * entire result equal to one.
   15355             :                      * But, will probably implement a separate node in the executor.
   15356             :                      */
   15357           0 :                     ereport(ERROR,
   15358             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15359             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15360             :                              parser_errposition(@1)));
   15361             :                 }
   15362             :             | a_expr IS DOCUMENT_P                  %prec IS
   15363             :                 {
   15364          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15365          18 :                                      list_make1($1), @2);
   15366             :                 }
   15367             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15368             :                 {
   15369          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15370          18 :                                                  list_make1($1), @2),
   15371          18 :                                      @2);
   15372             :                 }
   15373             :             | a_expr IS NORMALIZED                              %prec IS
   15374             :                 {
   15375          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15376          12 :                                                list_make1($1),
   15377             :                                                COERCE_SQL_SYNTAX,
   15378          12 :                                                @2);
   15379             :                 }
   15380             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15381             :                 {
   15382          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15383          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15384             :                                                COERCE_SQL_SYNTAX,
   15385          36 :                                                @2);
   15386             :                 }
   15387             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15388             :                 {
   15389           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15390           0 :                                                            list_make1($1),
   15391             :                                                            COERCE_SQL_SYNTAX,
   15392           0 :                                                            @2),
   15393           0 :                                      @2);
   15394             :                 }
   15395             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15396             :                 {
   15397           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15398           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15399             :                                                            COERCE_SQL_SYNTAX,
   15400           0 :                                                            @2),
   15401           0 :                                      @2);
   15402             :                 }
   15403             :             | a_expr IS json_predicate_type_constraint
   15404             :                     json_key_uniqueness_constraint_opt      %prec IS
   15405             :                 {
   15406         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15407             : 
   15408         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15409             :                 }
   15410             :             /*
   15411             :              * Required by SQL/JSON, but there are conflicts
   15412             :             | a_expr
   15413             :                 json_format_clause
   15414             :                 IS  json_predicate_type_constraint
   15415             :                     json_key_uniqueness_constraint_opt      %prec IS
   15416             :                 {
   15417             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15418             :                 }
   15419             :             */
   15420             :             | a_expr IS NOT
   15421             :                     json_predicate_type_constraint
   15422             :                     json_key_uniqueness_constraint_opt      %prec IS
   15423             :                 {
   15424          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15425             : 
   15426          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15427             :                 }
   15428             :             /*
   15429             :              * Required by SQL/JSON, but there are conflicts
   15430             :             | a_expr
   15431             :                 json_format_clause
   15432             :                 IS NOT
   15433             :                     json_predicate_type_constraint
   15434             :                     json_key_uniqueness_constraint_opt      %prec IS
   15435             :                 {
   15436             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15437             :                 }
   15438             :             */
   15439             :             | DEFAULT
   15440             :                 {
   15441             :                     /*
   15442             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15443             :                      * expressions", but for us, it's easier to allow it in
   15444             :                      * any a_expr and then throw error during parse analysis
   15445             :                      * if it's in an inappropriate context.  This way also
   15446             :                      * lets us say something smarter than "syntax error".
   15447             :                      */
   15448        1550 :                     SetToDefault *n = makeNode(SetToDefault);
   15449             : 
   15450             :                     /* parse analysis will fill in the rest */
   15451        1550 :                     n->location = @1;
   15452        1550 :                     $$ = (Node *) n;
   15453             :                 }
   15454             :         ;
   15455             : 
   15456             : /*
   15457             :  * Restricted expressions
   15458             :  *
   15459             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15460             :  *
   15461             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15462             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15463             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15464             :  */
   15465             : b_expr:     c_expr
   15466        3844 :                 { $$ = $1; }
   15467             :             | b_expr TYPECAST Typename
   15468         228 :                 { $$ = makeTypeCast($1, $3, @2); }
   15469             :             | '+' b_expr                    %prec UMINUS
   15470           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15471             :             | '-' b_expr                    %prec UMINUS
   15472          66 :                 { $$ = doNegate($2, @1); }
   15473             :             | b_expr '+' b_expr
   15474          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15475             :             | b_expr '-' b_expr
   15476          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15477             :             | b_expr '*' b_expr
   15478          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15479             :             | b_expr '/' b_expr
   15480           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15481             :             | b_expr '%' b_expr
   15482           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15483             :             | b_expr '^' b_expr
   15484           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15485             :             | b_expr '<' b_expr
   15486           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15487             :             | b_expr '>' b_expr
   15488           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15489             :             | b_expr '=' b_expr
   15490           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15491             :             | b_expr LESS_EQUALS b_expr
   15492           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15493             :             | b_expr GREATER_EQUALS b_expr
   15494           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15495             :             | b_expr NOT_EQUALS b_expr
   15496           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15497             :             | b_expr qual_Op b_expr             %prec Op
   15498          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15499             :             | qual_Op b_expr                    %prec Op
   15500           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15501             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15502             :                 {
   15503           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15504             :                 }
   15505             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15506             :                 {
   15507           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15508             :                 }
   15509             :             | b_expr IS DOCUMENT_P                  %prec IS
   15510             :                 {
   15511           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15512           0 :                                      list_make1($1), @2);
   15513             :                 }
   15514             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15515             :                 {
   15516           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15517           0 :                                                  list_make1($1), @2),
   15518           0 :                                      @2);
   15519             :                 }
   15520             :         ;
   15521             : 
   15522             : /*
   15523             :  * Productions that can be used in both a_expr and b_expr.
   15524             :  *
   15525             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15526             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15527             :  * inside parentheses, such as function arguments; that cannot introduce
   15528             :  * ambiguity to the b_expr syntax.
   15529             :  */
   15530     1861910 : c_expr:     columnref                               { $$ = $1; }
   15531     1312340 :             | AexprConst                            { $$ = $1; }
   15532             :             | PARAM opt_indirection
   15533             :                 {
   15534       46132 :                     ParamRef   *p = makeNode(ParamRef);
   15535             : 
   15536       46132 :                     p->number = $1;
   15537       46132 :                     p->location = @1;
   15538       46132 :                     if ($2)
   15539             :                     {
   15540        1074 :                         A_Indirection *n = makeNode(A_Indirection);
   15541             : 
   15542        1074 :                         n->arg = (Node *) p;
   15543        1074 :                         n->indirection = check_indirection($2, yyscanner);
   15544        1074 :                         $$ = (Node *) n;
   15545             :                     }
   15546             :                     else
   15547       45058 :                         $$ = (Node *) p;
   15548             :                 }
   15549             :             | '(' a_expr ')' opt_indirection
   15550             :                 {
   15551       92072 :                     if ($4)
   15552             :                     {
   15553       12036 :                         A_Indirection *n = makeNode(A_Indirection);
   15554             : 
   15555       12036 :                         n->arg = $2;
   15556       12036 :                         n->indirection = check_indirection($4, yyscanner);
   15557       12036 :                         $$ = (Node *) n;
   15558             :                     }
   15559             :                     else
   15560       80036 :                         $$ = $2;
   15561             :                 }
   15562             :             | case_expr
   15563       39560 :                 { $$ = $1; }
   15564             :             | func_expr
   15565      392360 :                 { $$ = $1; }
   15566             :             | select_with_parens            %prec UMINUS
   15567             :                 {
   15568       28816 :                     SubLink    *n = makeNode(SubLink);
   15569             : 
   15570       28816 :                     n->subLinkType = EXPR_SUBLINK;
   15571       28816 :                     n->subLinkId = 0;
   15572       28816 :                     n->testexpr = NULL;
   15573       28816 :                     n->operName = NIL;
   15574       28816 :                     n->subselect = $1;
   15575       28816 :                     n->location = @1;
   15576       28816 :                     $$ = (Node *) n;
   15577             :                 }
   15578             :             | select_with_parens indirection
   15579             :                 {
   15580             :                     /*
   15581             :                      * Because the select_with_parens nonterminal is designed
   15582             :                      * to "eat" as many levels of parens as possible, the
   15583             :                      * '(' a_expr ')' opt_indirection production above will
   15584             :                      * fail to match a sub-SELECT with indirection decoration;
   15585             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15586             :                      * as there are parens around it.  To support applying
   15587             :                      * subscripting or field selection to a sub-SELECT result,
   15588             :                      * we need this redundant-looking production.
   15589             :                      */
   15590          18 :                     SubLink    *n = makeNode(SubLink);
   15591          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15592             : 
   15593          18 :                     n->subLinkType = EXPR_SUBLINK;
   15594          18 :                     n->subLinkId = 0;
   15595          18 :                     n->testexpr = NULL;
   15596          18 :                     n->operName = NIL;
   15597          18 :                     n->subselect = $1;
   15598          18 :                     n->location = @1;
   15599          18 :                     a->arg = (Node *) n;
   15600          18 :                     a->indirection = check_indirection($2, yyscanner);
   15601          18 :                     $$ = (Node *) a;
   15602             :                 }
   15603             :             | EXISTS select_with_parens
   15604             :                 {
   15605        6436 :                     SubLink    *n = makeNode(SubLink);
   15606             : 
   15607        6436 :                     n->subLinkType = EXISTS_SUBLINK;
   15608        6436 :                     n->subLinkId = 0;
   15609        6436 :                     n->testexpr = NULL;
   15610        6436 :                     n->operName = NIL;
   15611        6436 :                     n->subselect = $2;
   15612        6436 :                     n->location = @1;
   15613        6436 :                     $$ = (Node *) n;
   15614             :                 }
   15615             :             | ARRAY select_with_parens
   15616             :                 {
   15617        8938 :                     SubLink    *n = makeNode(SubLink);
   15618             : 
   15619        8938 :                     n->subLinkType = ARRAY_SUBLINK;
   15620        8938 :                     n->subLinkId = 0;
   15621        8938 :                     n->testexpr = NULL;
   15622        8938 :                     n->operName = NIL;
   15623        8938 :                     n->subselect = $2;
   15624        8938 :                     n->location = @1;
   15625        8938 :                     $$ = (Node *) n;
   15626             :                 }
   15627             :             | ARRAY array_expr
   15628             :                 {
   15629        7398 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15630             : 
   15631             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15632        7398 :                     n->location = @1;
   15633        7398 :                     $$ = (Node *) n;
   15634             :                 }
   15635             :             | explicit_row
   15636             :                 {
   15637        3804 :                     RowExpr    *r = makeNode(RowExpr);
   15638             : 
   15639        3804 :                     r->args = $1;
   15640        3804 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15641        3804 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15642        3804 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15643        3804 :                     r->location = @1;
   15644        3804 :                     $$ = (Node *) r;
   15645             :                 }
   15646             :             | implicit_row
   15647             :                 {
   15648        2532 :                     RowExpr    *r = makeNode(RowExpr);
   15649             : 
   15650        2532 :                     r->args = $1;
   15651        2532 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15652        2532 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15653        2532 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15654        2532 :                     r->location = @1;
   15655        2532 :                     $$ = (Node *) r;
   15656             :                 }
   15657             :             | GROUPING '(' expr_list ')'
   15658             :               {
   15659         362 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15660             : 
   15661         362 :                   g->args = $3;
   15662         362 :                   g->location = @1;
   15663         362 :                   $$ = (Node *) g;
   15664             :               }
   15665             :         ;
   15666             : 
   15667             : func_application: func_name '(' ')'
   15668             :                 {
   15669       32166 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15670             :                                                COERCE_EXPLICIT_CALL,
   15671       32166 :                                                @1);
   15672             :                 }
   15673             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15674             :                 {
   15675      324030 :                     FuncCall   *n = makeFuncCall($1, $3,
   15676             :                                                  COERCE_EXPLICIT_CALL,
   15677      324030 :                                                  @1);
   15678             : 
   15679      324030 :                     n->agg_order = $4;
   15680      324030 :                     $$ = (Node *) n;
   15681             :                 }
   15682             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15683             :                 {
   15684         614 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15685             :                                                  COERCE_EXPLICIT_CALL,
   15686         614 :                                                  @1);
   15687             : 
   15688         614 :                     n->func_variadic = true;
   15689         614 :                     n->agg_order = $5;
   15690         614 :                     $$ = (Node *) n;
   15691             :                 }
   15692             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15693             :                 {
   15694         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15695             :                                                  COERCE_EXPLICIT_CALL,
   15696         120 :                                                  @1);
   15697             : 
   15698         120 :                     n->func_variadic = true;
   15699         120 :                     n->agg_order = $7;
   15700         120 :                     $$ = (Node *) n;
   15701             :                 }
   15702             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15703             :                 {
   15704           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15705             :                                                  COERCE_EXPLICIT_CALL,
   15706           0 :                                                  @1);
   15707             : 
   15708           0 :                     n->agg_order = $5;
   15709             :                     /* Ideally we'd mark the FuncCall node to indicate
   15710             :                      * "must be an aggregate", but there's no provision
   15711             :                      * for that in FuncCall at the moment.
   15712             :                      */
   15713           0 :                     $$ = (Node *) n;
   15714             :                 }
   15715             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15716             :                 {
   15717         550 :                     FuncCall   *n = makeFuncCall($1, $4,
   15718             :                                                  COERCE_EXPLICIT_CALL,
   15719         550 :                                                  @1);
   15720             : 
   15721         550 :                     n->agg_order = $5;
   15722         550 :                     n->agg_distinct = true;
   15723         550 :                     $$ = (Node *) n;
   15724             :                 }
   15725             :             | func_name '(' '*' ')'
   15726             :                 {
   15727             :                     /*
   15728             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15729             :                      * aggregate.  This does the right thing for COUNT(*),
   15730             :                      * and there are no other aggregates in SQL that accept
   15731             :                      * '*' as parameter.
   15732             :                      *
   15733             :                      * The FuncCall node is also marked agg_star = true,
   15734             :                      * so that later processing can detect what the argument
   15735             :                      * really was.
   15736             :                      */
   15737       12566 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15738             :                                                  COERCE_EXPLICIT_CALL,
   15739       12566 :                                                  @1);
   15740             : 
   15741       12566 :                     n->agg_star = true;
   15742       12566 :                     $$ = (Node *) n;
   15743             :                 }
   15744             :         ;
   15745             : 
   15746             : 
   15747             : /*
   15748             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15749             :  * so that we have classifications for "everything that is a function call or
   15750             :  * looks like one".  This isn't very important, but it saves us having to
   15751             :  * document which variants are legal in places like "FROM function()" or the
   15752             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15753             :  * (Note that many of the special SQL functions wouldn't actually make any
   15754             :  * sense as functional index entries, but we ignore that consideration here.)
   15755             :  */
   15756             : func_expr: func_application within_group_clause filter_clause over_clause
   15757             :                 {
   15758      317112 :                     FuncCall   *n = (FuncCall *) $1;
   15759             : 
   15760             :                     /*
   15761             :                      * The order clause for WITHIN GROUP and the one for
   15762             :                      * plain-aggregate ORDER BY share a field, so we have to
   15763             :                      * check here that at most one is present.  We also check
   15764             :                      * for DISTINCT and VARIADIC here to give a better error
   15765             :                      * location.  Other consistency checks are deferred to
   15766             :                      * parse analysis.
   15767             :                      */
   15768      317112 :                     if ($2 != NIL)
   15769             :                     {
   15770         348 :                         if (n->agg_order != NIL)
   15771           6 :                             ereport(ERROR,
   15772             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15773             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15774             :                                      parser_errposition(@2)));
   15775         342 :                         if (n->agg_distinct)
   15776           0 :                             ereport(ERROR,
   15777             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15778             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15779             :                                      parser_errposition(@2)));
   15780         342 :                         if (n->func_variadic)
   15781           0 :                             ereport(ERROR,
   15782             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15783             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15784             :                                      parser_errposition(@2)));
   15785         342 :                         n->agg_order = $2;
   15786         342 :                         n->agg_within_group = true;
   15787             :                     }
   15788      317106 :                     n->agg_filter = $3;
   15789      317106 :                     n->over = $4;
   15790      317106 :                     $$ = (Node *) n;
   15791             :                 }
   15792             :             | json_aggregate_func filter_clause over_clause
   15793             :                 {
   15794         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15795         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15796         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15797             : 
   15798         360 :                     n->agg_filter = $2;
   15799         360 :                     n->over = $3;
   15800         360 :                     $$ = (Node *) $1;
   15801             :                 }
   15802             :             | func_expr_common_subexpr
   15803       74894 :                 { $$ = $1; }
   15804             :         ;
   15805             : 
   15806             : /*
   15807             :  * Like func_expr but does not accept WINDOW functions directly
   15808             :  * (but they can still be contained in arguments for functions etc).
   15809             :  * Use this when window expressions are not allowed, where needed to
   15810             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15811             :  */
   15812             : func_expr_windowless:
   15813       52308 :             func_application                        { $$ = $1; }
   15814         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15815           0 :             | json_aggregate_func                   { $$ = $1; }
   15816             :         ;
   15817             : 
   15818             : /*
   15819             :  * Special expressions that are considered to be functions.
   15820             :  */
   15821             : func_expr_common_subexpr:
   15822             :             COLLATION FOR '(' a_expr ')'
   15823             :                 {
   15824          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15825          30 :                                                list_make1($4),
   15826             :                                                COERCE_SQL_SYNTAX,
   15827          30 :                                                @1);
   15828             :                 }
   15829             :             | CURRENT_DATE
   15830             :                 {
   15831         304 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15832             :                 }
   15833             :             | CURRENT_TIME
   15834             :                 {
   15835          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15836             :                 }
   15837             :             | CURRENT_TIME '(' Iconst ')'
   15838             :                 {
   15839          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15840             :                 }
   15841             :             | CURRENT_TIMESTAMP
   15842             :                 {
   15843         288 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15844             :                 }
   15845             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15846             :                 {
   15847         172 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15848             :                 }
   15849             :             | LOCALTIME
   15850             :                 {
   15851          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15852             :                 }
   15853             :             | LOCALTIME '(' Iconst ')'
   15854             :                 {
   15855          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15856             :                 }
   15857             :             | LOCALTIMESTAMP
   15858             :                 {
   15859          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15860             :                 }
   15861             :             | LOCALTIMESTAMP '(' Iconst ')'
   15862             :                 {
   15863          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15864             :                 }
   15865             :             | CURRENT_ROLE
   15866             :                 {
   15867          68 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15868             :                 }
   15869             :             | CURRENT_USER
   15870             :                 {
   15871        1076 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15872             :                 }
   15873             :             | SESSION_USER
   15874             :                 {
   15875         580 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15876             :                 }
   15877             :             | SYSTEM_USER
   15878             :                 {
   15879          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15880             :                                                NIL,
   15881             :                                                COERCE_SQL_SYNTAX,
   15882             :                                                @1);
   15883             :                 }
   15884             :             | USER
   15885             :                 {
   15886          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15887             :                 }
   15888             :             | CURRENT_CATALOG
   15889             :                 {
   15890          52 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15891             :                 }
   15892             :             | CURRENT_SCHEMA
   15893             :                 {
   15894          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15895             :                 }
   15896             :             | CAST '(' a_expr AS Typename ')'
   15897       61186 :                 { $$ = makeTypeCast($3, $5, @1); }
   15898             :             | EXTRACT '(' extract_list ')'
   15899             :                 {
   15900        1374 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15901        1374 :                                                $3,
   15902             :                                                COERCE_SQL_SYNTAX,
   15903        1374 :                                                @1);
   15904             :                 }
   15905             :             | NORMALIZE '(' a_expr ')'
   15906             :                 {
   15907          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15908          18 :                                                list_make1($3),
   15909             :                                                COERCE_SQL_SYNTAX,
   15910          18 :                                                @1);
   15911             :                 }
   15912             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15913             :                 {
   15914          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15915          42 :                                                list_make2($3, makeStringConst($5, @5)),
   15916             :                                                COERCE_SQL_SYNTAX,
   15917          42 :                                                @1);
   15918             :                 }
   15919             :             | OVERLAY '(' overlay_list ')'
   15920             :                 {
   15921          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15922          82 :                                                $3,
   15923             :                                                COERCE_SQL_SYNTAX,
   15924          82 :                                                @1);
   15925             :                 }
   15926             :             | OVERLAY '(' func_arg_list_opt ')'
   15927             :                 {
   15928             :                     /*
   15929             :                      * allow functions named overlay() to be called without
   15930             :                      * special syntax
   15931             :                      */
   15932           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15933           0 :                                                $3,
   15934             :                                                COERCE_EXPLICIT_CALL,
   15935           0 :                                                @1);
   15936             :                 }
   15937             :             | POSITION '(' position_list ')'
   15938             :                 {
   15939             :                     /*
   15940             :                      * position(A in B) is converted to position(B, A)
   15941             :                      *
   15942             :                      * We deliberately don't offer a "plain syntax" option
   15943             :                      * for position(), because the reversal of the arguments
   15944             :                      * creates too much risk of confusion.
   15945             :                      */
   15946         398 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15947         398 :                                                $3,
   15948             :                                                COERCE_SQL_SYNTAX,
   15949         398 :                                                @1);
   15950             :                 }
   15951             :             | SUBSTRING '(' substr_list ')'
   15952             :                 {
   15953             :                     /* substring(A from B for C) is converted to
   15954             :                      * substring(A, B, C) - thomas 2000-11-28
   15955             :                      */
   15956         702 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   15957         702 :                                                $3,
   15958             :                                                COERCE_SQL_SYNTAX,
   15959         702 :                                                @1);
   15960             :                 }
   15961             :             | SUBSTRING '(' func_arg_list_opt ')'
   15962             :                 {
   15963             :                     /*
   15964             :                      * allow functions named substring() to be called without
   15965             :                      * special syntax
   15966             :                      */
   15967         206 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   15968         206 :                                                $3,
   15969             :                                                COERCE_EXPLICIT_CALL,
   15970         206 :                                                @1);
   15971             :                 }
   15972             :             | TREAT '(' a_expr AS Typename ')'
   15973             :                 {
   15974             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   15975             :                      * which is defined to be a subtype of the original expression.
   15976             :                      * In SQL99, this is intended for use with structured UDTs,
   15977             :                      * but let's make this a generally useful form allowing stronger
   15978             :                      * coercions than are handled by implicit casting.
   15979             :                      *
   15980             :                      * Convert SystemTypeName() to SystemFuncName() even though
   15981             :                      * at the moment they result in the same thing.
   15982             :                      */
   15983           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   15984           0 :                                                list_make1($3),
   15985             :                                                COERCE_EXPLICIT_CALL,
   15986           0 :                                                @1);
   15987             :                 }
   15988             :             | TRIM '(' BOTH trim_list ')'
   15989             :                 {
   15990             :                     /* various trim expressions are defined in SQL
   15991             :                      * - thomas 1997-07-19
   15992             :                      */
   15993          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15994          12 :                                                $4,
   15995             :                                                COERCE_SQL_SYNTAX,
   15996          12 :                                                @1);
   15997             :                 }
   15998             :             | TRIM '(' LEADING trim_list ')'
   15999             :                 {
   16000          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   16001          24 :                                                $4,
   16002             :                                                COERCE_SQL_SYNTAX,
   16003          24 :                                                @1);
   16004             :                 }
   16005             :             | TRIM '(' TRAILING trim_list ')'
   16006             :                 {
   16007         572 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16008         572 :                                                $4,
   16009             :                                                COERCE_SQL_SYNTAX,
   16010         572 :                                                @1);
   16011             :                 }
   16012             :             | TRIM '(' trim_list ')'
   16013             :                 {
   16014          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16015          98 :                                                $3,
   16016             :                                                COERCE_SQL_SYNTAX,
   16017          98 :                                                @1);
   16018             :                 }
   16019             :             | NULLIF '(' a_expr ',' a_expr ')'
   16020             :                 {
   16021         416 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16022             :                 }
   16023             :             | COALESCE '(' expr_list ')'
   16024             :                 {
   16025        3148 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16026             : 
   16027        3148 :                     c->args = $3;
   16028        3148 :                     c->location = @1;
   16029        3148 :                     $$ = (Node *) c;
   16030             :                 }
   16031             :             | GREATEST '(' expr_list ')'
   16032             :                 {
   16033         140 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16034             : 
   16035         140 :                     v->args = $3;
   16036         140 :                     v->op = IS_GREATEST;
   16037         140 :                     v->location = @1;
   16038         140 :                     $$ = (Node *) v;
   16039             :                 }
   16040             :             | LEAST '(' expr_list ')'
   16041             :                 {
   16042         124 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16043             : 
   16044         124 :                     v->args = $3;
   16045         124 :                     v->op = IS_LEAST;
   16046         124 :                     v->location = @1;
   16047         124 :                     $$ = (Node *) v;
   16048             :                 }
   16049             :             | XMLCONCAT '(' expr_list ')'
   16050             :                 {
   16051          64 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16052             :                 }
   16053             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16054             :                 {
   16055           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16056             :                 }
   16057             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16058             :                 {
   16059          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16060             :                 }
   16061             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16062             :                 {
   16063         118 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16064             :                 }
   16065             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16066             :                 {
   16067          22 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16068             :                 }
   16069             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16070             :                 {
   16071             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16072             :                      * converted to xmlexists(A, B)*/
   16073          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16074          54 :                                                list_make2($3, $4),
   16075             :                                                COERCE_SQL_SYNTAX,
   16076          54 :                                                @1);
   16077             :                 }
   16078             :             | XMLFOREST '(' xml_attribute_list ')'
   16079             :                 {
   16080          34 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16081             :                 }
   16082             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16083             :                 {
   16084             :                     XmlExpr *x = (XmlExpr *)
   16085         142 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16086         142 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16087         142 :                                     @1);
   16088             : 
   16089         142 :                     x->xmloption = $3;
   16090         142 :                     $$ = (Node *) x;
   16091             :                 }
   16092             :             | XMLPI '(' NAME_P ColLabel ')'
   16093             :                 {
   16094          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16095             :                 }
   16096             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16097             :                 {
   16098          52 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16099             :                 }
   16100             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16101             :                 {
   16102          70 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16103          70 :                                      list_make3($3, $5, $6), @1);
   16104             :                 }
   16105             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16106             :                 {
   16107         226 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16108             : 
   16109         226 :                     n->xmloption = $3;
   16110         226 :                     n->expr = $4;
   16111         226 :                     n->typeName = $6;
   16112         226 :                     n->indent = $7;
   16113         226 :                     n->location = @1;
   16114         226 :                     $$ = (Node *) n;
   16115             :                 }
   16116             :             | JSON_OBJECT '(' func_arg_list ')'
   16117             :                 {
   16118             :                     /* Support for legacy (non-standard) json_object() */
   16119          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16120          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16121             :                 }
   16122             :             | JSON_OBJECT '(' json_name_and_value_list
   16123             :                 json_object_constructor_null_clause_opt
   16124             :                 json_key_uniqueness_constraint_opt
   16125             :                 json_returning_clause_opt ')'
   16126             :                 {
   16127         348 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16128             : 
   16129         348 :                     n->exprs = $3;
   16130         348 :                     n->absent_on_null = $4;
   16131         348 :                     n->unique = $5;
   16132         348 :                     n->output = (JsonOutput *) $6;
   16133         348 :                     n->location = @1;
   16134         348 :                     $$ = (Node *) n;
   16135             :                 }
   16136             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16137             :                 {
   16138          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16139             : 
   16140          92 :                     n->exprs = NULL;
   16141          92 :                     n->absent_on_null = false;
   16142          92 :                     n->unique = false;
   16143          92 :                     n->output = (JsonOutput *) $3;
   16144          92 :                     n->location = @1;
   16145          92 :                     $$ = (Node *) n;
   16146             :                 }
   16147             :             | JSON_ARRAY '('
   16148             :                 json_value_expr_list
   16149             :                 json_array_constructor_null_clause_opt
   16150             :                 json_returning_clause_opt
   16151             :             ')'
   16152             :                 {
   16153         108 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16154             : 
   16155         108 :                     n->exprs = $3;
   16156         108 :                     n->absent_on_null = $4;
   16157         108 :                     n->output = (JsonOutput *) $5;
   16158         108 :                     n->location = @1;
   16159         108 :                     $$ = (Node *) n;
   16160             :                 }
   16161             :             | JSON_ARRAY '('
   16162             :                 select_no_parens
   16163             :                 json_format_clause_opt
   16164             :                 /* json_array_constructor_null_clause_opt */
   16165             :                 json_returning_clause_opt
   16166             :             ')'
   16167             :                 {
   16168          60 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16169             : 
   16170          60 :                     n->query = $3;
   16171          60 :                     n->format = (JsonFormat *) $4;
   16172          60 :                     n->absent_on_null = true;    /* XXX */
   16173          60 :                     n->output = (JsonOutput *) $5;
   16174          60 :                     n->location = @1;
   16175          60 :                     $$ = (Node *) n;
   16176             :                 }
   16177             :             | JSON_ARRAY '('
   16178             :                 json_returning_clause_opt
   16179             :             ')'
   16180             :                 {
   16181          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16182             : 
   16183          86 :                     n->exprs = NIL;
   16184          86 :                     n->absent_on_null = true;
   16185          86 :                     n->output = (JsonOutput *) $3;
   16186          86 :                     n->location = @1;
   16187          86 :                     $$ = (Node *) n;
   16188             :                 }
   16189             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16190             :                 {
   16191         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16192             : 
   16193         164 :                     n->expr = (JsonValueExpr *) $3;
   16194         164 :                     n->unique_keys = $4;
   16195         164 :                     n->output = NULL;
   16196         164 :                     n->location = @1;
   16197         164 :                     $$ = (Node *) n;
   16198             :                 }
   16199             :             | JSON_SCALAR '(' a_expr ')'
   16200             :                 {
   16201         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16202             : 
   16203         112 :                     n->expr = (Expr *) $3;
   16204         112 :                     n->output = NULL;
   16205         112 :                     n->location = @1;
   16206         112 :                     $$ = (Node *) n;
   16207             :                 }
   16208             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16209             :                 {
   16210         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16211             : 
   16212         108 :                     n->expr = (JsonValueExpr *) $3;
   16213         108 :                     n->output = (JsonOutput *) $4;
   16214         108 :                     n->location = @1;
   16215         108 :                     $$ = (Node *) n;
   16216             :                 }
   16217             :             | MERGE_ACTION '(' ')'
   16218             :                 {
   16219         204 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16220             : 
   16221         204 :                     m->msftype = TEXTOID;
   16222         204 :                     m->location = @1;
   16223         204 :                     $$ = (Node *) m;
   16224             :                 }
   16225             :             | JSON_QUERY '('
   16226             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16227             :                 json_returning_clause_opt
   16228             :                 json_wrapper_behavior
   16229             :                 json_quotes_clause_opt
   16230             :                 json_behavior_clause_opt
   16231             :             ')'
   16232             :                 {
   16233         984 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16234             : 
   16235         984 :                     n->op = JSON_QUERY_OP;
   16236         984 :                     n->context_item = (JsonValueExpr *) $3;
   16237         984 :                     n->pathspec = $5;
   16238         984 :                     n->passing = $6;
   16239         984 :                     n->output = (JsonOutput *) $7;
   16240         984 :                     n->wrapper = $8;
   16241         984 :                     n->quotes = $9;
   16242         984 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16243         984 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16244         984 :                     n->location = @1;
   16245         984 :                     $$ = (Node *) n;
   16246             :                 }
   16247             :             | JSON_EXISTS '('
   16248             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16249             :                 json_on_error_clause_opt
   16250             :             ')'
   16251             :                 {
   16252         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16253             : 
   16254         168 :                     n->op = JSON_EXISTS_OP;
   16255         168 :                     n->context_item = (JsonValueExpr *) $3;
   16256         168 :                     n->pathspec = $5;
   16257         168 :                     n->passing = $6;
   16258         168 :                     n->output = NULL;
   16259         168 :                     n->on_error = (JsonBehavior *) $7;
   16260         168 :                     n->location = @1;
   16261         168 :                     $$ = (Node *) n;
   16262             :                 }
   16263             :             | JSON_VALUE '('
   16264             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16265             :                 json_returning_clause_opt
   16266             :                 json_behavior_clause_opt
   16267             :             ')'
   16268             :                 {
   16269         576 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16270             : 
   16271         576 :                     n->op = JSON_VALUE_OP;
   16272         576 :                     n->context_item = (JsonValueExpr *) $3;
   16273         576 :                     n->pathspec = $5;
   16274         576 :                     n->passing = $6;
   16275         576 :                     n->output = (JsonOutput *) $7;
   16276         576 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16277         576 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16278         576 :                     n->location = @1;
   16279         576 :                     $$ = (Node *) n;
   16280             :                 }
   16281             :             ;
   16282             : 
   16283             : 
   16284             : /*
   16285             :  * SQL/XML support
   16286             :  */
   16287             : xml_root_version: VERSION_P a_expr
   16288          24 :                 { $$ = $2; }
   16289             :             | VERSION_P NO VALUE_P
   16290          46 :                 { $$ = makeNullAConst(-1); }
   16291             :         ;
   16292             : 
   16293             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16294          28 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16295             :             | ',' STANDALONE_P NO
   16296          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16297             :             | ',' STANDALONE_P NO VALUE_P
   16298          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16299             :             | /*EMPTY*/
   16300          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16301             :         ;
   16302             : 
   16303          58 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16304             :         ;
   16305             : 
   16306          92 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16307         150 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16308             :         ;
   16309             : 
   16310             : xml_attribute_el: a_expr AS ColLabel
   16311             :                 {
   16312         116 :                     $$ = makeNode(ResTarget);
   16313         116 :                     $$->name = $3;
   16314         116 :                     $$->indirection = NIL;
   16315         116 :                     $$->val = (Node *) $1;
   16316         116 :                     $$->location = @1;
   16317             :                 }
   16318             :             | a_expr
   16319             :                 {
   16320         126 :                     $$ = makeNode(ResTarget);
   16321         126 :                     $$->name = NULL;
   16322         126 :                     $$->indirection = NIL;
   16323         126 :                     $$->val = (Node *) $1;
   16324         126 :                     $$->location = @1;
   16325             :                 }
   16326             :         ;
   16327             : 
   16328         190 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16329         194 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16330             :         ;
   16331             : 
   16332         142 : xml_indent_option: INDENT                           { $$ = true; }
   16333          42 :             | NO INDENT                             { $$ = false; }
   16334          42 :             | /*EMPTY*/                             { $$ = false; }
   16335             :         ;
   16336             : 
   16337           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16338           4 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16339         138 :             | /*EMPTY*/                             { $$ = false; }
   16340             :         ;
   16341             : 
   16342             : /* We allow several variants for SQL and other compatibility. */
   16343             : xmlexists_argument:
   16344             :             PASSING c_expr
   16345             :                 {
   16346         230 :                     $$ = $2;
   16347             :                 }
   16348             :             | PASSING c_expr xml_passing_mech
   16349             :                 {
   16350           0 :                     $$ = $2;
   16351             :                 }
   16352             :             | PASSING xml_passing_mech c_expr
   16353             :                 {
   16354          42 :                     $$ = $3;
   16355             :                 }
   16356             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16357             :                 {
   16358           6 :                     $$ = $3;
   16359             :                 }
   16360             :         ;
   16361             : 
   16362             : xml_passing_mech:
   16363             :             BY REF_P
   16364             :             | BY VALUE_P
   16365             :         ;
   16366             : 
   16367             : 
   16368             : /*
   16369             :  * Aggregate decoration clauses
   16370             :  */
   16371             : within_group_clause:
   16372         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16373      316770 :             | /*EMPTY*/                             { $$ = NIL; }
   16374             :         ;
   16375             : 
   16376             : filter_clause:
   16377         854 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16378      316624 :             | /*EMPTY*/                             { $$ = NULL; }
   16379             :         ;
   16380             : 
   16381             : 
   16382             : /*
   16383             :  * Window Definitions
   16384             :  */
   16385             : window_clause:
   16386         540 :             WINDOW window_definition_list           { $$ = $2; }
   16387      480564 :             | /*EMPTY*/                             { $$ = NIL; }
   16388             :         ;
   16389             : 
   16390             : window_definition_list:
   16391         540 :             window_definition                       { $$ = list_make1($1); }
   16392             :             | window_definition_list ',' window_definition
   16393          12 :                                                     { $$ = lappend($1, $3); }
   16394             :         ;
   16395             : 
   16396             : window_definition:
   16397             :             ColId AS window_specification
   16398             :                 {
   16399         552 :                     WindowDef  *n = $3;
   16400             : 
   16401         552 :                     n->name = $1;
   16402         552 :                     $$ = n;
   16403             :                 }
   16404             :         ;
   16405             : 
   16406             : over_clause: OVER window_specification
   16407        2614 :                 { $$ = $2; }
   16408             :             | OVER ColId
   16409             :                 {
   16410         954 :                     WindowDef  *n = makeNode(WindowDef);
   16411             : 
   16412         954 :                     n->name = $2;
   16413         954 :                     n->refname = NULL;
   16414         954 :                     n->partitionClause = NIL;
   16415         954 :                     n->orderClause = NIL;
   16416         954 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16417         954 :                     n->startOffset = NULL;
   16418         954 :                     n->endOffset = NULL;
   16419         954 :                     n->location = @2;
   16420         954 :                     $$ = n;
   16421             :                 }
   16422             :             | /*EMPTY*/
   16423      313904 :                 { $$ = NULL; }
   16424             :         ;
   16425             : 
   16426             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16427             :                         opt_sort_clause opt_frame_clause ')'
   16428             :                 {
   16429        3166 :                     WindowDef  *n = makeNode(WindowDef);
   16430             : 
   16431        3166 :                     n->name = NULL;
   16432        3166 :                     n->refname = $2;
   16433        3166 :                     n->partitionClause = $3;
   16434        3166 :                     n->orderClause = $4;
   16435             :                     /* copy relevant fields of opt_frame_clause */
   16436        3166 :                     n->frameOptions = $5->frameOptions;
   16437        3166 :                     n->startOffset = $5->startOffset;
   16438        3166 :                     n->endOffset = $5->endOffset;
   16439        3166 :                     n->location = @1;
   16440        3166 :                     $$ = n;
   16441             :                 }
   16442             :         ;
   16443             : 
   16444             : /*
   16445             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16446             :  * of a window_specification, we want the assumption to be that there is
   16447             :  * no existing_window_name; but those keywords are unreserved and so could
   16448             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16449             :  * and giving the empty production here a slightly higher precedence, so
   16450             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16451             :  * These keywords are thus precluded from being an existing_window_name but
   16452             :  * are not reserved for any other purpose.
   16453             :  */
   16454          54 : opt_existing_window_name: ColId                     { $$ = $1; }
   16455        3118 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16456             :         ;
   16457             : 
   16458         918 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16459        2248 :             | /*EMPTY*/                             { $$ = NIL; }
   16460             :         ;
   16461             : 
   16462             : /*
   16463             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16464             :  * frameOptions, startOffset, and endOffset.
   16465             :  */
   16466             : opt_frame_clause:
   16467             :             RANGE frame_extent opt_window_exclusion_clause
   16468             :                 {
   16469         796 :                     WindowDef  *n = $2;
   16470             : 
   16471         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16472         796 :                     n->frameOptions |= $3;
   16473         796 :                     $$ = n;
   16474             :                 }
   16475             :             | ROWS frame_extent opt_window_exclusion_clause
   16476             :                 {
   16477         624 :                     WindowDef  *n = $2;
   16478             : 
   16479         624 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16480         624 :                     n->frameOptions |= $3;
   16481         624 :                     $$ = n;
   16482             :                 }
   16483             :             | GROUPS frame_extent opt_window_exclusion_clause
   16484             :                 {
   16485         204 :                     WindowDef  *n = $2;
   16486             : 
   16487         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16488         204 :                     n->frameOptions |= $3;
   16489         204 :                     $$ = n;
   16490             :                 }
   16491             :             | /*EMPTY*/
   16492             :                 {
   16493        1542 :                     WindowDef  *n = makeNode(WindowDef);
   16494             : 
   16495        1542 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16496        1542 :                     n->startOffset = NULL;
   16497        1542 :                     n->endOffset = NULL;
   16498        1542 :                     $$ = n;
   16499             :                 }
   16500             :         ;
   16501             : 
   16502             : frame_extent: frame_bound
   16503             :                 {
   16504          12 :                     WindowDef  *n = $1;
   16505             : 
   16506             :                     /* reject invalid cases */
   16507          12 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16508           0 :                         ereport(ERROR,
   16509             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16510             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16511             :                                  parser_errposition(@1)));
   16512          12 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16513           0 :                         ereport(ERROR,
   16514             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16515             :                                  errmsg("frame starting from following row cannot end with current row"),
   16516             :                                  parser_errposition(@1)));
   16517          12 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16518          12 :                     $$ = n;
   16519             :                 }
   16520             :             | BETWEEN frame_bound AND frame_bound
   16521             :                 {
   16522        1612 :                     WindowDef  *n1 = $2;
   16523        1612 :                     WindowDef  *n2 = $4;
   16524             : 
   16525             :                     /* form merged options */
   16526        1612 :                     int     frameOptions = n1->frameOptions;
   16527             :                     /* shift converts START_ options to END_ options */
   16528        1612 :                     frameOptions |= n2->frameOptions << 1;
   16529        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16530             :                     /* reject invalid cases */
   16531        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16532           0 :                         ereport(ERROR,
   16533             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16534             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16535             :                                  parser_errposition(@2)));
   16536        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16537           0 :                         ereport(ERROR,
   16538             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16539             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16540             :                                  parser_errposition(@4)));
   16541        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16542         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16543           0 :                         ereport(ERROR,
   16544             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16545             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16546             :                                  parser_errposition(@4)));
   16547        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16548         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16549             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16550           0 :                         ereport(ERROR,
   16551             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16552             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16553             :                                  parser_errposition(@4)));
   16554        1612 :                     n1->frameOptions = frameOptions;
   16555        1612 :                     n1->endOffset = n2->startOffset;
   16556        1612 :                     $$ = n1;
   16557             :                 }
   16558             :         ;
   16559             : 
   16560             : /*
   16561             :  * This is used for both frame start and frame end, with output set up on
   16562             :  * the assumption it's frame start; the frame_extent productions must reject
   16563             :  * invalid cases.
   16564             :  */
   16565             : frame_bound:
   16566             :             UNBOUNDED PRECEDING
   16567             :                 {
   16568         198 :                     WindowDef  *n = makeNode(WindowDef);
   16569             : 
   16570         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16571         198 :                     n->startOffset = NULL;
   16572         198 :                     n->endOffset = NULL;
   16573         198 :                     $$ = n;
   16574             :                 }
   16575             :             | UNBOUNDED FOLLOWING
   16576             :                 {
   16577         376 :                     WindowDef  *n = makeNode(WindowDef);
   16578             : 
   16579         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16580         376 :                     n->startOffset = NULL;
   16581         376 :                     n->endOffset = NULL;
   16582         376 :                     $$ = n;
   16583             :                 }
   16584             :             | CURRENT_P ROW
   16585             :                 {
   16586         604 :                     WindowDef  *n = makeNode(WindowDef);
   16587             : 
   16588         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16589         604 :                     n->startOffset = NULL;
   16590         604 :                     n->endOffset = NULL;
   16591         604 :                     $$ = n;
   16592             :                 }
   16593             :             | a_expr PRECEDING
   16594             :                 {
   16595         906 :                     WindowDef  *n = makeNode(WindowDef);
   16596             : 
   16597         906 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16598         906 :                     n->startOffset = $1;
   16599         906 :                     n->endOffset = NULL;
   16600         906 :                     $$ = n;
   16601             :                 }
   16602             :             | a_expr FOLLOWING
   16603             :                 {
   16604        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16605             : 
   16606        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16607        1152 :                     n->startOffset = $1;
   16608        1152 :                     n->endOffset = NULL;
   16609        1152 :                     $$ = n;
   16610             :                 }
   16611             :         ;
   16612             : 
   16613             : opt_window_exclusion_clause:
   16614          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16615          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16616         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16617          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16618        1276 :             | /*EMPTY*/             { $$ = 0; }
   16619             :         ;
   16620             : 
   16621             : 
   16622             : /*
   16623             :  * Supporting nonterminals for expressions.
   16624             :  */
   16625             : 
   16626             : /* Explicit row production.
   16627             :  *
   16628             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16629             :  * without conflicting with the parenthesized a_expr production.  Without the
   16630             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16631             :  */
   16632           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16633           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16634        1896 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16635             :         ;
   16636             : 
   16637        3774 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16638          30 :             | ROW '(' ')'                           { $$ = NIL; }
   16639             :         ;
   16640             : 
   16641        2532 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16642             :         ;
   16643             : 
   16644       17214 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16645           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16646         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16647             :         ;
   16648             : 
   16649       11130 : all_Op:     Op                                      { $$ = $1; }
   16650       28378 :             | MathOp                                { $$ = $1; }
   16651             :         ;
   16652             : 
   16653          40 : MathOp:      '+'                                    { $$ = "+"; }
   16654          64 :             | '-'                                   { $$ = "-"; }
   16655         114 :             | '*'                                   { $$ = "*"; }
   16656           0 :             | '/'                                   { $$ = "/"; }
   16657           8 :             | '%'                                   { $$ = "%"; }
   16658           0 :             | '^'                                   { $$ = "^"; }
   16659         758 :             | '<'                                    { $$ = "<"; }
   16660         648 :             | '>'                                    { $$ = ">"; }
   16661       24790 :             | '='                                   { $$ = "="; }
   16662         618 :             | LESS_EQUALS                           { $$ = "<="; }
   16663         610 :             | GREATER_EQUALS                        { $$ = ">="; }
   16664         728 :             | NOT_EQUALS                            { $$ = "<>"; }
   16665             :         ;
   16666             : 
   16667             : qual_Op:    Op
   16668       43666 :                     { $$ = list_make1(makeString($1)); }
   16669             :             | OPERATOR '(' any_operator ')'
   16670       15436 :                     { $$ = $3; }
   16671             :         ;
   16672             : 
   16673             : qual_all_Op:
   16674             :             all_Op
   16675        1416 :                     { $$ = list_make1(makeString($1)); }
   16676             :             | OPERATOR '(' any_operator ')'
   16677          44 :                     { $$ = $3; }
   16678             :         ;
   16679             : 
   16680             : subquery_Op:
   16681             :             all_Op
   16682       17232 :                     { $$ = list_make1(makeString($1)); }
   16683             :             | OPERATOR '(' any_operator ')'
   16684         274 :                     { $$ = $3; }
   16685             :             | LIKE
   16686          24 :                     { $$ = list_make1(makeString("~~")); }
   16687             :             | NOT_LA LIKE
   16688          12 :                     { $$ = list_make1(makeString("!~~")); }
   16689             :             | ILIKE
   16690          12 :                     { $$ = list_make1(makeString("~~*")); }
   16691             :             | NOT_LA ILIKE
   16692           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16693             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16694             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16695             :  * and the ~ operator for posix regular expressions is used.
   16696             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16697             :  * this transformation is made on the fly by the parser upwards.
   16698             :  * however the SubLink structure which handles any/some/all stuff
   16699             :  * is not ready for such a thing.
   16700             :  */
   16701             :             ;
   16702             : 
   16703             : expr_list:  a_expr
   16704             :                 {
   16705      170984 :                     $$ = list_make1($1);
   16706             :                 }
   16707             :             | expr_list ',' a_expr
   16708             :                 {
   16709      151634 :                     $$ = lappend($1, $3);
   16710             :                 }
   16711             :         ;
   16712             : 
   16713             : /* function arguments can have names */
   16714             : func_arg_list:  func_arg_expr
   16715             :                 {
   16716      324996 :                     $$ = list_make1($1);
   16717             :                 }
   16718             :             | func_arg_list ',' func_arg_expr
   16719             :                 {
   16720      332756 :                     $$ = lappend($1, $3);
   16721             :                 }
   16722             :         ;
   16723             : 
   16724             : func_arg_expr:  a_expr
   16725             :                 {
   16726      611092 :                     $$ = $1;
   16727             :                 }
   16728             :             | param_name COLON_EQUALS a_expr
   16729             :                 {
   16730       45782 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16731             : 
   16732       45782 :                     na->name = $1;
   16733       45782 :                     na->arg = (Expr *) $3;
   16734       45782 :                     na->argnumber = -1;      /* until determined */
   16735       45782 :                     na->location = @1;
   16736       45782 :                     $$ = (Node *) na;
   16737             :                 }
   16738             :             | param_name EQUALS_GREATER a_expr
   16739             :                 {
   16740        1612 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16741             : 
   16742        1612 :                     na->name = $1;
   16743        1612 :                     na->arg = (Expr *) $3;
   16744        1612 :                     na->argnumber = -1;      /* until determined */
   16745        1612 :                     na->location = @1;
   16746        1612 :                     $$ = (Node *) na;
   16747             :                 }
   16748             :         ;
   16749             : 
   16750         206 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16751           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16752             :         ;
   16753             : 
   16754        2358 : type_list:  Typename                                { $$ = list_make1($1); }
   16755         756 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16756             :         ;
   16757             : 
   16758             : array_expr: '[' expr_list ']'
   16759             :                 {
   16760        7652 :                     $$ = makeAArrayExpr($2, @1);
   16761             :                 }
   16762             :             | '[' array_expr_list ']'
   16763             :                 {
   16764         412 :                     $$ = makeAArrayExpr($2, @1);
   16765             :                 }
   16766             :             | '[' ']'
   16767             :                 {
   16768          88 :                     $$ = makeAArrayExpr(NIL, @1);
   16769             :                 }
   16770             :         ;
   16771             : 
   16772         412 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16773         342 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16774             :         ;
   16775             : 
   16776             : 
   16777             : extract_list:
   16778             :             extract_arg FROM a_expr
   16779             :                 {
   16780        1374 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16781             :                 }
   16782             :         ;
   16783             : 
   16784             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16785             :  * - thomas 2001-04-12
   16786             :  */
   16787             : extract_arg:
   16788        1116 :             IDENT                                   { $$ = $1; }
   16789          72 :             | YEAR_P                                { $$ = "year"; }
   16790          42 :             | MONTH_P                               { $$ = "month"; }
   16791          54 :             | DAY_P                                 { $$ = "day"; }
   16792          30 :             | HOUR_P                                { $$ = "hour"; }
   16793          30 :             | MINUTE_P                              { $$ = "minute"; }
   16794          30 :             | SECOND_P                              { $$ = "second"; }
   16795           0 :             | Sconst                                { $$ = $1; }
   16796             :         ;
   16797             : 
   16798             : unicode_normal_form:
   16799          24 :             NFC                                     { $$ = "NFC"; }
   16800          18 :             | NFD                                   { $$ = "NFD"; }
   16801          18 :             | NFKC                                  { $$ = "NFKC"; }
   16802          18 :             | NFKD                                  { $$ = "NFKD"; }
   16803             :         ;
   16804             : 
   16805             : /* OVERLAY() arguments */
   16806             : overlay_list:
   16807             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16808             :                 {
   16809             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16810          34 :                     $$ = list_make4($1, $3, $5, $7);
   16811             :                 }
   16812             :             | a_expr PLACING a_expr FROM a_expr
   16813             :                 {
   16814             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16815          48 :                     $$ = list_make3($1, $3, $5);
   16816             :                 }
   16817             :         ;
   16818             : 
   16819             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16820             : position_list:
   16821         398 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16822             :         ;
   16823             : 
   16824             : /*
   16825             :  * SUBSTRING() arguments
   16826             :  *
   16827             :  * Note that SQL:1999 has both
   16828             :  *     text FROM int FOR int
   16829             :  * and
   16830             :  *     text FROM pattern FOR escape
   16831             :  *
   16832             :  * In the parser we map them both to a call to the substring() function and
   16833             :  * rely on type resolution to pick the right one.
   16834             :  *
   16835             :  * In SQL:2003, the second variant was changed to
   16836             :  *     text SIMILAR pattern ESCAPE escape
   16837             :  * We could in theory map that to a different function internally, but
   16838             :  * since we still support the SQL:1999 version, we don't.  However,
   16839             :  * ruleutils.c will reverse-list the call in the newer style.
   16840             :  */
   16841             : substr_list:
   16842             :             a_expr FROM a_expr FOR a_expr
   16843             :                 {
   16844         122 :                     $$ = list_make3($1, $3, $5);
   16845             :                 }
   16846             :             | a_expr FOR a_expr FROM a_expr
   16847             :                 {
   16848             :                     /* not legal per SQL, but might as well allow it */
   16849           0 :                     $$ = list_make3($1, $5, $3);
   16850             :                 }
   16851             :             | a_expr FROM a_expr
   16852             :                 {
   16853             :                     /*
   16854             :                      * Because we aren't restricting data types here, this
   16855             :                      * syntax can end up resolving to textregexsubstr().
   16856             :                      * We've historically allowed that to happen, so continue
   16857             :                      * to accept it.  However, ruleutils.c will reverse-list
   16858             :                      * such a call in regular function call syntax.
   16859             :                      */
   16860         364 :                     $$ = list_make2($1, $3);
   16861             :                 }
   16862             :             | a_expr FOR a_expr
   16863             :                 {
   16864             :                     /* not legal per SQL */
   16865             : 
   16866             :                     /*
   16867             :                      * Since there are no cases where this syntax allows
   16868             :                      * a textual FOR value, we forcibly cast the argument
   16869             :                      * to int4.  The possible matches in pg_proc are
   16870             :                      * substring(text,int4) and substring(text,text),
   16871             :                      * and we don't want the parser to choose the latter,
   16872             :                      * which it is likely to do if the second argument
   16873             :                      * is unknown or doesn't have an implicit cast to int4.
   16874             :                      */
   16875          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16876             :                                     makeTypeCast($3,
   16877             :                                                  SystemTypeName("int4"), -1));
   16878             :                 }
   16879             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16880             :                 {
   16881         180 :                     $$ = list_make3($1, $3, $5);
   16882             :                 }
   16883             :         ;
   16884             : 
   16885         596 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16886          24 :             | FROM expr_list                        { $$ = $2; }
   16887          86 :             | expr_list                             { $$ = $1; }
   16888             :         ;
   16889             : 
   16890             : in_expr:    select_with_parens
   16891             :                 {
   16892        5514 :                     SubLink    *n = makeNode(SubLink);
   16893             : 
   16894        5514 :                     n->subselect = $1;
   16895             :                     /* other fields will be filled later */
   16896        5514 :                     $$ = (Node *) n;
   16897             :                 }
   16898       21632 :             | '(' expr_list ')'                     { $$ = (Node *) $2; }
   16899             :         ;
   16900             : 
   16901             : /*
   16902             :  * Define SQL-style CASE clause.
   16903             :  * - Full specification
   16904             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16905             :  * - Implicit argument
   16906             :  *  CASE a WHEN b THEN c ... ELSE d END
   16907             :  */
   16908             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16909             :                 {
   16910       39560 :                     CaseExpr   *c = makeNode(CaseExpr);
   16911             : 
   16912       39560 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16913       39560 :                     c->arg = (Expr *) $2;
   16914       39560 :                     c->args = $3;
   16915       39560 :                     c->defresult = (Expr *) $4;
   16916       39560 :                     c->location = @1;
   16917       39560 :                     $$ = (Node *) c;
   16918             :                 }
   16919             :         ;
   16920             : 
   16921             : when_clause_list:
   16922             :             /* There must be at least one */
   16923       39560 :             when_clause                             { $$ = list_make1($1); }
   16924       28722 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16925             :         ;
   16926             : 
   16927             : when_clause:
   16928             :             WHEN a_expr THEN a_expr
   16929             :                 {
   16930       68282 :                     CaseWhen   *w = makeNode(CaseWhen);
   16931             : 
   16932       68282 :                     w->expr = (Expr *) $2;
   16933       68282 :                     w->result = (Expr *) $4;
   16934       68282 :                     w->location = @1;
   16935       68282 :                     $$ = (Node *) w;
   16936             :                 }
   16937             :         ;
   16938             : 
   16939             : case_default:
   16940       30060 :             ELSE a_expr                             { $$ = $2; }
   16941        9500 :             | /*EMPTY*/                             { $$ = NULL; }
   16942             :         ;
   16943             : 
   16944        6610 : case_arg:   a_expr                                  { $$ = $1; }
   16945       32950 :             | /*EMPTY*/                             { $$ = NULL; }
   16946             :         ;
   16947             : 
   16948             : columnref:  ColId
   16949             :                 {
   16950      776066 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16951             :                 }
   16952             :             | ColId indirection
   16953             :                 {
   16954     1085844 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16955             :                 }
   16956             :         ;
   16957             : 
   16958             : indirection_el:
   16959             :             '.' attr_name
   16960             :                 {
   16961     1488436 :                     $$ = (Node *) makeString($2);
   16962             :                 }
   16963             :             | '.' '*'
   16964             :                 {
   16965        6884 :                     $$ = (Node *) makeNode(A_Star);
   16966             :                 }
   16967             :             | '[' a_expr ']'
   16968             :                 {
   16969       13050 :                     A_Indices *ai = makeNode(A_Indices);
   16970             : 
   16971       13050 :                     ai->is_slice = false;
   16972       13050 :                     ai->lidx = NULL;
   16973       13050 :                     ai->uidx = $2;
   16974       13050 :                     $$ = (Node *) ai;
   16975             :                 }
   16976             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   16977             :                 {
   16978         588 :                     A_Indices *ai = makeNode(A_Indices);
   16979             : 
   16980         588 :                     ai->is_slice = true;
   16981         588 :                     ai->lidx = $2;
   16982         588 :                     ai->uidx = $4;
   16983         588 :                     $$ = (Node *) ai;
   16984             :                 }
   16985             :         ;
   16986             : 
   16987             : opt_slice_bound:
   16988         996 :             a_expr                                  { $$ = $1; }
   16989         180 :             | /*EMPTY*/                             { $$ = NULL; }
   16990             :         ;
   16991             : 
   16992             : indirection:
   16993     1488804 :             indirection_el                          { $$ = list_make1($1); }
   16994        3082 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   16995             :         ;
   16996             : 
   16997             : opt_indirection:
   16998      196950 :             /*EMPTY*/                               { $$ = NIL; }
   16999       17072 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   17000             :         ;
   17001             : 
   17002             : opt_asymmetric: ASYMMETRIC
   17003             :             | /*EMPTY*/
   17004             :         ;
   17005             : 
   17006             : /* SQL/JSON support */
   17007             : json_passing_clause_opt:
   17008         336 :             PASSING json_arguments                  { $$ = $2; }
   17009        1934 :             | /*EMPTY*/                             { $$ = NIL; }
   17010             :         ;
   17011             : 
   17012             : json_arguments:
   17013         336 :             json_argument                           { $$ = list_make1($1); }
   17014         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17015             :         ;
   17016             : 
   17017             : json_argument:
   17018             :             json_value_expr AS ColLabel
   17019             :             {
   17020         462 :                 JsonArgument *n = makeNode(JsonArgument);
   17021             : 
   17022         462 :                 n->val = (JsonValueExpr *) $1;
   17023         462 :                 n->name = $3;
   17024         462 :                 $$ = (Node *) n;
   17025             :             }
   17026             :         ;
   17027             : 
   17028             : /* ARRAY is a noise word */
   17029             : json_wrapper_behavior:
   17030          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17031           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17032          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17033          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17034           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17035          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17036          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17037           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17038        1634 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17039             :         ;
   17040             : 
   17041             : json_behavior:
   17042             :             DEFAULT a_expr
   17043         384 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17044             :             | json_behavior_type
   17045         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17046             :         ;
   17047             : 
   17048             : json_behavior_type:
   17049         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17050          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17051          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17052          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17053          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17054          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17055          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17056             :             /* non-standard, for Oracle compatibility only */
   17057          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17058             :         ;
   17059             : 
   17060             : json_behavior_clause_opt:
   17061             :             json_behavior ON EMPTY_P
   17062         174 :                 { $$ = list_make2($1, NULL); }
   17063             :             | json_behavior ON ERROR_P
   17064         552 :                 { $$ = list_make2(NULL, $1); }
   17065             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17066         102 :                 { $$ = list_make2($1, $4); }
   17067             :             | /* EMPTY */
   17068        1568 :                 { $$ = list_make2(NULL, NULL); }
   17069             :         ;
   17070             : 
   17071             : json_on_error_clause_opt:
   17072             :             json_behavior ON ERROR_P
   17073         150 :                 { $$ = $1; }
   17074             :             | /* EMPTY */
   17075         686 :                 { $$ = NULL; }
   17076             :         ;
   17077             : 
   17078             : json_value_expr:
   17079             :             a_expr json_format_clause_opt
   17080             :             {
   17081             :                 /* formatted_expr will be set during parse-analysis. */
   17082        4202 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17083        4202 :                                                 castNode(JsonFormat, $2));
   17084             :             }
   17085             :         ;
   17086             : 
   17087             : json_format_clause:
   17088             :             FORMAT_LA JSON ENCODING name
   17089             :                 {
   17090             :                     int     encoding;
   17091             : 
   17092         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17093          64 :                         encoding = JS_ENC_UTF8;
   17094          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17095          12 :                         encoding = JS_ENC_UTF16;
   17096          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17097          12 :                         encoding = JS_ENC_UTF32;
   17098             :                     else
   17099          12 :                         ereport(ERROR,
   17100             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17101             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17102             :                                  parser_errposition(@4)));
   17103             : 
   17104          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17105             :                 }
   17106             :             | FORMAT_LA JSON
   17107             :                 {
   17108         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17109             :                 }
   17110             :         ;
   17111             : 
   17112             : json_format_clause_opt:
   17113             :             json_format_clause
   17114             :                 {
   17115         392 :                     $$ = $1;
   17116             :                 }
   17117             :             | /* EMPTY */
   17118             :                 {
   17119        5314 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17120             :                 }
   17121             :         ;
   17122             : 
   17123             : json_quotes_clause_opt:
   17124          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17125          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17126          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17127         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17128        1538 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17129             :         ;
   17130             : 
   17131             : json_returning_clause_opt:
   17132             :             RETURNING Typename json_format_clause_opt
   17133             :                 {
   17134        1444 :                     JsonOutput *n = makeNode(JsonOutput);
   17135             : 
   17136        1444 :                     n->typeName = $2;
   17137        1444 :                     n->returning = makeNode(JsonReturning);
   17138        1444 :                     n->returning->format = (JsonFormat *) $3;
   17139        1444 :                     $$ = (Node *) n;
   17140             :                 }
   17141        1278 :             | /* EMPTY */                           { $$ = NULL; }
   17142             :         ;
   17143             : 
   17144             : /*
   17145             :  * We must assign the only-JSON production a precedence less than IDENT in
   17146             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17147             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17148             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17149             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17150             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17151             :  * really related to this syntax, but it's a convenient choice because it
   17152             :  * already has a precedence less than IDENT for other reasons.
   17153             :  */
   17154             : json_predicate_type_constraint:
   17155         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17156          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17157          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17158          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17159          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17160             :         ;
   17161             : 
   17162             : /*
   17163             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17164             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17165             :  * This prevents reducing them when the next token is KEYS.
   17166             :  */
   17167             : json_key_uniqueness_constraint_opt:
   17168         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17169         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17170          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17171          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17172         798 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17173             :         ;
   17174             : 
   17175             : json_name_and_value_list:
   17176             :             json_name_and_value
   17177         348 :                 { $$ = list_make1($1); }
   17178             :             | json_name_and_value_list ',' json_name_and_value
   17179         256 :                 { $$ = lappend($1, $3); }
   17180             :         ;
   17181             : 
   17182             : json_name_and_value:
   17183             : /* Supporting this syntax seems to require major surgery
   17184             :             KEY c_expr VALUE_P json_value_expr
   17185             :                 { $$ = makeJsonKeyValue($2, $4); }
   17186             :             |
   17187             : */
   17188             :             c_expr VALUE_P json_value_expr
   17189          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17190             :             |
   17191             :             a_expr ':' json_value_expr
   17192         784 :                 { $$ = makeJsonKeyValue($1, $3); }
   17193             :         ;
   17194             : 
   17195             : /* empty means false for objects, true for arrays */
   17196             : json_object_constructor_null_clause_opt:
   17197          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17198         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17199         412 :             | /* EMPTY */                       { $$ = false; }
   17200             :         ;
   17201             : 
   17202             : json_array_constructor_null_clause_opt:
   17203          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17204          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17205         168 :             | /* EMPTY */                           { $$ = true; }
   17206             :         ;
   17207             : 
   17208             : json_value_expr_list:
   17209         108 :             json_value_expr                             { $$ = list_make1($1); }
   17210         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17211             :         ;
   17212             : 
   17213             : json_aggregate_func:
   17214             :             JSON_OBJECTAGG '('
   17215             :                 json_name_and_value
   17216             :                 json_object_constructor_null_clause_opt
   17217             :                 json_key_uniqueness_constraint_opt
   17218             :                 json_returning_clause_opt
   17219             :             ')'
   17220             :                 {
   17221         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17222             : 
   17223         204 :                     n->arg = (JsonKeyValue *) $3;
   17224         204 :                     n->absent_on_null = $4;
   17225         204 :                     n->unique = $5;
   17226         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17227         204 :                     n->constructor->output = (JsonOutput *) $6;
   17228         204 :                     n->constructor->agg_order = NULL;
   17229         204 :                     n->constructor->location = @1;
   17230         204 :                     $$ = (Node *) n;
   17231             :                 }
   17232             :             | JSON_ARRAYAGG '('
   17233             :                 json_value_expr
   17234             :                 json_array_aggregate_order_by_clause_opt
   17235             :                 json_array_constructor_null_clause_opt
   17236             :                 json_returning_clause_opt
   17237             :             ')'
   17238             :                 {
   17239         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17240             : 
   17241         156 :                     n->arg = (JsonValueExpr *) $3;
   17242         156 :                     n->absent_on_null = $5;
   17243         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17244         156 :                     n->constructor->agg_order = $4;
   17245         156 :                     n->constructor->output = (JsonOutput *) $6;
   17246         156 :                     n->constructor->location = @1;
   17247         156 :                     $$ = (Node *) n;
   17248             :                 }
   17249             :         ;
   17250             : 
   17251             : json_array_aggregate_order_by_clause_opt:
   17252          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17253         138 :             | /* EMPTY */                           { $$ = NIL; }
   17254             :         ;
   17255             : 
   17256             : /*****************************************************************************
   17257             :  *
   17258             :  *  target list for SELECT
   17259             :  *
   17260             :  *****************************************************************************/
   17261             : 
   17262      476992 : opt_target_list: target_list                        { $$ = $1; }
   17263         440 :             | /* EMPTY */                           { $$ = NIL; }
   17264             :         ;
   17265             : 
   17266             : target_list:
   17267      483832 :             target_el                               { $$ = list_make1($1); }
   17268      707524 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17269             :         ;
   17270             : 
   17271             : target_el:  a_expr AS ColLabel
   17272             :                 {
   17273      240506 :                     $$ = makeNode(ResTarget);
   17274      240506 :                     $$->name = $3;
   17275      240506 :                     $$->indirection = NIL;
   17276      240506 :                     $$->val = (Node *) $1;
   17277      240506 :                     $$->location = @1;
   17278             :                 }
   17279             :             | a_expr BareColLabel
   17280             :                 {
   17281        3616 :                     $$ = makeNode(ResTarget);
   17282        3616 :                     $$->name = $2;
   17283        3616 :                     $$->indirection = NIL;
   17284        3616 :                     $$->val = (Node *) $1;
   17285        3616 :                     $$->location = @1;
   17286             :                 }
   17287             :             | a_expr
   17288             :                 {
   17289      888908 :                     $$ = makeNode(ResTarget);
   17290      888908 :                     $$->name = NULL;
   17291      888908 :                     $$->indirection = NIL;
   17292      888908 :                     $$->val = (Node *) $1;
   17293      888908 :                     $$->location = @1;
   17294             :                 }
   17295             :             | '*'
   17296             :                 {
   17297       58326 :                     ColumnRef  *n = makeNode(ColumnRef);
   17298             : 
   17299       58326 :                     n->fields = list_make1(makeNode(A_Star));
   17300       58326 :                     n->location = @1;
   17301             : 
   17302       58326 :                     $$ = makeNode(ResTarget);
   17303       58326 :                     $$->name = NULL;
   17304       58326 :                     $$->indirection = NIL;
   17305       58326 :                     $$->val = (Node *) n;
   17306       58326 :                     $$->location = @1;
   17307             :                 }
   17308             :         ;
   17309             : 
   17310             : 
   17311             : /*****************************************************************************
   17312             :  *
   17313             :  *  Names and constants
   17314             :  *
   17315             :  *****************************************************************************/
   17316             : 
   17317             : qualified_name_list:
   17318       17134 :             qualified_name                          { $$ = list_make1($1); }
   17319         456 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17320             :         ;
   17321             : 
   17322             : /*
   17323             :  * The production for a qualified relation name has to exactly match the
   17324             :  * production for a qualified func_name, because in a FROM clause we cannot
   17325             :  * tell which we are parsing until we see what comes after it ('(' for a
   17326             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17327             :  * which may contain subscripts, and reject that case in the C code.
   17328             :  */
   17329             : qualified_name:
   17330             :             ColId
   17331             :                 {
   17332      421652 :                     $$ = makeRangeVar(NULL, $1, @1);
   17333             :                 }
   17334             :             | ColId indirection
   17335             :                 {
   17336      268772 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17337             :                 }
   17338             :         ;
   17339             : 
   17340             : name_list:  name
   17341       28832 :                     { $$ = list_make1(makeString($1)); }
   17342             :             | name_list ',' name
   17343       60674 :                     { $$ = lappend($1, makeString($3)); }
   17344             :         ;
   17345             : 
   17346             : 
   17347      179790 : name:       ColId                                   { $$ = $1; };
   17348             : 
   17349     1619162 : attr_name:  ColLabel                                { $$ = $1; };
   17350             : 
   17351          52 : file_name:  Sconst                                  { $$ = $1; };
   17352             : 
   17353             : /*
   17354             :  * The production for a qualified func_name has to exactly match the
   17355             :  * production for a qualified columnref, because we cannot tell which we
   17356             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17357             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17358             :  * may contain subscripts, and reject that case in the C code.  (If we
   17359             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17360             :  */
   17361             : func_name:  type_function_name
   17362      291768 :                     { $$ = list_make1(makeString($1)); }
   17363             :             | ColId indirection
   17364             :                     {
   17365      134110 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17366             :                                              yyscanner);
   17367             :                     }
   17368             :         ;
   17369             : 
   17370             : 
   17371             : /*
   17372             :  * Constants
   17373             :  */
   17374             : AexprConst: Iconst
   17375             :                 {
   17376      384316 :                     $$ = makeIntConst($1, @1);
   17377             :                 }
   17378             :             | FCONST
   17379             :                 {
   17380       11368 :                     $$ = makeFloatConst($1, @1);
   17381             :                 }
   17382             :             | Sconst
   17383             :                 {
   17384      761844 :                     $$ = makeStringConst($1, @1);
   17385             :                 }
   17386             :             | BCONST
   17387             :                 {
   17388         754 :                     $$ = makeBitStringConst($1, @1);
   17389             :                 }
   17390             :             | XCONST
   17391             :                 {
   17392             :                     /* This is a bit constant per SQL99:
   17393             :                      * Without Feature F511, "BIT data type",
   17394             :                      * a <general literal> shall not be a
   17395             :                      * <bit string literal> or a <hex string literal>.
   17396             :                      */
   17397        3302 :                     $$ = makeBitStringConst($1, @1);
   17398             :                 }
   17399             :             | func_name Sconst
   17400             :                 {
   17401             :                     /* generic type 'literal' syntax */
   17402        9836 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17403             : 
   17404        9836 :                     t->location = @1;
   17405        9836 :                     $$ = makeStringConstCast($2, @2, t);
   17406             :                 }
   17407             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17408             :                 {
   17409             :                     /* generic syntax with a type modifier */
   17410           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17411             :                     ListCell   *lc;
   17412             : 
   17413             :                     /*
   17414             :                      * We must use func_arg_list and opt_sort_clause in the
   17415             :                      * production to avoid reduce/reduce conflicts, but we
   17416             :                      * don't actually wish to allow NamedArgExpr in this
   17417             :                      * context, nor ORDER BY.
   17418             :                      */
   17419           0 :                     foreach(lc, $3)
   17420             :                     {
   17421           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17422             : 
   17423           0 :                         if (IsA(arg, NamedArgExpr))
   17424           0 :                             ereport(ERROR,
   17425             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17426             :                                      errmsg("type modifier cannot have parameter name"),
   17427             :                                      parser_errposition(arg->location)));
   17428             :                     }
   17429           0 :                     if ($4 != NIL)
   17430           0 :                             ereport(ERROR,
   17431             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17432             :                                      errmsg("type modifier cannot have ORDER BY"),
   17433             :                                      parser_errposition(@4)));
   17434             : 
   17435           0 :                     t->typmods = $3;
   17436           0 :                     t->location = @1;
   17437           0 :                     $$ = makeStringConstCast($6, @6, t);
   17438             :                 }
   17439             :             | ConstTypename Sconst
   17440             :                 {
   17441        3114 :                     $$ = makeStringConstCast($2, @2, $1);
   17442             :                 }
   17443             :             | ConstInterval Sconst opt_interval
   17444             :                 {
   17445        3298 :                     TypeName   *t = $1;
   17446             : 
   17447        3298 :                     t->typmods = $3;
   17448        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17449             :                 }
   17450             :             | ConstInterval '(' Iconst ')' Sconst
   17451             :                 {
   17452          12 :                     TypeName   *t = $1;
   17453             : 
   17454          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17455             :                                             makeIntConst($3, @3));
   17456          12 :                     $$ = makeStringConstCast($5, @5, t);
   17457             :                 }
   17458             :             | TRUE_P
   17459             :                 {
   17460       31174 :                     $$ = makeBoolAConst(true, @1);
   17461             :                 }
   17462             :             | FALSE_P
   17463             :                 {
   17464       36416 :                     $$ = makeBoolAConst(false, @1);
   17465             :                 }
   17466             :             | NULL_P
   17467             :                 {
   17468       67038 :                     $$ = makeNullAConst(@1);
   17469             :                 }
   17470             :         ;
   17471             : 
   17472      410402 : Iconst:     ICONST                                  { $$ = $1; };
   17473      833712 : Sconst:     SCONST                                  { $$ = $1; };
   17474             : 
   17475       17842 : SignedIconst: Iconst                                { $$ = $1; }
   17476           0 :             | '+' Iconst                            { $$ = + $2; }
   17477         290 :             | '-' Iconst                            { $$ = - $2; }
   17478             :         ;
   17479             : 
   17480             : /* Role specifications */
   17481             : RoleId:     RoleSpec
   17482             :                 {
   17483        1916 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17484             : 
   17485        1916 :                     switch (spc->roletype)
   17486             :                     {
   17487        1906 :                         case ROLESPEC_CSTRING:
   17488        1906 :                             $$ = spc->rolename;
   17489        1906 :                             break;
   17490           4 :                         case ROLESPEC_PUBLIC:
   17491           4 :                             ereport(ERROR,
   17492             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17493             :                                      errmsg("role name \"%s\" is reserved",
   17494             :                                             "public"),
   17495             :                                      parser_errposition(@1)));
   17496             :                             break;
   17497           2 :                         case ROLESPEC_SESSION_USER:
   17498           2 :                             ereport(ERROR,
   17499             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17500             :                                      errmsg("%s cannot be used as a role name here",
   17501             :                                             "SESSION_USER"),
   17502             :                                      parser_errposition(@1)));
   17503             :                             break;
   17504           2 :                         case ROLESPEC_CURRENT_USER:
   17505           2 :                             ereport(ERROR,
   17506             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17507             :                                      errmsg("%s cannot be used as a role name here",
   17508             :                                             "CURRENT_USER"),
   17509             :                                      parser_errposition(@1)));
   17510             :                             break;
   17511           2 :                         case ROLESPEC_CURRENT_ROLE:
   17512           2 :                             ereport(ERROR,
   17513             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17514             :                                      errmsg("%s cannot be used as a role name here",
   17515             :                                             "CURRENT_ROLE"),
   17516             :                                      parser_errposition(@1)));
   17517             :                             break;
   17518             :                     }
   17519        1906 :                 }
   17520             :             ;
   17521             : 
   17522             : RoleSpec:   NonReservedWord
   17523             :                 {
   17524             :                     /*
   17525             :                      * "public" and "none" are not keywords, but they must
   17526             :                      * be treated specially here.
   17527             :                      */
   17528             :                     RoleSpec   *n;
   17529             : 
   17530       34436 :                     if (strcmp($1, "public") == 0)
   17531             :                     {
   17532       17378 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17533       17378 :                         n->roletype = ROLESPEC_PUBLIC;
   17534             :                     }
   17535       17058 :                     else if (strcmp($1, "none") == 0)
   17536             :                     {
   17537          26 :                         ereport(ERROR,
   17538             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17539             :                                  errmsg("role name \"%s\" is reserved",
   17540             :                                         "none"),
   17541             :                                  parser_errposition(@1)));
   17542             :                     }
   17543             :                     else
   17544             :                     {
   17545       17032 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17546       17032 :                         n->rolename = pstrdup($1);
   17547             :                     }
   17548       34410 :                     $$ = n;
   17549             :                 }
   17550             :             | CURRENT_ROLE
   17551             :                 {
   17552         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17553             :                 }
   17554             :             | CURRENT_USER
   17555             :                 {
   17556         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17557             :                 }
   17558             :             | SESSION_USER
   17559             :                 {
   17560          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17561             :                 }
   17562             :         ;
   17563             : 
   17564             : role_list:  RoleSpec
   17565        3246 :                 { $$ = list_make1($1); }
   17566             :             | role_list ',' RoleSpec
   17567         270 :                 { $$ = lappend($1, $3); }
   17568             :         ;
   17569             : 
   17570             : 
   17571             : /*****************************************************************************
   17572             :  *
   17573             :  * PL/pgSQL extensions
   17574             :  *
   17575             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17576             :  * historically it can include just about anything that can follow SELECT.
   17577             :  * Therefore the returned struct is a SelectStmt.
   17578             :  *****************************************************************************/
   17579             : 
   17580             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17581             :             from_clause where_clause
   17582             :             group_clause having_clause window_clause
   17583             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17584             :                 {
   17585       40264 :                     SelectStmt *n = makeNode(SelectStmt);
   17586             : 
   17587       40264 :                     n->distinctClause = $1;
   17588       40264 :                     n->targetList = $2;
   17589       40264 :                     n->fromClause = $3;
   17590       40264 :                     n->whereClause = $4;
   17591       40264 :                     n->groupClause = ($5)->list;
   17592       40264 :                     n->groupDistinct = ($5)->distinct;
   17593       40264 :                     n->havingClause = $6;
   17594       40264 :                     n->windowClause = $7;
   17595       40264 :                     n->sortClause = $8;
   17596       40264 :                     if ($9)
   17597             :                     {
   17598           4 :                         n->limitOffset = $9->limitOffset;
   17599           4 :                         n->limitCount = $9->limitCount;
   17600           4 :                         if (!n->sortClause &&
   17601           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17602           0 :                             ereport(ERROR,
   17603             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17604             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17605             :                                      parser_errposition($9->optionLoc)));
   17606           4 :                         n->limitOption = $9->limitOption;
   17607             :                     }
   17608       40264 :                     n->lockingClause = $10;
   17609       40264 :                     $$ = (Node *) n;
   17610             :                 }
   17611             :         ;
   17612             : 
   17613             : /*
   17614             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17615             :  */
   17616             : 
   17617             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17618             :                 {
   17619        7028 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17620             : 
   17621        7028 :                     n->name = $1;
   17622        7028 :                     n->indirection = check_indirection($2, yyscanner);
   17623             :                     /* nnames will be filled by calling production */
   17624        7028 :                     n->val = (SelectStmt *) $4;
   17625        7028 :                     n->location = @1;
   17626        7028 :                     $$ = (Node *) n;
   17627             :                 }
   17628             :         ;
   17629             : 
   17630        7004 : plassign_target: ColId                          { $$ = $1; }
   17631          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17632             :         ;
   17633             : 
   17634             : plassign_equals: COLON_EQUALS
   17635             :             | '='
   17636             :         ;
   17637             : 
   17638             : 
   17639             : /*
   17640             :  * Name classification hierarchy.
   17641             :  *
   17642             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17643             :  * no known keyword.  In most cases, we can accept certain keywords as
   17644             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17645             :  * as possible to minimize the impact of "reserved words" on programmers.
   17646             :  * So, we divide names into several possible classes.  The classification
   17647             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17648             :  */
   17649             : 
   17650             : /* Column identifier --- names that can be column, table, etc names.
   17651             :  */
   17652     3480108 : ColId:      IDENT                                   { $$ = $1; }
   17653       59644 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17654        6054 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17655             :         ;
   17656             : 
   17657             : /* Type/function identifier --- names that can be type or function names.
   17658             :  */
   17659      701428 : type_function_name: IDENT                           { $$ = $1; }
   17660       75684 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17661          66 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17662             :         ;
   17663             : 
   17664             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17665             :  */
   17666       83866 : NonReservedWord:    IDENT                           { $$ = $1; }
   17667       29946 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17668         178 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17669        5156 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17670             :         ;
   17671             : 
   17672             : /* Column label --- allowed labels in "AS" clauses.
   17673             :  * This presently includes *all* Postgres keywords.
   17674             :  */
   17675     1842670 : ColLabel:   IDENT                                   { $$ = $1; }
   17676       40814 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17677         284 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17678        1796 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17679        7510 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17680             :         ;
   17681             : 
   17682             : /* Bare column label --- names that can be column labels without writing "AS".
   17683             :  * This classification is orthogonal to the other keyword categories.
   17684             :  */
   17685        3602 : BareColLabel:   IDENT                               { $$ = $1; }
   17686          14 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17687             :         ;
   17688             : 
   17689             : 
   17690             : /*
   17691             :  * Keyword category lists.  Generally, every keyword present in
   17692             :  * the Postgres grammar should appear in exactly one of these lists.
   17693             :  *
   17694             :  * Put a new keyword into the first list that it can go into without causing
   17695             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17696             :  * categories of keywords.
   17697             :  *
   17698             :  * Make sure that each keyword's category in kwlist.h matches where
   17699             :  * it is listed here.  (Someday we may be able to generate these lists and
   17700             :  * kwlist.h's table from one source of truth.)
   17701             :  */
   17702             : 
   17703             : /* "Unreserved" keywords --- available for use as any kind of name.
   17704             :  */
   17705             : unreserved_keyword:
   17706             :               ABORT_P
   17707             :             | ABSENT
   17708             :             | ABSOLUTE_P
   17709             :             | ACCESS
   17710             :             | ACTION
   17711             :             | ADD_P
   17712             :             | ADMIN
   17713             :             | AFTER
   17714             :             | AGGREGATE
   17715             :             | ALSO
   17716             :             | ALTER
   17717             :             | ALWAYS
   17718             :             | ASENSITIVE
   17719             :             | ASSERTION
   17720             :             | ASSIGNMENT
   17721             :             | AT
   17722             :             | ATOMIC
   17723             :             | ATTACH
   17724             :             | ATTRIBUTE
   17725             :             | BACKWARD
   17726             :             | BEFORE
   17727             :             | BEGIN_P
   17728             :             | BREADTH
   17729             :             | BY
   17730             :             | CACHE
   17731             :             | CALL
   17732             :             | CALLED
   17733             :             | CASCADE
   17734             :             | CASCADED
   17735             :             | CATALOG_P
   17736             :             | CHAIN
   17737             :             | CHARACTERISTICS
   17738             :             | CHECKPOINT
   17739             :             | CLASS
   17740             :             | CLOSE
   17741             :             | CLUSTER
   17742             :             | COLUMNS
   17743             :             | COMMENT
   17744             :             | COMMENTS
   17745             :             | COMMIT
   17746             :             | COMMITTED
   17747             :             | COMPRESSION
   17748             :             | CONDITIONAL
   17749             :             | CONFIGURATION
   17750             :             | CONFLICT
   17751             :             | CONNECTION
   17752             :             | CONSTRAINTS
   17753             :             | CONTENT_P
   17754             :             | CONTINUE_P
   17755             :             | CONVERSION_P
   17756             :             | COPY
   17757             :             | COST
   17758             :             | CSV
   17759             :             | CUBE
   17760             :             | CURRENT_P
   17761             :             | CURSOR
   17762             :             | CYCLE
   17763             :             | DATA_P
   17764             :             | DATABASE
   17765             :             | DAY_P
   17766             :             | DEALLOCATE
   17767             :             | DECLARE
   17768             :             | DEFAULTS
   17769             :             | DEFERRED
   17770             :             | DEFINER
   17771             :             | DELETE_P
   17772             :             | DELIMITER
   17773             :             | DELIMITERS
   17774             :             | DEPENDS
   17775             :             | DEPTH
   17776             :             | DETACH
   17777             :             | DICTIONARY
   17778             :             | DISABLE_P
   17779             :             | DISCARD
   17780             :             | DOCUMENT_P
   17781             :             | DOMAIN_P
   17782             :             | DOUBLE_P
   17783             :             | DROP
   17784             :             | EACH
   17785             :             | EMPTY_P
   17786             :             | ENABLE_P
   17787             :             | ENCODING
   17788             :             | ENCRYPTED
   17789             :             | ENFORCED
   17790             :             | ENUM_P
   17791             :             | ERROR_P
   17792             :             | ESCAPE
   17793             :             | EVENT
   17794             :             | EXCLUDE
   17795             :             | EXCLUDING
   17796             :             | EXCLUSIVE
   17797             :             | EXECUTE
   17798             :             | EXPLAIN
   17799             :             | EXPRESSION
   17800             :             | EXTENSION
   17801             :             | EXTERNAL
   17802             :             | FAMILY
   17803             :             | FILTER
   17804             :             | FINALIZE
   17805             :             | FIRST_P
   17806             :             | FOLLOWING
   17807             :             | FORCE
   17808             :             | FORMAT
   17809             :             | FORWARD
   17810             :             | FUNCTION
   17811             :             | FUNCTIONS
   17812             :             | GENERATED
   17813             :             | GLOBAL
   17814             :             | GRANTED
   17815             :             | GROUPS
   17816             :             | HANDLER
   17817             :             | HEADER_P
   17818             :             | HOLD
   17819             :             | HOUR_P
   17820             :             | IDENTITY_P
   17821             :             | IF_P
   17822             :             | IMMEDIATE
   17823             :             | IMMUTABLE
   17824             :             | IMPLICIT_P
   17825             :             | IMPORT_P
   17826             :             | INCLUDE
   17827             :             | INCLUDING
   17828             :             | INCREMENT
   17829             :             | INDENT
   17830             :             | INDEX
   17831             :             | INDEXES
   17832             :             | INHERIT
   17833             :             | INHERITS
   17834             :             | INLINE_P
   17835             :             | INPUT_P
   17836             :             | INSENSITIVE
   17837             :             | INSERT
   17838             :             | INSTEAD
   17839             :             | INVOKER
   17840             :             | ISOLATION
   17841             :             | KEEP
   17842             :             | KEY
   17843             :             | KEYS
   17844             :             | LABEL
   17845             :             | LANGUAGE
   17846             :             | LARGE_P
   17847             :             | LAST_P
   17848             :             | LEAKPROOF
   17849             :             | LEVEL
   17850             :             | LISTEN
   17851             :             | LOAD
   17852             :             | LOCAL
   17853             :             | LOCATION
   17854             :             | LOCK_P
   17855             :             | LOCKED
   17856             :             | LOGGED
   17857             :             | MAPPING
   17858             :             | MATCH
   17859             :             | MATCHED
   17860             :             | MATERIALIZED
   17861             :             | MAXVALUE
   17862             :             | MERGE
   17863             :             | METHOD
   17864             :             | MINUTE_P
   17865             :             | MINVALUE
   17866             :             | MODE
   17867             :             | MONTH_P
   17868             :             | MOVE
   17869             :             | NAME_P
   17870             :             | NAMES
   17871             :             | NESTED
   17872             :             | NEW
   17873             :             | NEXT
   17874             :             | NFC
   17875             :             | NFD
   17876             :             | NFKC
   17877             :             | NFKD
   17878             :             | NO
   17879             :             | NORMALIZED
   17880             :             | NOTHING
   17881             :             | NOTIFY
   17882             :             | NOWAIT
   17883             :             | NULLS_P
   17884             :             | OBJECT_P
   17885             :             | OBJECTS_P
   17886             :             | OF
   17887             :             | OFF
   17888             :             | OIDS
   17889             :             | OLD
   17890             :             | OMIT
   17891             :             | OPERATOR
   17892             :             | OPTION
   17893             :             | OPTIONS
   17894             :             | ORDINALITY
   17895             :             | OTHERS
   17896             :             | OVER
   17897             :             | OVERRIDING
   17898             :             | OWNED
   17899             :             | OWNER
   17900             :             | PARALLEL
   17901             :             | PARAMETER
   17902             :             | PARSER
   17903             :             | PARTIAL
   17904             :             | PARTITION
   17905             :             | PASSING
   17906             :             | PASSWORD
   17907             :             | PATH
   17908             :             | PERIOD
   17909             :             | PLAN
   17910             :             | PLANS
   17911             :             | POLICY
   17912             :             | PRECEDING
   17913             :             | PREPARE
   17914             :             | PREPARED
   17915             :             | PRESERVE
   17916             :             | PRIOR
   17917             :             | PRIVILEGES
   17918             :             | PROCEDURAL
   17919             :             | PROCEDURE
   17920             :             | PROCEDURES
   17921             :             | PROGRAM
   17922             :             | PUBLICATION
   17923             :             | QUOTE
   17924             :             | QUOTES
   17925             :             | RANGE
   17926             :             | READ
   17927             :             | REASSIGN
   17928             :             | RECURSIVE
   17929             :             | REF_P
   17930             :             | REFERENCING
   17931             :             | REFRESH
   17932             :             | REINDEX
   17933             :             | RELATIVE_P
   17934             :             | RELEASE
   17935             :             | RENAME
   17936             :             | REPEATABLE
   17937             :             | REPLACE
   17938             :             | REPLICA
   17939             :             | RESET
   17940             :             | RESTART
   17941             :             | RESTRICT
   17942             :             | RETURN
   17943             :             | RETURNS
   17944             :             | REVOKE
   17945             :             | ROLE
   17946             :             | ROLLBACK
   17947             :             | ROLLUP
   17948             :             | ROUTINE
   17949             :             | ROUTINES
   17950             :             | ROWS
   17951             :             | RULE
   17952             :             | SAVEPOINT
   17953             :             | SCALAR
   17954             :             | SCHEMA
   17955             :             | SCHEMAS
   17956             :             | SCROLL
   17957             :             | SEARCH
   17958             :             | SECOND_P
   17959             :             | SECURITY
   17960             :             | SEQUENCE
   17961             :             | SEQUENCES
   17962             :             | SERIALIZABLE
   17963             :             | SERVER
   17964             :             | SESSION
   17965             :             | SET
   17966             :             | SETS
   17967             :             | SHARE
   17968             :             | SHOW
   17969             :             | SIMPLE
   17970             :             | SKIP
   17971             :             | SNAPSHOT
   17972             :             | SOURCE
   17973             :             | SQL_P
   17974             :             | STABLE
   17975             :             | STANDALONE_P
   17976             :             | START
   17977             :             | STATEMENT
   17978             :             | STATISTICS
   17979             :             | STDIN
   17980             :             | STDOUT
   17981             :             | STORAGE
   17982             :             | STORED
   17983             :             | STRICT_P
   17984             :             | STRING_P
   17985             :             | STRIP_P
   17986             :             | SUBSCRIPTION
   17987             :             | SUPPORT
   17988             :             | SYSID
   17989             :             | SYSTEM_P
   17990             :             | TABLES
   17991             :             | TABLESPACE
   17992             :             | TARGET
   17993             :             | TEMP
   17994             :             | TEMPLATE
   17995             :             | TEMPORARY
   17996             :             | TEXT_P
   17997             :             | TIES
   17998             :             | TRANSACTION
   17999             :             | TRANSFORM
   18000             :             | TRIGGER
   18001             :             | TRUNCATE
   18002             :             | TRUSTED
   18003             :             | TYPE_P
   18004             :             | TYPES_P
   18005             :             | UESCAPE
   18006             :             | UNBOUNDED
   18007             :             | UNCOMMITTED
   18008             :             | UNCONDITIONAL
   18009             :             | UNENCRYPTED
   18010             :             | UNKNOWN
   18011             :             | UNLISTEN
   18012             :             | UNLOGGED
   18013             :             | UNTIL
   18014             :             | UPDATE
   18015             :             | VACUUM
   18016             :             | VALID
   18017             :             | VALIDATE
   18018             :             | VALIDATOR
   18019             :             | VALUE_P
   18020             :             | VARYING
   18021             :             | VERSION_P
   18022             :             | VIEW
   18023             :             | VIEWS
   18024             :             | VIRTUAL
   18025             :             | VOLATILE
   18026             :             | WHITESPACE_P
   18027             :             | WITHIN
   18028             :             | WITHOUT
   18029             :             | WORK
   18030             :             | WRAPPER
   18031             :             | WRITE
   18032             :             | XML_P
   18033             :             | YEAR_P
   18034             :             | YES_P
   18035             :             | ZONE
   18036             :         ;
   18037             : 
   18038             : /* Column identifier --- keywords that can be column, table, etc names.
   18039             :  *
   18040             :  * Many of these keywords will in fact be recognized as type or function
   18041             :  * names too; but they have special productions for the purpose, and so
   18042             :  * can't be treated as "generic" type or function names.
   18043             :  *
   18044             :  * The type names appearing here are not usable as function names
   18045             :  * because they can be followed by '(' in typename productions, which
   18046             :  * looks too much like a function call for an LR(1) parser.
   18047             :  */
   18048             : col_name_keyword:
   18049             :               BETWEEN
   18050             :             | BIGINT
   18051             :             | BIT
   18052             :             | BOOLEAN_P
   18053             :             | CHAR_P
   18054             :             | CHARACTER
   18055             :             | COALESCE
   18056             :             | DEC
   18057             :             | DECIMAL_P
   18058             :             | EXISTS
   18059             :             | EXTRACT
   18060             :             | FLOAT_P
   18061             :             | GREATEST
   18062             :             | GROUPING
   18063             :             | INOUT
   18064             :             | INT_P
   18065             :             | INTEGER
   18066             :             | INTERVAL
   18067             :             | JSON
   18068             :             | JSON_ARRAY
   18069             :             | JSON_ARRAYAGG
   18070             :             | JSON_EXISTS
   18071             :             | JSON_OBJECT
   18072             :             | JSON_OBJECTAGG
   18073             :             | JSON_QUERY
   18074             :             | JSON_SCALAR
   18075             :             | JSON_SERIALIZE
   18076             :             | JSON_TABLE
   18077             :             | JSON_VALUE
   18078             :             | LEAST
   18079             :             | MERGE_ACTION
   18080             :             | NATIONAL
   18081             :             | NCHAR
   18082             :             | NONE
   18083             :             | NORMALIZE
   18084             :             | NULLIF
   18085             :             | NUMERIC
   18086             :             | OUT_P
   18087             :             | OVERLAY
   18088             :             | POSITION
   18089             :             | PRECISION
   18090             :             | REAL
   18091             :             | ROW
   18092             :             | SETOF
   18093             :             | SMALLINT
   18094             :             | SUBSTRING
   18095             :             | TIME
   18096             :             | TIMESTAMP
   18097             :             | TREAT
   18098             :             | TRIM
   18099             :             | VALUES
   18100             :             | VARCHAR
   18101             :             | XMLATTRIBUTES
   18102             :             | XMLCONCAT
   18103             :             | XMLELEMENT
   18104             :             | XMLEXISTS
   18105             :             | XMLFOREST
   18106             :             | XMLNAMESPACES
   18107             :             | XMLPARSE
   18108             :             | XMLPI
   18109             :             | XMLROOT
   18110             :             | XMLSERIALIZE
   18111             :             | XMLTABLE
   18112             :         ;
   18113             : 
   18114             : /* Type/function identifier --- keywords that can be type or function names.
   18115             :  *
   18116             :  * Most of these are keywords that are used as operators in expressions;
   18117             :  * in general such keywords can't be column names because they would be
   18118             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18119             :  *
   18120             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18121             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18122             :  * - thomas 2000-11-28
   18123             :  */
   18124             : type_func_name_keyword:
   18125             :               AUTHORIZATION
   18126             :             | BINARY
   18127             :             | COLLATION
   18128             :             | CONCURRENTLY
   18129             :             | CROSS
   18130             :             | CURRENT_SCHEMA
   18131             :             | FREEZE
   18132             :             | FULL
   18133             :             | ILIKE
   18134             :             | INNER_P
   18135             :             | IS
   18136             :             | ISNULL
   18137             :             | JOIN
   18138             :             | LEFT
   18139             :             | LIKE
   18140             :             | NATURAL
   18141             :             | NOTNULL
   18142             :             | OUTER_P
   18143             :             | OVERLAPS
   18144             :             | RIGHT
   18145             :             | SIMILAR
   18146             :             | TABLESAMPLE
   18147             :             | VERBOSE
   18148             :         ;
   18149             : 
   18150             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18151             :  *
   18152             :  * Keywords appear here if they could not be distinguished from variable,
   18153             :  * type, or function names in some contexts.  Don't put things here unless
   18154             :  * forced to.
   18155             :  */
   18156             : reserved_keyword:
   18157             :               ALL
   18158             :             | ANALYSE
   18159             :             | ANALYZE
   18160             :             | AND
   18161             :             | ANY
   18162             :             | ARRAY
   18163             :             | AS
   18164             :             | ASC
   18165             :             | ASYMMETRIC
   18166             :             | BOTH
   18167             :             | CASE
   18168             :             | CAST
   18169             :             | CHECK
   18170             :             | COLLATE
   18171             :             | COLUMN
   18172             :             | CONSTRAINT
   18173             :             | CREATE
   18174             :             | CURRENT_CATALOG
   18175             :             | CURRENT_DATE
   18176             :             | CURRENT_ROLE
   18177             :             | CURRENT_TIME
   18178             :             | CURRENT_TIMESTAMP
   18179             :             | CURRENT_USER
   18180             :             | DEFAULT
   18181             :             | DEFERRABLE
   18182             :             | DESC
   18183             :             | DISTINCT
   18184             :             | DO
   18185             :             | ELSE
   18186             :             | END_P
   18187             :             | EXCEPT
   18188             :             | FALSE_P
   18189             :             | FETCH
   18190             :             | FOR
   18191             :             | FOREIGN
   18192             :             | FROM
   18193             :             | GRANT
   18194             :             | GROUP_P
   18195             :             | HAVING
   18196             :             | IN_P
   18197             :             | INITIALLY
   18198             :             | INTERSECT
   18199             :             | INTO
   18200             :             | LATERAL_P
   18201             :             | LEADING
   18202             :             | LIMIT
   18203             :             | LOCALTIME
   18204             :             | LOCALTIMESTAMP
   18205             :             | NOT
   18206             :             | NULL_P
   18207             :             | OFFSET
   18208             :             | ON
   18209             :             | ONLY
   18210             :             | OR
   18211             :             | ORDER
   18212             :             | PLACING
   18213             :             | PRIMARY
   18214             :             | REFERENCES
   18215             :             | RETURNING
   18216             :             | SELECT
   18217             :             | SESSION_USER
   18218             :             | SOME
   18219             :             | SYMMETRIC
   18220             :             | SYSTEM_USER
   18221             :             | TABLE
   18222             :             | THEN
   18223             :             | TO
   18224             :             | TRAILING
   18225             :             | TRUE_P
   18226             :             | UNION
   18227             :             | UNIQUE
   18228             :             | USER
   18229             :             | USING
   18230             :             | VARIADIC
   18231             :             | WHEN
   18232             :             | WHERE
   18233             :             | WINDOW
   18234             :             | WITH
   18235             :         ;
   18236             : 
   18237             : /*
   18238             :  * While all keywords can be used as column labels when preceded by AS,
   18239             :  * not all of them can be used as a "bare" column label without AS.
   18240             :  * Those that can be used as a bare label must be listed here,
   18241             :  * in addition to appearing in one of the category lists above.
   18242             :  *
   18243             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18244             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18245             :  */
   18246             : bare_label_keyword:
   18247             :               ABORT_P
   18248             :             | ABSENT
   18249             :             | ABSOLUTE_P
   18250             :             | ACCESS
   18251             :             | ACTION
   18252             :             | ADD_P
   18253             :             | ADMIN
   18254             :             | AFTER
   18255             :             | AGGREGATE
   18256             :             | ALL
   18257             :             | ALSO
   18258             :             | ALTER
   18259             :             | ALWAYS
   18260             :             | ANALYSE
   18261             :             | ANALYZE
   18262             :             | AND
   18263             :             | ANY
   18264             :             | ASC
   18265             :             | ASENSITIVE
   18266             :             | ASSERTION
   18267             :             | ASSIGNMENT
   18268             :             | ASYMMETRIC
   18269             :             | AT
   18270             :             | ATOMIC
   18271             :             | ATTACH
   18272             :             | ATTRIBUTE
   18273             :             | AUTHORIZATION
   18274             :             | BACKWARD
   18275             :             | BEFORE
   18276             :             | BEGIN_P
   18277             :             | BETWEEN
   18278             :             | BIGINT
   18279             :             | BINARY
   18280             :             | BIT
   18281             :             | BOOLEAN_P
   18282             :             | BOTH
   18283             :             | BREADTH
   18284             :             | BY
   18285             :             | CACHE
   18286             :             | CALL
   18287             :             | CALLED
   18288             :             | CASCADE
   18289             :             | CASCADED
   18290             :             | CASE
   18291             :             | CAST
   18292             :             | CATALOG_P
   18293             :             | CHAIN
   18294             :             | CHARACTERISTICS
   18295             :             | CHECK
   18296             :             | CHECKPOINT
   18297             :             | CLASS
   18298             :             | CLOSE
   18299             :             | CLUSTER
   18300             :             | COALESCE
   18301             :             | COLLATE
   18302             :             | COLLATION
   18303             :             | COLUMN
   18304             :             | COLUMNS
   18305             :             | COMMENT
   18306             :             | COMMENTS
   18307             :             | COMMIT
   18308             :             | COMMITTED
   18309             :             | COMPRESSION
   18310             :             | CONCURRENTLY
   18311             :             | CONDITIONAL
   18312             :             | CONFIGURATION
   18313             :             | CONFLICT
   18314             :             | CONNECTION
   18315             :             | CONSTRAINT
   18316             :             | CONSTRAINTS
   18317             :             | CONTENT_P
   18318             :             | CONTINUE_P
   18319             :             | CONVERSION_P
   18320             :             | COPY
   18321             :             | COST
   18322             :             | CROSS
   18323             :             | CSV
   18324             :             | CUBE
   18325             :             | CURRENT_P
   18326             :             | CURRENT_CATALOG
   18327             :             | CURRENT_DATE
   18328             :             | CURRENT_ROLE
   18329             :             | CURRENT_SCHEMA
   18330             :             | CURRENT_TIME
   18331             :             | CURRENT_TIMESTAMP
   18332             :             | CURRENT_USER
   18333             :             | CURSOR
   18334             :             | CYCLE
   18335             :             | DATA_P
   18336             :             | DATABASE
   18337             :             | DEALLOCATE
   18338             :             | DEC
   18339             :             | DECIMAL_P
   18340             :             | DECLARE
   18341             :             | DEFAULT
   18342             :             | DEFAULTS
   18343             :             | DEFERRABLE
   18344             :             | DEFERRED
   18345             :             | DEFINER
   18346             :             | DELETE_P
   18347             :             | DELIMITER
   18348             :             | DELIMITERS
   18349             :             | DEPENDS
   18350             :             | DEPTH
   18351             :             | DESC
   18352             :             | DETACH
   18353             :             | DICTIONARY
   18354             :             | DISABLE_P
   18355             :             | DISCARD
   18356             :             | DISTINCT
   18357             :             | DO
   18358             :             | DOCUMENT_P
   18359             :             | DOMAIN_P
   18360             :             | DOUBLE_P
   18361             :             | DROP
   18362             :             | EACH
   18363             :             | ELSE
   18364             :             | EMPTY_P
   18365             :             | ENABLE_P
   18366             :             | ENCODING
   18367             :             | ENCRYPTED
   18368             :             | END_P
   18369             :             | ENFORCED
   18370             :             | ENUM_P
   18371             :             | ERROR_P
   18372             :             | ESCAPE
   18373             :             | EVENT
   18374             :             | EXCLUDE
   18375             :             | EXCLUDING
   18376             :             | EXCLUSIVE
   18377             :             | EXECUTE
   18378             :             | EXISTS
   18379             :             | EXPLAIN
   18380             :             | EXPRESSION
   18381             :             | EXTENSION
   18382             :             | EXTERNAL
   18383             :             | EXTRACT
   18384             :             | FALSE_P
   18385             :             | FAMILY
   18386             :             | FINALIZE
   18387             :             | FIRST_P
   18388             :             | FLOAT_P
   18389             :             | FOLLOWING
   18390             :             | FORCE
   18391             :             | FOREIGN
   18392             :             | FORMAT
   18393             :             | FORWARD
   18394             :             | FREEZE
   18395             :             | FULL
   18396             :             | FUNCTION
   18397             :             | FUNCTIONS
   18398             :             | GENERATED
   18399             :             | GLOBAL
   18400             :             | GRANTED
   18401             :             | GREATEST
   18402             :             | GROUPING
   18403             :             | GROUPS
   18404             :             | HANDLER
   18405             :             | HEADER_P
   18406             :             | HOLD
   18407             :             | IDENTITY_P
   18408             :             | IF_P
   18409             :             | ILIKE
   18410             :             | IMMEDIATE
   18411             :             | IMMUTABLE
   18412             :             | IMPLICIT_P
   18413             :             | IMPORT_P
   18414             :             | IN_P
   18415             :             | INCLUDE
   18416             :             | INCLUDING
   18417             :             | INCREMENT
   18418             :             | INDENT
   18419             :             | INDEX
   18420             :             | INDEXES
   18421             :             | INHERIT
   18422             :             | INHERITS
   18423             :             | INITIALLY
   18424             :             | INLINE_P
   18425             :             | INNER_P
   18426             :             | INOUT
   18427             :             | INPUT_P
   18428             :             | INSENSITIVE
   18429             :             | INSERT
   18430             :             | INSTEAD
   18431             :             | INT_P
   18432             :             | INTEGER
   18433             :             | INTERVAL
   18434             :             | INVOKER
   18435             :             | IS
   18436             :             | ISOLATION
   18437             :             | JOIN
   18438             :             | JSON
   18439             :             | JSON_ARRAY
   18440             :             | JSON_ARRAYAGG
   18441             :             | JSON_EXISTS
   18442             :             | JSON_OBJECT
   18443             :             | JSON_OBJECTAGG
   18444             :             | JSON_QUERY
   18445             :             | JSON_SCALAR
   18446             :             | JSON_SERIALIZE
   18447             :             | JSON_TABLE
   18448             :             | JSON_VALUE
   18449             :             | KEEP
   18450             :             | KEY
   18451             :             | KEYS
   18452             :             | LABEL
   18453             :             | LANGUAGE
   18454             :             | LARGE_P
   18455             :             | LAST_P
   18456             :             | LATERAL_P
   18457             :             | LEADING
   18458             :             | LEAKPROOF
   18459             :             | LEAST
   18460             :             | LEFT
   18461             :             | LEVEL
   18462             :             | LIKE
   18463             :             | LISTEN
   18464             :             | LOAD
   18465             :             | LOCAL
   18466             :             | LOCALTIME
   18467             :             | LOCALTIMESTAMP
   18468             :             | LOCATION
   18469             :             | LOCK_P
   18470             :             | LOCKED
   18471             :             | LOGGED
   18472             :             | MAPPING
   18473             :             | MATCH
   18474             :             | MATCHED
   18475             :             | MATERIALIZED
   18476             :             | MAXVALUE
   18477             :             | MERGE
   18478             :             | MERGE_ACTION
   18479             :             | METHOD
   18480             :             | MINVALUE
   18481             :             | MODE
   18482             :             | MOVE
   18483             :             | NAME_P
   18484             :             | NAMES
   18485             :             | NATIONAL
   18486             :             | NATURAL
   18487             :             | NCHAR
   18488             :             | NESTED
   18489             :             | NEW
   18490             :             | NEXT
   18491             :             | NFC
   18492             :             | NFD
   18493             :             | NFKC
   18494             :             | NFKD
   18495             :             | NO
   18496             :             | NONE
   18497             :             | NORMALIZE
   18498             :             | NORMALIZED
   18499             :             | NOT
   18500             :             | NOTHING
   18501             :             | NOTIFY
   18502             :             | NOWAIT
   18503             :             | NULL_P
   18504             :             | NULLIF
   18505             :             | NULLS_P
   18506             :             | NUMERIC
   18507             :             | OBJECT_P
   18508             :             | OBJECTS_P
   18509             :             | OF
   18510             :             | OFF
   18511             :             | OIDS
   18512             :             | OLD
   18513             :             | OMIT
   18514             :             | ONLY
   18515             :             | OPERATOR
   18516             :             | OPTION
   18517             :             | OPTIONS
   18518             :             | OR
   18519             :             | ORDINALITY
   18520             :             | OTHERS
   18521             :             | OUT_P
   18522             :             | OUTER_P
   18523             :             | OVERLAY
   18524             :             | OVERRIDING
   18525             :             | OWNED
   18526             :             | OWNER
   18527             :             | PARALLEL
   18528             :             | PARAMETER
   18529             :             | PARSER
   18530             :             | PARTIAL
   18531             :             | PARTITION
   18532             :             | PASSING
   18533             :             | PASSWORD
   18534             :             | PATH
   18535             :             | PERIOD
   18536             :             | PLACING
   18537             :             | PLAN
   18538             :             | PLANS
   18539             :             | POLICY
   18540             :             | POSITION
   18541             :             | PRECEDING
   18542             :             | PREPARE
   18543             :             | PREPARED
   18544             :             | PRESERVE
   18545             :             | PRIMARY
   18546             :             | PRIOR
   18547             :             | PRIVILEGES
   18548             :             | PROCEDURAL
   18549             :             | PROCEDURE
   18550             :             | PROCEDURES
   18551             :             | PROGRAM
   18552             :             | PUBLICATION
   18553             :             | QUOTE
   18554             :             | QUOTES
   18555             :             | RANGE
   18556             :             | READ
   18557             :             | REAL
   18558             :             | REASSIGN
   18559             :             | RECURSIVE
   18560             :             | REF_P
   18561             :             | REFERENCES
   18562             :             | REFERENCING
   18563             :             | REFRESH
   18564             :             | REINDEX
   18565             :             | RELATIVE_P
   18566             :             | RELEASE
   18567             :             | RENAME
   18568             :             | REPEATABLE
   18569             :             | REPLACE
   18570             :             | REPLICA
   18571             :             | RESET
   18572             :             | RESTART
   18573             :             | RESTRICT
   18574             :             | RETURN
   18575             :             | RETURNS
   18576             :             | REVOKE
   18577             :             | RIGHT
   18578             :             | ROLE
   18579             :             | ROLLBACK
   18580             :             | ROLLUP
   18581             :             | ROUTINE
   18582             :             | ROUTINES
   18583             :             | ROW
   18584             :             | ROWS
   18585             :             | RULE
   18586             :             | SAVEPOINT
   18587             :             | SCALAR
   18588             :             | SCHEMA
   18589             :             | SCHEMAS
   18590             :             | SCROLL
   18591             :             | SEARCH
   18592             :             | SECURITY
   18593             :             | SELECT
   18594             :             | SEQUENCE
   18595             :             | SEQUENCES
   18596             :             | SERIALIZABLE
   18597             :             | SERVER
   18598             :             | SESSION
   18599             :             | SESSION_USER
   18600             :             | SET
   18601             :             | SETOF
   18602             :             | SETS
   18603             :             | SHARE
   18604             :             | SHOW
   18605             :             | SIMILAR
   18606             :             | SIMPLE
   18607             :             | SKIP
   18608             :             | SMALLINT
   18609             :             | SNAPSHOT
   18610             :             | SOME
   18611             :             | SOURCE
   18612             :             | SQL_P
   18613             :             | STABLE
   18614             :             | STANDALONE_P
   18615             :             | START
   18616             :             | STATEMENT
   18617             :             | STATISTICS
   18618             :             | STDIN
   18619             :             | STDOUT
   18620             :             | STORAGE
   18621             :             | STORED
   18622             :             | STRICT_P
   18623             :             | STRING_P
   18624             :             | STRIP_P
   18625             :             | SUBSCRIPTION
   18626             :             | SUBSTRING
   18627             :             | SUPPORT
   18628             :             | SYMMETRIC
   18629             :             | SYSID
   18630             :             | SYSTEM_P
   18631             :             | SYSTEM_USER
   18632             :             | TABLE
   18633             :             | TABLES
   18634             :             | TABLESAMPLE
   18635             :             | TABLESPACE
   18636             :             | TARGET
   18637             :             | TEMP
   18638             :             | TEMPLATE
   18639             :             | TEMPORARY
   18640             :             | TEXT_P
   18641             :             | THEN
   18642             :             | TIES
   18643             :             | TIME
   18644             :             | TIMESTAMP
   18645             :             | TRAILING
   18646             :             | TRANSACTION
   18647             :             | TRANSFORM
   18648             :             | TREAT
   18649             :             | TRIGGER
   18650             :             | TRIM
   18651             :             | TRUE_P
   18652             :             | TRUNCATE
   18653             :             | TRUSTED
   18654             :             | TYPE_P
   18655             :             | TYPES_P
   18656             :             | UESCAPE
   18657             :             | UNBOUNDED
   18658             :             | UNCOMMITTED
   18659             :             | UNCONDITIONAL
   18660             :             | UNENCRYPTED
   18661             :             | UNIQUE
   18662             :             | UNKNOWN
   18663             :             | UNLISTEN
   18664             :             | UNLOGGED
   18665             :             | UNTIL
   18666             :             | UPDATE
   18667             :             | USER
   18668             :             | USING
   18669             :             | VACUUM
   18670             :             | VALID
   18671             :             | VALIDATE
   18672             :             | VALIDATOR
   18673             :             | VALUE_P
   18674             :             | VALUES
   18675             :             | VARCHAR
   18676             :             | VARIADIC
   18677             :             | VERBOSE
   18678             :             | VERSION_P
   18679             :             | VIEW
   18680             :             | VIEWS
   18681             :             | VIRTUAL
   18682             :             | VOLATILE
   18683             :             | WHEN
   18684             :             | WHITESPACE_P
   18685             :             | WORK
   18686             :             | WRAPPER
   18687             :             | WRITE
   18688             :             | XML_P
   18689             :             | XMLATTRIBUTES
   18690             :             | XMLCONCAT
   18691             :             | XMLELEMENT
   18692             :             | XMLEXISTS
   18693             :             | XMLFOREST
   18694             :             | XMLNAMESPACES
   18695             :             | XMLPARSE
   18696             :             | XMLPI
   18697             :             | XMLROOT
   18698             :             | XMLSERIALIZE
   18699             :             | XMLTABLE
   18700             :             | YES_P
   18701             :             | ZONE
   18702             :         ;
   18703             : 
   18704             : %%
   18705             : 
   18706             : /*
   18707             :  * The signature of this function is required by bison.  However, we
   18708             :  * ignore the passed yylloc and instead use the last token position
   18709             :  * available from the scanner.
   18710             :  */
   18711             : static void
   18712         696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18713             : {
   18714         696 :     parser_yyerror(msg);
   18715             : }
   18716             : 
   18717             : static RawStmt *
   18718      836876 : makeRawStmt(Node *stmt, int stmt_location)
   18719             : {
   18720      836876 :     RawStmt    *rs = makeNode(RawStmt);
   18721             : 
   18722      836876 :     rs->stmt = stmt;
   18723      836876 :     rs->stmt_location = stmt_location;
   18724      836876 :     rs->stmt_len = 0;            /* might get changed later */
   18725      836876 :     return rs;
   18726             : }
   18727             : 
   18728             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18729             : static void
   18730      591468 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18731             : {
   18732             :     /*
   18733             :      * If we already set the length, don't change it.  This is for situations
   18734             :      * like "select foo ;; select bar" where the same statement will be last
   18735             :      * in the string for more than one semicolon.
   18736             :      */
   18737      591468 :     if (rs->stmt_len > 0)
   18738         552 :         return;
   18739             : 
   18740             :     /* OK, update length of RawStmt */
   18741      590916 :     rs->stmt_len = end_location - rs->stmt_location;
   18742             : }
   18743             : 
   18744             : /*
   18745             :  * Adjust a PreparableStmt to reflect that it doesn't run to the end of the
   18746             :  * string.
   18747             :  */
   18748             : static void
   18749         464 : updatePreparableStmtEnd(Node *n, int end_location)
   18750             : {
   18751         464 :     if (IsA(n, SelectStmt))
   18752             :     {
   18753         276 :         SelectStmt *stmt = (SelectStmt *) n;
   18754             : 
   18755         276 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18756             :     }
   18757         188 :     else if (IsA(n, InsertStmt))
   18758             :     {
   18759          62 :         InsertStmt *stmt = (InsertStmt *) n;
   18760             : 
   18761          62 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18762             :     }
   18763         126 :     else if (IsA(n, UpdateStmt))
   18764             :     {
   18765          56 :         UpdateStmt *stmt = (UpdateStmt *) n;
   18766             : 
   18767          56 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18768             :     }
   18769          70 :     else if (IsA(n, DeleteStmt))
   18770             :     {
   18771          54 :         DeleteStmt *stmt = (DeleteStmt *) n;
   18772             : 
   18773          54 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18774             :     }
   18775          16 :     else if (IsA(n, MergeStmt))
   18776             :     {
   18777          16 :         MergeStmt  *stmt = (MergeStmt *) n;
   18778             : 
   18779          16 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18780             :     }
   18781             :     else
   18782           0 :         elog(ERROR, "unexpected node type %d", (int) n->type);
   18783         464 : }
   18784             : 
   18785             : static Node *
   18786     1861924 : makeColumnRef(char *colname, List *indirection,
   18787             :               int location, core_yyscan_t yyscanner)
   18788             : {
   18789             :     /*
   18790             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18791             :      * any subscripting in the specified indirection list.  However, any field
   18792             :      * selection at the start of the indirection list must be transposed into
   18793             :      * the "fields" part of the ColumnRef node.
   18794             :      */
   18795     1861924 :     ColumnRef  *c = makeNode(ColumnRef);
   18796     1861924 :     int         nfields = 0;
   18797             :     ListCell   *l;
   18798             : 
   18799     1861924 :     c->location = location;
   18800     2940492 :     foreach(l, indirection)
   18801             :     {
   18802     1088646 :         if (IsA(lfirst(l), A_Indices))
   18803             :         {
   18804       10078 :             A_Indirection *i = makeNode(A_Indirection);
   18805             : 
   18806       10078 :             if (nfields == 0)
   18807             :             {
   18808             :                 /* easy case - all indirection goes to A_Indirection */
   18809        7362 :                 c->fields = list_make1(makeString(colname));
   18810        7362 :                 i->indirection = check_indirection(indirection, yyscanner);
   18811             :             }
   18812             :             else
   18813             :             {
   18814             :                 /* got to split the list in two */
   18815        2716 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18816             :                                                                   nfields),
   18817             :                                                    yyscanner);
   18818        2716 :                 indirection = list_truncate(indirection, nfields);
   18819        2716 :                 c->fields = lcons(makeString(colname), indirection);
   18820             :             }
   18821       10078 :             i->arg = (Node *) c;
   18822       10078 :             return (Node *) i;
   18823             :         }
   18824     1078568 :         else if (IsA(lfirst(l), A_Star))
   18825             :         {
   18826             :             /* We only allow '*' at the end of a ColumnRef */
   18827        5450 :             if (lnext(indirection, l) != NULL)
   18828           0 :                 parser_yyerror("improper use of \"*\"");
   18829             :         }
   18830     1078568 :         nfields++;
   18831             :     }
   18832             :     /* No subscripting, so all indirection gets added to field list */
   18833     1851846 :     c->fields = lcons(makeString(colname), indirection);
   18834     1851846 :     return (Node *) c;
   18835             : }
   18836             : 
   18837             : static Node *
   18838      337204 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18839             : {
   18840      337204 :     TypeCast   *n = makeNode(TypeCast);
   18841             : 
   18842      337204 :     n->arg = arg;
   18843      337204 :     n->typeName = typename;
   18844      337204 :     n->location = location;
   18845      337204 :     return (Node *) n;
   18846             : }
   18847             : 
   18848             : static Node *
   18849       16260 : makeStringConstCast(char *str, int location, TypeName *typename)
   18850             : {
   18851       16260 :     Node       *s = makeStringConst(str, location);
   18852             : 
   18853       16260 :     return makeTypeCast(s, typename, -1);
   18854             : }
   18855             : 
   18856             : static Node *
   18857      394684 : makeIntConst(int val, int location)
   18858             : {
   18859      394684 :     A_Const    *n = makeNode(A_Const);
   18860             : 
   18861      394684 :     n->val.ival.type = T_Integer;
   18862      394684 :     n->val.ival.ival = val;
   18863      394684 :     n->location = location;
   18864             : 
   18865      394684 :     return (Node *) n;
   18866             : }
   18867             : 
   18868             : static Node *
   18869       11586 : makeFloatConst(char *str, int location)
   18870             : {
   18871       11586 :     A_Const    *n = makeNode(A_Const);
   18872             : 
   18873       11586 :     n->val.fval.type = T_Float;
   18874       11586 :     n->val.fval.fval = str;
   18875       11586 :     n->location = location;
   18876             : 
   18877       11586 :     return (Node *) n;
   18878             : }
   18879             : 
   18880             : static Node *
   18881       67852 : makeBoolAConst(bool state, int location)
   18882             : {
   18883       67852 :     A_Const    *n = makeNode(A_Const);
   18884             : 
   18885       67852 :     n->val.boolval.type = T_Boolean;
   18886       67852 :     n->val.boolval.boolval = state;
   18887       67852 :     n->location = location;
   18888             : 
   18889       67852 :     return (Node *) n;
   18890             : }
   18891             : 
   18892             : static Node *
   18893        4056 : makeBitStringConst(char *str, int location)
   18894             : {
   18895        4056 :     A_Const    *n = makeNode(A_Const);
   18896             : 
   18897        4056 :     n->val.bsval.type = T_BitString;
   18898        4056 :     n->val.bsval.bsval = str;
   18899        4056 :     n->location = location;
   18900             : 
   18901        4056 :     return (Node *) n;
   18902             : }
   18903             : 
   18904             : static Node *
   18905       67088 : makeNullAConst(int location)
   18906             : {
   18907       67088 :     A_Const    *n = makeNode(A_Const);
   18908             : 
   18909       67088 :     n->isnull = true;
   18910       67088 :     n->location = location;
   18911             : 
   18912       67088 :     return (Node *) n;
   18913             : }
   18914             : 
   18915             : static Node *
   18916        5728 : makeAConst(Node *v, int location)
   18917             : {
   18918             :     Node       *n;
   18919             : 
   18920        5728 :     switch (v->type)
   18921             :     {
   18922         218 :         case T_Float:
   18923         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18924         218 :             break;
   18925             : 
   18926        5510 :         case T_Integer:
   18927        5510 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18928        5510 :             break;
   18929             : 
   18930           0 :         default:
   18931             :             /* currently not used */
   18932             :             Assert(false);
   18933           0 :             n = NULL;
   18934             :     }
   18935             : 
   18936        5728 :     return n;
   18937             : }
   18938             : 
   18939             : /* makeRoleSpec
   18940             :  * Create a RoleSpec with the given type
   18941             :  */
   18942             : static RoleSpec *
   18943       35420 : makeRoleSpec(RoleSpecType type, int location)
   18944             : {
   18945       35420 :     RoleSpec   *spec = makeNode(RoleSpec);
   18946             : 
   18947       35420 :     spec->roletype = type;
   18948       35420 :     spec->location = location;
   18949             : 
   18950       35420 :     return spec;
   18951             : }
   18952             : 
   18953             : /* check_qualified_name --- check the result of qualified_name production
   18954             :  *
   18955             :  * It's easiest to let the grammar production for qualified_name allow
   18956             :  * subscripts and '*', which we then must reject here.
   18957             :  */
   18958             : static void
   18959      268804 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18960             : {
   18961             :     ListCell   *i;
   18962             : 
   18963      537608 :     foreach(i, names)
   18964             :     {
   18965      268804 :         if (!IsA(lfirst(i), String))
   18966           0 :             parser_yyerror("syntax error");
   18967             :     }
   18968      268804 : }
   18969             : 
   18970             : /* check_func_name --- check the result of func_name production
   18971             :  *
   18972             :  * It's easiest to let the grammar production for func_name allow subscripts
   18973             :  * and '*', which we then must reject here.
   18974             :  */
   18975             : static List *
   18976      134138 : check_func_name(List *names, core_yyscan_t yyscanner)
   18977             : {
   18978             :     ListCell   *i;
   18979             : 
   18980      402414 :     foreach(i, names)
   18981             :     {
   18982      268276 :         if (!IsA(lfirst(i), String))
   18983           0 :             parser_yyerror("syntax error");
   18984             :     }
   18985      134138 :     return names;
   18986             : }
   18987             : 
   18988             : /* check_indirection --- check the result of indirection production
   18989             :  *
   18990             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18991             :  * in the grammar, so do it here.
   18992             :  */
   18993             : static List *
   18994       81952 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18995             : {
   18996             :     ListCell   *l;
   18997             : 
   18998      109400 :     foreach(l, indirection)
   18999             :     {
   19000       27448 :         if (IsA(lfirst(l), A_Star))
   19001             :         {
   19002        1434 :             if (lnext(indirection, l) != NULL)
   19003           0 :                 parser_yyerror("improper use of \"*\"");
   19004             :         }
   19005             :     }
   19006       81952 :     return indirection;
   19007             : }
   19008             : 
   19009             : /* extractArgTypes()
   19010             :  * Given a list of FunctionParameter nodes, extract a list of just the
   19011             :  * argument types (TypeNames) for input parameters only.  This is what
   19012             :  * is needed to look up an existing function, which is what is wanted by
   19013             :  * the productions that use this call.
   19014             :  */
   19015             : static List *
   19016       16698 : extractArgTypes(List *parameters)
   19017             : {
   19018       16698 :     List       *result = NIL;
   19019             :     ListCell   *i;
   19020             : 
   19021       36202 :     foreach(i, parameters)
   19022             :     {
   19023       19504 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19024             : 
   19025       19504 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19026       19282 :             result = lappend(result, p->argType);
   19027             :     }
   19028       16698 :     return result;
   19029             : }
   19030             : 
   19031             : /* extractAggrArgTypes()
   19032             :  * As above, but work from the output of the aggr_args production.
   19033             :  */
   19034             : static List *
   19035         460 : extractAggrArgTypes(List *aggrargs)
   19036             : {
   19037             :     Assert(list_length(aggrargs) == 2);
   19038         460 :     return extractArgTypes((List *) linitial(aggrargs));
   19039             : }
   19040             : 
   19041             : /* makeOrderedSetArgs()
   19042             :  * Build the result of the aggr_args production (which see the comments for).
   19043             :  * This handles only the case where both given lists are nonempty, so that
   19044             :  * we have to deal with multiple VARIADIC arguments.
   19045             :  */
   19046             : static List *
   19047          40 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19048             :                    core_yyscan_t yyscanner)
   19049             : {
   19050          40 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19051             :     Integer    *ndirectargs;
   19052             : 
   19053             :     /* No restriction unless last direct arg is VARIADIC */
   19054          40 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19055             :     {
   19056          20 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19057             : 
   19058             :         /*
   19059             :          * We ignore the names, though the aggr_arg production allows them; it
   19060             :          * doesn't allow default values, so those need not be checked.
   19061             :          */
   19062          20 :         if (list_length(orderedargs) != 1 ||
   19063          20 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19064          20 :             !equal(lastd->argType, firsto->argType))
   19065           0 :             ereport(ERROR,
   19066             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19067             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19068             :                      parser_errposition(firsto->location)));
   19069             : 
   19070             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19071          20 :         orderedargs = NIL;
   19072             :     }
   19073             : 
   19074             :     /* don't merge into the next line, as list_concat changes directargs */
   19075          40 :     ndirectargs = makeInteger(list_length(directargs));
   19076             : 
   19077          40 :     return list_make2(list_concat(directargs, orderedargs),
   19078             :                       ndirectargs);
   19079             : }
   19080             : 
   19081             : /* insertSelectOptions()
   19082             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19083             :  *
   19084             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19085             :  */
   19086             : static void
   19087       84886 : insertSelectOptions(SelectStmt *stmt,
   19088             :                     List *sortClause, List *lockingClause,
   19089             :                     SelectLimit *limitClause,
   19090             :                     WithClause *withClause,
   19091             :                     core_yyscan_t yyscanner)
   19092             : {
   19093             :     Assert(IsA(stmt, SelectStmt));
   19094             : 
   19095             :     /*
   19096             :      * Tests here are to reject constructs like
   19097             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19098             :      */
   19099       84886 :     if (sortClause)
   19100             :     {
   19101       75638 :         if (stmt->sortClause)
   19102           0 :             ereport(ERROR,
   19103             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19104             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19105             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19106       75638 :         stmt->sortClause = sortClause;
   19107             :     }
   19108             :     /* We can handle multiple locking clauses, though */
   19109       84886 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19110       84886 :     if (limitClause && limitClause->limitOffset)
   19111             :     {
   19112         836 :         if (stmt->limitOffset)
   19113           0 :             ereport(ERROR,
   19114             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19115             :                      errmsg("multiple OFFSET clauses not allowed"),
   19116             :                      parser_errposition(limitClause->offsetLoc)));
   19117         836 :         stmt->limitOffset = limitClause->limitOffset;
   19118             :     }
   19119       84886 :     if (limitClause && limitClause->limitCount)
   19120             :     {
   19121        4652 :         if (stmt->limitCount)
   19122           0 :             ereport(ERROR,
   19123             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19124             :                      errmsg("multiple LIMIT clauses not allowed"),
   19125             :                      parser_errposition(limitClause->countLoc)));
   19126        4652 :         stmt->limitCount = limitClause->limitCount;
   19127             :     }
   19128       84886 :     if (limitClause)
   19129             :     {
   19130             :         /* If there was a conflict, we must have detected it above */
   19131             :         Assert(!stmt->limitOption);
   19132        5090 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19133           6 :             ereport(ERROR,
   19134             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19135             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19136             :                      parser_errposition(limitClause->optionLoc)));
   19137        5084 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19138             :         {
   19139             :             ListCell   *lc;
   19140             : 
   19141           6 :             foreach(lc, stmt->lockingClause)
   19142             :             {
   19143           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19144             : 
   19145           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19146           6 :                     ereport(ERROR,
   19147             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19148             :                              errmsg("%s and %s options cannot be used together",
   19149             :                                     "SKIP LOCKED", "WITH TIES"),
   19150             :                              parser_errposition(limitClause->optionLoc)));
   19151             :             }
   19152             :         }
   19153        5078 :         stmt->limitOption = limitClause->limitOption;
   19154             :     }
   19155       84874 :     if (withClause)
   19156             :     {
   19157        2896 :         if (stmt->withClause)
   19158           0 :             ereport(ERROR,
   19159             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19160             :                      errmsg("multiple WITH clauses not allowed"),
   19161             :                      parser_errposition(exprLocation((Node *) withClause))));
   19162        2896 :         stmt->withClause = withClause;
   19163             : 
   19164             :         /* Update SelectStmt's location to the start of the WITH clause */
   19165        2896 :         stmt->stmt_location = withClause->location;
   19166             :     }
   19167       84874 : }
   19168             : 
   19169             : static Node *
   19170       19334 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, int location)
   19171             : {
   19172       19334 :     SelectStmt *n = makeNode(SelectStmt);
   19173             : 
   19174       19334 :     n->op = op;
   19175       19334 :     n->all = all;
   19176       19334 :     n->larg = (SelectStmt *) larg;
   19177       19334 :     n->rarg = (SelectStmt *) rarg;
   19178       19334 :     n->stmt_location = location;
   19179       19334 :     return (Node *) n;
   19180             : }
   19181             : 
   19182             : /* SystemFuncName()
   19183             :  * Build a properly-qualified reference to a built-in function.
   19184             :  */
   19185             : List *
   19186       19266 : SystemFuncName(char *name)
   19187             : {
   19188       19266 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19189             : }
   19190             : 
   19191             : /* SystemTypeName()
   19192             :  * Build a properly-qualified reference to a built-in type.
   19193             :  *
   19194             :  * typmod is defaulted, but may be changed afterwards by caller.
   19195             :  * Likewise for the location.
   19196             :  */
   19197             : TypeName *
   19198      142438 : SystemTypeName(char *name)
   19199             : {
   19200      142438 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19201             :                                                makeString(name)));
   19202             : }
   19203             : 
   19204             : /* doNegate()
   19205             :  * Handle negation of a numeric constant.
   19206             :  *
   19207             :  * Formerly, we did this here because the optimizer couldn't cope with
   19208             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19209             :  * and a unary minus operator applied to a constant didn't qualify.
   19210             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19211             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19212             :  * there's still a good reason for doing this here, which is that we can
   19213             :  * postpone committing to a particular internal representation for simple
   19214             :  * negative constants.  It's better to leave "-123.456" in string form
   19215             :  * until we know what the desired type is.
   19216             :  */
   19217             : static Node *
   19218        9182 : doNegate(Node *n, int location)
   19219             : {
   19220        9182 :     if (IsA(n, A_Const))
   19221             :     {
   19222        8188 :         A_Const    *con = (A_Const *) n;
   19223             : 
   19224             :         /* report the constant's location as that of the '-' sign */
   19225        8188 :         con->location = location;
   19226             : 
   19227        8188 :         if (IsA(&con->val, Integer))
   19228             :         {
   19229        7230 :             con->val.ival.ival = -con->val.ival.ival;
   19230        7230 :             return n;
   19231             :         }
   19232         958 :         if (IsA(&con->val, Float))
   19233             :         {
   19234         958 :             doNegateFloat(&con->val.fval);
   19235         958 :             return n;
   19236             :         }
   19237             :     }
   19238             : 
   19239         994 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19240             : }
   19241             : 
   19242             : static void
   19243         980 : doNegateFloat(Float *v)
   19244             : {
   19245         980 :     char       *oldval = v->fval;
   19246             : 
   19247         980 :     if (*oldval == '+')
   19248           0 :         oldval++;
   19249         980 :     if (*oldval == '-')
   19250           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19251             :     else
   19252         980 :         v->fval = psprintf("-%s", oldval);
   19253         980 : }
   19254             : 
   19255             : static Node *
   19256      237716 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19257             : {
   19258             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19259      237716 :     if (IsA(lexpr, BoolExpr))
   19260             :     {
   19261      112430 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19262             : 
   19263      112430 :         if (blexpr->boolop == AND_EXPR)
   19264             :         {
   19265      109696 :             blexpr->args = lappend(blexpr->args, rexpr);
   19266      109696 :             return (Node *) blexpr;
   19267             :         }
   19268             :     }
   19269      128020 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19270             : }
   19271             : 
   19272             : static Node *
   19273       16590 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19274             : {
   19275             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19276       16590 :     if (IsA(lexpr, BoolExpr))
   19277             :     {
   19278        5866 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19279             : 
   19280        5866 :         if (blexpr->boolop == OR_EXPR)
   19281             :         {
   19282        4286 :             blexpr->args = lappend(blexpr->args, rexpr);
   19283        4286 :             return (Node *) blexpr;
   19284             :         }
   19285             :     }
   19286       12304 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19287             : }
   19288             : 
   19289             : static Node *
   19290       16920 : makeNotExpr(Node *expr, int location)
   19291             : {
   19292       16920 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19293             : }
   19294             : 
   19295             : static Node *
   19296        8152 : makeAArrayExpr(List *elements, int location)
   19297             : {
   19298        8152 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19299             : 
   19300        8152 :     n->elements = elements;
   19301        8152 :     n->location = location;
   19302        8152 :     return (Node *) n;
   19303             : }
   19304             : 
   19305             : static Node *
   19306        2750 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19307             : {
   19308        2750 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19309             : 
   19310        2750 :     svf->op = op;
   19311             :     /* svf->type will be filled during parse analysis */
   19312        2750 :     svf->typmod = typmod;
   19313        2750 :     svf->location = location;
   19314        2750 :     return (Node *) svf;
   19315             : }
   19316             : 
   19317             : static Node *
   19318         610 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19319             :             int location)
   19320             : {
   19321         610 :     XmlExpr    *x = makeNode(XmlExpr);
   19322             : 
   19323         610 :     x->op = op;
   19324         610 :     x->name = name;
   19325             : 
   19326             :     /*
   19327             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19328             :      * expression and name lists in transformXmlExpr().
   19329             :      */
   19330         610 :     x->named_args = named_args;
   19331         610 :     x->arg_names = NIL;
   19332         610 :     x->args = args;
   19333             :     /* xmloption, if relevant, must be filled in by caller */
   19334             :     /* type and typmod will be filled in during parse analysis */
   19335         610 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19336         610 :     x->location = location;
   19337         610 :     return (Node *) x;
   19338             : }
   19339             : 
   19340             : /*
   19341             :  * Merge the input and output parameters of a table function.
   19342             :  */
   19343             : static List *
   19344         202 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19345             : {
   19346             :     ListCell   *lc;
   19347             : 
   19348             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19349         412 :     foreach(lc, func_args)
   19350             :     {
   19351         210 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19352             : 
   19353         210 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19354           0 :             p->mode != FUNC_PARAM_IN &&
   19355           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19356           0 :             ereport(ERROR,
   19357             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19358             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19359             :                      parser_errposition(p->location)));
   19360             :     }
   19361             : 
   19362         202 :     return list_concat(func_args, columns);
   19363             : }
   19364             : 
   19365             : /*
   19366             :  * Determine return type of a TABLE function.  A single result column
   19367             :  * returns setof that column's type; otherwise return setof record.
   19368             :  */
   19369             : static TypeName *
   19370         202 : TableFuncTypeName(List *columns)
   19371             : {
   19372             :     TypeName   *result;
   19373             : 
   19374         202 :     if (list_length(columns) == 1)
   19375             :     {
   19376          70 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19377             : 
   19378          70 :         result = copyObject(p->argType);
   19379             :     }
   19380             :     else
   19381         132 :         result = SystemTypeName("record");
   19382             : 
   19383         202 :     result->setof = true;
   19384             : 
   19385         202 :     return result;
   19386             : }
   19387             : 
   19388             : /*
   19389             :  * Convert a list of (dotted) names to a RangeVar (like
   19390             :  * makeRangeVarFromNameList, but with position support).  The
   19391             :  * "AnyName" refers to the any_name production in the grammar.
   19392             :  */
   19393             : static RangeVar *
   19394        4764 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19395             : {
   19396        4764 :     RangeVar   *r = makeNode(RangeVar);
   19397             : 
   19398        4764 :     switch (list_length(names))
   19399             :     {
   19400        4642 :         case 1:
   19401        4642 :             r->catalogname = NULL;
   19402        4642 :             r->schemaname = NULL;
   19403        4642 :             r->relname = strVal(linitial(names));
   19404        4642 :             break;
   19405         122 :         case 2:
   19406         122 :             r->catalogname = NULL;
   19407         122 :             r->schemaname = strVal(linitial(names));
   19408         122 :             r->relname = strVal(lsecond(names));
   19409         122 :             break;
   19410           0 :         case 3:
   19411           0 :             r->catalogname = strVal(linitial(names));
   19412           0 :             r->schemaname = strVal(lsecond(names));
   19413           0 :             r->relname = strVal(lthird(names));
   19414           0 :             break;
   19415           0 :         default:
   19416           0 :             ereport(ERROR,
   19417             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19418             :                      errmsg("improper qualified name (too many dotted names): %s",
   19419             :                             NameListToString(names)),
   19420             :                      parser_errposition(position)));
   19421             :             break;
   19422             :     }
   19423             : 
   19424        4764 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19425        4764 :     r->location = position;
   19426             : 
   19427        4764 :     return r;
   19428             : }
   19429             : 
   19430             : /*
   19431             :  * Convert a relation_name with name and namelist to a RangeVar using
   19432             :  * makeRangeVar.
   19433             :  */
   19434             : static RangeVar *
   19435      268804 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19436             :                               core_yyscan_t yyscanner)
   19437             : {
   19438             :     RangeVar   *r;
   19439             : 
   19440      268804 :     check_qualified_name(namelist, yyscanner);
   19441      268804 :     r = makeRangeVar(NULL, NULL, location);
   19442             : 
   19443      268804 :     switch (list_length(namelist))
   19444             :     {
   19445      268804 :         case 1:
   19446      268804 :             r->catalogname = NULL;
   19447      268804 :             r->schemaname = name;
   19448      268804 :             r->relname = strVal(linitial(namelist));
   19449      268804 :             break;
   19450           0 :         case 2:
   19451           0 :             r->catalogname = name;
   19452           0 :             r->schemaname = strVal(linitial(namelist));
   19453           0 :             r->relname = strVal(lsecond(namelist));
   19454           0 :             break;
   19455           0 :         default:
   19456           0 :             ereport(ERROR,
   19457             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19458             :                     errmsg("improper qualified name (too many dotted names): %s",
   19459             :                            NameListToString(lcons(makeString(name), namelist))),
   19460             :                     parser_errposition(location));
   19461             :             break;
   19462             :     }
   19463             : 
   19464      268804 :     return r;
   19465             : }
   19466             : 
   19467             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19468             : static void
   19469       74252 : SplitColQualList(List *qualList,
   19470             :                  List **constraintList, CollateClause **collClause,
   19471             :                  core_yyscan_t yyscanner)
   19472             : {
   19473             :     ListCell   *cell;
   19474             : 
   19475       74252 :     *collClause = NULL;
   19476       94600 :     foreach(cell, qualList)
   19477             :     {
   19478       20348 :         Node       *n = (Node *) lfirst(cell);
   19479             : 
   19480       20348 :         if (IsA(n, Constraint))
   19481             :         {
   19482             :             /* keep it in list */
   19483       19588 :             continue;
   19484             :         }
   19485         760 :         if (IsA(n, CollateClause))
   19486             :         {
   19487         760 :             CollateClause *c = (CollateClause *) n;
   19488             : 
   19489         760 :             if (*collClause)
   19490           0 :                 ereport(ERROR,
   19491             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19492             :                          errmsg("multiple COLLATE clauses not allowed"),
   19493             :                          parser_errposition(c->location)));
   19494         760 :             *collClause = c;
   19495             :         }
   19496             :         else
   19497           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19498             :         /* remove non-Constraint nodes from qualList */
   19499         760 :         qualList = foreach_delete_current(qualList, cell);
   19500             :     }
   19501       74252 :     *constraintList = qualList;
   19502       74252 : }
   19503             : 
   19504             : /*
   19505             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19506             :  * in the output command node.  Pass NULL for any flags the particular
   19507             :  * command doesn't support.
   19508             :  */
   19509             : static void
   19510       17916 : processCASbits(int cas_bits, int location, const char *constrType,
   19511             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19512             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19513             : {
   19514             :     /* defaults */
   19515       17916 :     if (deferrable)
   19516       15816 :         *deferrable = false;
   19517       17916 :     if (initdeferred)
   19518       15816 :         *initdeferred = false;
   19519       17916 :     if (not_valid)
   19520        3904 :         *not_valid = false;
   19521       17916 :     if (is_enforced)
   19522        3376 :         *is_enforced = true;
   19523             : 
   19524       17916 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19525             :     {
   19526         242 :         if (deferrable)
   19527         242 :             *deferrable = true;
   19528             :         else
   19529           0 :             ereport(ERROR,
   19530             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19531             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19532             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19533             :                             constrType),
   19534             :                      parser_errposition(location)));
   19535             :     }
   19536             : 
   19537       17916 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19538             :     {
   19539         152 :         if (initdeferred)
   19540         152 :             *initdeferred = true;
   19541             :         else
   19542           0 :             ereport(ERROR,
   19543             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19544             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19545             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19546             :                             constrType),
   19547             :                      parser_errposition(location)));
   19548             :     }
   19549             : 
   19550       17916 :     if (cas_bits & CAS_NOT_VALID)
   19551             :     {
   19552         702 :         if (not_valid)
   19553         696 :             *not_valid = true;
   19554             :         else
   19555           6 :             ereport(ERROR,
   19556             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19557             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19558             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19559             :                             constrType),
   19560             :                      parser_errposition(location)));
   19561             :     }
   19562             : 
   19563       17910 :     if (cas_bits & CAS_NO_INHERIT)
   19564             :     {
   19565         242 :         if (no_inherit)
   19566         242 :             *no_inherit = true;
   19567             :         else
   19568           0 :             ereport(ERROR,
   19569             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19570             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19571             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19572             :                             constrType),
   19573             :                      parser_errposition(location)));
   19574             :     }
   19575             : 
   19576       17910 :     if (cas_bits & CAS_NOT_ENFORCED)
   19577             :     {
   19578         156 :         if (is_enforced)
   19579         150 :             *is_enforced = false;
   19580             :         else
   19581           6 :             ereport(ERROR,
   19582             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19583             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19584             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19585             :                             constrType),
   19586             :                      parser_errposition(location)));
   19587             : 
   19588             :         /*
   19589             :          * NB: The validated status is irrelevant when the constraint is set to
   19590             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19591             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19592             :          * will automatically be in the correct NOT VALIDATED state.
   19593             :          */
   19594         150 :         if (not_valid)
   19595         114 :             *not_valid = true;
   19596             :     }
   19597             : 
   19598       17904 :     if (cas_bits & CAS_ENFORCED)
   19599             :     {
   19600          90 :         if (is_enforced)
   19601          84 :             *is_enforced = true;
   19602             :         else
   19603           6 :             ereport(ERROR,
   19604             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19605             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19606             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19607             :                             constrType),
   19608             :                      parser_errposition(location)));
   19609             :     }
   19610       17898 : }
   19611             : 
   19612             : /*
   19613             :  * Parse a user-supplied partition strategy string into parse node
   19614             :  * PartitionStrategy representation, or die trying.
   19615             :  */
   19616             : static PartitionStrategy
   19617        5144 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19618             : {
   19619        5144 :     if (pg_strcasecmp(strategy, "list") == 0)
   19620        2600 :         return PARTITION_STRATEGY_LIST;
   19621        2544 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19622        2278 :         return PARTITION_STRATEGY_RANGE;
   19623         266 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19624         260 :         return PARTITION_STRATEGY_HASH;
   19625             : 
   19626           6 :     ereport(ERROR,
   19627             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19628             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19629             :              parser_errposition(location)));
   19630             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19631             : 
   19632             : }
   19633             : 
   19634             : /*
   19635             :  * Process pubobjspec_list to check for errors in any of the objects and
   19636             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19637             :  */
   19638             : static void
   19639        1588 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19640             : {
   19641             :     ListCell   *cell;
   19642             :     PublicationObjSpec *pubobj;
   19643        1588 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19644             : 
   19645        1588 :     if (!pubobjspec_list)
   19646           0 :         return;
   19647             : 
   19648        1588 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19649        1588 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19650          12 :         ereport(ERROR,
   19651             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19652             :                 errmsg("invalid publication object list"),
   19653             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19654             :                 parser_errposition(pubobj->location));
   19655             : 
   19656        3352 :     foreach(cell, pubobjspec_list)
   19657             :     {
   19658        1800 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19659             : 
   19660        1800 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19661         174 :             pubobj->pubobjtype = prevobjtype;
   19662             : 
   19663        1800 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19664             :         {
   19665             :             /* relation name or pubtable must be set for this type of object */
   19666        1396 :             if (!pubobj->name && !pubobj->pubtable)
   19667           6 :                 ereport(ERROR,
   19668             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19669             :                         errmsg("invalid table name"),
   19670             :                         parser_errposition(pubobj->location));
   19671             : 
   19672        1390 :             if (pubobj->name)
   19673             :             {
   19674             :                 /* convert it to PublicationTable */
   19675          58 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19676             : 
   19677          58 :                 pubtable->relation =
   19678          58 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19679          58 :                 pubobj->pubtable = pubtable;
   19680          58 :                 pubobj->name = NULL;
   19681             :             }
   19682             :         }
   19683         404 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19684          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19685             :         {
   19686             :             /* WHERE clause is not allowed on a schema object */
   19687         404 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19688           6 :                 ereport(ERROR,
   19689             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19690             :                         errmsg("WHERE clause not allowed for schema"),
   19691             :                         parser_errposition(pubobj->location));
   19692             : 
   19693             :             /* Column list is not allowed on a schema object */
   19694         398 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19695           6 :                 ereport(ERROR,
   19696             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19697             :                         errmsg("column specification not allowed for schema"),
   19698             :                         parser_errposition(pubobj->location));
   19699             : 
   19700             :             /*
   19701             :              * We can distinguish between the different type of schema objects
   19702             :              * based on whether name and pubtable is set.
   19703             :              */
   19704         392 :             if (pubobj->name)
   19705         362 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19706          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19707          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19708             :             else
   19709           6 :                 ereport(ERROR,
   19710             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19711             :                         errmsg("invalid schema name"),
   19712             :                         parser_errposition(pubobj->location));
   19713             :         }
   19714             : 
   19715        1776 :         prevobjtype = pubobj->pubobjtype;
   19716             :     }
   19717             : }
   19718             : 
   19719             : /*----------
   19720             :  * Recursive view transformation
   19721             :  *
   19722             :  * Convert
   19723             :  *
   19724             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19725             :  *
   19726             :  * to
   19727             :  *
   19728             :  *     CREATE VIEW relname (aliases) AS
   19729             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19730             :  *         SELECT aliases FROM relname
   19731             :  *
   19732             :  * Actually, just the WITH ... part, which is then inserted into the original
   19733             :  * view definition as the query.
   19734             :  * ----------
   19735             :  */
   19736             : static Node *
   19737          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19738             : {
   19739          14 :     SelectStmt *s = makeNode(SelectStmt);
   19740          14 :     WithClause *w = makeNode(WithClause);
   19741          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19742          14 :     List       *tl = NIL;
   19743             :     ListCell   *lc;
   19744             : 
   19745             :     /* create common table expression */
   19746          14 :     cte->ctename = relname;
   19747          14 :     cte->aliascolnames = aliases;
   19748          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19749          14 :     cte->ctequery = query;
   19750          14 :     cte->location = -1;
   19751             : 
   19752             :     /* create WITH clause and attach CTE */
   19753          14 :     w->recursive = true;
   19754          14 :     w->ctes = list_make1(cte);
   19755          14 :     w->location = -1;
   19756             : 
   19757             :     /*
   19758             :      * create target list for the new SELECT from the alias list of the
   19759             :      * recursive view specification
   19760             :      */
   19761          28 :     foreach(lc, aliases)
   19762             :     {
   19763          14 :         ResTarget  *rt = makeNode(ResTarget);
   19764             : 
   19765          14 :         rt->name = NULL;
   19766          14 :         rt->indirection = NIL;
   19767          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19768          14 :         rt->location = -1;
   19769             : 
   19770          14 :         tl = lappend(tl, rt);
   19771             :     }
   19772             : 
   19773             :     /*
   19774             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19775             :      * clause
   19776             :      */
   19777          14 :     s->withClause = w;
   19778          14 :     s->targetList = tl;
   19779          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19780             : 
   19781          14 :     return (Node *) s;
   19782             : }
   19783             : 
   19784             : /* parser_init()
   19785             :  * Initialize to parse one query string
   19786             :  */
   19787             : void
   19788      792858 : parser_init(base_yy_extra_type *yyext)
   19789             : {
   19790      792858 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19791      792858 : }

Generated by: LCOV version 1.14