LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 6753 7469 90.4 %
Date: 2025-02-18 22:14:58 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 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      718470 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     919             :                 (void) yynerrs;     /* suppress compiler warning */
     920             :             }
     921             :             | MODE_TYPE_NAME Typename
     922             :             {
     923        9586 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     924             :             }
     925             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     926             :             {
     927       33190 :                 pg_yyget_extra(yyscanner)->parsetree =
     928       33190 :                     list_make1(makeRawStmt($2, @2));
     929             :             }
     930             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     931             :             {
     932        6270 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     933             : 
     934        6270 :                 n->nnames = 1;
     935        6270 :                 pg_yyget_extra(yyscanner)->parsetree =
     936        6270 :                     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      574806 :                     if ($1 != NIL)
     965             :                     {
     966             :                         /* update length of previous stmt */
     967      574706 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     968             :                     }
     969      574806 :                     if ($3 != NULL)
     970       50728 :                         $$ = lappend($1, makeRawStmt($3, @3));
     971             :                     else
     972      524078 :                         $$ = $1;
     973             :                 }
     974             :             | toplevel_stmt
     975             :                 {
     976      718478 :                     if ($1 != NULL)
     977      717994 :                         $$ = list_make1(makeRawStmt($1, @1));
     978             :                     else
     979         484 :                         $$ = 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      524580 :                 { $$ = NULL; }
    1119             :         ;
    1120             : 
    1121             : /*
    1122             :  * Generic supporting productions for DDL
    1123             :  */
    1124             : opt_single_name:
    1125        5238 :             ColId                           { $$ = $1; }
    1126        1490 :             | /* EMPTY */                   { $$ = NULL; }
    1127             :         ;
    1128             : 
    1129             : opt_qualified_name:
    1130        1782 :             any_name                        { $$ = $1; }
    1131       14906 :             | /*EMPTY*/                     { $$ = NIL; }
    1132             :         ;
    1133             : 
    1134             : opt_concurrently:
    1135         984 :             CONCURRENTLY                    { $$ = true; }
    1136        7452 :             | /*EMPTY*/                     { $$ = false; }
    1137             :         ;
    1138             : 
    1139             : opt_drop_behavior:
    1140        1936 :             CASCADE                         { $$ = DROP_CASCADE; }
    1141         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1142       36856 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1143             :         ;
    1144             : 
    1145             : /*****************************************************************************
    1146             :  *
    1147             :  * CALL statement
    1148             :  *
    1149             :  *****************************************************************************/
    1150             : 
    1151             : CallStmt:   CALL func_application
    1152             :                 {
    1153         614 :                     CallStmt   *n = makeNode(CallStmt);
    1154             : 
    1155         614 :                     n->funccall = castNode(FuncCall, $2);
    1156         614 :                     $$ = (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        1314 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1170             : 
    1171        1314 :                     n->stmt_type = ROLESTMT_ROLE;
    1172        1314 :                     n->role = $3;
    1173        1314 :                     n->options = $5;
    1174        1314 :                     $$ = (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        1178 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1191        1790 :             | /* EMPTY */                           { $$ = NIL; }
    1192             :         ;
    1193             : 
    1194             : AlterOptRoleList:
    1195         586 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1196         406 :             | /* EMPTY */                           { $$ = NIL; }
    1197             :         ;
    1198             : 
    1199             : AlterOptRoleElem:
    1200             :             PASSWORD Sconst
    1201             :                 {
    1202         182 :                     $$ = makeDefElem("password",
    1203         182 :                                      (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          16 :                     $$ = makeDefElem("password",
    1217          16 :                                      (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          86 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1230             :                 }
    1231             :             | CONNECTION LIMIT SignedIconst
    1232             :                 {
    1233          24 :                     $$ = 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        1292 :                     if (strcmp($1, "superuser") == 0)
    1252         182 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1253        1110 :                     else if (strcmp($1, "nosuperuser") == 0)
    1254         100 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1255        1010 :                     else if (strcmp($1, "createrole") == 0)
    1256          92 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1257         918 :                     else if (strcmp($1, "nocreaterole") == 0)
    1258          38 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1259         880 :                     else if (strcmp($1, "replication") == 0)
    1260         120 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1261         760 :                     else if (strcmp($1, "noreplication") == 0)
    1262          96 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1263         664 :                     else if (strcmp($1, "createdb") == 0)
    1264          82 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1265         582 :                     else if (strcmp($1, "nocreatedb") == 0)
    1266          46 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1267         536 :                     else if (strcmp($1, "login") == 0)
    1268         274 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1269         262 :                     else if (strcmp($1, "nologin") == 0)
    1270          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1271         176 :                     else if (strcmp($1, "bypassrls") == 0)
    1272          72 :                         $$ = 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        1034 :             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          16 :                     $$ = 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         452 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1327             : 
    1328         452 :                     n->stmt_type = ROLESTMT_USER;
    1329         452 :                     n->role = $3;
    1330         452 :                     n->options = $5;
    1331         452 :                     $$ = (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         314 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1346             : 
    1347         314 :                     n->role = $3;
    1348         314 :                     n->action = +1;  /* add, if there are members */
    1349         314 :                     n->options = $5;
    1350         314 :                     $$ = (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        1084 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1421             : 
    1422        1084 :                     n->missing_ok = false;
    1423        1084 :                     n->roles = $3;
    1424        1084 :                     $$ = (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         404 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1437             : 
    1438         404 :                     n->missing_ok = false;
    1439         404 :                     n->roles = $3;
    1440         404 :                     $$ = (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         180 :             | 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         828 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1533             : 
    1534             :                     /* ...but not both */
    1535         828 :                     n->schemaname = $3;
    1536         828 :                     n->authrole = NULL;
    1537         828 :                     n->schemaElts = $4;
    1538         828 :                     n->if_not_exists = false;
    1539         828 :                     $$ = (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        1038 :                 { $$ = 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       19378 :                     VariableSetStmt *n = $2;
    1611             : 
    1612       19378 :                     n->is_local = false;
    1613       19378 :                     $$ = (Node *) n;
    1614             :                 }
    1615             :             | SET LOCAL set_rest
    1616             :                 {
    1617        1202 :                     VariableSetStmt *n = $3;
    1618             : 
    1619        1202 :                     n->is_local = true;
    1620        1202 :                     $$ = (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         520 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1635             : 
    1636         520 :                     n->kind = VAR_SET_MULTI;
    1637         520 :                     n->name = "TRANSACTION";
    1638         520 :                     n->args = $2;
    1639         520 :                     n->jumble_args = true;
    1640         520 :                     n->location = -1;
    1641         520 :                     $$ = 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        4760 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1661             : 
    1662        4760 :                     n->kind = VAR_SET_VALUE;
    1663        4760 :                     n->name = $1;
    1664        4760 :                     n->args = $3;
    1665        4760 :                     n->location = @3;
    1666        4760 :                     $$ = n;
    1667             :                 }
    1668             :             | var_name '=' var_list
    1669             :                 {
    1670       12980 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1671             : 
    1672       12980 :                     n->kind = VAR_SET_VALUE;
    1673       12980 :                     n->name = $1;
    1674       12980 :                     n->args = $3;
    1675       12980 :                     n->location = @3;
    1676       12980 :                     $$ = 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       17774 :             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         936 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1758             : 
    1759         936 :                     n->kind = VAR_SET_VALUE;
    1760         936 :                     n->name = "role";
    1761         936 :                     n->args = list_make1(makeStringConst($2, @2));
    1762         936 :                     n->location = @2;
    1763         936 :                     $$ = 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          44 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1799             : 
    1800          44 :                     n->kind = VAR_SET_MULTI;
    1801          44 :                     n->name = "TRANSACTION SNAPSHOT";
    1802          44 :                     n->args = list_make1(makeStringConst($3, @3));
    1803          44 :                     n->location = @3;
    1804          44 :                     $$ = n;
    1805             :                 }
    1806             :         ;
    1807             : 
    1808       22278 : var_name:   ColId                               { $$ = $1; }
    1809             :             | var_name '.' ColId
    1810         462 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1811             :         ;
    1812             : 
    1813       17740 : var_list:   var_value                               { $$ = list_make1($1); }
    1814         166 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1815             :         ;
    1816             : 
    1817             : var_value:  opt_boolean_or_string
    1818       13460 :                 { $$ = makeStringConst($1, @1); }
    1819             :             | NumericOnly
    1820        4446 :                 { $$ = makeAConst($1, @1); }
    1821             :         ;
    1822             : 
    1823           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1824         908 :             | READ COMMITTED                        { $$ = "read committed"; }
    1825        2488 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1826        3196 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1827             :         ;
    1828             : 
    1829             : opt_boolean_or_string:
    1830         580 :             TRUE_P                                  { $$ = "true"; }
    1831        1296 :             | FALSE_P                               { $$ = "false"; }
    1832        2086 :             | 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       28302 :             | 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       49530 :             NonReservedWord                         { $$ = $1; }
    1896        5160 :             | Sconst                                { $$ = $1; }
    1897             :         ;
    1898             : 
    1899             : VariableResetStmt:
    1900        4302 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1901             :         ;
    1902             : 
    1903             : reset_rest:
    1904        3522 :             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        3558 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1938             : 
    1939        3558 :                     n->kind = VAR_RESET;
    1940        3558 :                     n->name = $1;
    1941        3558 :                     n->location = -1;
    1942        3558 :                     $$ = 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        1176 :             SET set_rest                    { $$ = $2; }
    1957          44 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1958             :         ;
    1959             : 
    1960             : /* SetResetClause allows SET or RESET without LOCAL */
    1961             : FunctionSetResetClause:
    1962         134 :             SET set_rest_more               { $$ = $2; }
    1963          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1964             :         ;
    1965             : 
    1966             : 
    1967             : VariableShowStmt:
    1968             :             SHOW var_name
    1969             :                 {
    1970         830 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1971             : 
    1972         830 :                     n->name = $2;
    1973         830 :                     $$ = (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         204 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2035             : 
    2036         204 :                     $$ = (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       24274 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2099             : 
    2100       24274 :                     n->relation = $3;
    2101       24274 :                     n->cmds = $4;
    2102       24274 :                     n->objtype = OBJECT_TABLE;
    2103       24274 :                     n->missing_ok = false;
    2104       24274 :                     $$ = (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        2938 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2119             : 
    2120        2938 :                     n->relation = $3;
    2121        2938 :                     n->cmds = list_make1($4);
    2122        2938 :                     n->objtype = OBJECT_TABLE;
    2123        2938 :                     n->missing_ok = false;
    2124        2938 :                     $$ = (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         226 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2163             : 
    2164         226 :                     n->relation = $3;
    2165         226 :                     n->cmds = $4;
    2166         226 :                     n->objtype = OBJECT_INDEX;
    2167         226 :                     n->missing_ok = false;
    2168         226 :                     $$ = (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         398 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2183             : 
    2184         398 :                     n->relation = $3;
    2185         398 :                     n->cmds = list_make1($4);
    2186         398 :                     n->objtype = OBJECT_INDEX;
    2187         398 :                     n->missing_ok = false;
    2188         398 :                     $$ = (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          86 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2217             : 
    2218          86 :                     n->relation = $3;
    2219          86 :                     n->cmds = $4;
    2220          86 :                     n->objtype = OBJECT_SEQUENCE;
    2221          86 :                     n->missing_ok = false;
    2222          86 :                     $$ = (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         248 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2237             : 
    2238         248 :                     n->relation = $3;
    2239         248 :                     n->cmds = $4;
    2240         248 :                     n->objtype = OBJECT_VIEW;
    2241         248 :                     n->missing_ok = false;
    2242         248 :                     $$ = (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          48 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2257             : 
    2258          48 :                     n->relation = $4;
    2259          48 :                     n->cmds = $5;
    2260          48 :                     n->objtype = OBJECT_MATVIEW;
    2261          48 :                     n->missing_ok = false;
    2262          48 :                     $$ = (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       25418 :             alter_table_cmd                         { $$ = list_make1($1); }
    2322         990 :             | 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        2336 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2330        2336 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2331             : 
    2332        2336 :                     n->subtype = AT_AttachPartition;
    2333        2336 :                     cmd->name = $3;
    2334        2336 :                     cmd->bound = $4;
    2335        2336 :                     cmd->concurrent = false;
    2336        2336 :                     n->def = (Node *) cmd;
    2337             : 
    2338        2336 :                     $$ = (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         398 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2373         398 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2374             : 
    2375         398 :                     n->subtype = AT_AttachPartition;
    2376         398 :                     cmd->name = $3;
    2377         398 :                     cmd->bound = NULL;
    2378         398 :                     cmd->concurrent = false;
    2379         398 :                     n->def = (Node *) cmd;
    2380             : 
    2381         398 :                     $$ = (Node *) n;
    2382             :                 }
    2383             :         ;
    2384             : 
    2385             : alter_table_cmd:
    2386             :             /* ALTER TABLE <name> ADD <coldef> */
    2387             :             ADD_P columnDef
    2388             :                 {
    2389         186 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2390             : 
    2391         186 :                     n->subtype = AT_AddColumn;
    2392         186 :                     n->def = $2;
    2393         186 :                     n->missing_ok = false;
    2394         186 :                     $$ = (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        1806 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2410             : 
    2411        1806 :                     n->subtype = AT_AddColumn;
    2412        1806 :                     n->def = $3;
    2413        1806 :                     n->missing_ok = false;
    2414        1806 :                     $$ = (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         550 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2430             : 
    2431         550 :                     n->subtype = AT_ColumnDefault;
    2432         550 :                     n->name = $3;
    2433         550 :                     n->def = $4;
    2434         550 :                     $$ = (Node *) n;
    2435             :                 }
    2436             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2437             :             | ALTER opt_column ColId DROP NOT NULL_P
    2438             :                 {
    2439         288 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2440             : 
    2441         288 :                     n->subtype = AT_DropNotNull;
    2442         288 :                     n->name = $3;
    2443         288 :                     $$ = (Node *) n;
    2444             :                 }
    2445             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2446             :             | ALTER opt_column ColId SET NOT NULL_P
    2447             :                 {
    2448         410 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2449             : 
    2450         410 :                     n->subtype = AT_SetNotNull;
    2451         410 :                     n->name = $3;
    2452         410 :                     $$ = (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         120 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2458             : 
    2459         120 :                     n->subtype = AT_SetExpression;
    2460         120 :                     n->name = $3;
    2461         120 :                     n->def = $8;
    2462         120 :                     $$ = (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         212 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2533             : 
    2534         212 :                     n->subtype = AT_SetStorage;
    2535         212 :                     n->name = $3;
    2536         212 :                     n->def = (Node *) makeString($5);
    2537         212 :                     $$ = (Node *) n;
    2538             :                 }
    2539             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2540             :             | ALTER opt_column ColId SET column_compression
    2541             :                 {
    2542          68 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2543             : 
    2544          68 :                     n->subtype = AT_SetCompression;
    2545          68 :                     n->name = $3;
    2546          68 :                     n->def = (Node *) makeString($5);
    2547          68 :                     $$ = (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         166 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2553         166 :                     Constraint *c = makeNode(Constraint);
    2554             : 
    2555         166 :                     c->contype = CONSTR_IDENTITY;
    2556         166 :                     c->generated_when = $6;
    2557         166 :                     c->options = $9;
    2558         166 :                     c->location = @5;
    2559             : 
    2560         166 :                     n->subtype = AT_AddIdentity;
    2561         166 :                     n->name = $3;
    2562         166 :                     n->def = (Node *) c;
    2563             : 
    2564         166 :                     $$ = (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        1568 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2611             : 
    2612        1568 :                     n->subtype = AT_DropColumn;
    2613        1568 :                     n->name = $3;
    2614        1568 :                     n->behavior = $4;
    2615        1568 :                     n->missing_ok = false;
    2616        1568 :                     $$ = (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         970 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2625         970 :                     ColumnDef *def = makeNode(ColumnDef);
    2626             : 
    2627         970 :                     n->subtype = AT_AlterColumnType;
    2628         970 :                     n->name = $3;
    2629         970 :                     n->def = (Node *) def;
    2630             :                     /* We only use these fields of the ColumnDef node */
    2631         970 :                     def->typeName = $6;
    2632         970 :                     def->collClause = (CollateClause *) $7;
    2633         970 :                     def->raw_default = $8;
    2634         970 :                     def->location = @3;
    2635         970 :                     $$ = (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       13196 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2651             : 
    2652       13196 :                     n->subtype = AT_AddConstraint;
    2653       13196 :                     n->def = $2;
    2654       13196 :                     $$ = (Node *) n;
    2655             :                 }
    2656             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2657             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2658             :                 {
    2659         144 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2660         144 :                     Constraint *c = makeNode(Constraint);
    2661             : 
    2662         144 :                     n->subtype = AT_AlterConstraint;
    2663         144 :                     n->def = (Node *) c;
    2664         144 :                     c->contype = CONSTR_FOREIGN; /* others not supported, yet */
    2665         144 :                     c->conname = $3;
    2666         144 :                     processCASbits($4, @4, "ALTER CONSTRAINT statement",
    2667             :                                     &c->deferrable,
    2668             :                                     &c->initdeferred,
    2669             :                                     NULL, NULL, NULL, yyscanner);
    2670         132 :                     $$ = (Node *) n;
    2671             :                 }
    2672             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2673             :             | VALIDATE CONSTRAINT name
    2674             :                 {
    2675         412 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2676             : 
    2677         412 :                     n->subtype = AT_ValidateConstraint;
    2678         412 :                     n->name = $3;
    2679         412 :                     $$ = (Node *) n;
    2680             :                 }
    2681             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2682             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2683             :                 {
    2684          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2685             : 
    2686          18 :                     n->subtype = AT_DropConstraint;
    2687          18 :                     n->name = $5;
    2688          18 :                     n->behavior = $6;
    2689          18 :                     n->missing_ok = true;
    2690          18 :                     $$ = (Node *) n;
    2691             :                 }
    2692             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2693             :             | DROP CONSTRAINT name opt_drop_behavior
    2694             :                 {
    2695         822 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2696             : 
    2697         822 :                     n->subtype = AT_DropConstraint;
    2698         822 :                     n->name = $3;
    2699         822 :                     n->behavior = $4;
    2700         822 :                     n->missing_ok = false;
    2701         822 :                     $$ = (Node *) n;
    2702             :                 }
    2703             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2704             :             | SET WITHOUT OIDS
    2705             :                 {
    2706           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2707             : 
    2708           6 :                     n->subtype = AT_DropOids;
    2709           6 :                     $$ = (Node *) n;
    2710             :                 }
    2711             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2712             :             | CLUSTER ON name
    2713             :                 {
    2714          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2715             : 
    2716          46 :                     n->subtype = AT_ClusterOn;
    2717          46 :                     n->name = $3;
    2718          46 :                     $$ = (Node *) n;
    2719             :                 }
    2720             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2721             :             | SET WITHOUT CLUSTER
    2722             :                 {
    2723          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2724             : 
    2725          18 :                     n->subtype = AT_DropCluster;
    2726          18 :                     n->name = NULL;
    2727          18 :                     $$ = (Node *) n;
    2728             :                 }
    2729             :             /* ALTER TABLE <name> SET LOGGED */
    2730             :             | SET LOGGED
    2731             :                 {
    2732          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2733             : 
    2734          50 :                     n->subtype = AT_SetLogged;
    2735          50 :                     $$ = (Node *) n;
    2736             :                 }
    2737             :             /* ALTER TABLE <name> SET UNLOGGED */
    2738             :             | SET UNLOGGED
    2739             :                 {
    2740          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2741             : 
    2742          62 :                     n->subtype = AT_SetUnLogged;
    2743          62 :                     $$ = (Node *) n;
    2744             :                 }
    2745             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2746             :             | ENABLE_P TRIGGER name
    2747             :                 {
    2748         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2749             : 
    2750         122 :                     n->subtype = AT_EnableTrig;
    2751         122 :                     n->name = $3;
    2752         122 :                     $$ = (Node *) n;
    2753             :                 }
    2754             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2755             :             | ENABLE_P ALWAYS TRIGGER name
    2756             :                 {
    2757          40 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2758             : 
    2759          40 :                     n->subtype = AT_EnableAlwaysTrig;
    2760          40 :                     n->name = $4;
    2761          40 :                     $$ = (Node *) n;
    2762             :                 }
    2763             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2764             :             | ENABLE_P REPLICA TRIGGER name
    2765             :                 {
    2766          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2767             : 
    2768          16 :                     n->subtype = AT_EnableReplicaTrig;
    2769          16 :                     n->name = $4;
    2770          16 :                     $$ = (Node *) n;
    2771             :                 }
    2772             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2773             :             | ENABLE_P TRIGGER ALL
    2774             :                 {
    2775           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2776             : 
    2777           0 :                     n->subtype = AT_EnableTrigAll;
    2778           0 :                     $$ = (Node *) n;
    2779             :                 }
    2780             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2781             :             | ENABLE_P TRIGGER USER
    2782             :                 {
    2783           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2784             : 
    2785           0 :                     n->subtype = AT_EnableTrigUser;
    2786           0 :                     $$ = (Node *) n;
    2787             :                 }
    2788             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2789             :             | DISABLE_P TRIGGER name
    2790             :                 {
    2791         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2792             : 
    2793         138 :                     n->subtype = AT_DisableTrig;
    2794         138 :                     n->name = $3;
    2795         138 :                     $$ = (Node *) n;
    2796             :                 }
    2797             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2798             :             | DISABLE_P TRIGGER ALL
    2799             :                 {
    2800          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2801             : 
    2802          12 :                     n->subtype = AT_DisableTrigAll;
    2803          12 :                     $$ = (Node *) n;
    2804             :                 }
    2805             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2806             :             | DISABLE_P TRIGGER USER
    2807             :                 {
    2808          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2809             : 
    2810          12 :                     n->subtype = AT_DisableTrigUser;
    2811          12 :                     $$ = (Node *) n;
    2812             :                 }
    2813             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2814             :             | ENABLE_P RULE name
    2815             :                 {
    2816           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2817             : 
    2818           8 :                     n->subtype = AT_EnableRule;
    2819           8 :                     n->name = $3;
    2820           8 :                     $$ = (Node *) n;
    2821             :                 }
    2822             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2823             :             | ENABLE_P ALWAYS RULE name
    2824             :                 {
    2825           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2826             : 
    2827           0 :                     n->subtype = AT_EnableAlwaysRule;
    2828           0 :                     n->name = $4;
    2829           0 :                     $$ = (Node *) n;
    2830             :                 }
    2831             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2832             :             | ENABLE_P REPLICA RULE name
    2833             :                 {
    2834           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2835             : 
    2836           6 :                     n->subtype = AT_EnableReplicaRule;
    2837           6 :                     n->name = $4;
    2838           6 :                     $$ = (Node *) n;
    2839             :                 }
    2840             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2841             :             | DISABLE_P RULE name
    2842             :                 {
    2843          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2844             : 
    2845          32 :                     n->subtype = AT_DisableRule;
    2846          32 :                     n->name = $3;
    2847          32 :                     $$ = (Node *) n;
    2848             :                 }
    2849             :             /* ALTER TABLE <name> INHERIT <parent> */
    2850             :             | INHERIT qualified_name
    2851             :                 {
    2852         386 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2853             : 
    2854         386 :                     n->subtype = AT_AddInherit;
    2855         386 :                     n->def = (Node *) $2;
    2856         386 :                     $$ = (Node *) n;
    2857             :                 }
    2858             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2859             :             | NO INHERIT qualified_name
    2860             :                 {
    2861          86 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2862             : 
    2863          86 :                     n->subtype = AT_DropInherit;
    2864          86 :                     n->def = (Node *) $3;
    2865          86 :                     $$ = (Node *) n;
    2866             :                 }
    2867             :             /* ALTER TABLE <name> OF <type_name> */
    2868             :             | OF any_name
    2869             :                 {
    2870          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2871          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2872             : 
    2873          66 :                     def->location = @2;
    2874          66 :                     n->subtype = AT_AddOf;
    2875          66 :                     n->def = (Node *) def;
    2876          66 :                     $$ = (Node *) n;
    2877             :                 }
    2878             :             /* ALTER TABLE <name> NOT OF */
    2879             :             | NOT OF
    2880             :                 {
    2881           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2882             : 
    2883           6 :                     n->subtype = AT_DropOf;
    2884           6 :                     $$ = (Node *) n;
    2885             :                 }
    2886             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2887             :             | OWNER TO RoleSpec
    2888             :                 {
    2889        1918 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2890             : 
    2891        1918 :                     n->subtype = AT_ChangeOwner;
    2892        1918 :                     n->newowner = $3;
    2893        1918 :                     $$ = (Node *) n;
    2894             :                 }
    2895             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2896             :             | SET ACCESS METHOD set_access_method_name
    2897             :                 {
    2898         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2899             : 
    2900         128 :                     n->subtype = AT_SetAccessMethod;
    2901         128 :                     n->name = $4;
    2902         128 :                     $$ = (Node *) n;
    2903             :                 }
    2904             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2905             :             | SET TABLESPACE name
    2906             :                 {
    2907         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2908             : 
    2909         104 :                     n->subtype = AT_SetTableSpace;
    2910         104 :                     n->name = $3;
    2911         104 :                     $$ = (Node *) n;
    2912             :                 }
    2913             :             /* ALTER TABLE <name> SET (...) */
    2914             :             | SET reloptions
    2915             :                 {
    2916         588 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2917             : 
    2918         588 :                     n->subtype = AT_SetRelOptions;
    2919         588 :                     n->def = (Node *) $2;
    2920         588 :                     $$ = (Node *) n;
    2921             :                 }
    2922             :             /* ALTER TABLE <name> RESET (...) */
    2923             :             | RESET reloptions
    2924             :                 {
    2925         164 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2926             : 
    2927         164 :                     n->subtype = AT_ResetRelOptions;
    2928         164 :                     n->def = (Node *) $2;
    2929         164 :                     $$ = (Node *) n;
    2930             :                 }
    2931             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2932             :             | REPLICA IDENTITY_P replica_identity
    2933             :                 {
    2934         490 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2935             : 
    2936         490 :                     n->subtype = AT_ReplicaIdentity;
    2937         490 :                     n->def = $3;
    2938         490 :                     $$ = (Node *) n;
    2939             :                 }
    2940             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2941             :             | ENABLE_P ROW LEVEL SECURITY
    2942             :                 {
    2943         290 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2944             : 
    2945         290 :                     n->subtype = AT_EnableRowSecurity;
    2946         290 :                     $$ = (Node *) n;
    2947             :                 }
    2948             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2949             :             | DISABLE_P ROW LEVEL SECURITY
    2950             :                 {
    2951          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2952             : 
    2953          10 :                     n->subtype = AT_DisableRowSecurity;
    2954          10 :                     $$ = (Node *) n;
    2955             :                 }
    2956             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2957             :             | FORCE ROW LEVEL SECURITY
    2958             :                 {
    2959          94 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2960             : 
    2961          94 :                     n->subtype = AT_ForceRowSecurity;
    2962          94 :                     $$ = (Node *) n;
    2963             :                 }
    2964             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    2965             :             | NO FORCE ROW LEVEL SECURITY
    2966             :                 {
    2967          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2968             : 
    2969          32 :                     n->subtype = AT_NoForceRowSecurity;
    2970          32 :                     $$ = (Node *) n;
    2971             :                 }
    2972             :             | alter_generic_options
    2973             :                 {
    2974          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2975             : 
    2976          64 :                     n->subtype = AT_GenericOptions;
    2977          64 :                     n->def = (Node *) $1;
    2978          64 :                     $$ = (Node *) n;
    2979             :                 }
    2980             :         ;
    2981             : 
    2982             : alter_column_default:
    2983         378 :             SET DEFAULT a_expr          { $$ = $3; }
    2984         186 :             | DROP DEFAULT              { $$ = NULL; }
    2985             :         ;
    2986             : 
    2987             : opt_collate_clause:
    2988             :             COLLATE any_name
    2989             :                 {
    2990          18 :                     CollateClause *n = makeNode(CollateClause);
    2991             : 
    2992          18 :                     n->arg = NULL;
    2993          18 :                     n->collname = $2;
    2994          18 :                     n->location = @1;
    2995          18 :                     $$ = (Node *) n;
    2996             :                 }
    2997        4622 :             | /* EMPTY */               { $$ = NULL; }
    2998             :         ;
    2999             : 
    3000             : alter_using:
    3001         174 :             USING a_expr                { $$ = $2; }
    3002         796 :             | /* EMPTY */               { $$ = NULL; }
    3003             :         ;
    3004             : 
    3005             : replica_identity:
    3006             :             NOTHING
    3007             :                 {
    3008          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3009             : 
    3010          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3011          48 :                     n->name = NULL;
    3012          48 :                     $$ = (Node *) n;
    3013             :                 }
    3014             :             | FULL
    3015             :                 {
    3016         166 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3017             : 
    3018         166 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3019         166 :                     n->name = NULL;
    3020         166 :                     $$ = (Node *) n;
    3021             :                 }
    3022             :             | DEFAULT
    3023             :                 {
    3024           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3025             : 
    3026           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3027           6 :                     n->name = NULL;
    3028           6 :                     $$ = (Node *) n;
    3029             :                 }
    3030             :             | USING INDEX name
    3031             :                 {
    3032         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3033             : 
    3034         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3035         270 :                     n->name = $3;
    3036         270 :                     $$ = (Node *) n;
    3037             :                 }
    3038             : ;
    3039             : 
    3040             : reloptions:
    3041        2566 :             '(' reloption_list ')'                  { $$ = $2; }
    3042             :         ;
    3043             : 
    3044         934 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3045       21428 :              |      /* EMPTY */                     { $$ = NIL; }
    3046             :         ;
    3047             : 
    3048             : reloption_list:
    3049        2566 :             reloption_elem                          { $$ = list_make1($1); }
    3050         220 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3051             :         ;
    3052             : 
    3053             : /* This should match def_elem and also allow qualified names */
    3054             : reloption_elem:
    3055             :             ColLabel '=' def_arg
    3056             :                 {
    3057        2170 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3058             :                 }
    3059             :             | ColLabel
    3060             :                 {
    3061         548 :                     $$ = makeDefElem($1, NULL, @1);
    3062             :                 }
    3063             :             | ColLabel '.' ColLabel '=' def_arg
    3064             :                 {
    3065          62 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3066          62 :                                              DEFELEM_UNSPEC, @1);
    3067             :                 }
    3068             :             | ColLabel '.' ColLabel
    3069             :                 {
    3070           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3071             :                 }
    3072             :         ;
    3073             : 
    3074             : alter_identity_column_option_list:
    3075             :             alter_identity_column_option
    3076          62 :                 { $$ = list_make1($1); }
    3077             :             | alter_identity_column_option_list alter_identity_column_option
    3078          60 :                 { $$ = lappend($1, $2); }
    3079             :         ;
    3080             : 
    3081             : alter_identity_column_option:
    3082             :             RESTART
    3083             :                 {
    3084          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3085             :                 }
    3086             :             | RESTART opt_with NumericOnly
    3087             :                 {
    3088           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3089             :                 }
    3090             :             | SET SeqOptElem
    3091             :                 {
    3092          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3093          54 :                         strcmp($2->defname, "restart") == 0 ||
    3094          54 :                         strcmp($2->defname, "owned_by") == 0)
    3095           0 :                         ereport(ERROR,
    3096             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3097             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3098             :                                  parser_errposition(@2)));
    3099          54 :                     $$ = $2;
    3100             :                 }
    3101             :             | SET GENERATED generated_when
    3102             :                 {
    3103          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3104             :                 }
    3105             :         ;
    3106             : 
    3107             : set_statistics_value:
    3108         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3109           0 :             | DEFAULT                       { $$ = NULL; }
    3110             :         ;
    3111             : 
    3112             : set_access_method_name:
    3113          92 :             ColId                           { $$ = $1; }
    3114          36 :             | DEFAULT                       { $$ = NULL; }
    3115             :         ;
    3116             : 
    3117             : PartitionBoundSpec:
    3118             :             /* a HASH partition */
    3119             :             FOR VALUES WITH '(' hash_partbound ')'
    3120             :                 {
    3121             :                     ListCell   *lc;
    3122         704 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3123             : 
    3124         704 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3125         704 :                     n->modulus = n->remainder = -1;
    3126             : 
    3127        2112 :                     foreach (lc, $5)
    3128             :                     {
    3129        1408 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3130             : 
    3131        1408 :                         if (strcmp(opt->defname, "modulus") == 0)
    3132             :                         {
    3133         704 :                             if (n->modulus != -1)
    3134           0 :                                 ereport(ERROR,
    3135             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3136             :                                          errmsg("modulus for hash partition provided more than once"),
    3137             :                                          parser_errposition(opt->location)));
    3138         704 :                             n->modulus = defGetInt32(opt);
    3139             :                         }
    3140         704 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3141             :                         {
    3142         704 :                             if (n->remainder != -1)
    3143           0 :                                 ereport(ERROR,
    3144             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3145             :                                          errmsg("remainder for hash partition provided more than once"),
    3146             :                                          parser_errposition(opt->location)));
    3147         704 :                             n->remainder = defGetInt32(opt);
    3148             :                         }
    3149             :                         else
    3150           0 :                             ereport(ERROR,
    3151             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3152             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3153             :                                             opt->defname),
    3154             :                                      parser_errposition(opt->location)));
    3155             :                     }
    3156             : 
    3157         704 :                     if (n->modulus == -1)
    3158           0 :                         ereport(ERROR,
    3159             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3160             :                                  errmsg("modulus for hash partition must be specified"),
    3161             :                                  parser_errposition(@3)));
    3162         704 :                     if (n->remainder == -1)
    3163           0 :                         ereport(ERROR,
    3164             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3165             :                                  errmsg("remainder for hash partition must be specified"),
    3166             :                                  parser_errposition(@3)));
    3167             : 
    3168         704 :                     n->location = @3;
    3169             : 
    3170         704 :                     $$ = n;
    3171             :                 }
    3172             : 
    3173             :             /* a LIST partition */
    3174             :             | FOR VALUES IN_P '(' expr_list ')'
    3175             :                 {
    3176        4844 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3177             : 
    3178        4844 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3179        4844 :                     n->is_default = false;
    3180        4844 :                     n->listdatums = $5;
    3181        4844 :                     n->location = @3;
    3182             : 
    3183        4844 :                     $$ = n;
    3184             :                 }
    3185             : 
    3186             :             /* a RANGE partition */
    3187             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3188             :                 {
    3189        4084 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3190             : 
    3191        4084 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3192        4084 :                     n->is_default = false;
    3193        4084 :                     n->lowerdatums = $5;
    3194        4084 :                     n->upperdatums = $9;
    3195        4084 :                     n->location = @3;
    3196             : 
    3197        4084 :                     $$ = n;
    3198             :                 }
    3199             : 
    3200             :             /* a DEFAULT partition */
    3201             :             | DEFAULT
    3202             :                 {
    3203         590 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3204             : 
    3205         590 :                     n->is_default = true;
    3206         590 :                     n->location = @1;
    3207             : 
    3208         590 :                     $$ = n;
    3209             :                 }
    3210             :         ;
    3211             : 
    3212             : hash_partbound_elem:
    3213             :         NonReservedWord Iconst
    3214             :             {
    3215        1408 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3216             :             }
    3217             :         ;
    3218             : 
    3219             : hash_partbound:
    3220             :         hash_partbound_elem
    3221             :             {
    3222         704 :                 $$ = list_make1($1);
    3223             :             }
    3224             :         | hash_partbound ',' hash_partbound_elem
    3225             :             {
    3226         704 :                 $$ = lappend($1, $3);
    3227             :             }
    3228             :         ;
    3229             : 
    3230             : /*****************************************************************************
    3231             :  *
    3232             :  *  ALTER TYPE
    3233             :  *
    3234             :  * really variants of the ALTER TABLE subcommands with different spellings
    3235             :  *****************************************************************************/
    3236             : 
    3237             : AlterCompositeTypeStmt:
    3238             :             ALTER TYPE_P any_name alter_type_cmds
    3239             :                 {
    3240         208 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3241             : 
    3242             :                     /* can't use qualified_name, sigh */
    3243         208 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3244         208 :                     n->cmds = $4;
    3245         208 :                     n->objtype = OBJECT_TYPE;
    3246         208 :                     $$ = (Node *) n;
    3247             :                 }
    3248             :             ;
    3249             : 
    3250             : alter_type_cmds:
    3251         208 :             alter_type_cmd                          { $$ = list_make1($1); }
    3252          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3253             :         ;
    3254             : 
    3255             : alter_type_cmd:
    3256             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3257             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3258             :                 {
    3259          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3260             : 
    3261          64 :                     n->subtype = AT_AddColumn;
    3262          64 :                     n->def = $3;
    3263          64 :                     n->behavior = $4;
    3264          64 :                     $$ = (Node *) n;
    3265             :                 }
    3266             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3267             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3268             :                 {
    3269           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3270             : 
    3271           6 :                     n->subtype = AT_DropColumn;
    3272           6 :                     n->name = $5;
    3273           6 :                     n->behavior = $6;
    3274           6 :                     n->missing_ok = true;
    3275           6 :                     $$ = (Node *) n;
    3276             :                 }
    3277             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3278             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3279             :                 {
    3280          76 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3281             : 
    3282          76 :                     n->subtype = AT_DropColumn;
    3283          76 :                     n->name = $3;
    3284          76 :                     n->behavior = $4;
    3285          76 :                     n->missing_ok = false;
    3286          76 :                     $$ = (Node *) n;
    3287             :                 }
    3288             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3289             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3290             :                 {
    3291          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3292          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3293             : 
    3294          74 :                     n->subtype = AT_AlterColumnType;
    3295          74 :                     n->name = $3;
    3296          74 :                     n->def = (Node *) def;
    3297          74 :                     n->behavior = $8;
    3298             :                     /* We only use these fields of the ColumnDef node */
    3299          74 :                     def->typeName = $6;
    3300          74 :                     def->collClause = (CollateClause *) $7;
    3301          74 :                     def->raw_default = NULL;
    3302          74 :                     def->location = @3;
    3303          74 :                     $$ = (Node *) n;
    3304             :                 }
    3305             :         ;
    3306             : 
    3307             : 
    3308             : /*****************************************************************************
    3309             :  *
    3310             :  *      QUERY :
    3311             :  *              close <portalname>
    3312             :  *
    3313             :  *****************************************************************************/
    3314             : 
    3315             : ClosePortalStmt:
    3316             :             CLOSE cursor_name
    3317             :                 {
    3318        2182 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3319             : 
    3320        2182 :                     n->portalname = $2;
    3321        2182 :                     $$ = (Node *) n;
    3322             :                 }
    3323             :             | CLOSE ALL
    3324             :                 {
    3325          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3326             : 
    3327          12 :                     n->portalname = NULL;
    3328          12 :                     $$ = (Node *) n;
    3329             :                 }
    3330             :         ;
    3331             : 
    3332             : 
    3333             : /*****************************************************************************
    3334             :  *
    3335             :  *      QUERY :
    3336             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3337             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3338             :  *
    3339             :  *              where 'query' can be one of:
    3340             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3341             :  *
    3342             :  *              and 'file' can be one of:
    3343             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3344             :  *
    3345             :  *              In the preferred syntax the options are comma-separated
    3346             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3347             :  *              syntax had a hard-wired, space-separated set of options.
    3348             :  *
    3349             :  *              Really old syntax, from versions 7.2 and prior:
    3350             :  *              COPY [ BINARY ] table FROM/TO file
    3351             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3352             :  *                  [ WITH NULL AS 'null string' ]
    3353             :  *              This option placement is not supported with COPY (query...).
    3354             :  *
    3355             :  *****************************************************************************/
    3356             : 
    3357             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3358             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3359             :             copy_options where_clause
    3360             :                 {
    3361        9868 :                     CopyStmt *n = makeNode(CopyStmt);
    3362             : 
    3363        9868 :                     n->relation = $3;
    3364        9868 :                     n->query = NULL;
    3365        9868 :                     n->attlist = $4;
    3366        9868 :                     n->is_from = $5;
    3367        9868 :                     n->is_program = $6;
    3368        9868 :                     n->filename = $7;
    3369        9868 :                     n->whereClause = $11;
    3370             : 
    3371        9868 :                     if (n->is_program && n->filename == NULL)
    3372           0 :                         ereport(ERROR,
    3373             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3374             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3375             :                                  parser_errposition(@8)));
    3376             : 
    3377        9868 :                     if (!n->is_from && n->whereClause != NULL)
    3378           6 :                         ereport(ERROR,
    3379             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3380             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3381             :                                  parser_errposition(@11)));
    3382             : 
    3383        9862 :                     n->options = NIL;
    3384             :                     /* Concatenate user-supplied flags */
    3385        9862 :                     if ($2)
    3386          12 :                         n->options = lappend(n->options, $2);
    3387        9862 :                     if ($8)
    3388           0 :                         n->options = lappend(n->options, $8);
    3389        9862 :                     if ($10)
    3390         908 :                         n->options = list_concat(n->options, $10);
    3391        9862 :                     $$ = (Node *) n;
    3392             :                 }
    3393             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3394             :                 {
    3395         464 :                     CopyStmt *n = makeNode(CopyStmt);
    3396             : 
    3397         464 :                     updatePreparableStmtEnd($3, @4);
    3398         464 :                     n->relation = NULL;
    3399         464 :                     n->query = $3;
    3400         464 :                     n->attlist = NIL;
    3401         464 :                     n->is_from = false;
    3402         464 :                     n->is_program = $6;
    3403         464 :                     n->filename = $7;
    3404         464 :                     n->options = $9;
    3405             : 
    3406         464 :                     if (n->is_program && n->filename == NULL)
    3407           0 :                         ereport(ERROR,
    3408             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3409             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3410             :                                  parser_errposition(@5)));
    3411             : 
    3412         464 :                     $$ = (Node *) n;
    3413             :                 }
    3414             :         ;
    3415             : 
    3416             : copy_from:
    3417        1690 :             FROM                                    { $$ = true; }
    3418        8178 :             | TO                                    { $$ = false; }
    3419             :         ;
    3420             : 
    3421             : opt_program:
    3422           0 :             PROGRAM                                 { $$ = true; }
    3423       10332 :             | /* EMPTY */                           { $$ = false; }
    3424             :         ;
    3425             : 
    3426             : /*
    3427             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3428             :  * used depends on the direction. (It really doesn't make sense to copy from
    3429             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3430             :  */
    3431             : copy_file_name:
    3432         442 :             Sconst                                  { $$ = $1; }
    3433        1312 :             | STDIN                                 { $$ = NULL; }
    3434        8578 :             | STDOUT                                { $$ = NULL; }
    3435             :         ;
    3436             : 
    3437        9694 : copy_options: copy_opt_list                         { $$ = $1; }
    3438         638 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3439             :         ;
    3440             : 
    3441             : /* old COPY option syntax */
    3442             : copy_opt_list:
    3443         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3444        9694 :             | /* EMPTY */                           { $$ = NIL; }
    3445             :         ;
    3446             : 
    3447             : copy_opt_item:
    3448             :             BINARY
    3449             :                 {
    3450           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3451             :                 }
    3452             :             | FREEZE
    3453             :                 {
    3454          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3455             :                 }
    3456             :             | DELIMITER opt_as Sconst
    3457             :                 {
    3458         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3459             :                 }
    3460             :             | NULL_P opt_as Sconst
    3461             :                 {
    3462          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3463             :                 }
    3464             :             | CSV
    3465             :                 {
    3466         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3467             :                 }
    3468             :             | HEADER_P
    3469             :                 {
    3470          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3471             :                 }
    3472             :             | QUOTE opt_as Sconst
    3473             :                 {
    3474          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3475             :                 }
    3476             :             | ESCAPE opt_as Sconst
    3477             :                 {
    3478          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3479             :                 }
    3480             :             | FORCE QUOTE columnList
    3481             :                 {
    3482          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3483             :                 }
    3484             :             | FORCE QUOTE '*'
    3485             :                 {
    3486           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3487             :                 }
    3488             :             | FORCE NOT NULL_P columnList
    3489             :                 {
    3490           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3491             :                 }
    3492             :             | FORCE NOT NULL_P '*'
    3493             :                 {
    3494           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3495             :                 }
    3496             :             | FORCE NULL_P columnList
    3497             :                 {
    3498           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3499             :                 }
    3500             :             | FORCE NULL_P '*'
    3501             :                 {
    3502           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3503             :                 }
    3504             :             | ENCODING Sconst
    3505             :                 {
    3506          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3507             :                 }
    3508             :         ;
    3509             : 
    3510             : /* The following exist for backward compatibility with very old versions */
    3511             : 
    3512             : opt_binary:
    3513             :             BINARY
    3514             :                 {
    3515          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3516             :                 }
    3517        9856 :             | /*EMPTY*/                             { $$ = NULL; }
    3518             :         ;
    3519             : 
    3520             : copy_delimiter:
    3521             :             opt_using DELIMITERS Sconst
    3522             :                 {
    3523           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3524             :                 }
    3525        9868 :             | /*EMPTY*/                             { $$ = NULL; }
    3526             :         ;
    3527             : 
    3528             : opt_using:
    3529             :             USING
    3530             :             | /*EMPTY*/
    3531             :         ;
    3532             : 
    3533             : /* new COPY option syntax */
    3534             : copy_generic_opt_list:
    3535             :             copy_generic_opt_elem
    3536             :                 {
    3537         638 :                     $$ = list_make1($1);
    3538             :                 }
    3539             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3540             :                 {
    3541         450 :                     $$ = lappend($1, $3);
    3542             :                 }
    3543             :         ;
    3544             : 
    3545             : copy_generic_opt_elem:
    3546             :             ColLabel copy_generic_opt_arg
    3547             :                 {
    3548        1088 :                     $$ = makeDefElem($1, $2, @1);
    3549             :                 }
    3550             :         ;
    3551             : 
    3552             : copy_generic_opt_arg:
    3553         794 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3554          24 :             | NumericOnly                   { $$ = (Node *) $1; }
    3555          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3556           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3557         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3558          24 :             | /* EMPTY */                   { $$ = NULL; }
    3559             :         ;
    3560             : 
    3561             : copy_generic_opt_arg_list:
    3562             :               copy_generic_opt_arg_list_item
    3563             :                 {
    3564         150 :                     $$ = list_make1($1);
    3565             :                 }
    3566             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3567             :                 {
    3568          12 :                     $$ = lappend($1, $3);
    3569             :                 }
    3570             :         ;
    3571             : 
    3572             : /* beware of emitting non-string list elements here; see commands/define.c */
    3573             : copy_generic_opt_arg_list_item:
    3574         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3575             :         ;
    3576             : 
    3577             : 
    3578             : /*****************************************************************************
    3579             :  *
    3580             :  *      QUERY :
    3581             :  *              CREATE TABLE relname
    3582             :  *
    3583             :  *****************************************************************************/
    3584             : 
    3585             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3586             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3587             :             OnCommitOption OptTableSpace
    3588             :                 {
    3589       28552 :                     CreateStmt *n = makeNode(CreateStmt);
    3590             : 
    3591       28552 :                     $4->relpersistence = $2;
    3592       28552 :                     n->relation = $4;
    3593       28552 :                     n->tableElts = $6;
    3594       28552 :                     n->inhRelations = $8;
    3595       28552 :                     n->partspec = $9;
    3596       28552 :                     n->ofTypename = NULL;
    3597       28552 :                     n->constraints = NIL;
    3598       28552 :                     n->accessMethod = $10;
    3599       28552 :                     n->options = $11;
    3600       28552 :                     n->oncommit = $12;
    3601       28552 :                     n->tablespacename = $13;
    3602       28552 :                     n->if_not_exists = false;
    3603       28552 :                     $$ = (Node *) n;
    3604             :                 }
    3605             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3606             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3607             :             OptWith OnCommitOption OptTableSpace
    3608             :                 {
    3609          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3610             : 
    3611          30 :                     $7->relpersistence = $2;
    3612          30 :                     n->relation = $7;
    3613          30 :                     n->tableElts = $9;
    3614          30 :                     n->inhRelations = $11;
    3615          30 :                     n->partspec = $12;
    3616          30 :                     n->ofTypename = NULL;
    3617          30 :                     n->constraints = NIL;
    3618          30 :                     n->accessMethod = $13;
    3619          30 :                     n->options = $14;
    3620          30 :                     n->oncommit = $15;
    3621          30 :                     n->tablespacename = $16;
    3622          30 :                     n->if_not_exists = true;
    3623          30 :                     $$ = (Node *) n;
    3624             :                 }
    3625             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3626             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3627             :             OptWith OnCommitOption OptTableSpace
    3628             :                 {
    3629         122 :                     CreateStmt *n = makeNode(CreateStmt);
    3630             : 
    3631         122 :                     $4->relpersistence = $2;
    3632         122 :                     n->relation = $4;
    3633         122 :                     n->tableElts = $7;
    3634         122 :                     n->inhRelations = NIL;
    3635         122 :                     n->partspec = $8;
    3636         122 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3637         122 :                     n->ofTypename->location = @6;
    3638         122 :                     n->constraints = NIL;
    3639         122 :                     n->accessMethod = $9;
    3640         122 :                     n->options = $10;
    3641         122 :                     n->oncommit = $11;
    3642         122 :                     n->tablespacename = $12;
    3643         122 :                     n->if_not_exists = false;
    3644         122 :                     $$ = (Node *) n;
    3645             :                 }
    3646             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3647             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3648             :             OptWith OnCommitOption OptTableSpace
    3649             :                 {
    3650           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3651             : 
    3652           6 :                     $7->relpersistence = $2;
    3653           6 :                     n->relation = $7;
    3654           6 :                     n->tableElts = $10;
    3655           6 :                     n->inhRelations = NIL;
    3656           6 :                     n->partspec = $11;
    3657           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3658           6 :                     n->ofTypename->location = @9;
    3659           6 :                     n->constraints = NIL;
    3660           6 :                     n->accessMethod = $12;
    3661           6 :                     n->options = $13;
    3662           6 :                     n->oncommit = $14;
    3663           6 :                     n->tablespacename = $15;
    3664           6 :                     n->if_not_exists = true;
    3665           6 :                     $$ = (Node *) n;
    3666             :                 }
    3667             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3668             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3669             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3670             :                 {
    3671        7796 :                     CreateStmt *n = makeNode(CreateStmt);
    3672             : 
    3673        7796 :                     $4->relpersistence = $2;
    3674        7796 :                     n->relation = $4;
    3675        7796 :                     n->tableElts = $8;
    3676        7796 :                     n->inhRelations = list_make1($7);
    3677        7796 :                     n->partbound = $9;
    3678        7796 :                     n->partspec = $10;
    3679        7796 :                     n->ofTypename = NULL;
    3680        7796 :                     n->constraints = NIL;
    3681        7796 :                     n->accessMethod = $11;
    3682        7796 :                     n->options = $12;
    3683        7796 :                     n->oncommit = $13;
    3684        7796 :                     n->tablespacename = $14;
    3685        7796 :                     n->if_not_exists = false;
    3686        7796 :                     $$ = (Node *) n;
    3687             :                 }
    3688             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3689             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3690             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3691             :                 {
    3692           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3693             : 
    3694           0 :                     $7->relpersistence = $2;
    3695           0 :                     n->relation = $7;
    3696           0 :                     n->tableElts = $11;
    3697           0 :                     n->inhRelations = list_make1($10);
    3698           0 :                     n->partbound = $12;
    3699           0 :                     n->partspec = $13;
    3700           0 :                     n->ofTypename = NULL;
    3701           0 :                     n->constraints = NIL;
    3702           0 :                     n->accessMethod = $14;
    3703           0 :                     n->options = $15;
    3704           0 :                     n->oncommit = $16;
    3705           0 :                     n->tablespacename = $17;
    3706           0 :                     n->if_not_exists = true;
    3707           0 :                     $$ = (Node *) n;
    3708             :                 }
    3709             :         ;
    3710             : 
    3711             : /*
    3712             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3713             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3714             :  *
    3715             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3716             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3717             :  * temp table behavior, so warn about that.  Since we have no modules the
    3718             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3719             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3720             :  * so we'll probably continue to treat LOCAL as a noise word.
    3721             :  */
    3722         306 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3723        2672 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3724           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3725           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3726             :             | GLOBAL TEMPORARY
    3727             :                 {
    3728           0 :                     ereport(WARNING,
    3729             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3730             :                              parser_errposition(@1)));
    3731           0 :                     $$ = RELPERSISTENCE_TEMP;
    3732             :                 }
    3733             :             | GLOBAL TEMP
    3734             :                 {
    3735           0 :                     ereport(WARNING,
    3736             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3737             :                              parser_errposition(@1)));
    3738           0 :                     $$ = RELPERSISTENCE_TEMP;
    3739             :                 }
    3740         152 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3741       50638 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3742             :         ;
    3743             : 
    3744             : OptTableElementList:
    3745       27488 :             TableElementList                    { $$ = $1; }
    3746        1514 :             | /*EMPTY*/                         { $$ = NIL; }
    3747             :         ;
    3748             : 
    3749             : OptTypedTableElementList:
    3750         348 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3751        7672 :             | /*EMPTY*/                         { $$ = NIL; }
    3752             :         ;
    3753             : 
    3754             : TableElementList:
    3755             :             TableElement
    3756             :                 {
    3757       27542 :                     $$ = list_make1($1);
    3758             :                 }
    3759             :             | TableElementList ',' TableElement
    3760             :                 {
    3761       39456 :                     $$ = lappend($1, $3);
    3762             :                 }
    3763             :         ;
    3764             : 
    3765             : TypedTableElementList:
    3766             :             TypedTableElement
    3767             :                 {
    3768         348 :                     $$ = list_make1($1);
    3769             :                 }
    3770             :             | TypedTableElementList ',' TypedTableElement
    3771             :                 {
    3772          68 :                     $$ = lappend($1, $3);
    3773             :                 }
    3774             :         ;
    3775             : 
    3776             : TableElement:
    3777       63612 :             columnDef                           { $$ = $1; }
    3778         756 :             | TableLikeClause                   { $$ = $1; }
    3779        2630 :             | TableConstraint                   { $$ = $1; }
    3780             :         ;
    3781             : 
    3782             : TypedTableElement:
    3783         346 :             columnOptions                       { $$ = $1; }
    3784          70 :             | TableConstraint                   { $$ = $1; }
    3785             :         ;
    3786             : 
    3787             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3788             :                 {
    3789       65664 :                     ColumnDef *n = makeNode(ColumnDef);
    3790             : 
    3791       65664 :                     n->colname = $1;
    3792       65664 :                     n->typeName = $2;
    3793       65664 :                     n->storage_name = $3;
    3794       65664 :                     n->compression = $4;
    3795       65664 :                     n->inhcount = 0;
    3796       65664 :                     n->is_local = true;
    3797       65664 :                     n->is_not_null = false;
    3798       65664 :                     n->is_from_type = false;
    3799       65664 :                     n->storage = 0;
    3800       65664 :                     n->raw_default = NULL;
    3801       65664 :                     n->cooked_default = NULL;
    3802       65664 :                     n->collOid = InvalidOid;
    3803       65664 :                     n->fdwoptions = $5;
    3804       65664 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3805             :                                      yyscanner);
    3806       65664 :                     n->location = @1;
    3807       65664 :                     $$ = (Node *) n;
    3808             :                 }
    3809             :         ;
    3810             : 
    3811             : columnOptions:  ColId ColQualList
    3812             :                 {
    3813         138 :                     ColumnDef *n = makeNode(ColumnDef);
    3814             : 
    3815         138 :                     n->colname = $1;
    3816         138 :                     n->typeName = NULL;
    3817         138 :                     n->inhcount = 0;
    3818         138 :                     n->is_local = true;
    3819         138 :                     n->is_not_null = false;
    3820         138 :                     n->is_from_type = false;
    3821         138 :                     n->storage = 0;
    3822         138 :                     n->raw_default = NULL;
    3823         138 :                     n->cooked_default = NULL;
    3824         138 :                     n->collOid = InvalidOid;
    3825         138 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3826             :                                      yyscanner);
    3827         138 :                     n->location = @1;
    3828         138 :                     $$ = (Node *) n;
    3829             :                 }
    3830             :                 | ColId WITH OPTIONS ColQualList
    3831             :                 {
    3832         208 :                     ColumnDef *n = makeNode(ColumnDef);
    3833             : 
    3834         208 :                     n->colname = $1;
    3835         208 :                     n->typeName = NULL;
    3836         208 :                     n->inhcount = 0;
    3837         208 :                     n->is_local = true;
    3838         208 :                     n->is_not_null = false;
    3839         208 :                     n->is_from_type = false;
    3840         208 :                     n->storage = 0;
    3841         208 :                     n->raw_default = NULL;
    3842         208 :                     n->cooked_default = NULL;
    3843         208 :                     n->collOid = InvalidOid;
    3844         208 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3845             :                                      yyscanner);
    3846         208 :                     n->location = @1;
    3847         208 :                     $$ = (Node *) n;
    3848             :                 }
    3849             :         ;
    3850             : 
    3851             : column_compression:
    3852         138 :             COMPRESSION ColId                       { $$ = $2; }
    3853           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3854             :         ;
    3855             : 
    3856             : opt_column_compression:
    3857          76 :             column_compression                      { $$ = $1; }
    3858       65654 :             | /*EMPTY*/                             { $$ = NULL; }
    3859             :         ;
    3860             : 
    3861             : column_storage:
    3862         226 :             STORAGE ColId                           { $$ = $2; }
    3863           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3864             :         ;
    3865             : 
    3866             : opt_column_storage:
    3867          20 :             column_storage                          { $$ = $1; }
    3868       65710 :             | /*EMPTY*/                             { $$ = NULL; }
    3869             :         ;
    3870             : 
    3871             : ColQualList:
    3872       19126 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3873       67424 :             | /*EMPTY*/                             { $$ = NIL; }
    3874             :         ;
    3875             : 
    3876             : ColConstraint:
    3877             :             CONSTRAINT name ColConstraintElem
    3878             :                 {
    3879         734 :                     Constraint *n = castNode(Constraint, $3);
    3880             : 
    3881         734 :                     n->conname = $2;
    3882         734 :                     n->location = @1;
    3883         734 :                     $$ = (Node *) n;
    3884             :                 }
    3885       17374 :             | ColConstraintElem                     { $$ = $1; }
    3886         276 :             | ConstraintAttr                        { $$ = $1; }
    3887             :             | COLLATE any_name
    3888             :                 {
    3889             :                     /*
    3890             :                      * Note: the CollateClause is momentarily included in
    3891             :                      * the list built by ColQualList, but we split it out
    3892             :                      * again in SplitColQualList.
    3893             :                      */
    3894         742 :                     CollateClause *n = makeNode(CollateClause);
    3895             : 
    3896         742 :                     n->arg = NULL;
    3897         742 :                     n->collname = $2;
    3898         742 :                     n->location = @1;
    3899         742 :                     $$ = (Node *) n;
    3900             :                 }
    3901             :         ;
    3902             : 
    3903             : /* DEFAULT NULL is already the default for Postgres.
    3904             :  * But define it here and carry it forward into the system
    3905             :  * to make it explicit.
    3906             :  * - thomas 1998-09-13
    3907             :  *
    3908             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3909             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3910             :  * that a column may have that value. WITH NULL leads to
    3911             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3912             :  * - thomas 1999-01-08
    3913             :  *
    3914             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3915             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3916             :  * or be part of a_expr NOT LIKE or similar constructs).
    3917             :  */
    3918             : ColConstraintElem:
    3919             :             NOT NULL_P opt_no_inherit
    3920             :                 {
    3921        6458 :                     Constraint *n = makeNode(Constraint);
    3922             : 
    3923        6458 :                     n->contype = CONSTR_NOTNULL;
    3924        6458 :                     n->location = @1;
    3925        6458 :                     n->is_no_inherit = $3;
    3926        6458 :                     n->is_enforced = true;
    3927        6458 :                     n->skip_validation = false;
    3928        6458 :                     n->initially_valid = true;
    3929        6458 :                     $$ = (Node *) n;
    3930             :                 }
    3931             :             | NULL_P
    3932             :                 {
    3933          30 :                     Constraint *n = makeNode(Constraint);
    3934             : 
    3935          30 :                     n->contype = CONSTR_NULL;
    3936          30 :                     n->location = @1;
    3937          30 :                     $$ = (Node *) n;
    3938             :                 }
    3939             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3940             :                 {
    3941         428 :                     Constraint *n = makeNode(Constraint);
    3942             : 
    3943         428 :                     n->contype = CONSTR_UNIQUE;
    3944         428 :                     n->location = @1;
    3945         428 :                     n->nulls_not_distinct = !$2;
    3946         428 :                     n->keys = NULL;
    3947         428 :                     n->options = $3;
    3948         428 :                     n->indexname = NULL;
    3949         428 :                     n->indexspace = $4;
    3950         428 :                     $$ = (Node *) n;
    3951             :                 }
    3952             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3953             :                 {
    3954        5728 :                     Constraint *n = makeNode(Constraint);
    3955             : 
    3956        5728 :                     n->contype = CONSTR_PRIMARY;
    3957        5728 :                     n->location = @1;
    3958        5728 :                     n->keys = NULL;
    3959        5728 :                     n->options = $3;
    3960        5728 :                     n->indexname = NULL;
    3961        5728 :                     n->indexspace = $4;
    3962        5728 :                     $$ = (Node *) n;
    3963             :                 }
    3964             :             | CHECK '(' a_expr ')' opt_no_inherit
    3965             :                 {
    3966        1014 :                     Constraint *n = makeNode(Constraint);
    3967             : 
    3968        1014 :                     n->contype = CONSTR_CHECK;
    3969        1014 :                     n->location = @1;
    3970        1014 :                     n->is_no_inherit = $5;
    3971        1014 :                     n->raw_expr = $3;
    3972        1014 :                     n->cooked_expr = NULL;
    3973        1014 :                     n->is_enforced = true;
    3974        1014 :                     n->skip_validation = false;
    3975        1014 :                     n->initially_valid = true;
    3976        1014 :                     $$ = (Node *) n;
    3977             :                 }
    3978             :             | DEFAULT b_expr
    3979             :                 {
    3980        1714 :                     Constraint *n = makeNode(Constraint);
    3981             : 
    3982        1714 :                     n->contype = CONSTR_DEFAULT;
    3983        1714 :                     n->location = @1;
    3984        1714 :                     n->raw_expr = $2;
    3985        1714 :                     n->cooked_expr = NULL;
    3986        1714 :                     $$ = (Node *) n;
    3987             :                 }
    3988             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    3989             :                 {
    3990         326 :                     Constraint *n = makeNode(Constraint);
    3991             : 
    3992         326 :                     n->contype = CONSTR_IDENTITY;
    3993         326 :                     n->generated_when = $2;
    3994         326 :                     n->options = $5;
    3995         326 :                     n->location = @1;
    3996         326 :                     $$ = (Node *) n;
    3997             :                 }
    3998             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    3999             :                 {
    4000        1606 :                     Constraint *n = makeNode(Constraint);
    4001             : 
    4002        1606 :                     n->contype = CONSTR_GENERATED;
    4003        1606 :                     n->generated_when = $2;
    4004        1606 :                     n->raw_expr = $5;
    4005        1606 :                     n->cooked_expr = NULL;
    4006        1606 :                     n->generated_kind = $7;
    4007        1606 :                     n->location = @1;
    4008             : 
    4009             :                     /*
    4010             :                      * Can't do this in the grammar because of shift/reduce
    4011             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4012             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4013             :                      * can also give a more useful error message and location.
    4014             :                      */
    4015        1606 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4016          12 :                         ereport(ERROR,
    4017             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4018             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4019             :                                  parser_errposition(@2)));
    4020             : 
    4021        1594 :                     $$ = (Node *) n;
    4022             :                 }
    4023             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4024             :                 {
    4025         816 :                     Constraint *n = makeNode(Constraint);
    4026             : 
    4027         816 :                     n->contype = CONSTR_FOREIGN;
    4028         816 :                     n->location = @1;
    4029         816 :                     n->pktable = $2;
    4030         816 :                     n->fk_attrs = NIL;
    4031         816 :                     n->pk_attrs = $3;
    4032         816 :                     n->fk_matchtype = $4;
    4033         816 :                     n->fk_upd_action = ($5)->updateAction->action;
    4034         816 :                     n->fk_del_action = ($5)->deleteAction->action;
    4035         816 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4036         816 :                     n->is_enforced = true;
    4037         816 :                     n->skip_validation = false;
    4038         816 :                     n->initially_valid = true;
    4039         816 :                     $$ = (Node *) n;
    4040             :                 }
    4041             :         ;
    4042             : 
    4043             : opt_unique_null_treatment:
    4044          12 :             NULLS_P DISTINCT        { $$ = true; }
    4045          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4046        7488 :             | /*EMPTY*/             { $$ = true; }
    4047             :         ;
    4048             : 
    4049             : generated_when:
    4050        1960 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4051         182 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4052             :         ;
    4053             : 
    4054             : opt_virtual_or_stored:
    4055         954 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4056         580 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4057          72 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4058             :         ;
    4059             : 
    4060             : /*
    4061             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4062             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4063             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4064             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4065             :  * attribute information to the preceding "real" constraint node, and for
    4066             :  * complaining if attribute clauses appear in the wrong place or wrong
    4067             :  * combinations.
    4068             :  *
    4069             :  * See also ConstraintAttributeSpec, which can be used in places where
    4070             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4071             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4072             :  * might need to allow them here too, but for the moment it doesn't seem
    4073             :  * useful in the statements that use ConstraintAttr.)
    4074             :  */
    4075             : ConstraintAttr:
    4076             :             DEFERRABLE
    4077             :                 {
    4078         102 :                     Constraint *n = makeNode(Constraint);
    4079             : 
    4080         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4081         102 :                     n->location = @1;
    4082         102 :                     $$ = (Node *) n;
    4083             :                 }
    4084             :             | NOT DEFERRABLE
    4085             :                 {
    4086           0 :                     Constraint *n = makeNode(Constraint);
    4087             : 
    4088           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4089           0 :                     n->location = @1;
    4090           0 :                     $$ = (Node *) n;
    4091             :                 }
    4092             :             | INITIALLY DEFERRED
    4093             :                 {
    4094          78 :                     Constraint *n = makeNode(Constraint);
    4095             : 
    4096          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4097          78 :                     n->location = @1;
    4098          78 :                     $$ = (Node *) n;
    4099             :                 }
    4100             :             | INITIALLY IMMEDIATE
    4101             :                 {
    4102           6 :                     Constraint *n = makeNode(Constraint);
    4103             : 
    4104           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4105           6 :                     n->location = @1;
    4106           6 :                     $$ = (Node *) n;
    4107             :                 }
    4108             :             | ENFORCED
    4109             :                 {
    4110          36 :                     Constraint *n = makeNode(Constraint);
    4111             : 
    4112          36 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4113          36 :                     n->location = @1;
    4114          36 :                     $$ = (Node *) n;
    4115             :                 }
    4116             :             | NOT ENFORCED
    4117             :                 {
    4118          54 :                     Constraint *n = makeNode(Constraint);
    4119             : 
    4120          54 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4121          54 :                     n->location = @1;
    4122          54 :                     $$ = (Node *) n;
    4123             :                 }
    4124             :         ;
    4125             : 
    4126             : 
    4127             : TableLikeClause:
    4128             :             LIKE qualified_name TableLikeOptionList
    4129             :                 {
    4130         756 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4131             : 
    4132         756 :                     n->relation = $2;
    4133         756 :                     n->options = $3;
    4134         756 :                     n->relationOid = InvalidOid;
    4135         756 :                     $$ = (Node *) n;
    4136             :                 }
    4137             :         ;
    4138             : 
    4139             : TableLikeOptionList:
    4140         276 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4141           2 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4142         756 :                 | /* EMPTY */                       { $$ = 0; }
    4143             :         ;
    4144             : 
    4145             : TableLikeOption:
    4146          24 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4147           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4148          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4149          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4150          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4151          30 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4152          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4153           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4154          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4155          56 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4156             :         ;
    4157             : 
    4158             : 
    4159             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4160             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4161             :  * - thomas 1997-12-03
    4162             :  */
    4163             : TableConstraint:
    4164             :             CONSTRAINT name ConstraintElem
    4165             :                 {
    4166        3852 :                     Constraint *n = castNode(Constraint, $3);
    4167             : 
    4168        3852 :                     n->conname = $2;
    4169        3852 :                     n->location = @1;
    4170        3852 :                     $$ = (Node *) n;
    4171             :                 }
    4172       12044 :             | ConstraintElem                        { $$ = $1; }
    4173             :         ;
    4174             : 
    4175             : ConstraintElem:
    4176             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4177             :                 {
    4178        1190 :                     Constraint *n = makeNode(Constraint);
    4179             : 
    4180        1190 :                     n->contype = CONSTR_CHECK;
    4181        1190 :                     n->location = @1;
    4182        1190 :                     n->raw_expr = $3;
    4183        1190 :                     n->cooked_expr = NULL;
    4184        1190 :                     processCASbits($5, @5, "CHECK",
    4185             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4186             :                                    &n->is_no_inherit, yyscanner);
    4187        1190 :                     n->initially_valid = !n->skip_validation;
    4188        1190 :                     $$ = (Node *) n;
    4189             :                 }
    4190             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4191             :                 {
    4192         398 :                     Constraint *n = makeNode(Constraint);
    4193             : 
    4194         398 :                     n->contype = CONSTR_NOTNULL;
    4195         398 :                     n->location = @1;
    4196         398 :                     n->keys = list_make1(makeString($3));
    4197             :                     /* no NOT VALID support yet */
    4198         398 :                     processCASbits($4, @4, "NOT NULL",
    4199             :                                    NULL, NULL, NULL, NULL,
    4200             :                                    &n->is_no_inherit, yyscanner);
    4201         398 :                     n->initially_valid = true;
    4202         398 :                     $$ = (Node *) n;
    4203             :                 }
    4204             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4205             :                 ConstraintAttributeSpec
    4206             :                 {
    4207         614 :                     Constraint *n = makeNode(Constraint);
    4208             : 
    4209         614 :                     n->contype = CONSTR_UNIQUE;
    4210         614 :                     n->location = @1;
    4211         614 :                     n->nulls_not_distinct = !$2;
    4212         614 :                     n->keys = $4;
    4213         614 :                     n->without_overlaps = $5;
    4214         614 :                     n->including = $7;
    4215         614 :                     n->options = $8;
    4216         614 :                     n->indexname = NULL;
    4217         614 :                     n->indexspace = $9;
    4218         614 :                     processCASbits($10, @10, "UNIQUE",
    4219             :                                    &n->deferrable, &n->initdeferred, NULL,
    4220             :                                    NULL, NULL, yyscanner);
    4221         614 :                     $$ = (Node *) n;
    4222             :                 }
    4223             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4224             :                 {
    4225        4168 :                     Constraint *n = makeNode(Constraint);
    4226             : 
    4227        4168 :                     n->contype = CONSTR_UNIQUE;
    4228        4168 :                     n->location = @1;
    4229        4168 :                     n->keys = NIL;
    4230        4168 :                     n->including = NIL;
    4231        4168 :                     n->options = NIL;
    4232        4168 :                     n->indexname = $2;
    4233        4168 :                     n->indexspace = NULL;
    4234        4168 :                     processCASbits($3, @3, "UNIQUE",
    4235             :                                    &n->deferrable, &n->initdeferred, NULL,
    4236             :                                    NULL, NULL, yyscanner);
    4237        4168 :                     $$ = (Node *) n;
    4238             :                 }
    4239             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4240             :                 ConstraintAttributeSpec
    4241             :                 {
    4242        2096 :                     Constraint *n = makeNode(Constraint);
    4243             : 
    4244        2096 :                     n->contype = CONSTR_PRIMARY;
    4245        2096 :                     n->location = @1;
    4246        2096 :                     n->keys = $4;
    4247        2096 :                     n->without_overlaps = $5;
    4248        2096 :                     n->including = $7;
    4249        2096 :                     n->options = $8;
    4250        2096 :                     n->indexname = NULL;
    4251        2096 :                     n->indexspace = $9;
    4252        2096 :                     processCASbits($10, @10, "PRIMARY KEY",
    4253             :                                    &n->deferrable, &n->initdeferred, NULL,
    4254             :                                    NULL, NULL, yyscanner);
    4255        2096 :                     $$ = (Node *) n;
    4256             :                 }
    4257             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4258             :                 {
    4259        5398 :                     Constraint *n = makeNode(Constraint);
    4260             : 
    4261        5398 :                     n->contype = CONSTR_PRIMARY;
    4262        5398 :                     n->location = @1;
    4263        5398 :                     n->keys = NIL;
    4264        5398 :                     n->including = NIL;
    4265        5398 :                     n->options = NIL;
    4266        5398 :                     n->indexname = $3;
    4267        5398 :                     n->indexspace = NULL;
    4268        5398 :                     processCASbits($4, @4, "PRIMARY KEY",
    4269             :                                    &n->deferrable, &n->initdeferred, NULL,
    4270             :                                    NULL, NULL, yyscanner);
    4271        5398 :                     $$ = (Node *) n;
    4272             :                 }
    4273             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4274             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4275             :                 ConstraintAttributeSpec
    4276             :                 {
    4277         234 :                     Constraint *n = makeNode(Constraint);
    4278             : 
    4279         234 :                     n->contype = CONSTR_EXCLUSION;
    4280         234 :                     n->location = @1;
    4281         234 :                     n->access_method = $2;
    4282         234 :                     n->exclusions = $4;
    4283         234 :                     n->including = $6;
    4284         234 :                     n->options = $7;
    4285         234 :                     n->indexname = NULL;
    4286         234 :                     n->indexspace = $8;
    4287         234 :                     n->where_clause = $9;
    4288         234 :                     processCASbits($10, @10, "EXCLUDE",
    4289             :                                    &n->deferrable, &n->initdeferred, NULL,
    4290             :                                    NULL, NULL, yyscanner);
    4291         234 :                     $$ = (Node *) n;
    4292             :                 }
    4293             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4294             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4295             :                 {
    4296        1798 :                     Constraint *n = makeNode(Constraint);
    4297             : 
    4298        1798 :                     n->contype = CONSTR_FOREIGN;
    4299        1798 :                     n->location = @1;
    4300        1798 :                     n->pktable = $8;
    4301        1798 :                     n->fk_attrs = $4;
    4302        1798 :                     if ($5)
    4303             :                     {
    4304         310 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4305         310 :                         n->fk_with_period = true;
    4306             :                     }
    4307        1798 :                     n->pk_attrs = linitial($9);
    4308        1798 :                     if (lsecond($9))
    4309             :                     {
    4310         178 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4311         178 :                         n->pk_with_period = true;
    4312             :                     }
    4313        1798 :                     n->fk_matchtype = $10;
    4314        1798 :                     n->fk_upd_action = ($11)->updateAction->action;
    4315        1798 :                     n->fk_del_action = ($11)->deleteAction->action;
    4316        1798 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4317        1798 :                     processCASbits($12, @12, "FOREIGN KEY",
    4318             :                                    &n->deferrable, &n->initdeferred,
    4319             :                                    NULL, &n->skip_validation, NULL,
    4320             :                                    yyscanner);
    4321        1798 :                     n->initially_valid = !n->skip_validation;
    4322        1798 :                     $$ = (Node *) n;
    4323             :                 }
    4324             :         ;
    4325             : 
    4326             : /*
    4327             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4328             :  * NOT NULL constraints is different.  For table constraints, we need to
    4329             :  * accept a column name, but for domain constraints, we don't.  (We could
    4330             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4331             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4332             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4333             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4334             :  * standard; we are just living with the bits of inconsistency that have built
    4335             :  * up over time.
    4336             :  */
    4337             : DomainConstraint:
    4338             :             CONSTRAINT name DomainConstraintElem
    4339             :                 {
    4340         156 :                     Constraint *n = castNode(Constraint, $3);
    4341             : 
    4342         156 :                     n->conname = $2;
    4343         156 :                     n->location = @1;
    4344         156 :                     $$ = (Node *) n;
    4345             :                 }
    4346          18 :             | DomainConstraintElem                  { $$ = $1; }
    4347             :         ;
    4348             : 
    4349             : DomainConstraintElem:
    4350             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4351             :                 {
    4352         156 :                     Constraint *n = makeNode(Constraint);
    4353             : 
    4354         156 :                     n->contype = CONSTR_CHECK;
    4355         156 :                     n->location = @1;
    4356         156 :                     n->raw_expr = $3;
    4357         156 :                     n->cooked_expr = NULL;
    4358         156 :                     processCASbits($5, @5, "CHECK",
    4359             :                                    NULL, NULL, NULL, &n->skip_validation,
    4360             :                                    &n->is_no_inherit, yyscanner);
    4361         144 :                     n->is_enforced = true;
    4362         144 :                     n->initially_valid = !n->skip_validation;
    4363         144 :                     $$ = (Node *) n;
    4364             :                 }
    4365             :             | NOT NULL_P ConstraintAttributeSpec
    4366             :                 {
    4367          30 :                     Constraint *n = makeNode(Constraint);
    4368             : 
    4369          30 :                     n->contype = CONSTR_NOTNULL;
    4370          30 :                     n->location = @1;
    4371          30 :                     n->keys = list_make1(makeString("value"));
    4372             :                     /* no NOT VALID, NO INHERIT support */
    4373          30 :                     processCASbits($3, @3, "NOT NULL",
    4374             :                                    NULL, NULL, NULL,
    4375             :                                    NULL, NULL, yyscanner);
    4376          30 :                     n->initially_valid = true;
    4377          30 :                     $$ = (Node *) n;
    4378             :                 }
    4379             :         ;
    4380             : 
    4381         114 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4382        7358 :             | /* EMPTY */                           {  $$ = false; }
    4383             :         ;
    4384             : 
    4385             : opt_without_overlaps:
    4386         554 :             WITHOUT OVERLAPS                        { $$ = true; }
    4387        2156 :             | /*EMPTY*/                             { $$ = false; }
    4388             :     ;
    4389             : 
    4390             : opt_column_list:
    4391        9464 :             '(' columnList ')'                      { $$ = $2; }
    4392       38498 :             | /*EMPTY*/                             { $$ = NIL; }
    4393             :         ;
    4394             : 
    4395             : columnList:
    4396       15674 :             columnElem                              { $$ = list_make1($1); }
    4397       27330 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4398             :         ;
    4399             : 
    4400             : optionalPeriodName:
    4401         488 :             ',' PERIOD columnElem { $$ = $3; }
    4402        2448 :             | /*EMPTY*/               { $$ = NULL; }
    4403             :     ;
    4404             : 
    4405             : opt_column_and_period_list:
    4406        1132 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4407         672 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4408             :         ;
    4409             : 
    4410             : columnElem: ColId
    4411             :                 {
    4412       43492 :                     $$ = (Node *) makeString($1);
    4413             :                 }
    4414             :         ;
    4415             : 
    4416         168 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4417        2776 :              |      /* EMPTY */                     { $$ = NIL; }
    4418             :         ;
    4419             : 
    4420             : key_match:  MATCH FULL
    4421             :             {
    4422          98 :                 $$ = FKCONSTR_MATCH_FULL;
    4423             :             }
    4424             :         | MATCH PARTIAL
    4425             :             {
    4426           0 :                 ereport(ERROR,
    4427             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4428             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4429             :                          parser_errposition(@1)));
    4430             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4431             :             }
    4432             :         | MATCH SIMPLE
    4433             :             {
    4434           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4435             :             }
    4436             :         | /*EMPTY*/
    4437             :             {
    4438        2516 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4439             :             }
    4440             :         ;
    4441             : 
    4442             : ExclusionConstraintList:
    4443         234 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4444             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4445         106 :                                                     { $$ = lappend($1, $3); }
    4446             :         ;
    4447             : 
    4448             : ExclusionConstraintElem: index_elem WITH any_operator
    4449             :             {
    4450         340 :                 $$ = list_make2($1, $3);
    4451             :             }
    4452             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4453             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4454             :             {
    4455           0 :                 $$ = list_make2($1, $5);
    4456             :             }
    4457             :         ;
    4458             : 
    4459             : OptWhereClause:
    4460         440 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4461        1220 :             | /*EMPTY*/                             { $$ = NULL; }
    4462             :         ;
    4463             : 
    4464             : key_actions:
    4465             :             key_update
    4466             :                 {
    4467          74 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4468             : 
    4469          74 :                     n->updateAction = $1;
    4470          74 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4471          74 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4472          74 :                     n->deleteAction->cols = NIL;
    4473          74 :                     $$ = n;
    4474             :                 }
    4475             :             | key_delete
    4476             :                 {
    4477         172 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4478             : 
    4479         172 :                     n->updateAction = palloc(sizeof(KeyAction));
    4480         172 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4481         172 :                     n->updateAction->cols = NIL;
    4482         172 :                     n->deleteAction = $1;
    4483         172 :                     $$ = n;
    4484             :                 }
    4485             :             | key_update key_delete
    4486             :                 {
    4487         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4488             : 
    4489         150 :                     n->updateAction = $1;
    4490         150 :                     n->deleteAction = $2;
    4491         150 :                     $$ = n;
    4492             :                 }
    4493             :             | key_delete key_update
    4494             :                 {
    4495         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4496             : 
    4497         150 :                     n->updateAction = $2;
    4498         150 :                     n->deleteAction = $1;
    4499         150 :                     $$ = n;
    4500             :                 }
    4501             :             | /*EMPTY*/
    4502             :                 {
    4503        2068 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4504             : 
    4505        2068 :                     n->updateAction = palloc(sizeof(KeyAction));
    4506        2068 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4507        2068 :                     n->updateAction->cols = NIL;
    4508        2068 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4509        2068 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4510        2068 :                     n->deleteAction->cols = NIL;
    4511        2068 :                     $$ = n;
    4512             :                 }
    4513             :         ;
    4514             : 
    4515             : key_update: ON UPDATE key_action
    4516             :                 {
    4517         380 :                     if (($3)->cols)
    4518           6 :                         ereport(ERROR,
    4519             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4520             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4521             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4522             :                                  parser_errposition(@1)));
    4523         374 :                     $$ = $3;
    4524             :                 }
    4525             :         ;
    4526             : 
    4527             : key_delete: ON DELETE_P key_action
    4528             :                 {
    4529         472 :                     $$ = $3;
    4530             :                 }
    4531             :         ;
    4532             : 
    4533             : key_action:
    4534             :             NO ACTION
    4535             :                 {
    4536          80 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4537             : 
    4538          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4539          80 :                     n->cols = NIL;
    4540          80 :                     $$ = n;
    4541             :                 }
    4542             :             | RESTRICT
    4543             :                 {
    4544          70 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4545             : 
    4546          70 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4547          70 :                     n->cols = NIL;
    4548          70 :                     $$ = n;
    4549             :                 }
    4550             :             | CASCADE
    4551             :                 {
    4552         410 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4553             : 
    4554         410 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4555         410 :                     n->cols = NIL;
    4556         410 :                     $$ = n;
    4557             :                 }
    4558             :             | SET NULL_P opt_column_list
    4559             :                 {
    4560         190 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4561             : 
    4562         190 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4563         190 :                     n->cols = $3;
    4564         190 :                     $$ = n;
    4565             :                 }
    4566             :             | SET DEFAULT opt_column_list
    4567             :                 {
    4568         102 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4569             : 
    4570         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4571         102 :                     n->cols = $3;
    4572         102 :                     $$ = n;
    4573             :                 }
    4574             :         ;
    4575             : 
    4576        1974 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4577       27010 :             | /*EMPTY*/                             { $$ = NIL; }
    4578             :         ;
    4579             : 
    4580             : /* Optional partition key specification */
    4581        4900 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4582       31618 :             | /*EMPTY*/         { $$ = NULL; }
    4583             :         ;
    4584             : 
    4585             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4586             :                 {
    4587        4906 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4588             : 
    4589        4906 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4590        4900 :                     n->partParams = $5;
    4591        4900 :                     n->location = @1;
    4592             : 
    4593        4900 :                     $$ = n;
    4594             :                 }
    4595             :         ;
    4596             : 
    4597        4906 : part_params:    part_elem                       { $$ = list_make1($1); }
    4598         456 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4599             :         ;
    4600             : 
    4601             : part_elem: ColId opt_collate opt_qualified_name
    4602             :                 {
    4603        5058 :                     PartitionElem *n = makeNode(PartitionElem);
    4604             : 
    4605        5058 :                     n->name = $1;
    4606        5058 :                     n->expr = NULL;
    4607        5058 :                     n->collation = $2;
    4608        5058 :                     n->opclass = $3;
    4609        5058 :                     n->location = @1;
    4610        5058 :                     $$ = n;
    4611             :                 }
    4612             :             | func_expr_windowless opt_collate opt_qualified_name
    4613             :                 {
    4614         130 :                     PartitionElem *n = makeNode(PartitionElem);
    4615             : 
    4616         130 :                     n->name = NULL;
    4617         130 :                     n->expr = $1;
    4618         130 :                     n->collation = $2;
    4619         130 :                     n->opclass = $3;
    4620         130 :                     n->location = @1;
    4621         130 :                     $$ = n;
    4622             :                 }
    4623             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4624             :                 {
    4625         174 :                     PartitionElem *n = makeNode(PartitionElem);
    4626             : 
    4627         174 :                     n->name = NULL;
    4628         174 :                     n->expr = $2;
    4629         174 :                     n->collation = $4;
    4630         174 :                     n->opclass = $5;
    4631         174 :                     n->location = @1;
    4632         174 :                     $$ = n;
    4633             :                 }
    4634             :         ;
    4635             : 
    4636             : table_access_method_clause:
    4637         122 :             USING name                          { $$ = $2; }
    4638       38252 :             | /*EMPTY*/                         { $$ = NULL; }
    4639             :         ;
    4640             : 
    4641             : /* WITHOUT OIDS is legacy only */
    4642             : OptWith:
    4643         670 :             WITH reloptions             { $$ = $2; }
    4644          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4645       37100 :             | /*EMPTY*/                 { $$ = NIL; }
    4646             :         ;
    4647             : 
    4648          56 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4649          98 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4650          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4651       37616 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4652             :         ;
    4653             : 
    4654         206 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4655       44656 :             | /*EMPTY*/                             { $$ = NULL; }
    4656             :         ;
    4657             : 
    4658          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4659        9034 :             | /*EMPTY*/                             { $$ = NULL; }
    4660             :         ;
    4661             : 
    4662        9566 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4663             :         ;
    4664             : 
    4665             : /*****************************************************************************
    4666             :  *
    4667             :  *      QUERY :
    4668             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4669             :  *                  ON expression-list FROM from_list
    4670             :  *
    4671             :  * Note: the expectation here is that the clauses after ON are a subset of
    4672             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4673             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4674             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4675             :  * errors as necessary at execution.
    4676             :  *
    4677             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4678             :  *
    4679             :  *****************************************************************************/
    4680             : 
    4681             : CreateStatsStmt:
    4682             :             CREATE STATISTICS opt_qualified_name
    4683             :             opt_name_list ON stats_params FROM from_list
    4684             :                 {
    4685         638 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4686             : 
    4687         638 :                     n->defnames = $3;
    4688         638 :                     n->stat_types = $4;
    4689         638 :                     n->exprs = $6;
    4690         638 :                     n->relations = $8;
    4691         638 :                     n->stxcomment = NULL;
    4692         638 :                     n->if_not_exists = false;
    4693         638 :                     $$ = (Node *) n;
    4694             :                 }
    4695             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4696             :             opt_name_list ON stats_params FROM from_list
    4697             :                 {
    4698          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4699             : 
    4700          12 :                     n->defnames = $6;
    4701          12 :                     n->stat_types = $7;
    4702          12 :                     n->exprs = $9;
    4703          12 :                     n->relations = $11;
    4704          12 :                     n->stxcomment = NULL;
    4705          12 :                     n->if_not_exists = true;
    4706          12 :                     $$ = (Node *) n;
    4707             :                 }
    4708             :             ;
    4709             : 
    4710             : /*
    4711             :  * Statistics attributes can be either simple column references, or arbitrary
    4712             :  * expressions in parens.  For compatibility with index attributes permitted
    4713             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4714             :  * written without parens.
    4715             :  */
    4716             : 
    4717         662 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4718         952 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4719             :         ;
    4720             : 
    4721             : stats_param:    ColId
    4722             :                 {
    4723        1140 :                     $$ = makeNode(StatsElem);
    4724        1140 :                     $$->name = $1;
    4725        1140 :                     $$->expr = NULL;
    4726             :                 }
    4727             :             | func_expr_windowless
    4728             :                 {
    4729          32 :                     $$ = makeNode(StatsElem);
    4730          32 :                     $$->name = NULL;
    4731          32 :                     $$->expr = $1;
    4732             :                 }
    4733             :             | '(' a_expr ')'
    4734             :                 {
    4735         442 :                     $$ = makeNode(StatsElem);
    4736         442 :                     $$->name = NULL;
    4737         442 :                     $$->expr = $2;
    4738             :                 }
    4739             :         ;
    4740             : 
    4741             : /*****************************************************************************
    4742             :  *
    4743             :  *      QUERY :
    4744             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4745             :  *                  SET STATISTICS  <SignedIconst>
    4746             :  *
    4747             :  *****************************************************************************/
    4748             : 
    4749             : AlterStatsStmt:
    4750             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4751             :                 {
    4752          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4753             : 
    4754          20 :                     n->defnames = $3;
    4755          20 :                     n->missing_ok = false;
    4756          20 :                     n->stxstattarget = $6;
    4757          20 :                     $$ = (Node *) n;
    4758             :                 }
    4759             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4760             :                 {
    4761           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4762             : 
    4763           6 :                     n->defnames = $5;
    4764           6 :                     n->missing_ok = true;
    4765           6 :                     n->stxstattarget = $8;
    4766           6 :                     $$ = (Node *) n;
    4767             :                 }
    4768             :             ;
    4769             : 
    4770             : /*****************************************************************************
    4771             :  *
    4772             :  *      QUERY :
    4773             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4774             :  *
    4775             :  *
    4776             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4777             :  *
    4778             :  *****************************************************************************/
    4779             : 
    4780             : CreateAsStmt:
    4781             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4782             :                 {
    4783        1148 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4784             : 
    4785        1148 :                     ctas->query = $6;
    4786        1148 :                     ctas->into = $4;
    4787        1148 :                     ctas->objtype = OBJECT_TABLE;
    4788        1148 :                     ctas->is_select_into = false;
    4789        1148 :                     ctas->if_not_exists = false;
    4790             :                     /* cram additional flags into the IntoClause */
    4791        1148 :                     $4->rel->relpersistence = $2;
    4792        1148 :                     $4->skipData = !($7);
    4793        1148 :                     $$ = (Node *) ctas;
    4794             :                 }
    4795             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4796             :                 {
    4797          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4798             : 
    4799          52 :                     ctas->query = $9;
    4800          52 :                     ctas->into = $7;
    4801          52 :                     ctas->objtype = OBJECT_TABLE;
    4802          52 :                     ctas->is_select_into = false;
    4803          52 :                     ctas->if_not_exists = true;
    4804             :                     /* cram additional flags into the IntoClause */
    4805          52 :                     $7->rel->relpersistence = $2;
    4806          52 :                     $7->skipData = !($10);
    4807          52 :                     $$ = (Node *) ctas;
    4808             :                 }
    4809             :         ;
    4810             : 
    4811             : create_as_target:
    4812             :             qualified_name opt_column_list table_access_method_clause
    4813             :             OptWith OnCommitOption OptTableSpace
    4814             :                 {
    4815        1288 :                     $$ = makeNode(IntoClause);
    4816        1288 :                     $$->rel = $1;
    4817        1288 :                     $$->colNames = $2;
    4818        1288 :                     $$->accessMethod = $3;
    4819        1288 :                     $$->options = $4;
    4820        1288 :                     $$->onCommit = $5;
    4821        1288 :                     $$->tableSpaceName = $6;
    4822        1288 :                     $$->viewQuery = NULL;
    4823        1288 :                     $$->skipData = false;        /* might get changed later */
    4824             :                 }
    4825             :         ;
    4826             : 
    4827             : opt_with_data:
    4828          36 :             WITH DATA_P                             { $$ = true; }
    4829         212 :             | WITH NO DATA_P                        { $$ = false; }
    4830        1876 :             | /*EMPTY*/                             { $$ = true; }
    4831             :         ;
    4832             : 
    4833             : 
    4834             : /*****************************************************************************
    4835             :  *
    4836             :  *      QUERY :
    4837             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4838             :  *
    4839             :  *****************************************************************************/
    4840             : 
    4841             : CreateMatViewStmt:
    4842             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4843             :                 {
    4844         526 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4845             : 
    4846         526 :                     ctas->query = $7;
    4847         526 :                     ctas->into = $5;
    4848         526 :                     ctas->objtype = OBJECT_MATVIEW;
    4849         526 :                     ctas->is_select_into = false;
    4850         526 :                     ctas->if_not_exists = false;
    4851             :                     /* cram additional flags into the IntoClause */
    4852         526 :                     $5->rel->relpersistence = $2;
    4853         526 :                     $5->skipData = !($8);
    4854         526 :                     $$ = (Node *) ctas;
    4855             :                 }
    4856             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4857             :                 {
    4858          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4859             : 
    4860          48 :                     ctas->query = $10;
    4861          48 :                     ctas->into = $8;
    4862          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4863          48 :                     ctas->is_select_into = false;
    4864          48 :                     ctas->if_not_exists = true;
    4865             :                     /* cram additional flags into the IntoClause */
    4866          48 :                     $8->rel->relpersistence = $2;
    4867          48 :                     $8->skipData = !($11);
    4868          48 :                     $$ = (Node *) ctas;
    4869             :                 }
    4870             :         ;
    4871             : 
    4872             : create_mv_target:
    4873             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4874             :                 {
    4875         574 :                     $$ = makeNode(IntoClause);
    4876         574 :                     $$->rel = $1;
    4877         574 :                     $$->colNames = $2;
    4878         574 :                     $$->accessMethod = $3;
    4879         574 :                     $$->options = $4;
    4880         574 :                     $$->onCommit = ONCOMMIT_NOOP;
    4881         574 :                     $$->tableSpaceName = $5;
    4882         574 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4883         574 :                     $$->skipData = false;        /* might get changed later */
    4884             :                 }
    4885             :         ;
    4886             : 
    4887           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4888         574 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4889             :         ;
    4890             : 
    4891             : 
    4892             : /*****************************************************************************
    4893             :  *
    4894             :  *      QUERY :
    4895             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4896             :  *
    4897             :  *****************************************************************************/
    4898             : 
    4899             : RefreshMatViewStmt:
    4900             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4901             :                 {
    4902         262 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4903             : 
    4904         262 :                     n->concurrent = $4;
    4905         262 :                     n->relation = $5;
    4906         262 :                     n->skipData = !($6);
    4907         262 :                     $$ = (Node *) n;
    4908             :                 }
    4909             :         ;
    4910             : 
    4911             : 
    4912             : /*****************************************************************************
    4913             :  *
    4914             :  *      QUERY :
    4915             :  *              CREATE SEQUENCE seqname
    4916             :  *              ALTER SEQUENCE seqname
    4917             :  *
    4918             :  *****************************************************************************/
    4919             : 
    4920             : CreateSeqStmt:
    4921             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4922             :                 {
    4923         642 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4924             : 
    4925         642 :                     $4->relpersistence = $2;
    4926         642 :                     n->sequence = $4;
    4927         642 :                     n->options = $5;
    4928         642 :                     n->ownerId = InvalidOid;
    4929         642 :                     n->if_not_exists = false;
    4930         642 :                     $$ = (Node *) n;
    4931             :                 }
    4932             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4933             :                 {
    4934          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4935             : 
    4936          24 :                     $7->relpersistence = $2;
    4937          24 :                     n->sequence = $7;
    4938          24 :                     n->options = $8;
    4939          24 :                     n->ownerId = InvalidOid;
    4940          24 :                     n->if_not_exists = true;
    4941          24 :                     $$ = (Node *) n;
    4942             :                 }
    4943             :         ;
    4944             : 
    4945             : AlterSeqStmt:
    4946             :             ALTER SEQUENCE qualified_name SeqOptList
    4947             :                 {
    4948         184 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4949             : 
    4950         184 :                     n->sequence = $3;
    4951         184 :                     n->options = $4;
    4952         184 :                     n->missing_ok = false;
    4953         184 :                     $$ = (Node *) n;
    4954             :                 }
    4955             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4956             :                 {
    4957          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4958             : 
    4959          12 :                     n->sequence = $5;
    4960          12 :                     n->options = $6;
    4961          12 :                     n->missing_ok = true;
    4962          12 :                     $$ = (Node *) n;
    4963             :                 }
    4964             : 
    4965             :         ;
    4966             : 
    4967         248 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4968         418 :             | /*EMPTY*/                             { $$ = NIL; }
    4969             :         ;
    4970             : 
    4971          74 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4972         418 :             | /*EMPTY*/                             { $$ = NIL; }
    4973             :         ;
    4974             : 
    4975         518 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    4976         778 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    4977             :         ;
    4978             : 
    4979             : SeqOptElem: AS SimpleTypename
    4980             :                 {
    4981         190 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    4982             :                 }
    4983             :             | CACHE NumericOnly
    4984             :                 {
    4985         122 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    4986             :                 }
    4987             :             | CYCLE
    4988             :                 {
    4989          34 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    4990             :                 }
    4991             :             | NO CYCLE
    4992             :                 {
    4993          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    4994             :                 }
    4995             :             | INCREMENT opt_by NumericOnly
    4996             :                 {
    4997         242 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    4998             :                 }
    4999             :             | LOGGED
    5000             :                 {
    5001           2 :                     $$ = makeDefElem("logged", NULL, @1);
    5002             :                 }
    5003             :             | MAXVALUE NumericOnly
    5004             :                 {
    5005          68 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5006             :                 }
    5007             :             | MINVALUE NumericOnly
    5008             :                 {
    5009          72 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5010             :                 }
    5011             :             | NO MAXVALUE
    5012             :                 {
    5013         100 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5014             :                 }
    5015             :             | NO MINVALUE
    5016             :                 {
    5017         100 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5018             :                 }
    5019             :             | OWNED BY any_name
    5020             :                 {
    5021          72 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5022             :                 }
    5023             :             | SEQUENCE NAME_P any_name
    5024             :                 {
    5025          44 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5026             :                 }
    5027             :             | START opt_with NumericOnly
    5028             :                 {
    5029         222 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5030             :                 }
    5031             :             | RESTART
    5032             :                 {
    5033           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5034             :                 }
    5035             :             | RESTART opt_with NumericOnly
    5036             :                 {
    5037          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5038             :                 }
    5039             :             | UNLOGGED
    5040             :                 {
    5041           2 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5042             :                 }
    5043             :         ;
    5044             : 
    5045             : opt_by:     BY
    5046             :             | /* EMPTY */
    5047             :       ;
    5048             : 
    5049             : NumericOnly:
    5050         318 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5051           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5052             :             | '-' FCONST
    5053             :                 {
    5054          20 :                     Float      *f = makeFloat($2);
    5055             : 
    5056          20 :                     doNegateFloat(f);
    5057          20 :                     $$ = (Node *) f;
    5058             :                 }
    5059       11372 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5060             :         ;
    5061             : 
    5062          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5063           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5064             :         ;
    5065             : 
    5066             : /*****************************************************************************
    5067             :  *
    5068             :  *      QUERIES :
    5069             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5070             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5071             :  *
    5072             :  *****************************************************************************/
    5073             : 
    5074             : CreatePLangStmt:
    5075             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5076             :             {
    5077             :                 /*
    5078             :                  * We now interpret parameterless CREATE LANGUAGE as
    5079             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5080             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5081             :                  * seems more useful than throwing an error.  We just
    5082             :                  * ignore TRUSTED, as the previous code would have too.
    5083             :                  */
    5084           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5085             : 
    5086           0 :                 n->if_not_exists = $2;
    5087           0 :                 n->extname = $6;
    5088           0 :                 n->options = NIL;
    5089           0 :                 $$ = (Node *) n;
    5090             :             }
    5091             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5092             :               HANDLER handler_name opt_inline_handler opt_validator
    5093             :             {
    5094         132 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5095             : 
    5096         132 :                 n->replace = $2;
    5097         132 :                 n->plname = $6;
    5098         132 :                 n->plhandler = $8;
    5099         132 :                 n->plinline = $9;
    5100         132 :                 n->plvalidator = $10;
    5101         132 :                 n->pltrusted = $3;
    5102         132 :                 $$ = (Node *) n;
    5103             :             }
    5104             :         ;
    5105             : 
    5106             : opt_trusted:
    5107         102 :             TRUSTED                                 { $$ = true; }
    5108          38 :             | /*EMPTY*/                             { $$ = false; }
    5109             :         ;
    5110             : 
    5111             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5112             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5113             :  * Work around by using simple names, instead.
    5114             :  */
    5115             : handler_name:
    5116         522 :             name                        { $$ = list_make1(makeString($1)); }
    5117           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5118             :         ;
    5119             : 
    5120             : opt_inline_handler:
    5121         114 :             INLINE_P handler_name                   { $$ = $2; }
    5122          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5123             :         ;
    5124             : 
    5125             : validator_clause:
    5126         114 :             VALIDATOR handler_name                  { $$ = $2; }
    5127           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5128             :         ;
    5129             : 
    5130             : opt_validator:
    5131         114 :             validator_clause                        { $$ = $1; }
    5132          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5133             :         ;
    5134             : 
    5135             : opt_procedural:
    5136             :             PROCEDURAL
    5137             :             | /*EMPTY*/
    5138             :         ;
    5139             : 
    5140             : /*****************************************************************************
    5141             :  *
    5142             :  *      QUERY:
    5143             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5144             :  *
    5145             :  *****************************************************************************/
    5146             : 
    5147             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5148             :                 {
    5149         112 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5150             : 
    5151         112 :                     n->tablespacename = $3;
    5152         112 :                     n->owner = $4;
    5153         112 :                     n->location = $6;
    5154         112 :                     n->options = $7;
    5155         112 :                     $$ = (Node *) n;
    5156             :                 }
    5157             :         ;
    5158             : 
    5159           2 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5160         110 :             | /*EMPTY */                { $$ = NULL; }
    5161             :         ;
    5162             : 
    5163             : /*****************************************************************************
    5164             :  *
    5165             :  *      QUERY :
    5166             :  *              DROP TABLESPACE <tablespace>
    5167             :  *
    5168             :  *      No need for drop behaviour as we cannot implement dependencies for
    5169             :  *      objects in other databases; we can only support RESTRICT.
    5170             :  *
    5171             :  ****************************************************************************/
    5172             : 
    5173             : DropTableSpaceStmt: DROP TABLESPACE name
    5174             :                 {
    5175          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5176             : 
    5177          64 :                     n->tablespacename = $3;
    5178          64 :                     n->missing_ok = false;
    5179          64 :                     $$ = (Node *) n;
    5180             :                 }
    5181             :                 |  DROP TABLESPACE IF_P EXISTS name
    5182             :                 {
    5183           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5184             : 
    5185           0 :                     n->tablespacename = $5;
    5186           0 :                     n->missing_ok = true;
    5187           0 :                     $$ = (Node *) n;
    5188             :                 }
    5189             :         ;
    5190             : 
    5191             : /*****************************************************************************
    5192             :  *
    5193             :  *      QUERY:
    5194             :  *             CREATE EXTENSION extension
    5195             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5196             :  *
    5197             :  *****************************************************************************/
    5198             : 
    5199             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5200             :                 {
    5201         470 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5202             : 
    5203         470 :                     n->extname = $3;
    5204         470 :                     n->if_not_exists = false;
    5205         470 :                     n->options = $5;
    5206         470 :                     $$ = (Node *) n;
    5207             :                 }
    5208             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5209             :                 {
    5210          16 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5211             : 
    5212          16 :                     n->extname = $6;
    5213          16 :                     n->if_not_exists = true;
    5214          16 :                     n->options = $8;
    5215          16 :                     $$ = (Node *) n;
    5216             :                 }
    5217             :         ;
    5218             : 
    5219             : create_extension_opt_list:
    5220             :             create_extension_opt_list create_extension_opt_item
    5221          98 :                 { $$ = lappend($1, $2); }
    5222             :             | /* EMPTY */
    5223         486 :                 { $$ = NIL; }
    5224             :         ;
    5225             : 
    5226             : create_extension_opt_item:
    5227             :             SCHEMA name
    5228             :                 {
    5229          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5230             :                 }
    5231             :             | VERSION_P NonReservedWord_or_Sconst
    5232             :                 {
    5233          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5234             :                 }
    5235             :             | FROM NonReservedWord_or_Sconst
    5236             :                 {
    5237           0 :                     ereport(ERROR,
    5238             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5239             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5240             :                              parser_errposition(@1)));
    5241             :                 }
    5242             :             | CASCADE
    5243             :                 {
    5244          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5245             :                 }
    5246             :         ;
    5247             : 
    5248             : /*****************************************************************************
    5249             :  *
    5250             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5251             :  *
    5252             :  *****************************************************************************/
    5253             : 
    5254             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5255             :                 {
    5256          38 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5257             : 
    5258          38 :                     n->extname = $3;
    5259          38 :                     n->options = $5;
    5260          38 :                     $$ = (Node *) n;
    5261             :                 }
    5262             :         ;
    5263             : 
    5264             : alter_extension_opt_list:
    5265             :             alter_extension_opt_list alter_extension_opt_item
    5266          38 :                 { $$ = lappend($1, $2); }
    5267             :             | /* EMPTY */
    5268          38 :                 { $$ = NIL; }
    5269             :         ;
    5270             : 
    5271             : alter_extension_opt_item:
    5272             :             TO NonReservedWord_or_Sconst
    5273             :                 {
    5274          38 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5275             :                 }
    5276             :         ;
    5277             : 
    5278             : /*****************************************************************************
    5279             :  *
    5280             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5281             :  *
    5282             :  *****************************************************************************/
    5283             : 
    5284             : AlterExtensionContentsStmt:
    5285             :             ALTER EXTENSION name add_drop object_type_name name
    5286             :                 {
    5287          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5288             : 
    5289          18 :                     n->extname = $3;
    5290          18 :                     n->action = $4;
    5291          18 :                     n->objtype = $5;
    5292          18 :                     n->object = (Node *) makeString($6);
    5293          18 :                     $$ = (Node *) n;
    5294             :                 }
    5295             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5296             :                 {
    5297          68 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5298             : 
    5299          68 :                     n->extname = $3;
    5300          68 :                     n->action = $4;
    5301          68 :                     n->objtype = $5;
    5302          68 :                     n->object = (Node *) $6;
    5303          68 :                     $$ = (Node *) n;
    5304             :                 }
    5305             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5306             :                 {
    5307           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5308             : 
    5309           8 :                     n->extname = $3;
    5310           8 :                     n->action = $4;
    5311           8 :                     n->objtype = OBJECT_AGGREGATE;
    5312           8 :                     n->object = (Node *) $6;
    5313           8 :                     $$ = (Node *) n;
    5314             :                 }
    5315             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5316             :                 {
    5317           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5318             : 
    5319           4 :                     n->extname = $3;
    5320           4 :                     n->action = $4;
    5321           4 :                     n->objtype = OBJECT_CAST;
    5322           4 :                     n->object = (Node *) list_make2($7, $9);
    5323           4 :                     $$ = (Node *) n;
    5324             :                 }
    5325             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5326             :                 {
    5327           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5328             : 
    5329           0 :                     n->extname = $3;
    5330           0 :                     n->action = $4;
    5331           0 :                     n->objtype = OBJECT_DOMAIN;
    5332           0 :                     n->object = (Node *) $6;
    5333           0 :                     $$ = (Node *) n;
    5334             :                 }
    5335             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5336             :                 {
    5337          88 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5338             : 
    5339          88 :                     n->extname = $3;
    5340          88 :                     n->action = $4;
    5341          88 :                     n->objtype = OBJECT_FUNCTION;
    5342          88 :                     n->object = (Node *) $6;
    5343          88 :                     $$ = (Node *) n;
    5344             :                 }
    5345             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5346             :                 {
    5347          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5348             : 
    5349          18 :                     n->extname = $3;
    5350          18 :                     n->action = $4;
    5351          18 :                     n->objtype = OBJECT_OPERATOR;
    5352          18 :                     n->object = (Node *) $6;
    5353          18 :                     $$ = (Node *) n;
    5354             :                 }
    5355             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5356             :                 {
    5357           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5358             : 
    5359           4 :                     n->extname = $3;
    5360           4 :                     n->action = $4;
    5361           4 :                     n->objtype = OBJECT_OPCLASS;
    5362           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5363           4 :                     $$ = (Node *) n;
    5364             :                 }
    5365             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5366             :                 {
    5367           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5368             : 
    5369           4 :                     n->extname = $3;
    5370           4 :                     n->action = $4;
    5371           4 :                     n->objtype = OBJECT_OPFAMILY;
    5372           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5373           4 :                     $$ = (Node *) n;
    5374             :                 }
    5375             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5376             :                 {
    5377           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5378             : 
    5379           0 :                     n->extname = $3;
    5380           0 :                     n->action = $4;
    5381           0 :                     n->objtype = OBJECT_PROCEDURE;
    5382           0 :                     n->object = (Node *) $6;
    5383           0 :                     $$ = (Node *) n;
    5384             :                 }
    5385             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5386             :                 {
    5387           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5388             : 
    5389           0 :                     n->extname = $3;
    5390           0 :                     n->action = $4;
    5391           0 :                     n->objtype = OBJECT_ROUTINE;
    5392           0 :                     n->object = (Node *) $6;
    5393           0 :                     $$ = (Node *) n;
    5394             :                 }
    5395             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5396             :                 {
    5397           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5398             : 
    5399           4 :                     n->extname = $3;
    5400           4 :                     n->action = $4;
    5401           4 :                     n->objtype = OBJECT_TRANSFORM;
    5402           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5403           4 :                     $$ = (Node *) n;
    5404             :                 }
    5405             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5406             :                 {
    5407           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5408             : 
    5409           8 :                     n->extname = $3;
    5410           8 :                     n->action = $4;
    5411           8 :                     n->objtype = OBJECT_TYPE;
    5412           8 :                     n->object = (Node *) $6;
    5413           8 :                     $$ = (Node *) n;
    5414             :                 }
    5415             :         ;
    5416             : 
    5417             : /*****************************************************************************
    5418             :  *
    5419             :  *      QUERY:
    5420             :  *             CREATE FOREIGN DATA WRAPPER name options
    5421             :  *
    5422             :  *****************************************************************************/
    5423             : 
    5424             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5425             :                 {
    5426         198 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5427             : 
    5428         198 :                     n->fdwname = $5;
    5429         198 :                     n->func_options = $6;
    5430         198 :                     n->options = $7;
    5431         198 :                     $$ = (Node *) n;
    5432             :                 }
    5433             :         ;
    5434             : 
    5435             : fdw_option:
    5436          56 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5437           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5438          46 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5439           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5440             :         ;
    5441             : 
    5442             : fdw_options:
    5443          88 :             fdw_option                          { $$ = list_make1($1); }
    5444          20 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5445             :         ;
    5446             : 
    5447             : opt_fdw_options:
    5448          52 :             fdw_options                         { $$ = $1; }
    5449         238 :             | /*EMPTY*/                         { $$ = NIL; }
    5450             :         ;
    5451             : 
    5452             : /*****************************************************************************
    5453             :  *
    5454             :  *      QUERY :
    5455             :  *              ALTER FOREIGN DATA WRAPPER name options
    5456             :  *
    5457             :  ****************************************************************************/
    5458             : 
    5459             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5460             :                 {
    5461          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5462             : 
    5463          86 :                     n->fdwname = $5;
    5464          86 :                     n->func_options = $6;
    5465          86 :                     n->options = $7;
    5466          86 :                     $$ = (Node *) n;
    5467             :                 }
    5468             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5469             :                 {
    5470          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5471             : 
    5472          36 :                     n->fdwname = $5;
    5473          36 :                     n->func_options = $6;
    5474          36 :                     n->options = NIL;
    5475          36 :                     $$ = (Node *) n;
    5476             :                 }
    5477             :         ;
    5478             : 
    5479             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5480             : create_generic_options:
    5481         716 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5482       66252 :             | /*EMPTY*/                                 { $$ = NIL; }
    5483             :         ;
    5484             : 
    5485             : generic_option_list:
    5486             :             generic_option_elem
    5487             :                 {
    5488         716 :                     $$ = list_make1($1);
    5489             :                 }
    5490             :             | generic_option_list ',' generic_option_elem
    5491             :                 {
    5492         450 :                     $$ = lappend($1, $3);
    5493             :                 }
    5494             :         ;
    5495             : 
    5496             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5497             : alter_generic_options:
    5498         488 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5499             :         ;
    5500             : 
    5501             : alter_generic_option_list:
    5502             :             alter_generic_option_elem
    5503             :                 {
    5504         488 :                     $$ = list_make1($1);
    5505             :                 }
    5506             :             | alter_generic_option_list ',' alter_generic_option_elem
    5507             :                 {
    5508         168 :                     $$ = lappend($1, $3);
    5509             :                 }
    5510             :         ;
    5511             : 
    5512             : alter_generic_option_elem:
    5513             :             generic_option_elem
    5514             :                 {
    5515         200 :                     $$ = $1;
    5516             :                 }
    5517             :             | SET generic_option_elem
    5518             :                 {
    5519         128 :                     $$ = $2;
    5520         128 :                     $$->defaction = DEFELEM_SET;
    5521             :                 }
    5522             :             | ADD_P generic_option_elem
    5523             :                 {
    5524         202 :                     $$ = $2;
    5525         202 :                     $$->defaction = DEFELEM_ADD;
    5526             :                 }
    5527             :             | DROP generic_option_name
    5528             :                 {
    5529         126 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5530             :                 }
    5531             :         ;
    5532             : 
    5533             : generic_option_elem:
    5534             :             generic_option_name generic_option_arg
    5535             :                 {
    5536        1696 :                     $$ = makeDefElem($1, $2, @1);
    5537             :                 }
    5538             :         ;
    5539             : 
    5540             : generic_option_name:
    5541        1822 :                 ColLabel            { $$ = $1; }
    5542             :         ;
    5543             : 
    5544             : /* We could use def_arg here, but the spec only requires string literals */
    5545             : generic_option_arg:
    5546        1696 :                 Sconst              { $$ = (Node *) makeString($1); }
    5547             :         ;
    5548             : 
    5549             : /*****************************************************************************
    5550             :  *
    5551             :  *      QUERY:
    5552             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5553             :  *
    5554             :  *****************************************************************************/
    5555             : 
    5556             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5557             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5558             :                 {
    5559         258 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5560             : 
    5561         258 :                     n->servername = $3;
    5562         258 :                     n->servertype = $4;
    5563         258 :                     n->version = $5;
    5564         258 :                     n->fdwname = $9;
    5565         258 :                     n->options = $10;
    5566         258 :                     n->if_not_exists = false;
    5567         258 :                     $$ = (Node *) n;
    5568             :                 }
    5569             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5570             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5571             :                 {
    5572          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5573             : 
    5574          24 :                     n->servername = $6;
    5575          24 :                     n->servertype = $7;
    5576          24 :                     n->version = $8;
    5577          24 :                     n->fdwname = $12;
    5578          24 :                     n->options = $13;
    5579          24 :                     n->if_not_exists = true;
    5580          24 :                     $$ = (Node *) n;
    5581             :                 }
    5582             :         ;
    5583             : 
    5584             : opt_type:
    5585          18 :             TYPE_P Sconst           { $$ = $2; }
    5586         264 :             | /*EMPTY*/             { $$ = NULL; }
    5587             :         ;
    5588             : 
    5589             : 
    5590             : foreign_server_version:
    5591          66 :             VERSION_P Sconst        { $$ = $2; }
    5592           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5593             :         ;
    5594             : 
    5595             : opt_foreign_server_version:
    5596          18 :             foreign_server_version  { $$ = $1; }
    5597         264 :             | /*EMPTY*/             { $$ = NULL; }
    5598             :         ;
    5599             : 
    5600             : /*****************************************************************************
    5601             :  *
    5602             :  *      QUERY :
    5603             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5604             :  *
    5605             :  ****************************************************************************/
    5606             : 
    5607             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5608             :                 {
    5609           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5610             : 
    5611           6 :                     n->servername = $3;
    5612           6 :                     n->version = $4;
    5613           6 :                     n->options = $5;
    5614           6 :                     n->has_version = true;
    5615           6 :                     $$ = (Node *) n;
    5616             :                 }
    5617             :             | ALTER SERVER name foreign_server_version
    5618             :                 {
    5619          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5620             : 
    5621          42 :                     n->servername = $3;
    5622          42 :                     n->version = $4;
    5623          42 :                     n->has_version = true;
    5624          42 :                     $$ = (Node *) n;
    5625             :                 }
    5626             :             | ALTER SERVER name alter_generic_options
    5627             :                 {
    5628         172 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5629             : 
    5630         172 :                     n->servername = $3;
    5631         172 :                     n->options = $4;
    5632         172 :                     $$ = (Node *) n;
    5633             :                 }
    5634             :         ;
    5635             : 
    5636             : /*****************************************************************************
    5637             :  *
    5638             :  *      QUERY:
    5639             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5640             :  *
    5641             :  *****************************************************************************/
    5642             : 
    5643             : CreateForeignTableStmt:
    5644             :         CREATE FOREIGN TABLE qualified_name
    5645             :             '(' OptTableElementList ')'
    5646             :             OptInherit SERVER name create_generic_options
    5647             :                 {
    5648         378 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5649             : 
    5650         378 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5651         378 :                     n->base.relation = $4;
    5652         378 :                     n->base.tableElts = $6;
    5653         378 :                     n->base.inhRelations = $8;
    5654         378 :                     n->base.ofTypename = NULL;
    5655         378 :                     n->base.constraints = NIL;
    5656         378 :                     n->base.options = NIL;
    5657         378 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5658         378 :                     n->base.tablespacename = NULL;
    5659         378 :                     n->base.if_not_exists = false;
    5660             :                     /* FDW-specific data */
    5661         378 :                     n->servername = $10;
    5662         378 :                     n->options = $11;
    5663         378 :                     $$ = (Node *) n;
    5664             :                 }
    5665             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5666             :             '(' OptTableElementList ')'
    5667             :             OptInherit SERVER name create_generic_options
    5668             :                 {
    5669           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5670             : 
    5671           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5672           0 :                     n->base.relation = $7;
    5673           0 :                     n->base.tableElts = $9;
    5674           0 :                     n->base.inhRelations = $11;
    5675           0 :                     n->base.ofTypename = NULL;
    5676           0 :                     n->base.constraints = NIL;
    5677           0 :                     n->base.options = NIL;
    5678           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5679           0 :                     n->base.tablespacename = NULL;
    5680           0 :                     n->base.if_not_exists = true;
    5681             :                     /* FDW-specific data */
    5682           0 :                     n->servername = $13;
    5683           0 :                     n->options = $14;
    5684           0 :                     $$ = (Node *) n;
    5685             :                 }
    5686             :         | CREATE FOREIGN TABLE qualified_name
    5687             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5688             :             SERVER name create_generic_options
    5689             :                 {
    5690          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5691             : 
    5692          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5693          90 :                     n->base.relation = $4;
    5694          90 :                     n->base.inhRelations = list_make1($7);
    5695          90 :                     n->base.tableElts = $8;
    5696          90 :                     n->base.partbound = $9;
    5697          90 :                     n->base.ofTypename = NULL;
    5698          90 :                     n->base.constraints = NIL;
    5699          90 :                     n->base.options = NIL;
    5700          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5701          90 :                     n->base.tablespacename = NULL;
    5702          90 :                     n->base.if_not_exists = false;
    5703             :                     /* FDW-specific data */
    5704          90 :                     n->servername = $11;
    5705          90 :                     n->options = $12;
    5706          90 :                     $$ = (Node *) n;
    5707             :                 }
    5708             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5709             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5710             :             SERVER name create_generic_options
    5711             :                 {
    5712           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5713             : 
    5714           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5715           0 :                     n->base.relation = $7;
    5716           0 :                     n->base.inhRelations = list_make1($10);
    5717           0 :                     n->base.tableElts = $11;
    5718           0 :                     n->base.partbound = $12;
    5719           0 :                     n->base.ofTypename = NULL;
    5720           0 :                     n->base.constraints = NIL;
    5721           0 :                     n->base.options = NIL;
    5722           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5723           0 :                     n->base.tablespacename = NULL;
    5724           0 :                     n->base.if_not_exists = true;
    5725             :                     /* FDW-specific data */
    5726           0 :                     n->servername = $14;
    5727           0 :                     n->options = $15;
    5728           0 :                     $$ = (Node *) n;
    5729             :                 }
    5730             :         ;
    5731             : 
    5732             : /*****************************************************************************
    5733             :  *
    5734             :  *      QUERY:
    5735             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5736             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5737             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5738             :  *
    5739             :  ****************************************************************************/
    5740             : 
    5741             : ImportForeignSchemaStmt:
    5742             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5743             :           FROM SERVER name INTO name create_generic_options
    5744             :             {
    5745          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5746             : 
    5747          48 :                 n->server_name = $8;
    5748          48 :                 n->remote_schema = $4;
    5749          48 :                 n->local_schema = $10;
    5750          48 :                 n->list_type = $5->type;
    5751          48 :                 n->table_list = $5->table_names;
    5752          48 :                 n->options = $11;
    5753          48 :                 $$ = (Node *) n;
    5754             :             }
    5755             :         ;
    5756             : 
    5757             : import_qualification_type:
    5758          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5759          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5760             :         ;
    5761             : 
    5762             : import_qualification:
    5763             :         import_qualification_type '(' relation_expr_list ')'
    5764             :             {
    5765          28 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5766             : 
    5767          28 :                 n->type = $1;
    5768          28 :                 n->table_names = $3;
    5769          28 :                 $$ = n;
    5770             :             }
    5771             :         | /*EMPTY*/
    5772             :             {
    5773          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5774          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5775          20 :                 n->table_names = NIL;
    5776          20 :                 $$ = n;
    5777             :             }
    5778             :         ;
    5779             : 
    5780             : /*****************************************************************************
    5781             :  *
    5782             :  *      QUERY:
    5783             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5784             :  *
    5785             :  *****************************************************************************/
    5786             : 
    5787             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5788             :                 {
    5789         236 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5790             : 
    5791         236 :                     n->user = $5;
    5792         236 :                     n->servername = $7;
    5793         236 :                     n->options = $8;
    5794         236 :                     n->if_not_exists = false;
    5795         236 :                     $$ = (Node *) n;
    5796             :                 }
    5797             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5798             :                 {
    5799           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5800             : 
    5801           6 :                     n->user = $8;
    5802           6 :                     n->servername = $10;
    5803           6 :                     n->options = $11;
    5804           6 :                     n->if_not_exists = true;
    5805           6 :                     $$ = (Node *) n;
    5806             :                 }
    5807             :         ;
    5808             : 
    5809             : /* User mapping authorization identifier */
    5810         432 : auth_ident: RoleSpec            { $$ = $1; }
    5811          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5812             :         ;
    5813             : 
    5814             : /*****************************************************************************
    5815             :  *
    5816             :  *      QUERY :
    5817             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5818             :  *
    5819             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5820             :  * only pro forma; but the SQL standard doesn't show one.
    5821             :  ****************************************************************************/
    5822             : 
    5823             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5824             :                 {
    5825          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5826             : 
    5827          88 :                     n->user = $5;
    5828          88 :                     n->servername = $7;
    5829          88 :                     n->missing_ok = false;
    5830          88 :                     $$ = (Node *) n;
    5831             :                 }
    5832             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5833             :                 {
    5834          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5835             : 
    5836          38 :                     n->user = $7;
    5837          38 :                     n->servername = $9;
    5838          38 :                     n->missing_ok = true;
    5839          38 :                     $$ = (Node *) n;
    5840             :                 }
    5841             :         ;
    5842             : 
    5843             : /*****************************************************************************
    5844             :  *
    5845             :  *      QUERY :
    5846             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5847             :  *
    5848             :  ****************************************************************************/
    5849             : 
    5850             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5851             :                 {
    5852         110 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5853             : 
    5854         110 :                     n->user = $5;
    5855         110 :                     n->servername = $7;
    5856         110 :                     n->options = $8;
    5857         110 :                     $$ = (Node *) n;
    5858             :                 }
    5859             :         ;
    5860             : 
    5861             : /*****************************************************************************
    5862             :  *
    5863             :  *      QUERIES:
    5864             :  *              CREATE POLICY name ON table
    5865             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5866             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5867             :  *                  [TO role, ...]
    5868             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5869             :  *              ALTER POLICY name ON table [TO role, ...]
    5870             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5871             :  *
    5872             :  *****************************************************************************/
    5873             : 
    5874             : CreatePolicyStmt:
    5875             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5876             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5877             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5878             :                 {
    5879         676 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5880             : 
    5881         676 :                     n->policy_name = $3;
    5882         676 :                     n->table = $5;
    5883         676 :                     n->permissive = $6;
    5884         676 :                     n->cmd_name = $7;
    5885         676 :                     n->roles = $8;
    5886         676 :                     n->qual = $9;
    5887         676 :                     n->with_check = $10;
    5888         676 :                     $$ = (Node *) n;
    5889             :                 }
    5890             :         ;
    5891             : 
    5892             : AlterPolicyStmt:
    5893             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5894             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5895             :                 {
    5896          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5897             : 
    5898          84 :                     n->policy_name = $3;
    5899          84 :                     n->table = $5;
    5900          84 :                     n->roles = $6;
    5901          84 :                     n->qual = $7;
    5902          84 :                     n->with_check = $8;
    5903          84 :                     $$ = (Node *) n;
    5904             :                 }
    5905             :         ;
    5906             : 
    5907             : RowSecurityOptionalExpr:
    5908         702 :             USING '(' a_expr ')'    { $$ = $3; }
    5909          58 :             | /* EMPTY */           { $$ = NULL; }
    5910             :         ;
    5911             : 
    5912             : RowSecurityOptionalWithCheck:
    5913         122 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5914         638 :             | /* EMPTY */                   { $$ = NULL; }
    5915             :         ;
    5916             : 
    5917             : RowSecurityDefaultToRole:
    5918         124 :             TO role_list            { $$ = $2; }
    5919         552 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5920             :         ;
    5921             : 
    5922             : RowSecurityOptionalToRole:
    5923          12 :             TO role_list            { $$ = $2; }
    5924          72 :             | /* EMPTY */           { $$ = NULL; }
    5925             :         ;
    5926             : 
    5927             : RowSecurityDefaultPermissive:
    5928             :             AS IDENT
    5929             :                 {
    5930          98 :                     if (strcmp($2, "permissive") == 0)
    5931          24 :                         $$ = true;
    5932          74 :                     else if (strcmp($2, "restrictive") == 0)
    5933          68 :                         $$ = false;
    5934             :                     else
    5935           6 :                         ereport(ERROR,
    5936             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5937             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5938             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5939             :                                  parser_errposition(@2)));
    5940             : 
    5941             :                 }
    5942         584 :             | /* EMPTY */           { $$ = true; }
    5943             :         ;
    5944             : 
    5945             : RowSecurityDefaultForCmd:
    5946         314 :             FOR row_security_cmd    { $$ = $2; }
    5947         362 :             | /* EMPTY */           { $$ = "all"; }
    5948             :         ;
    5949             : 
    5950             : row_security_cmd:
    5951          44 :             ALL             { $$ = "all"; }
    5952         106 :         |   SELECT          { $$ = "select"; }
    5953          44 :         |   INSERT          { $$ = "insert"; }
    5954          78 :         |   UPDATE          { $$ = "update"; }
    5955          42 :         |   DELETE_P        { $$ = "delete"; }
    5956             :         ;
    5957             : 
    5958             : /*****************************************************************************
    5959             :  *
    5960             :  *      QUERY:
    5961             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5962             :  *
    5963             :  *****************************************************************************/
    5964             : 
    5965             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5966             :                 {
    5967          62 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5968             : 
    5969          62 :                     n->amname = $4;
    5970          62 :                     n->handler_name = $8;
    5971          62 :                     n->amtype = $6;
    5972          62 :                     $$ = (Node *) n;
    5973             :                 }
    5974             :         ;
    5975             : 
    5976             : am_type:
    5977          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    5978          28 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    5979             :         ;
    5980             : 
    5981             : /*****************************************************************************
    5982             :  *
    5983             :  *      QUERIES :
    5984             :  *              CREATE TRIGGER ...
    5985             :  *
    5986             :  *****************************************************************************/
    5987             : 
    5988             : CreateTrigStmt:
    5989             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    5990             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    5991             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5992             :                 {
    5993        3162 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5994             : 
    5995        3162 :                     n->replace = $2;
    5996        3162 :                     n->isconstraint = false;
    5997        3162 :                     n->trigname = $4;
    5998        3162 :                     n->relation = $8;
    5999        3162 :                     n->funcname = $14;
    6000        3162 :                     n->args = $16;
    6001        3162 :                     n->row = $10;
    6002        3162 :                     n->timing = $5;
    6003        3162 :                     n->events = intVal(linitial($6));
    6004        3162 :                     n->columns = (List *) lsecond($6);
    6005        3162 :                     n->whenClause = $11;
    6006        3162 :                     n->transitionRels = $9;
    6007        3162 :                     n->deferrable = false;
    6008        3162 :                     n->initdeferred = false;
    6009        3162 :                     n->constrrel = NULL;
    6010        3162 :                     $$ = (Node *) n;
    6011             :                 }
    6012             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6013             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6014             :             FOR EACH ROW TriggerWhen
    6015             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6016             :                 {
    6017          62 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6018             : 
    6019          62 :                     n->replace = $2;
    6020          62 :                     if (n->replace) /* not supported, see CreateTrigger */
    6021           0 :                         ereport(ERROR,
    6022             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6023             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6024             :                                  parser_errposition(@1)));
    6025          62 :                     n->isconstraint = true;
    6026          62 :                     n->trigname = $5;
    6027          62 :                     n->relation = $9;
    6028          62 :                     n->funcname = $18;
    6029          62 :                     n->args = $20;
    6030          62 :                     n->row = true;
    6031          62 :                     n->timing = TRIGGER_TYPE_AFTER;
    6032          62 :                     n->events = intVal(linitial($7));
    6033          62 :                     n->columns = (List *) lsecond($7);
    6034          62 :                     n->whenClause = $15;
    6035          62 :                     n->transitionRels = NIL;
    6036          62 :                     processCASbits($11, @11, "TRIGGER",
    6037             :                                    &n->deferrable, &n->initdeferred, NULL,
    6038             :                                    NULL, NULL, yyscanner);
    6039          62 :                     n->constrrel = $10;
    6040          62 :                     $$ = (Node *) n;
    6041             :                 }
    6042             :         ;
    6043             : 
    6044             : TriggerActionTime:
    6045        1452 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6046        1578 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6047         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6048             :         ;
    6049             : 
    6050             : TriggerEvents:
    6051             :             TriggerOneEvent
    6052        3236 :                 { $$ = $1; }
    6053             :             | TriggerEvents OR TriggerOneEvent
    6054             :                 {
    6055        1160 :                     int         events1 = intVal(linitial($1));
    6056        1160 :                     int         events2 = intVal(linitial($3));
    6057        1160 :                     List       *columns1 = (List *) lsecond($1);
    6058        1160 :                     List       *columns2 = (List *) lsecond($3);
    6059             : 
    6060        1160 :                     if (events1 & events2)
    6061           6 :                         parser_yyerror("duplicate trigger events specified");
    6062             :                     /*
    6063             :                      * concat'ing the columns lists loses information about
    6064             :                      * which columns went with which event, but so long as
    6065             :                      * only UPDATE carries columns and we disallow multiple
    6066             :                      * UPDATE items, it doesn't matter.  Command execution
    6067             :                      * should just ignore the columns for non-UPDATE events.
    6068             :                      */
    6069        1154 :                     $$ = list_make2(makeInteger(events1 | events2),
    6070             :                                     list_concat(columns1, columns2));
    6071             :                 }
    6072             :         ;
    6073             : 
    6074             : TriggerOneEvent:
    6075             :             INSERT
    6076        1644 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6077             :             | DELETE_P
    6078         884 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6079             :             | UPDATE
    6080        1730 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6081             :             | UPDATE OF columnList
    6082         100 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6083             :             | TRUNCATE
    6084          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6085             :         ;
    6086             : 
    6087             : TriggerReferencing:
    6088         454 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6089        2708 :             | /*EMPTY*/                             { $$ = NIL; }
    6090             :         ;
    6091             : 
    6092             : TriggerTransitions:
    6093         454 :             TriggerTransition                       { $$ = list_make1($1); }
    6094         138 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6095             :         ;
    6096             : 
    6097             : TriggerTransition:
    6098             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6099             :                 {
    6100         592 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6101             : 
    6102         592 :                     n->name = $4;
    6103         592 :                     n->isNew = $1;
    6104         592 :                     n->isTable = $2;
    6105         592 :                     $$ = (Node *) n;
    6106             :                 }
    6107             :         ;
    6108             : 
    6109             : TransitionOldOrNew:
    6110         324 :             NEW                                     { $$ = true; }
    6111         268 :             | OLD                                   { $$ = false; }
    6112             :         ;
    6113             : 
    6114             : TransitionRowOrTable:
    6115         592 :             TABLE                                   { $$ = true; }
    6116             :             /*
    6117             :              * According to the standard, lack of a keyword here implies ROW.
    6118             :              * Support for that would require prohibiting ROW entirely here,
    6119             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6120             :              * allowing it to be optional, as the standard specifies) as the
    6121             :              * next token.  Requiring ROW seems cleanest and easiest to
    6122             :              * explain.
    6123             :              */
    6124           0 :             | ROW                                   { $$ = false; }
    6125             :         ;
    6126             : 
    6127             : TransitionRelName:
    6128         592 :             ColId                                   { $$ = $1; }
    6129             :         ;
    6130             : 
    6131             : TriggerForSpec:
    6132             :             FOR TriggerForOptEach TriggerForType
    6133             :                 {
    6134        2934 :                     $$ = $3;
    6135             :                 }
    6136             :             | /* EMPTY */
    6137             :                 {
    6138             :                     /*
    6139             :                      * If ROW/STATEMENT not specified, default to
    6140             :                      * STATEMENT, per SQL
    6141             :                      */
    6142         228 :                     $$ = false;
    6143             :                 }
    6144             :         ;
    6145             : 
    6146             : TriggerForOptEach:
    6147             :             EACH
    6148             :             | /*EMPTY*/
    6149             :         ;
    6150             : 
    6151             : TriggerForType:
    6152        2124 :             ROW                                     { $$ = true; }
    6153         810 :             | STATEMENT                             { $$ = false; }
    6154             :         ;
    6155             : 
    6156             : TriggerWhen:
    6157         190 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6158        3034 :             | /*EMPTY*/                             { $$ = NULL; }
    6159             :         ;
    6160             : 
    6161             : FUNCTION_or_PROCEDURE:
    6162             :             FUNCTION
    6163             :         |   PROCEDURE
    6164             :         ;
    6165             : 
    6166             : TriggerFuncArgs:
    6167         576 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6168         264 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6169        2648 :             | /*EMPTY*/                             { $$ = NIL; }
    6170             :         ;
    6171             : 
    6172             : TriggerFuncArg:
    6173             :             Iconst
    6174             :                 {
    6175         102 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6176             :                 }
    6177           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6178         696 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6179          42 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6180             :         ;
    6181             : 
    6182             : OptConstrFromTable:
    6183          12 :             FROM qualified_name                     { $$ = $2; }
    6184          50 :             | /*EMPTY*/                             { $$ = NULL; }
    6185             :         ;
    6186             : 
    6187             : ConstraintAttributeSpec:
    6188             :             /*EMPTY*/
    6189       16294 :                 { $$ = 0; }
    6190             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6191             :                 {
    6192             :                     /*
    6193             :                      * We must complain about conflicting options.
    6194             :                      * We could, but choose not to, complain about redundant
    6195             :                      * options (ie, where $2's bit is already set in $1).
    6196             :                      */
    6197        1312 :                     int     newspec = $1 | $2;
    6198             : 
    6199             :                     /* special message for this case */
    6200        1312 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6201           6 :                         ereport(ERROR,
    6202             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6203             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6204             :                                  parser_errposition(@2)));
    6205             :                     /* generic message for other conflicts */
    6206        1306 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6207        1306 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6208        1306 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6209           0 :                         ereport(ERROR,
    6210             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6211             :                                  errmsg("conflicting constraint properties"),
    6212             :                                  parser_errposition(@2)));
    6213        1306 :                     $$ = newspec;
    6214             :                 }
    6215             :         ;
    6216             : 
    6217             : ConstraintAttributeElem:
    6218          36 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6219         218 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6220          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6221         170 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6222         542 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6223         190 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6224          84 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6225          42 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6226             :         ;
    6227             : 
    6228             : 
    6229             : /*****************************************************************************
    6230             :  *
    6231             :  *      QUERIES :
    6232             :  *              CREATE EVENT TRIGGER ...
    6233             :  *              ALTER EVENT TRIGGER ...
    6234             :  *
    6235             :  *****************************************************************************/
    6236             : 
    6237             : CreateEventTrigStmt:
    6238             :             CREATE EVENT TRIGGER name ON ColLabel
    6239             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6240             :                 {
    6241          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6242             : 
    6243          98 :                     n->trigname = $4;
    6244          98 :                     n->eventname = $6;
    6245          98 :                     n->whenclause = NULL;
    6246          98 :                     n->funcname = $9;
    6247          98 :                     $$ = (Node *) n;
    6248             :                 }
    6249             :           | CREATE EVENT TRIGGER name ON ColLabel
    6250             :             WHEN event_trigger_when_list
    6251             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6252             :                 {
    6253          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6254             : 
    6255          98 :                     n->trigname = $4;
    6256          98 :                     n->eventname = $6;
    6257          98 :                     n->whenclause = $8;
    6258          98 :                     n->funcname = $11;
    6259          98 :                     $$ = (Node *) n;
    6260             :                 }
    6261             :         ;
    6262             : 
    6263             : event_trigger_when_list:
    6264             :           event_trigger_when_item
    6265          98 :             { $$ = list_make1($1); }
    6266             :         | event_trigger_when_list AND event_trigger_when_item
    6267           6 :             { $$ = lappend($1, $3); }
    6268             :         ;
    6269             : 
    6270             : event_trigger_when_item:
    6271             :         ColId IN_P '(' event_trigger_value_list ')'
    6272         104 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6273             :         ;
    6274             : 
    6275             : event_trigger_value_list:
    6276             :           SCONST
    6277         104 :             { $$ = list_make1(makeString($1)); }
    6278             :         | event_trigger_value_list ',' SCONST
    6279          66 :             { $$ = lappend($1, makeString($3)); }
    6280             :         ;
    6281             : 
    6282             : AlterEventTrigStmt:
    6283             :             ALTER EVENT TRIGGER name enable_trigger
    6284             :                 {
    6285          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6286             : 
    6287          48 :                     n->trigname = $4;
    6288          48 :                     n->tgenabled = $5;
    6289          48 :                     $$ = (Node *) n;
    6290             :                 }
    6291             :         ;
    6292             : 
    6293             : enable_trigger:
    6294           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6295           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6296          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6297          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6298             :         ;
    6299             : 
    6300             : /*****************************************************************************
    6301             :  *
    6302             :  *      QUERY :
    6303             :  *              CREATE ASSERTION ...
    6304             :  *
    6305             :  *****************************************************************************/
    6306             : 
    6307             : CreateAssertionStmt:
    6308             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6309             :                 {
    6310           0 :                     ereport(ERROR,
    6311             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6312             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6313             :                              parser_errposition(@1)));
    6314             : 
    6315             :                     $$ = NULL;
    6316             :                 }
    6317             :         ;
    6318             : 
    6319             : 
    6320             : /*****************************************************************************
    6321             :  *
    6322             :  *      QUERY :
    6323             :  *              define (aggregate,operator,type)
    6324             :  *
    6325             :  *****************************************************************************/
    6326             : 
    6327             : DefineStmt:
    6328             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6329             :                 {
    6330         544 :                     DefineStmt *n = makeNode(DefineStmt);
    6331             : 
    6332         544 :                     n->kind = OBJECT_AGGREGATE;
    6333         544 :                     n->oldstyle = false;
    6334         544 :                     n->replace = $2;
    6335         544 :                     n->defnames = $4;
    6336         544 :                     n->args = $5;
    6337         544 :                     n->definition = $6;
    6338         544 :                     $$ = (Node *) n;
    6339             :                 }
    6340             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6341             :                 {
    6342             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6343         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6344             : 
    6345         362 :                     n->kind = OBJECT_AGGREGATE;
    6346         362 :                     n->oldstyle = true;
    6347         362 :                     n->replace = $2;
    6348         362 :                     n->defnames = $4;
    6349         362 :                     n->args = NIL;
    6350         362 :                     n->definition = $5;
    6351         362 :                     $$ = (Node *) n;
    6352             :                 }
    6353             :             | CREATE OPERATOR any_operator definition
    6354             :                 {
    6355        1586 :                     DefineStmt *n = makeNode(DefineStmt);
    6356             : 
    6357        1586 :                     n->kind = OBJECT_OPERATOR;
    6358        1586 :                     n->oldstyle = false;
    6359        1586 :                     n->defnames = $3;
    6360        1586 :                     n->args = NIL;
    6361        1586 :                     n->definition = $4;
    6362        1586 :                     $$ = (Node *) n;
    6363             :                 }
    6364             :             | CREATE TYPE_P any_name definition
    6365             :                 {
    6366         214 :                     DefineStmt *n = makeNode(DefineStmt);
    6367             : 
    6368         214 :                     n->kind = OBJECT_TYPE;
    6369         214 :                     n->oldstyle = false;
    6370         214 :                     n->defnames = $3;
    6371         214 :                     n->args = NIL;
    6372         214 :                     n->definition = $4;
    6373         214 :                     $$ = (Node *) n;
    6374             :                 }
    6375             :             | CREATE TYPE_P any_name
    6376             :                 {
    6377             :                     /* Shell type (identified by lack of definition) */
    6378         154 :                     DefineStmt *n = makeNode(DefineStmt);
    6379             : 
    6380         154 :                     n->kind = OBJECT_TYPE;
    6381         154 :                     n->oldstyle = false;
    6382         154 :                     n->defnames = $3;
    6383         154 :                     n->args = NIL;
    6384         154 :                     n->definition = NIL;
    6385         154 :                     $$ = (Node *) n;
    6386             :                 }
    6387             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6388             :                 {
    6389        4492 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6390             : 
    6391             :                     /* can't use qualified_name, sigh */
    6392        4492 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6393        4492 :                     n->coldeflist = $6;
    6394        4492 :                     $$ = (Node *) n;
    6395             :                 }
    6396             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6397             :                 {
    6398         194 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6399             : 
    6400         194 :                     n->typeName = $3;
    6401         194 :                     n->vals = $7;
    6402         194 :                     $$ = (Node *) n;
    6403             :                 }
    6404             :             | CREATE TYPE_P any_name AS RANGE definition
    6405             :                 {
    6406         184 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6407             : 
    6408         184 :                     n->typeName = $3;
    6409         184 :                     n->params = $6;
    6410         184 :                     $$ = (Node *) n;
    6411             :                 }
    6412             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6413             :                 {
    6414          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6415             : 
    6416          40 :                     n->kind = OBJECT_TSPARSER;
    6417          40 :                     n->args = NIL;
    6418          40 :                     n->defnames = $5;
    6419          40 :                     n->definition = $6;
    6420          40 :                     $$ = (Node *) n;
    6421             :                 }
    6422             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6423             :                 {
    6424        2554 :                     DefineStmt *n = makeNode(DefineStmt);
    6425             : 
    6426        2554 :                     n->kind = OBJECT_TSDICTIONARY;
    6427        2554 :                     n->args = NIL;
    6428        2554 :                     n->defnames = $5;
    6429        2554 :                     n->definition = $6;
    6430        2554 :                     $$ = (Node *) n;
    6431             :                 }
    6432             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6433             :                 {
    6434         130 :                     DefineStmt *n = makeNode(DefineStmt);
    6435             : 
    6436         130 :                     n->kind = OBJECT_TSTEMPLATE;
    6437         130 :                     n->args = NIL;
    6438         130 :                     n->defnames = $5;
    6439         130 :                     n->definition = $6;
    6440         130 :                     $$ = (Node *) n;
    6441             :                 }
    6442             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6443             :                 {
    6444        2496 :                     DefineStmt *n = makeNode(DefineStmt);
    6445             : 
    6446        2496 :                     n->kind = OBJECT_TSCONFIGURATION;
    6447        2496 :                     n->args = NIL;
    6448        2496 :                     n->defnames = $5;
    6449        2496 :                     n->definition = $6;
    6450        2496 :                     $$ = (Node *) n;
    6451             :                 }
    6452             :             | CREATE COLLATION any_name definition
    6453             :                 {
    6454         292 :                     DefineStmt *n = makeNode(DefineStmt);
    6455             : 
    6456         292 :                     n->kind = OBJECT_COLLATION;
    6457         292 :                     n->args = NIL;
    6458         292 :                     n->defnames = $3;
    6459         292 :                     n->definition = $4;
    6460         292 :                     $$ = (Node *) n;
    6461             :                 }
    6462             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6463             :                 {
    6464          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6465             : 
    6466          18 :                     n->kind = OBJECT_COLLATION;
    6467          18 :                     n->args = NIL;
    6468          18 :                     n->defnames = $6;
    6469          18 :                     n->definition = $7;
    6470          18 :                     n->if_not_exists = true;
    6471          18 :                     $$ = (Node *) n;
    6472             :                 }
    6473             :             | CREATE COLLATION any_name FROM any_name
    6474             :                 {
    6475          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6476             : 
    6477          54 :                     n->kind = OBJECT_COLLATION;
    6478          54 :                     n->args = NIL;
    6479          54 :                     n->defnames = $3;
    6480          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6481          54 :                     $$ = (Node *) n;
    6482             :                 }
    6483             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6484             :                 {
    6485           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6486             : 
    6487           0 :                     n->kind = OBJECT_COLLATION;
    6488           0 :                     n->args = NIL;
    6489           0 :                     n->defnames = $6;
    6490           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6491           0 :                     n->if_not_exists = true;
    6492           0 :                     $$ = (Node *) n;
    6493             :                 }
    6494             :         ;
    6495             : 
    6496        9022 : definition: '(' def_list ')'                        { $$ = $2; }
    6497             :         ;
    6498             : 
    6499        9022 : def_list:   def_elem                                { $$ = list_make1($1); }
    6500       14008 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6501             :         ;
    6502             : 
    6503             : def_elem:   ColLabel '=' def_arg
    6504             :                 {
    6505       22694 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6506             :                 }
    6507             :             | ColLabel
    6508             :                 {
    6509         336 :                     $$ = makeDefElem($1, NULL, @1);
    6510             :                 }
    6511             :         ;
    6512             : 
    6513             : /* Note: any simple identifier will be returned as a type name! */
    6514       18542 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6515        3592 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6516        1174 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6517        1282 :             | NumericOnly                   { $$ = (Node *) $1; }
    6518        1830 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6519         160 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6520             :         ;
    6521             : 
    6522         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6523             :         ;
    6524             : 
    6525         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6526        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6527             :         ;
    6528             : 
    6529             : /*
    6530             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6531             :  * the item names needed in old aggregate definitions are likely to become
    6532             :  * SQL keywords.
    6533             :  */
    6534             : old_aggr_elem:  IDENT '=' def_arg
    6535             :                 {
    6536        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6537             :                 }
    6538             :         ;
    6539             : 
    6540             : opt_enum_val_list:
    6541         186 :         enum_val_list                           { $$ = $1; }
    6542           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6543             :         ;
    6544             : 
    6545             : enum_val_list:  Sconst
    6546         186 :                 { $$ = list_make1(makeString($1)); }
    6547             :             | enum_val_list ',' Sconst
    6548       10394 :                 { $$ = lappend($1, makeString($3)); }
    6549             :         ;
    6550             : 
    6551             : /*****************************************************************************
    6552             :  *
    6553             :  *  ALTER TYPE enumtype ADD ...
    6554             :  *
    6555             :  *****************************************************************************/
    6556             : 
    6557             : AlterEnumStmt:
    6558             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6559             :             {
    6560         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6561             : 
    6562         154 :                 n->typeName = $3;
    6563         154 :                 n->oldVal = NULL;
    6564         154 :                 n->newVal = $7;
    6565         154 :                 n->newValNeighbor = NULL;
    6566         154 :                 n->newValIsAfter = true;
    6567         154 :                 n->skipIfNewValExists = $6;
    6568         154 :                 $$ = (Node *) n;
    6569             :             }
    6570             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6571             :             {
    6572         194 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6573             : 
    6574         194 :                 n->typeName = $3;
    6575         194 :                 n->oldVal = NULL;
    6576         194 :                 n->newVal = $7;
    6577         194 :                 n->newValNeighbor = $9;
    6578         194 :                 n->newValIsAfter = false;
    6579         194 :                 n->skipIfNewValExists = $6;
    6580         194 :                 $$ = (Node *) n;
    6581             :             }
    6582             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6583             :             {
    6584          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6585             : 
    6586          22 :                 n->typeName = $3;
    6587          22 :                 n->oldVal = NULL;
    6588          22 :                 n->newVal = $7;
    6589          22 :                 n->newValNeighbor = $9;
    6590          22 :                 n->newValIsAfter = true;
    6591          22 :                 n->skipIfNewValExists = $6;
    6592          22 :                 $$ = (Node *) n;
    6593             :             }
    6594             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6595             :             {
    6596          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6597             : 
    6598          24 :                 n->typeName = $3;
    6599          24 :                 n->oldVal = $6;
    6600          24 :                 n->newVal = $8;
    6601          24 :                 n->newValNeighbor = NULL;
    6602          24 :                 n->newValIsAfter = false;
    6603          24 :                 n->skipIfNewValExists = false;
    6604          24 :                 $$ = (Node *) n;
    6605             :             }
    6606             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6607             :             {
    6608             :                 /*
    6609             :                  * The following problems must be solved before this can be
    6610             :                  * implemented:
    6611             :                  *
    6612             :                  * - There must be no instance of the target value in
    6613             :                  *   any table.
    6614             :                  *
    6615             :                  * - The value must not appear in any catalog metadata,
    6616             :                  *   such as stored view expressions or column defaults.
    6617             :                  *
    6618             :                  * - The value must not appear in any non-leaf page of a
    6619             :                  *   btree (and similar issues with other index types).
    6620             :                  *   This is problematic because a value could persist
    6621             :                  *   there long after it's gone from user-visible data.
    6622             :                  *
    6623             :                  * - Concurrent sessions must not be able to insert the
    6624             :                  *   value while the preceding conditions are being checked.
    6625             :                  *
    6626             :                  * - Possibly more...
    6627             :                  */
    6628           0 :                 ereport(ERROR,
    6629             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6630             :                          errmsg("dropping an enum value is not implemented"),
    6631             :                          parser_errposition(@4)));
    6632             :             }
    6633             :          ;
    6634             : 
    6635          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6636         358 :         | /* EMPTY */                          { $$ = false; }
    6637             :         ;
    6638             : 
    6639             : 
    6640             : /*****************************************************************************
    6641             :  *
    6642             :  *      QUERIES :
    6643             :  *              CREATE OPERATOR CLASS ...
    6644             :  *              CREATE OPERATOR FAMILY ...
    6645             :  *              ALTER OPERATOR FAMILY ...
    6646             :  *              DROP OPERATOR CLASS ...
    6647             :  *              DROP OPERATOR FAMILY ...
    6648             :  *
    6649             :  *****************************************************************************/
    6650             : 
    6651             : CreateOpClassStmt:
    6652             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6653             :             USING name opt_opfamily AS opclass_item_list
    6654             :                 {
    6655         388 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6656             : 
    6657         388 :                     n->opclassname = $4;
    6658         388 :                     n->isDefault = $5;
    6659         388 :                     n->datatype = $8;
    6660         388 :                     n->amname = $10;
    6661         388 :                     n->opfamilyname = $11;
    6662         388 :                     n->items = $13;
    6663         388 :                     $$ = (Node *) n;
    6664             :                 }
    6665             :         ;
    6666             : 
    6667             : opclass_item_list:
    6668         838 :             opclass_item                            { $$ = list_make1($1); }
    6669        3088 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6670             :         ;
    6671             : 
    6672             : opclass_item:
    6673             :             OPERATOR Iconst any_operator opclass_purpose
    6674             :                 {
    6675        1092 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6676        1092 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6677             : 
    6678        1092 :                     owa->objname = $3;
    6679        1092 :                     owa->objargs = NIL;
    6680        1092 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6681        1092 :                     n->name = owa;
    6682        1092 :                     n->number = $2;
    6683        1092 :                     n->order_family = $4;
    6684        1092 :                     $$ = (Node *) n;
    6685             :                 }
    6686             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6687             :                 {
    6688        1062 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6689             : 
    6690        1062 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6691        1062 :                     n->name = $3;
    6692        1062 :                     n->number = $2;
    6693        1062 :                     n->order_family = $4;
    6694        1062 :                     $$ = (Node *) n;
    6695             :                 }
    6696             :             | FUNCTION Iconst function_with_argtypes
    6697             :                 {
    6698        1386 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6699             : 
    6700        1386 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6701        1386 :                     n->name = $3;
    6702        1386 :                     n->number = $2;
    6703        1386 :                     $$ = (Node *) n;
    6704             :                 }
    6705             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6706             :                 {
    6707         188 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6708             : 
    6709         188 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6710         188 :                     n->name = $6;
    6711         188 :                     n->number = $2;
    6712         188 :                     n->class_args = $4;
    6713         188 :                     $$ = (Node *) n;
    6714             :                 }
    6715             :             | STORAGE Typename
    6716             :                 {
    6717         198 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6718             : 
    6719         198 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6720         198 :                     n->storedtype = $2;
    6721         198 :                     $$ = (Node *) n;
    6722             :                 }
    6723             :         ;
    6724             : 
    6725         290 : opt_default:    DEFAULT                     { $$ = true; }
    6726         162 :             | /*EMPTY*/                     { $$ = false; }
    6727             :         ;
    6728             : 
    6729          44 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6730         344 :             | /*EMPTY*/                     { $$ = NIL; }
    6731             :         ;
    6732             : 
    6733           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6734          72 :             | FOR ORDER BY any_name         { $$ = $4; }
    6735        2082 :             | /*EMPTY*/                     { $$ = NIL; }
    6736             :         ;
    6737             : 
    6738             : 
    6739             : CreateOpFamilyStmt:
    6740             :             CREATE OPERATOR FAMILY any_name USING name
    6741             :                 {
    6742         148 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6743             : 
    6744         148 :                     n->opfamilyname = $4;
    6745         148 :                     n->amname = $6;
    6746         148 :                     $$ = (Node *) n;
    6747             :                 }
    6748             :         ;
    6749             : 
    6750             : AlterOpFamilyStmt:
    6751             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6752             :                 {
    6753         450 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6754             : 
    6755         450 :                     n->opfamilyname = $4;
    6756         450 :                     n->amname = $6;
    6757         450 :                     n->isDrop = false;
    6758         450 :                     n->items = $8;
    6759         450 :                     $$ = (Node *) n;
    6760             :                 }
    6761             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6762             :                 {
    6763          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6764             : 
    6765          64 :                     n->opfamilyname = $4;
    6766          64 :                     n->amname = $6;
    6767          64 :                     n->isDrop = true;
    6768          64 :                     n->items = $8;
    6769          64 :                     $$ = (Node *) n;
    6770             :                 }
    6771             :         ;
    6772             : 
    6773             : opclass_drop_list:
    6774          64 :             opclass_drop                            { $$ = list_make1($1); }
    6775          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6776             :         ;
    6777             : 
    6778             : opclass_drop:
    6779             :             OPERATOR Iconst '(' type_list ')'
    6780             :                 {
    6781          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6782             : 
    6783          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6784          56 :                     n->number = $2;
    6785          56 :                     n->class_args = $4;
    6786          56 :                     $$ = (Node *) n;
    6787             :                 }
    6788             :             | FUNCTION Iconst '(' type_list ')'
    6789             :                 {
    6790          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6791             : 
    6792          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6793          38 :                     n->number = $2;
    6794          38 :                     n->class_args = $4;
    6795          38 :                     $$ = (Node *) n;
    6796             :                 }
    6797             :         ;
    6798             : 
    6799             : 
    6800             : DropOpClassStmt:
    6801             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6802             :                 {
    6803          38 :                     DropStmt *n = makeNode(DropStmt);
    6804             : 
    6805          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6806          38 :                     n->removeType = OBJECT_OPCLASS;
    6807          38 :                     n->behavior = $7;
    6808          38 :                     n->missing_ok = false;
    6809          38 :                     n->concurrent = false;
    6810          38 :                     $$ = (Node *) n;
    6811             :                 }
    6812             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6813             :                 {
    6814          18 :                     DropStmt *n = makeNode(DropStmt);
    6815             : 
    6816          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6817          18 :                     n->removeType = OBJECT_OPCLASS;
    6818          18 :                     n->behavior = $9;
    6819          18 :                     n->missing_ok = true;
    6820          18 :                     n->concurrent = false;
    6821          18 :                     $$ = (Node *) n;
    6822             :                 }
    6823             :         ;
    6824             : 
    6825             : DropOpFamilyStmt:
    6826             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6827             :                 {
    6828         110 :                     DropStmt *n = makeNode(DropStmt);
    6829             : 
    6830         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6831         110 :                     n->removeType = OBJECT_OPFAMILY;
    6832         110 :                     n->behavior = $7;
    6833         110 :                     n->missing_ok = false;
    6834         110 :                     n->concurrent = false;
    6835         110 :                     $$ = (Node *) n;
    6836             :                 }
    6837             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6838             :                 {
    6839          18 :                     DropStmt *n = makeNode(DropStmt);
    6840             : 
    6841          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6842          18 :                     n->removeType = OBJECT_OPFAMILY;
    6843          18 :                     n->behavior = $9;
    6844          18 :                     n->missing_ok = true;
    6845          18 :                     n->concurrent = false;
    6846          18 :                     $$ = (Node *) n;
    6847             :                 }
    6848             :         ;
    6849             : 
    6850             : 
    6851             : /*****************************************************************************
    6852             :  *
    6853             :  *      QUERY:
    6854             :  *
    6855             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6856             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6857             :  *
    6858             :  *****************************************************************************/
    6859             : DropOwnedStmt:
    6860             :             DROP OWNED BY role_list opt_drop_behavior
    6861             :                 {
    6862         148 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6863             : 
    6864         148 :                     n->roles = $4;
    6865         148 :                     n->behavior = $5;
    6866         148 :                     $$ = (Node *) n;
    6867             :                 }
    6868             :         ;
    6869             : 
    6870             : ReassignOwnedStmt:
    6871             :             REASSIGN OWNED BY role_list TO RoleSpec
    6872             :                 {
    6873          46 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6874             : 
    6875          46 :                     n->roles = $4;
    6876          46 :                     n->newrole = $6;
    6877          46 :                     $$ = (Node *) n;
    6878             :                 }
    6879             :         ;
    6880             : 
    6881             : /*****************************************************************************
    6882             :  *
    6883             :  *      QUERY:
    6884             :  *
    6885             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6886             :  *           [ RESTRICT | CASCADE ]
    6887             :  *
    6888             :  *****************************************************************************/
    6889             : 
    6890             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6891             :                 {
    6892        1304 :                     DropStmt *n = makeNode(DropStmt);
    6893             : 
    6894        1304 :                     n->removeType = $2;
    6895        1304 :                     n->missing_ok = true;
    6896        1304 :                     n->objects = $5;
    6897        1304 :                     n->behavior = $6;
    6898        1304 :                     n->concurrent = false;
    6899        1304 :                     $$ = (Node *) n;
    6900             :                 }
    6901             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6902             :                 {
    6903       15680 :                     DropStmt *n = makeNode(DropStmt);
    6904             : 
    6905       15680 :                     n->removeType = $2;
    6906       15680 :                     n->missing_ok = false;
    6907       15680 :                     n->objects = $3;
    6908       15680 :                     n->behavior = $4;
    6909       15680 :                     n->concurrent = false;
    6910       15680 :                     $$ = (Node *) n;
    6911             :                 }
    6912             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6913             :                 {
    6914          78 :                     DropStmt *n = makeNode(DropStmt);
    6915             : 
    6916          78 :                     n->removeType = $2;
    6917          78 :                     n->missing_ok = true;
    6918          78 :                     n->objects = $5;
    6919          78 :                     n->behavior = $6;
    6920          78 :                     n->concurrent = false;
    6921          78 :                     $$ = (Node *) n;
    6922             :                 }
    6923             :             | DROP drop_type_name name_list opt_drop_behavior
    6924             :                 {
    6925        1378 :                     DropStmt *n = makeNode(DropStmt);
    6926             : 
    6927        1378 :                     n->removeType = $2;
    6928        1378 :                     n->missing_ok = false;
    6929        1378 :                     n->objects = $3;
    6930        1378 :                     n->behavior = $4;
    6931        1378 :                     n->concurrent = false;
    6932        1378 :                     $$ = (Node *) n;
    6933             :                 }
    6934             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6935             :                 {
    6936        1124 :                     DropStmt *n = makeNode(DropStmt);
    6937             : 
    6938        1124 :                     n->removeType = $2;
    6939        1124 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6940        1124 :                     n->behavior = $6;
    6941        1124 :                     n->missing_ok = false;
    6942        1124 :                     n->concurrent = false;
    6943        1124 :                     $$ = (Node *) n;
    6944             :                 }
    6945             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6946             :                 {
    6947          48 :                     DropStmt *n = makeNode(DropStmt);
    6948             : 
    6949          48 :                     n->removeType = $2;
    6950          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6951          48 :                     n->behavior = $8;
    6952          48 :                     n->missing_ok = true;
    6953          48 :                     n->concurrent = false;
    6954          48 :                     $$ = (Node *) n;
    6955             :                 }
    6956             :             | DROP TYPE_P type_name_list opt_drop_behavior
    6957             :                 {
    6958         548 :                     DropStmt *n = makeNode(DropStmt);
    6959             : 
    6960         548 :                     n->removeType = OBJECT_TYPE;
    6961         548 :                     n->missing_ok = false;
    6962         548 :                     n->objects = $3;
    6963         548 :                     n->behavior = $4;
    6964         548 :                     n->concurrent = false;
    6965         548 :                     $$ = (Node *) n;
    6966             :                 }
    6967             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    6968             :                 {
    6969          22 :                     DropStmt *n = makeNode(DropStmt);
    6970             : 
    6971          22 :                     n->removeType = OBJECT_TYPE;
    6972          22 :                     n->missing_ok = true;
    6973          22 :                     n->objects = $5;
    6974          22 :                     n->behavior = $6;
    6975          22 :                     n->concurrent = false;
    6976          22 :                     $$ = (Node *) n;
    6977             :                 }
    6978             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    6979             :                 {
    6980         440 :                     DropStmt *n = makeNode(DropStmt);
    6981             : 
    6982         440 :                     n->removeType = OBJECT_DOMAIN;
    6983         440 :                     n->missing_ok = false;
    6984         440 :                     n->objects = $3;
    6985         440 :                     n->behavior = $4;
    6986         440 :                     n->concurrent = false;
    6987         440 :                     $$ = (Node *) n;
    6988             :                 }
    6989             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    6990             :                 {
    6991          18 :                     DropStmt *n = makeNode(DropStmt);
    6992             : 
    6993          18 :                     n->removeType = OBJECT_DOMAIN;
    6994          18 :                     n->missing_ok = true;
    6995          18 :                     n->objects = $5;
    6996          18 :                     n->behavior = $6;
    6997          18 :                     n->concurrent = false;
    6998          18 :                     $$ = (Node *) n;
    6999             :                 }
    7000             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7001             :                 {
    7002         114 :                     DropStmt *n = makeNode(DropStmt);
    7003             : 
    7004         114 :                     n->removeType = OBJECT_INDEX;
    7005         114 :                     n->missing_ok = false;
    7006         114 :                     n->objects = $4;
    7007         114 :                     n->behavior = $5;
    7008         114 :                     n->concurrent = true;
    7009         114 :                     $$ = (Node *) n;
    7010             :                 }
    7011             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7012             :                 {
    7013          12 :                     DropStmt *n = makeNode(DropStmt);
    7014             : 
    7015          12 :                     n->removeType = OBJECT_INDEX;
    7016          12 :                     n->missing_ok = true;
    7017          12 :                     n->objects = $6;
    7018          12 :                     n->behavior = $7;
    7019          12 :                     n->concurrent = true;
    7020          12 :                     $$ = (Node *) n;
    7021             :                 }
    7022             :         ;
    7023             : 
    7024             : /* object types taking any_name/any_name_list */
    7025             : object_type_any_name:
    7026       14646 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7027         198 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7028         992 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7029         124 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7030         772 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7031         172 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7032          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7033          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7034         192 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7035          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7036        2438 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7037         106 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7038        2442 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7039             :         ;
    7040             : 
    7041             : /*
    7042             :  * object types taking name/name_list
    7043             :  *
    7044             :  * DROP handles some of them separately
    7045             :  */
    7046             : 
    7047             : object_type_name:
    7048         194 :             drop_type_name                          { $$ = $1; }
    7049         198 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7050          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7051          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7052           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7053             :         ;
    7054             : 
    7055             : drop_type_name:
    7056          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7057         126 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7058         144 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7059         148 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7060         144 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7061         362 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7062         550 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7063         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7064             :         ;
    7065             : 
    7066             : /* object types attached to a table */
    7067             : object_type_name_on_any_name:
    7068         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7069         268 :             | RULE                                  { $$ = OBJECT_RULE; }
    7070         792 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7071             :         ;
    7072             : 
    7073             : any_name_list:
    7074       24664 :             any_name                                { $$ = list_make1($1); }
    7075        4056 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7076             :         ;
    7077             : 
    7078       61804 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7079        8768 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7080             :         ;
    7081             : 
    7082             : attrs:      '.' attr_name
    7083      113562 :                     { $$ = list_make1(makeString($2)); }
    7084             :             | attrs '.' attr_name
    7085          64 :                     { $$ = lappend($1, makeString($3)); }
    7086             :         ;
    7087             : 
    7088             : type_name_list:
    7089        1028 :             Typename                                { $$ = list_make1($1); }
    7090          96 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7091             :         ;
    7092             : 
    7093             : /*****************************************************************************
    7094             :  *
    7095             :  *      QUERY:
    7096             :  *              truncate table relname1, relname2, ...
    7097             :  *
    7098             :  *****************************************************************************/
    7099             : 
    7100             : TruncateStmt:
    7101             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7102             :                 {
    7103        1654 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7104             : 
    7105        1654 :                     n->relations = $3;
    7106        1654 :                     n->restart_seqs = $4;
    7107        1654 :                     n->behavior = $5;
    7108        1654 :                     $$ = (Node *) n;
    7109             :                 }
    7110             :         ;
    7111             : 
    7112             : opt_restart_seqs:
    7113          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7114          24 :             | RESTART IDENTITY_P        { $$ = true; }
    7115        1606 :             | /* EMPTY */               { $$ = false; }
    7116             :         ;
    7117             : 
    7118             : /*****************************************************************************
    7119             :  *
    7120             :  * COMMENT ON <object> IS <text>
    7121             :  *
    7122             :  *****************************************************************************/
    7123             : 
    7124             : CommentStmt:
    7125             :             COMMENT ON object_type_any_name any_name IS comment_text
    7126             :                 {
    7127        5136 :                     CommentStmt *n = makeNode(CommentStmt);
    7128             : 
    7129        5136 :                     n->objtype = $3;
    7130        5136 :                     n->object = (Node *) $4;
    7131        5136 :                     n->comment = $6;
    7132        5136 :                     $$ = (Node *) n;
    7133             :                 }
    7134             :             | COMMENT ON COLUMN any_name IS comment_text
    7135             :                 {
    7136         108 :                     CommentStmt *n = makeNode(CommentStmt);
    7137             : 
    7138         108 :                     n->objtype = OBJECT_COLUMN;
    7139         108 :                     n->object = (Node *) $4;
    7140         108 :                     n->comment = $6;
    7141         108 :                     $$ = (Node *) n;
    7142             :                 }
    7143             :             | COMMENT ON object_type_name name IS comment_text
    7144             :                 {
    7145         392 :                     CommentStmt *n = makeNode(CommentStmt);
    7146             : 
    7147         392 :                     n->objtype = $3;
    7148         392 :                     n->object = (Node *) makeString($4);
    7149         392 :                     n->comment = $6;
    7150         392 :                     $$ = (Node *) n;
    7151             :                 }
    7152             :             | COMMENT ON TYPE_P Typename IS comment_text
    7153             :                 {
    7154          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7155             : 
    7156          56 :                     n->objtype = OBJECT_TYPE;
    7157          56 :                     n->object = (Node *) $4;
    7158          56 :                     n->comment = $6;
    7159          56 :                     $$ = (Node *) n;
    7160             :                 }
    7161             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7162             :                 {
    7163           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7164             : 
    7165           8 :                     n->objtype = OBJECT_DOMAIN;
    7166           8 :                     n->object = (Node *) $4;
    7167           8 :                     n->comment = $6;
    7168           8 :                     $$ = (Node *) n;
    7169             :                 }
    7170             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7171             :                 {
    7172          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7173             : 
    7174          40 :                     n->objtype = OBJECT_AGGREGATE;
    7175          40 :                     n->object = (Node *) $4;
    7176          40 :                     n->comment = $6;
    7177          40 :                     $$ = (Node *) n;
    7178             :                 }
    7179             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7180             :                 {
    7181         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7182             : 
    7183         170 :                     n->objtype = OBJECT_FUNCTION;
    7184         170 :                     n->object = (Node *) $4;
    7185         170 :                     n->comment = $6;
    7186         170 :                     $$ = (Node *) n;
    7187             :                 }
    7188             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7189             :                 {
    7190          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7191             : 
    7192          18 :                     n->objtype = OBJECT_OPERATOR;
    7193          18 :                     n->object = (Node *) $4;
    7194          18 :                     n->comment = $6;
    7195          18 :                     $$ = (Node *) n;
    7196             :                 }
    7197             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7198             :                 {
    7199         110 :                     CommentStmt *n = makeNode(CommentStmt);
    7200             : 
    7201         110 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7202         110 :                     n->object = (Node *) lappend($6, makeString($4));
    7203         110 :                     n->comment = $8;
    7204         110 :                     $$ = (Node *) n;
    7205             :                 }
    7206             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7207             :                 {
    7208          38 :                     CommentStmt *n = makeNode(CommentStmt);
    7209             : 
    7210          38 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7211             :                     /*
    7212             :                      * should use Typename not any_name in the production, but
    7213             :                      * there's a shift/reduce conflict if we do that, so fix it
    7214             :                      * up here.
    7215             :                      */
    7216          38 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7217          38 :                     n->comment = $9;
    7218          38 :                     $$ = (Node *) n;
    7219             :                 }
    7220             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7221             :                 {
    7222          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7223             : 
    7224          40 :                     n->objtype = $3;
    7225          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7226          40 :                     n->comment = $8;
    7227          40 :                     $$ = (Node *) n;
    7228             :                 }
    7229             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7230             :                 {
    7231           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7232             : 
    7233           0 :                     n->objtype = OBJECT_PROCEDURE;
    7234           0 :                     n->object = (Node *) $4;
    7235           0 :                     n->comment = $6;
    7236           0 :                     $$ = (Node *) n;
    7237             :                 }
    7238             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7239             :                 {
    7240           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7241             : 
    7242           0 :                     n->objtype = OBJECT_ROUTINE;
    7243           0 :                     n->object = (Node *) $4;
    7244           0 :                     n->comment = $6;
    7245           0 :                     $$ = (Node *) n;
    7246             :                 }
    7247             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7248             :                 {
    7249          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7250             : 
    7251          14 :                     n->objtype = OBJECT_TRANSFORM;
    7252          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7253          14 :                     n->comment = $9;
    7254          14 :                     $$ = (Node *) n;
    7255             :                 }
    7256             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7257             :                 {
    7258           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7259             : 
    7260           0 :                     n->objtype = OBJECT_OPCLASS;
    7261           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7262           0 :                     n->comment = $9;
    7263           0 :                     $$ = (Node *) n;
    7264             :                 }
    7265             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7266             :                 {
    7267           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7268             : 
    7269           0 :                     n->objtype = OBJECT_OPFAMILY;
    7270           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7271           0 :                     n->comment = $9;
    7272           0 :                     $$ = (Node *) n;
    7273             :                 }
    7274             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7275             :                 {
    7276          24 :                     CommentStmt *n = makeNode(CommentStmt);
    7277             : 
    7278          24 :                     n->objtype = OBJECT_LARGEOBJECT;
    7279          24 :                     n->object = (Node *) $5;
    7280          24 :                     n->comment = $7;
    7281          24 :                     $$ = (Node *) n;
    7282             :                 }
    7283             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7284             :                 {
    7285           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7286             : 
    7287           0 :                     n->objtype = OBJECT_CAST;
    7288           0 :                     n->object = (Node *) list_make2($5, $7);
    7289           0 :                     n->comment = $10;
    7290           0 :                     $$ = (Node *) n;
    7291             :                 }
    7292             :         ;
    7293             : 
    7294             : comment_text:
    7295        6050 :             Sconst                              { $$ = $1; }
    7296         104 :             | NULL_P                            { $$ = NULL; }
    7297             :         ;
    7298             : 
    7299             : 
    7300             : /*****************************************************************************
    7301             :  *
    7302             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7303             :  *
    7304             :  *  As with COMMENT ON, <object> can refer to various types of database
    7305             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7306             :  *
    7307             :  *****************************************************************************/
    7308             : 
    7309             : SecLabelStmt:
    7310             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7311             :             IS security_label
    7312             :                 {
    7313          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7314             : 
    7315          48 :                     n->provider = $3;
    7316          48 :                     n->objtype = $5;
    7317          48 :                     n->object = (Node *) $6;
    7318          48 :                     n->label = $8;
    7319          48 :                     $$ = (Node *) n;
    7320             :                 }
    7321             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7322             :               IS security_label
    7323             :                 {
    7324           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7325             : 
    7326           4 :                     n->provider = $3;
    7327           4 :                     n->objtype = OBJECT_COLUMN;
    7328           4 :                     n->object = (Node *) $6;
    7329           4 :                     n->label = $8;
    7330           4 :                     $$ = (Node *) n;
    7331             :                 }
    7332             :             | SECURITY LABEL opt_provider ON object_type_name name
    7333             :               IS security_label
    7334             :                 {
    7335          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7336             : 
    7337          44 :                     n->provider = $3;
    7338          44 :                     n->objtype = $5;
    7339          44 :                     n->object = (Node *) makeString($6);
    7340          44 :                     n->label = $8;
    7341          44 :                     $$ = (Node *) n;
    7342             :                 }
    7343             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7344             :               IS security_label
    7345             :                 {
    7346           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7347             : 
    7348           0 :                     n->provider = $3;
    7349           0 :                     n->objtype = OBJECT_TYPE;
    7350           0 :                     n->object = (Node *) $6;
    7351           0 :                     n->label = $8;
    7352           0 :                     $$ = (Node *) n;
    7353             :                 }
    7354             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7355             :               IS security_label
    7356             :                 {
    7357           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7358             : 
    7359           2 :                     n->provider = $3;
    7360           2 :                     n->objtype = OBJECT_DOMAIN;
    7361           2 :                     n->object = (Node *) $6;
    7362           2 :                     n->label = $8;
    7363           2 :                     $$ = (Node *) n;
    7364             :                 }
    7365             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7366             :               IS security_label
    7367             :                 {
    7368           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7369             : 
    7370           0 :                     n->provider = $3;
    7371           0 :                     n->objtype = OBJECT_AGGREGATE;
    7372           0 :                     n->object = (Node *) $6;
    7373           0 :                     n->label = $8;
    7374           0 :                     $$ = (Node *) n;
    7375             :                 }
    7376             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7377             :               IS security_label
    7378             :                 {
    7379           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7380             : 
    7381           2 :                     n->provider = $3;
    7382           2 :                     n->objtype = OBJECT_FUNCTION;
    7383           2 :                     n->object = (Node *) $6;
    7384           2 :                     n->label = $8;
    7385           2 :                     $$ = (Node *) n;
    7386             :                 }
    7387             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7388             :               IS security_label
    7389             :                 {
    7390           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7391             : 
    7392           0 :                     n->provider = $3;
    7393           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7394           0 :                     n->object = (Node *) $7;
    7395           0 :                     n->label = $9;
    7396           0 :                     $$ = (Node *) n;
    7397             :                 }
    7398             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7399             :               IS security_label
    7400             :                 {
    7401           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7402             : 
    7403           0 :                     n->provider = $3;
    7404           0 :                     n->objtype = OBJECT_PROCEDURE;
    7405           0 :                     n->object = (Node *) $6;
    7406           0 :                     n->label = $8;
    7407           0 :                     $$ = (Node *) n;
    7408             :                 }
    7409             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7410             :               IS security_label
    7411             :                 {
    7412           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7413             : 
    7414           0 :                     n->provider = $3;
    7415           0 :                     n->objtype = OBJECT_ROUTINE;
    7416           0 :                     n->object = (Node *) $6;
    7417           0 :                     n->label = $8;
    7418           0 :                     $$ = (Node *) n;
    7419             :                 }
    7420             :         ;
    7421             : 
    7422          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7423          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7424             :         ;
    7425             : 
    7426         100 : security_label: Sconst              { $$ = $1; }
    7427           0 :                 | NULL_P            { $$ = NULL; }
    7428             :         ;
    7429             : 
    7430             : /*****************************************************************************
    7431             :  *
    7432             :  *      QUERY:
    7433             :  *          fetch/move
    7434             :  *
    7435             :  *****************************************************************************/
    7436             : 
    7437             : FetchStmt:  FETCH fetch_args
    7438             :                 {
    7439        5682 :                     FetchStmt *n = (FetchStmt *) $2;
    7440             : 
    7441        5682 :                     n->ismove = false;
    7442        5682 :                     $$ = (Node *) n;
    7443             :                 }
    7444             :             | MOVE fetch_args
    7445             :                 {
    7446          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7447             : 
    7448          68 :                     n->ismove = true;
    7449          68 :                     $$ = (Node *) n;
    7450             :                 }
    7451             :         ;
    7452             : 
    7453             : fetch_args: cursor_name
    7454             :                 {
    7455         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7456             : 
    7457         266 :                     n->portalname = $1;
    7458         266 :                     n->direction = FETCH_FORWARD;
    7459         266 :                     n->howMany = 1;
    7460         266 :                     $$ = (Node *) n;
    7461             :                 }
    7462             :             | from_in cursor_name
    7463             :                 {
    7464         216 :                     FetchStmt *n = makeNode(FetchStmt);
    7465             : 
    7466         216 :                     n->portalname = $2;
    7467         216 :                     n->direction = FETCH_FORWARD;
    7468         216 :                     n->howMany = 1;
    7469         216 :                     $$ = (Node *) n;
    7470             :                 }
    7471             :             | NEXT opt_from_in cursor_name
    7472             :                 {
    7473         262 :                     FetchStmt *n = makeNode(FetchStmt);
    7474             : 
    7475         262 :                     n->portalname = $3;
    7476         262 :                     n->direction = FETCH_FORWARD;
    7477         262 :                     n->howMany = 1;
    7478         262 :                     $$ = (Node *) n;
    7479             :                 }
    7480             :             | PRIOR opt_from_in cursor_name
    7481             :                 {
    7482          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7483             : 
    7484          30 :                     n->portalname = $3;
    7485          30 :                     n->direction = FETCH_BACKWARD;
    7486          30 :                     n->howMany = 1;
    7487          30 :                     $$ = (Node *) n;
    7488             :                 }
    7489             :             | FIRST_P opt_from_in cursor_name
    7490             :                 {
    7491          24 :                     FetchStmt *n = makeNode(FetchStmt);
    7492             : 
    7493          24 :                     n->portalname = $3;
    7494          24 :                     n->direction = FETCH_ABSOLUTE;
    7495          24 :                     n->howMany = 1;
    7496          24 :                     $$ = (Node *) n;
    7497             :                 }
    7498             :             | LAST_P opt_from_in cursor_name
    7499             :                 {
    7500          18 :                     FetchStmt *n = makeNode(FetchStmt);
    7501             : 
    7502          18 :                     n->portalname = $3;
    7503          18 :                     n->direction = FETCH_ABSOLUTE;
    7504          18 :                     n->howMany = -1;
    7505          18 :                     $$ = (Node *) n;
    7506             :                 }
    7507             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7508             :                 {
    7509          88 :                     FetchStmt *n = makeNode(FetchStmt);
    7510             : 
    7511          88 :                     n->portalname = $4;
    7512          88 :                     n->direction = FETCH_ABSOLUTE;
    7513          88 :                     n->howMany = $2;
    7514          88 :                     $$ = (Node *) n;
    7515             :                 }
    7516             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7517             :                 {
    7518          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7519             : 
    7520          30 :                     n->portalname = $4;
    7521          30 :                     n->direction = FETCH_RELATIVE;
    7522          30 :                     n->howMany = $2;
    7523          30 :                     $$ = (Node *) n;
    7524             :                 }
    7525             :             | SignedIconst opt_from_in cursor_name
    7526             :                 {
    7527        4114 :                     FetchStmt *n = makeNode(FetchStmt);
    7528             : 
    7529        4114 :                     n->portalname = $3;
    7530        4114 :                     n->direction = FETCH_FORWARD;
    7531        4114 :                     n->howMany = $1;
    7532        4114 :                     $$ = (Node *) n;
    7533             :                 }
    7534             :             | ALL opt_from_in cursor_name
    7535             :                 {
    7536         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7537             : 
    7538         266 :                     n->portalname = $3;
    7539         266 :                     n->direction = FETCH_FORWARD;
    7540         266 :                     n->howMany = FETCH_ALL;
    7541         266 :                     $$ = (Node *) n;
    7542             :                 }
    7543             :             | FORWARD opt_from_in cursor_name
    7544             :                 {
    7545          28 :                     FetchStmt *n = makeNode(FetchStmt);
    7546             : 
    7547          28 :                     n->portalname = $3;
    7548          28 :                     n->direction = FETCH_FORWARD;
    7549          28 :                     n->howMany = 1;
    7550          28 :                     $$ = (Node *) n;
    7551             :                 }
    7552             :             | FORWARD SignedIconst opt_from_in cursor_name
    7553             :                 {
    7554           6 :                     FetchStmt *n = makeNode(FetchStmt);
    7555             : 
    7556           6 :                     n->portalname = $4;
    7557           6 :                     n->direction = FETCH_FORWARD;
    7558           6 :                     n->howMany = $2;
    7559           6 :                     $$ = (Node *) n;
    7560             :                 }
    7561             :             | FORWARD ALL opt_from_in cursor_name
    7562             :                 {
    7563          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7564             : 
    7565          14 :                     n->portalname = $4;
    7566          14 :                     n->direction = FETCH_FORWARD;
    7567          14 :                     n->howMany = FETCH_ALL;
    7568          14 :                     $$ = (Node *) n;
    7569             :                 }
    7570             :             | BACKWARD opt_from_in cursor_name
    7571             :                 {
    7572          78 :                     FetchStmt *n = makeNode(FetchStmt);
    7573             : 
    7574          78 :                     n->portalname = $3;
    7575          78 :                     n->direction = FETCH_BACKWARD;
    7576          78 :                     n->howMany = 1;
    7577          78 :                     $$ = (Node *) n;
    7578             :                 }
    7579             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7580             :                 {
    7581         220 :                     FetchStmt *n = makeNode(FetchStmt);
    7582             : 
    7583         220 :                     n->portalname = $4;
    7584         220 :                     n->direction = FETCH_BACKWARD;
    7585         220 :                     n->howMany = $2;
    7586         220 :                     $$ = (Node *) n;
    7587             :                 }
    7588             :             | BACKWARD ALL opt_from_in cursor_name
    7589             :                 {
    7590          90 :                     FetchStmt *n = makeNode(FetchStmt);
    7591             : 
    7592          90 :                     n->portalname = $4;
    7593          90 :                     n->direction = FETCH_BACKWARD;
    7594          90 :                     n->howMany = FETCH_ALL;
    7595          90 :                     $$ = (Node *) n;
    7596             :                 }
    7597             :         ;
    7598             : 
    7599             : from_in:    FROM
    7600             :             | IN_P
    7601             :         ;
    7602             : 
    7603             : opt_from_in:    from_in
    7604             :             | /* EMPTY */
    7605             :         ;
    7606             : 
    7607             : 
    7608             : /*****************************************************************************
    7609             :  *
    7610             :  * GRANT and REVOKE statements
    7611             :  *
    7612             :  *****************************************************************************/
    7613             : 
    7614             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7615             :             opt_grant_grant_option opt_granted_by
    7616             :                 {
    7617       10272 :                     GrantStmt *n = makeNode(GrantStmt);
    7618             : 
    7619       10272 :                     n->is_grant = true;
    7620       10272 :                     n->privileges = $2;
    7621       10272 :                     n->targtype = ($4)->targtype;
    7622       10272 :                     n->objtype = ($4)->objtype;
    7623       10272 :                     n->objects = ($4)->objs;
    7624       10272 :                     n->grantees = $6;
    7625       10272 :                     n->grant_option = $7;
    7626       10272 :                     n->grantor = $8;
    7627       10272 :                     $$ = (Node *) n;
    7628             :                 }
    7629             :         ;
    7630             : 
    7631             : RevokeStmt:
    7632             :             REVOKE privileges ON privilege_target
    7633             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7634             :                 {
    7635        9000 :                     GrantStmt *n = makeNode(GrantStmt);
    7636             : 
    7637        9000 :                     n->is_grant = false;
    7638        9000 :                     n->grant_option = false;
    7639        9000 :                     n->privileges = $2;
    7640        9000 :                     n->targtype = ($4)->targtype;
    7641        9000 :                     n->objtype = ($4)->objtype;
    7642        9000 :                     n->objects = ($4)->objs;
    7643        9000 :                     n->grantees = $6;
    7644        9000 :                     n->grantor = $7;
    7645        9000 :                     n->behavior = $8;
    7646        9000 :                     $$ = (Node *) n;
    7647             :                 }
    7648             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7649             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7650             :                 {
    7651          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7652             : 
    7653          16 :                     n->is_grant = false;
    7654          16 :                     n->grant_option = true;
    7655          16 :                     n->privileges = $5;
    7656          16 :                     n->targtype = ($7)->targtype;
    7657          16 :                     n->objtype = ($7)->objtype;
    7658          16 :                     n->objects = ($7)->objs;
    7659          16 :                     n->grantees = $9;
    7660          16 :                     n->grantor = $10;
    7661          16 :                     n->behavior = $11;
    7662          16 :                     $$ = (Node *) n;
    7663             :                 }
    7664             :         ;
    7665             : 
    7666             : 
    7667             : /*
    7668             :  * Privilege names are represented as strings; the validity of the privilege
    7669             :  * names gets checked at execution.  This is a bit annoying but we have little
    7670             :  * choice because of the syntactic conflict with lists of role names in
    7671             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7672             :  * production any reserved keywords that need to be usable as privilege names.
    7673             :  */
    7674             : 
    7675             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7676             : privileges: privilege_list
    7677       17142 :                 { $$ = $1; }
    7678             :             | ALL
    7679        2180 :                 { $$ = NIL; }
    7680             :             | ALL PRIVILEGES
    7681         120 :                 { $$ = NIL; }
    7682             :             | ALL '(' columnList ')'
    7683             :                 {
    7684          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7685             : 
    7686          18 :                     n->priv_name = NULL;
    7687          18 :                     n->cols = $3;
    7688          18 :                     $$ = list_make1(n);
    7689             :                 }
    7690             :             | ALL PRIVILEGES '(' columnList ')'
    7691             :                 {
    7692           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7693             : 
    7694           0 :                     n->priv_name = NULL;
    7695           0 :                     n->cols = $4;
    7696           0 :                     $$ = list_make1(n);
    7697             :                 }
    7698             :         ;
    7699             : 
    7700       18068 : privilege_list: privilege                           { $$ = list_make1($1); }
    7701         486 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7702             :         ;
    7703             : 
    7704             : privilege:  SELECT opt_column_list
    7705             :             {
    7706        8536 :                 AccessPriv *n = makeNode(AccessPriv);
    7707             : 
    7708        8536 :                 n->priv_name = pstrdup($1);
    7709        8536 :                 n->cols = $2;
    7710        8536 :                 $$ = n;
    7711             :             }
    7712             :         | REFERENCES opt_column_list
    7713             :             {
    7714          14 :                 AccessPriv *n = makeNode(AccessPriv);
    7715             : 
    7716          14 :                 n->priv_name = pstrdup($1);
    7717          14 :                 n->cols = $2;
    7718          14 :                 $$ = n;
    7719             :             }
    7720             :         | CREATE opt_column_list
    7721             :             {
    7722         270 :                 AccessPriv *n = makeNode(AccessPriv);
    7723             : 
    7724         270 :                 n->priv_name = pstrdup($1);
    7725         270 :                 n->cols = $2;
    7726         270 :                 $$ = n;
    7727             :             }
    7728             :         | ALTER SYSTEM_P
    7729             :             {
    7730          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7731          24 :                 n->priv_name = pstrdup("alter system");
    7732          24 :                 n->cols = NIL;
    7733          24 :                 $$ = n;
    7734             :             }
    7735             :         | ColId opt_column_list
    7736             :             {
    7737        9710 :                 AccessPriv *n = makeNode(AccessPriv);
    7738             : 
    7739        9710 :                 n->priv_name = $1;
    7740        9710 :                 n->cols = $2;
    7741        9710 :                 $$ = n;
    7742             :             }
    7743             :         ;
    7744             : 
    7745             : parameter_name_list:
    7746             :         parameter_name
    7747             :             {
    7748          74 :                 $$ = list_make1(makeString($1));
    7749             :             }
    7750             :         | parameter_name_list ',' parameter_name
    7751             :             {
    7752          50 :                 $$ = lappend($1, makeString($3));
    7753             :             }
    7754             :         ;
    7755             : 
    7756             : parameter_name:
    7757             :         ColId
    7758             :             {
    7759         124 :                 $$ = $1;
    7760             :             }
    7761             :         | parameter_name '.' ColId
    7762             :             {
    7763          30 :                 $$ = psprintf("%s.%s", $1, $3);
    7764             :             }
    7765             :         ;
    7766             : 
    7767             : 
    7768             : /* Don't bother trying to fold the first two rules into one using
    7769             :  * opt_table.  You're going to get conflicts.
    7770             :  */
    7771             : privilege_target:
    7772             :             qualified_name_list
    7773             :                 {
    7774       10172 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7775             : 
    7776       10172 :                     n->targtype = ACL_TARGET_OBJECT;
    7777       10172 :                     n->objtype = OBJECT_TABLE;
    7778       10172 :                     n->objs = $1;
    7779       10172 :                     $$ = n;
    7780             :                 }
    7781             :             | TABLE qualified_name_list
    7782             :                 {
    7783         368 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7784             : 
    7785         368 :                     n->targtype = ACL_TARGET_OBJECT;
    7786         368 :                     n->objtype = OBJECT_TABLE;
    7787         368 :                     n->objs = $2;
    7788         368 :                     $$ = n;
    7789             :                 }
    7790             :             | SEQUENCE qualified_name_list
    7791             :                 {
    7792          22 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7793             : 
    7794          22 :                     n->targtype = ACL_TARGET_OBJECT;
    7795          22 :                     n->objtype = OBJECT_SEQUENCE;
    7796          22 :                     n->objs = $2;
    7797          22 :                     $$ = n;
    7798             :                 }
    7799             :             | FOREIGN DATA_P WRAPPER name_list
    7800             :                 {
    7801          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7802             : 
    7803          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7804          92 :                     n->objtype = OBJECT_FDW;
    7805          92 :                     n->objs = $4;
    7806          92 :                     $$ = n;
    7807             :                 }
    7808             :             | FOREIGN SERVER name_list
    7809             :                 {
    7810          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7811             : 
    7812          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7813          80 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7814          80 :                     n->objs = $3;
    7815          80 :                     $$ = n;
    7816             :                 }
    7817             :             | FUNCTION function_with_argtypes_list
    7818             :                 {
    7819        7518 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7820             : 
    7821        7518 :                     n->targtype = ACL_TARGET_OBJECT;
    7822        7518 :                     n->objtype = OBJECT_FUNCTION;
    7823        7518 :                     n->objs = $2;
    7824        7518 :                     $$ = n;
    7825             :                 }
    7826             :             | PROCEDURE function_with_argtypes_list
    7827             :                 {
    7828          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7829             : 
    7830          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7831          42 :                     n->objtype = OBJECT_PROCEDURE;
    7832          42 :                     n->objs = $2;
    7833          42 :                     $$ = n;
    7834             :                 }
    7835             :             | ROUTINE function_with_argtypes_list
    7836             :                 {
    7837           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7838             : 
    7839           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7840           0 :                     n->objtype = OBJECT_ROUTINE;
    7841           0 :                     n->objs = $2;
    7842           0 :                     $$ = n;
    7843             :                 }
    7844             :             | DATABASE name_list
    7845             :                 {
    7846         306 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7847             : 
    7848         306 :                     n->targtype = ACL_TARGET_OBJECT;
    7849         306 :                     n->objtype = OBJECT_DATABASE;
    7850         306 :                     n->objs = $2;
    7851         306 :                     $$ = n;
    7852             :                 }
    7853             :             | DOMAIN_P any_name_list
    7854             :                 {
    7855          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7856             : 
    7857          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7858          26 :                     n->objtype = OBJECT_DOMAIN;
    7859          26 :                     n->objs = $2;
    7860          26 :                     $$ = n;
    7861             :                 }
    7862             :             | LANGUAGE name_list
    7863             :                 {
    7864          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7865             : 
    7866          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7867          42 :                     n->objtype = OBJECT_LANGUAGE;
    7868          42 :                     n->objs = $2;
    7869          42 :                     $$ = n;
    7870             :                 }
    7871             :             | LARGE_P OBJECT_P NumericOnly_list
    7872             :                 {
    7873          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7874             : 
    7875          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7876          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7877          80 :                     n->objs = $3;
    7878          80 :                     $$ = n;
    7879             :                 }
    7880             :             | PARAMETER parameter_name_list
    7881             :                 {
    7882          74 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7883          74 :                     n->targtype = ACL_TARGET_OBJECT;
    7884          74 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7885          74 :                     n->objs = $2;
    7886          74 :                     $$ = n;
    7887             :                 }
    7888             :             | SCHEMA name_list
    7889             :                 {
    7890         330 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7891             : 
    7892         330 :                     n->targtype = ACL_TARGET_OBJECT;
    7893         330 :                     n->objtype = OBJECT_SCHEMA;
    7894         330 :                     n->objs = $2;
    7895         330 :                     $$ = n;
    7896             :                 }
    7897             :             | TABLESPACE name_list
    7898             :                 {
    7899           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7900             : 
    7901           6 :                     n->targtype = ACL_TARGET_OBJECT;
    7902           6 :                     n->objtype = OBJECT_TABLESPACE;
    7903           6 :                     n->objs = $2;
    7904           6 :                     $$ = n;
    7905             :                 }
    7906             :             | TYPE_P any_name_list
    7907             :                 {
    7908         112 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7909             : 
    7910         112 :                     n->targtype = ACL_TARGET_OBJECT;
    7911         112 :                     n->objtype = OBJECT_TYPE;
    7912         112 :                     n->objs = $2;
    7913         112 :                     $$ = n;
    7914             :                 }
    7915             :             | ALL TABLES IN_P SCHEMA name_list
    7916             :                 {
    7917          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7918             : 
    7919          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7920          12 :                     n->objtype = OBJECT_TABLE;
    7921          12 :                     n->objs = $5;
    7922          12 :                     $$ = n;
    7923             :                 }
    7924             :             | ALL SEQUENCES IN_P SCHEMA name_list
    7925             :                 {
    7926           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7927             : 
    7928           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7929           0 :                     n->objtype = OBJECT_SEQUENCE;
    7930           0 :                     n->objs = $5;
    7931           0 :                     $$ = n;
    7932             :                 }
    7933             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    7934             :                 {
    7935           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7936             : 
    7937           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7938           6 :                     n->objtype = OBJECT_FUNCTION;
    7939           6 :                     n->objs = $5;
    7940           6 :                     $$ = n;
    7941             :                 }
    7942             :             | ALL PROCEDURES IN_P SCHEMA name_list
    7943             :                 {
    7944           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7945             : 
    7946           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7947           6 :                     n->objtype = OBJECT_PROCEDURE;
    7948           6 :                     n->objs = $5;
    7949           6 :                     $$ = n;
    7950             :                 }
    7951             :             | ALL ROUTINES IN_P SCHEMA name_list
    7952             :                 {
    7953           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7954             : 
    7955           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7956           6 :                     n->objtype = OBJECT_ROUTINE;
    7957           6 :                     n->objs = $5;
    7958           6 :                     $$ = n;
    7959             :                 }
    7960             :         ;
    7961             : 
    7962             : 
    7963             : grantee_list:
    7964       19448 :             grantee                                 { $$ = list_make1($1); }
    7965         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    7966             :         ;
    7967             : 
    7968             : grantee:
    7969       19532 :             RoleSpec                                { $$ = $1; }
    7970          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    7971             :         ;
    7972             : 
    7973             : 
    7974             : opt_grant_grant_option:
    7975          90 :             WITH GRANT OPTION { $$ = true; }
    7976       10282 :             | /*EMPTY*/ { $$ = false; }
    7977             :         ;
    7978             : 
    7979             : /*****************************************************************************
    7980             :  *
    7981             :  * GRANT and REVOKE ROLE statements
    7982             :  *
    7983             :  *****************************************************************************/
    7984             : 
    7985             : GrantRoleStmt:
    7986             :             GRANT privilege_list TO role_list opt_granted_by
    7987             :                 {
    7988         592 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7989             : 
    7990         592 :                     n->is_grant = true;
    7991         592 :                     n->granted_roles = $2;
    7992         592 :                     n->grantee_roles = $4;
    7993         592 :                     n->opt = NIL;
    7994         592 :                     n->grantor = $5;
    7995         592 :                     $$ = (Node *) n;
    7996             :                 }
    7997             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    7998             :                 {
    7999         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8000             : 
    8001         178 :                     n->is_grant = true;
    8002         178 :                     n->granted_roles = $2;
    8003         178 :                     n->grantee_roles = $4;
    8004         178 :                     n->opt = $6;
    8005         178 :                     n->grantor = $7;
    8006         178 :                     $$ = (Node *) n;
    8007             :                 }
    8008             :         ;
    8009             : 
    8010             : RevokeRoleStmt:
    8011             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8012             :                 {
    8013          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8014             : 
    8015          90 :                     n->is_grant = false;
    8016          90 :                     n->opt = NIL;
    8017          90 :                     n->granted_roles = $2;
    8018          90 :                     n->grantee_roles = $4;
    8019          90 :                     n->grantor = $5;
    8020          90 :                     n->behavior = $6;
    8021          90 :                     $$ = (Node *) n;
    8022             :                 }
    8023             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8024             :                 {
    8025          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8026             :                     DefElem *opt;
    8027             : 
    8028          66 :                     opt = makeDefElem(pstrdup($2),
    8029          66 :                                       (Node *) makeBoolean(false), @2);
    8030          66 :                     n->is_grant = false;
    8031          66 :                     n->opt = list_make1(opt);
    8032          66 :                     n->granted_roles = $5;
    8033          66 :                     n->grantee_roles = $7;
    8034          66 :                     n->grantor = $8;
    8035          66 :                     n->behavior = $9;
    8036          66 :                     $$ = (Node *) n;
    8037             :                 }
    8038             :         ;
    8039             : 
    8040             : grant_role_opt_list:
    8041         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8042         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8043             :         ;
    8044             : 
    8045             : grant_role_opt:
    8046             :         ColLabel grant_role_opt_value
    8047             :             {
    8048         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8049             :             }
    8050             :         ;
    8051             : 
    8052             : grant_role_opt_value:
    8053          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8054         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8055         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8056             :         ;
    8057             : 
    8058         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8059       20076 :             | /*EMPTY*/                                 { $$ = NULL; }
    8060             :         ;
    8061             : 
    8062             : /*****************************************************************************
    8063             :  *
    8064             :  * ALTER DEFAULT PRIVILEGES statement
    8065             :  *
    8066             :  *****************************************************************************/
    8067             : 
    8068             : AlterDefaultPrivilegesStmt:
    8069             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8070             :                 {
    8071         160 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8072             : 
    8073         160 :                     n->options = $4;
    8074         160 :                     n->action = (GrantStmt *) $5;
    8075         160 :                     $$ = (Node *) n;
    8076             :                 }
    8077             :         ;
    8078             : 
    8079             : DefACLOptionList:
    8080         122 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8081         160 :             | /* EMPTY */                           { $$ = NIL; }
    8082             :         ;
    8083             : 
    8084             : DefACLOption:
    8085             :             IN_P SCHEMA name_list
    8086             :                 {
    8087          54 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8088             :                 }
    8089             :             | FOR ROLE role_list
    8090             :                 {
    8091          68 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8092             :                 }
    8093             :             | FOR USER role_list
    8094             :                 {
    8095           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8096             :                 }
    8097             :         ;
    8098             : 
    8099             : /*
    8100             :  * This should match GRANT/REVOKE, except that individual target objects
    8101             :  * are not mentioned and we only allow a subset of object types.
    8102             :  */
    8103             : DefACLAction:
    8104             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8105             :             opt_grant_grant_option
    8106             :                 {
    8107         100 :                     GrantStmt *n = makeNode(GrantStmt);
    8108             : 
    8109         100 :                     n->is_grant = true;
    8110         100 :                     n->privileges = $2;
    8111         100 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8112         100 :                     n->objtype = $4;
    8113         100 :                     n->objects = NIL;
    8114         100 :                     n->grantees = $6;
    8115         100 :                     n->grant_option = $7;
    8116         100 :                     $$ = (Node *) n;
    8117             :                 }
    8118             :             | REVOKE privileges ON defacl_privilege_target
    8119             :             FROM grantee_list opt_drop_behavior
    8120             :                 {
    8121          60 :                     GrantStmt *n = makeNode(GrantStmt);
    8122             : 
    8123          60 :                     n->is_grant = false;
    8124          60 :                     n->grant_option = false;
    8125          60 :                     n->privileges = $2;
    8126          60 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8127          60 :                     n->objtype = $4;
    8128          60 :                     n->objects = NIL;
    8129          60 :                     n->grantees = $6;
    8130          60 :                     n->behavior = $7;
    8131          60 :                     $$ = (Node *) n;
    8132             :                 }
    8133             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8134             :             FROM grantee_list opt_drop_behavior
    8135             :                 {
    8136           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8137             : 
    8138           0 :                     n->is_grant = false;
    8139           0 :                     n->grant_option = true;
    8140           0 :                     n->privileges = $5;
    8141           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8142           0 :                     n->objtype = $7;
    8143           0 :                     n->objects = NIL;
    8144           0 :                     n->grantees = $9;
    8145           0 :                     n->behavior = $10;
    8146           0 :                     $$ = (Node *) n;
    8147             :                 }
    8148             :         ;
    8149             : 
    8150             : defacl_privilege_target:
    8151          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8152          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8153           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8154           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8155          18 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8156          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8157             :         ;
    8158             : 
    8159             : 
    8160             : /*****************************************************************************
    8161             :  *
    8162             :  *      QUERY: CREATE INDEX
    8163             :  *
    8164             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8165             :  * willing to make TABLESPACE a fully reserved word.
    8166             :  *****************************************************************************/
    8167             : 
    8168             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8169             :             ON relation_expr access_method_clause '(' index_params ')'
    8170             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8171             :                 {
    8172        6476 :                     IndexStmt *n = makeNode(IndexStmt);
    8173             : 
    8174        6476 :                     n->unique = $2;
    8175        6476 :                     n->concurrent = $4;
    8176        6476 :                     n->idxname = $5;
    8177        6476 :                     n->relation = $7;
    8178        6476 :                     n->accessMethod = $8;
    8179        6476 :                     n->indexParams = $10;
    8180        6476 :                     n->indexIncludingParams = $12;
    8181        6476 :                     n->nulls_not_distinct = !$13;
    8182        6476 :                     n->options = $14;
    8183        6476 :                     n->tableSpace = $15;
    8184        6476 :                     n->whereClause = $16;
    8185        6476 :                     n->excludeOpNames = NIL;
    8186        6476 :                     n->idxcomment = NULL;
    8187        6476 :                     n->indexOid = InvalidOid;
    8188        6476 :                     n->oldNumber = InvalidRelFileNumber;
    8189        6476 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8190        6476 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8191        6476 :                     n->primary = false;
    8192        6476 :                     n->isconstraint = false;
    8193        6476 :                     n->deferrable = false;
    8194        6476 :                     n->initdeferred = false;
    8195        6476 :                     n->transformed = false;
    8196        6476 :                     n->if_not_exists = false;
    8197        6476 :                     n->reset_default_tblspc = false;
    8198        6476 :                     $$ = (Node *) n;
    8199             :                 }
    8200             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8201             :             ON relation_expr access_method_clause '(' index_params ')'
    8202             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8203             :                 {
    8204          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8205             : 
    8206          18 :                     n->unique = $2;
    8207          18 :                     n->concurrent = $4;
    8208          18 :                     n->idxname = $8;
    8209          18 :                     n->relation = $10;
    8210          18 :                     n->accessMethod = $11;
    8211          18 :                     n->indexParams = $13;
    8212          18 :                     n->indexIncludingParams = $15;
    8213          18 :                     n->nulls_not_distinct = !$16;
    8214          18 :                     n->options = $17;
    8215          18 :                     n->tableSpace = $18;
    8216          18 :                     n->whereClause = $19;
    8217          18 :                     n->excludeOpNames = NIL;
    8218          18 :                     n->idxcomment = NULL;
    8219          18 :                     n->indexOid = InvalidOid;
    8220          18 :                     n->oldNumber = InvalidRelFileNumber;
    8221          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8222          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8223          18 :                     n->primary = false;
    8224          18 :                     n->isconstraint = false;
    8225          18 :                     n->deferrable = false;
    8226          18 :                     n->initdeferred = false;
    8227          18 :                     n->transformed = false;
    8228          18 :                     n->if_not_exists = true;
    8229          18 :                     n->reset_default_tblspc = false;
    8230          18 :                     $$ = (Node *) n;
    8231             :                 }
    8232             :         ;
    8233             : 
    8234             : opt_unique:
    8235        1298 :             UNIQUE                                  { $$ = true; }
    8236        5202 :             | /*EMPTY*/                             { $$ = false; }
    8237             :         ;
    8238             : 
    8239             : access_method_clause:
    8240        2928 :             USING name                              { $$ = $2; }
    8241        3800 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8242             :         ;
    8243             : 
    8244        7924 : index_params:   index_elem                          { $$ = list_make1($1); }
    8245        2152 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8246             :         ;
    8247             : 
    8248             : 
    8249             : index_elem_options:
    8250             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8251             :         {
    8252       10658 :             $$ = makeNode(IndexElem);
    8253       10658 :             $$->name = NULL;
    8254       10658 :             $$->expr = NULL;
    8255       10658 :             $$->indexcolname = NULL;
    8256       10658 :             $$->collation = $1;
    8257       10658 :             $$->opclass = $2;
    8258       10658 :             $$->opclassopts = NIL;
    8259       10658 :             $$->ordering = $3;
    8260       10658 :             $$->nulls_ordering = $4;
    8261             :         }
    8262             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8263             :         {
    8264         142 :             $$ = makeNode(IndexElem);
    8265         142 :             $$->name = NULL;
    8266         142 :             $$->expr = NULL;
    8267         142 :             $$->indexcolname = NULL;
    8268         142 :             $$->collation = $1;
    8269         142 :             $$->opclass = $2;
    8270         142 :             $$->opclassopts = $3;
    8271         142 :             $$->ordering = $4;
    8272         142 :             $$->nulls_ordering = $5;
    8273             :         }
    8274             :     ;
    8275             : 
    8276             : /*
    8277             :  * Index attributes can be either simple column references, or arbitrary
    8278             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8279             :  * an expression that's just a function call to be written without parens.
    8280             :  */
    8281             : index_elem: ColId index_elem_options
    8282             :                 {
    8283        9714 :                     $$ = $2;
    8284        9714 :                     $$->name = $1;
    8285             :                 }
    8286             :             | func_expr_windowless index_elem_options
    8287             :                 {
    8288         608 :                     $$ = $2;
    8289         608 :                     $$->expr = $1;
    8290             :                 }
    8291             :             | '(' a_expr ')' index_elem_options
    8292             :                 {
    8293         478 :                     $$ = $4;
    8294         478 :                     $$->expr = $2;
    8295             :                 }
    8296             :         ;
    8297             : 
    8298         218 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8299        6276 :              |      /* EMPTY */                     { $$ = NIL; }
    8300             :         ;
    8301             : 
    8302         218 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8303         166 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8304             :         ;
    8305             : 
    8306         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8307       15970 :             | /*EMPTY*/                             { $$ = NIL; }
    8308             :         ;
    8309             : 
    8310             : 
    8311        1776 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8312        2934 :             | DESC                          { $$ = SORTBY_DESC; }
    8313      102334 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8314             :         ;
    8315             : 
    8316         346 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8317        1698 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8318      105220 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8319             :         ;
    8320             : 
    8321             : 
    8322             : /*****************************************************************************
    8323             :  *
    8324             :  *      QUERY:
    8325             :  *              create [or replace] function <fname>
    8326             :  *                      [(<type-1> { , <type-n>})]
    8327             :  *                      returns <type-r>
    8328             :  *                      as <filename or code in language as appropriate>
    8329             :  *                      language <lang> [with parameters]
    8330             :  *
    8331             :  *****************************************************************************/
    8332             : 
    8333             : CreateFunctionStmt:
    8334             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8335             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8336             :                 {
    8337       21668 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8338             : 
    8339       21668 :                     n->is_procedure = false;
    8340       21668 :                     n->replace = $2;
    8341       21668 :                     n->funcname = $4;
    8342       21668 :                     n->parameters = $5;
    8343       21668 :                     n->returnType = $7;
    8344       21668 :                     n->options = $8;
    8345       21668 :                     n->sql_body = $9;
    8346       21668 :                     $$ = (Node *) n;
    8347             :                 }
    8348             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8349             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8350             :                 {
    8351         188 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8352             : 
    8353         188 :                     n->is_procedure = false;
    8354         188 :                     n->replace = $2;
    8355         188 :                     n->funcname = $4;
    8356         188 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8357         188 :                     n->returnType = TableFuncTypeName($9);
    8358         188 :                     n->returnType->location = @7;
    8359         188 :                     n->options = $11;
    8360         188 :                     n->sql_body = $12;
    8361         188 :                     $$ = (Node *) n;
    8362             :                 }
    8363             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8364             :               opt_createfunc_opt_list opt_routine_body
    8365             :                 {
    8366         478 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8367             : 
    8368         478 :                     n->is_procedure = false;
    8369         478 :                     n->replace = $2;
    8370         478 :                     n->funcname = $4;
    8371         478 :                     n->parameters = $5;
    8372         478 :                     n->returnType = NULL;
    8373         478 :                     n->options = $6;
    8374         478 :                     n->sql_body = $7;
    8375         478 :                     $$ = (Node *) n;
    8376             :                 }
    8377             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8378             :               opt_createfunc_opt_list opt_routine_body
    8379             :                 {
    8380         368 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8381             : 
    8382         368 :                     n->is_procedure = true;
    8383         368 :                     n->replace = $2;
    8384         368 :                     n->funcname = $4;
    8385         368 :                     n->parameters = $5;
    8386         368 :                     n->returnType = NULL;
    8387         368 :                     n->options = $6;
    8388         368 :                     n->sql_body = $7;
    8389         368 :                     $$ = (Node *) n;
    8390             :                 }
    8391             :         ;
    8392             : 
    8393             : opt_or_replace:
    8394        9154 :             OR REPLACE                              { $$ = true; }
    8395       18952 :             | /*EMPTY*/                             { $$ = false; }
    8396             :         ;
    8397             : 
    8398        9392 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8399        4938 :             | '(' ')'                               { $$ = NIL; }
    8400             :         ;
    8401             : 
    8402             : func_args_list:
    8403        9392 :             func_arg                                { $$ = list_make1($1); }
    8404        7830 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8405             :         ;
    8406             : 
    8407             : function_with_argtypes_list:
    8408       11198 :             function_with_argtypes                  { $$ = list_make1($1); }
    8409             :             | function_with_argtypes_list ',' function_with_argtypes
    8410          84 :                                                     { $$ = lappend($1, $3); }
    8411             :         ;
    8412             : 
    8413             : function_with_argtypes:
    8414             :             func_name func_args
    8415             :                 {
    8416       14330 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8417             : 
    8418       14330 :                     n->objname = $1;
    8419       14330 :                     n->objargs = extractArgTypes($2);
    8420       14330 :                     n->objfuncargs = $2;
    8421       14330 :                     $$ = n;
    8422             :                 }
    8423             :             /*
    8424             :              * Because of reduce/reduce conflicts, we can't use func_name
    8425             :              * below, but we can write it out the long way, which actually
    8426             :              * allows more cases.
    8427             :              */
    8428             :             | type_func_name_keyword
    8429             :                 {
    8430           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8431             : 
    8432           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8433           0 :                     n->args_unspecified = true;
    8434           0 :                     $$ = n;
    8435             :                 }
    8436             :             | ColId
    8437             :                 {
    8438         340 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8439             : 
    8440         340 :                     n->objname = list_make1(makeString($1));
    8441         340 :                     n->args_unspecified = true;
    8442         340 :                     $$ = n;
    8443             :                 }
    8444             :             | ColId indirection
    8445             :                 {
    8446          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8447             : 
    8448          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8449             :                                                   yyscanner);
    8450          28 :                     n->args_unspecified = true;
    8451          28 :                     $$ = n;
    8452             :                 }
    8453             :         ;
    8454             : 
    8455             : /*
    8456             :  * func_args_with_defaults is separate because we only want to accept
    8457             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8458             :  */
    8459             : func_args_with_defaults:
    8460       18348 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8461        4354 :         | '(' ')'                                   { $$ = NIL; }
    8462             :         ;
    8463             : 
    8464             : func_args_with_defaults_list:
    8465       18348 :         func_arg_with_default                       { $$ = list_make1($1); }
    8466             :         | func_args_with_defaults_list ',' func_arg_with_default
    8467       31938 :                                                     { $$ = lappend($1, $3); }
    8468             :         ;
    8469             : 
    8470             : /*
    8471             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8472             :  * param_name first; accept both since it's likely people will try both
    8473             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8474             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8475             :  *
    8476             :  * We can catch over-specified arguments here if we want to,
    8477             :  * but for now better to silently swallow typmod, etc.
    8478             :  * - thomas 2000-03-22
    8479             :  */
    8480             : func_arg:
    8481             :             arg_class param_name func_type
    8482             :                 {
    8483       14670 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8484             : 
    8485       14670 :                     n->name = $2;
    8486       14670 :                     n->argType = $3;
    8487       14670 :                     n->mode = $1;
    8488       14670 :                     n->defexpr = NULL;
    8489       14670 :                     n->location = @1;
    8490       14670 :                     $$ = n;
    8491             :                 }
    8492             :             | param_name arg_class func_type
    8493             :                 {
    8494         412 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8495             : 
    8496         412 :                     n->name = $1;
    8497         412 :                     n->argType = $3;
    8498         412 :                     n->mode = $2;
    8499         412 :                     n->defexpr = NULL;
    8500         412 :                     n->location = @1;
    8501         412 :                     $$ = n;
    8502             :                 }
    8503             :             | param_name func_type
    8504             :                 {
    8505       15586 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8506             : 
    8507       15586 :                     n->name = $1;
    8508       15586 :                     n->argType = $2;
    8509       15586 :                     n->mode = FUNC_PARAM_DEFAULT;
    8510       15586 :                     n->defexpr = NULL;
    8511       15586 :                     n->location = @1;
    8512       15586 :                     $$ = n;
    8513             :                 }
    8514             :             | arg_class func_type
    8515             :                 {
    8516         314 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8517             : 
    8518         314 :                     n->name = NULL;
    8519         314 :                     n->argType = $2;
    8520         314 :                     n->mode = $1;
    8521         314 :                     n->defexpr = NULL;
    8522         314 :                     n->location = @1;
    8523         314 :                     $$ = n;
    8524             :                 }
    8525             :             | func_type
    8526             :                 {
    8527       37426 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8528             : 
    8529       37426 :                     n->name = NULL;
    8530       37426 :                     n->argType = $1;
    8531       37426 :                     n->mode = FUNC_PARAM_DEFAULT;
    8532       37426 :                     n->defexpr = NULL;
    8533       37426 :                     n->location = @1;
    8534       37426 :                     $$ = n;
    8535             :                 }
    8536             :         ;
    8537             : 
    8538             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8539        3542 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8540       11130 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8541         198 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8542           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8543         526 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8544             :         ;
    8545             : 
    8546             : /*
    8547             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8548             :  */
    8549             : param_name: type_function_name
    8550             :         ;
    8551             : 
    8552             : func_return:
    8553             :             func_type
    8554             :                 {
    8555             :                     /* We can catch over-specified results here if we want to,
    8556             :                      * but for now better to silently swallow typmod, etc.
    8557             :                      * - thomas 2000-03-22
    8558             :                      */
    8559       21668 :                     $$ = $1;
    8560             :                 }
    8561             :         ;
    8562             : 
    8563             : /*
    8564             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8565             :  * but that causes reduce/reduce conflicts.  type_function_name
    8566             :  * is next best choice.
    8567             :  */
    8568      110068 : func_type:  Typename                                { $$ = $1; }
    8569             :             | type_function_name attrs '%' TYPE_P
    8570             :                 {
    8571          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8572          18 :                     $$->pct_type = true;
    8573          18 :                     $$->location = @1;
    8574             :                 }
    8575             :             | SETOF type_function_name attrs '%' TYPE_P
    8576             :                 {
    8577           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8578           6 :                     $$->pct_type = true;
    8579           6 :                     $$->setof = true;
    8580           6 :                     $$->location = @2;
    8581             :                 }
    8582             :         ;
    8583             : 
    8584             : func_arg_with_default:
    8585             :         func_arg
    8586             :                 {
    8587       43456 :                     $$ = $1;
    8588             :                 }
    8589             :         | func_arg DEFAULT a_expr
    8590             :                 {
    8591        6634 :                     $$ = $1;
    8592        6634 :                     $$->defexpr = $3;
    8593             :                 }
    8594             :         | func_arg '=' a_expr
    8595             :                 {
    8596         196 :                     $$ = $1;
    8597         196 :                     $$->defexpr = $3;
    8598             :                 }
    8599             :         ;
    8600             : 
    8601             : /* Aggregate args can be most things that function args can be */
    8602             : aggr_arg:   func_arg
    8603             :                 {
    8604         900 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8605          60 :                           $1->mode == FUNC_PARAM_IN ||
    8606          60 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8607           0 :                         ereport(ERROR,
    8608             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8609             :                                  errmsg("aggregates cannot have output arguments"),
    8610             :                                  parser_errposition(@1)));
    8611         900 :                     $$ = $1;
    8612             :                 }
    8613             :         ;
    8614             : 
    8615             : /*
    8616             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8617             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8618             :  *
    8619             :  * (*)                                  - normal agg with no args
    8620             :  * (aggr_arg,...)                       - normal agg with args
    8621             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8622             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8623             :  *
    8624             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8625             :  *
    8626             :  * An additional restriction is that if the direct-args list ends in a
    8627             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8628             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8629             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8630             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8631             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8632             :  * in cases such as DROP AGGREGATE.
    8633             :  *
    8634             :  * The return value of this production is a two-element list, in which the
    8635             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8636             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8637             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8638             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8639             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8640             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8641             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8642             :  * sublist.
    8643             :  */
    8644             : aggr_args:  '(' '*' ')'
    8645             :                 {
    8646         136 :                     $$ = list_make2(NIL, makeInteger(-1));
    8647             :                 }
    8648             :             | '(' aggr_args_list ')'
    8649             :                 {
    8650         732 :                     $$ = list_make2($2, makeInteger(-1));
    8651             :                 }
    8652             :             | '(' ORDER BY aggr_args_list ')'
    8653             :                 {
    8654           6 :                     $$ = list_make2($4, makeInteger(0));
    8655             :                 }
    8656             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8657             :                 {
    8658             :                     /* this is the only case requiring consistency checking */
    8659          32 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8660             :                 }
    8661             :         ;
    8662             : 
    8663             : aggr_args_list:
    8664         802 :             aggr_arg                                { $$ = list_make1($1); }
    8665          98 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8666             :         ;
    8667             : 
    8668             : aggregate_with_argtypes:
    8669             :             func_name aggr_args
    8670             :                 {
    8671         362 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8672             : 
    8673         362 :                     n->objname = $1;
    8674         362 :                     n->objargs = extractAggrArgTypes($2);
    8675         362 :                     n->objfuncargs = (List *) linitial($2);
    8676         362 :                     $$ = n;
    8677             :                 }
    8678             :         ;
    8679             : 
    8680             : aggregate_with_argtypes_list:
    8681         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8682             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8683           0 :                                                     { $$ = lappend($1, $3); }
    8684             :         ;
    8685             : 
    8686             : opt_createfunc_opt_list:
    8687             :             createfunc_opt_list
    8688          48 :             | /*EMPTY*/ { $$ = NIL; }
    8689             :     ;
    8690             : 
    8691             : createfunc_opt_list:
    8692             :             /* Must be at least one to prevent conflict */
    8693       22654 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8694       58930 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8695             :     ;
    8696             : 
    8697             : /*
    8698             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8699             :  */
    8700             : common_func_opt_item:
    8701             :             CALLED ON NULL_P INPUT_P
    8702             :                 {
    8703         510 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8704             :                 }
    8705             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8706             :                 {
    8707         792 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8708             :                 }
    8709             :             | STRICT_P
    8710             :                 {
    8711       11442 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8712             :                 }
    8713             :             | IMMUTABLE
    8714             :                 {
    8715        8588 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8716             :                 }
    8717             :             | STABLE
    8718             :                 {
    8719        2108 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8720             :                 }
    8721             :             | VOLATILE
    8722             :                 {
    8723        1674 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8724             :                 }
    8725             :             | EXTERNAL SECURITY DEFINER
    8726             :                 {
    8727           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8728             :                 }
    8729             :             | EXTERNAL SECURITY INVOKER
    8730             :                 {
    8731           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8732             :                 }
    8733             :             | SECURITY DEFINER
    8734             :                 {
    8735          54 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8736             :                 }
    8737             :             | SECURITY INVOKER
    8738             :                 {
    8739          18 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8740             :                 }
    8741             :             | LEAKPROOF
    8742             :                 {
    8743          46 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8744             :                 }
    8745             :             | NOT LEAKPROOF
    8746             :                 {
    8747          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8748             :                 }
    8749             :             | COST NumericOnly
    8750             :                 {
    8751        3908 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8752             :                 }
    8753             :             | ROWS NumericOnly
    8754             :                 {
    8755         540 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8756             :                 }
    8757             :             | SUPPORT any_name
    8758             :                 {
    8759         104 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8760             :                 }
    8761             :             | FunctionSetResetClause
    8762             :                 {
    8763             :                     /* we abuse the normal content of a DefElem here */
    8764         146 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8765             :                 }
    8766             :             | PARALLEL ColId
    8767             :                 {
    8768       11944 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8769             :                 }
    8770             :         ;
    8771             : 
    8772             : createfunc_opt_item:
    8773             :             AS func_as
    8774             :                 {
    8775       17594 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8776             :                 }
    8777             :             | LANGUAGE NonReservedWord_or_Sconst
    8778             :                 {
    8779       22634 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8780             :                 }
    8781             :             | TRANSFORM transform_type_list
    8782             :                 {
    8783         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8784             :                 }
    8785             :             | WINDOW
    8786             :                 {
    8787          20 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8788             :                 }
    8789             :             | common_func_opt_item
    8790             :                 {
    8791       41218 :                     $$ = $1;
    8792             :                 }
    8793             :         ;
    8794             : 
    8795       14724 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8796             :             | Sconst ',' Sconst
    8797             :                 {
    8798        2870 :                     $$ = list_make2(makeString($1), makeString($3));
    8799             :                 }
    8800             :         ;
    8801             : 
    8802             : ReturnStmt: RETURN a_expr
    8803             :                 {
    8804        4388 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8805             : 
    8806        4388 :                     r->returnval = (Node *) $2;
    8807        4388 :                     $$ = (Node *) r;
    8808             :                 }
    8809             :         ;
    8810             : 
    8811             : opt_routine_body:
    8812             :             ReturnStmt
    8813             :                 {
    8814        4382 :                     $$ = $1;
    8815             :                 }
    8816             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8817             :                 {
    8818             :                     /*
    8819             :                      * A compound statement is stored as a single-item list
    8820             :                      * containing the list of statements as its member.  That
    8821             :                      * way, the parse analysis code can tell apart an empty
    8822             :                      * body from no body at all.
    8823             :                      */
    8824         732 :                     $$ = (Node *) list_make1($3);
    8825             :                 }
    8826             :             | /*EMPTY*/
    8827             :                 {
    8828       17588 :                     $$ = NULL;
    8829             :                 }
    8830             :         ;
    8831             : 
    8832             : routine_body_stmt_list:
    8833             :             routine_body_stmt_list routine_body_stmt ';'
    8834             :                 {
    8835             :                     /* As in stmtmulti, discard empty statements */
    8836         748 :                     if ($2 != NULL)
    8837         730 :                         $$ = lappend($1, $2);
    8838             :                     else
    8839          18 :                         $$ = $1;
    8840             :                 }
    8841             :             | /*EMPTY*/
    8842             :                 {
    8843         732 :                     $$ = NIL;
    8844             :                 }
    8845             :         ;
    8846             : 
    8847             : routine_body_stmt:
    8848             :             stmt
    8849             :             | ReturnStmt
    8850             :         ;
    8851             : 
    8852             : transform_type_list:
    8853         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8854           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8855             :         ;
    8856             : 
    8857             : opt_definition:
    8858         600 :             WITH definition                         { $$ = $2; }
    8859        9904 :             | /*EMPTY*/                             { $$ = NIL; }
    8860             :         ;
    8861             : 
    8862             : table_func_column:  param_name func_type
    8863             :                 {
    8864         442 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8865             : 
    8866         442 :                     n->name = $1;
    8867         442 :                     n->argType = $2;
    8868         442 :                     n->mode = FUNC_PARAM_TABLE;
    8869         442 :                     n->defexpr = NULL;
    8870         442 :                     n->location = @1;
    8871         442 :                     $$ = n;
    8872             :                 }
    8873             :         ;
    8874             : 
    8875             : table_func_column_list:
    8876             :             table_func_column
    8877             :                 {
    8878         188 :                     $$ = list_make1($1);
    8879             :                 }
    8880             :             | table_func_column_list ',' table_func_column
    8881             :                 {
    8882         254 :                     $$ = lappend($1, $3);
    8883             :                 }
    8884             :         ;
    8885             : 
    8886             : /*****************************************************************************
    8887             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8888             :  *
    8889             :  * RENAME and OWNER subcommands are already provided by the generic
    8890             :  * ALTER infrastructure, here we just specify alterations that can
    8891             :  * only be applied to functions.
    8892             :  *
    8893             :  *****************************************************************************/
    8894             : AlterFunctionStmt:
    8895             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8896             :                 {
    8897         650 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8898             : 
    8899         650 :                     n->objtype = OBJECT_FUNCTION;
    8900         650 :                     n->func = $3;
    8901         650 :                     n->actions = $4;
    8902         650 :                     $$ = (Node *) n;
    8903             :                 }
    8904             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8905             :                 {
    8906          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8907             : 
    8908          18 :                     n->objtype = OBJECT_PROCEDURE;
    8909          18 :                     n->func = $3;
    8910          18 :                     n->actions = $4;
    8911          18 :                     $$ = (Node *) n;
    8912             :                 }
    8913             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8914             :                 {
    8915           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8916             : 
    8917           0 :                     n->objtype = OBJECT_ROUTINE;
    8918           0 :                     n->func = $3;
    8919           0 :                     n->actions = $4;
    8920           0 :                     $$ = (Node *) n;
    8921             :                 }
    8922             :         ;
    8923             : 
    8924             : alterfunc_opt_list:
    8925             :             /* At least one option must be specified */
    8926         668 :             common_func_opt_item                    { $$ = list_make1($1); }
    8927           0 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    8928             :         ;
    8929             : 
    8930             : /* Ignored, merely for SQL compliance */
    8931             : opt_restrict:
    8932             :             RESTRICT
    8933             :             | /* EMPTY */
    8934             :         ;
    8935             : 
    8936             : 
    8937             : /*****************************************************************************
    8938             :  *
    8939             :  *      QUERY:
    8940             :  *
    8941             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8942             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8943             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8944             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    8945             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    8946             :  *
    8947             :  *****************************************************************************/
    8948             : 
    8949             : RemoveFuncStmt:
    8950             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    8951             :                 {
    8952        3216 :                     DropStmt *n = makeNode(DropStmt);
    8953             : 
    8954        3216 :                     n->removeType = OBJECT_FUNCTION;
    8955        3216 :                     n->objects = $3;
    8956        3216 :                     n->behavior = $4;
    8957        3216 :                     n->missing_ok = false;
    8958        3216 :                     n->concurrent = false;
    8959        3216 :                     $$ = (Node *) n;
    8960             :                 }
    8961             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8962             :                 {
    8963         260 :                     DropStmt *n = makeNode(DropStmt);
    8964             : 
    8965         260 :                     n->removeType = OBJECT_FUNCTION;
    8966         260 :                     n->objects = $5;
    8967         260 :                     n->behavior = $6;
    8968         260 :                     n->missing_ok = true;
    8969         260 :                     n->concurrent = false;
    8970         260 :                     $$ = (Node *) n;
    8971             :                 }
    8972             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    8973             :                 {
    8974         138 :                     DropStmt *n = makeNode(DropStmt);
    8975             : 
    8976         138 :                     n->removeType = OBJECT_PROCEDURE;
    8977         138 :                     n->objects = $3;
    8978         138 :                     n->behavior = $4;
    8979         138 :                     n->missing_ok = false;
    8980         138 :                     n->concurrent = false;
    8981         138 :                     $$ = (Node *) n;
    8982             :                 }
    8983             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8984             :                 {
    8985           6 :                     DropStmt *n = makeNode(DropStmt);
    8986             : 
    8987           6 :                     n->removeType = OBJECT_PROCEDURE;
    8988           6 :                     n->objects = $5;
    8989           6 :                     n->behavior = $6;
    8990           6 :                     n->missing_ok = true;
    8991           6 :                     n->concurrent = false;
    8992           6 :                     $$ = (Node *) n;
    8993             :                 }
    8994             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    8995             :                 {
    8996          12 :                     DropStmt *n = makeNode(DropStmt);
    8997             : 
    8998          12 :                     n->removeType = OBJECT_ROUTINE;
    8999          12 :                     n->objects = $3;
    9000          12 :                     n->behavior = $4;
    9001          12 :                     n->missing_ok = false;
    9002          12 :                     n->concurrent = false;
    9003          12 :                     $$ = (Node *) n;
    9004             :                 }
    9005             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9006             :                 {
    9007           6 :                     DropStmt *n = makeNode(DropStmt);
    9008             : 
    9009           6 :                     n->removeType = OBJECT_ROUTINE;
    9010           6 :                     n->objects = $5;
    9011           6 :                     n->behavior = $6;
    9012           6 :                     n->missing_ok = true;
    9013           6 :                     n->concurrent = false;
    9014           6 :                     $$ = (Node *) n;
    9015             :                 }
    9016             :         ;
    9017             : 
    9018             : RemoveAggrStmt:
    9019             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9020             :                 {
    9021          74 :                     DropStmt *n = makeNode(DropStmt);
    9022             : 
    9023          74 :                     n->removeType = OBJECT_AGGREGATE;
    9024          74 :                     n->objects = $3;
    9025          74 :                     n->behavior = $4;
    9026          74 :                     n->missing_ok = false;
    9027          74 :                     n->concurrent = false;
    9028          74 :                     $$ = (Node *) n;
    9029             :                 }
    9030             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9031             :                 {
    9032          30 :                     DropStmt *n = makeNode(DropStmt);
    9033             : 
    9034          30 :                     n->removeType = OBJECT_AGGREGATE;
    9035          30 :                     n->objects = $5;
    9036          30 :                     n->behavior = $6;
    9037          30 :                     n->missing_ok = true;
    9038          30 :                     n->concurrent = false;
    9039          30 :                     $$ = (Node *) n;
    9040             :                 }
    9041             :         ;
    9042             : 
    9043             : RemoveOperStmt:
    9044             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9045             :                 {
    9046         194 :                     DropStmt *n = makeNode(DropStmt);
    9047             : 
    9048         194 :                     n->removeType = OBJECT_OPERATOR;
    9049         194 :                     n->objects = $3;
    9050         194 :                     n->behavior = $4;
    9051         194 :                     n->missing_ok = false;
    9052         194 :                     n->concurrent = false;
    9053         194 :                     $$ = (Node *) n;
    9054             :                 }
    9055             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9056             :                 {
    9057          30 :                     DropStmt *n = makeNode(DropStmt);
    9058             : 
    9059          30 :                     n->removeType = OBJECT_OPERATOR;
    9060          30 :                     n->objects = $5;
    9061          30 :                     n->behavior = $6;
    9062          30 :                     n->missing_ok = true;
    9063          30 :                     n->concurrent = false;
    9064          30 :                     $$ = (Node *) n;
    9065             :                 }
    9066             :         ;
    9067             : 
    9068             : oper_argtypes:
    9069             :             '(' Typename ')'
    9070             :                 {
    9071          12 :                    ereport(ERROR,
    9072             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9073             :                             errmsg("missing argument"),
    9074             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9075             :                             parser_errposition(@3)));
    9076             :                 }
    9077             :             | '(' Typename ',' Typename ')'
    9078        1950 :                     { $$ = list_make2($2, $4); }
    9079             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9080          32 :                     { $$ = list_make2(NULL, $4); }
    9081             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9082          12 :                     { $$ = list_make2($2, NULL); }
    9083             :         ;
    9084             : 
    9085             : any_operator:
    9086             :             all_Op
    9087       20258 :                     { $$ = list_make1(makeString($1)); }
    9088             :             | ColId '.' any_operator
    9089       15352 :                     { $$ = lcons(makeString($1), $3); }
    9090             :         ;
    9091             : 
    9092             : operator_with_argtypes_list:
    9093         224 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9094             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9095           0 :                                                     { $$ = lappend($1, $3); }
    9096             :         ;
    9097             : 
    9098             : operator_with_argtypes:
    9099             :             any_operator oper_argtypes
    9100             :                 {
    9101        1994 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9102             : 
    9103        1994 :                     n->objname = $1;
    9104        1994 :                     n->objargs = $2;
    9105        1994 :                     $$ = n;
    9106             :                 }
    9107             :         ;
    9108             : 
    9109             : /*****************************************************************************
    9110             :  *
    9111             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9112             :  *
    9113             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9114             :  * in the clause order.
    9115             :  *
    9116             :  *****************************************************************************/
    9117             : 
    9118             : DoStmt: DO dostmt_opt_list
    9119             :                 {
    9120        1130 :                     DoStmt *n = makeNode(DoStmt);
    9121             : 
    9122        1130 :                     n->args = $2;
    9123        1130 :                     $$ = (Node *) n;
    9124             :                 }
    9125             :         ;
    9126             : 
    9127             : dostmt_opt_list:
    9128        1130 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9129         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9130             :         ;
    9131             : 
    9132             : dostmt_opt_item:
    9133             :             Sconst
    9134             :                 {
    9135        1130 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9136             :                 }
    9137             :             | LANGUAGE NonReservedWord_or_Sconst
    9138             :                 {
    9139         198 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9140             :                 }
    9141             :         ;
    9142             : 
    9143             : /*****************************************************************************
    9144             :  *
    9145             :  *      CREATE CAST / DROP CAST
    9146             :  *
    9147             :  *****************************************************************************/
    9148             : 
    9149             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9150             :                     WITH FUNCTION function_with_argtypes cast_context
    9151             :                 {
    9152         102 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9153             : 
    9154         102 :                     n->sourcetype = $4;
    9155         102 :                     n->targettype = $6;
    9156         102 :                     n->func = $10;
    9157         102 :                     n->context = (CoercionContext) $11;
    9158         102 :                     n->inout = false;
    9159         102 :                     $$ = (Node *) n;
    9160             :                 }
    9161             :             | CREATE CAST '(' Typename AS Typename ')'
    9162             :                     WITHOUT FUNCTION cast_context
    9163             :                 {
    9164         162 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9165             : 
    9166         162 :                     n->sourcetype = $4;
    9167         162 :                     n->targettype = $6;
    9168         162 :                     n->func = NULL;
    9169         162 :                     n->context = (CoercionContext) $10;
    9170         162 :                     n->inout = false;
    9171         162 :                     $$ = (Node *) n;
    9172             :                 }
    9173             :             | CREATE CAST '(' Typename AS Typename ')'
    9174             :                     WITH INOUT cast_context
    9175             :                 {
    9176           6 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9177             : 
    9178           6 :                     n->sourcetype = $4;
    9179           6 :                     n->targettype = $6;
    9180           6 :                     n->func = NULL;
    9181           6 :                     n->context = (CoercionContext) $10;
    9182           6 :                     n->inout = true;
    9183           6 :                     $$ = (Node *) n;
    9184             :                 }
    9185             :         ;
    9186             : 
    9187          30 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9188          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9189         182 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9190             :         ;
    9191             : 
    9192             : 
    9193             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9194             :                 {
    9195          54 :                     DropStmt *n = makeNode(DropStmt);
    9196             : 
    9197          54 :                     n->removeType = OBJECT_CAST;
    9198          54 :                     n->objects = list_make1(list_make2($5, $7));
    9199          54 :                     n->behavior = $9;
    9200          54 :                     n->missing_ok = $3;
    9201          54 :                     n->concurrent = false;
    9202          54 :                     $$ = (Node *) n;
    9203             :                 }
    9204             :         ;
    9205             : 
    9206          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9207          32 :         | /*EMPTY*/                             { $$ = false; }
    9208             :         ;
    9209             : 
    9210             : 
    9211             : /*****************************************************************************
    9212             :  *
    9213             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9214             :  *
    9215             :  *****************************************************************************/
    9216             : 
    9217             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9218             :                 {
    9219          50 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9220             : 
    9221          50 :                     n->replace = $2;
    9222          50 :                     n->type_name = $5;
    9223          50 :                     n->lang = $7;
    9224          50 :                     n->fromsql = linitial($9);
    9225          50 :                     n->tosql = lsecond($9);
    9226          50 :                     $$ = (Node *) n;
    9227             :                 }
    9228             :         ;
    9229             : 
    9230             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9231             :                 {
    9232          44 :                     $$ = list_make2($5, $11);
    9233             :                 }
    9234             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9235             :                 {
    9236           0 :                     $$ = list_make2($11, $5);
    9237             :                 }
    9238             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9239             :                 {
    9240           4 :                     $$ = list_make2($5, NULL);
    9241             :                 }
    9242             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9243             :                 {
    9244           2 :                     $$ = list_make2(NULL, $5);
    9245             :                 }
    9246             :         ;
    9247             : 
    9248             : 
    9249             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9250             :                 {
    9251          14 :                     DropStmt *n = makeNode(DropStmt);
    9252             : 
    9253          14 :                     n->removeType = OBJECT_TRANSFORM;
    9254          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9255          14 :                     n->behavior = $8;
    9256          14 :                     n->missing_ok = $3;
    9257          14 :                     $$ = (Node *) n;
    9258             :                 }
    9259             :         ;
    9260             : 
    9261             : 
    9262             : /*****************************************************************************
    9263             :  *
    9264             :  *      QUERY:
    9265             :  *
    9266             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9267             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9268             :  *****************************************************************************/
    9269             : 
    9270             : ReindexStmt:
    9271             :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9272             :                 {
    9273         910 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9274             : 
    9275         910 :                     n->kind = $3;
    9276         910 :                     n->relation = $5;
    9277         910 :                     n->name = NULL;
    9278         910 :                     n->params = $2;
    9279         910 :                     if ($4)
    9280         510 :                         n->params = lappend(n->params,
    9281         510 :                                             makeDefElem("concurrently", NULL, @4));
    9282         910 :                     $$ = (Node *) n;
    9283             :                 }
    9284             :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9285             :                 {
    9286         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9287             : 
    9288         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9289         114 :                     n->relation = NULL;
    9290         114 :                     n->name = $5;
    9291         114 :                     n->params = $2;
    9292         114 :                     if ($4)
    9293          40 :                         n->params = lappend(n->params,
    9294          40 :                                             makeDefElem("concurrently", NULL, @4));
    9295         114 :                     $$ = (Node *) n;
    9296             :                 }
    9297             :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9298             :                 {
    9299          68 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9300             : 
    9301          68 :                     n->kind = $3;
    9302          68 :                     n->relation = NULL;
    9303          68 :                     n->name = $5;
    9304          68 :                     n->params = $2;
    9305          68 :                     if ($4)
    9306          10 :                         n->params = lappend(n->params,
    9307          10 :                                             makeDefElem("concurrently", NULL, @4));
    9308          68 :                     $$ = (Node *) n;
    9309             :                 }
    9310             :         ;
    9311             : reindex_target_relation:
    9312         394 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9313         516 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9314             :         ;
    9315             : reindex_target_all:
    9316          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9317          34 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9318             :         ;
    9319             : opt_reindex_option_list:
    9320         156 :             '(' utility_option_list ')'             { $$ = $2; }
    9321         936 :             | /* EMPTY */                           { $$ = NULL; }
    9322             :         ;
    9323             : 
    9324             : /*****************************************************************************
    9325             :  *
    9326             :  * ALTER TABLESPACE
    9327             :  *
    9328             :  *****************************************************************************/
    9329             : 
    9330             : AlterTblSpcStmt:
    9331             :             ALTER TABLESPACE name SET reloptions
    9332             :                 {
    9333             :                     AlterTableSpaceOptionsStmt *n =
    9334          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9335             : 
    9336          12 :                     n->tablespacename = $3;
    9337          12 :                     n->options = $5;
    9338          12 :                     n->isReset = false;
    9339          12 :                     $$ = (Node *) n;
    9340             :                 }
    9341             :             | ALTER TABLESPACE name RESET reloptions
    9342             :                 {
    9343             :                     AlterTableSpaceOptionsStmt *n =
    9344          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9345             : 
    9346          12 :                     n->tablespacename = $3;
    9347          12 :                     n->options = $5;
    9348          12 :                     n->isReset = true;
    9349          12 :                     $$ = (Node *) n;
    9350             :                 }
    9351             :         ;
    9352             : 
    9353             : /*****************************************************************************
    9354             :  *
    9355             :  * ALTER THING name RENAME TO newname
    9356             :  *
    9357             :  *****************************************************************************/
    9358             : 
    9359             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9360             :                 {
    9361          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9362             : 
    9363          42 :                     n->renameType = OBJECT_AGGREGATE;
    9364          42 :                     n->object = (Node *) $3;
    9365          42 :                     n->newname = $6;
    9366          42 :                     n->missing_ok = false;
    9367          42 :                     $$ = (Node *) n;
    9368             :                 }
    9369             :             | ALTER COLLATION any_name RENAME TO name
    9370             :                 {
    9371          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9372             : 
    9373          18 :                     n->renameType = OBJECT_COLLATION;
    9374          18 :                     n->object = (Node *) $3;
    9375          18 :                     n->newname = $6;
    9376          18 :                     n->missing_ok = false;
    9377          18 :                     $$ = (Node *) n;
    9378             :                 }
    9379             :             | ALTER CONVERSION_P any_name RENAME TO name
    9380             :                 {
    9381          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9382             : 
    9383          24 :                     n->renameType = OBJECT_CONVERSION;
    9384          24 :                     n->object = (Node *) $3;
    9385          24 :                     n->newname = $6;
    9386          24 :                     n->missing_ok = false;
    9387          24 :                     $$ = (Node *) n;
    9388             :                 }
    9389             :             | ALTER DATABASE name RENAME TO name
    9390             :                 {
    9391           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9392             : 
    9393           6 :                     n->renameType = OBJECT_DATABASE;
    9394           6 :                     n->subname = $3;
    9395           6 :                     n->newname = $6;
    9396           6 :                     n->missing_ok = false;
    9397           6 :                     $$ = (Node *) n;
    9398             :                 }
    9399             :             | ALTER DOMAIN_P any_name RENAME TO name
    9400             :                 {
    9401           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9402             : 
    9403           6 :                     n->renameType = OBJECT_DOMAIN;
    9404           6 :                     n->object = (Node *) $3;
    9405           6 :                     n->newname = $6;
    9406           6 :                     n->missing_ok = false;
    9407           6 :                     $$ = (Node *) n;
    9408             :                 }
    9409             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9410             :                 {
    9411           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9412             : 
    9413           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9414           6 :                     n->object = (Node *) $3;
    9415           6 :                     n->subname = $6;
    9416           6 :                     n->newname = $8;
    9417           6 :                     $$ = (Node *) n;
    9418             :                 }
    9419             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9420             :                 {
    9421          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9422             : 
    9423          24 :                     n->renameType = OBJECT_FDW;
    9424          24 :                     n->object = (Node *) makeString($5);
    9425          24 :                     n->newname = $8;
    9426          24 :                     n->missing_ok = false;
    9427          24 :                     $$ = (Node *) n;
    9428             :                 }
    9429             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9430             :                 {
    9431          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9432             : 
    9433          24 :                     n->renameType = OBJECT_FUNCTION;
    9434          24 :                     n->object = (Node *) $3;
    9435          24 :                     n->newname = $6;
    9436          24 :                     n->missing_ok = false;
    9437          24 :                     $$ = (Node *) n;
    9438             :                 }
    9439             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9440             :                 {
    9441           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9442             : 
    9443           0 :                     n->renameType = OBJECT_ROLE;
    9444           0 :                     n->subname = $3;
    9445           0 :                     n->newname = $6;
    9446           0 :                     n->missing_ok = false;
    9447           0 :                     $$ = (Node *) n;
    9448             :                 }
    9449             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9450             :                 {
    9451          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9452             : 
    9453          18 :                     n->renameType = OBJECT_LANGUAGE;
    9454          18 :                     n->object = (Node *) makeString($4);
    9455          18 :                     n->newname = $7;
    9456          18 :                     n->missing_ok = false;
    9457          18 :                     $$ = (Node *) n;
    9458             :                 }
    9459             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9460             :                 {
    9461          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9462             : 
    9463          24 :                     n->renameType = OBJECT_OPCLASS;
    9464          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9465          24 :                     n->newname = $9;
    9466          24 :                     n->missing_ok = false;
    9467          24 :                     $$ = (Node *) n;
    9468             :                 }
    9469             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9470             :                 {
    9471          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9472             : 
    9473          24 :                     n->renameType = OBJECT_OPFAMILY;
    9474          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9475          24 :                     n->newname = $9;
    9476          24 :                     n->missing_ok = false;
    9477          24 :                     $$ = (Node *) n;
    9478             :                 }
    9479             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9480             :                 {
    9481          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9482             : 
    9483          18 :                     n->renameType = OBJECT_POLICY;
    9484          18 :                     n->relation = $5;
    9485          18 :                     n->subname = $3;
    9486          18 :                     n->newname = $8;
    9487          18 :                     n->missing_ok = false;
    9488          18 :                     $$ = (Node *) n;
    9489             :                 }
    9490             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9491             :                 {
    9492           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9493             : 
    9494           0 :                     n->renameType = OBJECT_POLICY;
    9495           0 :                     n->relation = $7;
    9496           0 :                     n->subname = $5;
    9497           0 :                     n->newname = $10;
    9498           0 :                     n->missing_ok = true;
    9499           0 :                     $$ = (Node *) n;
    9500             :                 }
    9501             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9502             :                 {
    9503           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9504             : 
    9505           0 :                     n->renameType = OBJECT_PROCEDURE;
    9506           0 :                     n->object = (Node *) $3;
    9507           0 :                     n->newname = $6;
    9508           0 :                     n->missing_ok = false;
    9509           0 :                     $$ = (Node *) n;
    9510             :                 }
    9511             :             | ALTER PUBLICATION name RENAME TO name
    9512             :                 {
    9513          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9514             : 
    9515          18 :                     n->renameType = OBJECT_PUBLICATION;
    9516          18 :                     n->object = (Node *) makeString($3);
    9517          18 :                     n->newname = $6;
    9518          18 :                     n->missing_ok = false;
    9519          18 :                     $$ = (Node *) n;
    9520             :                 }
    9521             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9522             :                 {
    9523          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9524             : 
    9525          24 :                     n->renameType = OBJECT_ROUTINE;
    9526          24 :                     n->object = (Node *) $3;
    9527          24 :                     n->newname = $6;
    9528          24 :                     n->missing_ok = false;
    9529          24 :                     $$ = (Node *) n;
    9530             :                 }
    9531             :             | ALTER SCHEMA name RENAME TO name
    9532             :                 {
    9533          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9534             : 
    9535          20 :                     n->renameType = OBJECT_SCHEMA;
    9536          20 :                     n->subname = $3;
    9537          20 :                     n->newname = $6;
    9538          20 :                     n->missing_ok = false;
    9539          20 :                     $$ = (Node *) n;
    9540             :                 }
    9541             :             | ALTER SERVER name RENAME TO name
    9542             :                 {
    9543          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9544             : 
    9545          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9546          24 :                     n->object = (Node *) makeString($3);
    9547          24 :                     n->newname = $6;
    9548          24 :                     n->missing_ok = false;
    9549          24 :                     $$ = (Node *) n;
    9550             :                 }
    9551             :             | ALTER SUBSCRIPTION name RENAME TO name
    9552             :                 {
    9553          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9554             : 
    9555          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9556          38 :                     n->object = (Node *) makeString($3);
    9557          38 :                     n->newname = $6;
    9558          38 :                     n->missing_ok = false;
    9559          38 :                     $$ = (Node *) n;
    9560             :                 }
    9561             :             | ALTER TABLE relation_expr RENAME TO name
    9562             :                 {
    9563         286 :                     RenameStmt *n = makeNode(RenameStmt);
    9564             : 
    9565         286 :                     n->renameType = OBJECT_TABLE;
    9566         286 :                     n->relation = $3;
    9567         286 :                     n->subname = NULL;
    9568         286 :                     n->newname = $6;
    9569         286 :                     n->missing_ok = false;
    9570         286 :                     $$ = (Node *) n;
    9571             :                 }
    9572             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9573             :                 {
    9574           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9575             : 
    9576           0 :                     n->renameType = OBJECT_TABLE;
    9577           0 :                     n->relation = $5;
    9578           0 :                     n->subname = NULL;
    9579           0 :                     n->newname = $8;
    9580           0 :                     n->missing_ok = true;
    9581           0 :                     $$ = (Node *) n;
    9582             :                 }
    9583             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9584             :                 {
    9585           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9586             : 
    9587           2 :                     n->renameType = OBJECT_SEQUENCE;
    9588           2 :                     n->relation = $3;
    9589           2 :                     n->subname = NULL;
    9590           2 :                     n->newname = $6;
    9591           2 :                     n->missing_ok = false;
    9592           2 :                     $$ = (Node *) n;
    9593             :                 }
    9594             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9595             :                 {
    9596           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9597             : 
    9598           0 :                     n->renameType = OBJECT_SEQUENCE;
    9599           0 :                     n->relation = $5;
    9600           0 :                     n->subname = NULL;
    9601           0 :                     n->newname = $8;
    9602           0 :                     n->missing_ok = true;
    9603           0 :                     $$ = (Node *) n;
    9604             :                 }
    9605             :             | ALTER VIEW qualified_name RENAME TO name
    9606             :                 {
    9607           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9608             : 
    9609           6 :                     n->renameType = OBJECT_VIEW;
    9610           6 :                     n->relation = $3;
    9611           6 :                     n->subname = NULL;
    9612           6 :                     n->newname = $6;
    9613           6 :                     n->missing_ok = false;
    9614           6 :                     $$ = (Node *) n;
    9615             :                 }
    9616             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9617             :                 {
    9618           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9619             : 
    9620           0 :                     n->renameType = OBJECT_VIEW;
    9621           0 :                     n->relation = $5;
    9622           0 :                     n->subname = NULL;
    9623           0 :                     n->newname = $8;
    9624           0 :                     n->missing_ok = true;
    9625           0 :                     $$ = (Node *) n;
    9626             :                 }
    9627             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9628             :                 {
    9629           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9630             : 
    9631           0 :                     n->renameType = OBJECT_MATVIEW;
    9632           0 :                     n->relation = $4;
    9633           0 :                     n->subname = NULL;
    9634           0 :                     n->newname = $7;
    9635           0 :                     n->missing_ok = false;
    9636           0 :                     $$ = (Node *) n;
    9637             :                 }
    9638             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9639             :                 {
    9640           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9641             : 
    9642           0 :                     n->renameType = OBJECT_MATVIEW;
    9643           0 :                     n->relation = $6;
    9644           0 :                     n->subname = NULL;
    9645           0 :                     n->newname = $9;
    9646           0 :                     n->missing_ok = true;
    9647           0 :                     $$ = (Node *) n;
    9648             :                 }
    9649             :             | ALTER INDEX qualified_name RENAME TO name
    9650             :                 {
    9651         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9652             : 
    9653         192 :                     n->renameType = OBJECT_INDEX;
    9654         192 :                     n->relation = $3;
    9655         192 :                     n->subname = NULL;
    9656         192 :                     n->newname = $6;
    9657         192 :                     n->missing_ok = false;
    9658         192 :                     $$ = (Node *) n;
    9659             :                 }
    9660             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9661             :                 {
    9662          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9663             : 
    9664          12 :                     n->renameType = OBJECT_INDEX;
    9665          12 :                     n->relation = $5;
    9666          12 :                     n->subname = NULL;
    9667          12 :                     n->newname = $8;
    9668          12 :                     n->missing_ok = true;
    9669          12 :                     $$ = (Node *) n;
    9670             :                 }
    9671             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9672             :                 {
    9673           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9674             : 
    9675           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9676           6 :                     n->relation = $4;
    9677           6 :                     n->subname = NULL;
    9678           6 :                     n->newname = $7;
    9679           6 :                     n->missing_ok = false;
    9680           6 :                     $$ = (Node *) n;
    9681             :                 }
    9682             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9683             :                 {
    9684           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9685             : 
    9686           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9687           6 :                     n->relation = $6;
    9688           6 :                     n->subname = NULL;
    9689           6 :                     n->newname = $9;
    9690           6 :                     n->missing_ok = true;
    9691           6 :                     $$ = (Node *) n;
    9692             :                 }
    9693             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9694             :                 {
    9695         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9696             : 
    9697         238 :                     n->renameType = OBJECT_COLUMN;
    9698         238 :                     n->relationType = OBJECT_TABLE;
    9699         238 :                     n->relation = $3;
    9700         238 :                     n->subname = $6;
    9701         238 :                     n->newname = $8;
    9702         238 :                     n->missing_ok = false;
    9703         238 :                     $$ = (Node *) n;
    9704             :                 }
    9705             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9706             :                 {
    9707          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9708             : 
    9709          24 :                     n->renameType = OBJECT_COLUMN;
    9710          24 :                     n->relationType = OBJECT_TABLE;
    9711          24 :                     n->relation = $5;
    9712          24 :                     n->subname = $8;
    9713          24 :                     n->newname = $10;
    9714          24 :                     n->missing_ok = true;
    9715          24 :                     $$ = (Node *) n;
    9716             :                 }
    9717             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9718             :                 {
    9719          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9720             : 
    9721          18 :                     n->renameType = OBJECT_COLUMN;
    9722          18 :                     n->relationType = OBJECT_VIEW;
    9723          18 :                     n->relation = $3;
    9724          18 :                     n->subname = $6;
    9725          18 :                     n->newname = $8;
    9726          18 :                     n->missing_ok = false;
    9727          18 :                     $$ = (Node *) n;
    9728             :                 }
    9729             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9730             :                 {
    9731           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9732             : 
    9733           0 :                     n->renameType = OBJECT_COLUMN;
    9734           0 :                     n->relationType = OBJECT_VIEW;
    9735           0 :                     n->relation = $5;
    9736           0 :                     n->subname = $8;
    9737           0 :                     n->newname = $10;
    9738           0 :                     n->missing_ok = true;
    9739           0 :                     $$ = (Node *) n;
    9740             :                 }
    9741             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9742             :                 {
    9743           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9744             : 
    9745           0 :                     n->renameType = OBJECT_COLUMN;
    9746           0 :                     n->relationType = OBJECT_MATVIEW;
    9747           0 :                     n->relation = $4;
    9748           0 :                     n->subname = $7;
    9749           0 :                     n->newname = $9;
    9750           0 :                     n->missing_ok = false;
    9751           0 :                     $$ = (Node *) n;
    9752             :                 }
    9753             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9754             :                 {
    9755           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9756             : 
    9757           0 :                     n->renameType = OBJECT_COLUMN;
    9758           0 :                     n->relationType = OBJECT_MATVIEW;
    9759           0 :                     n->relation = $6;
    9760           0 :                     n->subname = $9;
    9761           0 :                     n->newname = $11;
    9762           0 :                     n->missing_ok = true;
    9763           0 :                     $$ = (Node *) n;
    9764             :                 }
    9765             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9766             :                 {
    9767          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9768             : 
    9769          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9770          72 :                     n->relation = $3;
    9771          72 :                     n->subname = $6;
    9772          72 :                     n->newname = $8;
    9773          72 :                     n->missing_ok = false;
    9774          72 :                     $$ = (Node *) n;
    9775             :                 }
    9776             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9777             :                 {
    9778           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9779             : 
    9780           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9781           6 :                     n->relation = $5;
    9782           6 :                     n->subname = $8;
    9783           6 :                     n->newname = $10;
    9784           6 :                     n->missing_ok = true;
    9785           6 :                     $$ = (Node *) n;
    9786             :                 }
    9787             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9788             :                 {
    9789           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9790             : 
    9791           6 :                     n->renameType = OBJECT_COLUMN;
    9792           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9793           6 :                     n->relation = $4;
    9794           6 :                     n->subname = $7;
    9795           6 :                     n->newname = $9;
    9796           6 :                     n->missing_ok = false;
    9797           6 :                     $$ = (Node *) n;
    9798             :                 }
    9799             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9800             :                 {
    9801           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9802             : 
    9803           6 :                     n->renameType = OBJECT_COLUMN;
    9804           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9805           6 :                     n->relation = $6;
    9806           6 :                     n->subname = $9;
    9807           6 :                     n->newname = $11;
    9808           6 :                     n->missing_ok = true;
    9809           6 :                     $$ = (Node *) n;
    9810             :                 }
    9811             :             | ALTER RULE name ON qualified_name RENAME TO name
    9812             :                 {
    9813          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9814             : 
    9815          34 :                     n->renameType = OBJECT_RULE;
    9816          34 :                     n->relation = $5;
    9817          34 :                     n->subname = $3;
    9818          34 :                     n->newname = $8;
    9819          34 :                     n->missing_ok = false;
    9820          34 :                     $$ = (Node *) n;
    9821             :                 }
    9822             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9823             :                 {
    9824          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9825             : 
    9826          40 :                     n->renameType = OBJECT_TRIGGER;
    9827          40 :                     n->relation = $5;
    9828          40 :                     n->subname = $3;
    9829          40 :                     n->newname = $8;
    9830          40 :                     n->missing_ok = false;
    9831          40 :                     $$ = (Node *) n;
    9832             :                 }
    9833             :             | ALTER EVENT TRIGGER name RENAME TO name
    9834             :                 {
    9835          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9836             : 
    9837          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9838          12 :                     n->object = (Node *) makeString($4);
    9839          12 :                     n->newname = $7;
    9840          12 :                     $$ = (Node *) n;
    9841             :                 }
    9842             :             | ALTER ROLE RoleId RENAME TO RoleId
    9843             :                 {
    9844          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9845             : 
    9846          30 :                     n->renameType = OBJECT_ROLE;
    9847          30 :                     n->subname = $3;
    9848          30 :                     n->newname = $6;
    9849          30 :                     n->missing_ok = false;
    9850          30 :                     $$ = (Node *) n;
    9851             :                 }
    9852             :             | ALTER USER RoleId RENAME TO RoleId
    9853             :                 {
    9854           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9855             : 
    9856           0 :                     n->renameType = OBJECT_ROLE;
    9857           0 :                     n->subname = $3;
    9858           0 :                     n->newname = $6;
    9859           0 :                     n->missing_ok = false;
    9860           0 :                     $$ = (Node *) n;
    9861             :                 }
    9862             :             | ALTER TABLESPACE name RENAME TO name
    9863             :                 {
    9864           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9865             : 
    9866           6 :                     n->renameType = OBJECT_TABLESPACE;
    9867           6 :                     n->subname = $3;
    9868           6 :                     n->newname = $6;
    9869           6 :                     n->missing_ok = false;
    9870           6 :                     $$ = (Node *) n;
    9871             :                 }
    9872             :             | ALTER STATISTICS any_name RENAME TO name
    9873             :                 {
    9874          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9875             : 
    9876          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9877          30 :                     n->object = (Node *) $3;
    9878          30 :                     n->newname = $6;
    9879          30 :                     n->missing_ok = false;
    9880          30 :                     $$ = (Node *) n;
    9881             :                 }
    9882             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9883             :                 {
    9884          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9885             : 
    9886          12 :                     n->renameType = OBJECT_TSPARSER;
    9887          12 :                     n->object = (Node *) $5;
    9888          12 :                     n->newname = $8;
    9889          12 :                     n->missing_ok = false;
    9890          12 :                     $$ = (Node *) n;
    9891             :                 }
    9892             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9893             :                 {
    9894          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9895             : 
    9896          24 :                     n->renameType = OBJECT_TSDICTIONARY;
    9897          24 :                     n->object = (Node *) $5;
    9898          24 :                     n->newname = $8;
    9899          24 :                     n->missing_ok = false;
    9900          24 :                     $$ = (Node *) n;
    9901             :                 }
    9902             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9903             :                 {
    9904          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9905             : 
    9906          12 :                     n->renameType = OBJECT_TSTEMPLATE;
    9907          12 :                     n->object = (Node *) $5;
    9908          12 :                     n->newname = $8;
    9909          12 :                     n->missing_ok = false;
    9910          12 :                     $$ = (Node *) n;
    9911             :                 }
    9912             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9913             :                 {
    9914          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9915             : 
    9916          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9917          24 :                     n->object = (Node *) $5;
    9918          24 :                     n->newname = $8;
    9919          24 :                     n->missing_ok = false;
    9920          24 :                     $$ = (Node *) n;
    9921             :                 }
    9922             :             | ALTER TYPE_P any_name RENAME TO name
    9923             :                 {
    9924          26 :                     RenameStmt *n = makeNode(RenameStmt);
    9925             : 
    9926          26 :                     n->renameType = OBJECT_TYPE;
    9927          26 :                     n->object = (Node *) $3;
    9928          26 :                     n->newname = $6;
    9929          26 :                     n->missing_ok = false;
    9930          26 :                     $$ = (Node *) n;
    9931             :                 }
    9932             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
    9933             :                 {
    9934          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9935             : 
    9936          24 :                     n->renameType = OBJECT_ATTRIBUTE;
    9937          24 :                     n->relationType = OBJECT_TYPE;
    9938          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    9939          24 :                     n->subname = $6;
    9940          24 :                     n->newname = $8;
    9941          24 :                     n->behavior = $9;
    9942          24 :                     n->missing_ok = false;
    9943          24 :                     $$ = (Node *) n;
    9944             :                 }
    9945             :         ;
    9946             : 
    9947             : opt_column: COLUMN
    9948             :             | /*EMPTY*/
    9949             :         ;
    9950             : 
    9951         184 : opt_set_data: SET DATA_P                            { $$ = 1; }
    9952         860 :             | /*EMPTY*/                             { $$ = 0; }
    9953             :         ;
    9954             : 
    9955             : /*****************************************************************************
    9956             :  *
    9957             :  * ALTER THING name DEPENDS ON EXTENSION name
    9958             :  *
    9959             :  *****************************************************************************/
    9960             : 
    9961             : AlterObjectDependsStmt:
    9962             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9963             :                 {
    9964          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9965             : 
    9966          12 :                     n->objectType = OBJECT_FUNCTION;
    9967          12 :                     n->object = (Node *) $3;
    9968          12 :                     n->extname = makeString($8);
    9969          12 :                     n->remove = $4;
    9970          12 :                     $$ = (Node *) n;
    9971             :                 }
    9972             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9973             :                 {
    9974           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9975             : 
    9976           0 :                     n->objectType = OBJECT_PROCEDURE;
    9977           0 :                     n->object = (Node *) $3;
    9978           0 :                     n->extname = makeString($8);
    9979           0 :                     n->remove = $4;
    9980           0 :                     $$ = (Node *) n;
    9981             :                 }
    9982             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9983             :                 {
    9984           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9985             : 
    9986           0 :                     n->objectType = OBJECT_ROUTINE;
    9987           0 :                     n->object = (Node *) $3;
    9988           0 :                     n->extname = makeString($8);
    9989           0 :                     n->remove = $4;
    9990           0 :                     $$ = (Node *) n;
    9991             :                 }
    9992             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
    9993             :                 {
    9994          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9995             : 
    9996          10 :                     n->objectType = OBJECT_TRIGGER;
    9997          10 :                     n->relation = $5;
    9998          10 :                     n->object = (Node *) list_make1(makeString($3));
    9999          10 :                     n->extname = makeString($10);
   10000          10 :                     n->remove = $6;
   10001          10 :                     $$ = (Node *) n;
   10002             :                 }
   10003             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10004             :                 {
   10005          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10006             : 
   10007          10 :                     n->objectType = OBJECT_MATVIEW;
   10008          10 :                     n->relation = $4;
   10009          10 :                     n->extname = makeString($9);
   10010          10 :                     n->remove = $5;
   10011          10 :                     $$ = (Node *) n;
   10012             :                 }
   10013             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10014             :                 {
   10015          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10016             : 
   10017          14 :                     n->objectType = OBJECT_INDEX;
   10018          14 :                     n->relation = $3;
   10019          14 :                     n->extname = makeString($8);
   10020          14 :                     n->remove = $4;
   10021          14 :                     $$ = (Node *) n;
   10022             :                 }
   10023             :         ;
   10024             : 
   10025           8 : opt_no:     NO              { $$ = true; }
   10026          38 :             | /* EMPTY */   { $$ = false;   }
   10027             :         ;
   10028             : 
   10029             : /*****************************************************************************
   10030             :  *
   10031             :  * ALTER THING name SET SCHEMA name
   10032             :  *
   10033             :  *****************************************************************************/
   10034             : 
   10035             : AlterObjectSchemaStmt:
   10036             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10037             :                 {
   10038          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10039             : 
   10040          24 :                     n->objectType = OBJECT_AGGREGATE;
   10041          24 :                     n->object = (Node *) $3;
   10042          24 :                     n->newschema = $6;
   10043          24 :                     n->missing_ok = false;
   10044          24 :                     $$ = (Node *) n;
   10045             :                 }
   10046             :             | ALTER COLLATION any_name SET SCHEMA name
   10047             :                 {
   10048           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10049             : 
   10050           6 :                     n->objectType = OBJECT_COLLATION;
   10051           6 :                     n->object = (Node *) $3;
   10052           6 :                     n->newschema = $6;
   10053           6 :                     n->missing_ok = false;
   10054           6 :                     $$ = (Node *) n;
   10055             :                 }
   10056             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10057             :                 {
   10058          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10059             : 
   10060          24 :                     n->objectType = OBJECT_CONVERSION;
   10061          24 :                     n->object = (Node *) $3;
   10062          24 :                     n->newschema = $6;
   10063          24 :                     n->missing_ok = false;
   10064          24 :                     $$ = (Node *) n;
   10065             :                 }
   10066             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10067             :                 {
   10068           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10069             : 
   10070           6 :                     n->objectType = OBJECT_DOMAIN;
   10071           6 :                     n->object = (Node *) $3;
   10072           6 :                     n->newschema = $6;
   10073           6 :                     n->missing_ok = false;
   10074           6 :                     $$ = (Node *) n;
   10075             :                 }
   10076             :             | ALTER EXTENSION name SET SCHEMA name
   10077             :                 {
   10078          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10079             : 
   10080          12 :                     n->objectType = OBJECT_EXTENSION;
   10081          12 :                     n->object = (Node *) makeString($3);
   10082          12 :                     n->newschema = $6;
   10083          12 :                     n->missing_ok = false;
   10084          12 :                     $$ = (Node *) n;
   10085             :                 }
   10086             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10087             :                 {
   10088          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10089             : 
   10090          42 :                     n->objectType = OBJECT_FUNCTION;
   10091          42 :                     n->object = (Node *) $3;
   10092          42 :                     n->newschema = $6;
   10093          42 :                     n->missing_ok = false;
   10094          42 :                     $$ = (Node *) n;
   10095             :                 }
   10096             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10097             :                 {
   10098          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10099             : 
   10100          18 :                     n->objectType = OBJECT_OPERATOR;
   10101          18 :                     n->object = (Node *) $3;
   10102          18 :                     n->newschema = $6;
   10103          18 :                     n->missing_ok = false;
   10104          18 :                     $$ = (Node *) n;
   10105             :                 }
   10106             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10107             :                 {
   10108          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10109             : 
   10110          24 :                     n->objectType = OBJECT_OPCLASS;
   10111          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10112          24 :                     n->newschema = $9;
   10113          24 :                     n->missing_ok = false;
   10114          24 :                     $$ = (Node *) n;
   10115             :                 }
   10116             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10117             :                 {
   10118          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10119             : 
   10120          24 :                     n->objectType = OBJECT_OPFAMILY;
   10121          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10122          24 :                     n->newschema = $9;
   10123          24 :                     n->missing_ok = false;
   10124          24 :                     $$ = (Node *) n;
   10125             :                 }
   10126             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10127             :                 {
   10128           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10129             : 
   10130           0 :                     n->objectType = OBJECT_PROCEDURE;
   10131           0 :                     n->object = (Node *) $3;
   10132           0 :                     n->newschema = $6;
   10133           0 :                     n->missing_ok = false;
   10134           0 :                     $$ = (Node *) n;
   10135             :                 }
   10136             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10137             :                 {
   10138           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10139             : 
   10140           0 :                     n->objectType = OBJECT_ROUTINE;
   10141           0 :                     n->object = (Node *) $3;
   10142           0 :                     n->newschema = $6;
   10143           0 :                     n->missing_ok = false;
   10144           0 :                     $$ = (Node *) n;
   10145             :                 }
   10146             :             | ALTER TABLE relation_expr SET SCHEMA name
   10147             :                 {
   10148          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10149             : 
   10150          66 :                     n->objectType = OBJECT_TABLE;
   10151          66 :                     n->relation = $3;
   10152          66 :                     n->newschema = $6;
   10153          66 :                     n->missing_ok = false;
   10154          66 :                     $$ = (Node *) n;
   10155             :                 }
   10156             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10157             :                 {
   10158          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10159             : 
   10160          12 :                     n->objectType = OBJECT_TABLE;
   10161          12 :                     n->relation = $5;
   10162          12 :                     n->newschema = $8;
   10163          12 :                     n->missing_ok = true;
   10164          12 :                     $$ = (Node *) n;
   10165             :                 }
   10166             :             | ALTER STATISTICS any_name SET SCHEMA name
   10167             :                 {
   10168          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10169             : 
   10170          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10171          18 :                     n->object = (Node *) $3;
   10172          18 :                     n->newschema = $6;
   10173          18 :                     n->missing_ok = false;
   10174          18 :                     $$ = (Node *) n;
   10175             :                 }
   10176             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10177             :                 {
   10178          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10179             : 
   10180          18 :                     n->objectType = OBJECT_TSPARSER;
   10181          18 :                     n->object = (Node *) $5;
   10182          18 :                     n->newschema = $8;
   10183          18 :                     n->missing_ok = false;
   10184          18 :                     $$ = (Node *) n;
   10185             :                 }
   10186             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10187             :                 {
   10188          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10189             : 
   10190          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10191          24 :                     n->object = (Node *) $5;
   10192          24 :                     n->newschema = $8;
   10193          24 :                     n->missing_ok = false;
   10194          24 :                     $$ = (Node *) n;
   10195             :                 }
   10196             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10197             :                 {
   10198          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10199             : 
   10200          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10201          18 :                     n->object = (Node *) $5;
   10202          18 :                     n->newschema = $8;
   10203          18 :                     n->missing_ok = false;
   10204          18 :                     $$ = (Node *) n;
   10205             :                 }
   10206             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10207             :                 {
   10208          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10209             : 
   10210          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10211          24 :                     n->object = (Node *) $5;
   10212          24 :                     n->newschema = $8;
   10213          24 :                     n->missing_ok = false;
   10214          24 :                     $$ = (Node *) n;
   10215             :                 }
   10216             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10217             :                 {
   10218           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10219             : 
   10220           8 :                     n->objectType = OBJECT_SEQUENCE;
   10221           8 :                     n->relation = $3;
   10222           8 :                     n->newschema = $6;
   10223           8 :                     n->missing_ok = false;
   10224           8 :                     $$ = (Node *) n;
   10225             :                 }
   10226             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10227             :                 {
   10228           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10229             : 
   10230           0 :                     n->objectType = OBJECT_SEQUENCE;
   10231           0 :                     n->relation = $5;
   10232           0 :                     n->newschema = $8;
   10233           0 :                     n->missing_ok = true;
   10234           0 :                     $$ = (Node *) n;
   10235             :                 }
   10236             :             | ALTER VIEW qualified_name SET SCHEMA name
   10237             :                 {
   10238           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10239             : 
   10240           0 :                     n->objectType = OBJECT_VIEW;
   10241           0 :                     n->relation = $3;
   10242           0 :                     n->newschema = $6;
   10243           0 :                     n->missing_ok = false;
   10244           0 :                     $$ = (Node *) n;
   10245             :                 }
   10246             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10247             :                 {
   10248           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10249             : 
   10250           0 :                     n->objectType = OBJECT_VIEW;
   10251           0 :                     n->relation = $5;
   10252           0 :                     n->newschema = $8;
   10253           0 :                     n->missing_ok = true;
   10254           0 :                     $$ = (Node *) n;
   10255             :                 }
   10256             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10257             :                 {
   10258           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10259             : 
   10260           6 :                     n->objectType = OBJECT_MATVIEW;
   10261           6 :                     n->relation = $4;
   10262           6 :                     n->newschema = $7;
   10263           6 :                     n->missing_ok = false;
   10264           6 :                     $$ = (Node *) n;
   10265             :                 }
   10266             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10267             :                 {
   10268           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10269             : 
   10270           0 :                     n->objectType = OBJECT_MATVIEW;
   10271           0 :                     n->relation = $6;
   10272           0 :                     n->newschema = $9;
   10273           0 :                     n->missing_ok = true;
   10274           0 :                     $$ = (Node *) n;
   10275             :                 }
   10276             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10277             :                 {
   10278           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10279             : 
   10280           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10281           6 :                     n->relation = $4;
   10282           6 :                     n->newschema = $7;
   10283           6 :                     n->missing_ok = false;
   10284           6 :                     $$ = (Node *) n;
   10285             :                 }
   10286             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10287             :                 {
   10288           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10289             : 
   10290           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10291           6 :                     n->relation = $6;
   10292           6 :                     n->newschema = $9;
   10293           6 :                     n->missing_ok = true;
   10294           6 :                     $$ = (Node *) n;
   10295             :                 }
   10296             :             | ALTER TYPE_P any_name SET SCHEMA name
   10297             :                 {
   10298          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10299             : 
   10300          12 :                     n->objectType = OBJECT_TYPE;
   10301          12 :                     n->object = (Node *) $3;
   10302          12 :                     n->newschema = $6;
   10303          12 :                     n->missing_ok = false;
   10304          12 :                     $$ = (Node *) n;
   10305             :                 }
   10306             :         ;
   10307             : 
   10308             : /*****************************************************************************
   10309             :  *
   10310             :  * ALTER OPERATOR name SET define
   10311             :  *
   10312             :  *****************************************************************************/
   10313             : 
   10314             : AlterOperatorStmt:
   10315             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10316             :                 {
   10317         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10318             : 
   10319         608 :                     n->opername = $3;
   10320         608 :                     n->options = $6;
   10321         608 :                     $$ = (Node *) n;
   10322             :                 }
   10323             :         ;
   10324             : 
   10325         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10326         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10327             :         ;
   10328             : 
   10329             : operator_def_elem: ColLabel '=' NONE
   10330          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10331             :                    | ColLabel '=' operator_def_arg
   10332        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10333             :                    | ColLabel
   10334          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10335             :         ;
   10336             : 
   10337             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10338             : operator_def_arg:
   10339        1032 :             func_type                       { $$ = (Node *) $1; }
   10340          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10341          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10342           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10343           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10344             :         ;
   10345             : 
   10346             : /*****************************************************************************
   10347             :  *
   10348             :  * ALTER TYPE name SET define
   10349             :  *
   10350             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10351             :  *
   10352             :  *****************************************************************************/
   10353             : 
   10354             : AlterTypeStmt:
   10355             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10356             :                 {
   10357          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10358             : 
   10359          60 :                     n->typeName = $3;
   10360          60 :                     n->options = $6;
   10361          60 :                     $$ = (Node *) n;
   10362             :                 }
   10363             :         ;
   10364             : 
   10365             : /*****************************************************************************
   10366             :  *
   10367             :  * ALTER THING name OWNER TO newname
   10368             :  *
   10369             :  *****************************************************************************/
   10370             : 
   10371             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10372             :                 {
   10373         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10374             : 
   10375         142 :                     n->objectType = OBJECT_AGGREGATE;
   10376         142 :                     n->object = (Node *) $3;
   10377         142 :                     n->newowner = $6;
   10378         142 :                     $$ = (Node *) n;
   10379             :                 }
   10380             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10381             :                 {
   10382          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10383             : 
   10384          18 :                     n->objectType = OBJECT_COLLATION;
   10385          18 :                     n->object = (Node *) $3;
   10386          18 :                     n->newowner = $6;
   10387          18 :                     $$ = (Node *) n;
   10388             :                 }
   10389             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10390             :                 {
   10391          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10392             : 
   10393          24 :                     n->objectType = OBJECT_CONVERSION;
   10394          24 :                     n->object = (Node *) $3;
   10395          24 :                     n->newowner = $6;
   10396          24 :                     $$ = (Node *) n;
   10397             :                 }
   10398             :             | ALTER DATABASE name OWNER TO RoleSpec
   10399             :                 {
   10400          50 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10401             : 
   10402          50 :                     n->objectType = OBJECT_DATABASE;
   10403          50 :                     n->object = (Node *) makeString($3);
   10404          50 :                     n->newowner = $6;
   10405          50 :                     $$ = (Node *) n;
   10406             :                 }
   10407             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10408             :                 {
   10409          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10410             : 
   10411          42 :                     n->objectType = OBJECT_DOMAIN;
   10412          42 :                     n->object = (Node *) $3;
   10413          42 :                     n->newowner = $6;
   10414          42 :                     $$ = (Node *) n;
   10415             :                 }
   10416             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10417             :                 {
   10418         592 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10419             : 
   10420         592 :                     n->objectType = OBJECT_FUNCTION;
   10421         592 :                     n->object = (Node *) $3;
   10422         592 :                     n->newowner = $6;
   10423         592 :                     $$ = (Node *) n;
   10424             :                 }
   10425             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10426             :                 {
   10427         132 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10428             : 
   10429         132 :                     n->objectType = OBJECT_LANGUAGE;
   10430         132 :                     n->object = (Node *) makeString($4);
   10431         132 :                     n->newowner = $7;
   10432         132 :                     $$ = (Node *) n;
   10433             :                 }
   10434             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10435             :                 {
   10436          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10437             : 
   10438          12 :                     n->objectType = OBJECT_LARGEOBJECT;
   10439          12 :                     n->object = (Node *) $4;
   10440          12 :                     n->newowner = $7;
   10441          12 :                     $$ = (Node *) n;
   10442             :                 }
   10443             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10444             :                 {
   10445          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10446             : 
   10447          46 :                     n->objectType = OBJECT_OPERATOR;
   10448          46 :                     n->object = (Node *) $3;
   10449          46 :                     n->newowner = $6;
   10450          46 :                     $$ = (Node *) n;
   10451             :                 }
   10452             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10453             :                 {
   10454          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10455             : 
   10456          54 :                     n->objectType = OBJECT_OPCLASS;
   10457          54 :                     n->object = (Node *) lcons(makeString($6), $4);
   10458          54 :                     n->newowner = $9;
   10459          54 :                     $$ = (Node *) n;
   10460             :                 }
   10461             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10462             :                 {
   10463          62 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10464             : 
   10465          62 :                     n->objectType = OBJECT_OPFAMILY;
   10466          62 :                     n->object = (Node *) lcons(makeString($6), $4);
   10467          62 :                     n->newowner = $9;
   10468          62 :                     $$ = (Node *) n;
   10469             :                 }
   10470             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10471             :                 {
   10472          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10473             : 
   10474          24 :                     n->objectType = OBJECT_PROCEDURE;
   10475          24 :                     n->object = (Node *) $3;
   10476          24 :                     n->newowner = $6;
   10477          24 :                     $$ = (Node *) n;
   10478             :                 }
   10479             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10480             :                 {
   10481           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10482             : 
   10483           0 :                     n->objectType = OBJECT_ROUTINE;
   10484           0 :                     n->object = (Node *) $3;
   10485           0 :                     n->newowner = $6;
   10486           0 :                     $$ = (Node *) n;
   10487             :                 }
   10488             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10489             :                 {
   10490          56 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10491             : 
   10492          56 :                     n->objectType = OBJECT_SCHEMA;
   10493          56 :                     n->object = (Node *) makeString($3);
   10494          56 :                     n->newowner = $6;
   10495          56 :                     $$ = (Node *) n;
   10496             :                 }
   10497             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10498             :                 {
   10499          84 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10500             : 
   10501          84 :                     n->objectType = OBJECT_TYPE;
   10502          84 :                     n->object = (Node *) $3;
   10503          84 :                     n->newowner = $6;
   10504          84 :                     $$ = (Node *) n;
   10505             :                 }
   10506             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10507             :                 {
   10508           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10509             : 
   10510           6 :                     n->objectType = OBJECT_TABLESPACE;
   10511           6 :                     n->object = (Node *) makeString($3);
   10512           6 :                     n->newowner = $6;
   10513           6 :                     $$ = (Node *) n;
   10514             :                 }
   10515             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10516             :                 {
   10517          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10518             : 
   10519          32 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10520          32 :                     n->object = (Node *) $3;
   10521          32 :                     n->newowner = $6;
   10522          32 :                     $$ = (Node *) n;
   10523             :                 }
   10524             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10525             :                 {
   10526          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10527             : 
   10528          42 :                     n->objectType = OBJECT_TSDICTIONARY;
   10529          42 :                     n->object = (Node *) $5;
   10530          42 :                     n->newowner = $8;
   10531          42 :                     $$ = (Node *) n;
   10532             :                 }
   10533             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10534             :                 {
   10535          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10536             : 
   10537          32 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10538          32 :                     n->object = (Node *) $5;
   10539          32 :                     n->newowner = $8;
   10540          32 :                     $$ = (Node *) n;
   10541             :                 }
   10542             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10543             :                 {
   10544          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10545             : 
   10546          20 :                     n->objectType = OBJECT_FDW;
   10547          20 :                     n->object = (Node *) makeString($5);
   10548          20 :                     n->newowner = $8;
   10549          20 :                     $$ = (Node *) n;
   10550             :                 }
   10551             :             | ALTER SERVER name OWNER TO RoleSpec
   10552             :                 {
   10553          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10554             : 
   10555          68 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10556          68 :                     n->object = (Node *) makeString($3);
   10557          68 :                     n->newowner = $6;
   10558          68 :                     $$ = (Node *) n;
   10559             :                 }
   10560             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10561             :                 {
   10562          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10563             : 
   10564          14 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10565          14 :                     n->object = (Node *) makeString($4);
   10566          14 :                     n->newowner = $7;
   10567          14 :                     $$ = (Node *) n;
   10568             :                 }
   10569             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10570             :                 {
   10571          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10572             : 
   10573          26 :                     n->objectType = OBJECT_PUBLICATION;
   10574          26 :                     n->object = (Node *) makeString($3);
   10575          26 :                     n->newowner = $6;
   10576          26 :                     $$ = (Node *) n;
   10577             :                 }
   10578             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10579             :                 {
   10580          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10581             : 
   10582          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10583          18 :                     n->object = (Node *) makeString($3);
   10584          18 :                     n->newowner = $6;
   10585          18 :                     $$ = (Node *) n;
   10586             :                 }
   10587             :         ;
   10588             : 
   10589             : 
   10590             : /*****************************************************************************
   10591             :  *
   10592             :  * CREATE PUBLICATION name [WITH options]
   10593             :  *
   10594             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10595             :  *
   10596             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10597             :  *
   10598             :  * pub_obj is one of:
   10599             :  *
   10600             :  *      TABLE table [, ...]
   10601             :  *      TABLES IN SCHEMA schema [, ...]
   10602             :  *
   10603             :  *****************************************************************************/
   10604             : 
   10605             : CreatePublicationStmt:
   10606             :             CREATE PUBLICATION name opt_definition
   10607             :                 {
   10608         122 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10609             : 
   10610         122 :                     n->pubname = $3;
   10611         122 :                     n->options = $4;
   10612         122 :                     $$ = (Node *) n;
   10613             :                 }
   10614             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10615             :                 {
   10616          88 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10617             : 
   10618          88 :                     n->pubname = $3;
   10619          88 :                     n->options = $7;
   10620          88 :                     n->for_all_tables = true;
   10621          88 :                     $$ = (Node *) n;
   10622             :                 }
   10623             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10624             :                 {
   10625         610 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10626             : 
   10627         610 :                     n->pubname = $3;
   10628         610 :                     n->options = $6;
   10629         610 :                     n->pubobjects = (List *) $5;
   10630         610 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10631         580 :                     $$ = (Node *) n;
   10632             :                 }
   10633             :         ;
   10634             : 
   10635             : /*
   10636             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10637             :  *
   10638             :  * This rule parses publication objects with and without keyword prefixes.
   10639             :  *
   10640             :  * The actual type of the object without keyword prefix depends on the previous
   10641             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10642             :  *
   10643             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10644             :  * because some extended expressions in relation_expr cannot be used as a
   10645             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10646             :  * relation_expr here.
   10647             :  */
   10648             : PublicationObjSpec:
   10649             :             TABLE relation_expr opt_column_list OptWhereClause
   10650             :                 {
   10651        1260 :                     $$ = makeNode(PublicationObjSpec);
   10652        1260 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10653        1260 :                     $$->pubtable = makeNode(PublicationTable);
   10654        1260 :                     $$->pubtable->relation = $2;
   10655        1260 :                     $$->pubtable->columns = $3;
   10656        1260 :                     $$->pubtable->whereClause = $4;
   10657             :                 }
   10658             :             | TABLES IN_P SCHEMA ColId
   10659             :                 {
   10660         332 :                     $$ = makeNode(PublicationObjSpec);
   10661         332 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10662         332 :                     $$->name = $4;
   10663         332 :                     $$->location = @4;
   10664             :                 }
   10665             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10666             :                 {
   10667          18 :                     $$ = makeNode(PublicationObjSpec);
   10668          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10669          18 :                     $$->location = @4;
   10670             :                 }
   10671             :             | ColId opt_column_list OptWhereClause
   10672             :                 {
   10673         128 :                     $$ = makeNode(PublicationObjSpec);
   10674         128 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10675             :                     /*
   10676             :                      * If either a row filter or column list is specified, create
   10677             :                      * a PublicationTable object.
   10678             :                      */
   10679         128 :                     if ($2 || $3)
   10680             :                     {
   10681             :                         /*
   10682             :                          * The OptWhereClause must be stored here but it is
   10683             :                          * valid only for tables. For non-table objects, an
   10684             :                          * error will be thrown later via
   10685             :                          * preprocess_pubobj_list().
   10686             :                          */
   10687          42 :                         $$->pubtable = makeNode(PublicationTable);
   10688          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10689          42 :                         $$->pubtable->columns = $2;
   10690          42 :                         $$->pubtable->whereClause = $3;
   10691             :                     }
   10692             :                     else
   10693             :                     {
   10694          86 :                         $$->name = $1;
   10695             :                     }
   10696         128 :                     $$->location = @1;
   10697             :                 }
   10698             :             | ColId indirection opt_column_list OptWhereClause
   10699             :                 {
   10700          32 :                     $$ = makeNode(PublicationObjSpec);
   10701          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10702          32 :                     $$->pubtable = makeNode(PublicationTable);
   10703          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10704          32 :                     $$->pubtable->columns = $3;
   10705          32 :                     $$->pubtable->whereClause = $4;
   10706          32 :                     $$->location = @1;
   10707             :                 }
   10708             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10709             :             | extended_relation_expr opt_column_list OptWhereClause
   10710             :                 {
   10711           6 :                     $$ = makeNode(PublicationObjSpec);
   10712           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10713           6 :                     $$->pubtable = makeNode(PublicationTable);
   10714           6 :                     $$->pubtable->relation = $1;
   10715           6 :                     $$->pubtable->columns = $2;
   10716           6 :                     $$->pubtable->whereClause = $3;
   10717             :                 }
   10718             :             | CURRENT_SCHEMA
   10719             :                 {
   10720          18 :                     $$ = makeNode(PublicationObjSpec);
   10721          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10722          18 :                     $$->location = @1;
   10723             :                 }
   10724             :                 ;
   10725             : 
   10726             : pub_obj_list:   PublicationObjSpec
   10727        1572 :                     { $$ = list_make1($1); }
   10728             :             | pub_obj_list ',' PublicationObjSpec
   10729         222 :                     { $$ = lappend($1, $3); }
   10730             :     ;
   10731             : 
   10732             : /*****************************************************************************
   10733             :  *
   10734             :  * ALTER PUBLICATION name SET ( options )
   10735             :  *
   10736             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10737             :  *
   10738             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10739             :  *
   10740             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10741             :  *
   10742             :  * pub_obj is one of:
   10743             :  *
   10744             :  *      TABLE table_name [, ...]
   10745             :  *      TABLES IN SCHEMA schema_name [, ...]
   10746             :  *
   10747             :  *****************************************************************************/
   10748             : 
   10749             : AlterPublicationStmt:
   10750             :             ALTER PUBLICATION name SET definition
   10751             :                 {
   10752         116 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10753             : 
   10754         116 :                     n->pubname = $3;
   10755         116 :                     n->options = $5;
   10756         116 :                     $$ = (Node *) n;
   10757             :                 }
   10758             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10759             :                 {
   10760         344 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10761             : 
   10762         344 :                     n->pubname = $3;
   10763         344 :                     n->pubobjects = $5;
   10764         344 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10765         338 :                     n->action = AP_AddObjects;
   10766         338 :                     $$ = (Node *) n;
   10767             :                 }
   10768             :             | ALTER PUBLICATION name SET pub_obj_list
   10769             :                 {
   10770         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10771             : 
   10772         464 :                     n->pubname = $3;
   10773         464 :                     n->pubobjects = $5;
   10774         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10775         464 :                     n->action = AP_SetObjects;
   10776         464 :                     $$ = (Node *) n;
   10777             :                 }
   10778             :             | ALTER PUBLICATION name DROP pub_obj_list
   10779             :                 {
   10780         154 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10781             : 
   10782         154 :                     n->pubname = $3;
   10783         154 :                     n->pubobjects = $5;
   10784         154 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10785         154 :                     n->action = AP_DropObjects;
   10786         154 :                     $$ = (Node *) n;
   10787             :                 }
   10788             :         ;
   10789             : 
   10790             : /*****************************************************************************
   10791             :  *
   10792             :  * CREATE SUBSCRIPTION name ...
   10793             :  *
   10794             :  *****************************************************************************/
   10795             : 
   10796             : CreateSubscriptionStmt:
   10797             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10798             :                 {
   10799             :                     CreateSubscriptionStmt *n =
   10800         436 :                         makeNode(CreateSubscriptionStmt);
   10801         436 :                     n->subname = $3;
   10802         436 :                     n->conninfo = $5;
   10803         436 :                     n->publication = $7;
   10804         436 :                     n->options = $8;
   10805         436 :                     $$ = (Node *) n;
   10806             :                 }
   10807             :         ;
   10808             : 
   10809             : /*****************************************************************************
   10810             :  *
   10811             :  * ALTER SUBSCRIPTION name ...
   10812             :  *
   10813             :  *****************************************************************************/
   10814             : 
   10815             : AlterSubscriptionStmt:
   10816             :             ALTER SUBSCRIPTION name SET definition
   10817             :                 {
   10818             :                     AlterSubscriptionStmt *n =
   10819         184 :                         makeNode(AlterSubscriptionStmt);
   10820             : 
   10821         184 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10822         184 :                     n->subname = $3;
   10823         184 :                     n->options = $5;
   10824         184 :                     $$ = (Node *) n;
   10825             :                 }
   10826             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10827             :                 {
   10828             :                     AlterSubscriptionStmt *n =
   10829          26 :                         makeNode(AlterSubscriptionStmt);
   10830             : 
   10831          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10832          26 :                     n->subname = $3;
   10833          26 :                     n->conninfo = $5;
   10834          26 :                     $$ = (Node *) n;
   10835             :                 }
   10836             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10837             :                 {
   10838             :                     AlterSubscriptionStmt *n =
   10839          54 :                         makeNode(AlterSubscriptionStmt);
   10840             : 
   10841          54 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10842          54 :                     n->subname = $3;
   10843          54 :                     n->options = $6;
   10844          54 :                     $$ = (Node *) n;
   10845             :                 }
   10846             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10847             :                 {
   10848             :                     AlterSubscriptionStmt *n =
   10849          28 :                         makeNode(AlterSubscriptionStmt);
   10850             : 
   10851          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10852          28 :                     n->subname = $3;
   10853          28 :                     n->publication = $6;
   10854          28 :                     n->options = $7;
   10855          28 :                     $$ = (Node *) n;
   10856             :                 }
   10857             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10858             :                 {
   10859             :                     AlterSubscriptionStmt *n =
   10860          26 :                         makeNode(AlterSubscriptionStmt);
   10861             : 
   10862          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10863          26 :                     n->subname = $3;
   10864          26 :                     n->publication = $6;
   10865          26 :                     n->options = $7;
   10866          26 :                     $$ = (Node *) n;
   10867             :                 }
   10868             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10869             :                 {
   10870             :                     AlterSubscriptionStmt *n =
   10871          40 :                         makeNode(AlterSubscriptionStmt);
   10872             : 
   10873          40 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10874          40 :                     n->subname = $3;
   10875          40 :                     n->publication = $6;
   10876          40 :                     n->options = $7;
   10877          40 :                     $$ = (Node *) n;
   10878             :                 }
   10879             :             | ALTER SUBSCRIPTION name ENABLE_P
   10880             :                 {
   10881             :                     AlterSubscriptionStmt *n =
   10882          48 :                         makeNode(AlterSubscriptionStmt);
   10883             : 
   10884          48 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10885          48 :                     n->subname = $3;
   10886          48 :                     n->options = list_make1(makeDefElem("enabled",
   10887             :                                             (Node *) makeBoolean(true), @1));
   10888          48 :                     $$ = (Node *) n;
   10889             :                 }
   10890             :             | ALTER SUBSCRIPTION name DISABLE_P
   10891             :                 {
   10892             :                     AlterSubscriptionStmt *n =
   10893          32 :                         makeNode(AlterSubscriptionStmt);
   10894             : 
   10895          32 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10896          32 :                     n->subname = $3;
   10897          32 :                     n->options = list_make1(makeDefElem("enabled",
   10898             :                                             (Node *) makeBoolean(false), @1));
   10899          32 :                     $$ = (Node *) n;
   10900             :                 }
   10901             :             | ALTER SUBSCRIPTION name SKIP definition
   10902             :                 {
   10903             :                     AlterSubscriptionStmt *n =
   10904          24 :                         makeNode(AlterSubscriptionStmt);
   10905             : 
   10906          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10907          24 :                     n->subname = $3;
   10908          24 :                     n->options = $5;
   10909          24 :                     $$ = (Node *) n;
   10910             :                 }
   10911             :         ;
   10912             : 
   10913             : /*****************************************************************************
   10914             :  *
   10915             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   10916             :  *
   10917             :  *****************************************************************************/
   10918             : 
   10919             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   10920             :                 {
   10921         208 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10922             : 
   10923         208 :                     n->subname = $3;
   10924         208 :                     n->missing_ok = false;
   10925         208 :                     n->behavior = $4;
   10926         208 :                     $$ = (Node *) n;
   10927             :                 }
   10928             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   10929             :                 {
   10930           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10931             : 
   10932           6 :                     n->subname = $5;
   10933           6 :                     n->missing_ok = true;
   10934           6 :                     n->behavior = $6;
   10935           6 :                     $$ = (Node *) n;
   10936             :                 }
   10937             :         ;
   10938             : 
   10939             : /*****************************************************************************
   10940             :  *
   10941             :  *      QUERY:  Define Rewrite Rule
   10942             :  *
   10943             :  *****************************************************************************/
   10944             : 
   10945             : RuleStmt:   CREATE opt_or_replace RULE name AS
   10946             :             ON event TO qualified_name where_clause
   10947             :             DO opt_instead RuleActionList
   10948             :                 {
   10949        1072 :                     RuleStmt   *n = makeNode(RuleStmt);
   10950             : 
   10951        1072 :                     n->replace = $2;
   10952        1072 :                     n->relation = $9;
   10953        1072 :                     n->rulename = $4;
   10954        1072 :                     n->whereClause = $10;
   10955        1072 :                     n->event = $7;
   10956        1072 :                     n->instead = $12;
   10957        1072 :                     n->actions = $13;
   10958        1072 :                     $$ = (Node *) n;
   10959             :                 }
   10960             :         ;
   10961             : 
   10962             : RuleActionList:
   10963         152 :             NOTHING                                 { $$ = NIL; }
   10964         874 :             | RuleActionStmt                        { $$ = list_make1($1); }
   10965          46 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   10966             :         ;
   10967             : 
   10968             : /* the thrashing around here is to discard "empty" statements... */
   10969             : RuleActionMulti:
   10970             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   10971          62 :                 { if ($3 != NULL)
   10972          46 :                     $$ = lappend($1, $3);
   10973             :                   else
   10974          16 :                     $$ = $1;
   10975             :                 }
   10976             :             | RuleActionStmtOrEmpty
   10977          46 :                 { if ($1 != NULL)
   10978          46 :                     $$ = list_make1($1);
   10979             :                   else
   10980           0 :                     $$ = NIL;
   10981             :                 }
   10982             :         ;
   10983             : 
   10984             : RuleActionStmt:
   10985             :             SelectStmt
   10986             :             | InsertStmt
   10987             :             | UpdateStmt
   10988             :             | DeleteStmt
   10989             :             | NotifyStmt
   10990             :         ;
   10991             : 
   10992             : RuleActionStmtOrEmpty:
   10993          92 :             RuleActionStmt                          { $$ = $1; }
   10994          16 :             |   /*EMPTY*/                           { $$ = NULL; }
   10995             :         ;
   10996             : 
   10997          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   10998         412 :             | UPDATE                                { $$ = CMD_UPDATE; }
   10999         164 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11000         478 :             | INSERT                                { $$ = CMD_INSERT; }
   11001             :          ;
   11002             : 
   11003             : opt_instead:
   11004         742 :             INSTEAD                                 { $$ = true; }
   11005         156 :             | ALSO                                  { $$ = false; }
   11006         174 :             | /*EMPTY*/                             { $$ = false; }
   11007             :         ;
   11008             : 
   11009             : 
   11010             : /*****************************************************************************
   11011             :  *
   11012             :  *      QUERY:
   11013             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11014             :  *              as a query-level command
   11015             :  *
   11016             :  *****************************************************************************/
   11017             : 
   11018             : NotifyStmt: NOTIFY ColId notify_payload
   11019             :                 {
   11020         128 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11021             : 
   11022         128 :                     n->conditionname = $2;
   11023         128 :                     n->payload = $3;
   11024         128 :                     $$ = (Node *) n;
   11025             :                 }
   11026             :         ;
   11027             : 
   11028             : notify_payload:
   11029          62 :             ',' Sconst                          { $$ = $2; }
   11030          66 :             | /*EMPTY*/                         { $$ = NULL; }
   11031             :         ;
   11032             : 
   11033             : ListenStmt: LISTEN ColId
   11034             :                 {
   11035          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11036             : 
   11037          74 :                     n->conditionname = $2;
   11038          74 :                     $$ = (Node *) n;
   11039             :                 }
   11040             :         ;
   11041             : 
   11042             : UnlistenStmt:
   11043             :             UNLISTEN ColId
   11044             :                 {
   11045           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11046             : 
   11047           6 :                     n->conditionname = $2;
   11048           6 :                     $$ = (Node *) n;
   11049             :                 }
   11050             :             | UNLISTEN '*'
   11051             :                 {
   11052          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11053             : 
   11054          32 :                     n->conditionname = NULL;
   11055          32 :                     $$ = (Node *) n;
   11056             :                 }
   11057             :         ;
   11058             : 
   11059             : 
   11060             : /*****************************************************************************
   11061             :  *
   11062             :  *      Transactions:
   11063             :  *
   11064             :  *      BEGIN / COMMIT / ROLLBACK
   11065             :  *      (also older versions END / ABORT)
   11066             :  *
   11067             :  *****************************************************************************/
   11068             : 
   11069             : TransactionStmt:
   11070             :             ABORT_P opt_transaction opt_transaction_chain
   11071             :                 {
   11072         234 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11073             : 
   11074         234 :                     n->kind = TRANS_STMT_ROLLBACK;
   11075         234 :                     n->options = NIL;
   11076         234 :                     n->chain = $3;
   11077         234 :                     n->location = -1;
   11078         234 :                     $$ = (Node *) n;
   11079             :                 }
   11080             :             | START TRANSACTION transaction_mode_list_or_empty
   11081             :                 {
   11082        1600 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11083             : 
   11084        1600 :                     n->kind = TRANS_STMT_START;
   11085        1600 :                     n->options = $3;
   11086        1600 :                     n->location = -1;
   11087        1600 :                     $$ = (Node *) n;
   11088             :                 }
   11089             :             | COMMIT opt_transaction opt_transaction_chain
   11090             :                 {
   11091       11542 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11092             : 
   11093       11542 :                     n->kind = TRANS_STMT_COMMIT;
   11094       11542 :                     n->options = NIL;
   11095       11542 :                     n->chain = $3;
   11096       11542 :                     n->location = -1;
   11097       11542 :                     $$ = (Node *) n;
   11098             :                 }
   11099             :             | ROLLBACK opt_transaction opt_transaction_chain
   11100             :                 {
   11101        2538 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11102             : 
   11103        2538 :                     n->kind = TRANS_STMT_ROLLBACK;
   11104        2538 :                     n->options = NIL;
   11105        2538 :                     n->chain = $3;
   11106        2538 :                     n->location = -1;
   11107        2538 :                     $$ = (Node *) n;
   11108             :                 }
   11109             :             | SAVEPOINT ColId
   11110             :                 {
   11111        1970 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11112             : 
   11113        1970 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11114        1970 :                     n->savepoint_name = $2;
   11115        1970 :                     n->location = @2;
   11116        1970 :                     $$ = (Node *) n;
   11117             :                 }
   11118             :             | RELEASE SAVEPOINT ColId
   11119             :                 {
   11120         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11121             : 
   11122         208 :                     n->kind = TRANS_STMT_RELEASE;
   11123         208 :                     n->savepoint_name = $3;
   11124         208 :                     n->location = @3;
   11125         208 :                     $$ = (Node *) n;
   11126             :                 }
   11127             :             | RELEASE ColId
   11128             :                 {
   11129          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11130             : 
   11131          86 :                     n->kind = TRANS_STMT_RELEASE;
   11132          86 :                     n->savepoint_name = $2;
   11133          86 :                     n->location = @2;
   11134          86 :                     $$ = (Node *) n;
   11135             :                 }
   11136             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11137             :                 {
   11138         218 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11139             : 
   11140         218 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11141         218 :                     n->savepoint_name = $5;
   11142         218 :                     n->location = @5;
   11143         218 :                     $$ = (Node *) n;
   11144             :                 }
   11145             :             | ROLLBACK opt_transaction TO ColId
   11146             :                 {
   11147         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11148             : 
   11149         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11150         496 :                     n->savepoint_name = $4;
   11151         496 :                     n->location = @4;
   11152         496 :                     $$ = (Node *) n;
   11153             :                 }
   11154             :             | PREPARE TRANSACTION Sconst
   11155             :                 {
   11156         800 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11157             : 
   11158         800 :                     n->kind = TRANS_STMT_PREPARE;
   11159         800 :                     n->gid = $3;
   11160         800 :                     n->location = @3;
   11161         800 :                     $$ = (Node *) n;
   11162             :                 }
   11163             :             | COMMIT PREPARED Sconst
   11164             :                 {
   11165         644 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11166             : 
   11167         644 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11168         644 :                     n->gid = $3;
   11169         644 :                     n->location = @3;
   11170         644 :                     $$ = (Node *) n;
   11171             :                 }
   11172             :             | ROLLBACK PREPARED Sconst
   11173             :                 {
   11174          76 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11175             : 
   11176          76 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11177          76 :                     n->gid = $3;
   11178          76 :                     n->location = @3;
   11179          76 :                     $$ = (Node *) n;
   11180             :                 }
   11181             :         ;
   11182             : 
   11183             : TransactionStmtLegacy:
   11184             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11185             :                 {
   11186       14164 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11187             : 
   11188       14164 :                     n->kind = TRANS_STMT_BEGIN;
   11189       14164 :                     n->options = $3;
   11190       14164 :                     n->location = -1;
   11191       14164 :                     $$ = (Node *) n;
   11192             :                 }
   11193             :             | END_P opt_transaction opt_transaction_chain
   11194             :                 {
   11195         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11196             : 
   11197         360 :                     n->kind = TRANS_STMT_COMMIT;
   11198         360 :                     n->options = NIL;
   11199         360 :                     n->chain = $3;
   11200         360 :                     n->location = -1;
   11201         360 :                     $$ = (Node *) n;
   11202             :                 }
   11203             :         ;
   11204             : 
   11205             : opt_transaction:    WORK
   11206             :             | TRANSACTION
   11207             :             | /*EMPTY*/
   11208             :         ;
   11209             : 
   11210             : transaction_mode_item:
   11211             :             ISOLATION LEVEL iso_level
   11212        6592 :                     { $$ = makeDefElem("transaction_isolation",
   11213        6592 :                                        makeStringConst($3, @3), @1); }
   11214             :             | READ ONLY
   11215        1328 :                     { $$ = makeDefElem("transaction_read_only",
   11216        1328 :                                        makeIntConst(true, @1), @1); }
   11217             :             | READ WRITE
   11218          90 :                     { $$ = makeDefElem("transaction_read_only",
   11219          90 :                                        makeIntConst(false, @1), @1); }
   11220             :             | DEFERRABLE
   11221          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11222             :                                        makeIntConst(true, @1), @1); }
   11223             :             | NOT DEFERRABLE
   11224          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11225          10 :                                        makeIntConst(false, @1), @1); }
   11226             :         ;
   11227             : 
   11228             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11229             : transaction_mode_list:
   11230             :             transaction_mode_item
   11231        6808 :                     { $$ = list_make1($1); }
   11232             :             | transaction_mode_list ',' transaction_mode_item
   11233         878 :                     { $$ = lappend($1, $3); }
   11234             :             | transaction_mode_list transaction_mode_item
   11235         378 :                     { $$ = lappend($1, $2); }
   11236             :         ;
   11237             : 
   11238             : transaction_mode_list_or_empty:
   11239             :             transaction_mode_list
   11240             :             | /* EMPTY */
   11241        9494 :                     { $$ = NIL; }
   11242             :         ;
   11243             : 
   11244             : opt_transaction_chain:
   11245         120 :             AND CHAIN       { $$ = true; }
   11246           2 :             | AND NO CHAIN  { $$ = false; }
   11247       14552 :             | /* EMPTY */   { $$ = false; }
   11248             :         ;
   11249             : 
   11250             : 
   11251             : /*****************************************************************************
   11252             :  *
   11253             :  *  QUERY:
   11254             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11255             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11256             :  *
   11257             :  *****************************************************************************/
   11258             : 
   11259             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11260             :                 AS SelectStmt opt_check_option
   11261             :                 {
   11262       14918 :                     ViewStmt   *n = makeNode(ViewStmt);
   11263             : 
   11264       14918 :                     n->view = $4;
   11265       14918 :                     n->view->relpersistence = $2;
   11266       14918 :                     n->aliases = $5;
   11267       14918 :                     n->query = $8;
   11268       14918 :                     n->replace = false;
   11269       14918 :                     n->options = $6;
   11270       14918 :                     n->withCheckOption = $9;
   11271       14918 :                     $$ = (Node *) n;
   11272             :                 }
   11273             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11274             :                 AS SelectStmt opt_check_option
   11275             :                 {
   11276         244 :                     ViewStmt   *n = makeNode(ViewStmt);
   11277             : 
   11278         244 :                     n->view = $6;
   11279         244 :                     n->view->relpersistence = $4;
   11280         244 :                     n->aliases = $7;
   11281         244 :                     n->query = $10;
   11282         244 :                     n->replace = true;
   11283         244 :                     n->options = $8;
   11284         244 :                     n->withCheckOption = $11;
   11285         244 :                     $$ = (Node *) n;
   11286             :                 }
   11287             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11288             :                 AS SelectStmt opt_check_option
   11289             :                 {
   11290           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11291             : 
   11292           8 :                     n->view = $5;
   11293           8 :                     n->view->relpersistence = $2;
   11294           8 :                     n->aliases = $7;
   11295           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11296           8 :                     n->replace = false;
   11297           8 :                     n->options = $9;
   11298           8 :                     n->withCheckOption = $12;
   11299           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11300           0 :                         ereport(ERROR,
   11301             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11302             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11303             :                                  parser_errposition(@12)));
   11304           8 :                     $$ = (Node *) n;
   11305             :                 }
   11306             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11307             :                 AS SelectStmt opt_check_option
   11308             :                 {
   11309           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11310             : 
   11311           6 :                     n->view = $7;
   11312           6 :                     n->view->relpersistence = $4;
   11313           6 :                     n->aliases = $9;
   11314           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11315           6 :                     n->replace = true;
   11316           6 :                     n->options = $11;
   11317           6 :                     n->withCheckOption = $14;
   11318           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11319           0 :                         ereport(ERROR,
   11320             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11321             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11322             :                                  parser_errposition(@14)));
   11323           6 :                     $$ = (Node *) n;
   11324             :                 }
   11325             :         ;
   11326             : 
   11327             : opt_check_option:
   11328          96 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11329           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11330          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11331       15050 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11332             :         ;
   11333             : 
   11334             : /*****************************************************************************
   11335             :  *
   11336             :  *      QUERY:
   11337             :  *              LOAD "filename"
   11338             :  *
   11339             :  *****************************************************************************/
   11340             : 
   11341             : LoadStmt:   LOAD file_name
   11342             :                 {
   11343          58 :                     LoadStmt   *n = makeNode(LoadStmt);
   11344             : 
   11345          58 :                     n->filename = $2;
   11346          58 :                     $$ = (Node *) n;
   11347             :                 }
   11348             :         ;
   11349             : 
   11350             : 
   11351             : /*****************************************************************************
   11352             :  *
   11353             :  *      CREATE DATABASE
   11354             :  *
   11355             :  *****************************************************************************/
   11356             : 
   11357             : CreatedbStmt:
   11358             :             CREATE DATABASE name opt_with createdb_opt_list
   11359             :                 {
   11360         688 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11361             : 
   11362         688 :                     n->dbname = $3;
   11363         688 :                     n->options = $5;
   11364         688 :                     $$ = (Node *) n;
   11365             :                 }
   11366             :         ;
   11367             : 
   11368             : createdb_opt_list:
   11369         536 :             createdb_opt_items                      { $$ = $1; }
   11370         182 :             | /* EMPTY */                           { $$ = NIL; }
   11371             :         ;
   11372             : 
   11373             : createdb_opt_items:
   11374         536 :             createdb_opt_item                       { $$ = list_make1($1); }
   11375         722 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11376             :         ;
   11377             : 
   11378             : createdb_opt_item:
   11379             :             createdb_opt_name opt_equal NumericOnly
   11380             :                 {
   11381         210 :                     $$ = makeDefElem($1, $3, @1);
   11382             :                 }
   11383             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11384             :                 {
   11385        1048 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11386             :                 }
   11387             :             | createdb_opt_name opt_equal DEFAULT
   11388             :                 {
   11389           0 :                     $$ = makeDefElem($1, NULL, @1);
   11390             :                 }
   11391             :         ;
   11392             : 
   11393             : /*
   11394             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11395             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11396             :  * we need, and allow IDENT so that database option names don't have to be
   11397             :  * parser keywords unless they are already keywords for other reasons.
   11398             :  *
   11399             :  * XXX this coding technique is fragile since if someone makes a formerly
   11400             :  * non-keyword option name into a keyword and forgets to add it here, the
   11401             :  * option will silently break.  Best defense is to provide a regression test
   11402             :  * exercising every such option, at least at the syntax level.
   11403             :  */
   11404             : createdb_opt_name:
   11405         870 :             IDENT                           { $$ = $1; }
   11406           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11407          68 :             | ENCODING                      { $$ = pstrdup($1); }
   11408           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11409           2 :             | OWNER                         { $$ = pstrdup($1); }
   11410          16 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11411         300 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11412             :         ;
   11413             : 
   11414             : /*
   11415             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11416             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11417             :  */
   11418             : opt_equal:  '='
   11419             :             | /*EMPTY*/
   11420             :         ;
   11421             : 
   11422             : 
   11423             : /*****************************************************************************
   11424             :  *
   11425             :  *      ALTER DATABASE
   11426             :  *
   11427             :  *****************************************************************************/
   11428             : 
   11429             : AlterDatabaseStmt:
   11430             :             ALTER DATABASE name WITH createdb_opt_list
   11431             :                  {
   11432           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11433             : 
   11434           0 :                     n->dbname = $3;
   11435           0 :                     n->options = $5;
   11436           0 :                     $$ = (Node *) n;
   11437             :                  }
   11438             :             | ALTER DATABASE name createdb_opt_list
   11439             :                  {
   11440          30 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11441             : 
   11442          30 :                     n->dbname = $3;
   11443          30 :                     n->options = $4;
   11444          30 :                     $$ = (Node *) n;
   11445             :                  }
   11446             :             | ALTER DATABASE name SET TABLESPACE name
   11447             :                  {
   11448          16 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11449             : 
   11450          16 :                     n->dbname = $3;
   11451          16 :                     n->options = list_make1(makeDefElem("tablespace",
   11452             :                                                         (Node *) makeString($6), @6));
   11453          16 :                     $$ = (Node *) n;
   11454             :                  }
   11455             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11456             :                  {
   11457           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11458             : 
   11459           6 :                     n->dbname = $3;
   11460           6 :                     $$ = (Node *) n;
   11461             :                  }
   11462             :         ;
   11463             : 
   11464             : AlterDatabaseSetStmt:
   11465             :             ALTER DATABASE name SetResetClause
   11466             :                 {
   11467        1138 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11468             : 
   11469        1138 :                     n->dbname = $3;
   11470        1138 :                     n->setstmt = $4;
   11471        1138 :                     $$ = (Node *) n;
   11472             :                 }
   11473             :         ;
   11474             : 
   11475             : 
   11476             : /*****************************************************************************
   11477             :  *
   11478             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11479             :  *
   11480             :  * This is implicitly CASCADE, no need for drop behavior
   11481             :  *****************************************************************************/
   11482             : 
   11483             : DropdbStmt: DROP DATABASE name
   11484             :                 {
   11485          72 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11486             : 
   11487          72 :                     n->dbname = $3;
   11488          72 :                     n->missing_ok = false;
   11489          72 :                     n->options = NULL;
   11490          72 :                     $$ = (Node *) n;
   11491             :                 }
   11492             :             | DROP DATABASE IF_P EXISTS name
   11493             :                 {
   11494           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11495             : 
   11496           4 :                     n->dbname = $5;
   11497           4 :                     n->missing_ok = true;
   11498           4 :                     n->options = NULL;
   11499           4 :                     $$ = (Node *) n;
   11500             :                 }
   11501             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11502             :                 {
   11503          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11504             : 
   11505          14 :                     n->dbname = $3;
   11506          14 :                     n->missing_ok = false;
   11507          14 :                     n->options = $6;
   11508          14 :                     $$ = (Node *) n;
   11509             :                 }
   11510             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11511             :                 {
   11512          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11513             : 
   11514          12 :                     n->dbname = $5;
   11515          12 :                     n->missing_ok = true;
   11516          12 :                     n->options = $8;
   11517          12 :                     $$ = (Node *) n;
   11518             :                 }
   11519             :         ;
   11520             : 
   11521             : drop_option_list:
   11522             :             drop_option
   11523             :                 {
   11524          26 :                     $$ = list_make1((Node *) $1);
   11525             :                 }
   11526             :             | drop_option_list ',' drop_option
   11527             :                 {
   11528           0 :                     $$ = lappend($1, (Node *) $3);
   11529             :                 }
   11530             :         ;
   11531             : 
   11532             : /*
   11533             :  * Currently only the FORCE option is supported, but the syntax is designed
   11534             :  * to be extensible so that we can add more options in the future if required.
   11535             :  */
   11536             : drop_option:
   11537             :             FORCE
   11538             :                 {
   11539          26 :                     $$ = makeDefElem("force", NULL, @1);
   11540             :                 }
   11541             :         ;
   11542             : 
   11543             : /*****************************************************************************
   11544             :  *
   11545             :  *      ALTER COLLATION
   11546             :  *
   11547             :  *****************************************************************************/
   11548             : 
   11549             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11550             :                 {
   11551           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11552             : 
   11553           6 :                     n->collname = $3;
   11554           6 :                     $$ = (Node *) n;
   11555             :                 }
   11556             :         ;
   11557             : 
   11558             : 
   11559             : /*****************************************************************************
   11560             :  *
   11561             :  *      ALTER SYSTEM
   11562             :  *
   11563             :  * This is used to change configuration parameters persistently.
   11564             :  *****************************************************************************/
   11565             : 
   11566             : AlterSystemStmt:
   11567             :             ALTER SYSTEM_P SET generic_set
   11568             :                 {
   11569         112 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11570             : 
   11571         112 :                     n->setstmt = $4;
   11572         112 :                     $$ = (Node *) n;
   11573             :                 }
   11574             :             | ALTER SYSTEM_P RESET generic_reset
   11575             :                 {
   11576          54 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11577             : 
   11578          54 :                     n->setstmt = $4;
   11579          54 :                     $$ = (Node *) n;
   11580             :                 }
   11581             :         ;
   11582             : 
   11583             : 
   11584             : /*****************************************************************************
   11585             :  *
   11586             :  * Manipulate a domain
   11587             :  *
   11588             :  *****************************************************************************/
   11589             : 
   11590             : CreateDomainStmt:
   11591             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11592             :                 {
   11593        1348 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11594             : 
   11595        1348 :                     n->domainname = $3;
   11596        1348 :                     n->typeName = $5;
   11597        1348 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11598             :                                      yyscanner);
   11599        1348 :                     $$ = (Node *) n;
   11600             :                 }
   11601             :         ;
   11602             : 
   11603             : AlterDomainStmt:
   11604             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11605             :             ALTER DOMAIN_P any_name alter_column_default
   11606             :                 {
   11607          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11608             : 
   11609          14 :                     n->subtype = 'T';
   11610          14 :                     n->typeName = $3;
   11611          14 :                     n->def = $4;
   11612          14 :                     $$ = (Node *) n;
   11613             :                 }
   11614             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11615             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11616             :                 {
   11617          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11618             : 
   11619          12 :                     n->subtype = 'N';
   11620          12 :                     n->typeName = $3;
   11621          12 :                     $$ = (Node *) n;
   11622             :                 }
   11623             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11624             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11625             :                 {
   11626          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11627             : 
   11628          24 :                     n->subtype = 'O';
   11629          24 :                     n->typeName = $3;
   11630          24 :                     $$ = (Node *) n;
   11631             :                 }
   11632             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11633             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11634             :                 {
   11635         174 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11636             : 
   11637         174 :                     n->subtype = 'C';
   11638         174 :                     n->typeName = $3;
   11639         174 :                     n->def = $5;
   11640         174 :                     $$ = (Node *) n;
   11641             :                 }
   11642             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11643             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11644             :                 {
   11645          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11646             : 
   11647          54 :                     n->subtype = 'X';
   11648          54 :                     n->typeName = $3;
   11649          54 :                     n->name = $6;
   11650          54 :                     n->behavior = $7;
   11651          54 :                     n->missing_ok = false;
   11652          54 :                     $$ = (Node *) n;
   11653             :                 }
   11654             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11655             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11656             :                 {
   11657           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11658             : 
   11659           6 :                     n->subtype = 'X';
   11660           6 :                     n->typeName = $3;
   11661           6 :                     n->name = $8;
   11662           6 :                     n->behavior = $9;
   11663           6 :                     n->missing_ok = true;
   11664           6 :                     $$ = (Node *) n;
   11665             :                 }
   11666             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11667             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11668             :                 {
   11669          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11670             : 
   11671          12 :                     n->subtype = 'V';
   11672          12 :                     n->typeName = $3;
   11673          12 :                     n->name = $6;
   11674          12 :                     $$ = (Node *) n;
   11675             :                 }
   11676             :             ;
   11677             : 
   11678             : opt_as:     AS
   11679             :             | /* EMPTY */
   11680             :         ;
   11681             : 
   11682             : 
   11683             : /*****************************************************************************
   11684             :  *
   11685             :  * Manipulate a text search dictionary or configuration
   11686             :  *
   11687             :  *****************************************************************************/
   11688             : 
   11689             : AlterTSDictionaryStmt:
   11690             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11691             :                 {
   11692          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11693             : 
   11694          40 :                     n->dictname = $5;
   11695          40 :                     n->options = $6;
   11696          40 :                     $$ = (Node *) n;
   11697             :                 }
   11698             :         ;
   11699             : 
   11700             : AlterTSConfigurationStmt:
   11701             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11702             :                 {
   11703        7390 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11704             : 
   11705        7390 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11706        7390 :                     n->cfgname = $5;
   11707        7390 :                     n->tokentype = $9;
   11708        7390 :                     n->dicts = $11;
   11709        7390 :                     n->override = false;
   11710        7390 :                     n->replace = false;
   11711        7390 :                     $$ = (Node *) n;
   11712             :                 }
   11713             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11714             :                 {
   11715          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11716             : 
   11717          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11718          26 :                     n->cfgname = $5;
   11719          26 :                     n->tokentype = $9;
   11720          26 :                     n->dicts = $11;
   11721          26 :                     n->override = true;
   11722          26 :                     n->replace = false;
   11723          26 :                     $$ = (Node *) n;
   11724             :                 }
   11725             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11726             :                 {
   11727          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11728             : 
   11729          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11730          18 :                     n->cfgname = $5;
   11731          18 :                     n->tokentype = NIL;
   11732          18 :                     n->dicts = list_make2($9,$11);
   11733          18 :                     n->override = false;
   11734          18 :                     n->replace = true;
   11735          18 :                     $$ = (Node *) n;
   11736             :                 }
   11737             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11738             :                 {
   11739           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11740             : 
   11741           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11742           0 :                     n->cfgname = $5;
   11743           0 :                     n->tokentype = $9;
   11744           0 :                     n->dicts = list_make2($11,$13);
   11745           0 :                     n->override = false;
   11746           0 :                     n->replace = true;
   11747           0 :                     $$ = (Node *) n;
   11748             :                 }
   11749             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11750             :                 {
   11751          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11752             : 
   11753          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11754          18 :                     n->cfgname = $5;
   11755          18 :                     n->tokentype = $9;
   11756          18 :                     n->missing_ok = false;
   11757          18 :                     $$ = (Node *) n;
   11758             :                 }
   11759             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11760             :                 {
   11761          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11762             : 
   11763          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11764          12 :                     n->cfgname = $5;
   11765          12 :                     n->tokentype = $11;
   11766          12 :                     n->missing_ok = true;
   11767          12 :                     $$ = (Node *) n;
   11768             :                 }
   11769             :         ;
   11770             : 
   11771             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11772             : any_with:   WITH
   11773             :             | WITH_LA
   11774             :         ;
   11775             : 
   11776             : 
   11777             : /*****************************************************************************
   11778             :  *
   11779             :  * Manipulate a conversion
   11780             :  *
   11781             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11782             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11783             :  *
   11784             :  *****************************************************************************/
   11785             : 
   11786             : CreateConversionStmt:
   11787             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11788             :             TO Sconst FROM any_name
   11789             :             {
   11790          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11791             : 
   11792          64 :                 n->conversion_name = $4;
   11793          64 :                 n->for_encoding_name = $6;
   11794          64 :                 n->to_encoding_name = $8;
   11795          64 :                 n->func_name = $10;
   11796          64 :                 n->def = $2;
   11797          64 :                 $$ = (Node *) n;
   11798             :             }
   11799             :         ;
   11800             : 
   11801             : /*****************************************************************************
   11802             :  *
   11803             :  *      QUERY:
   11804             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11805             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11806             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11807             :  *
   11808             :  *****************************************************************************/
   11809             : 
   11810             : ClusterStmt:
   11811             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11812             :                 {
   11813           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11814             : 
   11815           0 :                     n->relation = $5;
   11816           0 :                     n->indexname = $6;
   11817           0 :                     n->params = $3;
   11818           0 :                     $$ = (Node *) n;
   11819             :                 }
   11820             :             | CLUSTER '(' utility_option_list ')'
   11821             :                 {
   11822           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11823             : 
   11824           0 :                     n->relation = NULL;
   11825           0 :                     n->indexname = NULL;
   11826           0 :                     n->params = $3;
   11827           0 :                     $$ = (Node *) n;
   11828             :                 }
   11829             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11830             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11831             :                 {
   11832         190 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11833             : 
   11834         190 :                     n->relation = $3;
   11835         190 :                     n->indexname = $4;
   11836         190 :                     n->params = NIL;
   11837         190 :                     if ($2)
   11838           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11839         190 :                     $$ = (Node *) n;
   11840             :                 }
   11841             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11842             :             | CLUSTER opt_verbose
   11843             :                 {
   11844          28 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11845             : 
   11846          28 :                     n->relation = NULL;
   11847          28 :                     n->indexname = NULL;
   11848          28 :                     n->params = NIL;
   11849          28 :                     if ($2)
   11850          12 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11851          28 :                     $$ = (Node *) n;
   11852             :                 }
   11853             :             /* kept for pre-8.3 compatibility */
   11854             :             | CLUSTER opt_verbose name ON qualified_name
   11855             :                 {
   11856          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11857             : 
   11858          18 :                     n->relation = $5;
   11859          18 :                     n->indexname = $3;
   11860          18 :                     n->params = NIL;
   11861          18 :                     if ($2)
   11862           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11863          18 :                     $$ = (Node *) n;
   11864             :                 }
   11865             :         ;
   11866             : 
   11867             : cluster_index_specification:
   11868         156 :             USING name              { $$ = $2; }
   11869          34 :             | /*EMPTY*/             { $$ = NULL; }
   11870             :         ;
   11871             : 
   11872             : 
   11873             : /*****************************************************************************
   11874             :  *
   11875             :  *      QUERY:
   11876             :  *              VACUUM
   11877             :  *              ANALYZE
   11878             :  *
   11879             :  *****************************************************************************/
   11880             : 
   11881             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11882             :                 {
   11883        1176 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11884             : 
   11885        1176 :                     n->options = NIL;
   11886        1176 :                     if ($2)
   11887         136 :                         n->options = lappend(n->options,
   11888         136 :                                              makeDefElem("full", NULL, @2));
   11889        1176 :                     if ($3)
   11890         158 :                         n->options = lappend(n->options,
   11891         158 :                                              makeDefElem("freeze", NULL, @3));
   11892        1176 :                     if ($4)
   11893          18 :                         n->options = lappend(n->options,
   11894          18 :                                              makeDefElem("verbose", NULL, @4));
   11895        1176 :                     if ($5)
   11896         284 :                         n->options = lappend(n->options,
   11897         284 :                                              makeDefElem("analyze", NULL, @5));
   11898        1176 :                     n->rels = $6;
   11899        1176 :                     n->is_vacuumcmd = true;
   11900        1176 :                     $$ = (Node *) n;
   11901             :                 }
   11902             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11903             :                 {
   11904        4964 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11905             : 
   11906        4964 :                     n->options = $3;
   11907        4964 :                     n->rels = $5;
   11908        4964 :                     n->is_vacuumcmd = true;
   11909        4964 :                     $$ = (Node *) n;
   11910             :                 }
   11911             :         ;
   11912             : 
   11913             : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   11914             :                 {
   11915        4424 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11916             : 
   11917        4424 :                     n->options = NIL;
   11918        4424 :                     if ($2)
   11919           0 :                         n->options = lappend(n->options,
   11920           0 :                                              makeDefElem("verbose", NULL, @2));
   11921        4424 :                     n->rels = $3;
   11922        4424 :                     n->is_vacuumcmd = false;
   11923        4424 :                     $$ = (Node *) n;
   11924             :                 }
   11925             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   11926             :                 {
   11927         186 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11928             : 
   11929         186 :                     n->options = $3;
   11930         186 :                     n->rels = $5;
   11931         186 :                     n->is_vacuumcmd = false;
   11932         186 :                     $$ = (Node *) n;
   11933             :                 }
   11934             :         ;
   11935             : 
   11936             : utility_option_list:
   11937             :             utility_option_elem
   11938             :                 {
   11939       18642 :                     $$ = list_make1($1);
   11940             :                 }
   11941             :             | utility_option_list ',' utility_option_elem
   11942             :                 {
   11943        9496 :                     $$ = lappend($1, $3);
   11944             :                 }
   11945             :         ;
   11946             : 
   11947             : analyze_keyword:
   11948             :             ANALYZE
   11949             :             | ANALYSE /* British */
   11950             :         ;
   11951             : 
   11952             : utility_option_elem:
   11953             :             utility_option_name utility_option_arg
   11954             :                 {
   11955       28138 :                     $$ = makeDefElem($1, $2, @1);
   11956             :                 }
   11957             :         ;
   11958             : 
   11959             : utility_option_name:
   11960       25756 :             NonReservedWord                         { $$ = $1; }
   11961        2240 :             | analyze_keyword                       { $$ = "analyze"; }
   11962         148 :             | FORMAT_LA                             { $$ = "format"; }
   11963             :         ;
   11964             : 
   11965             : utility_option_arg:
   11966       16800 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   11967         368 :             | NumericOnly                           { $$ = (Node *) $1; }
   11968       10970 :             | /* EMPTY */                           { $$ = NULL; }
   11969             :         ;
   11970             : 
   11971             : opt_analyze:
   11972         284 :             analyze_keyword                         { $$ = true; }
   11973         892 :             | /*EMPTY*/                             { $$ = false; }
   11974             :         ;
   11975             : 
   11976             : opt_verbose:
   11977          30 :             VERBOSE                                 { $$ = true; }
   11978        8098 :             | /*EMPTY*/                             { $$ = false; }
   11979             :         ;
   11980             : 
   11981         136 : opt_full:   FULL                                    { $$ = true; }
   11982        1040 :             | /*EMPTY*/                             { $$ = false; }
   11983             :         ;
   11984             : 
   11985         158 : opt_freeze: FREEZE                                  { $$ = true; }
   11986        1018 :             | /*EMPTY*/                             { $$ = false; }
   11987             :         ;
   11988             : 
   11989             : opt_name_list:
   11990        2504 :             '(' name_list ')'                       { $$ = $2; }
   11991       12734 :             | /*EMPTY*/                             { $$ = NIL; }
   11992             :         ;
   11993             : 
   11994             : vacuum_relation:
   11995             :             relation_expr opt_name_list
   11996             :                 {
   11997       10582 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   11998             :                 }
   11999             :         ;
   12000             : 
   12001             : vacuum_relation_list:
   12002             :             vacuum_relation
   12003       10434 :                     { $$ = list_make1($1); }
   12004             :             | vacuum_relation_list ',' vacuum_relation
   12005         148 :                     { $$ = lappend($1, $3); }
   12006             :         ;
   12007             : 
   12008             : opt_vacuum_relation_list:
   12009       10434 :             vacuum_relation_list                    { $$ = $1; }
   12010         316 :             | /*EMPTY*/                             { $$ = NIL; }
   12011             :         ;
   12012             : 
   12013             : 
   12014             : /*****************************************************************************
   12015             :  *
   12016             :  *      QUERY:
   12017             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12018             :  *              EXPLAIN ( options ) query
   12019             :  *
   12020             :  *****************************************************************************/
   12021             : 
   12022             : ExplainStmt:
   12023             :         EXPLAIN ExplainableStmt
   12024             :                 {
   12025        7646 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12026             : 
   12027        7646 :                     n->query = $2;
   12028        7646 :                     n->options = NIL;
   12029        7646 :                     $$ = (Node *) n;
   12030             :                 }
   12031             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12032             :                 {
   12033        2292 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12034             : 
   12035        2292 :                     n->query = $4;
   12036        2292 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12037        2292 :                     if ($3)
   12038           0 :                         n->options = lappend(n->options,
   12039           0 :                                              makeDefElem("verbose", NULL, @3));
   12040        2292 :                     $$ = (Node *) n;
   12041             :                 }
   12042             :         | EXPLAIN VERBOSE ExplainableStmt
   12043             :                 {
   12044           0 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12045             : 
   12046           0 :                     n->query = $3;
   12047           0 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12048           0 :                     $$ = (Node *) n;
   12049             :                 }
   12050             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12051             :                 {
   12052       13336 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12053             : 
   12054       13336 :                     n->query = $5;
   12055       13336 :                     n->options = $3;
   12056       13336 :                     $$ = (Node *) n;
   12057             :                 }
   12058             :         ;
   12059             : 
   12060             : ExplainableStmt:
   12061             :             SelectStmt
   12062             :             | InsertStmt
   12063             :             | UpdateStmt
   12064             :             | DeleteStmt
   12065             :             | MergeStmt
   12066             :             | DeclareCursorStmt
   12067             :             | CreateAsStmt
   12068             :             | CreateMatViewStmt
   12069             :             | RefreshMatViewStmt
   12070             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12071             :         ;
   12072             : 
   12073             : /*****************************************************************************
   12074             :  *
   12075             :  *      QUERY:
   12076             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12077             :  *
   12078             :  *****************************************************************************/
   12079             : 
   12080             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12081             :                 {
   12082        1726 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12083             : 
   12084        1726 :                     n->name = $2;
   12085        1726 :                     n->argtypes = $3;
   12086        1726 :                     n->query = $5;
   12087        1726 :                     $$ = (Node *) n;
   12088             :                 }
   12089             :         ;
   12090             : 
   12091        1418 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12092         326 :                 | /* EMPTY */               { $$ = NIL; }
   12093             :         ;
   12094             : 
   12095             : PreparableStmt:
   12096             :             SelectStmt
   12097             :             | InsertStmt
   12098             :             | UpdateStmt
   12099             :             | DeleteStmt
   12100             :             | MergeStmt                     /* by default all are $$=$1 */
   12101             :         ;
   12102             : 
   12103             : /*****************************************************************************
   12104             :  *
   12105             :  * EXECUTE <plan_name> [(params, ...)]
   12106             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12107             :  *
   12108             :  *****************************************************************************/
   12109             : 
   12110             : ExecuteStmt: EXECUTE name execute_param_clause
   12111             :                 {
   12112       15504 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12113             : 
   12114       15504 :                     n->name = $2;
   12115       15504 :                     n->params = $3;
   12116       15504 :                     $$ = (Node *) n;
   12117             :                 }
   12118             :             | CREATE OptTemp TABLE create_as_target AS
   12119             :                 EXECUTE name execute_param_clause opt_with_data
   12120             :                 {
   12121          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12122          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12123             : 
   12124          76 :                     n->name = $7;
   12125          76 :                     n->params = $8;
   12126          76 :                     ctas->query = (Node *) n;
   12127          76 :                     ctas->into = $4;
   12128          76 :                     ctas->objtype = OBJECT_TABLE;
   12129          76 :                     ctas->is_select_into = false;
   12130          76 :                     ctas->if_not_exists = false;
   12131             :                     /* cram additional flags into the IntoClause */
   12132          76 :                     $4->rel->relpersistence = $2;
   12133          76 :                     $4->skipData = !($9);
   12134          76 :                     $$ = (Node *) ctas;
   12135             :                 }
   12136             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12137             :                 EXECUTE name execute_param_clause opt_with_data
   12138             :                 {
   12139          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12140          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12141             : 
   12142          12 :                     n->name = $10;
   12143          12 :                     n->params = $11;
   12144          12 :                     ctas->query = (Node *) n;
   12145          12 :                     ctas->into = $7;
   12146          12 :                     ctas->objtype = OBJECT_TABLE;
   12147          12 :                     ctas->is_select_into = false;
   12148          12 :                     ctas->if_not_exists = true;
   12149             :                     /* cram additional flags into the IntoClause */
   12150          12 :                     $7->rel->relpersistence = $2;
   12151          12 :                     $7->skipData = !($12);
   12152          12 :                     $$ = (Node *) ctas;
   12153             :                 }
   12154             :         ;
   12155             : 
   12156       14450 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12157        1142 :                     | /* EMPTY */                   { $$ = NIL; }
   12158             :                     ;
   12159             : 
   12160             : /*****************************************************************************
   12161             :  *
   12162             :  *      QUERY:
   12163             :  *              DEALLOCATE [PREPARE] <plan_name>
   12164             :  *
   12165             :  *****************************************************************************/
   12166             : 
   12167             : DeallocateStmt: DEALLOCATE name
   12168             :                     {
   12169        3978 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12170             : 
   12171        3978 :                         n->name = $2;
   12172        3978 :                         n->isall = false;
   12173        3978 :                         n->location = @2;
   12174        3978 :                         $$ = (Node *) n;
   12175             :                     }
   12176             :                 | DEALLOCATE PREPARE name
   12177             :                     {
   12178          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12179             : 
   12180          20 :                         n->name = $3;
   12181          20 :                         n->isall = false;
   12182          20 :                         n->location = @3;
   12183          20 :                         $$ = (Node *) n;
   12184             :                     }
   12185             :                 | DEALLOCATE ALL
   12186             :                     {
   12187          54 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12188             : 
   12189          54 :                         n->name = NULL;
   12190          54 :                         n->isall = true;
   12191          54 :                         n->location = -1;
   12192          54 :                         $$ = (Node *) n;
   12193             :                     }
   12194             :                 | DEALLOCATE PREPARE ALL
   12195             :                     {
   12196           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12197             : 
   12198           2 :                         n->name = NULL;
   12199           2 :                         n->isall = true;
   12200           2 :                         n->location = -1;
   12201           2 :                         $$ = (Node *) n;
   12202             :                     }
   12203             :         ;
   12204             : 
   12205             : /*****************************************************************************
   12206             :  *
   12207             :  *      QUERY:
   12208             :  *              INSERT STATEMENTS
   12209             :  *
   12210             :  *****************************************************************************/
   12211             : 
   12212             : InsertStmt:
   12213             :             opt_with_clause INSERT INTO insert_target insert_rest
   12214             :             opt_on_conflict returning_clause
   12215             :                 {
   12216       73716 :                     $5->relation = $4;
   12217       73716 :                     $5->onConflictClause = $6;
   12218       73716 :                     $5->returningClause = $7;
   12219       73716 :                     $5->withClause = $1;
   12220       73716 :                     $5->stmt_location = @$;
   12221       73716 :                     $$ = (Node *) $5;
   12222             :                 }
   12223             :         ;
   12224             : 
   12225             : /*
   12226             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12227             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12228             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12229             :  * divergence from other places.  So just require AS for now.
   12230             :  */
   12231             : insert_target:
   12232             :             qualified_name
   12233             :                 {
   12234       73590 :                     $$ = $1;
   12235             :                 }
   12236             :             | qualified_name AS ColId
   12237             :                 {
   12238         132 :                     $1->alias = makeAlias($3, NIL);
   12239         132 :                     $$ = $1;
   12240             :                 }
   12241             :         ;
   12242             : 
   12243             : insert_rest:
   12244             :             SelectStmt
   12245             :                 {
   12246       48630 :                     $$ = makeNode(InsertStmt);
   12247       48630 :                     $$->cols = NIL;
   12248       48630 :                     $$->selectStmt = $1;
   12249             :                 }
   12250             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12251             :                 {
   12252          96 :                     $$ = makeNode(InsertStmt);
   12253          96 :                     $$->cols = NIL;
   12254          96 :                     $$->override = $2;
   12255          96 :                     $$->selectStmt = $4;
   12256             :                 }
   12257             :             | '(' insert_column_list ')' SelectStmt
   12258             :                 {
   12259       14182 :                     $$ = makeNode(InsertStmt);
   12260       14182 :                     $$->cols = $2;
   12261       14182 :                     $$->selectStmt = $4;
   12262             :                 }
   12263             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12264             :                 {
   12265           0 :                     $$ = makeNode(InsertStmt);
   12266           0 :                     $$->cols = $2;
   12267           0 :                     $$->override = $5;
   12268           0 :                     $$->selectStmt = $7;
   12269             :                 }
   12270             :             | DEFAULT VALUES
   12271             :                 {
   12272       10814 :                     $$ = makeNode(InsertStmt);
   12273       10814 :                     $$->cols = NIL;
   12274       10814 :                     $$->selectStmt = NULL;
   12275             :                 }
   12276             :         ;
   12277             : 
   12278             : override_kind:
   12279          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12280          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12281             :         ;
   12282             : 
   12283             : insert_column_list:
   12284             :             insert_column_item
   12285       14480 :                     { $$ = list_make1($1); }
   12286             :             | insert_column_list ',' insert_column_item
   12287       15818 :                     { $$ = lappend($1, $3); }
   12288             :         ;
   12289             : 
   12290             : insert_column_item:
   12291             :             ColId opt_indirection
   12292             :                 {
   12293       30298 :                     $$ = makeNode(ResTarget);
   12294       30298 :                     $$->name = $1;
   12295       30298 :                     $$->indirection = check_indirection($2, yyscanner);
   12296       30298 :                     $$->val = NULL;
   12297       30298 :                     $$->location = @1;
   12298             :                 }
   12299             :         ;
   12300             : 
   12301             : opt_on_conflict:
   12302             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12303             :                 {
   12304        1306 :                     $$ = makeNode(OnConflictClause);
   12305        1306 :                     $$->action = ONCONFLICT_UPDATE;
   12306        1306 :                     $$->infer = $3;
   12307        1306 :                     $$->targetList = $7;
   12308        1306 :                     $$->whereClause = $8;
   12309        1306 :                     $$->location = @1;
   12310             :                 }
   12311             :             |
   12312             :             ON CONFLICT opt_conf_expr DO NOTHING
   12313             :                 {
   12314         550 :                     $$ = makeNode(OnConflictClause);
   12315         550 :                     $$->action = ONCONFLICT_NOTHING;
   12316         550 :                     $$->infer = $3;
   12317         550 :                     $$->targetList = NIL;
   12318         550 :                     $$->whereClause = NULL;
   12319         550 :                     $$->location = @1;
   12320             :                 }
   12321             :             | /*EMPTY*/
   12322             :                 {
   12323       71866 :                     $$ = NULL;
   12324             :                 }
   12325             :         ;
   12326             : 
   12327             : opt_conf_expr:
   12328             :             '(' index_params ')' where_clause
   12329             :                 {
   12330        1430 :                     $$ = makeNode(InferClause);
   12331        1430 :                     $$->indexElems = $2;
   12332        1430 :                     $$->whereClause = $4;
   12333        1430 :                     $$->conname = NULL;
   12334        1430 :                     $$->location = @1;
   12335             :                 }
   12336             :             |
   12337             :             ON CONSTRAINT name
   12338             :                 {
   12339         192 :                     $$ = makeNode(InferClause);
   12340         192 :                     $$->indexElems = NIL;
   12341         192 :                     $$->whereClause = NULL;
   12342         192 :                     $$->conname = $3;
   12343         192 :                     $$->location = @1;
   12344             :                 }
   12345             :             | /*EMPTY*/
   12346             :                 {
   12347         234 :                     $$ = NULL;
   12348             :                 }
   12349             :         ;
   12350             : 
   12351             : returning_clause:
   12352             :             RETURNING returning_with_clause target_list
   12353             :                 {
   12354        3096 :                     ReturningClause *n = makeNode(ReturningClause);
   12355             : 
   12356        3096 :                     n->options = $2;
   12357        3096 :                     n->exprs = $3;
   12358        3096 :                     $$ = n;
   12359             :                 }
   12360             :             | /* EMPTY */
   12361             :                 {
   12362       91080 :                     $$ = NULL;
   12363             :                 }
   12364             :         ;
   12365             : 
   12366             : returning_with_clause:
   12367          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12368        3024 :             | /* EMPTY */                       { $$ = NIL; }
   12369             :         ;
   12370             : 
   12371             : returning_options:
   12372          72 :             returning_option                            { $$ = list_make1($1); }
   12373          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12374             :         ;
   12375             : 
   12376             : returning_option:
   12377             :             returning_option_kind AS ColId
   12378             :                 {
   12379         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12380             : 
   12381         126 :                     n->option = $1;
   12382         126 :                     n->value = $3;
   12383         126 :                     n->location = @1;
   12384         126 :                     $$ = (Node *) n;
   12385             :                 }
   12386             :         ;
   12387             : 
   12388             : returning_option_kind:
   12389          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12390          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12391             :         ;
   12392             : 
   12393             : 
   12394             : /*****************************************************************************
   12395             :  *
   12396             :  *      QUERY:
   12397             :  *              DELETE STATEMENTS
   12398             :  *
   12399             :  *****************************************************************************/
   12400             : 
   12401             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12402             :             using_clause where_or_current_clause returning_clause
   12403             :                 {
   12404        4686 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12405             : 
   12406        4686 :                     n->relation = $4;
   12407        4686 :                     n->usingClause = $5;
   12408        4686 :                     n->whereClause = $6;
   12409        4686 :                     n->returningClause = $7;
   12410        4686 :                     n->withClause = $1;
   12411        4686 :                     n->stmt_location = @$;
   12412        4686 :                     $$ = (Node *) n;
   12413             :                 }
   12414             :         ;
   12415             : 
   12416             : using_clause:
   12417         108 :                 USING from_list                     { $$ = $2; }
   12418        4578 :             | /*EMPTY*/                             { $$ = NIL; }
   12419             :         ;
   12420             : 
   12421             : 
   12422             : /*****************************************************************************
   12423             :  *
   12424             :  *      QUERY:
   12425             :  *              LOCK TABLE
   12426             :  *
   12427             :  *****************************************************************************/
   12428             : 
   12429             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12430             :                 {
   12431        1088 :                     LockStmt   *n = makeNode(LockStmt);
   12432             : 
   12433        1088 :                     n->relations = $3;
   12434        1088 :                     n->mode = $4;
   12435        1088 :                     n->nowait = $5;
   12436        1088 :                     $$ = (Node *) n;
   12437             :                 }
   12438             :         ;
   12439             : 
   12440         992 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12441          96 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12442             :         ;
   12443             : 
   12444         502 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12445          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12446          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12447          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12448          80 :             | SHARE                         { $$ = ShareLock; }
   12449          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12450         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12451         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12452             :         ;
   12453             : 
   12454         286 : opt_nowait: NOWAIT                          { $$ = true; }
   12455         832 :             | /*EMPTY*/                     { $$ = false; }
   12456             :         ;
   12457             : 
   12458             : opt_nowait_or_skip:
   12459          50 :             NOWAIT                          { $$ = LockWaitError; }
   12460         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12461        5100 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12462             :         ;
   12463             : 
   12464             : 
   12465             : /*****************************************************************************
   12466             :  *
   12467             :  *      QUERY:
   12468             :  *              UpdateStmt (UPDATE)
   12469             :  *
   12470             :  *****************************************************************************/
   12471             : 
   12472             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12473             :             SET set_clause_list
   12474             :             from_clause
   12475             :             where_or_current_clause
   12476             :             returning_clause
   12477             :                 {
   12478       13752 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12479             : 
   12480       13752 :                     n->relation = $3;
   12481       13752 :                     n->targetList = $5;
   12482       13752 :                     n->fromClause = $6;
   12483       13752 :                     n->whereClause = $7;
   12484       13752 :                     n->returningClause = $8;
   12485       13752 :                     n->withClause = $1;
   12486       13752 :                     n->stmt_location = @$;
   12487       13752 :                     $$ = (Node *) n;
   12488             :                 }
   12489             :         ;
   12490             : 
   12491             : set_clause_list:
   12492       16608 :             set_clause                          { $$ = $1; }
   12493        3910 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12494             :         ;
   12495             : 
   12496             : set_clause:
   12497             :             set_target '=' a_expr
   12498             :                 {
   12499       20334 :                     $1->val = (Node *) $3;
   12500       20334 :                     $$ = list_make1($1);
   12501             :                 }
   12502             :             | '(' set_target_list ')' '=' a_expr
   12503             :                 {
   12504         184 :                     int         ncolumns = list_length($2);
   12505         184 :                     int         i = 1;
   12506             :                     ListCell   *col_cell;
   12507             : 
   12508             :                     /* Create a MultiAssignRef source for each target */
   12509         568 :                     foreach(col_cell, $2)
   12510             :                     {
   12511         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12512         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12513             : 
   12514         384 :                         r->source = (Node *) $5;
   12515         384 :                         r->colno = i;
   12516         384 :                         r->ncolumns = ncolumns;
   12517         384 :                         res_col->val = (Node *) r;
   12518         384 :                         i++;
   12519             :                     }
   12520             : 
   12521         184 :                     $$ = $2;
   12522             :                 }
   12523             :         ;
   12524             : 
   12525             : set_target:
   12526             :             ColId opt_indirection
   12527             :                 {
   12528       20724 :                     $$ = makeNode(ResTarget);
   12529       20724 :                     $$->name = $1;
   12530       20724 :                     $$->indirection = check_indirection($2, yyscanner);
   12531       20724 :                     $$->val = NULL;  /* upper production sets this */
   12532       20724 :                     $$->location = @1;
   12533             :                 }
   12534             :         ;
   12535             : 
   12536             : set_target_list:
   12537         190 :             set_target                              { $$ = list_make1($1); }
   12538         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12539             :         ;
   12540             : 
   12541             : 
   12542             : /*****************************************************************************
   12543             :  *
   12544             :  *      QUERY:
   12545             :  *              MERGE
   12546             :  *
   12547             :  *****************************************************************************/
   12548             : 
   12549             : MergeStmt:
   12550             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12551             :             USING table_ref
   12552             :             ON a_expr
   12553             :             merge_when_list
   12554             :             returning_clause
   12555             :                 {
   12556        2022 :                     MergeStmt  *m = makeNode(MergeStmt);
   12557             : 
   12558        2022 :                     m->withClause = $1;
   12559        2022 :                     m->relation = $4;
   12560        2022 :                     m->sourceRelation = $6;
   12561        2022 :                     m->joinCondition = $8;
   12562        2022 :                     m->mergeWhenClauses = $9;
   12563        2022 :                     m->returningClause = $10;
   12564        2022 :                     m->stmt_location = @$;
   12565             : 
   12566        2022 :                     $$ = (Node *) m;
   12567             :                 }
   12568             :         ;
   12569             : 
   12570             : merge_when_list:
   12571        2022 :             merge_when_clause                       { $$ = list_make1($1); }
   12572        1158 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12573             :         ;
   12574             : 
   12575             : /*
   12576             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12577             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12578             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12579             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12580             :  */
   12581             : merge_when_clause:
   12582             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12583             :                 {
   12584        1550 :                     $4->matchKind = $1;
   12585        1550 :                     $4->condition = $2;
   12586             : 
   12587        1550 :                     $$ = (Node *) $4;
   12588             :                 }
   12589             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12590             :                 {
   12591         518 :                     $4->matchKind = $1;
   12592         518 :                     $4->condition = $2;
   12593             : 
   12594         518 :                     $$ = (Node *) $4;
   12595             :                 }
   12596             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12597             :                 {
   12598        1034 :                     $4->matchKind = $1;
   12599        1034 :                     $4->condition = $2;
   12600             : 
   12601        1034 :                     $$ = (Node *) $4;
   12602             :                 }
   12603             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12604             :                 {
   12605          58 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12606             : 
   12607          58 :                     m->matchKind = $1;
   12608          58 :                     m->commandType = CMD_NOTHING;
   12609          58 :                     m->condition = $2;
   12610             : 
   12611          58 :                     $$ = (Node *) m;
   12612             :                 }
   12613             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12614             :                 {
   12615          20 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12616             : 
   12617          20 :                     m->matchKind = $1;
   12618          20 :                     m->commandType = CMD_NOTHING;
   12619          20 :                     m->condition = $2;
   12620             : 
   12621          20 :                     $$ = (Node *) m;
   12622             :                 }
   12623             :         ;
   12624             : 
   12625             : merge_when_tgt_matched:
   12626        1964 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12627         180 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12628             :         ;
   12629             : 
   12630             : merge_when_tgt_not_matched:
   12631        1060 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12632          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12633             :         ;
   12634             : 
   12635             : opt_merge_when_condition:
   12636         808 :             AND a_expr              { $$ = $2; }
   12637        2414 :             |                       { $$ = NULL; }
   12638             :         ;
   12639             : 
   12640             : merge_update:
   12641             :             UPDATE SET set_clause_list
   12642             :                 {
   12643        1550 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12644        1550 :                     n->commandType = CMD_UPDATE;
   12645        1550 :                     n->override = OVERRIDING_NOT_SET;
   12646        1550 :                     n->targetList = $3;
   12647        1550 :                     n->values = NIL;
   12648             : 
   12649        1550 :                     $$ = n;
   12650             :                 }
   12651             :         ;
   12652             : 
   12653             : merge_delete:
   12654             :             DELETE_P
   12655             :                 {
   12656         518 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12657         518 :                     n->commandType = CMD_DELETE;
   12658         518 :                     n->override = OVERRIDING_NOT_SET;
   12659         518 :                     n->targetList = NIL;
   12660         518 :                     n->values = NIL;
   12661             : 
   12662         518 :                     $$ = n;
   12663             :                 }
   12664             :         ;
   12665             : 
   12666             : merge_insert:
   12667             :             INSERT merge_values_clause
   12668             :                 {
   12669         700 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12670         700 :                     n->commandType = CMD_INSERT;
   12671         700 :                     n->override = OVERRIDING_NOT_SET;
   12672         700 :                     n->targetList = NIL;
   12673         700 :                     n->values = $2;
   12674         700 :                     $$ = n;
   12675             :                 }
   12676             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12677             :                 {
   12678           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12679           0 :                     n->commandType = CMD_INSERT;
   12680           0 :                     n->override = $3;
   12681           0 :                     n->targetList = NIL;
   12682           0 :                     n->values = $5;
   12683           0 :                     $$ = n;
   12684             :                 }
   12685             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12686             :                 {
   12687         268 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12688         268 :                     n->commandType = CMD_INSERT;
   12689         268 :                     n->override = OVERRIDING_NOT_SET;
   12690         268 :                     n->targetList = $3;
   12691         268 :                     n->values = $5;
   12692         268 :                     $$ = n;
   12693             :                 }
   12694             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12695             :                 {
   12696          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12697          30 :                     n->commandType = CMD_INSERT;
   12698          30 :                     n->override = $6;
   12699          30 :                     n->targetList = $3;
   12700          30 :                     n->values = $8;
   12701          30 :                     $$ = n;
   12702             :                 }
   12703             :             | INSERT DEFAULT VALUES
   12704             :                 {
   12705          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12706          36 :                     n->commandType = CMD_INSERT;
   12707          36 :                     n->override = OVERRIDING_NOT_SET;
   12708          36 :                     n->targetList = NIL;
   12709          36 :                     n->values = NIL;
   12710          36 :                     $$ = n;
   12711             :                 }
   12712             :         ;
   12713             : 
   12714             : merge_values_clause:
   12715             :             VALUES '(' expr_list ')'
   12716             :                 {
   12717         998 :                     $$ = $3;
   12718             :                 }
   12719             :         ;
   12720             : 
   12721             : /*****************************************************************************
   12722             :  *
   12723             :  *      QUERY:
   12724             :  *              CURSOR STATEMENTS
   12725             :  *
   12726             :  *****************************************************************************/
   12727             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12728             :                 {
   12729        2810 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12730             : 
   12731        2810 :                     n->portalname = $2;
   12732             :                     /* currently we always set FAST_PLAN option */
   12733        2810 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12734        2810 :                     n->query = $7;
   12735        2810 :                     $$ = (Node *) n;
   12736             :                 }
   12737             :         ;
   12738             : 
   12739       11008 : cursor_name:    name                        { $$ = $1; }
   12740             :         ;
   12741             : 
   12742        2810 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12743          24 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12744         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12745          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12746           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12747           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12748             :         ;
   12749             : 
   12750        2712 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12751          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12752           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12753             :         ;
   12754             : 
   12755             : /*****************************************************************************
   12756             :  *
   12757             :  *      QUERY:
   12758             :  *              SELECT STATEMENTS
   12759             :  *
   12760             :  *****************************************************************************/
   12761             : 
   12762             : /* A complete SELECT statement looks like this.
   12763             :  *
   12764             :  * The rule returns either a single SelectStmt node or a tree of them,
   12765             :  * representing a set-operation tree.
   12766             :  *
   12767             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12768             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12769             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12770             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12771             :  * the decision is staved off as long as possible: as long as we can keep
   12772             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12773             :  * it's no longer possible to do that will we decide that parens belong to
   12774             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12775             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12776             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12777             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12778             :  * SELECT viewpoint when we see the UNION.
   12779             :  *
   12780             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12781             :  * which represents a SELECT with at least one outer layer of parentheses,
   12782             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12783             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12784             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12785             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12786             :  * conflict with the select_with_parens productions are manually given
   12787             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12788             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12789             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12790             :  * precedence for this, which is a fairly arbitrary choice.
   12791             :  *
   12792             :  * To be able to define select_with_parens itself without ambiguity, we need
   12793             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12794             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12795             :  *
   12796             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12797             :  * with or without outer parentheses.
   12798             :  */
   12799             : 
   12800             : SelectStmt: select_no_parens            %prec UMINUS
   12801             :             | select_with_parens        %prec UMINUS
   12802             :         ;
   12803             : 
   12804             : select_with_parens:
   12805             :             '(' select_no_parens ')'
   12806             :                 {
   12807       57478 :                     SelectStmt *n = (SelectStmt *) $2;
   12808             : 
   12809             :                     /*
   12810             :                      * As SelectStmt's location starts at the SELECT keyword,
   12811             :                      * we need to track the length of the SelectStmt within
   12812             :                      * parentheses to be able to extract the relevant part
   12813             :                      * of the query.  Without this, the RawStmt's length would
   12814             :                      * be used and would include the closing parenthesis.
   12815             :                      */
   12816       57478 :                     n->stmt_len = @3 - @2;
   12817       57478 :                     $$ = $2;
   12818             :                 }
   12819         150 :             | '(' select_with_parens ')'            { $$ = $2; }
   12820             :         ;
   12821             : 
   12822             : /*
   12823             :  * This rule parses the equivalent of the standard's <query expression>.
   12824             :  * The duplicative productions are annoying, but hard to get rid of without
   12825             :  * creating shift/reduce conflicts.
   12826             :  *
   12827             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12828             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12829             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12830             :  * clause.
   12831             :  *  2002-08-28 bjm
   12832             :  */
   12833             : select_no_parens:
   12834      415238 :             simple_select                       { $$ = $1; }
   12835             :             | select_clause sort_clause
   12836             :                 {
   12837       62200 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12838             :                                         NULL, NULL,
   12839             :                                         yyscanner);
   12840       62200 :                     $$ = $1;
   12841             :                 }
   12842             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12843             :                 {
   12844        4896 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12845        4896 :                                         $4,
   12846             :                                         NULL,
   12847             :                                         yyscanner);
   12848        4896 :                     $$ = $1;
   12849             :                 }
   12850             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12851             :                 {
   12852        4738 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12853        4738 :                                         $3,
   12854             :                                         NULL,
   12855             :                                         yyscanner);
   12856        4726 :                     $$ = $1;
   12857             :                 }
   12858             :             | with_clause select_clause
   12859             :                 {
   12860        1964 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12861             :                                         NULL,
   12862        1964 :                                         $1,
   12863             :                                         yyscanner);
   12864        1964 :                     $$ = $2;
   12865             :                 }
   12866             :             | with_clause select_clause sort_clause
   12867             :                 {
   12868         478 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12869             :                                         NULL,
   12870         478 :                                         $1,
   12871             :                                         yyscanner);
   12872         478 :                     $$ = $2;
   12873             :                 }
   12874             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12875             :                 {
   12876           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12877           6 :                                         $5,
   12878           6 :                                         $1,
   12879             :                                         yyscanner);
   12880           6 :                     $$ = $2;
   12881             :                 }
   12882             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12883             :                 {
   12884          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12885          64 :                                         $4,
   12886          64 :                                         $1,
   12887             :                                         yyscanner);
   12888          64 :                     $$ = $2;
   12889             :                 }
   12890             :         ;
   12891             : 
   12892             : select_clause:
   12893      104472 :             simple_select                           { $$ = $1; }
   12894         578 :             | select_with_parens                    { $$ = $1; }
   12895             :         ;
   12896             : 
   12897             : /*
   12898             :  * This rule parses SELECT statements that can appear within set operations,
   12899             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12900             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12901             :  * operations to be ordered per the precedence specs at the head of this file.
   12902             :  *
   12903             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12904             :  * but can have parenthesized subclauses.
   12905             :  *
   12906             :  * It might appear that we could fold the first two alternatives into one
   12907             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12908             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12909             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12910             :  *
   12911             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12912             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12913             :  * to be parsed as
   12914             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12915             :  * not
   12916             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12917             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12918             :  * described as part of the select_no_parens production, not simple_select.
   12919             :  * This does not limit functionality, because you can reintroduce these
   12920             :  * clauses inside parentheses.
   12921             :  *
   12922             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12923             :  * However, this is not checked by the grammar; parse analysis must check it.
   12924             :  */
   12925             : simple_select:
   12926             :             SELECT opt_all_clause opt_target_list
   12927             :             into_clause from_clause where_clause
   12928             :             group_clause having_clause window_clause
   12929             :                 {
   12930      439020 :                     SelectStmt *n = makeNode(SelectStmt);
   12931             : 
   12932      439020 :                     n->targetList = $3;
   12933      439020 :                     n->intoClause = $4;
   12934      439020 :                     n->fromClause = $5;
   12935      439020 :                     n->whereClause = $6;
   12936      439020 :                     n->groupClause = ($7)->list;
   12937      439020 :                     n->groupDistinct = ($7)->distinct;
   12938      439020 :                     n->havingClause = $8;
   12939      439020 :                     n->windowClause = $9;
   12940      439020 :                     n->stmt_location = @1;
   12941      439020 :                     $$ = (Node *) n;
   12942             :                 }
   12943             :             | SELECT distinct_clause target_list
   12944             :             into_clause from_clause where_clause
   12945             :             group_clause having_clause window_clause
   12946             :                 {
   12947        3356 :                     SelectStmt *n = makeNode(SelectStmt);
   12948             : 
   12949        3356 :                     n->distinctClause = $2;
   12950        3356 :                     n->targetList = $3;
   12951        3356 :                     n->intoClause = $4;
   12952        3356 :                     n->fromClause = $5;
   12953        3356 :                     n->whereClause = $6;
   12954        3356 :                     n->groupClause = ($7)->list;
   12955        3356 :                     n->groupDistinct = ($7)->distinct;
   12956        3356 :                     n->havingClause = $8;
   12957        3356 :                     n->windowClause = $9;
   12958        3356 :                     n->stmt_location = @1;
   12959        3356 :                     $$ = (Node *) n;
   12960             :                 }
   12961       61710 :             | values_clause                         { $$ = $1; }
   12962             :             | TABLE relation_expr
   12963             :                 {
   12964             :                     /* same as SELECT * FROM relation_expr */
   12965         278 :                     ColumnRef  *cr = makeNode(ColumnRef);
   12966         278 :                     ResTarget  *rt = makeNode(ResTarget);
   12967         278 :                     SelectStmt *n = makeNode(SelectStmt);
   12968             : 
   12969         278 :                     cr->fields = list_make1(makeNode(A_Star));
   12970         278 :                     cr->location = -1;
   12971             : 
   12972         278 :                     rt->name = NULL;
   12973         278 :                     rt->indirection = NIL;
   12974         278 :                     rt->val = (Node *) cr;
   12975         278 :                     rt->location = -1;
   12976             : 
   12977         278 :                     n->targetList = list_make1(rt);
   12978         278 :                     n->fromClause = list_make1($2);
   12979         278 :                     n->stmt_location = @1;
   12980         278 :                     $$ = (Node *) n;
   12981             :                 }
   12982             :             | select_clause UNION set_quantifier select_clause
   12983             :                 {
   12984       14588 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   12985             :                 }
   12986             :             | select_clause INTERSECT set_quantifier select_clause
   12987             :                 {
   12988         258 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   12989             :                 }
   12990             :             | select_clause EXCEPT set_quantifier select_clause
   12991             :                 {
   12992         500 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   12993             :                 }
   12994             :         ;
   12995             : 
   12996             : /*
   12997             :  * SQL standard WITH clause looks like:
   12998             :  *
   12999             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13000             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13001             :  *
   13002             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13003             :  */
   13004             : with_clause:
   13005             :         WITH cte_list
   13006             :             {
   13007        1796 :                 $$ = makeNode(WithClause);
   13008        1796 :                 $$->ctes = $2;
   13009        1796 :                 $$->recursive = false;
   13010        1796 :                 $$->location = @1;
   13011             :             }
   13012             :         | WITH_LA cte_list
   13013             :             {
   13014           6 :                 $$ = makeNode(WithClause);
   13015           6 :                 $$->ctes = $2;
   13016           6 :                 $$->recursive = false;
   13017           6 :                 $$->location = @1;
   13018             :             }
   13019             :         | WITH RECURSIVE cte_list
   13020             :             {
   13021        1132 :                 $$ = makeNode(WithClause);
   13022        1132 :                 $$->ctes = $3;
   13023        1132 :                 $$->recursive = true;
   13024        1132 :                 $$->location = @1;
   13025             :             }
   13026             :         ;
   13027             : 
   13028             : cte_list:
   13029        2934 :         common_table_expr                       { $$ = list_make1($1); }
   13030        1042 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13031             :         ;
   13032             : 
   13033             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13034             :             {
   13035        3976 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13036             : 
   13037        3976 :                 n->ctename = $1;
   13038        3976 :                 n->aliascolnames = $2;
   13039        3976 :                 n->ctematerialized = $4;
   13040        3976 :                 n->ctequery = $6;
   13041        3976 :                 n->search_clause = castNode(CTESearchClause, $8);
   13042        3976 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13043        3976 :                 n->location = @1;
   13044        3976 :                 $$ = (Node *) n;
   13045             :             }
   13046             :         ;
   13047             : 
   13048             : opt_materialized:
   13049         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13050          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13051        3750 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13052             :         ;
   13053             : 
   13054             : opt_search_clause:
   13055             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13056             :             {
   13057          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13058             : 
   13059          90 :                 n->search_col_list = $5;
   13060          90 :                 n->search_breadth_first = false;
   13061          90 :                 n->search_seq_column = $7;
   13062          90 :                 n->location = @1;
   13063          90 :                 $$ = (Node *) n;
   13064             :             }
   13065             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13066             :             {
   13067          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13068             : 
   13069          36 :                 n->search_col_list = $5;
   13070          36 :                 n->search_breadth_first = true;
   13071          36 :                 n->search_seq_column = $7;
   13072          36 :                 n->location = @1;
   13073          36 :                 $$ = (Node *) n;
   13074             :             }
   13075             :         | /*EMPTY*/
   13076             :             {
   13077        3850 :                 $$ = NULL;
   13078             :             }
   13079             :         ;
   13080             : 
   13081             : opt_cycle_clause:
   13082             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13083             :             {
   13084          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13085             : 
   13086          66 :                 n->cycle_col_list = $2;
   13087          66 :                 n->cycle_mark_column = $4;
   13088          66 :                 n->cycle_mark_value = $6;
   13089          66 :                 n->cycle_mark_default = $8;
   13090          66 :                 n->cycle_path_column = $10;
   13091          66 :                 n->location = @1;
   13092          66 :                 $$ = (Node *) n;
   13093             :             }
   13094             :         | CYCLE columnList SET ColId USING ColId
   13095             :             {
   13096          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13097             : 
   13098          60 :                 n->cycle_col_list = $2;
   13099          60 :                 n->cycle_mark_column = $4;
   13100          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13101          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13102          60 :                 n->cycle_path_column = $6;
   13103          60 :                 n->location = @1;
   13104          60 :                 $$ = (Node *) n;
   13105             :             }
   13106             :         | /*EMPTY*/
   13107             :             {
   13108        3850 :                 $$ = NULL;
   13109             :             }
   13110             :         ;
   13111             : 
   13112             : opt_with_clause:
   13113         422 :         with_clause                             { $$ = $1; }
   13114       93870 :         | /*EMPTY*/                             { $$ = NULL; }
   13115             :         ;
   13116             : 
   13117             : into_clause:
   13118             :             INTO OptTempTableName
   13119             :                 {
   13120         132 :                     $$ = makeNode(IntoClause);
   13121         132 :                     $$->rel = $2;
   13122         132 :                     $$->colNames = NIL;
   13123         132 :                     $$->options = NIL;
   13124         132 :                     $$->onCommit = ONCOMMIT_NOOP;
   13125         132 :                     $$->tableSpaceName = NULL;
   13126         132 :                     $$->viewQuery = NULL;
   13127         132 :                     $$->skipData = false;
   13128             :                 }
   13129             :             | /*EMPTY*/
   13130      442268 :                 { $$ = NULL; }
   13131             :         ;
   13132             : 
   13133             : /*
   13134             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13135             :  * since TEMP is not a reserved word.  See also OptTemp.
   13136             :  */
   13137             : OptTempTableName:
   13138             :             TEMPORARY opt_table qualified_name
   13139             :                 {
   13140           0 :                     $$ = $3;
   13141           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13142             :                 }
   13143             :             | TEMP opt_table qualified_name
   13144             :                 {
   13145           6 :                     $$ = $3;
   13146           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13147             :                 }
   13148             :             | LOCAL TEMPORARY opt_table qualified_name
   13149             :                 {
   13150           0 :                     $$ = $4;
   13151           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13152             :                 }
   13153             :             | LOCAL TEMP opt_table qualified_name
   13154             :                 {
   13155           0 :                     $$ = $4;
   13156           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13157             :                 }
   13158             :             | GLOBAL TEMPORARY opt_table qualified_name
   13159             :                 {
   13160           0 :                     ereport(WARNING,
   13161             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13162             :                              parser_errposition(@1)));
   13163           0 :                     $$ = $4;
   13164           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13165             :                 }
   13166             :             | GLOBAL TEMP opt_table qualified_name
   13167             :                 {
   13168           0 :                     ereport(WARNING,
   13169             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13170             :                              parser_errposition(@1)));
   13171           0 :                     $$ = $4;
   13172           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13173             :                 }
   13174             :             | UNLOGGED opt_table qualified_name
   13175             :                 {
   13176           0 :                     $$ = $3;
   13177           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13178             :                 }
   13179             :             | TABLE qualified_name
   13180             :                 {
   13181          30 :                     $$ = $2;
   13182          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13183             :                 }
   13184             :             | qualified_name
   13185             :                 {
   13186          96 :                     $$ = $1;
   13187          96 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13188             :                 }
   13189             :         ;
   13190             : 
   13191             : opt_table:  TABLE
   13192             :             | /*EMPTY*/
   13193             :         ;
   13194             : 
   13195             : set_quantifier:
   13196        6976 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13197          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13198       12912 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13199             :         ;
   13200             : 
   13201             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13202             :  * should be placed in the DISTINCT list during parsetree analysis.
   13203             :  */
   13204             : distinct_clause:
   13205        3112 :             DISTINCT                                { $$ = list_make1(NIL); }
   13206         250 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13207             :         ;
   13208             : 
   13209             : opt_all_clause:
   13210             :             ALL
   13211             :             | /*EMPTY*/
   13212             :         ;
   13213             : 
   13214             : opt_distinct_clause:
   13215           0 :             distinct_clause                         { $$ = $1; }
   13216       40162 :             | opt_all_clause                        { $$ = NIL; }
   13217             :         ;
   13218             : 
   13219             : opt_sort_clause:
   13220        6718 :             sort_clause                             { $$ = $1; }
   13221      349968 :             | /*EMPTY*/                             { $$ = NIL; }
   13222             :         ;
   13223             : 
   13224             : sort_clause:
   13225       69744 :             ORDER BY sortby_list                    { $$ = $3; }
   13226             :         ;
   13227             : 
   13228             : sortby_list:
   13229       69762 :             sortby                                  { $$ = list_make1($1); }
   13230       26702 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13231             :         ;
   13232             : 
   13233             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13234             :                 {
   13235         220 :                     $$ = makeNode(SortBy);
   13236         220 :                     $$->node = $1;
   13237         220 :                     $$->sortby_dir = SORTBY_USING;
   13238         220 :                     $$->sortby_nulls = $4;
   13239         220 :                     $$->useOp = $3;
   13240         220 :                     $$->location = @3;
   13241             :                 }
   13242             :             | a_expr opt_asc_desc opt_nulls_order
   13243             :                 {
   13244       96244 :                     $$ = makeNode(SortBy);
   13245       96244 :                     $$->node = $1;
   13246       96244 :                     $$->sortby_dir = $2;
   13247       96244 :                     $$->sortby_nulls = $3;
   13248       96244 :                     $$->useOp = NIL;
   13249       96244 :                     $$->location = -1;       /* no operator */
   13250             :                 }
   13251             :         ;
   13252             : 
   13253             : 
   13254             : select_limit:
   13255             :             limit_clause offset_clause
   13256             :                 {
   13257         168 :                     $$ = $1;
   13258         168 :                     ($$)->limitOffset = $2;
   13259         168 :                     ($$)->offsetLoc = @2;
   13260             :                 }
   13261             :             | offset_clause limit_clause
   13262             :                 {
   13263         214 :                     $$ = $2;
   13264         214 :                     ($$)->limitOffset = $1;
   13265         214 :                     ($$)->offsetLoc = @1;
   13266             :                 }
   13267             :             | limit_clause
   13268             :                 {
   13269        4212 :                     $$ = $1;
   13270             :                 }
   13271             :             | offset_clause
   13272             :                 {
   13273         398 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13274             : 
   13275         398 :                     n->limitOffset = $1;
   13276         398 :                     n->limitCount = NULL;
   13277         398 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13278         398 :                     n->offsetLoc = @1;
   13279         398 :                     n->countLoc = -1;
   13280         398 :                     n->optionLoc = -1;
   13281         398 :                     $$ = n;
   13282             :                 }
   13283             :         ;
   13284             : 
   13285             : opt_select_limit:
   13286         190 :             select_limit                        { $$ = $1; }
   13287       44874 :             | /* EMPTY */                       { $$ = NULL; }
   13288             :         ;
   13289             : 
   13290             : limit_clause:
   13291             :             LIMIT select_limit_value
   13292             :                 {
   13293        4510 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13294             : 
   13295        4510 :                     n->limitOffset = NULL;
   13296        4510 :                     n->limitCount = $2;
   13297        4510 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13298        4510 :                     n->offsetLoc = -1;
   13299        4510 :                     n->countLoc = @1;
   13300        4510 :                     n->optionLoc = -1;
   13301        4510 :                     $$ = n;
   13302             :                 }
   13303             :             | LIMIT select_limit_value ',' select_offset_value
   13304             :                 {
   13305             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13306           0 :                     ereport(ERROR,
   13307             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13308             :                              errmsg("LIMIT #,# syntax is not supported"),
   13309             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13310             :                              parser_errposition(@1)));
   13311             :                 }
   13312             :             /* SQL:2008 syntax */
   13313             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13314             :              * a separate production rather than an opt_ expression.  The fact
   13315             :              * that ONLY is fully reserved means that this way, we defer any
   13316             :              * decision about what rule reduces ROW or ROWS to the point where
   13317             :              * we can see the ONLY token in the lookahead slot.
   13318             :              */
   13319             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13320             :                 {
   13321          20 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13322             : 
   13323          20 :                     n->limitOffset = NULL;
   13324          20 :                     n->limitCount = $3;
   13325          20 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13326          20 :                     n->offsetLoc = -1;
   13327          20 :                     n->countLoc = @1;
   13328          20 :                     n->optionLoc = -1;
   13329          20 :                     $$ = n;
   13330             :                 }
   13331             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13332             :                 {
   13333          58 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13334             : 
   13335          58 :                     n->limitOffset = NULL;
   13336          58 :                     n->limitCount = $3;
   13337          58 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13338          58 :                     n->offsetLoc = -1;
   13339          58 :                     n->countLoc = @1;
   13340          58 :                     n->optionLoc = @5;
   13341          58 :                     $$ = n;
   13342             :                 }
   13343             :             | FETCH first_or_next row_or_rows ONLY
   13344             :                 {
   13345           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13346             : 
   13347           0 :                     n->limitOffset = NULL;
   13348           0 :                     n->limitCount = makeIntConst(1, -1);
   13349           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13350           0 :                     n->offsetLoc = -1;
   13351           0 :                     n->countLoc = @1;
   13352           0 :                     n->optionLoc = -1;
   13353           0 :                     $$ = n;
   13354             :                 }
   13355             :             | FETCH first_or_next row_or_rows WITH TIES
   13356             :                 {
   13357           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13358             : 
   13359           6 :                     n->limitOffset = NULL;
   13360           6 :                     n->limitCount = makeIntConst(1, -1);
   13361           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13362           6 :                     n->offsetLoc = -1;
   13363           6 :                     n->countLoc = @1;
   13364           6 :                     n->optionLoc = @4;
   13365           6 :                     $$ = n;
   13366             :                 }
   13367             :         ;
   13368             : 
   13369             : offset_clause:
   13370             :             OFFSET select_offset_value
   13371         780 :                 { $$ = $2; }
   13372             :             /* SQL:2008 syntax */
   13373             :             | OFFSET select_fetch_first_value row_or_rows
   13374           0 :                 { $$ = $2; }
   13375             :         ;
   13376             : 
   13377             : select_limit_value:
   13378        4508 :             a_expr                                  { $$ = $1; }
   13379             :             | ALL
   13380             :                 {
   13381             :                     /* LIMIT ALL is represented as a NULL constant */
   13382           2 :                     $$ = makeNullAConst(@1);
   13383             :                 }
   13384             :         ;
   13385             : 
   13386             : select_offset_value:
   13387         780 :             a_expr                                  { $$ = $1; }
   13388             :         ;
   13389             : 
   13390             : /*
   13391             :  * Allowing full expressions without parentheses causes various parsing
   13392             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13393             :  * <simple value specification>, which is either a literal or a parameter (but
   13394             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13395             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13396             :  * to determine whether the expression is missing rather than trying to make it
   13397             :  * optional in this rule.
   13398             :  *
   13399             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13400             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13401             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13402             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13403             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13404             :  * builds.)
   13405             :  */
   13406             : select_fetch_first_value:
   13407          78 :             c_expr                                  { $$ = $1; }
   13408             :             | '+' I_or_F_const
   13409           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13410             :             | '-' I_or_F_const
   13411           0 :                 { $$ = doNegate($2, @1); }
   13412             :         ;
   13413             : 
   13414             : I_or_F_const:
   13415           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13416           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13417             :         ;
   13418             : 
   13419             : /* noise words */
   13420          32 : row_or_rows: ROW                                    { $$ = 0; }
   13421          52 :             | ROWS                                  { $$ = 0; }
   13422             :         ;
   13423             : 
   13424          84 : first_or_next: FIRST_P                              { $$ = 0; }
   13425           0 :             | NEXT                                  { $$ = 0; }
   13426             :         ;
   13427             : 
   13428             : 
   13429             : /*
   13430             :  * This syntax for group_clause tries to follow the spec quite closely.
   13431             :  * However, the spec allows only column references, not expressions,
   13432             :  * which introduces an ambiguity between implicit row constructors
   13433             :  * (a,b) and lists of column references.
   13434             :  *
   13435             :  * We handle this by using the a_expr production for what the spec calls
   13436             :  * <ordinary grouping set>, which in the spec represents either one column
   13437             :  * reference or a parenthesized list of column references. Then, we check the
   13438             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13439             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13440             :  * not here)
   13441             :  *
   13442             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13443             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13444             :  * in a group clause, but if they have a reason to, we make it possible.)
   13445             :  *
   13446             :  * Each item in the group_clause list is either an expression tree or a
   13447             :  * GroupingSet node of some type.
   13448             :  */
   13449             : group_clause:
   13450             :             GROUP_P BY set_quantifier group_by_list
   13451             :                 {
   13452        4562 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13453             : 
   13454        4562 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13455        4562 :                     n->list = $4;
   13456        4562 :                     $$ = n;
   13457             :                 }
   13458             :             | /*EMPTY*/
   13459             :                 {
   13460      477976 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13461             : 
   13462      477976 :                     n->distinct = false;
   13463      477976 :                     n->list = NIL;
   13464      477976 :                     $$ = n;
   13465             :                 }
   13466             :         ;
   13467             : 
   13468             : group_by_list:
   13469        5136 :             group_by_item                           { $$ = list_make1($1); }
   13470        2926 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13471             :         ;
   13472             : 
   13473             : group_by_item:
   13474        6796 :             a_expr                                  { $$ = $1; }
   13475         222 :             | empty_grouping_set                    { $$ = $1; }
   13476         184 :             | cube_clause                           { $$ = $1; }
   13477         286 :             | rollup_clause                         { $$ = $1; }
   13478         574 :             | grouping_sets_clause                  { $$ = $1; }
   13479             :         ;
   13480             : 
   13481             : empty_grouping_set:
   13482             :             '(' ')'
   13483             :                 {
   13484         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13485             :                 }
   13486             :         ;
   13487             : 
   13488             : /*
   13489             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13490             :  * so that they shift in these rules rather than reducing the conflicting
   13491             :  * unreserved_keyword rule.
   13492             :  */
   13493             : 
   13494             : rollup_clause:
   13495             :             ROLLUP '(' expr_list ')'
   13496             :                 {
   13497         286 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13498             :                 }
   13499             :         ;
   13500             : 
   13501             : cube_clause:
   13502             :             CUBE '(' expr_list ')'
   13503             :                 {
   13504         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13505             :                 }
   13506             :         ;
   13507             : 
   13508             : grouping_sets_clause:
   13509             :             GROUPING SETS '(' group_by_list ')'
   13510             :                 {
   13511         574 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13512             :                 }
   13513             :         ;
   13514             : 
   13515             : having_clause:
   13516         714 :             HAVING a_expr                           { $$ = $2; }
   13517      481824 :             | /*EMPTY*/                             { $$ = NULL; }
   13518             :         ;
   13519             : 
   13520             : for_locking_clause:
   13521        5242 :             for_locking_items                       { $$ = $1; }
   13522           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13523             :         ;
   13524             : 
   13525             : opt_for_locking_clause:
   13526         340 :             for_locking_clause                      { $$ = $1; }
   13527       44624 :             | /* EMPTY */                           { $$ = NIL; }
   13528             :         ;
   13529             : 
   13530             : for_locking_items:
   13531        5242 :             for_locking_item                        { $$ = list_make1($1); }
   13532          98 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13533             :         ;
   13534             : 
   13535             : for_locking_item:
   13536             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13537             :                 {
   13538        5340 :                     LockingClause *n = makeNode(LockingClause);
   13539             : 
   13540        5340 :                     n->lockedRels = $2;
   13541        5340 :                     n->strength = $1;
   13542        5340 :                     n->waitPolicy = $3;
   13543        5340 :                     $$ = (Node *) n;
   13544             :                 }
   13545             :         ;
   13546             : 
   13547             : for_locking_strength:
   13548        1516 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13549          76 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13550         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13551        3534 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13552             :         ;
   13553             : 
   13554             : locked_rels_list:
   13555        3554 :             OF qualified_name_list                  { $$ = $2; }
   13556        1786 :             | /* EMPTY */                           { $$ = NIL; }
   13557             :         ;
   13558             : 
   13559             : 
   13560             : /*
   13561             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13562             :  * making VALUES a fully reserved word, which will probably break more apps
   13563             :  * than allowing the noise-word is worth.
   13564             :  */
   13565             : values_clause:
   13566             :             VALUES '(' expr_list ')'
   13567             :                 {
   13568       61710 :                     SelectStmt *n = makeNode(SelectStmt);
   13569             : 
   13570       61710 :                     n->stmt_location = @1;
   13571       61710 :                     n->valuesLists = list_make1($3);
   13572       61710 :                     $$ = (Node *) n;
   13573             :                 }
   13574             :             | values_clause ',' '(' expr_list ')'
   13575             :                 {
   13576       25038 :                     SelectStmt *n = (SelectStmt *) $1;
   13577             : 
   13578       25038 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13579       25038 :                     $$ = (Node *) n;
   13580             :                 }
   13581             :         ;
   13582             : 
   13583             : 
   13584             : /*****************************************************************************
   13585             :  *
   13586             :  *  clauses common to all Optimizable Stmts:
   13587             :  *      from_clause     - allow list of both JOIN expressions and table names
   13588             :  *      where_clause    - qualifications for joins or restrictions
   13589             :  *
   13590             :  *****************************************************************************/
   13591             : 
   13592             : from_clause:
   13593      291538 :             FROM from_list                          { $$ = $2; }
   13594      204752 :             | /*EMPTY*/                             { $$ = NIL; }
   13595             :         ;
   13596             : 
   13597             : from_list:
   13598      292296 :             table_ref                               { $$ = list_make1($1); }
   13599       57528 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13600             :         ;
   13601             : 
   13602             : /*
   13603             :  * table_ref is where an alias clause can be attached.
   13604             :  */
   13605             : table_ref:  relation_expr opt_alias_clause
   13606             :                 {
   13607      369666 :                     $1->alias = $2;
   13608      369666 :                     $$ = (Node *) $1;
   13609             :                 }
   13610             :             | relation_expr opt_alias_clause tablesample_clause
   13611             :                 {
   13612         260 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13613             : 
   13614         260 :                     $1->alias = $2;
   13615             :                     /* relation_expr goes inside the RangeTableSample node */
   13616         260 :                     n->relation = (Node *) $1;
   13617         260 :                     $$ = (Node *) n;
   13618             :                 }
   13619             :             | func_table func_alias_clause
   13620             :                 {
   13621       42482 :                     RangeFunction *n = (RangeFunction *) $1;
   13622             : 
   13623       42482 :                     n->alias = linitial($2);
   13624       42482 :                     n->coldeflist = lsecond($2);
   13625       42482 :                     $$ = (Node *) n;
   13626             :                 }
   13627             :             | LATERAL_P func_table func_alias_clause
   13628             :                 {
   13629        1098 :                     RangeFunction *n = (RangeFunction *) $2;
   13630             : 
   13631        1098 :                     n->lateral = true;
   13632        1098 :                     n->alias = linitial($3);
   13633        1098 :                     n->coldeflist = lsecond($3);
   13634        1098 :                     $$ = (Node *) n;
   13635             :                 }
   13636             :             | xmltable opt_alias_clause
   13637             :                 {
   13638          80 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13639             : 
   13640          80 :                     n->alias = $2;
   13641          80 :                     $$ = (Node *) n;
   13642             :                 }
   13643             :             | LATERAL_P xmltable opt_alias_clause
   13644             :                 {
   13645         140 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13646             : 
   13647         140 :                     n->lateral = true;
   13648         140 :                     n->alias = $3;
   13649         140 :                     $$ = (Node *) n;
   13650             :                 }
   13651             :             | select_with_parens opt_alias_clause
   13652             :                 {
   13653       13350 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13654             : 
   13655       13350 :                     n->lateral = false;
   13656       13350 :                     n->subquery = $1;
   13657       13350 :                     n->alias = $2;
   13658       13350 :                     $$ = (Node *) n;
   13659             :                 }
   13660             :             | LATERAL_P select_with_parens opt_alias_clause
   13661             :                 {
   13662        1602 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13663             : 
   13664        1602 :                     n->lateral = true;
   13665        1602 :                     n->subquery = $2;
   13666        1602 :                     n->alias = $3;
   13667        1602 :                     $$ = (Node *) n;
   13668             :                 }
   13669             :             | joined_table
   13670             :                 {
   13671       77140 :                     $$ = (Node *) $1;
   13672             :                 }
   13673             :             | '(' joined_table ')' alias_clause
   13674             :                 {
   13675         174 :                     $2->alias = $4;
   13676         174 :                     $$ = (Node *) $2;
   13677             :                 }
   13678             :             | json_table opt_alias_clause
   13679             :                 {
   13680         524 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13681             : 
   13682         524 :                     jt->alias = $2;
   13683         524 :                     $$ = (Node *) jt;
   13684             :                 }
   13685             :             | LATERAL_P json_table opt_alias_clause
   13686             :                 {
   13687           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13688             : 
   13689           0 :                     jt->alias = $3;
   13690           0 :                     jt->lateral = true;
   13691           0 :                     $$ = (Node *) jt;
   13692             :                 }
   13693             :         ;
   13694             : 
   13695             : 
   13696             : /*
   13697             :  * It may seem silly to separate joined_table from table_ref, but there is
   13698             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13699             :  * reduce conflicts, because it's not clear to the parser generator whether
   13700             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13701             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13702             :  * join_type to expand to empty; if we try it, the parser generator can't
   13703             :  * figure out when to reduce an empty join_type right after table_ref.
   13704             :  *
   13705             :  * Note that a CROSS JOIN is the same as an unqualified
   13706             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13707             :  * but a qualification expression to limit membership.
   13708             :  * A NATURAL JOIN implicitly matches column names between
   13709             :  * tables and the shape is determined by which columns are
   13710             :  * in common. We'll collect columns during the later transformations.
   13711             :  */
   13712             : 
   13713             : joined_table:
   13714             :             '(' joined_table ')'
   13715             :                 {
   13716        3718 :                     $$ = $2;
   13717             :                 }
   13718             :             | table_ref CROSS JOIN table_ref
   13719             :                 {
   13720             :                     /* CROSS JOIN is same as unqualified inner join */
   13721         322 :                     JoinExpr   *n = makeNode(JoinExpr);
   13722             : 
   13723         322 :                     n->jointype = JOIN_INNER;
   13724         322 :                     n->isNatural = false;
   13725         322 :                     n->larg = $1;
   13726         322 :                     n->rarg = $4;
   13727         322 :                     n->usingClause = NIL;
   13728         322 :                     n->join_using_alias = NULL;
   13729         322 :                     n->quals = NULL;
   13730         322 :                     $$ = n;
   13731             :                 }
   13732             :             | table_ref join_type JOIN table_ref join_qual
   13733             :                 {
   13734       44022 :                     JoinExpr   *n = makeNode(JoinExpr);
   13735             : 
   13736       44022 :                     n->jointype = $2;
   13737       44022 :                     n->isNatural = false;
   13738       44022 :                     n->larg = $1;
   13739       44022 :                     n->rarg = $4;
   13740       44022 :                     if ($5 != NULL && IsA($5, List))
   13741             :                     {
   13742             :                          /* USING clause */
   13743         492 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13744         492 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13745             :                     }
   13746             :                     else
   13747             :                     {
   13748             :                         /* ON clause */
   13749       43530 :                         n->quals = $5;
   13750             :                     }
   13751       44022 :                     $$ = n;
   13752             :                 }
   13753             :             | table_ref JOIN table_ref join_qual
   13754             :                 {
   13755             :                     /* letting join_type reduce to empty doesn't work */
   13756       32712 :                     JoinExpr   *n = makeNode(JoinExpr);
   13757             : 
   13758       32712 :                     n->jointype = JOIN_INNER;
   13759       32712 :                     n->isNatural = false;
   13760       32712 :                     n->larg = $1;
   13761       32712 :                     n->rarg = $3;
   13762       32712 :                     if ($4 != NULL && IsA($4, List))
   13763             :                     {
   13764             :                         /* USING clause */
   13765         708 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13766         708 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13767             :                     }
   13768             :                     else
   13769             :                     {
   13770             :                         /* ON clause */
   13771       32004 :                         n->quals = $4;
   13772             :                     }
   13773       32712 :                     $$ = n;
   13774             :                 }
   13775             :             | table_ref NATURAL join_type JOIN table_ref
   13776             :                 {
   13777          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13778             : 
   13779          78 :                     n->jointype = $3;
   13780          78 :                     n->isNatural = true;
   13781          78 :                     n->larg = $1;
   13782          78 :                     n->rarg = $5;
   13783          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13784          78 :                     n->join_using_alias = NULL;
   13785          78 :                     n->quals = NULL; /* fill later */
   13786          78 :                     $$ = n;
   13787             :                 }
   13788             :             | table_ref NATURAL JOIN table_ref
   13789             :                 {
   13790             :                     /* letting join_type reduce to empty doesn't work */
   13791         180 :                     JoinExpr   *n = makeNode(JoinExpr);
   13792             : 
   13793         180 :                     n->jointype = JOIN_INNER;
   13794         180 :                     n->isNatural = true;
   13795         180 :                     n->larg = $1;
   13796         180 :                     n->rarg = $4;
   13797         180 :                     n->usingClause = NIL; /* figure out which columns later... */
   13798         180 :                     n->join_using_alias = NULL;
   13799         180 :                     n->quals = NULL; /* fill later */
   13800         180 :                     $$ = n;
   13801             :                 }
   13802             :         ;
   13803             : 
   13804             : alias_clause:
   13805             :             AS ColId '(' name_list ')'
   13806             :                 {
   13807        5736 :                     $$ = makeNode(Alias);
   13808        5736 :                     $$->aliasname = $2;
   13809        5736 :                     $$->colnames = $4;
   13810             :                 }
   13811             :             | AS ColId
   13812             :                 {
   13813       10260 :                     $$ = makeNode(Alias);
   13814       10260 :                     $$->aliasname = $2;
   13815             :                 }
   13816             :             | ColId '(' name_list ')'
   13817             :                 {
   13818        5688 :                     $$ = makeNode(Alias);
   13819        5688 :                     $$->aliasname = $1;
   13820        5688 :                     $$->colnames = $3;
   13821             :                 }
   13822             :             | ColId
   13823             :                 {
   13824      246220 :                     $$ = makeNode(Alias);
   13825      246220 :                     $$->aliasname = $1;
   13826             :                 }
   13827             :         ;
   13828             : 
   13829      238476 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13830      147146 :             | /*EMPTY*/                             { $$ = NULL; }
   13831             :         ;
   13832             : 
   13833             : /*
   13834             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13835             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13836             :  * don't seem to be useful, and it might lead to parser problems in the
   13837             :  * future.)
   13838             :  */
   13839             : opt_alias_clause_for_join_using:
   13840             :             AS ColId
   13841             :                 {
   13842          84 :                     $$ = makeNode(Alias);
   13843          84 :                     $$->aliasname = $2;
   13844             :                     /* the column name list will be inserted later */
   13845             :                 }
   13846        1116 :             | /*EMPTY*/                             { $$ = NULL; }
   13847             :         ;
   13848             : 
   13849             : /*
   13850             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13851             :  * return a 2-element list that gets disassembled by calling production.
   13852             :  */
   13853             : func_alias_clause:
   13854             :             alias_clause
   13855             :                 {
   13856       29254 :                     $$ = list_make2($1, NIL);
   13857             :                 }
   13858             :             | AS '(' TableFuncElementList ')'
   13859             :                 {
   13860         114 :                     $$ = list_make2(NULL, $3);
   13861             :                 }
   13862             :             | AS ColId '(' TableFuncElementList ')'
   13863             :                 {
   13864         586 :                     Alias      *a = makeNode(Alias);
   13865             : 
   13866         586 :                     a->aliasname = $2;
   13867         586 :                     $$ = list_make2(a, $4);
   13868             :                 }
   13869             :             | ColId '(' TableFuncElementList ')'
   13870             :                 {
   13871          50 :                     Alias      *a = makeNode(Alias);
   13872             : 
   13873          50 :                     a->aliasname = $1;
   13874          50 :                     $$ = list_make2(a, $3);
   13875             :                 }
   13876             :             | /*EMPTY*/
   13877             :                 {
   13878       13576 :                     $$ = list_make2(NULL, NIL);
   13879             :                 }
   13880             :         ;
   13881             : 
   13882        1030 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13883       38836 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13884         362 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13885        3872 :             | INNER_P                               { $$ = JOIN_INNER; }
   13886             :         ;
   13887             : 
   13888             : /* OUTER is just noise... */
   13889             : opt_outer: OUTER_P
   13890             :             | /*EMPTY*/
   13891             :         ;
   13892             : 
   13893             : /* JOIN qualification clauses
   13894             :  * Possibilities are:
   13895             :  *  USING ( column list ) [ AS alias ]
   13896             :  *                        allows only unqualified column names,
   13897             :  *                        which must match between tables.
   13898             :  *  ON expr allows more general qualifications.
   13899             :  *
   13900             :  * We return USING as a two-element List (the first item being a sub-List
   13901             :  * of the common column names, and the second either an Alias item or NULL).
   13902             :  * An ON-expr will not be a List, so it can be told apart that way.
   13903             :  */
   13904             : 
   13905             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13906             :                 {
   13907        1200 :                     $$ = (Node *) list_make2($3, $5);
   13908             :                 }
   13909             :             | ON a_expr
   13910             :                 {
   13911       75534 :                     $$ = $2;
   13912             :                 }
   13913             :         ;
   13914             : 
   13915             : 
   13916             : relation_expr:
   13917             :             qualified_name
   13918             :                 {
   13919             :                     /* inheritance query, implicitly */
   13920      443502 :                     $$ = $1;
   13921      443502 :                     $$->inh = true;
   13922      443502 :                     $$->alias = NULL;
   13923             :                 }
   13924             :             | extended_relation_expr
   13925             :                 {
   13926        7092 :                     $$ = $1;
   13927             :                 }
   13928             :         ;
   13929             : 
   13930             : extended_relation_expr:
   13931             :             qualified_name '*'
   13932             :                 {
   13933             :                     /* inheritance query, explicitly */
   13934         204 :                     $$ = $1;
   13935         204 :                     $$->inh = true;
   13936         204 :                     $$->alias = NULL;
   13937             :                 }
   13938             :             | ONLY qualified_name
   13939             :                 {
   13940             :                     /* no inheritance */
   13941        6894 :                     $$ = $2;
   13942        6894 :                     $$->inh = false;
   13943        6894 :                     $$->alias = NULL;
   13944             :                 }
   13945             :             | ONLY '(' qualified_name ')'
   13946             :                 {
   13947             :                     /* no inheritance, SQL99-style syntax */
   13948           0 :                     $$ = $3;
   13949           0 :                     $$->inh = false;
   13950           0 :                     $$->alias = NULL;
   13951             :                 }
   13952             :         ;
   13953             : 
   13954             : 
   13955             : relation_expr_list:
   13956        2770 :             relation_expr                           { $$ = list_make1($1); }
   13957       10250 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   13958             :         ;
   13959             : 
   13960             : 
   13961             : /*
   13962             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   13963             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   13964             :  * keyword.  Since "set" is allowed as a column name both interpretations
   13965             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   13966             :  * relation_expr_opt_alias production a higher precedence than the SET token
   13967             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   13968             :  * SET is not an alias.
   13969             :  */
   13970             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   13971             :                 {
   13972       18268 :                     $$ = $1;
   13973             :                 }
   13974             :             | relation_expr ColId
   13975             :                 {
   13976        2156 :                     Alias      *alias = makeNode(Alias);
   13977             : 
   13978        2156 :                     alias->aliasname = $2;
   13979        2156 :                     $1->alias = alias;
   13980        2156 :                     $$ = $1;
   13981             :                 }
   13982             :             | relation_expr AS ColId
   13983             :                 {
   13984          90 :                     Alias      *alias = makeNode(Alias);
   13985             : 
   13986          90 :                     alias->aliasname = $3;
   13987          90 :                     $1->alias = alias;
   13988          90 :                     $$ = $1;
   13989             :                 }
   13990             :         ;
   13991             : 
   13992             : /*
   13993             :  * TABLESAMPLE decoration in a FROM item
   13994             :  */
   13995             : tablesample_clause:
   13996             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   13997             :                 {
   13998         260 :                     RangeTableSample *n = makeNode(RangeTableSample);
   13999             : 
   14000             :                     /* n->relation will be filled in later */
   14001         260 :                     n->method = $2;
   14002         260 :                     n->args = $4;
   14003         260 :                     n->repeatable = $6;
   14004         260 :                     n->location = @2;
   14005         260 :                     $$ = (Node *) n;
   14006             :                 }
   14007             :         ;
   14008             : 
   14009             : opt_repeatable_clause:
   14010         108 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14011         152 :             | /*EMPTY*/                 { $$ = NULL; }
   14012             :         ;
   14013             : 
   14014             : /*
   14015             :  * func_table represents a function invocation in a FROM list. It can be
   14016             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14017             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14018             :  * optionally with WITH ORDINALITY attached.
   14019             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14020             :  * function, for example:
   14021             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14022             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14023             :  * It's also possible to attach a column definition list to the RangeFunction
   14024             :  * as a whole, but that's handled by the table_ref production.
   14025             :  */
   14026             : func_table: func_expr_windowless opt_ordinality
   14027             :                 {
   14028       43454 :                     RangeFunction *n = makeNode(RangeFunction);
   14029             : 
   14030       43454 :                     n->lateral = false;
   14031       43454 :                     n->ordinality = $2;
   14032       43454 :                     n->is_rowsfrom = false;
   14033       43454 :                     n->functions = list_make1(list_make2($1, NIL));
   14034             :                     /* alias and coldeflist are set by table_ref production */
   14035       43454 :                     $$ = (Node *) n;
   14036             :                 }
   14037             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14038             :                 {
   14039         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14040             : 
   14041         132 :                     n->lateral = false;
   14042         132 :                     n->ordinality = $6;
   14043         132 :                     n->is_rowsfrom = true;
   14044         132 :                     n->functions = $4;
   14045             :                     /* alias and coldeflist are set by table_ref production */
   14046         132 :                     $$ = (Node *) n;
   14047             :                 }
   14048             :         ;
   14049             : 
   14050             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14051         318 :                 { $$ = list_make2($1, $2); }
   14052             :         ;
   14053             : 
   14054             : rowsfrom_list:
   14055         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14056         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14057             :         ;
   14058             : 
   14059          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14060         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14061             :         ;
   14062             : 
   14063         784 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14064       42802 :             | /*EMPTY*/                             { $$ = false; }
   14065             :         ;
   14066             : 
   14067             : 
   14068             : where_clause:
   14069      196700 :             WHERE a_expr                            { $$ = $2; }
   14070      306008 :             | /*EMPTY*/                             { $$ = NULL; }
   14071             :         ;
   14072             : 
   14073             : /* variant for UPDATE and DELETE */
   14074             : where_or_current_clause:
   14075       13226 :             WHERE a_expr                            { $$ = $2; }
   14076             :             | WHERE CURRENT_P OF cursor_name
   14077             :                 {
   14078         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14079             : 
   14080             :                     /* cvarno is filled in by parse analysis */
   14081         266 :                     n->cursor_name = $4;
   14082         266 :                     n->cursor_param = 0;
   14083         266 :                     $$ = (Node *) n;
   14084             :                 }
   14085        4946 :             | /*EMPTY*/                             { $$ = NULL; }
   14086             :         ;
   14087             : 
   14088             : 
   14089             : OptTableFuncElementList:
   14090         706 :             TableFuncElementList                { $$ = $1; }
   14091        3786 :             | /*EMPTY*/                         { $$ = NIL; }
   14092             :         ;
   14093             : 
   14094             : TableFuncElementList:
   14095             :             TableFuncElement
   14096             :                 {
   14097        1510 :                     $$ = list_make1($1);
   14098             :                 }
   14099             :             | TableFuncElementList ',' TableFuncElement
   14100             :                 {
   14101        2022 :                     $$ = lappend($1, $3);
   14102             :                 }
   14103             :         ;
   14104             : 
   14105             : TableFuncElement:   ColId Typename opt_collate_clause
   14106             :                 {
   14107        3596 :                     ColumnDef *n = makeNode(ColumnDef);
   14108             : 
   14109        3596 :                     n->colname = $1;
   14110        3596 :                     n->typeName = $2;
   14111        3596 :                     n->inhcount = 0;
   14112        3596 :                     n->is_local = true;
   14113        3596 :                     n->is_not_null = false;
   14114        3596 :                     n->is_from_type = false;
   14115        3596 :                     n->storage = 0;
   14116        3596 :                     n->raw_default = NULL;
   14117        3596 :                     n->cooked_default = NULL;
   14118        3596 :                     n->collClause = (CollateClause *) $3;
   14119        3596 :                     n->collOid = InvalidOid;
   14120        3596 :                     n->constraints = NIL;
   14121        3596 :                     n->location = @1;
   14122        3596 :                     $$ = (Node *) n;
   14123             :                 }
   14124             :         ;
   14125             : 
   14126             : /*
   14127             :  * XMLTABLE
   14128             :  */
   14129             : xmltable:
   14130             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14131             :                 {
   14132         200 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14133             : 
   14134         200 :                     n->rowexpr = $3;
   14135         200 :                     n->docexpr = $4;
   14136         200 :                     n->columns = $6;
   14137         200 :                     n->namespaces = NIL;
   14138         200 :                     n->location = @1;
   14139         200 :                     $$ = (Node *) n;
   14140             :                 }
   14141             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14142             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14143             :                 {
   14144          20 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14145             : 
   14146          20 :                     n->rowexpr = $8;
   14147          20 :                     n->docexpr = $9;
   14148          20 :                     n->columns = $11;
   14149          20 :                     n->namespaces = $5;
   14150          20 :                     n->location = @1;
   14151          20 :                     $$ = (Node *) n;
   14152             :                 }
   14153             :         ;
   14154             : 
   14155         220 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14156         530 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14157             :         ;
   14158             : 
   14159             : xmltable_column_el:
   14160             :             ColId Typename
   14161             :                 {
   14162         198 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14163             : 
   14164         198 :                     fc->colname = $1;
   14165         198 :                     fc->for_ordinality = false;
   14166         198 :                     fc->typeName = $2;
   14167         198 :                     fc->is_not_null = false;
   14168         198 :                     fc->colexpr = NULL;
   14169         198 :                     fc->coldefexpr = NULL;
   14170         198 :                     fc->location = @1;
   14171             : 
   14172         198 :                     $$ = (Node *) fc;
   14173             :                 }
   14174             :             | ColId Typename xmltable_column_option_list
   14175             :                 {
   14176         490 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14177             :                     ListCell   *option;
   14178         490 :                     bool        nullability_seen = false;
   14179             : 
   14180         490 :                     fc->colname = $1;
   14181         490 :                     fc->typeName = $2;
   14182         490 :                     fc->for_ordinality = false;
   14183         490 :                     fc->is_not_null = false;
   14184         490 :                     fc->colexpr = NULL;
   14185         490 :                     fc->coldefexpr = NULL;
   14186         490 :                     fc->location = @1;
   14187             : 
   14188        1092 :                     foreach(option, $3)
   14189             :                     {
   14190         602 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14191             : 
   14192         602 :                         if (strcmp(defel->defname, "default") == 0)
   14193             :                         {
   14194          56 :                             if (fc->coldefexpr != NULL)
   14195           0 :                                 ereport(ERROR,
   14196             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14197             :                                          errmsg("only one DEFAULT value is allowed"),
   14198             :                                          parser_errposition(defel->location)));
   14199          56 :                             fc->coldefexpr = defel->arg;
   14200             :                         }
   14201         546 :                         else if (strcmp(defel->defname, "path") == 0)
   14202             :                         {
   14203         490 :                             if (fc->colexpr != NULL)
   14204           0 :                                 ereport(ERROR,
   14205             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14206             :                                          errmsg("only one PATH value per column is allowed"),
   14207             :                                          parser_errposition(defel->location)));
   14208         490 :                             fc->colexpr = defel->arg;
   14209             :                         }
   14210          56 :                         else if (strcmp(defel->defname, "is_not_null") == 0)
   14211             :                         {
   14212          56 :                             if (nullability_seen)
   14213           0 :                                 ereport(ERROR,
   14214             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14215             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14216             :                                          parser_errposition(defel->location)));
   14217          56 :                             fc->is_not_null = boolVal(defel->arg);
   14218          56 :                             nullability_seen = true;
   14219             :                         }
   14220             :                         else
   14221             :                         {
   14222           0 :                             ereport(ERROR,
   14223             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14224             :                                      errmsg("unrecognized column option \"%s\"",
   14225             :                                             defel->defname),
   14226             :                                      parser_errposition(defel->location)));
   14227             :                         }
   14228             :                     }
   14229         490 :                     $$ = (Node *) fc;
   14230             :                 }
   14231             :             | ColId FOR ORDINALITY
   14232             :                 {
   14233          62 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14234             : 
   14235          62 :                     fc->colname = $1;
   14236          62 :                     fc->for_ordinality = true;
   14237             :                     /* other fields are ignored, initialized by makeNode */
   14238          62 :                     fc->location = @1;
   14239             : 
   14240          62 :                     $$ = (Node *) fc;
   14241             :                 }
   14242             :         ;
   14243             : 
   14244             : xmltable_column_option_list:
   14245             :             xmltable_column_option_el
   14246         490 :                 { $$ = list_make1($1); }
   14247             :             | xmltable_column_option_list xmltable_column_option_el
   14248         112 :                 { $$ = lappend($1, $2); }
   14249             :         ;
   14250             : 
   14251             : xmltable_column_option_el:
   14252             :             IDENT b_expr
   14253           0 :                 { $$ = makeDefElem($1, $2, @1); }
   14254             :             | DEFAULT b_expr
   14255          56 :                 { $$ = makeDefElem("default", $2, @1); }
   14256             :             | NOT NULL_P
   14257          56 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
   14258             :             | NULL_P
   14259           0 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
   14260             :             | PATH b_expr
   14261         490 :                 { $$ = makeDefElem("path", $2, @1); }
   14262             :         ;
   14263             : 
   14264             : xml_namespace_list:
   14265             :             xml_namespace_el
   14266          20 :                 { $$ = list_make1($1); }
   14267             :             | xml_namespace_list ',' xml_namespace_el
   14268           0 :                 { $$ = lappend($1, $3); }
   14269             :         ;
   14270             : 
   14271             : xml_namespace_el:
   14272             :             b_expr AS ColLabel
   14273             :                 {
   14274          14 :                     $$ = makeNode(ResTarget);
   14275          14 :                     $$->name = $3;
   14276          14 :                     $$->indirection = NIL;
   14277          14 :                     $$->val = $1;
   14278          14 :                     $$->location = @1;
   14279             :                 }
   14280             :             | DEFAULT b_expr
   14281             :                 {
   14282           6 :                     $$ = makeNode(ResTarget);
   14283           6 :                     $$->name = NULL;
   14284           6 :                     $$->indirection = NIL;
   14285           6 :                     $$->val = $2;
   14286           6 :                     $$->location = @1;
   14287             :                 }
   14288             :         ;
   14289             : 
   14290             : json_table:
   14291             :             JSON_TABLE '('
   14292             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14293             :                 json_passing_clause_opt
   14294             :                 COLUMNS '(' json_table_column_definition_list ')'
   14295             :                 json_on_error_clause_opt
   14296             :             ')'
   14297             :                 {
   14298         530 :                     JsonTable *n = makeNode(JsonTable);
   14299             :                     char      *pathstring;
   14300             : 
   14301         530 :                     n->context_item = (JsonValueExpr *) $3;
   14302         530 :                     if (!IsA($5, A_Const) ||
   14303         524 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14304           6 :                         ereport(ERROR,
   14305             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14306             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14307             :                                 parser_errposition(@5));
   14308         524 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14309         524 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14310         524 :                     n->passing = $7;
   14311         524 :                     n->columns = $10;
   14312         524 :                     n->on_error = (JsonBehavior *) $12;
   14313         524 :                     n->location = @1;
   14314         524 :                     $$ = (Node *) n;
   14315             :                 }
   14316             :         ;
   14317             : 
   14318             : json_table_path_name_opt:
   14319          62 :             AS name         { $$ = $2; }
   14320         480 :             | /* empty */   { $$ = NULL; }
   14321             :         ;
   14322             : 
   14323             : json_table_column_definition_list:
   14324             :             json_table_column_definition
   14325         820 :                 { $$ = list_make1($1); }
   14326             :             | json_table_column_definition_list ',' json_table_column_definition
   14327         528 :                 { $$ = lappend($1, $3); }
   14328             :         ;
   14329             : 
   14330             : json_table_column_definition:
   14331             :             ColId FOR ORDINALITY
   14332             :                 {
   14333          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14334             : 
   14335          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14336          84 :                     n->name = $1;
   14337          84 :                     n->location = @1;
   14338          84 :                     $$ = (Node *) n;
   14339             :                 }
   14340             :             | ColId Typename
   14341             :                 json_table_column_path_clause_opt
   14342             :                 json_wrapper_behavior
   14343             :                 json_quotes_clause_opt
   14344             :                 json_behavior_clause_opt
   14345             :                 {
   14346         728 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14347             : 
   14348         728 :                     n->coltype = JTC_REGULAR;
   14349         728 :                     n->name = $1;
   14350         728 :                     n->typeName = $2;
   14351         728 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14352         728 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14353         728 :                     n->wrapper = $4;
   14354         728 :                     n->quotes = $5;
   14355         728 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14356         728 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14357         728 :                     n->location = @1;
   14358         728 :                     $$ = (Node *) n;
   14359             :                 }
   14360             :             | ColId Typename json_format_clause
   14361             :                 json_table_column_path_clause_opt
   14362             :                 json_wrapper_behavior
   14363             :                 json_quotes_clause_opt
   14364             :                 json_behavior_clause_opt
   14365             :                 {
   14366         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14367             : 
   14368         108 :                     n->coltype = JTC_FORMATTED;
   14369         108 :                     n->name = $1;
   14370         108 :                     n->typeName = $2;
   14371         108 :                     n->format = (JsonFormat *) $3;
   14372         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14373         108 :                     n->wrapper = $5;
   14374         108 :                     n->quotes = $6;
   14375         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14376         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14377         108 :                     n->location = @1;
   14378         108 :                     $$ = (Node *) n;
   14379             :                 }
   14380             :             | ColId Typename
   14381             :                 EXISTS json_table_column_path_clause_opt
   14382             :                 json_on_error_clause_opt
   14383             :                 {
   14384         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14385             : 
   14386         138 :                     n->coltype = JTC_EXISTS;
   14387         138 :                     n->name = $1;
   14388         138 :                     n->typeName = $2;
   14389         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14390         138 :                     n->wrapper = JSW_NONE;
   14391         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14392         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14393         138 :                     n->on_empty = NULL;
   14394         138 :                     n->on_error = (JsonBehavior *) $5;
   14395         138 :                     n->location = @1;
   14396         138 :                     $$ = (Node *) n;
   14397             :                 }
   14398             :             | NESTED path_opt Sconst
   14399             :                 COLUMNS '(' json_table_column_definition_list ')'
   14400             :                 {
   14401         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14402             : 
   14403         144 :                     n->coltype = JTC_NESTED;
   14404         288 :                     n->pathspec = (JsonTablePathSpec *)
   14405         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14406         144 :                     n->columns = $6;
   14407         144 :                     n->location = @1;
   14408         144 :                     $$ = (Node *) n;
   14409             :                 }
   14410             :             | NESTED path_opt Sconst AS name
   14411             :                 COLUMNS '(' json_table_column_definition_list ')'
   14412             :                 {
   14413         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14414             : 
   14415         146 :                     n->coltype = JTC_NESTED;
   14416         292 :                     n->pathspec = (JsonTablePathSpec *)
   14417         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14418         146 :                     n->columns = $8;
   14419         146 :                     n->location = @1;
   14420         146 :                     $$ = (Node *) n;
   14421             :                 }
   14422             :         ;
   14423             : 
   14424             : path_opt:
   14425             :             PATH
   14426             :             | /* EMPTY */
   14427             :         ;
   14428             : 
   14429             : json_table_column_path_clause_opt:
   14430             :             PATH Sconst
   14431         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14432             :             | /* EMPTY */
   14433         152 :                 { $$ = NULL; }
   14434             :         ;
   14435             : 
   14436             : /*****************************************************************************
   14437             :  *
   14438             :  *  Type syntax
   14439             :  *      SQL introduces a large amount of type-specific syntax.
   14440             :  *      Define individual clauses to handle these cases, and use
   14441             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14442             :  *      - thomas 1997-10-10
   14443             :  *
   14444             :  *****************************************************************************/
   14445             : 
   14446             : Typename:   SimpleTypename opt_array_bounds
   14447             :                 {
   14448      455746 :                     $$ = $1;
   14449      455746 :                     $$->arrayBounds = $2;
   14450             :                 }
   14451             :             | SETOF SimpleTypename opt_array_bounds
   14452             :                 {
   14453        2116 :                     $$ = $2;
   14454        2116 :                     $$->arrayBounds = $3;
   14455        2116 :                     $$->setof = true;
   14456             :                 }
   14457             :             /* SQL standard syntax, currently only one-dimensional */
   14458             :             | SimpleTypename ARRAY '[' Iconst ']'
   14459             :                 {
   14460           6 :                     $$ = $1;
   14461           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14462             :                 }
   14463             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14464             :                 {
   14465           0 :                     $$ = $2;
   14466           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14467           0 :                     $$->setof = true;
   14468             :                 }
   14469             :             | SimpleTypename ARRAY
   14470             :                 {
   14471           0 :                     $$ = $1;
   14472           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14473             :                 }
   14474             :             | SETOF SimpleTypename ARRAY
   14475             :                 {
   14476           0 :                     $$ = $2;
   14477           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14478           0 :                     $$->setof = true;
   14479             :                 }
   14480             :         ;
   14481             : 
   14482             : opt_array_bounds:
   14483             :             opt_array_bounds '[' ']'
   14484       12602 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14485             :             | opt_array_bounds '[' Iconst ']'
   14486          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14487             :             | /*EMPTY*/
   14488      457862 :                     {  $$ = NIL; }
   14489             :         ;
   14490             : 
   14491             : SimpleTypename:
   14492      366432 :             GenericType                             { $$ = $1; }
   14493       77214 :             | Numeric                               { $$ = $1; }
   14494        1894 :             | Bit                                   { $$ = $1; }
   14495        2942 :             | Character                             { $$ = $1; }
   14496        4600 :             | ConstDatetime                         { $$ = $1; }
   14497             :             | ConstInterval opt_interval
   14498             :                 {
   14499        3518 :                     $$ = $1;
   14500        3518 :                     $$->typmods = $2;
   14501             :                 }
   14502             :             | ConstInterval '(' Iconst ')'
   14503             :                 {
   14504           0 :                     $$ = $1;
   14505           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14506             :                                              makeIntConst($3, @3));
   14507             :                 }
   14508        1660 :             | JsonType                              { $$ = $1; }
   14509             :         ;
   14510             : 
   14511             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14512             :  * types such as CHAR() and BIT() to an unspecified length.
   14513             :  * SQL9x requires that these default to a length of one, but this
   14514             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14515             :  * where there is an obvious better choice to make.
   14516             :  * Note that ConstInterval is not included here since it must
   14517             :  * be pushed up higher in the rules to accommodate the postfix
   14518             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14519             :  * the generic-type-name case in AexprConst to avoid premature
   14520             :  * reduce/reduce conflicts against function names.
   14521             :  */
   14522             : ConstTypename:
   14523          78 :             Numeric                                 { $$ = $1; }
   14524           0 :             | ConstBit                              { $$ = $1; }
   14525          34 :             | ConstCharacter                        { $$ = $1; }
   14526        2738 :             | ConstDatetime                         { $$ = $1; }
   14527         264 :             | JsonType                              { $$ = $1; }
   14528             :         ;
   14529             : 
   14530             : /*
   14531             :  * GenericType covers all type names that don't have special syntax mandated
   14532             :  * by the standard, including qualified names.  We also allow type modifiers.
   14533             :  * To avoid parsing conflicts against function invocations, the modifiers
   14534             :  * have to be shown as expr_list here, but parse analysis will only accept
   14535             :  * constants for them.
   14536             :  */
   14537             : GenericType:
   14538             :             type_function_name opt_type_modifiers
   14539             :                 {
   14540      261664 :                     $$ = makeTypeName($1);
   14541      261664 :                     $$->typmods = $2;
   14542      261664 :                     $$->location = @1;
   14543             :                 }
   14544             :             | type_function_name attrs opt_type_modifiers
   14545             :                 {
   14546      104768 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14547      104768 :                     $$->typmods = $3;
   14548      104768 :                     $$->location = @1;
   14549             :                 }
   14550             :         ;
   14551             : 
   14552        1348 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14553      371056 :                     | /* EMPTY */                   { $$ = NIL; }
   14554             :         ;
   14555             : 
   14556             : /*
   14557             :  * SQL numeric data types
   14558             :  */
   14559             : Numeric:    INT_P
   14560             :                 {
   14561       36982 :                     $$ = SystemTypeName("int4");
   14562       36982 :                     $$->location = @1;
   14563             :                 }
   14564             :             | INTEGER
   14565             :                 {
   14566       14604 :                     $$ = SystemTypeName("int4");
   14567       14604 :                     $$->location = @1;
   14568             :                 }
   14569             :             | SMALLINT
   14570             :                 {
   14571        1232 :                     $$ = SystemTypeName("int2");
   14572        1232 :                     $$->location = @1;
   14573             :                 }
   14574             :             | BIGINT
   14575             :                 {
   14576        4646 :                     $$ = SystemTypeName("int8");
   14577        4646 :                     $$->location = @1;
   14578             :                 }
   14579             :             | REAL
   14580             :                 {
   14581        1962 :                     $$ = SystemTypeName("float4");
   14582        1962 :                     $$->location = @1;
   14583             :                 }
   14584             :             | FLOAT_P opt_float
   14585             :                 {
   14586         512 :                     $$ = $2;
   14587         512 :                     $$->location = @1;
   14588             :                 }
   14589             :             | DOUBLE_P PRECISION
   14590             :                 {
   14591         698 :                     $$ = SystemTypeName("float8");
   14592         698 :                     $$->location = @1;
   14593             :                 }
   14594             :             | DECIMAL_P opt_type_modifiers
   14595             :                 {
   14596          36 :                     $$ = SystemTypeName("numeric");
   14597          36 :                     $$->typmods = $2;
   14598          36 :                     $$->location = @1;
   14599             :                 }
   14600             :             | DEC opt_type_modifiers
   14601             :                 {
   14602           0 :                     $$ = SystemTypeName("numeric");
   14603           0 :                     $$->typmods = $2;
   14604           0 :                     $$->location = @1;
   14605             :                 }
   14606             :             | NUMERIC opt_type_modifiers
   14607             :                 {
   14608        5936 :                     $$ = SystemTypeName("numeric");
   14609        5936 :                     $$->typmods = $2;
   14610        5936 :                     $$->location = @1;
   14611             :                 }
   14612             :             | BOOLEAN_P
   14613             :                 {
   14614       10684 :                     $$ = SystemTypeName("bool");
   14615       10684 :                     $$->location = @1;
   14616             :                 }
   14617             :         ;
   14618             : 
   14619             : opt_float:  '(' Iconst ')'
   14620             :                 {
   14621             :                     /*
   14622             :                      * Check FLOAT() precision limits assuming IEEE floating
   14623             :                      * types - thomas 1997-09-18
   14624             :                      */
   14625           2 :                     if ($2 < 1)
   14626           0 :                         ereport(ERROR,
   14627             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14628             :                                  errmsg("precision for type float must be at least 1 bit"),
   14629             :                                  parser_errposition(@2)));
   14630           2 :                     else if ($2 <= 24)
   14631           2 :                         $$ = SystemTypeName("float4");
   14632           0 :                     else if ($2 <= 53)
   14633           0 :                         $$ = SystemTypeName("float8");
   14634             :                     else
   14635           0 :                         ereport(ERROR,
   14636             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14637             :                                  errmsg("precision for type float must be less than 54 bits"),
   14638             :                                  parser_errposition(@2)));
   14639             :                 }
   14640             :             | /*EMPTY*/
   14641             :                 {
   14642         510 :                     $$ = SystemTypeName("float8");
   14643             :                 }
   14644             :         ;
   14645             : 
   14646             : /*
   14647             :  * SQL bit-field data types
   14648             :  * The following implements BIT() and BIT VARYING().
   14649             :  */
   14650             : Bit:        BitWithLength
   14651             :                 {
   14652        1696 :                     $$ = $1;
   14653             :                 }
   14654             :             | BitWithoutLength
   14655             :                 {
   14656         198 :                     $$ = $1;
   14657             :                 }
   14658             :         ;
   14659             : 
   14660             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14661             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14662             : ConstBit:   BitWithLength
   14663             :                 {
   14664           0 :                     $$ = $1;
   14665             :                 }
   14666             :             | BitWithoutLength
   14667             :                 {
   14668           0 :                     $$ = $1;
   14669           0 :                     $$->typmods = NIL;
   14670             :                 }
   14671             :         ;
   14672             : 
   14673             : BitWithLength:
   14674             :             BIT opt_varying '(' expr_list ')'
   14675             :                 {
   14676             :                     char *typname;
   14677             : 
   14678        1696 :                     typname = $2 ? "varbit" : "bit";
   14679        1696 :                     $$ = SystemTypeName(typname);
   14680        1696 :                     $$->typmods = $4;
   14681        1696 :                     $$->location = @1;
   14682             :                 }
   14683             :         ;
   14684             : 
   14685             : BitWithoutLength:
   14686             :             BIT opt_varying
   14687             :                 {
   14688             :                     /* bit defaults to bit(1), varbit to no limit */
   14689         198 :                     if ($2)
   14690             :                     {
   14691          20 :                         $$ = SystemTypeName("varbit");
   14692             :                     }
   14693             :                     else
   14694             :                     {
   14695         178 :                         $$ = SystemTypeName("bit");
   14696         178 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14697             :                     }
   14698         198 :                     $$->location = @1;
   14699             :                 }
   14700             :         ;
   14701             : 
   14702             : 
   14703             : /*
   14704             :  * SQL character data types
   14705             :  * The following implements CHAR() and VARCHAR().
   14706             :  */
   14707             : Character:  CharacterWithLength
   14708             :                 {
   14709        1700 :                     $$ = $1;
   14710             :                 }
   14711             :             | CharacterWithoutLength
   14712             :                 {
   14713        1242 :                     $$ = $1;
   14714             :                 }
   14715             :         ;
   14716             : 
   14717             : ConstCharacter:  CharacterWithLength
   14718             :                 {
   14719          12 :                     $$ = $1;
   14720             :                 }
   14721             :             | CharacterWithoutLength
   14722             :                 {
   14723             :                     /* Length was not specified so allow to be unrestricted.
   14724             :                      * This handles problems with fixed-length (bpchar) strings
   14725             :                      * which in column definitions must default to a length
   14726             :                      * of one, but should not be constrained if the length
   14727             :                      * was not specified.
   14728             :                      */
   14729          22 :                     $$ = $1;
   14730          22 :                     $$->typmods = NIL;
   14731             :                 }
   14732             :         ;
   14733             : 
   14734             : CharacterWithLength:  character '(' Iconst ')'
   14735             :                 {
   14736        1712 :                     $$ = SystemTypeName($1);
   14737        1712 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14738        1712 :                     $$->location = @1;
   14739             :                 }
   14740             :         ;
   14741             : 
   14742             : CharacterWithoutLength:  character
   14743             :                 {
   14744        1264 :                     $$ = SystemTypeName($1);
   14745             :                     /* char defaults to char(1), varchar to no limit */
   14746        1264 :                     if (strcmp($1, "bpchar") == 0)
   14747         252 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14748        1264 :                     $$->location = @1;
   14749             :                 }
   14750             :         ;
   14751             : 
   14752             : character:  CHARACTER opt_varying
   14753         522 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14754             :             | CHAR_P opt_varying
   14755        1164 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14756             :             | VARCHAR
   14757        1286 :                                         { $$ = "varchar"; }
   14758             :             | NATIONAL CHARACTER opt_varying
   14759           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14760             :             | NATIONAL CHAR_P opt_varying
   14761           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14762             :             | NCHAR opt_varying
   14763           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14764             :         ;
   14765             : 
   14766             : opt_varying:
   14767         418 :             VARYING                                 { $$ = true; }
   14768        3166 :             | /*EMPTY*/                             { $$ = false; }
   14769             :         ;
   14770             : 
   14771             : /*
   14772             :  * SQL date/time types
   14773             :  */
   14774             : ConstDatetime:
   14775             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14776             :                 {
   14777         124 :                     if ($5)
   14778         100 :                         $$ = SystemTypeName("timestamptz");
   14779             :                     else
   14780          24 :                         $$ = SystemTypeName("timestamp");
   14781         124 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14782         124 :                     $$->location = @1;
   14783             :                 }
   14784             :             | TIMESTAMP opt_timezone
   14785             :                 {
   14786        4840 :                     if ($2)
   14787        1352 :                         $$ = SystemTypeName("timestamptz");
   14788             :                     else
   14789        3488 :                         $$ = SystemTypeName("timestamp");
   14790        4840 :                     $$->location = @1;
   14791             :                 }
   14792             :             | TIME '(' Iconst ')' opt_timezone
   14793             :                 {
   14794          22 :                     if ($5)
   14795           8 :                         $$ = SystemTypeName("timetz");
   14796             :                     else
   14797          14 :                         $$ = SystemTypeName("time");
   14798          22 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14799          22 :                     $$->location = @1;
   14800             :                 }
   14801             :             | TIME opt_timezone
   14802             :                 {
   14803        2352 :                     if ($2)
   14804         344 :                         $$ = SystemTypeName("timetz");
   14805             :                     else
   14806        2008 :                         $$ = SystemTypeName("time");
   14807        2352 :                     $$->location = @1;
   14808             :                 }
   14809             :         ;
   14810             : 
   14811             : ConstInterval:
   14812             :             INTERVAL
   14813             :                 {
   14814        6828 :                     $$ = SystemTypeName("interval");
   14815        6828 :                     $$->location = @1;
   14816             :                 }
   14817             :         ;
   14818             : 
   14819             : opt_timezone:
   14820        1804 :             WITH_LA TIME ZONE                       { $$ = true; }
   14821         592 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14822        4942 :             | /*EMPTY*/                             { $$ = false; }
   14823             :         ;
   14824             : 
   14825             : opt_interval:
   14826             :             YEAR_P
   14827          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14828             :             | MONTH_P
   14829          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14830             :             | DAY_P
   14831          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14832             :             | HOUR_P
   14833          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14834             :             | MINUTE_P
   14835          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14836             :             | interval_second
   14837          36 :                 { $$ = $1; }
   14838             :             | YEAR_P TO MONTH_P
   14839             :                 {
   14840          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14841             :                                                  INTERVAL_MASK(MONTH), @1));
   14842             :                 }
   14843             :             | DAY_P TO HOUR_P
   14844             :                 {
   14845          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14846             :                                                  INTERVAL_MASK(HOUR), @1));
   14847             :                 }
   14848             :             | DAY_P TO MINUTE_P
   14849             :                 {
   14850          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14851             :                                                  INTERVAL_MASK(HOUR) |
   14852             :                                                  INTERVAL_MASK(MINUTE), @1));
   14853             :                 }
   14854             :             | DAY_P TO interval_second
   14855             :                 {
   14856          48 :                     $$ = $3;
   14857          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14858             :                                                 INTERVAL_MASK(HOUR) |
   14859             :                                                 INTERVAL_MASK(MINUTE) |
   14860          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14861             :                 }
   14862             :             | HOUR_P TO MINUTE_P
   14863             :                 {
   14864          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14865             :                                                  INTERVAL_MASK(MINUTE), @1));
   14866             :                 }
   14867             :             | HOUR_P TO interval_second
   14868             :                 {
   14869          36 :                     $$ = $3;
   14870          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14871             :                                                 INTERVAL_MASK(MINUTE) |
   14872          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14873             :                 }
   14874             :             | MINUTE_P TO interval_second
   14875             :                 {
   14876          66 :                     $$ = $3;
   14877          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14878          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14879             :                 }
   14880             :             | /*EMPTY*/
   14881        6474 :                 { $$ = NIL; }
   14882             :         ;
   14883             : 
   14884             : interval_second:
   14885             :             SECOND_P
   14886             :                 {
   14887         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14888             :                 }
   14889             :             | SECOND_P '(' Iconst ')'
   14890             :                 {
   14891          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14892             :                                     makeIntConst($3, @3));
   14893             :                 }
   14894             :         ;
   14895             : 
   14896             : JsonType:
   14897             :             JSON
   14898             :                 {
   14899        1924 :                     $$ = SystemTypeName("json");
   14900        1924 :                     $$->location = @1;
   14901             :                 }
   14902             :         ;
   14903             : 
   14904             : /*****************************************************************************
   14905             :  *
   14906             :  *  expression grammar
   14907             :  *
   14908             :  *****************************************************************************/
   14909             : 
   14910             : /*
   14911             :  * General expressions
   14912             :  * This is the heart of the expression syntax.
   14913             :  *
   14914             :  * We have two expression types: a_expr is the unrestricted kind, and
   14915             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14916             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14917             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14918             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14919             :  *
   14920             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14921             :  * always be used by surrounding it with parens.
   14922             :  *
   14923             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14924             :  * it's factored out just to eliminate redundant coding.
   14925             :  *
   14926             :  * Be careful of productions involving more than one terminal token.
   14927             :  * By default, bison will assign such productions the precedence of their
   14928             :  * last terminal, but in nearly all cases you want it to be the precedence
   14929             :  * of the first terminal instead; otherwise you will not get the behavior
   14930             :  * you expect!  So we use %prec annotations freely to set precedences.
   14931             :  */
   14932     3552270 : a_expr:     c_expr                                  { $$ = $1; }
   14933             :             | a_expr TYPECAST Typename
   14934      198486 :                     { $$ = makeTypeCast($1, $3, @2); }
   14935             :             | a_expr COLLATE any_name
   14936             :                 {
   14937        8732 :                     CollateClause *n = makeNode(CollateClause);
   14938             : 
   14939        8732 :                     n->arg = $1;
   14940        8732 :                     n->collname = $3;
   14941        8732 :                     n->location = @2;
   14942        8732 :                     $$ = (Node *) n;
   14943             :                 }
   14944             :             | a_expr AT TIME ZONE a_expr            %prec AT
   14945             :                 {
   14946         408 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14947         408 :                                                list_make2($5, $1),
   14948             :                                                COERCE_SQL_SYNTAX,
   14949         408 :                                                @2);
   14950             :                 }
   14951             :             | a_expr AT LOCAL                       %prec AT
   14952             :                 {
   14953          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14954          42 :                                                list_make1($1),
   14955             :                                                COERCE_SQL_SYNTAX,
   14956             :                                                -1);
   14957             :                 }
   14958             :         /*
   14959             :          * These operators must be called out explicitly in order to make use
   14960             :          * of bison's automatic operator-precedence handling.  All other
   14961             :          * operator names are handled by the generic productions using "Op",
   14962             :          * below; and all those operators will have the same precedence.
   14963             :          *
   14964             :          * If you add more explicitly-known operators, be sure to add them
   14965             :          * also to b_expr and to the MathOp list below.
   14966             :          */
   14967             :             | '+' a_expr                    %prec UMINUS
   14968          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   14969             :             | '-' a_expr                    %prec UMINUS
   14970       27862 :                 { $$ = doNegate($2, @1); }
   14971             :             | a_expr '+' a_expr
   14972       14116 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   14973             :             | a_expr '-' a_expr
   14974        6212 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   14975             :             | a_expr '*' a_expr
   14976        6124 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   14977             :             | a_expr '/' a_expr
   14978        3374 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   14979             :             | a_expr '%' a_expr
   14980        2776 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   14981             :             | a_expr '^' a_expr
   14982         466 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   14983             :             | a_expr '<' a_expr
   14984       23048 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   14985             :             | a_expr '>' a_expr
   14986       32888 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   14987             :             | a_expr '=' a_expr
   14988      370812 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   14989             :             | a_expr LESS_EQUALS a_expr
   14990        4900 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   14991             :             | a_expr GREATER_EQUALS a_expr
   14992        4924 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   14993             :             | a_expr NOT_EQUALS a_expr
   14994       38408 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   14995             : 
   14996             :             | a_expr qual_Op a_expr             %prec Op
   14997       56442 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   14998             :             | qual_Op a_expr                    %prec Op
   14999         192 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15000             : 
   15001             :             | a_expr AND a_expr
   15002      214020 :                 { $$ = makeAndExpr($1, $3, @2); }
   15003             :             | a_expr OR a_expr
   15004       15930 :                 { $$ = makeOrExpr($1, $3, @2); }
   15005             :             | NOT a_expr
   15006       14428 :                 { $$ = makeNotExpr($2, @1); }
   15007             :             | NOT_LA a_expr                     %prec NOT
   15008           0 :                 { $$ = makeNotExpr($2, @1); }
   15009             : 
   15010             :             | a_expr LIKE a_expr
   15011             :                 {
   15012        1940 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15013        1940 :                                                    $1, $3, @2);
   15014             :                 }
   15015             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15016             :                 {
   15017          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15018          96 :                                                  list_make2($3, $5),
   15019             :                                                  COERCE_EXPLICIT_CALL,
   15020          96 :                                                  @2);
   15021          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15022          96 :                                                    $1, (Node *) n, @2);
   15023             :                 }
   15024             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15025             :                 {
   15026         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15027         198 :                                                    $1, $4, @2);
   15028             :                 }
   15029             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15030             :                 {
   15031          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15032          96 :                                                  list_make2($4, $6),
   15033             :                                                  COERCE_EXPLICIT_CALL,
   15034          96 :                                                  @2);
   15035          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15036          96 :                                                    $1, (Node *) n, @2);
   15037             :                 }
   15038             :             | a_expr ILIKE a_expr
   15039             :                 {
   15040         174 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15041         174 :                                                    $1, $3, @2);
   15042             :                 }
   15043             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15044             :                 {
   15045           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15046           0 :                                                  list_make2($3, $5),
   15047             :                                                  COERCE_EXPLICIT_CALL,
   15048           0 :                                                  @2);
   15049           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15050           0 :                                                    $1, (Node *) n, @2);
   15051             :                 }
   15052             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15053             :                 {
   15054          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15055          30 :                                                    $1, $4, @2);
   15056             :                 }
   15057             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15058             :                 {
   15059           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15060           0 :                                                  list_make2($4, $6),
   15061             :                                                  COERCE_EXPLICIT_CALL,
   15062           0 :                                                  @2);
   15063           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15064           0 :                                                    $1, (Node *) n, @2);
   15065             :                 }
   15066             : 
   15067             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15068             :                 {
   15069          40 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15070          40 :                                                  list_make1($4),
   15071             :                                                  COERCE_EXPLICIT_CALL,
   15072          40 :                                                  @2);
   15073          40 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15074          40 :                                                    $1, (Node *) n, @2);
   15075             :                 }
   15076             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15077             :                 {
   15078          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15079          30 :                                                  list_make2($4, $6),
   15080             :                                                  COERCE_EXPLICIT_CALL,
   15081          30 :                                                  @2);
   15082          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15083          30 :                                                    $1, (Node *) n, @2);
   15084             :                 }
   15085             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15086             :                 {
   15087           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15088           0 :                                                  list_make1($5),
   15089             :                                                  COERCE_EXPLICIT_CALL,
   15090           0 :                                                  @2);
   15091           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15092           0 :                                                    $1, (Node *) n, @2);
   15093             :                 }
   15094             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15095             :                 {
   15096           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15097           0 :                                                  list_make2($5, $7),
   15098             :                                                  COERCE_EXPLICIT_CALL,
   15099           0 :                                                  @2);
   15100           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15101           0 :                                                    $1, (Node *) n, @2);
   15102             :                 }
   15103             : 
   15104             :             /* NullTest clause
   15105             :              * Define SQL-style Null test clause.
   15106             :              * Allow two forms described in the standard:
   15107             :              *  a IS NULL
   15108             :              *  a IS NOT NULL
   15109             :              * Allow two SQL extensions
   15110             :              *  a ISNULL
   15111             :              *  a NOTNULL
   15112             :              */
   15113             :             | a_expr IS NULL_P                          %prec IS
   15114             :                 {
   15115        5004 :                     NullTest   *n = makeNode(NullTest);
   15116             : 
   15117        5004 :                     n->arg = (Expr *) $1;
   15118        5004 :                     n->nulltesttype = IS_NULL;
   15119        5004 :                     n->location = @2;
   15120        5004 :                     $$ = (Node *) n;
   15121             :                 }
   15122             :             | a_expr ISNULL
   15123             :                 {
   15124          96 :                     NullTest   *n = makeNode(NullTest);
   15125             : 
   15126          96 :                     n->arg = (Expr *) $1;
   15127          96 :                     n->nulltesttype = IS_NULL;
   15128          96 :                     n->location = @2;
   15129          96 :                     $$ = (Node *) n;
   15130             :                 }
   15131             :             | a_expr IS NOT NULL_P                      %prec IS
   15132             :                 {
   15133       11404 :                     NullTest   *n = makeNode(NullTest);
   15134             : 
   15135       11404 :                     n->arg = (Expr *) $1;
   15136       11404 :                     n->nulltesttype = IS_NOT_NULL;
   15137       11404 :                     n->location = @2;
   15138       11404 :                     $$ = (Node *) n;
   15139             :                 }
   15140             :             | a_expr NOTNULL
   15141             :                 {
   15142           6 :                     NullTest   *n = makeNode(NullTest);
   15143             : 
   15144           6 :                     n->arg = (Expr *) $1;
   15145           6 :                     n->nulltesttype = IS_NOT_NULL;
   15146           6 :                     n->location = @2;
   15147           6 :                     $$ = (Node *) n;
   15148             :                 }
   15149             :             | row OVERLAPS row
   15150             :                 {
   15151         876 :                     if (list_length($1) != 2)
   15152           0 :                         ereport(ERROR,
   15153             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15154             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15155             :                                  parser_errposition(@1)));
   15156         876 :                     if (list_length($3) != 2)
   15157           0 :                         ereport(ERROR,
   15158             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15159             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15160             :                                  parser_errposition(@3)));
   15161         876 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15162         876 :                                                list_concat($1, $3),
   15163             :                                                COERCE_SQL_SYNTAX,
   15164         876 :                                                @2);
   15165             :                 }
   15166             :             | a_expr IS TRUE_P                          %prec IS
   15167             :                 {
   15168         372 :                     BooleanTest *b = makeNode(BooleanTest);
   15169             : 
   15170         372 :                     b->arg = (Expr *) $1;
   15171         372 :                     b->booltesttype = IS_TRUE;
   15172         372 :                     b->location = @2;
   15173         372 :                     $$ = (Node *) b;
   15174             :                 }
   15175             :             | a_expr IS NOT TRUE_P                      %prec IS
   15176             :                 {
   15177         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15178             : 
   15179         140 :                     b->arg = (Expr *) $1;
   15180         140 :                     b->booltesttype = IS_NOT_TRUE;
   15181         140 :                     b->location = @2;
   15182         140 :                     $$ = (Node *) b;
   15183             :                 }
   15184             :             | a_expr IS FALSE_P                         %prec IS
   15185             :                 {
   15186         102 :                     BooleanTest *b = makeNode(BooleanTest);
   15187             : 
   15188         102 :                     b->arg = (Expr *) $1;
   15189         102 :                     b->booltesttype = IS_FALSE;
   15190         102 :                     b->location = @2;
   15191         102 :                     $$ = (Node *) b;
   15192             :                 }
   15193             :             | a_expr IS NOT FALSE_P                     %prec IS
   15194             :                 {
   15195          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15196             : 
   15197          92 :                     b->arg = (Expr *) $1;
   15198          92 :                     b->booltesttype = IS_NOT_FALSE;
   15199          92 :                     b->location = @2;
   15200          92 :                     $$ = (Node *) b;
   15201             :                 }
   15202             :             | a_expr IS UNKNOWN                         %prec IS
   15203             :                 {
   15204          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15205             : 
   15206          52 :                     b->arg = (Expr *) $1;
   15207          52 :                     b->booltesttype = IS_UNKNOWN;
   15208          52 :                     b->location = @2;
   15209          52 :                     $$ = (Node *) b;
   15210             :                 }
   15211             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15212             :                 {
   15213          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15214             : 
   15215          48 :                     b->arg = (Expr *) $1;
   15216          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15217          48 :                     b->location = @2;
   15218          48 :                     $$ = (Node *) b;
   15219             :                 }
   15220             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15221             :                 {
   15222         876 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15223             :                 }
   15224             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15225             :                 {
   15226          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15227             :                 }
   15228             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15229             :                 {
   15230         466 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15231             :                                                    "BETWEEN",
   15232         466 :                                                    $1,
   15233         466 :                                                    (Node *) list_make2($4, $6),
   15234         466 :                                                    @2);
   15235             :                 }
   15236             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15237             :                 {
   15238          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15239             :                                                    "NOT BETWEEN",
   15240          12 :                                                    $1,
   15241          12 :                                                    (Node *) list_make2($5, $7),
   15242          12 :                                                    @2);
   15243             :                 }
   15244             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15245             :                 {
   15246          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15247             :                                                    "BETWEEN SYMMETRIC",
   15248          12 :                                                    $1,
   15249          12 :                                                    (Node *) list_make2($4, $6),
   15250          12 :                                                    @2);
   15251             :                 }
   15252             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15253             :                 {
   15254          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15255             :                                                    "NOT BETWEEN SYMMETRIC",
   15256          12 :                                                    $1,
   15257          12 :                                                    (Node *) list_make2($5, $7),
   15258          12 :                                                    @2);
   15259             :                 }
   15260             :             | a_expr IN_P in_expr
   15261             :                 {
   15262             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15263       18846 :                     if (IsA($3, SubLink))
   15264             :                     {
   15265             :                         /* generate foo = ANY (subquery) */
   15266        2442 :                         SubLink    *n = (SubLink *) $3;
   15267             : 
   15268        2442 :                         n->subLinkType = ANY_SUBLINK;
   15269        2442 :                         n->subLinkId = 0;
   15270        2442 :                         n->testexpr = $1;
   15271        2442 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15272        2442 :                         n->location = @2;
   15273        2442 :                         $$ = (Node *) n;
   15274             :                     }
   15275             :                     else
   15276             :                     {
   15277             :                         /* generate scalar IN expression */
   15278       16404 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
   15279             :                     }
   15280             :                 }
   15281             :             | a_expr NOT_LA IN_P in_expr                        %prec NOT_LA
   15282             :                 {
   15283             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15284        4970 :                     if (IsA($4, SubLink))
   15285             :                     {
   15286             :                         /* generate NOT (foo = ANY (subquery)) */
   15287             :                         /* Make an = ANY node */
   15288         120 :                         SubLink    *n = (SubLink *) $4;
   15289             : 
   15290         120 :                         n->subLinkType = ANY_SUBLINK;
   15291         120 :                         n->subLinkId = 0;
   15292         120 :                         n->testexpr = $1;
   15293         120 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15294         120 :                         n->location = @2;
   15295             :                         /* Stick a NOT on top; must have same parse location */
   15296         120 :                         $$ = makeNotExpr((Node *) n, @2);
   15297             :                     }
   15298             :                     else
   15299             :                     {
   15300             :                         /* generate scalar NOT IN expression */
   15301        4850 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
   15302             :                     }
   15303             :                 }
   15304             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15305             :                 {
   15306         166 :                     SubLink    *n = makeNode(SubLink);
   15307             : 
   15308         166 :                     n->subLinkType = $3;
   15309         166 :                     n->subLinkId = 0;
   15310         166 :                     n->testexpr = $1;
   15311         166 :                     n->operName = $2;
   15312         166 :                     n->subselect = $4;
   15313         166 :                     n->location = @2;
   15314         166 :                     $$ = (Node *) n;
   15315             :                 }
   15316             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15317             :                 {
   15318       16072 :                     if ($3 == ANY_SUBLINK)
   15319       15772 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15320             :                     else
   15321         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15322             :                 }
   15323             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15324             :                 {
   15325             :                     /* Not sure how to get rid of the parentheses
   15326             :                      * but there are lots of shift/reduce errors without them.
   15327             :                      *
   15328             :                      * Should be able to implement this by plopping the entire
   15329             :                      * select into a node, then transforming the target expressions
   15330             :                      * from whatever they are into count(*), and testing the
   15331             :                      * entire result equal to one.
   15332             :                      * But, will probably implement a separate node in the executor.
   15333             :                      */
   15334           0 :                     ereport(ERROR,
   15335             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15336             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15337             :                              parser_errposition(@1)));
   15338             :                 }
   15339             :             | a_expr IS DOCUMENT_P                  %prec IS
   15340             :                 {
   15341          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15342          18 :                                      list_make1($1), @2);
   15343             :                 }
   15344             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15345             :                 {
   15346          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15347          18 :                                                  list_make1($1), @2),
   15348          18 :                                      @2);
   15349             :                 }
   15350             :             | a_expr IS NORMALIZED                              %prec IS
   15351             :                 {
   15352          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15353          12 :                                                list_make1($1),
   15354             :                                                COERCE_SQL_SYNTAX,
   15355          12 :                                                @2);
   15356             :                 }
   15357             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15358             :                 {
   15359          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15360          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15361             :                                                COERCE_SQL_SYNTAX,
   15362          36 :                                                @2);
   15363             :                 }
   15364             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15365             :                 {
   15366           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15367           0 :                                                            list_make1($1),
   15368             :                                                            COERCE_SQL_SYNTAX,
   15369           0 :                                                            @2),
   15370           0 :                                      @2);
   15371             :                 }
   15372             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15373             :                 {
   15374           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15375           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15376             :                                                            COERCE_SQL_SYNTAX,
   15377           0 :                                                            @2),
   15378           0 :                                      @2);
   15379             :                 }
   15380             :             | a_expr IS json_predicate_type_constraint
   15381             :                     json_key_uniqueness_constraint_opt      %prec IS
   15382             :                 {
   15383         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15384             : 
   15385         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15386             :                 }
   15387             :             /*
   15388             :              * Required by SQL/JSON, but there are conflicts
   15389             :             | a_expr
   15390             :                 json_format_clause
   15391             :                 IS  json_predicate_type_constraint
   15392             :                     json_key_uniqueness_constraint_opt      %prec IS
   15393             :                 {
   15394             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15395             :                 }
   15396             :             */
   15397             :             | a_expr IS NOT
   15398             :                     json_predicate_type_constraint
   15399             :                     json_key_uniqueness_constraint_opt      %prec IS
   15400             :                 {
   15401          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15402             : 
   15403          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15404             :                 }
   15405             :             /*
   15406             :              * Required by SQL/JSON, but there are conflicts
   15407             :             | a_expr
   15408             :                 json_format_clause
   15409             :                 IS NOT
   15410             :                     json_predicate_type_constraint
   15411             :                     json_key_uniqueness_constraint_opt      %prec IS
   15412             :                 {
   15413             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15414             :                 }
   15415             :             */
   15416             :             | DEFAULT
   15417             :                 {
   15418             :                     /*
   15419             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15420             :                      * expressions", but for us, it's easier to allow it in
   15421             :                      * any a_expr and then throw error during parse analysis
   15422             :                      * if it's in an inappropriate context.  This way also
   15423             :                      * lets us say something smarter than "syntax error".
   15424             :                      */
   15425        1504 :                     SetToDefault *n = makeNode(SetToDefault);
   15426             : 
   15427             :                     /* parse analysis will fill in the rest */
   15428        1504 :                     n->location = @1;
   15429        1504 :                     $$ = (Node *) n;
   15430             :                 }
   15431             :         ;
   15432             : 
   15433             : /*
   15434             :  * Restricted expressions
   15435             :  *
   15436             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15437             :  *
   15438             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15439             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15440             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15441             :  */
   15442             : b_expr:     c_expr
   15443        3580 :                 { $$ = $1; }
   15444             :             | b_expr TYPECAST Typename
   15445         134 :                 { $$ = makeTypeCast($1, $3, @2); }
   15446             :             | '+' b_expr                    %prec UMINUS
   15447           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15448             :             | '-' b_expr                    %prec UMINUS
   15449          66 :                 { $$ = doNegate($2, @1); }
   15450             :             | b_expr '+' b_expr
   15451          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15452             :             | b_expr '-' b_expr
   15453          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15454             :             | b_expr '*' b_expr
   15455          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15456             :             | b_expr '/' b_expr
   15457           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15458             :             | b_expr '%' b_expr
   15459           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15460             :             | b_expr '^' b_expr
   15461           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15462             :             | b_expr '<' b_expr
   15463           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15464             :             | b_expr '>' b_expr
   15465           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15466             :             | b_expr '=' b_expr
   15467           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15468             :             | b_expr LESS_EQUALS b_expr
   15469           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15470             :             | b_expr GREATER_EQUALS b_expr
   15471           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15472             :             | b_expr NOT_EQUALS b_expr
   15473           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15474             :             | b_expr qual_Op b_expr             %prec Op
   15475          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15476             :             | qual_Op b_expr                    %prec Op
   15477           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15478             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15479             :                 {
   15480           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15481             :                 }
   15482             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15483             :                 {
   15484           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15485             :                 }
   15486             :             | b_expr IS DOCUMENT_P                  %prec IS
   15487             :                 {
   15488           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15489           0 :                                      list_make1($1), @2);
   15490             :                 }
   15491             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15492             :                 {
   15493           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15494           0 :                                                  list_make1($1), @2),
   15495           0 :                                      @2);
   15496             :                 }
   15497             :         ;
   15498             : 
   15499             : /*
   15500             :  * Productions that can be used in both a_expr and b_expr.
   15501             :  *
   15502             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15503             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15504             :  * inside parentheses, such as function arguments; that cannot introduce
   15505             :  * ambiguity to the b_expr syntax.
   15506             :  */
   15507     1648498 : c_expr:     columnref                               { $$ = $1; }
   15508     1181876 :             | AexprConst                            { $$ = $1; }
   15509             :             | PARAM opt_indirection
   15510             :                 {
   15511      145310 :                     ParamRef   *p = makeNode(ParamRef);
   15512             : 
   15513      145310 :                     p->number = $1;
   15514      145310 :                     p->location = @1;
   15515      145310 :                     if ($2)
   15516             :                     {
   15517        1198 :                         A_Indirection *n = makeNode(A_Indirection);
   15518             : 
   15519        1198 :                         n->arg = (Node *) p;
   15520        1198 :                         n->indirection = check_indirection($2, yyscanner);
   15521        1198 :                         $$ = (Node *) n;
   15522             :                     }
   15523             :                     else
   15524      144112 :                         $$ = (Node *) p;
   15525             :                 }
   15526             :             | '(' a_expr ')' opt_indirection
   15527             :                 {
   15528       85606 :                     if ($4)
   15529             :                     {
   15530       11128 :                         A_Indirection *n = makeNode(A_Indirection);
   15531             : 
   15532       11128 :                         n->arg = $2;
   15533       11128 :                         n->indirection = check_indirection($4, yyscanner);
   15534       11128 :                         $$ = (Node *) n;
   15535             :                     }
   15536             :                     else
   15537       74478 :                         $$ = $2;
   15538             :                 }
   15539             :             | case_expr
   15540       55866 :                 { $$ = $1; }
   15541             :             | func_expr
   15542      386662 :                 { $$ = $1; }
   15543             :             | select_with_parens            %prec UMINUS
   15544             :                 {
   15545       25574 :                     SubLink    *n = makeNode(SubLink);
   15546             : 
   15547       25574 :                     n->subLinkType = EXPR_SUBLINK;
   15548       25574 :                     n->subLinkId = 0;
   15549       25574 :                     n->testexpr = NULL;
   15550       25574 :                     n->operName = NIL;
   15551       25574 :                     n->subselect = $1;
   15552       25574 :                     n->location = @1;
   15553       25574 :                     $$ = (Node *) n;
   15554             :                 }
   15555             :             | select_with_parens indirection
   15556             :                 {
   15557             :                     /*
   15558             :                      * Because the select_with_parens nonterminal is designed
   15559             :                      * to "eat" as many levels of parens as possible, the
   15560             :                      * '(' a_expr ')' opt_indirection production above will
   15561             :                      * fail to match a sub-SELECT with indirection decoration;
   15562             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15563             :                      * as there are parens around it.  To support applying
   15564             :                      * subscripting or field selection to a sub-SELECT result,
   15565             :                      * we need this redundant-looking production.
   15566             :                      */
   15567          18 :                     SubLink    *n = makeNode(SubLink);
   15568          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15569             : 
   15570          18 :                     n->subLinkType = EXPR_SUBLINK;
   15571          18 :                     n->subLinkId = 0;
   15572          18 :                     n->testexpr = NULL;
   15573          18 :                     n->operName = NIL;
   15574          18 :                     n->subselect = $1;
   15575          18 :                     n->location = @1;
   15576          18 :                     a->arg = (Node *) n;
   15577          18 :                     a->indirection = check_indirection($2, yyscanner);
   15578          18 :                     $$ = (Node *) a;
   15579             :                 }
   15580             :             | EXISTS select_with_parens
   15581             :                 {
   15582        5358 :                     SubLink    *n = makeNode(SubLink);
   15583             : 
   15584        5358 :                     n->subLinkType = EXISTS_SUBLINK;
   15585        5358 :                     n->subLinkId = 0;
   15586        5358 :                     n->testexpr = NULL;
   15587        5358 :                     n->operName = NIL;
   15588        5358 :                     n->subselect = $2;
   15589        5358 :                     n->location = @1;
   15590        5358 :                     $$ = (Node *) n;
   15591             :                 }
   15592             :             | ARRAY select_with_parens
   15593             :                 {
   15594        7888 :                     SubLink    *n = makeNode(SubLink);
   15595             : 
   15596        7888 :                     n->subLinkType = ARRAY_SUBLINK;
   15597        7888 :                     n->subLinkId = 0;
   15598        7888 :                     n->testexpr = NULL;
   15599        7888 :                     n->operName = NIL;
   15600        7888 :                     n->subselect = $2;
   15601        7888 :                     n->location = @1;
   15602        7888 :                     $$ = (Node *) n;
   15603             :                 }
   15604             :             | ARRAY array_expr
   15605             :                 {
   15606        7150 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15607             : 
   15608             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15609        7150 :                     n->location = @1;
   15610        7150 :                     $$ = (Node *) n;
   15611             :                 }
   15612             :             | explicit_row
   15613             :                 {
   15614        3894 :                     RowExpr    *r = makeNode(RowExpr);
   15615             : 
   15616        3894 :                     r->args = $1;
   15617        3894 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15618        3894 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15619        3894 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15620        3894 :                     r->location = @1;
   15621        3894 :                     $$ = (Node *) r;
   15622             :                 }
   15623             :             | implicit_row
   15624             :                 {
   15625        2438 :                     RowExpr    *r = makeNode(RowExpr);
   15626             : 
   15627        2438 :                     r->args = $1;
   15628        2438 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15629        2438 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15630        2438 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15631        2438 :                     r->location = @1;
   15632        2438 :                     $$ = (Node *) r;
   15633             :                 }
   15634             :             | GROUPING '(' expr_list ')'
   15635             :               {
   15636         362 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15637             : 
   15638         362 :                   g->args = $3;
   15639         362 :                   g->location = @1;
   15640         362 :                   $$ = (Node *) g;
   15641             :               }
   15642             :         ;
   15643             : 
   15644             : func_application: func_name '(' ')'
   15645             :                 {
   15646       45640 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15647             :                                                COERCE_EXPLICIT_CALL,
   15648       45640 :                                                @1);
   15649             :                 }
   15650             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15651             :                 {
   15652      302504 :                     FuncCall   *n = makeFuncCall($1, $3,
   15653             :                                                  COERCE_EXPLICIT_CALL,
   15654      302504 :                                                  @1);
   15655             : 
   15656      302504 :                     n->agg_order = $4;
   15657      302504 :                     $$ = (Node *) n;
   15658             :                 }
   15659             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15660             :                 {
   15661         594 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15662             :                                                  COERCE_EXPLICIT_CALL,
   15663         594 :                                                  @1);
   15664             : 
   15665         594 :                     n->func_variadic = true;
   15666         594 :                     n->agg_order = $5;
   15667         594 :                     $$ = (Node *) n;
   15668             :                 }
   15669             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15670             :                 {
   15671         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15672             :                                                  COERCE_EXPLICIT_CALL,
   15673         120 :                                                  @1);
   15674             : 
   15675         120 :                     n->func_variadic = true;
   15676         120 :                     n->agg_order = $7;
   15677         120 :                     $$ = (Node *) n;
   15678             :                 }
   15679             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15680             :                 {
   15681           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15682             :                                                  COERCE_EXPLICIT_CALL,
   15683           0 :                                                  @1);
   15684             : 
   15685           0 :                     n->agg_order = $5;
   15686             :                     /* Ideally we'd mark the FuncCall node to indicate
   15687             :                      * "must be an aggregate", but there's no provision
   15688             :                      * for that in FuncCall at the moment.
   15689             :                      */
   15690           0 :                     $$ = (Node *) n;
   15691             :                 }
   15692             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15693             :                 {
   15694         538 :                     FuncCall   *n = makeFuncCall($1, $4,
   15695             :                                                  COERCE_EXPLICIT_CALL,
   15696         538 :                                                  @1);
   15697             : 
   15698         538 :                     n->agg_order = $5;
   15699         538 :                     n->agg_distinct = true;
   15700         538 :                     $$ = (Node *) n;
   15701             :                 }
   15702             :             | func_name '(' '*' ')'
   15703             :                 {
   15704             :                     /*
   15705             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15706             :                      * aggregate.  This does the right thing for COUNT(*),
   15707             :                      * and there are no other aggregates in SQL that accept
   15708             :                      * '*' as parameter.
   15709             :                      *
   15710             :                      * The FuncCall node is also marked agg_star = true,
   15711             :                      * so that later processing can detect what the argument
   15712             :                      * really was.
   15713             :                      */
   15714       12248 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15715             :                                                  COERCE_EXPLICIT_CALL,
   15716       12248 :                                                  @1);
   15717             : 
   15718       12248 :                     n->agg_star = true;
   15719       12248 :                     $$ = (Node *) n;
   15720             :                 }
   15721             :         ;
   15722             : 
   15723             : 
   15724             : /*
   15725             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15726             :  * so that we have classifications for "everything that is a function call or
   15727             :  * looks like one".  This isn't very important, but it saves us having to
   15728             :  * document which variants are legal in places like "FROM function()" or the
   15729             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15730             :  * (Note that many of the special SQL functions wouldn't actually make any
   15731             :  * sense as functional index entries, but we ignore that consideration here.)
   15732             :  */
   15733             : func_expr: func_application within_group_clause filter_clause over_clause
   15734             :                 {
   15735      316884 :                     FuncCall   *n = (FuncCall *) $1;
   15736             : 
   15737             :                     /*
   15738             :                      * The order clause for WITHIN GROUP and the one for
   15739             :                      * plain-aggregate ORDER BY share a field, so we have to
   15740             :                      * check here that at most one is present.  We also check
   15741             :                      * for DISTINCT and VARIADIC here to give a better error
   15742             :                      * location.  Other consistency checks are deferred to
   15743             :                      * parse analysis.
   15744             :                      */
   15745      316884 :                     if ($2 != NIL)
   15746             :                     {
   15747         348 :                         if (n->agg_order != NIL)
   15748           6 :                             ereport(ERROR,
   15749             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15750             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15751             :                                      parser_errposition(@2)));
   15752         342 :                         if (n->agg_distinct)
   15753           0 :                             ereport(ERROR,
   15754             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15755             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15756             :                                      parser_errposition(@2)));
   15757         342 :                         if (n->func_variadic)
   15758           0 :                             ereport(ERROR,
   15759             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15760             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15761             :                                      parser_errposition(@2)));
   15762         342 :                         n->agg_order = $2;
   15763         342 :                         n->agg_within_group = true;
   15764             :                     }
   15765      316878 :                     n->agg_filter = $3;
   15766      316878 :                     n->over = $4;
   15767      316878 :                     $$ = (Node *) n;
   15768             :                 }
   15769             :             | json_aggregate_func filter_clause over_clause
   15770             :                 {
   15771         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15772         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15773         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15774             : 
   15775         360 :                     n->agg_filter = $2;
   15776         360 :                     n->over = $3;
   15777         360 :                     $$ = (Node *) $1;
   15778             :                 }
   15779             :             | func_expr_common_subexpr
   15780       69424 :                 { $$ = $1; }
   15781             :         ;
   15782             : 
   15783             : /*
   15784             :  * Like func_expr but does not accept WINDOW functions directly
   15785             :  * (but they can still be contained in arguments for functions etc).
   15786             :  * Use this when window expressions are not allowed, where needed to
   15787             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15788             :  */
   15789             : func_expr_windowless:
   15790       44140 :             func_application                        { $$ = $1; }
   15791         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15792           0 :             | json_aggregate_func                   { $$ = $1; }
   15793             :         ;
   15794             : 
   15795             : /*
   15796             :  * Special expressions that are considered to be functions.
   15797             :  */
   15798             : func_expr_common_subexpr:
   15799             :             COLLATION FOR '(' a_expr ')'
   15800             :                 {
   15801          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15802          30 :                                                list_make1($4),
   15803             :                                                COERCE_SQL_SYNTAX,
   15804          30 :                                                @1);
   15805             :                 }
   15806             :             | CURRENT_DATE
   15807             :                 {
   15808         288 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15809             :                 }
   15810             :             | CURRENT_TIME
   15811             :                 {
   15812          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15813             :                 }
   15814             :             | CURRENT_TIME '(' Iconst ')'
   15815             :                 {
   15816          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15817             :                 }
   15818             :             | CURRENT_TIMESTAMP
   15819             :                 {
   15820         288 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15821             :                 }
   15822             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15823             :                 {
   15824         164 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15825             :                 }
   15826             :             | LOCALTIME
   15827             :                 {
   15828          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15829             :                 }
   15830             :             | LOCALTIME '(' Iconst ')'
   15831             :                 {
   15832          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15833             :                 }
   15834             :             | LOCALTIMESTAMP
   15835             :                 {
   15836          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15837             :                 }
   15838             :             | LOCALTIMESTAMP '(' Iconst ')'
   15839             :                 {
   15840          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15841             :                 }
   15842             :             | CURRENT_ROLE
   15843             :                 {
   15844         116 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15845             :                 }
   15846             :             | CURRENT_USER
   15847             :                 {
   15848        1028 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15849             :                 }
   15850             :             | SESSION_USER
   15851             :                 {
   15852         622 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15853             :                 }
   15854             :             | SYSTEM_USER
   15855             :                 {
   15856          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15857             :                                                NIL,
   15858             :                                                COERCE_SQL_SYNTAX,
   15859             :                                                @1);
   15860             :                 }
   15861             :             | USER
   15862             :                 {
   15863          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15864             :                 }
   15865             :             | CURRENT_CATALOG
   15866             :                 {
   15867          52 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15868             :                 }
   15869             :             | CURRENT_SCHEMA
   15870             :                 {
   15871          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15872             :                 }
   15873             :             | CAST '(' a_expr AS Typename ')'
   15874       56042 :                 { $$ = makeTypeCast($3, $5, @1); }
   15875             :             | EXTRACT '(' extract_list ')'
   15876             :                 {
   15877        1330 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15878        1330 :                                                $3,
   15879             :                                                COERCE_SQL_SYNTAX,
   15880        1330 :                                                @1);
   15881             :                 }
   15882             :             | NORMALIZE '(' a_expr ')'
   15883             :                 {
   15884          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15885          18 :                                                list_make1($3),
   15886             :                                                COERCE_SQL_SYNTAX,
   15887          18 :                                                @1);
   15888             :                 }
   15889             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15890             :                 {
   15891          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15892          36 :                                                list_make2($3, makeStringConst($5, @5)),
   15893             :                                                COERCE_SQL_SYNTAX,
   15894          36 :                                                @1);
   15895             :                 }
   15896             :             | OVERLAY '(' overlay_list ')'
   15897             :                 {
   15898          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15899          82 :                                                $3,
   15900             :                                                COERCE_SQL_SYNTAX,
   15901          82 :                                                @1);
   15902             :                 }
   15903             :             | OVERLAY '(' func_arg_list_opt ')'
   15904             :                 {
   15905             :                     /*
   15906             :                      * allow functions named overlay() to be called without
   15907             :                      * special syntax
   15908             :                      */
   15909           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15910           0 :                                                $3,
   15911             :                                                COERCE_EXPLICIT_CALL,
   15912           0 :                                                @1);
   15913             :                 }
   15914             :             | POSITION '(' position_list ')'
   15915             :                 {
   15916             :                     /*
   15917             :                      * position(A in B) is converted to position(B, A)
   15918             :                      *
   15919             :                      * We deliberately don't offer a "plain syntax" option
   15920             :                      * for position(), because the reversal of the arguments
   15921             :                      * creates too much risk of confusion.
   15922             :                      */
   15923         360 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15924         360 :                                                $3,
   15925             :                                                COERCE_SQL_SYNTAX,
   15926         360 :                                                @1);
   15927             :                 }
   15928             :             | SUBSTRING '(' substr_list ')'
   15929             :                 {
   15930             :                     /* substring(A from B for C) is converted to
   15931             :                      * substring(A, B, C) - thomas 2000-11-28
   15932             :                      */
   15933         670 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   15934         670 :                                                $3,
   15935             :                                                COERCE_SQL_SYNTAX,
   15936         670 :                                                @1);
   15937             :                 }
   15938             :             | SUBSTRING '(' func_arg_list_opt ')'
   15939             :                 {
   15940             :                     /*
   15941             :                      * allow functions named substring() to be called without
   15942             :                      * special syntax
   15943             :                      */
   15944         198 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   15945         198 :                                                $3,
   15946             :                                                COERCE_EXPLICIT_CALL,
   15947         198 :                                                @1);
   15948             :                 }
   15949             :             | TREAT '(' a_expr AS Typename ')'
   15950             :                 {
   15951             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   15952             :                      * which is defined to be a subtype of the original expression.
   15953             :                      * In SQL99, this is intended for use with structured UDTs,
   15954             :                      * but let's make this a generally useful form allowing stronger
   15955             :                      * coercions than are handled by implicit casting.
   15956             :                      *
   15957             :                      * Convert SystemTypeName() to SystemFuncName() even though
   15958             :                      * at the moment they result in the same thing.
   15959             :                      */
   15960           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   15961           0 :                                                list_make1($3),
   15962             :                                                COERCE_EXPLICIT_CALL,
   15963           0 :                                                @1);
   15964             :                 }
   15965             :             | TRIM '(' BOTH trim_list ')'
   15966             :                 {
   15967             :                     /* various trim expressions are defined in SQL
   15968             :                      * - thomas 1997-07-19
   15969             :                      */
   15970          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15971          12 :                                                $4,
   15972             :                                                COERCE_SQL_SYNTAX,
   15973          12 :                                                @1);
   15974             :                 }
   15975             :             | TRIM '(' LEADING trim_list ')'
   15976             :                 {
   15977          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   15978          24 :                                                $4,
   15979             :                                                COERCE_SQL_SYNTAX,
   15980          24 :                                                @1);
   15981             :                 }
   15982             :             | TRIM '(' TRAILING trim_list ')'
   15983             :                 {
   15984         564 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   15985         564 :                                                $4,
   15986             :                                                COERCE_SQL_SYNTAX,
   15987         564 :                                                @1);
   15988             :                 }
   15989             :             | TRIM '(' trim_list ')'
   15990             :                 {
   15991          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15992          98 :                                                $3,
   15993             :                                                COERCE_SQL_SYNTAX,
   15994          98 :                                                @1);
   15995             :                 }
   15996             :             | NULLIF '(' a_expr ',' a_expr ')'
   15997             :                 {
   15998         284 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   15999             :                 }
   16000             :             | COALESCE '(' expr_list ')'
   16001             :                 {
   16002        3116 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16003             : 
   16004        3116 :                     c->args = $3;
   16005        3116 :                     c->location = @1;
   16006        3116 :                     $$ = (Node *) c;
   16007             :                 }
   16008             :             | GREATEST '(' expr_list ')'
   16009             :                 {
   16010         140 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16011             : 
   16012         140 :                     v->args = $3;
   16013         140 :                     v->op = IS_GREATEST;
   16014         140 :                     v->location = @1;
   16015         140 :                     $$ = (Node *) v;
   16016             :                 }
   16017             :             | LEAST '(' expr_list ')'
   16018             :                 {
   16019         142 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16020             : 
   16021         142 :                     v->args = $3;
   16022         142 :                     v->op = IS_LEAST;
   16023         142 :                     v->location = @1;
   16024         142 :                     $$ = (Node *) v;
   16025             :                 }
   16026             :             | XMLCONCAT '(' expr_list ')'
   16027             :                 {
   16028          62 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16029             :                 }
   16030             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16031             :                 {
   16032           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16033             :                 }
   16034             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16035             :                 {
   16036          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16037             :                 }
   16038             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16039             :                 {
   16040         116 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16041             :                 }
   16042             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16043             :                 {
   16044          20 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16045             :                 }
   16046             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16047             :                 {
   16048             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16049             :                      * converted to xmlexists(A, B)*/
   16050          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16051          54 :                                                list_make2($3, $4),
   16052             :                                                COERCE_SQL_SYNTAX,
   16053          54 :                                                @1);
   16054             :                 }
   16055             :             | XMLFOREST '(' xml_attribute_list ')'
   16056             :                 {
   16057          32 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16058             :                 }
   16059             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16060             :                 {
   16061             :                     XmlExpr *x = (XmlExpr *)
   16062         140 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16063         140 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16064         140 :                                     @1);
   16065             : 
   16066         140 :                     x->xmloption = $3;
   16067         140 :                     $$ = (Node *) x;
   16068             :                 }
   16069             :             | XMLPI '(' NAME_P ColLabel ')'
   16070             :                 {
   16071          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16072             :                 }
   16073             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16074             :                 {
   16075          50 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16076             :                 }
   16077             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16078             :                 {
   16079          68 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16080          68 :                                      list_make3($3, $5, $6), @1);
   16081             :                 }
   16082             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16083             :                 {
   16084         202 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16085             : 
   16086         202 :                     n->xmloption = $3;
   16087         202 :                     n->expr = $4;
   16088         202 :                     n->typeName = $6;
   16089         202 :                     n->indent = $7;
   16090         202 :                     n->location = @1;
   16091         202 :                     $$ = (Node *) n;
   16092             :                 }
   16093             :             | JSON_OBJECT '(' func_arg_list ')'
   16094             :                 {
   16095             :                     /* Support for legacy (non-standard) json_object() */
   16096          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16097          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16098             :                 }
   16099             :             | JSON_OBJECT '(' json_name_and_value_list
   16100             :                 json_object_constructor_null_clause_opt
   16101             :                 json_key_uniqueness_constraint_opt
   16102             :                 json_returning_clause_opt ')'
   16103             :                 {
   16104         342 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16105             : 
   16106         342 :                     n->exprs = $3;
   16107         342 :                     n->absent_on_null = $4;
   16108         342 :                     n->unique = $5;
   16109         342 :                     n->output = (JsonOutput *) $6;
   16110         342 :                     n->location = @1;
   16111         342 :                     $$ = (Node *) n;
   16112             :                 }
   16113             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16114             :                 {
   16115          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16116             : 
   16117          92 :                     n->exprs = NULL;
   16118          92 :                     n->absent_on_null = false;
   16119          92 :                     n->unique = false;
   16120          92 :                     n->output = (JsonOutput *) $3;
   16121          92 :                     n->location = @1;
   16122          92 :                     $$ = (Node *) n;
   16123             :                 }
   16124             :             | JSON_ARRAY '('
   16125             :                 json_value_expr_list
   16126             :                 json_array_constructor_null_clause_opt
   16127             :                 json_returning_clause_opt
   16128             :             ')'
   16129             :                 {
   16130         108 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16131             : 
   16132         108 :                     n->exprs = $3;
   16133         108 :                     n->absent_on_null = $4;
   16134         108 :                     n->output = (JsonOutput *) $5;
   16135         108 :                     n->location = @1;
   16136         108 :                     $$ = (Node *) n;
   16137             :                 }
   16138             :             | JSON_ARRAY '('
   16139             :                 select_no_parens
   16140             :                 json_format_clause_opt
   16141             :                 /* json_array_constructor_null_clause_opt */
   16142             :                 json_returning_clause_opt
   16143             :             ')'
   16144             :                 {
   16145          54 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16146             : 
   16147          54 :                     n->query = $3;
   16148          54 :                     n->format = (JsonFormat *) $4;
   16149          54 :                     n->absent_on_null = true;    /* XXX */
   16150          54 :                     n->output = (JsonOutput *) $5;
   16151          54 :                     n->location = @1;
   16152          54 :                     $$ = (Node *) n;
   16153             :                 }
   16154             :             | JSON_ARRAY '('
   16155             :                 json_returning_clause_opt
   16156             :             ')'
   16157             :                 {
   16158          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16159             : 
   16160          86 :                     n->exprs = NIL;
   16161          86 :                     n->absent_on_null = true;
   16162          86 :                     n->output = (JsonOutput *) $3;
   16163          86 :                     n->location = @1;
   16164          86 :                     $$ = (Node *) n;
   16165             :                 }
   16166             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16167             :                 {
   16168         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16169             : 
   16170         164 :                     n->expr = (JsonValueExpr *) $3;
   16171         164 :                     n->unique_keys = $4;
   16172         164 :                     n->output = NULL;
   16173         164 :                     n->location = @1;
   16174         164 :                     $$ = (Node *) n;
   16175             :                 }
   16176             :             | JSON_SCALAR '(' a_expr ')'
   16177             :                 {
   16178         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16179             : 
   16180         112 :                     n->expr = (Expr *) $3;
   16181         112 :                     n->output = NULL;
   16182         112 :                     n->location = @1;
   16183         112 :                     $$ = (Node *) n;
   16184             :                 }
   16185             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16186             :                 {
   16187         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16188             : 
   16189         108 :                     n->expr = (JsonValueExpr *) $3;
   16190         108 :                     n->output = (JsonOutput *) $4;
   16191         108 :                     n->location = @1;
   16192         108 :                     $$ = (Node *) n;
   16193             :                 }
   16194             :             | MERGE_ACTION '(' ')'
   16195             :                 {
   16196         192 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16197             : 
   16198         192 :                     m->msftype = TEXTOID;
   16199         192 :                     m->location = @1;
   16200         192 :                     $$ = (Node *) m;
   16201             :                 }
   16202             :             | JSON_QUERY '('
   16203             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16204             :                 json_returning_clause_opt
   16205             :                 json_wrapper_behavior
   16206             :                 json_quotes_clause_opt
   16207             :                 json_behavior_clause_opt
   16208             :             ')'
   16209             :                 {
   16210         984 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16211             : 
   16212         984 :                     n->op = JSON_QUERY_OP;
   16213         984 :                     n->context_item = (JsonValueExpr *) $3;
   16214         984 :                     n->pathspec = $5;
   16215         984 :                     n->passing = $6;
   16216         984 :                     n->output = (JsonOutput *) $7;
   16217         984 :                     n->wrapper = $8;
   16218         984 :                     n->quotes = $9;
   16219         984 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16220         984 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16221         984 :                     n->location = @1;
   16222         984 :                     $$ = (Node *) n;
   16223             :                 }
   16224             :             | JSON_EXISTS '('
   16225             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16226             :                 json_on_error_clause_opt
   16227             :             ')'
   16228             :                 {
   16229         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16230             : 
   16231         168 :                     n->op = JSON_EXISTS_OP;
   16232         168 :                     n->context_item = (JsonValueExpr *) $3;
   16233         168 :                     n->pathspec = $5;
   16234         168 :                     n->passing = $6;
   16235         168 :                     n->output = NULL;
   16236         168 :                     n->on_error = (JsonBehavior *) $7;
   16237         168 :                     n->location = @1;
   16238         168 :                     $$ = (Node *) n;
   16239             :                 }
   16240             :             | JSON_VALUE '('
   16241             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16242             :                 json_returning_clause_opt
   16243             :                 json_behavior_clause_opt
   16244             :             ')'
   16245             :                 {
   16246         576 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16247             : 
   16248         576 :                     n->op = JSON_VALUE_OP;
   16249         576 :                     n->context_item = (JsonValueExpr *) $3;
   16250         576 :                     n->pathspec = $5;
   16251         576 :                     n->passing = $6;
   16252         576 :                     n->output = (JsonOutput *) $7;
   16253         576 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16254         576 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16255         576 :                     n->location = @1;
   16256         576 :                     $$ = (Node *) n;
   16257             :                 }
   16258             :             ;
   16259             : 
   16260             : 
   16261             : /*
   16262             :  * SQL/XML support
   16263             :  */
   16264             : xml_root_version: VERSION_P a_expr
   16265          24 :                 { $$ = $2; }
   16266             :             | VERSION_P NO VALUE_P
   16267          44 :                 { $$ = makeNullAConst(-1); }
   16268             :         ;
   16269             : 
   16270             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16271          26 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16272             :             | ',' STANDALONE_P NO
   16273          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16274             :             | ',' STANDALONE_P NO VALUE_P
   16275          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16276             :             | /*EMPTY*/
   16277          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16278             :         ;
   16279             : 
   16280          56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16281             :         ;
   16282             : 
   16283          88 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16284         144 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16285             :         ;
   16286             : 
   16287             : xml_attribute_el: a_expr AS ColLabel
   16288             :                 {
   16289         106 :                     $$ = makeNode(ResTarget);
   16290         106 :                     $$->name = $3;
   16291         106 :                     $$->indirection = NIL;
   16292         106 :                     $$->val = (Node *) $1;
   16293         106 :                     $$->location = @1;
   16294             :                 }
   16295             :             | a_expr
   16296             :                 {
   16297         126 :                     $$ = makeNode(ResTarget);
   16298         126 :                     $$->name = NULL;
   16299         126 :                     $$->indirection = NIL;
   16300         126 :                     $$->val = (Node *) $1;
   16301         126 :                     $$->location = @1;
   16302             :                 }
   16303             :         ;
   16304             : 
   16305         170 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16306         188 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16307             :         ;
   16308             : 
   16309         132 : xml_indent_option: INDENT                           { $$ = true; }
   16310          24 :             | NO INDENT                             { $$ = false; }
   16311          46 :             | /*EMPTY*/                             { $$ = false; }
   16312             :         ;
   16313             : 
   16314           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16315           2 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16316         138 :             | /*EMPTY*/                             { $$ = false; }
   16317             :         ;
   16318             : 
   16319             : /* We allow several variants for SQL and other compatibility. */
   16320             : xmlexists_argument:
   16321             :             PASSING c_expr
   16322             :                 {
   16323         226 :                     $$ = $2;
   16324             :                 }
   16325             :             | PASSING c_expr xml_passing_mech
   16326             :                 {
   16327           0 :                     $$ = $2;
   16328             :                 }
   16329             :             | PASSING xml_passing_mech c_expr
   16330             :                 {
   16331          42 :                     $$ = $3;
   16332             :                 }
   16333             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16334             :                 {
   16335           6 :                     $$ = $3;
   16336             :                 }
   16337             :         ;
   16338             : 
   16339             : xml_passing_mech:
   16340             :             BY REF_P
   16341             :             | BY VALUE_P
   16342             :         ;
   16343             : 
   16344             : 
   16345             : /*
   16346             :  * Aggregate decoration clauses
   16347             :  */
   16348             : within_group_clause:
   16349         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16350      316542 :             | /*EMPTY*/                             { $$ = NIL; }
   16351             :         ;
   16352             : 
   16353             : filter_clause:
   16354         836 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16355      316414 :             | /*EMPTY*/                             { $$ = NULL; }
   16356             :         ;
   16357             : 
   16358             : 
   16359             : /*
   16360             :  * Window Definitions
   16361             :  */
   16362             : window_clause:
   16363         528 :             WINDOW window_definition_list           { $$ = $2; }
   16364      482010 :             | /*EMPTY*/                             { $$ = NIL; }
   16365             :         ;
   16366             : 
   16367             : window_definition_list:
   16368         528 :             window_definition                       { $$ = list_make1($1); }
   16369             :             | window_definition_list ',' window_definition
   16370          12 :                                                     { $$ = lappend($1, $3); }
   16371             :         ;
   16372             : 
   16373             : window_definition:
   16374             :             ColId AS window_specification
   16375             :                 {
   16376         540 :                     WindowDef  *n = $3;
   16377             : 
   16378         540 :                     n->name = $1;
   16379         540 :                     $$ = n;
   16380             :                 }
   16381             :         ;
   16382             : 
   16383             : over_clause: OVER window_specification
   16384        2524 :                 { $$ = $2; }
   16385             :             | OVER ColId
   16386             :                 {
   16387         942 :                     WindowDef  *n = makeNode(WindowDef);
   16388             : 
   16389         942 :                     n->name = $2;
   16390         942 :                     n->refname = NULL;
   16391         942 :                     n->partitionClause = NIL;
   16392         942 :                     n->orderClause = NIL;
   16393         942 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16394         942 :                     n->startOffset = NULL;
   16395         942 :                     n->endOffset = NULL;
   16396         942 :                     n->location = @2;
   16397         942 :                     $$ = n;
   16398             :                 }
   16399             :             | /*EMPTY*/
   16400      313778 :                 { $$ = NULL; }
   16401             :         ;
   16402             : 
   16403             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16404             :                         opt_sort_clause opt_frame_clause ')'
   16405             :                 {
   16406        3064 :                     WindowDef  *n = makeNode(WindowDef);
   16407             : 
   16408        3064 :                     n->name = NULL;
   16409        3064 :                     n->refname = $2;
   16410        3064 :                     n->partitionClause = $3;
   16411        3064 :                     n->orderClause = $4;
   16412             :                     /* copy relevant fields of opt_frame_clause */
   16413        3064 :                     n->frameOptions = $5->frameOptions;
   16414        3064 :                     n->startOffset = $5->startOffset;
   16415        3064 :                     n->endOffset = $5->endOffset;
   16416        3064 :                     n->location = @1;
   16417        3064 :                     $$ = n;
   16418             :                 }
   16419             :         ;
   16420             : 
   16421             : /*
   16422             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16423             :  * of a window_specification, we want the assumption to be that there is
   16424             :  * no existing_window_name; but those keywords are unreserved and so could
   16425             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16426             :  * and giving the empty production here a slightly higher precedence, so
   16427             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16428             :  * These keywords are thus precluded from being an existing_window_name but
   16429             :  * are not reserved for any other purpose.
   16430             :  */
   16431          30 : opt_existing_window_name: ColId                     { $$ = $1; }
   16432        3040 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16433             :         ;
   16434             : 
   16435         850 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16436        2214 :             | /*EMPTY*/                             { $$ = NIL; }
   16437             :         ;
   16438             : 
   16439             : /*
   16440             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16441             :  * frameOptions, startOffset, and endOffset.
   16442             :  */
   16443             : opt_frame_clause:
   16444             :             RANGE frame_extent opt_window_exclusion_clause
   16445             :                 {
   16446         796 :                     WindowDef  *n = $2;
   16447             : 
   16448         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16449         796 :                     n->frameOptions |= $3;
   16450         796 :                     $$ = n;
   16451             :                 }
   16452             :             | ROWS frame_extent opt_window_exclusion_clause
   16453             :                 {
   16454         618 :                     WindowDef  *n = $2;
   16455             : 
   16456         618 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16457         618 :                     n->frameOptions |= $3;
   16458         618 :                     $$ = n;
   16459             :                 }
   16460             :             | GROUPS frame_extent opt_window_exclusion_clause
   16461             :                 {
   16462         204 :                     WindowDef  *n = $2;
   16463             : 
   16464         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16465         204 :                     n->frameOptions |= $3;
   16466         204 :                     $$ = n;
   16467             :                 }
   16468             :             | /*EMPTY*/
   16469             :                 {
   16470        1446 :                     WindowDef  *n = makeNode(WindowDef);
   16471             : 
   16472        1446 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16473        1446 :                     n->startOffset = NULL;
   16474        1446 :                     n->endOffset = NULL;
   16475        1446 :                     $$ = n;
   16476             :                 }
   16477             :         ;
   16478             : 
   16479             : frame_extent: frame_bound
   16480             :                 {
   16481           6 :                     WindowDef  *n = $1;
   16482             : 
   16483             :                     /* reject invalid cases */
   16484           6 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16485           0 :                         ereport(ERROR,
   16486             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16487             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16488             :                                  parser_errposition(@1)));
   16489           6 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16490           0 :                         ereport(ERROR,
   16491             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16492             :                                  errmsg("frame starting from following row cannot end with current row"),
   16493             :                                  parser_errposition(@1)));
   16494           6 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16495           6 :                     $$ = n;
   16496             :                 }
   16497             :             | BETWEEN frame_bound AND frame_bound
   16498             :                 {
   16499        1612 :                     WindowDef  *n1 = $2;
   16500        1612 :                     WindowDef  *n2 = $4;
   16501             : 
   16502             :                     /* form merged options */
   16503        1612 :                     int     frameOptions = n1->frameOptions;
   16504             :                     /* shift converts START_ options to END_ options */
   16505        1612 :                     frameOptions |= n2->frameOptions << 1;
   16506        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16507             :                     /* reject invalid cases */
   16508        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16509           0 :                         ereport(ERROR,
   16510             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16511             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16512             :                                  parser_errposition(@2)));
   16513        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16514           0 :                         ereport(ERROR,
   16515             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16516             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16517             :                                  parser_errposition(@4)));
   16518        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16519         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16520           0 :                         ereport(ERROR,
   16521             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16522             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16523             :                                  parser_errposition(@4)));
   16524        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16525         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16526             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16527           0 :                         ereport(ERROR,
   16528             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16529             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16530             :                                  parser_errposition(@4)));
   16531        1612 :                     n1->frameOptions = frameOptions;
   16532        1612 :                     n1->endOffset = n2->startOffset;
   16533        1612 :                     $$ = n1;
   16534             :                 }
   16535             :         ;
   16536             : 
   16537             : /*
   16538             :  * This is used for both frame start and frame end, with output set up on
   16539             :  * the assumption it's frame start; the frame_extent productions must reject
   16540             :  * invalid cases.
   16541             :  */
   16542             : frame_bound:
   16543             :             UNBOUNDED PRECEDING
   16544             :                 {
   16545         198 :                     WindowDef  *n = makeNode(WindowDef);
   16546             : 
   16547         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16548         198 :                     n->startOffset = NULL;
   16549         198 :                     n->endOffset = NULL;
   16550         198 :                     $$ = n;
   16551             :                 }
   16552             :             | UNBOUNDED FOLLOWING
   16553             :                 {
   16554         376 :                     WindowDef  *n = makeNode(WindowDef);
   16555             : 
   16556         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16557         376 :                     n->startOffset = NULL;
   16558         376 :                     n->endOffset = NULL;
   16559         376 :                     $$ = n;
   16560             :                 }
   16561             :             | CURRENT_P ROW
   16562             :                 {
   16563         604 :                     WindowDef  *n = makeNode(WindowDef);
   16564             : 
   16565         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16566         604 :                     n->startOffset = NULL;
   16567         604 :                     n->endOffset = NULL;
   16568         604 :                     $$ = n;
   16569             :                 }
   16570             :             | a_expr PRECEDING
   16571             :                 {
   16572         900 :                     WindowDef  *n = makeNode(WindowDef);
   16573             : 
   16574         900 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16575         900 :                     n->startOffset = $1;
   16576         900 :                     n->endOffset = NULL;
   16577         900 :                     $$ = n;
   16578             :                 }
   16579             :             | a_expr FOLLOWING
   16580             :                 {
   16581        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16582             : 
   16583        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16584        1152 :                     n->startOffset = $1;
   16585        1152 :                     n->endOffset = NULL;
   16586        1152 :                     $$ = n;
   16587             :                 }
   16588             :         ;
   16589             : 
   16590             : opt_window_exclusion_clause:
   16591          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16592          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16593         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16594          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16595        1270 :             | /*EMPTY*/             { $$ = 0; }
   16596             :         ;
   16597             : 
   16598             : 
   16599             : /*
   16600             :  * Supporting nonterminals for expressions.
   16601             :  */
   16602             : 
   16603             : /* Explicit row production.
   16604             :  *
   16605             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16606             :  * without conflicting with the parenthesized a_expr production.  Without the
   16607             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16608             :  */
   16609           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16610           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16611        1752 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16612             :         ;
   16613             : 
   16614        3864 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16615          30 :             | ROW '(' ')'                           { $$ = NIL; }
   16616             :         ;
   16617             : 
   16618        2438 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16619             :         ;
   16620             : 
   16621       15914 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16622           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16623         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16624             :         ;
   16625             : 
   16626       11238 : all_Op:     Op                                      { $$ = $1; }
   16627       26404 :             | MathOp                                { $$ = $1; }
   16628             :         ;
   16629             : 
   16630          40 : MathOp:      '+'                                    { $$ = "+"; }
   16631          46 :             | '-'                                   { $$ = "-"; }
   16632         138 :             | '*'                                   { $$ = "*"; }
   16633           0 :             | '/'                                   { $$ = "/"; }
   16634           8 :             | '%'                                   { $$ = "%"; }
   16635           0 :             | '^'                                   { $$ = "^"; }
   16636         752 :             | '<'                                    { $$ = "<"; }
   16637         594 :             | '>'                                    { $$ = ">"; }
   16638       23018 :             | '='                                   { $$ = "="; }
   16639         618 :             | LESS_EQUALS                           { $$ = "<="; }
   16640         610 :             | GREATER_EQUALS                        { $$ = ">="; }
   16641         580 :             | NOT_EQUALS                            { $$ = "<>"; }
   16642             :         ;
   16643             : 
   16644             : qual_Op:    Op
   16645       41712 :                     { $$ = list_make1(makeString($1)); }
   16646             :             | OPERATOR '(' any_operator ')'
   16647       14940 :                     { $$ = $3; }
   16648             :         ;
   16649             : 
   16650             : qual_all_Op:
   16651             :             all_Op
   16652        1414 :                     { $$ = list_make1(makeString($1)); }
   16653             :             | OPERATOR '(' any_operator ')'
   16654          34 :                     { $$ = $3; }
   16655             :         ;
   16656             : 
   16657             : subquery_Op:
   16658             :             all_Op
   16659       15970 :                     { $$ = list_make1(makeString($1)); }
   16660             :             | OPERATOR '(' any_operator ')'
   16661         236 :                     { $$ = $3; }
   16662             :             | LIKE
   16663          24 :                     { $$ = list_make1(makeString("~~")); }
   16664             :             | NOT_LA LIKE
   16665          12 :                     { $$ = list_make1(makeString("!~~")); }
   16666             :             | ILIKE
   16667          12 :                     { $$ = list_make1(makeString("~~*")); }
   16668             :             | NOT_LA ILIKE
   16669           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16670             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16671             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16672             :  * and the ~ operator for posix regular expressions is used.
   16673             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16674             :  * this transformation is made on the fly by the parser upwards.
   16675             :  * however the SubLink structure which handles any/some/all stuff
   16676             :  * is not ready for such a thing.
   16677             :  */
   16678             :             ;
   16679             : 
   16680             : expr_list:  a_expr
   16681             :                 {
   16682      161450 :                     $$ = list_make1($1);
   16683             :                 }
   16684             :             | expr_list ',' a_expr
   16685             :                 {
   16686      145760 :                     $$ = lappend($1, $3);
   16687             :                 }
   16688             :         ;
   16689             : 
   16690             : /* function arguments can have names */
   16691             : func_arg_list:  func_arg_expr
   16692             :                 {
   16693      303450 :                     $$ = list_make1($1);
   16694             :                 }
   16695             :             | func_arg_list ',' func_arg_expr
   16696             :                 {
   16697      223344 :                     $$ = lappend($1, $3);
   16698             :                 }
   16699             :         ;
   16700             : 
   16701             : func_arg_expr:  a_expr
   16702             :                 {
   16703      479098 :                     $$ = $1;
   16704             :                 }
   16705             :             | param_name COLON_EQUALS a_expr
   16706             :                 {
   16707       45778 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16708             : 
   16709       45778 :                     na->name = $1;
   16710       45778 :                     na->arg = (Expr *) $3;
   16711       45778 :                     na->argnumber = -1;      /* until determined */
   16712       45778 :                     na->location = @1;
   16713       45778 :                     $$ = (Node *) na;
   16714             :                 }
   16715             :             | param_name EQUALS_GREATER a_expr
   16716             :                 {
   16717        2632 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16718             : 
   16719        2632 :                     na->name = $1;
   16720        2632 :                     na->arg = (Expr *) $3;
   16721        2632 :                     na->argnumber = -1;      /* until determined */
   16722        2632 :                     na->location = @1;
   16723        2632 :                     $$ = (Node *) na;
   16724             :                 }
   16725             :         ;
   16726             : 
   16727         198 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16728           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16729             :         ;
   16730             : 
   16731        1700 : type_list:  Typename                                { $$ = list_make1($1); }
   16732         392 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16733             :         ;
   16734             : 
   16735             : array_expr: '[' expr_list ']'
   16736             :                 {
   16737        7392 :                     $$ = makeAArrayExpr($2, @1);
   16738             :                 }
   16739             :             | '[' array_expr_list ']'
   16740             :                 {
   16741         406 :                     $$ = makeAArrayExpr($2, @1);
   16742             :                 }
   16743             :             | '[' ']'
   16744             :                 {
   16745          88 :                     $$ = makeAArrayExpr(NIL, @1);
   16746             :                 }
   16747             :         ;
   16748             : 
   16749         406 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16750         330 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16751             :         ;
   16752             : 
   16753             : 
   16754             : extract_list:
   16755             :             extract_arg FROM a_expr
   16756             :                 {
   16757        1330 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16758             :                 }
   16759             :         ;
   16760             : 
   16761             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16762             :  * - thomas 2001-04-12
   16763             :  */
   16764             : extract_arg:
   16765        1084 :             IDENT                                   { $$ = $1; }
   16766          60 :             | YEAR_P                                { $$ = "year"; }
   16767          42 :             | MONTH_P                               { $$ = "month"; }
   16768          54 :             | DAY_P                                 { $$ = "day"; }
   16769          30 :             | HOUR_P                                { $$ = "hour"; }
   16770          30 :             | MINUTE_P                              { $$ = "minute"; }
   16771          30 :             | SECOND_P                              { $$ = "second"; }
   16772           0 :             | Sconst                                { $$ = $1; }
   16773             :         ;
   16774             : 
   16775             : unicode_normal_form:
   16776          24 :             NFC                                     { $$ = "NFC"; }
   16777          12 :             | NFD                                   { $$ = "NFD"; }
   16778          18 :             | NFKC                                  { $$ = "NFKC"; }
   16779          18 :             | NFKD                                  { $$ = "NFKD"; }
   16780             :         ;
   16781             : 
   16782             : /* OVERLAY() arguments */
   16783             : overlay_list:
   16784             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16785             :                 {
   16786             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16787          34 :                     $$ = list_make4($1, $3, $5, $7);
   16788             :                 }
   16789             :             | a_expr PLACING a_expr FROM a_expr
   16790             :                 {
   16791             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16792          48 :                     $$ = list_make3($1, $3, $5);
   16793             :                 }
   16794             :         ;
   16795             : 
   16796             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16797             : position_list:
   16798         360 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16799             :         ;
   16800             : 
   16801             : /*
   16802             :  * SUBSTRING() arguments
   16803             :  *
   16804             :  * Note that SQL:1999 has both
   16805             :  *     text FROM int FOR int
   16806             :  * and
   16807             :  *     text FROM pattern FOR escape
   16808             :  *
   16809             :  * In the parser we map them both to a call to the substring() function and
   16810             :  * rely on type resolution to pick the right one.
   16811             :  *
   16812             :  * In SQL:2003, the second variant was changed to
   16813             :  *     text SIMILAR pattern ESCAPE escape
   16814             :  * We could in theory map that to a different function internally, but
   16815             :  * since we still support the SQL:1999 version, we don't.  However,
   16816             :  * ruleutils.c will reverse-list the call in the newer style.
   16817             :  */
   16818             : substr_list:
   16819             :             a_expr FROM a_expr FOR a_expr
   16820             :                 {
   16821         122 :                     $$ = list_make3($1, $3, $5);
   16822             :                 }
   16823             :             | a_expr FOR a_expr FROM a_expr
   16824             :                 {
   16825             :                     /* not legal per SQL, but might as well allow it */
   16826           0 :                     $$ = list_make3($1, $5, $3);
   16827             :                 }
   16828             :             | a_expr FROM a_expr
   16829             :                 {
   16830             :                     /*
   16831             :                      * Because we aren't restricting data types here, this
   16832             :                      * syntax can end up resolving to textregexsubstr().
   16833             :                      * We've historically allowed that to happen, so continue
   16834             :                      * to accept it.  However, ruleutils.c will reverse-list
   16835             :                      * such a call in regular function call syntax.
   16836             :                      */
   16837         340 :                     $$ = list_make2($1, $3);
   16838             :                 }
   16839             :             | a_expr FOR a_expr
   16840             :                 {
   16841             :                     /* not legal per SQL */
   16842             : 
   16843             :                     /*
   16844             :                      * Since there are no cases where this syntax allows
   16845             :                      * a textual FOR value, we forcibly cast the argument
   16846             :                      * to int4.  The possible matches in pg_proc are
   16847             :                      * substring(text,int4) and substring(text,text),
   16848             :                      * and we don't want the parser to choose the latter,
   16849             :                      * which it is likely to do if the second argument
   16850             :                      * is unknown or doesn't have an implicit cast to int4.
   16851             :                      */
   16852          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16853             :                                     makeTypeCast($3,
   16854             :                                                  SystemTypeName("int4"), -1));
   16855             :                 }
   16856             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16857             :                 {
   16858         172 :                     $$ = list_make3($1, $3, $5);
   16859             :                 }
   16860             :         ;
   16861             : 
   16862         588 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16863          24 :             | FROM expr_list                        { $$ = $2; }
   16864          86 :             | expr_list                             { $$ = $1; }
   16865             :         ;
   16866             : 
   16867             : in_expr:    select_with_parens
   16868             :                 {
   16869        2562 :                     SubLink    *n = makeNode(SubLink);
   16870             : 
   16871        2562 :                     n->subselect = $1;
   16872             :                     /* other fields will be filled later */
   16873        2562 :                     $$ = (Node *) n;
   16874             :                 }
   16875       21254 :             | '(' expr_list ')'                     { $$ = (Node *) $2; }
   16876             :         ;
   16877             : 
   16878             : /*
   16879             :  * Define SQL-style CASE clause.
   16880             :  * - Full specification
   16881             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16882             :  * - Implicit argument
   16883             :  *  CASE a WHEN b THEN c ... ELSE d END
   16884             :  */
   16885             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16886             :                 {
   16887       55866 :                     CaseExpr   *c = makeNode(CaseExpr);
   16888             : 
   16889       55866 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16890       55866 :                     c->arg = (Expr *) $2;
   16891       55866 :                     c->args = $3;
   16892       55866 :                     c->defresult = (Expr *) $4;
   16893       55866 :                     c->location = @1;
   16894       55866 :                     $$ = (Node *) c;
   16895             :                 }
   16896             :         ;
   16897             : 
   16898             : when_clause_list:
   16899             :             /* There must be at least one */
   16900       55866 :             when_clause                             { $$ = list_make1($1); }
   16901       44046 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16902             :         ;
   16903             : 
   16904             : when_clause:
   16905             :             WHEN a_expr THEN a_expr
   16906             :                 {
   16907       99912 :                     CaseWhen   *w = makeNode(CaseWhen);
   16908             : 
   16909       99912 :                     w->expr = (Expr *) $2;
   16910       99912 :                     w->result = (Expr *) $4;
   16911       99912 :                     w->location = @1;
   16912       99912 :                     $$ = (Node *) w;
   16913             :                 }
   16914             :         ;
   16915             : 
   16916             : case_default:
   16917       46800 :             ELSE a_expr                             { $$ = $2; }
   16918        9066 :             | /*EMPTY*/                             { $$ = NULL; }
   16919             :         ;
   16920             : 
   16921        6354 : case_arg:   a_expr                                  { $$ = $1; }
   16922       49512 :             | /*EMPTY*/                             { $$ = NULL; }
   16923             :         ;
   16924             : 
   16925             : columnref:  ColId
   16926             :                 {
   16927      670800 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16928             :                 }
   16929             :             | ColId indirection
   16930             :                 {
   16931      977698 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16932             :                 }
   16933             :         ;
   16934             : 
   16935             : indirection_el:
   16936             :             '.' attr_name
   16937             :                 {
   16938     1323990 :                     $$ = (Node *) makeString($2);
   16939             :                 }
   16940             :             | '.' '*'
   16941             :                 {
   16942        6680 :                     $$ = (Node *) makeNode(A_Star);
   16943             :                 }
   16944             :             | '[' a_expr ']'
   16945             :                 {
   16946       12414 :                     A_Indices *ai = makeNode(A_Indices);
   16947             : 
   16948       12414 :                     ai->is_slice = false;
   16949       12414 :                     ai->lidx = NULL;
   16950       12414 :                     ai->uidx = $2;
   16951       12414 :                     $$ = (Node *) ai;
   16952             :                 }
   16953             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   16954             :                 {
   16955         570 :                     A_Indices *ai = makeNode(A_Indices);
   16956             : 
   16957         570 :                     ai->is_slice = true;
   16958         570 :                     ai->lidx = $2;
   16959         570 :                     ai->uidx = $4;
   16960         570 :                     $$ = (Node *) ai;
   16961             :                 }
   16962             :         ;
   16963             : 
   16964             : opt_slice_bound:
   16965         960 :             a_expr                                  { $$ = $1; }
   16966         180 :             | /*EMPTY*/                             { $$ = NULL; }
   16967             :         ;
   16968             : 
   16969             : indirection:
   16970     1324432 :             indirection_el                          { $$ = list_make1($1); }
   16971        2974 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   16972             :         ;
   16973             : 
   16974             : opt_indirection:
   16975      288910 :             /*EMPTY*/                               { $$ = NIL; }
   16976       16248 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   16977             :         ;
   16978             : 
   16979             : opt_asymmetric: ASYMMETRIC
   16980             :             | /*EMPTY*/
   16981             :         ;
   16982             : 
   16983             : /* SQL/JSON support */
   16984             : json_passing_clause_opt:
   16985         336 :             PASSING json_arguments                  { $$ = $2; }
   16986        1934 :             | /*EMPTY*/                             { $$ = NIL; }
   16987             :         ;
   16988             : 
   16989             : json_arguments:
   16990         336 :             json_argument                           { $$ = list_make1($1); }
   16991         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   16992             :         ;
   16993             : 
   16994             : json_argument:
   16995             :             json_value_expr AS ColLabel
   16996             :             {
   16997         462 :                 JsonArgument *n = makeNode(JsonArgument);
   16998             : 
   16999         462 :                 n->val = (JsonValueExpr *) $1;
   17000         462 :                 n->name = $3;
   17001         462 :                 $$ = (Node *) n;
   17002             :             }
   17003             :         ;
   17004             : 
   17005             : /* ARRAY is a noise word */
   17006             : json_wrapper_behavior:
   17007          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17008           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17009          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17010          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17011           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17012          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17013          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17014           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17015        1634 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17016             :         ;
   17017             : 
   17018             : json_behavior:
   17019             :             DEFAULT a_expr
   17020         384 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17021             :             | json_behavior_type
   17022         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17023             :         ;
   17024             : 
   17025             : json_behavior_type:
   17026         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17027          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17028          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17029          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17030          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17031          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17032          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17033             :             /* non-standard, for Oracle compatibility only */
   17034          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17035             :         ;
   17036             : 
   17037             : json_behavior_clause_opt:
   17038             :             json_behavior ON EMPTY_P
   17039         174 :                 { $$ = list_make2($1, NULL); }
   17040             :             | json_behavior ON ERROR_P
   17041         552 :                 { $$ = list_make2(NULL, $1); }
   17042             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17043         102 :                 { $$ = list_make2($1, $4); }
   17044             :             | /* EMPTY */
   17045        1568 :                 { $$ = list_make2(NULL, NULL); }
   17046             :         ;
   17047             : 
   17048             : json_on_error_clause_opt:
   17049             :             json_behavior ON ERROR_P
   17050         150 :                 { $$ = $1; }
   17051             :             | /* EMPTY */
   17052         686 :                 { $$ = NULL; }
   17053             :         ;
   17054             : 
   17055             : json_value_expr:
   17056             :             a_expr json_format_clause_opt
   17057             :             {
   17058             :                 /* formatted_expr will be set during parse-analysis. */
   17059        4196 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17060        4196 :                                                 castNode(JsonFormat, $2));
   17061             :             }
   17062             :         ;
   17063             : 
   17064             : json_format_clause:
   17065             :             FORMAT_LA JSON ENCODING name
   17066             :                 {
   17067             :                     int     encoding;
   17068             : 
   17069         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17070          64 :                         encoding = JS_ENC_UTF8;
   17071          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17072          12 :                         encoding = JS_ENC_UTF16;
   17073          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17074          12 :                         encoding = JS_ENC_UTF32;
   17075             :                     else
   17076          12 :                         ereport(ERROR,
   17077             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17078             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17079             :                                  parser_errposition(@4)));
   17080             : 
   17081          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17082             :                 }
   17083             :             | FORMAT_LA JSON
   17084             :                 {
   17085         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17086             :                 }
   17087             :         ;
   17088             : 
   17089             : json_format_clause_opt:
   17090             :             json_format_clause
   17091             :                 {
   17092         392 :                     $$ = $1;
   17093             :                 }
   17094             :             | /* EMPTY */
   17095             :                 {
   17096        5302 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17097             :                 }
   17098             :         ;
   17099             : 
   17100             : json_quotes_clause_opt:
   17101          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17102          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17103          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17104         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17105        1538 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17106             :         ;
   17107             : 
   17108             : json_returning_clause_opt:
   17109             :             RETURNING Typename json_format_clause_opt
   17110             :                 {
   17111        1444 :                     JsonOutput *n = makeNode(JsonOutput);
   17112             : 
   17113        1444 :                     n->typeName = $2;
   17114        1444 :                     n->returning = makeNode(JsonReturning);
   17115        1444 :                     n->returning->format = (JsonFormat *) $3;
   17116        1444 :                     $$ = (Node *) n;
   17117             :                 }
   17118        1266 :             | /* EMPTY */                           { $$ = NULL; }
   17119             :         ;
   17120             : 
   17121             : /*
   17122             :  * We must assign the only-JSON production a precedence less than IDENT in
   17123             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17124             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17125             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17126             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17127             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17128             :  * really related to this syntax, but it's a convenient choice because it
   17129             :  * already has a precedence less than IDENT for other reasons.
   17130             :  */
   17131             : json_predicate_type_constraint:
   17132         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17133          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17134          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17135          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17136          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17137             :         ;
   17138             : 
   17139             : /*
   17140             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17141             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17142             :  * This prevents reducing them when the next token is KEYS.
   17143             :  */
   17144             : json_key_uniqueness_constraint_opt:
   17145         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17146         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17147          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17148          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17149         792 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17150             :         ;
   17151             : 
   17152             : json_name_and_value_list:
   17153             :             json_name_and_value
   17154         342 :                 { $$ = list_make1($1); }
   17155             :             | json_name_and_value_list ',' json_name_and_value
   17156         256 :                 { $$ = lappend($1, $3); }
   17157             :         ;
   17158             : 
   17159             : json_name_and_value:
   17160             : /* Supporting this syntax seems to require major surgery
   17161             :             KEY c_expr VALUE_P json_value_expr
   17162             :                 { $$ = makeJsonKeyValue($2, $4); }
   17163             :             |
   17164             : */
   17165             :             c_expr VALUE_P json_value_expr
   17166          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17167             :             |
   17168             :             a_expr ':' json_value_expr
   17169         778 :                 { $$ = makeJsonKeyValue($1, $3); }
   17170             :         ;
   17171             : 
   17172             : /* empty means false for objects, true for arrays */
   17173             : json_object_constructor_null_clause_opt:
   17174          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17175         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17176         406 :             | /* EMPTY */                       { $$ = false; }
   17177             :         ;
   17178             : 
   17179             : json_array_constructor_null_clause_opt:
   17180          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17181          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17182         168 :             | /* EMPTY */                           { $$ = true; }
   17183             :         ;
   17184             : 
   17185             : json_value_expr_list:
   17186         108 :             json_value_expr                             { $$ = list_make1($1); }
   17187         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17188             :         ;
   17189             : 
   17190             : json_aggregate_func:
   17191             :             JSON_OBJECTAGG '('
   17192             :                 json_name_and_value
   17193             :                 json_object_constructor_null_clause_opt
   17194             :                 json_key_uniqueness_constraint_opt
   17195             :                 json_returning_clause_opt
   17196             :             ')'
   17197             :                 {
   17198         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17199             : 
   17200         204 :                     n->arg = (JsonKeyValue *) $3;
   17201         204 :                     n->absent_on_null = $4;
   17202         204 :                     n->unique = $5;
   17203         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17204         204 :                     n->constructor->output = (JsonOutput *) $6;
   17205         204 :                     n->constructor->agg_order = NULL;
   17206         204 :                     n->constructor->location = @1;
   17207         204 :                     $$ = (Node *) n;
   17208             :                 }
   17209             :             | JSON_ARRAYAGG '('
   17210             :                 json_value_expr
   17211             :                 json_array_aggregate_order_by_clause_opt
   17212             :                 json_array_constructor_null_clause_opt
   17213             :                 json_returning_clause_opt
   17214             :             ')'
   17215             :                 {
   17216         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17217             : 
   17218         156 :                     n->arg = (JsonValueExpr *) $3;
   17219         156 :                     n->absent_on_null = $5;
   17220         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17221         156 :                     n->constructor->agg_order = $4;
   17222         156 :                     n->constructor->output = (JsonOutput *) $6;
   17223         156 :                     n->constructor->location = @1;
   17224         156 :                     $$ = (Node *) n;
   17225             :                 }
   17226             :         ;
   17227             : 
   17228             : json_array_aggregate_order_by_clause_opt:
   17229          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17230         138 :             | /* EMPTY */                           { $$ = NIL; }
   17231             :         ;
   17232             : 
   17233             : /*****************************************************************************
   17234             :  *
   17235             :  *  target list for SELECT
   17236             :  *
   17237             :  *****************************************************************************/
   17238             : 
   17239      478804 : opt_target_list: target_list                        { $$ = $1; }
   17240         402 :             | /* EMPTY */                           { $$ = NIL; }
   17241             :         ;
   17242             : 
   17243             : target_list:
   17244      485262 :             target_el                               { $$ = list_make1($1); }
   17245      605872 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17246             :         ;
   17247             : 
   17248             : target_el:  a_expr AS ColLabel
   17249             :                 {
   17250      203138 :                     $$ = makeNode(ResTarget);
   17251      203138 :                     $$->name = $3;
   17252      203138 :                     $$->indirection = NIL;
   17253      203138 :                     $$->val = (Node *) $1;
   17254      203138 :                     $$->location = @1;
   17255             :                 }
   17256             :             | a_expr BareColLabel
   17257             :                 {
   17258        3368 :                     $$ = makeNode(ResTarget);
   17259        3368 :                     $$->name = $2;
   17260        3368 :                     $$->indirection = NIL;
   17261        3368 :                     $$->val = (Node *) $1;
   17262        3368 :                     $$->location = @1;
   17263             :                 }
   17264             :             | a_expr
   17265             :                 {
   17266      833546 :                     $$ = makeNode(ResTarget);
   17267      833546 :                     $$->name = NULL;
   17268      833546 :                     $$->indirection = NIL;
   17269      833546 :                     $$->val = (Node *) $1;
   17270      833546 :                     $$->location = @1;
   17271             :                 }
   17272             :             | '*'
   17273             :                 {
   17274       51082 :                     ColumnRef  *n = makeNode(ColumnRef);
   17275             : 
   17276       51082 :                     n->fields = list_make1(makeNode(A_Star));
   17277       51082 :                     n->location = @1;
   17278             : 
   17279       51082 :                     $$ = makeNode(ResTarget);
   17280       51082 :                     $$->name = NULL;
   17281       51082 :                     $$->indirection = NIL;
   17282       51082 :                     $$->val = (Node *) n;
   17283       51082 :                     $$->location = @1;
   17284             :                 }
   17285             :         ;
   17286             : 
   17287             : 
   17288             : /*****************************************************************************
   17289             :  *
   17290             :  *  Names and constants
   17291             :  *
   17292             :  *****************************************************************************/
   17293             : 
   17294             : qualified_name_list:
   17295       16138 :             qualified_name                          { $$ = list_make1($1); }
   17296         422 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17297             :         ;
   17298             : 
   17299             : /*
   17300             :  * The production for a qualified relation name has to exactly match the
   17301             :  * production for a qualified func_name, because in a FROM clause we cannot
   17302             :  * tell which we are parsing until we see what comes after it ('(' for a
   17303             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17304             :  * which may contain subscripts, and reject that case in the C code.
   17305             :  */
   17306             : qualified_name:
   17307             :             ColId
   17308             :                 {
   17309      399276 :                     $$ = makeRangeVar(NULL, $1, @1);
   17310             :                 }
   17311             :             | ColId indirection
   17312             :                 {
   17313      229518 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17314             :                 }
   17315             :         ;
   17316             : 
   17317             : name_list:  name
   17318       25500 :                     { $$ = list_make1(makeString($1)); }
   17319             :             | name_list ',' name
   17320       53824 :                     { $$ = lappend($1, makeString($3)); }
   17321             :         ;
   17322             : 
   17323             : 
   17324      157024 : name:       ColId                                   { $$ = $1; };
   17325             : 
   17326     1437616 : attr_name:  ColLabel                                { $$ = $1; };
   17327             : 
   17328          58 : file_name:  Sconst                                  { $$ = $1; };
   17329             : 
   17330             : /*
   17331             :  * The production for a qualified func_name has to exactly match the
   17332             :  * production for a qualified columnref, because we cannot tell which we
   17333             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17334             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17335             :  * may contain subscripts, and reject that case in the C code.  (If we
   17336             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17337             :  */
   17338             : func_name:  type_function_name
   17339      296254 :                     { $$ = list_make1(makeString($1)); }
   17340             :             | ColId indirection
   17341             :                     {
   17342      117138 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17343             :                                              yyscanner);
   17344             :                     }
   17345             :         ;
   17346             : 
   17347             : 
   17348             : /*
   17349             :  * Constants
   17350             :  */
   17351             : AexprConst: Iconst
   17352             :                 {
   17353      433566 :                     $$ = makeIntConst($1, @1);
   17354             :                 }
   17355             :             | FCONST
   17356             :                 {
   17357       11810 :                     $$ = makeFloatConst($1, @1);
   17358             :                 }
   17359             :             | Sconst
   17360             :                 {
   17361      597340 :                     $$ = makeStringConst($1, @1);
   17362             :                 }
   17363             :             | BCONST
   17364             :                 {
   17365         754 :                     $$ = makeBitStringConst($1, @1);
   17366             :                 }
   17367             :             | XCONST
   17368             :                 {
   17369             :                     /* This is a bit constant per SQL99:
   17370             :                      * Without Feature F511, "BIT data type",
   17371             :                      * a <general literal> shall not be a
   17372             :                      * <bit string literal> or a <hex string literal>.
   17373             :                      */
   17374        3302 :                     $$ = makeBitStringConst($1, @1);
   17375             :                 }
   17376             :             | func_name Sconst
   17377             :                 {
   17378             :                     /* generic type 'literal' syntax */
   17379        9762 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17380             : 
   17381        9762 :                     t->location = @1;
   17382        9762 :                     $$ = makeStringConstCast($2, @2, t);
   17383             :                 }
   17384             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17385             :                 {
   17386             :                     /* generic syntax with a type modifier */
   17387           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17388             :                     ListCell   *lc;
   17389             : 
   17390             :                     /*
   17391             :                      * We must use func_arg_list and opt_sort_clause in the
   17392             :                      * production to avoid reduce/reduce conflicts, but we
   17393             :                      * don't actually wish to allow NamedArgExpr in this
   17394             :                      * context, nor ORDER BY.
   17395             :                      */
   17396           0 :                     foreach(lc, $3)
   17397             :                     {
   17398           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17399             : 
   17400           0 :                         if (IsA(arg, NamedArgExpr))
   17401           0 :                             ereport(ERROR,
   17402             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17403             :                                      errmsg("type modifier cannot have parameter name"),
   17404             :                                      parser_errposition(arg->location)));
   17405             :                     }
   17406           0 :                     if ($4 != NIL)
   17407           0 :                             ereport(ERROR,
   17408             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17409             :                                      errmsg("type modifier cannot have ORDER BY"),
   17410             :                                      parser_errposition(@4)));
   17411             : 
   17412           0 :                     t->typmods = $3;
   17413           0 :                     t->location = @1;
   17414           0 :                     $$ = makeStringConstCast($6, @6, t);
   17415             :                 }
   17416             :             | ConstTypename Sconst
   17417             :                 {
   17418        3114 :                     $$ = makeStringConstCast($2, @2, $1);
   17419             :                 }
   17420             :             | ConstInterval Sconst opt_interval
   17421             :                 {
   17422        3298 :                     TypeName   *t = $1;
   17423             : 
   17424        3298 :                     t->typmods = $3;
   17425        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17426             :                 }
   17427             :             | ConstInterval '(' Iconst ')' Sconst
   17428             :                 {
   17429          12 :                     TypeName   *t = $1;
   17430             : 
   17431          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17432             :                                             makeIntConst($3, @3));
   17433          12 :                     $$ = makeStringConstCast($5, @5, t);
   17434             :                 }
   17435             :             | TRUE_P
   17436             :                 {
   17437       23302 :                     $$ = makeBoolAConst(true, @1);
   17438             :                 }
   17439             :             | FALSE_P
   17440             :                 {
   17441       32588 :                     $$ = makeBoolAConst(false, @1);
   17442             :                 }
   17443             :             | NULL_P
   17444             :                 {
   17445       63160 :                     $$ = makeNullAConst(@1);
   17446             :                 }
   17447             :         ;
   17448             : 
   17449      457246 : Iconst:     ICONST                                  { $$ = $1; };
   17450      666434 : Sconst:     SCONST                                  { $$ = $1; };
   17451             : 
   17452       15746 : SignedIconst: Iconst                                { $$ = $1; }
   17453           0 :             | '+' Iconst                            { $$ = + $2; }
   17454         266 :             | '-' Iconst                            { $$ = - $2; }
   17455             :         ;
   17456             : 
   17457             : /* Role specifications */
   17458             : RoleId:     RoleSpec
   17459             :                 {
   17460        1860 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17461             : 
   17462        1860 :                     switch (spc->roletype)
   17463             :                     {
   17464        1850 :                         case ROLESPEC_CSTRING:
   17465        1850 :                             $$ = spc->rolename;
   17466        1850 :                             break;
   17467           4 :                         case ROLESPEC_PUBLIC:
   17468           4 :                             ereport(ERROR,
   17469             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17470             :                                      errmsg("role name \"%s\" is reserved",
   17471             :                                             "public"),
   17472             :                                      parser_errposition(@1)));
   17473             :                             break;
   17474           2 :                         case ROLESPEC_SESSION_USER:
   17475           2 :                             ereport(ERROR,
   17476             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17477             :                                      errmsg("%s cannot be used as a role name here",
   17478             :                                             "SESSION_USER"),
   17479             :                                      parser_errposition(@1)));
   17480             :                             break;
   17481           2 :                         case ROLESPEC_CURRENT_USER:
   17482           2 :                             ereport(ERROR,
   17483             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17484             :                                      errmsg("%s cannot be used as a role name here",
   17485             :                                             "CURRENT_USER"),
   17486             :                                      parser_errposition(@1)));
   17487             :                             break;
   17488           2 :                         case ROLESPEC_CURRENT_ROLE:
   17489           2 :                             ereport(ERROR,
   17490             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17491             :                                      errmsg("%s cannot be used as a role name here",
   17492             :                                             "CURRENT_ROLE"),
   17493             :                                      parser_errposition(@1)));
   17494             :                             break;
   17495             :                     }
   17496        1850 :                 }
   17497             :             ;
   17498             : 
   17499             : RoleSpec:   NonReservedWord
   17500             :                 {
   17501             :                     /*
   17502             :                      * "public" and "none" are not keywords, but they must
   17503             :                      * be treated specially here.
   17504             :                      */
   17505             :                     RoleSpec   *n;
   17506             : 
   17507       29346 :                     if (strcmp($1, "public") == 0)
   17508             :                     {
   17509       15710 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17510       15710 :                         n->roletype = ROLESPEC_PUBLIC;
   17511             :                     }
   17512       13636 :                     else if (strcmp($1, "none") == 0)
   17513             :                     {
   17514          26 :                         ereport(ERROR,
   17515             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17516             :                                  errmsg("role name \"%s\" is reserved",
   17517             :                                         "none"),
   17518             :                                  parser_errposition(@1)));
   17519             :                     }
   17520             :                     else
   17521             :                     {
   17522       13610 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17523       13610 :                         n->rolename = pstrdup($1);
   17524             :                     }
   17525       29320 :                     $$ = n;
   17526             :                 }
   17527             :             | CURRENT_ROLE
   17528             :                 {
   17529         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17530             :                 }
   17531             :             | CURRENT_USER
   17532             :                 {
   17533         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17534             :                 }
   17535             :             | SESSION_USER
   17536             :                 {
   17537          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17538             :                 }
   17539             :         ;
   17540             : 
   17541             : role_list:  RoleSpec
   17542        3210 :                 { $$ = list_make1($1); }
   17543             :             | role_list ',' RoleSpec
   17544         258 :                 { $$ = lappend($1, $3); }
   17545             :         ;
   17546             : 
   17547             : 
   17548             : /*****************************************************************************
   17549             :  *
   17550             :  * PL/pgSQL extensions
   17551             :  *
   17552             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17553             :  * historically it can include just about anything that can follow SELECT.
   17554             :  * Therefore the returned struct is a SelectStmt.
   17555             :  *****************************************************************************/
   17556             : 
   17557             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17558             :             from_clause where_clause
   17559             :             group_clause having_clause window_clause
   17560             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17561             :                 {
   17562       40162 :                     SelectStmt *n = makeNode(SelectStmt);
   17563             : 
   17564       40162 :                     n->distinctClause = $1;
   17565       40162 :                     n->targetList = $2;
   17566       40162 :                     n->fromClause = $3;
   17567       40162 :                     n->whereClause = $4;
   17568       40162 :                     n->groupClause = ($5)->list;
   17569       40162 :                     n->groupDistinct = ($5)->distinct;
   17570       40162 :                     n->havingClause = $6;
   17571       40162 :                     n->windowClause = $7;
   17572       40162 :                     n->sortClause = $8;
   17573       40162 :                     if ($9)
   17574             :                     {
   17575           4 :                         n->limitOffset = $9->limitOffset;
   17576           4 :                         n->limitCount = $9->limitCount;
   17577           4 :                         if (!n->sortClause &&
   17578           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17579           0 :                             ereport(ERROR,
   17580             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17581             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17582             :                                      parser_errposition($9->optionLoc)));
   17583           4 :                         n->limitOption = $9->limitOption;
   17584             :                     }
   17585       40162 :                     n->lockingClause = $10;
   17586       40162 :                     $$ = (Node *) n;
   17587             :                 }
   17588             :         ;
   17589             : 
   17590             : /*
   17591             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17592             :  */
   17593             : 
   17594             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17595             :                 {
   17596        6972 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17597             : 
   17598        6972 :                     n->name = $1;
   17599        6972 :                     n->indirection = check_indirection($2, yyscanner);
   17600             :                     /* nnames will be filled by calling production */
   17601        6972 :                     n->val = (SelectStmt *) $4;
   17602        6972 :                     n->location = @1;
   17603        6972 :                     $$ = (Node *) n;
   17604             :                 }
   17605             :         ;
   17606             : 
   17607        6948 : plassign_target: ColId                          { $$ = $1; }
   17608          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17609             :         ;
   17610             : 
   17611             : plassign_equals: COLON_EQUALS
   17612             :             | '='
   17613             :         ;
   17614             : 
   17615             : 
   17616             : /*
   17617             :  * Name classification hierarchy.
   17618             :  *
   17619             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17620             :  * no known keyword.  In most cases, we can accept certain keywords as
   17621             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17622             :  * as possible to minimize the impact of "reserved words" on programmers.
   17623             :  * So, we divide names into several possible classes.  The classification
   17624             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17625             :  */
   17626             : 
   17627             : /* Column identifier --- names that can be column, table, etc names.
   17628             :  */
   17629     3106204 : ColId:      IDENT                                   { $$ = $1; }
   17630       53758 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17631        5408 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17632             :         ;
   17633             : 
   17634             : /* Type/function identifier --- names that can be type or function names.
   17635             :  */
   17636      671596 : type_function_name: IDENT                           { $$ = $1; }
   17637       70574 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17638          60 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17639             :         ;
   17640             : 
   17641             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17642             :  */
   17643       73800 : NonReservedWord:    IDENT                           { $$ = $1; }
   17644       28300 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17645         178 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17646        3762 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17647             :         ;
   17648             : 
   17649             : /* Column label --- allowed labels in "AS" clauses.
   17650             :  * This presently includes *all* Postgres keywords.
   17651             :  */
   17652     1625766 : ColLabel:   IDENT                                   { $$ = $1; }
   17653       36856 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17654         284 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17655        1774 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17656        7424 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17657             :         ;
   17658             : 
   17659             : /* Bare column label --- names that can be column labels without writing "AS".
   17660             :  * This classification is orthogonal to the other keyword categories.
   17661             :  */
   17662        3362 : BareColLabel:   IDENT                               { $$ = $1; }
   17663           6 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17664             :         ;
   17665             : 
   17666             : 
   17667             : /*
   17668             :  * Keyword category lists.  Generally, every keyword present in
   17669             :  * the Postgres grammar should appear in exactly one of these lists.
   17670             :  *
   17671             :  * Put a new keyword into the first list that it can go into without causing
   17672             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17673             :  * categories of keywords.
   17674             :  *
   17675             :  * Make sure that each keyword's category in kwlist.h matches where
   17676             :  * it is listed here.  (Someday we may be able to generate these lists and
   17677             :  * kwlist.h's table from one source of truth.)
   17678             :  */
   17679             : 
   17680             : /* "Unreserved" keywords --- available for use as any kind of name.
   17681             :  */
   17682             : unreserved_keyword:
   17683             :               ABORT_P
   17684             :             | ABSENT
   17685             :             | ABSOLUTE_P
   17686             :             | ACCESS
   17687             :             | ACTION
   17688             :             | ADD_P
   17689             :             | ADMIN
   17690             :             | AFTER
   17691             :             | AGGREGATE
   17692             :             | ALSO
   17693             :             | ALTER
   17694             :             | ALWAYS
   17695             :             | ASENSITIVE
   17696             :             | ASSERTION
   17697             :             | ASSIGNMENT
   17698             :             | AT
   17699             :             | ATOMIC
   17700             :             | ATTACH
   17701             :             | ATTRIBUTE
   17702             :             | BACKWARD
   17703             :             | BEFORE
   17704             :             | BEGIN_P
   17705             :             | BREADTH
   17706             :             | BY
   17707             :             | CACHE
   17708             :             | CALL
   17709             :             | CALLED
   17710             :             | CASCADE
   17711             :             | CASCADED
   17712             :             | CATALOG_P
   17713             :             | CHAIN
   17714             :             | CHARACTERISTICS
   17715             :             | CHECKPOINT
   17716             :             | CLASS
   17717             :             | CLOSE
   17718             :             | CLUSTER
   17719             :             | COLUMNS
   17720             :             | COMMENT
   17721             :             | COMMENTS
   17722             :             | COMMIT
   17723             :             | COMMITTED
   17724             :             | COMPRESSION
   17725             :             | CONDITIONAL
   17726             :             | CONFIGURATION
   17727             :             | CONFLICT
   17728             :             | CONNECTION
   17729             :             | CONSTRAINTS
   17730             :             | CONTENT_P
   17731             :             | CONTINUE_P
   17732             :             | CONVERSION_P
   17733             :             | COPY
   17734             :             | COST
   17735             :             | CSV
   17736             :             | CUBE
   17737             :             | CURRENT_P
   17738             :             | CURSOR
   17739             :             | CYCLE
   17740             :             | DATA_P
   17741             :             | DATABASE
   17742             :             | DAY_P
   17743             :             | DEALLOCATE
   17744             :             | DECLARE
   17745             :             | DEFAULTS
   17746             :             | DEFERRED
   17747             :             | DEFINER
   17748             :             | DELETE_P
   17749             :             | DELIMITER
   17750             :             | DELIMITERS
   17751             :             | DEPENDS
   17752             :             | DEPTH
   17753             :             | DETACH
   17754             :             | DICTIONARY
   17755             :             | DISABLE_P
   17756             :             | DISCARD
   17757             :             | DOCUMENT_P
   17758             :             | DOMAIN_P
   17759             :             | DOUBLE_P
   17760             :             | DROP
   17761             :             | EACH
   17762             :             | EMPTY_P
   17763             :             | ENABLE_P
   17764             :             | ENCODING
   17765             :             | ENCRYPTED
   17766             :             | ENFORCED
   17767             :             | ENUM_P
   17768             :             | ERROR_P
   17769             :             | ESCAPE
   17770             :             | EVENT
   17771             :             | EXCLUDE
   17772             :             | EXCLUDING
   17773             :             | EXCLUSIVE
   17774             :             | EXECUTE
   17775             :             | EXPLAIN
   17776             :             | EXPRESSION
   17777             :             | EXTENSION
   17778             :             | EXTERNAL
   17779             :             | FAMILY
   17780             :             | FILTER
   17781             :             | FINALIZE
   17782             :             | FIRST_P
   17783             :             | FOLLOWING
   17784             :             | FORCE
   17785             :             | FORMAT
   17786             :             | FORWARD
   17787             :             | FUNCTION
   17788             :             | FUNCTIONS
   17789             :             | GENERATED
   17790             :             | GLOBAL
   17791             :             | GRANTED
   17792             :             | GROUPS
   17793             :             | HANDLER
   17794             :             | HEADER_P
   17795             :             | HOLD
   17796             :             | HOUR_P
   17797             :             | IDENTITY_P
   17798             :             | IF_P
   17799             :             | IMMEDIATE
   17800             :             | IMMUTABLE
   17801             :             | IMPLICIT_P
   17802             :             | IMPORT_P
   17803             :             | INCLUDE
   17804             :             | INCLUDING
   17805             :             | INCREMENT
   17806             :             | INDENT
   17807             :             | INDEX
   17808             :             | INDEXES
   17809             :             | INHERIT
   17810             :             | INHERITS
   17811             :             | INLINE_P
   17812             :             | INPUT_P
   17813             :             | INSENSITIVE
   17814             :             | INSERT
   17815             :             | INSTEAD
   17816             :             | INVOKER
   17817             :             | ISOLATION
   17818             :             | KEEP
   17819             :             | KEY
   17820             :             | KEYS
   17821             :             | LABEL
   17822             :             | LANGUAGE
   17823             :             | LARGE_P
   17824             :             | LAST_P
   17825             :             | LEAKPROOF
   17826             :             | LEVEL
   17827             :             | LISTEN
   17828             :             | LOAD
   17829             :             | LOCAL
   17830             :             | LOCATION
   17831             :             | LOCK_P
   17832             :             | LOCKED
   17833             :             | LOGGED
   17834             :             | MAPPING
   17835             :             | MATCH
   17836             :             | MATCHED
   17837             :             | MATERIALIZED
   17838             :             | MAXVALUE
   17839             :             | MERGE
   17840             :             | METHOD
   17841             :             | MINUTE_P
   17842             :             | MINVALUE
   17843             :             | MODE
   17844             :             | MONTH_P
   17845             :             | MOVE
   17846             :             | NAME_P
   17847             :             | NAMES
   17848             :             | NESTED
   17849             :             | NEW
   17850             :             | NEXT
   17851             :             | NFC
   17852             :             | NFD
   17853             :             | NFKC
   17854             :             | NFKD
   17855             :             | NO
   17856             :             | NORMALIZED
   17857             :             | NOTHING
   17858             :             | NOTIFY
   17859             :             | NOWAIT
   17860             :             | NULLS_P
   17861             :             | OBJECT_P
   17862             :             | OF
   17863             :             | OFF
   17864             :             | OIDS
   17865             :             | OLD
   17866             :             | OMIT
   17867             :             | OPERATOR
   17868             :             | OPTION
   17869             :             | OPTIONS
   17870             :             | ORDINALITY
   17871             :             | OTHERS
   17872             :             | OVER
   17873             :             | OVERRIDING
   17874             :             | OWNED
   17875             :             | OWNER
   17876             :             | PARALLEL
   17877             :             | PARAMETER
   17878             :             | PARSER
   17879             :             | PARTIAL
   17880             :             | PARTITION
   17881             :             | PASSING
   17882             :             | PASSWORD
   17883             :             | PATH
   17884             :             | PERIOD
   17885             :             | PLAN
   17886             :             | PLANS
   17887             :             | POLICY
   17888             :             | PRECEDING
   17889             :             | PREPARE
   17890             :             | PREPARED
   17891             :             | PRESERVE
   17892             :             | PRIOR
   17893             :             | PRIVILEGES
   17894             :             | PROCEDURAL
   17895             :             | PROCEDURE
   17896             :             | PROCEDURES
   17897             :             | PROGRAM
   17898             :             | PUBLICATION
   17899             :             | QUOTE
   17900             :             | QUOTES
   17901             :             | RANGE
   17902             :             | READ
   17903             :             | REASSIGN
   17904             :             | RECURSIVE
   17905             :             | REF_P
   17906             :             | REFERENCING
   17907             :             | REFRESH
   17908             :             | REINDEX
   17909             :             | RELATIVE_P
   17910             :             | RELEASE
   17911             :             | RENAME
   17912             :             | REPEATABLE
   17913             :             | REPLACE
   17914             :             | REPLICA
   17915             :             | RESET
   17916             :             | RESTART
   17917             :             | RESTRICT
   17918             :             | RETURN
   17919             :             | RETURNS
   17920             :             | REVOKE
   17921             :             | ROLE
   17922             :             | ROLLBACK
   17923             :             | ROLLUP
   17924             :             | ROUTINE
   17925             :             | ROUTINES
   17926             :             | ROWS
   17927             :             | RULE
   17928             :             | SAVEPOINT
   17929             :             | SCALAR
   17930             :             | SCHEMA
   17931             :             | SCHEMAS
   17932             :             | SCROLL
   17933             :             | SEARCH
   17934             :             | SECOND_P
   17935             :             | SECURITY
   17936             :             | SEQUENCE
   17937             :             | SEQUENCES
   17938             :             | SERIALIZABLE
   17939             :             | SERVER
   17940             :             | SESSION
   17941             :             | SET
   17942             :             | SETS
   17943             :             | SHARE
   17944             :             | SHOW
   17945             :             | SIMPLE
   17946             :             | SKIP
   17947             :             | SNAPSHOT
   17948             :             | SOURCE
   17949             :             | SQL_P
   17950             :             | STABLE
   17951             :             | STANDALONE_P
   17952             :             | START
   17953             :             | STATEMENT
   17954             :             | STATISTICS
   17955             :             | STDIN
   17956             :             | STDOUT
   17957             :             | STORAGE
   17958             :             | STORED
   17959             :             | STRICT_P
   17960             :             | STRING_P
   17961             :             | STRIP_P
   17962             :             | SUBSCRIPTION
   17963             :             | SUPPORT
   17964             :             | SYSID
   17965             :             | SYSTEM_P
   17966             :             | TABLES
   17967             :             | TABLESPACE
   17968             :             | TARGET
   17969             :             | TEMP
   17970             :             | TEMPLATE
   17971             :             | TEMPORARY
   17972             :             | TEXT_P
   17973             :             | TIES
   17974             :             | TRANSACTION
   17975             :             | TRANSFORM
   17976             :             | TRIGGER
   17977             :             | TRUNCATE
   17978             :             | TRUSTED
   17979             :             | TYPE_P
   17980             :             | TYPES_P
   17981             :             | UESCAPE
   17982             :             | UNBOUNDED
   17983             :             | UNCOMMITTED
   17984             :             | UNCONDITIONAL
   17985             :             | UNENCRYPTED
   17986             :             | UNKNOWN
   17987             :             | UNLISTEN
   17988             :             | UNLOGGED
   17989             :             | UNTIL
   17990             :             | UPDATE
   17991             :             | VACUUM
   17992             :             | VALID
   17993             :             | VALIDATE
   17994             :             | VALIDATOR
   17995             :             | VALUE_P
   17996             :             | VARYING
   17997             :             | VERSION_P
   17998             :             | VIEW
   17999             :             | VIEWS
   18000             :             | VIRTUAL
   18001             :             | VOLATILE
   18002             :             | WHITESPACE_P
   18003             :             | WITHIN
   18004             :             | WITHOUT
   18005             :             | WORK
   18006             :             | WRAPPER
   18007             :             | WRITE
   18008             :             | XML_P
   18009             :             | YEAR_P
   18010             :             | YES_P
   18011             :             | ZONE
   18012             :         ;
   18013             : 
   18014             : /* Column identifier --- keywords that can be column, table, etc names.
   18015             :  *
   18016             :  * Many of these keywords will in fact be recognized as type or function
   18017             :  * names too; but they have special productions for the purpose, and so
   18018             :  * can't be treated as "generic" type or function names.
   18019             :  *
   18020             :  * The type names appearing here are not usable as function names
   18021             :  * because they can be followed by '(' in typename productions, which
   18022             :  * looks too much like a function call for an LR(1) parser.
   18023             :  */
   18024             : col_name_keyword:
   18025             :               BETWEEN
   18026             :             | BIGINT
   18027             :             | BIT
   18028             :             | BOOLEAN_P
   18029             :             | CHAR_P
   18030             :             | CHARACTER
   18031             :             | COALESCE
   18032             :             | DEC
   18033             :             | DECIMAL_P
   18034             :             | EXISTS
   18035             :             | EXTRACT
   18036             :             | FLOAT_P
   18037             :             | GREATEST
   18038             :             | GROUPING
   18039             :             | INOUT
   18040             :             | INT_P
   18041             :             | INTEGER
   18042             :             | INTERVAL
   18043             :             | JSON
   18044             :             | JSON_ARRAY
   18045             :             | JSON_ARRAYAGG
   18046             :             | JSON_EXISTS
   18047             :             | JSON_OBJECT
   18048             :             | JSON_OBJECTAGG
   18049             :             | JSON_QUERY
   18050             :             | JSON_SCALAR
   18051             :             | JSON_SERIALIZE
   18052             :             | JSON_TABLE
   18053             :             | JSON_VALUE
   18054             :             | LEAST
   18055             :             | MERGE_ACTION
   18056             :             | NATIONAL
   18057             :             | NCHAR
   18058             :             | NONE
   18059             :             | NORMALIZE
   18060             :             | NULLIF
   18061             :             | NUMERIC
   18062             :             | OUT_P
   18063             :             | OVERLAY
   18064             :             | POSITION
   18065             :             | PRECISION
   18066             :             | REAL
   18067             :             | ROW
   18068             :             | SETOF
   18069             :             | SMALLINT
   18070             :             | SUBSTRING
   18071             :             | TIME
   18072             :             | TIMESTAMP
   18073             :             | TREAT
   18074             :             | TRIM
   18075             :             | VALUES
   18076             :             | VARCHAR
   18077             :             | XMLATTRIBUTES
   18078             :             | XMLCONCAT
   18079             :             | XMLELEMENT
   18080             :             | XMLEXISTS
   18081             :             | XMLFOREST
   18082             :             | XMLNAMESPACES
   18083             :             | XMLPARSE
   18084             :             | XMLPI
   18085             :             | XMLROOT
   18086             :             | XMLSERIALIZE
   18087             :             | XMLTABLE
   18088             :         ;
   18089             : 
   18090             : /* Type/function identifier --- keywords that can be type or function names.
   18091             :  *
   18092             :  * Most of these are keywords that are used as operators in expressions;
   18093             :  * in general such keywords can't be column names because they would be
   18094             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18095             :  *
   18096             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18097             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18098             :  * - thomas 2000-11-28
   18099             :  */
   18100             : type_func_name_keyword:
   18101             :               AUTHORIZATION
   18102             :             | BINARY
   18103             :             | COLLATION
   18104             :             | CONCURRENTLY
   18105             :             | CROSS
   18106             :             | CURRENT_SCHEMA
   18107             :             | FREEZE
   18108             :             | FULL
   18109             :             | ILIKE
   18110             :             | INNER_P
   18111             :             | IS
   18112             :             | ISNULL
   18113             :             | JOIN
   18114             :             | LEFT
   18115             :             | LIKE
   18116             :             | NATURAL
   18117             :             | NOTNULL
   18118             :             | OUTER_P
   18119             :             | OVERLAPS
   18120             :             | RIGHT
   18121             :             | SIMILAR
   18122             :             | TABLESAMPLE
   18123             :             | VERBOSE
   18124             :         ;
   18125             : 
   18126             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18127             :  *
   18128             :  * Keywords appear here if they could not be distinguished from variable,
   18129             :  * type, or function names in some contexts.  Don't put things here unless
   18130             :  * forced to.
   18131             :  */
   18132             : reserved_keyword:
   18133             :               ALL
   18134             :             | ANALYSE
   18135             :             | ANALYZE
   18136             :             | AND
   18137             :             | ANY
   18138             :             | ARRAY
   18139             :             | AS
   18140             :             | ASC
   18141             :             | ASYMMETRIC
   18142             :             | BOTH
   18143             :             | CASE
   18144             :             | CAST
   18145             :             | CHECK
   18146             :             | COLLATE
   18147             :             | COLUMN
   18148             :             | CONSTRAINT
   18149             :             | CREATE
   18150             :             | CURRENT_CATALOG
   18151             :             | CURRENT_DATE
   18152             :             | CURRENT_ROLE
   18153             :             | CURRENT_TIME
   18154             :             | CURRENT_TIMESTAMP
   18155             :             | CURRENT_USER
   18156             :             | DEFAULT
   18157             :             | DEFERRABLE
   18158             :             | DESC
   18159             :             | DISTINCT
   18160             :             | DO
   18161             :             | ELSE
   18162             :             | END_P
   18163             :             | EXCEPT
   18164             :             | FALSE_P
   18165             :             | FETCH
   18166             :             | FOR
   18167             :             | FOREIGN
   18168             :             | FROM
   18169             :             | GRANT
   18170             :             | GROUP_P
   18171             :             | HAVING
   18172             :             | IN_P
   18173             :             | INITIALLY
   18174             :             | INTERSECT
   18175             :             | INTO
   18176             :             | LATERAL_P
   18177             :             | LEADING
   18178             :             | LIMIT
   18179             :             | LOCALTIME
   18180             :             | LOCALTIMESTAMP
   18181             :             | NOT
   18182             :             | NULL_P
   18183             :             | OFFSET
   18184             :             | ON
   18185             :             | ONLY
   18186             :             | OR
   18187             :             | ORDER
   18188             :             | PLACING
   18189             :             | PRIMARY
   18190             :             | REFERENCES
   18191             :             | RETURNING
   18192             :             | SELECT
   18193             :             | SESSION_USER
   18194             :             | SOME
   18195             :             | SYMMETRIC
   18196             :             | SYSTEM_USER
   18197             :             | TABLE
   18198             :             | THEN
   18199             :             | TO
   18200             :             | TRAILING
   18201             :             | TRUE_P
   18202             :             | UNION
   18203             :             | UNIQUE
   18204             :             | USER
   18205             :             | USING
   18206             :             | VARIADIC
   18207             :             | WHEN
   18208             :             | WHERE
   18209             :             | WINDOW
   18210             :             | WITH
   18211             :         ;
   18212             : 
   18213             : /*
   18214             :  * While all keywords can be used as column labels when preceded by AS,
   18215             :  * not all of them can be used as a "bare" column label without AS.
   18216             :  * Those that can be used as a bare label must be listed here,
   18217             :  * in addition to appearing in one of the category lists above.
   18218             :  *
   18219             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18220             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18221             :  */
   18222             : bare_label_keyword:
   18223             :               ABORT_P
   18224             :             | ABSENT
   18225             :             | ABSOLUTE_P
   18226             :             | ACCESS
   18227             :             | ACTION
   18228             :             | ADD_P
   18229             :             | ADMIN
   18230             :             | AFTER
   18231             :             | AGGREGATE
   18232             :             | ALL
   18233             :             | ALSO
   18234             :             | ALTER
   18235             :             | ALWAYS
   18236             :             | ANALYSE
   18237             :             | ANALYZE
   18238             :             | AND
   18239             :             | ANY
   18240             :             | ASC
   18241             :             | ASENSITIVE
   18242             :             | ASSERTION
   18243             :             | ASSIGNMENT
   18244             :             | ASYMMETRIC
   18245             :             | AT
   18246             :             | ATOMIC
   18247             :             | ATTACH
   18248             :             | ATTRIBUTE
   18249             :             | AUTHORIZATION
   18250             :             | BACKWARD
   18251             :             | BEFORE
   18252             :             | BEGIN_P
   18253             :             | BETWEEN
   18254             :             | BIGINT
   18255             :             | BINARY
   18256             :             | BIT
   18257             :             | BOOLEAN_P
   18258             :             | BOTH
   18259             :             | BREADTH
   18260             :             | BY
   18261             :             | CACHE
   18262             :             | CALL
   18263             :             | CALLED
   18264             :             | CASCADE
   18265             :             | CASCADED
   18266             :             | CASE
   18267             :             | CAST
   18268             :             | CATALOG_P
   18269             :             | CHAIN
   18270             :             | CHARACTERISTICS
   18271             :             | CHECK
   18272             :             | CHECKPOINT
   18273             :             | CLASS
   18274             :             | CLOSE
   18275             :             | CLUSTER
   18276             :             | COALESCE
   18277             :             | COLLATE
   18278             :             | COLLATION
   18279             :             | COLUMN
   18280             :             | COLUMNS
   18281             :             | COMMENT
   18282             :             | COMMENTS
   18283             :             | COMMIT
   18284             :             | COMMITTED
   18285             :             | COMPRESSION
   18286             :             | CONCURRENTLY
   18287             :             | CONDITIONAL
   18288             :             | CONFIGURATION
   18289             :             | CONFLICT
   18290             :             | CONNECTION
   18291             :             | CONSTRAINT
   18292             :             | CONSTRAINTS
   18293             :             | CONTENT_P
   18294             :             | CONTINUE_P
   18295             :             | CONVERSION_P
   18296             :             | COPY
   18297             :             | COST
   18298             :             | CROSS
   18299             :             | CSV
   18300             :             | CUBE
   18301             :             | CURRENT_P
   18302             :             | CURRENT_CATALOG
   18303             :             | CURRENT_DATE
   18304             :             | CURRENT_ROLE
   18305             :             | CURRENT_SCHEMA
   18306             :             | CURRENT_TIME
   18307             :             | CURRENT_TIMESTAMP
   18308             :             | CURRENT_USER
   18309             :             | CURSOR
   18310             :             | CYCLE
   18311             :             | DATA_P
   18312             :             | DATABASE
   18313             :             | DEALLOCATE
   18314             :             | DEC
   18315             :             | DECIMAL_P
   18316             :             | DECLARE
   18317             :             | DEFAULT
   18318             :             | DEFAULTS
   18319             :             | DEFERRABLE
   18320             :             | DEFERRED
   18321             :             | DEFINER
   18322             :             | DELETE_P
   18323             :             | DELIMITER
   18324             :             | DELIMITERS
   18325             :             | DEPENDS
   18326             :             | DEPTH
   18327             :             | DESC
   18328             :             | DETACH
   18329             :             | DICTIONARY
   18330             :             | DISABLE_P
   18331             :             | DISCARD
   18332             :             | DISTINCT
   18333             :             | DO
   18334             :             | DOCUMENT_P
   18335             :             | DOMAIN_P
   18336             :             | DOUBLE_P
   18337             :             | DROP
   18338             :             | EACH
   18339             :             | ELSE
   18340             :             | EMPTY_P
   18341             :             | ENABLE_P
   18342             :             | ENCODING
   18343             :             | ENCRYPTED
   18344             :             | END_P
   18345             :             | ENFORCED
   18346             :             | ENUM_P
   18347             :             | ERROR_P
   18348             :             | ESCAPE
   18349             :             | EVENT
   18350             :             | EXCLUDE
   18351             :             | EXCLUDING
   18352             :             | EXCLUSIVE
   18353             :             | EXECUTE
   18354             :             | EXISTS
   18355             :             | EXPLAIN
   18356             :             | EXPRESSION
   18357             :             | EXTENSION
   18358             :             | EXTERNAL
   18359             :             | EXTRACT
   18360             :             | FALSE_P
   18361             :             | FAMILY
   18362             :             | FINALIZE
   18363             :             | FIRST_P
   18364             :             | FLOAT_P
   18365             :             | FOLLOWING
   18366             :             | FORCE
   18367             :             | FOREIGN
   18368             :             | FORMAT
   18369             :             | FORWARD
   18370             :             | FREEZE
   18371             :             | FULL
   18372             :             | FUNCTION
   18373             :             | FUNCTIONS
   18374             :             | GENERATED
   18375             :             | GLOBAL
   18376             :             | GRANTED
   18377             :             | GREATEST
   18378             :             | GROUPING
   18379             :             | GROUPS
   18380             :             | HANDLER
   18381             :             | HEADER_P
   18382             :             | HOLD
   18383             :             | IDENTITY_P
   18384             :             | IF_P
   18385             :             | ILIKE
   18386             :             | IMMEDIATE
   18387             :             | IMMUTABLE
   18388             :             | IMPLICIT_P
   18389             :             | IMPORT_P
   18390             :             | IN_P
   18391             :             | INCLUDE
   18392             :             | INCLUDING
   18393             :             | INCREMENT
   18394             :             | INDENT
   18395             :             | INDEX
   18396             :             | INDEXES
   18397             :             | INHERIT
   18398             :             | INHERITS
   18399             :             | INITIALLY
   18400             :             | INLINE_P
   18401             :             | INNER_P
   18402             :             | INOUT
   18403             :             | INPUT_P
   18404             :             | INSENSITIVE
   18405             :             | INSERT
   18406             :             | INSTEAD
   18407             :             | INT_P
   18408             :             | INTEGER
   18409             :             | INTERVAL
   18410             :             | INVOKER
   18411             :             | IS
   18412             :             | ISOLATION
   18413             :             | JOIN
   18414             :             | JSON
   18415             :             | JSON_ARRAY
   18416             :             | JSON_ARRAYAGG
   18417             :             | JSON_EXISTS
   18418             :             | JSON_OBJECT
   18419             :             | JSON_OBJECTAGG
   18420             :             | JSON_QUERY
   18421             :             | JSON_SCALAR
   18422             :             | JSON_SERIALIZE
   18423             :             | JSON_TABLE
   18424             :             | JSON_VALUE
   18425             :             | KEEP
   18426             :             | KEY
   18427             :             | KEYS
   18428             :             | LABEL
   18429             :             | LANGUAGE
   18430             :             | LARGE_P
   18431             :             | LAST_P
   18432             :             | LATERAL_P
   18433             :             | LEADING
   18434             :             | LEAKPROOF
   18435             :             | LEAST
   18436             :             | LEFT
   18437             :             | LEVEL
   18438             :             | LIKE
   18439             :             | LISTEN
   18440             :             | LOAD
   18441             :             | LOCAL
   18442             :             | LOCALTIME
   18443             :             | LOCALTIMESTAMP
   18444             :             | LOCATION
   18445             :             | LOCK_P
   18446             :             | LOCKED
   18447             :             | LOGGED
   18448             :             | MAPPING
   18449             :             | MATCH
   18450             :             | MATCHED
   18451             :             | MATERIALIZED
   18452             :             | MAXVALUE
   18453             :             | MERGE
   18454             :             | MERGE_ACTION
   18455             :             | METHOD
   18456             :             | MINVALUE
   18457             :             | MODE
   18458             :             | MOVE
   18459             :             | NAME_P
   18460             :             | NAMES
   18461             :             | NATIONAL
   18462             :             | NATURAL
   18463             :             | NCHAR
   18464             :             | NESTED
   18465             :             | NEW
   18466             :             | NEXT
   18467             :             | NFC
   18468             :             | NFD
   18469             :             | NFKC
   18470             :             | NFKD
   18471             :             | NO
   18472             :             | NONE
   18473             :             | NORMALIZE
   18474             :             | NORMALIZED
   18475             :             | NOT
   18476             :             | NOTHING
   18477             :             | NOTIFY
   18478             :             | NOWAIT
   18479             :             | NULL_P
   18480             :             | NULLIF
   18481             :             | NULLS_P
   18482             :             | NUMERIC
   18483             :             | OBJECT_P
   18484             :             | OF
   18485             :             | OFF
   18486             :             | OIDS
   18487             :             | OLD
   18488             :             | OMIT
   18489             :             | ONLY
   18490             :             | OPERATOR
   18491             :             | OPTION
   18492             :             | OPTIONS
   18493             :             | OR
   18494             :             | ORDINALITY
   18495             :             | OTHERS
   18496             :             | OUT_P
   18497             :             | OUTER_P
   18498             :             | OVERLAY
   18499             :             | OVERRIDING
   18500             :             | OWNED
   18501             :             | OWNER
   18502             :             | PARALLEL
   18503             :             | PARAMETER
   18504             :             | PARSER
   18505             :             | PARTIAL
   18506             :             | PARTITION
   18507             :             | PASSING
   18508             :             | PASSWORD
   18509             :             | PATH
   18510             :             | PERIOD
   18511             :             | PLACING
   18512             :             | PLAN
   18513             :             | PLANS
   18514             :             | POLICY
   18515             :             | POSITION
   18516             :             | PRECEDING
   18517             :             | PREPARE
   18518             :             | PREPARED
   18519             :             | PRESERVE
   18520             :             | PRIMARY
   18521             :             | PRIOR
   18522             :             | PRIVILEGES
   18523             :             | PROCEDURAL
   18524             :             | PROCEDURE
   18525             :             | PROCEDURES
   18526             :             | PROGRAM
   18527             :             | PUBLICATION
   18528             :             | QUOTE
   18529             :             | QUOTES
   18530             :             | RANGE
   18531             :             | READ
   18532             :             | REAL
   18533             :             | REASSIGN
   18534             :             | RECURSIVE
   18535             :             | REF_P
   18536             :             | REFERENCES
   18537             :             | REFERENCING
   18538             :             | REFRESH
   18539             :             | REINDEX
   18540             :             | RELATIVE_P
   18541             :             | RELEASE
   18542             :             | RENAME
   18543             :             | REPEATABLE
   18544             :             | REPLACE
   18545             :             | REPLICA
   18546             :             | RESET
   18547             :             | RESTART
   18548             :             | RESTRICT
   18549             :             | RETURN
   18550             :             | RETURNS
   18551             :             | REVOKE
   18552             :             | RIGHT
   18553             :             | ROLE
   18554             :             | ROLLBACK
   18555             :             | ROLLUP
   18556             :             | ROUTINE
   18557             :             | ROUTINES
   18558             :             | ROW
   18559             :             | ROWS
   18560             :             | RULE
   18561             :             | SAVEPOINT
   18562             :             | SCALAR
   18563             :             | SCHEMA
   18564             :             | SCHEMAS
   18565             :             | SCROLL
   18566             :             | SEARCH
   18567             :             | SECURITY
   18568             :             | SELECT
   18569             :             | SEQUENCE
   18570             :             | SEQUENCES
   18571             :             | SERIALIZABLE
   18572             :             | SERVER
   18573             :             | SESSION
   18574             :             | SESSION_USER
   18575             :             | SET
   18576             :             | SETOF
   18577             :             | SETS
   18578             :             | SHARE
   18579             :             | SHOW
   18580             :             | SIMILAR
   18581             :             | SIMPLE
   18582             :             | SKIP
   18583             :             | SMALLINT
   18584             :             | SNAPSHOT
   18585             :             | SOME
   18586             :             | SOURCE
   18587             :             | SQL_P
   18588             :             | STABLE
   18589             :             | STANDALONE_P
   18590             :             | START
   18591             :             | STATEMENT
   18592             :             | STATISTICS
   18593             :             | STDIN
   18594             :             | STDOUT
   18595             :             | STORAGE
   18596             :             | STORED
   18597             :             | STRICT_P
   18598             :             | STRING_P
   18599             :             | STRIP_P
   18600             :             | SUBSCRIPTION
   18601             :             | SUBSTRING
   18602             :             | SUPPORT
   18603             :             | SYMMETRIC
   18604             :             | SYSID
   18605             :             | SYSTEM_P
   18606             :             | SYSTEM_USER
   18607             :             | TABLE
   18608             :             | TABLES
   18609             :             | TABLESAMPLE
   18610             :             | TABLESPACE
   18611             :             | TARGET
   18612             :             | TEMP
   18613             :             | TEMPLATE
   18614             :             | TEMPORARY
   18615             :             | TEXT_P
   18616             :             | THEN
   18617             :             | TIES
   18618             :             | TIME
   18619             :             | TIMESTAMP
   18620             :             | TRAILING
   18621             :             | TRANSACTION
   18622             :             | TRANSFORM
   18623             :             | TREAT
   18624             :             | TRIGGER
   18625             :             | TRIM
   18626             :             | TRUE_P
   18627             :             | TRUNCATE
   18628             :             | TRUSTED
   18629             :             | TYPE_P
   18630             :             | TYPES_P
   18631             :             | UESCAPE
   18632             :             | UNBOUNDED
   18633             :             | UNCOMMITTED
   18634             :             | UNCONDITIONAL
   18635             :             | UNENCRYPTED
   18636             :             | UNIQUE
   18637             :             | UNKNOWN
   18638             :             | UNLISTEN
   18639             :             | UNLOGGED
   18640             :             | UNTIL
   18641             :             | UPDATE
   18642             :             | USER
   18643             :             | USING
   18644             :             | VACUUM
   18645             :             | VALID
   18646             :             | VALIDATE
   18647             :             | VALIDATOR
   18648             :             | VALUE_P
   18649             :             | VALUES
   18650             :             | VARCHAR
   18651             :             | VARIADIC
   18652             :             | VERBOSE
   18653             :             | VERSION_P
   18654             :             | VIEW
   18655             :             | VIEWS
   18656             :             | VIRTUAL
   18657             :             | VOLATILE
   18658             :             | WHEN
   18659             :             | WHITESPACE_P
   18660             :             | WORK
   18661             :             | WRAPPER
   18662             :             | WRITE
   18663             :             | XML_P
   18664             :             | XMLATTRIBUTES
   18665             :             | XMLCONCAT
   18666             :             | XMLELEMENT
   18667             :             | XMLEXISTS
   18668             :             | XMLFOREST
   18669             :             | XMLNAMESPACES
   18670             :             | XMLPARSE
   18671             :             | XMLPI
   18672             :             | XMLROOT
   18673             :             | XMLSERIALIZE
   18674             :             | XMLTABLE
   18675             :             | YES_P
   18676             :             | ZONE
   18677             :         ;
   18678             : 
   18679             : %%
   18680             : 
   18681             : /*
   18682             :  * The signature of this function is required by bison.  However, we
   18683             :  * ignore the passed yylloc and instead use the last token position
   18684             :  * available from the scanner.
   18685             :  */
   18686             : static void
   18687         702 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18688             : {
   18689         702 :     parser_yyerror(msg);
   18690             : }
   18691             : 
   18692             : static RawStmt *
   18693      808884 : makeRawStmt(Node *stmt, int stmt_location)
   18694             : {
   18695      808884 :     RawStmt    *rs = makeNode(RawStmt);
   18696             : 
   18697      808884 :     rs->stmt = stmt;
   18698      808884 :     rs->stmt_location = stmt_location;
   18699      808884 :     rs->stmt_len = 0;            /* might get changed later */
   18700      808884 :     return rs;
   18701             : }
   18702             : 
   18703             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18704             : static void
   18705      574706 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18706             : {
   18707             :     /*
   18708             :      * If we already set the length, don't change it.  This is for situations
   18709             :      * like "select foo ;; select bar" where the same statement will be last
   18710             :      * in the string for more than one semicolon.
   18711             :      */
   18712      574706 :     if (rs->stmt_len > 0)
   18713         302 :         return;
   18714             : 
   18715             :     /* OK, update length of RawStmt */
   18716      574404 :     rs->stmt_len = end_location - rs->stmt_location;
   18717             : }
   18718             : 
   18719             : /*
   18720             :  * Adjust a PreparableStmt to reflect that it doesn't run to the end of the
   18721             :  * string.
   18722             :  */
   18723             : static void
   18724         464 : updatePreparableStmtEnd(Node *n, int end_location)
   18725             : {
   18726         464 :     if (IsA(n, SelectStmt))
   18727             :     {
   18728         276 :         SelectStmt *stmt = (SelectStmt *) n;
   18729             : 
   18730         276 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18731             :     }
   18732         188 :     else if (IsA(n, InsertStmt))
   18733             :     {
   18734          62 :         InsertStmt *stmt = (InsertStmt *) n;
   18735             : 
   18736          62 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18737             :     }
   18738         126 :     else if (IsA(n, UpdateStmt))
   18739             :     {
   18740          56 :         UpdateStmt *stmt = (UpdateStmt *) n;
   18741             : 
   18742          56 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18743             :     }
   18744          70 :     else if (IsA(n, DeleteStmt))
   18745             :     {
   18746          54 :         DeleteStmt *stmt = (DeleteStmt *) n;
   18747             : 
   18748          54 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18749             :     }
   18750          16 :     else if (IsA(n, MergeStmt))
   18751             :     {
   18752          16 :         MergeStmt  *stmt = (MergeStmt *) n;
   18753             : 
   18754          16 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18755             :     }
   18756             :     else
   18757           0 :         elog(ERROR, "unexpected node type %d", (int) n->type);
   18758         464 : }
   18759             : 
   18760             : static Node *
   18761     1648512 : makeColumnRef(char *colname, List *indirection,
   18762             :               int location, core_yyscan_t yyscanner)
   18763             : {
   18764             :     /*
   18765             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18766             :      * any subscripting in the specified indirection list.  However, any field
   18767             :      * selection at the start of the indirection list must be transposed into
   18768             :      * the "fields" part of the ColumnRef node.
   18769             :      */
   18770     1648512 :     ColumnRef  *c = makeNode(ColumnRef);
   18771     1648512 :     int         nfields = 0;
   18772             :     ListCell   *l;
   18773             : 
   18774     1648512 :     c->location = location;
   18775     2619478 :     foreach(l, indirection)
   18776             :     {
   18777      980398 :         if (IsA(lfirst(l), A_Indices))
   18778             :         {
   18779        9432 :             A_Indirection *i = makeNode(A_Indirection);
   18780             : 
   18781        9432 :             if (nfields == 0)
   18782             :             {
   18783             :                 /* easy case - all indirection goes to A_Indirection */
   18784        6818 :                 c->fields = list_make1(makeString(colname));
   18785        6818 :                 i->indirection = check_indirection(indirection, yyscanner);
   18786             :             }
   18787             :             else
   18788             :             {
   18789             :                 /* got to split the list in two */
   18790        2614 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18791             :                                                                   nfields),
   18792             :                                                    yyscanner);
   18793        2614 :                 indirection = list_truncate(indirection, nfields);
   18794        2614 :                 c->fields = lcons(makeString(colname), indirection);
   18795             :             }
   18796        9432 :             i->arg = (Node *) c;
   18797        9432 :             return (Node *) i;
   18798             :         }
   18799      970966 :         else if (IsA(lfirst(l), A_Star))
   18800             :         {
   18801             :             /* We only allow '*' at the end of a ColumnRef */
   18802        5338 :             if (lnext(indirection, l) != NULL)
   18803           0 :                 parser_yyerror("improper use of \"*\"");
   18804             :         }
   18805      970966 :         nfields++;
   18806             :     }
   18807             :     /* No subscripting, so all indirection gets added to field list */
   18808     1639080 :     c->fields = lcons(makeString(colname), indirection);
   18809     1639080 :     return (Node *) c;
   18810             : }
   18811             : 
   18812             : static Node *
   18813      270884 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18814             : {
   18815      270884 :     TypeCast   *n = makeNode(TypeCast);
   18816             : 
   18817      270884 :     n->arg = arg;
   18818      270884 :     n->typeName = typename;
   18819      270884 :     n->location = location;
   18820      270884 :     return (Node *) n;
   18821             : }
   18822             : 
   18823             : static Node *
   18824       16186 : makeStringConstCast(char *str, int location, TypeName *typename)
   18825             : {
   18826       16186 :     Node       *s = makeStringConst(str, location);
   18827             : 
   18828       16186 :     return makeTypeCast(s, typename, -1);
   18829             : }
   18830             : 
   18831             : static Node *
   18832      442288 : makeIntConst(int val, int location)
   18833             : {
   18834      442288 :     A_Const    *n = makeNode(A_Const);
   18835             : 
   18836      442288 :     n->val.ival.type = T_Integer;
   18837      442288 :     n->val.ival.ival = val;
   18838      442288 :     n->location = location;
   18839             : 
   18840      442288 :     return (Node *) n;
   18841             : }
   18842             : 
   18843             : static Node *
   18844       12028 : makeFloatConst(char *str, int location)
   18845             : {
   18846       12028 :     A_Const    *n = makeNode(A_Const);
   18847             : 
   18848       12028 :     n->val.fval.type = T_Float;
   18849       12028 :     n->val.fval.fval = str;
   18850       12028 :     n->location = location;
   18851             : 
   18852       12028 :     return (Node *) n;
   18853             : }
   18854             : 
   18855             : static Node *
   18856       56150 : makeBoolAConst(bool state, int location)
   18857             : {
   18858       56150 :     A_Const    *n = makeNode(A_Const);
   18859             : 
   18860       56150 :     n->val.boolval.type = T_Boolean;
   18861       56150 :     n->val.boolval.boolval = state;
   18862       56150 :     n->location = location;
   18863             : 
   18864       56150 :     return (Node *) n;
   18865             : }
   18866             : 
   18867             : static Node *
   18868        4056 : makeBitStringConst(char *str, int location)
   18869             : {
   18870        4056 :     A_Const    *n = makeNode(A_Const);
   18871             : 
   18872        4056 :     n->val.bsval.type = T_BitString;
   18873        4056 :     n->val.bsval.bsval = str;
   18874        4056 :     n->location = location;
   18875             : 
   18876        4056 :     return (Node *) n;
   18877             : }
   18878             : 
   18879             : static Node *
   18880       63206 : makeNullAConst(int location)
   18881             : {
   18882       63206 :     A_Const    *n = makeNode(A_Const);
   18883             : 
   18884       63206 :     n->isnull = true;
   18885       63206 :     n->location = location;
   18886             : 
   18887       63206 :     return (Node *) n;
   18888             : }
   18889             : 
   18890             : static Node *
   18891        4470 : makeAConst(Node *v, int location)
   18892             : {
   18893             :     Node       *n;
   18894             : 
   18895        4470 :     switch (v->type)
   18896             :     {
   18897         218 :         case T_Float:
   18898         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18899         218 :             break;
   18900             : 
   18901        4252 :         case T_Integer:
   18902        4252 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18903        4252 :             break;
   18904             : 
   18905           0 :         default:
   18906             :             /* currently not used */
   18907             :             Assert(false);
   18908           0 :             n = NULL;
   18909             :     }
   18910             : 
   18911        4470 :     return n;
   18912             : }
   18913             : 
   18914             : /* makeRoleSpec
   18915             :  * Create a RoleSpec with the given type
   18916             :  */
   18917             : static RoleSpec *
   18918       30312 : makeRoleSpec(RoleSpecType type, int location)
   18919             : {
   18920       30312 :     RoleSpec   *spec = makeNode(RoleSpec);
   18921             : 
   18922       30312 :     spec->roletype = type;
   18923       30312 :     spec->location = location;
   18924             : 
   18925       30312 :     return spec;
   18926             : }
   18927             : 
   18928             : /* check_qualified_name --- check the result of qualified_name production
   18929             :  *
   18930             :  * It's easiest to let the grammar production for qualified_name allow
   18931             :  * subscripts and '*', which we then must reject here.
   18932             :  */
   18933             : static void
   18934      229550 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18935             : {
   18936             :     ListCell   *i;
   18937             : 
   18938      459100 :     foreach(i, names)
   18939             :     {
   18940      229550 :         if (!IsA(lfirst(i), String))
   18941           0 :             parser_yyerror("syntax error");
   18942             :     }
   18943      229550 : }
   18944             : 
   18945             : /* check_func_name --- check the result of func_name production
   18946             :  *
   18947             :  * It's easiest to let the grammar production for func_name allow subscripts
   18948             :  * and '*', which we then must reject here.
   18949             :  */
   18950             : static List *
   18951      117166 : check_func_name(List *names, core_yyscan_t yyscanner)
   18952             : {
   18953             :     ListCell   *i;
   18954             : 
   18955      351498 :     foreach(i, names)
   18956             :     {
   18957      234332 :         if (!IsA(lfirst(i), String))
   18958           0 :             parser_yyerror("syntax error");
   18959             :     }
   18960      117166 :     return names;
   18961             : }
   18962             : 
   18963             : /* check_indirection --- check the result of indirection production
   18964             :  *
   18965             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18966             :  * in the grammar, so do it here.
   18967             :  */
   18968             : static List *
   18969       79770 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18970             : {
   18971             :     ListCell   *l;
   18972             : 
   18973      105742 :     foreach(l, indirection)
   18974             :     {
   18975       25972 :         if (IsA(lfirst(l), A_Star))
   18976             :         {
   18977        1342 :             if (lnext(indirection, l) != NULL)
   18978           0 :                 parser_yyerror("improper use of \"*\"");
   18979             :         }
   18980             :     }
   18981       79770 :     return indirection;
   18982             : }
   18983             : 
   18984             : /* extractArgTypes()
   18985             :  * Given a list of FunctionParameter nodes, extract a list of just the
   18986             :  * argument types (TypeNames) for input parameters only.  This is what
   18987             :  * is needed to look up an existing function, which is what is wanted by
   18988             :  * the productions that use this call.
   18989             :  */
   18990             : static List *
   18991       14692 : extractArgTypes(List *parameters)
   18992             : {
   18993       14692 :     List       *result = NIL;
   18994             :     ListCell   *i;
   18995             : 
   18996       32258 :     foreach(i, parameters)
   18997             :     {
   18998       17566 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   18999             : 
   19000       17566 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19001       17410 :             result = lappend(result, p->argType);
   19002             :     }
   19003       14692 :     return result;
   19004             : }
   19005             : 
   19006             : /* extractAggrArgTypes()
   19007             :  * As above, but work from the output of the aggr_args production.
   19008             :  */
   19009             : static List *
   19010         362 : extractAggrArgTypes(List *aggrargs)
   19011             : {
   19012             :     Assert(list_length(aggrargs) == 2);
   19013         362 :     return extractArgTypes((List *) linitial(aggrargs));
   19014             : }
   19015             : 
   19016             : /* makeOrderedSetArgs()
   19017             :  * Build the result of the aggr_args production (which see the comments for).
   19018             :  * This handles only the case where both given lists are nonempty, so that
   19019             :  * we have to deal with multiple VARIADIC arguments.
   19020             :  */
   19021             : static List *
   19022          32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19023             :                    core_yyscan_t yyscanner)
   19024             : {
   19025          32 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19026             :     Integer    *ndirectargs;
   19027             : 
   19028             :     /* No restriction unless last direct arg is VARIADIC */
   19029          32 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19030             :     {
   19031          16 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19032             : 
   19033             :         /*
   19034             :          * We ignore the names, though the aggr_arg production allows them; it
   19035             :          * doesn't allow default values, so those need not be checked.
   19036             :          */
   19037          16 :         if (list_length(orderedargs) != 1 ||
   19038          16 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19039          16 :             !equal(lastd->argType, firsto->argType))
   19040           0 :             ereport(ERROR,
   19041             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19042             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19043             :                      parser_errposition(firsto->location)));
   19044             : 
   19045             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19046          16 :         orderedargs = NIL;
   19047             :     }
   19048             : 
   19049             :     /* don't merge into the next line, as list_concat changes directargs */
   19050          32 :     ndirectargs = makeInteger(list_length(directargs));
   19051             : 
   19052          32 :     return list_make2(list_concat(directargs, orderedargs),
   19053             :                       ndirectargs);
   19054             : }
   19055             : 
   19056             : /* insertSelectOptions()
   19057             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19058             :  *
   19059             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19060             :  */
   19061             : static void
   19062       74346 : insertSelectOptions(SelectStmt *stmt,
   19063             :                     List *sortClause, List *lockingClause,
   19064             :                     SelectLimit *limitClause,
   19065             :                     WithClause *withClause,
   19066             :                     core_yyscan_t yyscanner)
   19067             : {
   19068             :     Assert(IsA(stmt, SelectStmt));
   19069             : 
   19070             :     /*
   19071             :      * Tests here are to reject constructs like
   19072             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19073             :      */
   19074       74346 :     if (sortClause)
   19075             :     {
   19076       65166 :         if (stmt->sortClause)
   19077           0 :             ereport(ERROR,
   19078             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19079             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19080             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19081       65166 :         stmt->sortClause = sortClause;
   19082             :     }
   19083             :     /* We can handle multiple locking clauses, though */
   19084       74346 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19085       74346 :     if (limitClause && limitClause->limitOffset)
   19086             :     {
   19087         780 :         if (stmt->limitOffset)
   19088           0 :             ereport(ERROR,
   19089             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19090             :                      errmsg("multiple OFFSET clauses not allowed"),
   19091             :                      parser_errposition(limitClause->offsetLoc)));
   19092         780 :         stmt->limitOffset = limitClause->limitOffset;
   19093             :     }
   19094       74346 :     if (limitClause && limitClause->limitCount)
   19095             :     {
   19096        4590 :         if (stmt->limitCount)
   19097           0 :             ereport(ERROR,
   19098             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19099             :                      errmsg("multiple LIMIT clauses not allowed"),
   19100             :                      parser_errposition(limitClause->countLoc)));
   19101        4590 :         stmt->limitCount = limitClause->limitCount;
   19102             :     }
   19103       74346 :     if (limitClause)
   19104             :     {
   19105             :         /* If there was a conflict, we must have detected it above */
   19106             :         Assert(!stmt->limitOption);
   19107        4988 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19108           6 :             ereport(ERROR,
   19109             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19110             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19111             :                      parser_errposition(limitClause->optionLoc)));
   19112        4982 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19113             :         {
   19114             :             ListCell   *lc;
   19115             : 
   19116           6 :             foreach(lc, stmt->lockingClause)
   19117             :             {
   19118           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19119             : 
   19120           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19121           6 :                     ereport(ERROR,
   19122             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19123             :                              errmsg("%s and %s options cannot be used together",
   19124             :                                     "SKIP LOCKED", "WITH TIES"),
   19125             :                              parser_errposition(limitClause->optionLoc)));
   19126             :             }
   19127             :         }
   19128        4976 :         stmt->limitOption = limitClause->limitOption;
   19129             :     }
   19130       74334 :     if (withClause)
   19131             :     {
   19132        2512 :         if (stmt->withClause)
   19133           0 :             ereport(ERROR,
   19134             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19135             :                      errmsg("multiple WITH clauses not allowed"),
   19136             :                      parser_errposition(exprLocation((Node *) withClause))));
   19137        2512 :         stmt->withClause = withClause;
   19138             : 
   19139             :         /* Update SelectStmt's location to the start of the WITH clause */
   19140        2512 :         stmt->stmt_location = withClause->location;
   19141             :     }
   19142       74334 : }
   19143             : 
   19144             : static Node *
   19145       15346 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, int location)
   19146             : {
   19147       15346 :     SelectStmt *n = makeNode(SelectStmt);
   19148             : 
   19149       15346 :     n->op = op;
   19150       15346 :     n->all = all;
   19151       15346 :     n->larg = (SelectStmt *) larg;
   19152       15346 :     n->rarg = (SelectStmt *) rarg;
   19153       15346 :     n->stmt_location = location;
   19154       15346 :     return (Node *) n;
   19155             : }
   19156             : 
   19157             : /* SystemFuncName()
   19158             :  * Build a properly-qualified reference to a built-in function.
   19159             :  */
   19160             : List *
   19161       18210 : SystemFuncName(char *name)
   19162             : {
   19163       18210 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19164             : }
   19165             : 
   19166             : /* SystemTypeName()
   19167             :  * Build a properly-qualified reference to a built-in type.
   19168             :  *
   19169             :  * typmod is defaulted, but may be changed afterwards by caller.
   19170             :  * Likewise for the location.
   19171             :  */
   19172             : TypeName *
   19173       99246 : SystemTypeName(char *name)
   19174             : {
   19175       99246 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19176             :                                                makeString(name)));
   19177             : }
   19178             : 
   19179             : /* doNegate()
   19180             :  * Handle negation of a numeric constant.
   19181             :  *
   19182             :  * Formerly, we did this here because the optimizer couldn't cope with
   19183             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19184             :  * and a unary minus operator applied to a constant didn't qualify.
   19185             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19186             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19187             :  * there's still a good reason for doing this here, which is that we can
   19188             :  * postpone committing to a particular internal representation for simple
   19189             :  * negative constants.  It's better to leave "-123.456" in string form
   19190             :  * until we know what the desired type is.
   19191             :  */
   19192             : static Node *
   19193       27928 : doNegate(Node *n, int location)
   19194             : {
   19195       27928 :     if (IsA(n, A_Const))
   19196             :     {
   19197       26696 :         A_Const    *con = (A_Const *) n;
   19198             : 
   19199             :         /* report the constant's location as that of the '-' sign */
   19200       26696 :         con->location = location;
   19201             : 
   19202       26696 :         if (IsA(&con->val, Integer))
   19203             :         {
   19204       25744 :             con->val.ival.ival = -con->val.ival.ival;
   19205       25744 :             return n;
   19206             :         }
   19207         952 :         if (IsA(&con->val, Float))
   19208             :         {
   19209         952 :             doNegateFloat(&con->val.fval);
   19210         952 :             return n;
   19211             :         }
   19212             :     }
   19213             : 
   19214        1232 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19215             : }
   19216             : 
   19217             : static void
   19218         972 : doNegateFloat(Float *v)
   19219             : {
   19220         972 :     char       *oldval = v->fval;
   19221             : 
   19222         972 :     if (*oldval == '+')
   19223           0 :         oldval++;
   19224         972 :     if (*oldval == '-')
   19225           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19226             :     else
   19227         972 :         v->fval = psprintf("-%s", oldval);
   19228         972 : }
   19229             : 
   19230             : static Node *
   19231      214020 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19232             : {
   19233             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19234      214020 :     if (IsA(lexpr, BoolExpr))
   19235             :     {
   19236       99402 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19237             : 
   19238       99402 :         if (blexpr->boolop == AND_EXPR)
   19239             :         {
   19240       97038 :             blexpr->args = lappend(blexpr->args, rexpr);
   19241       97038 :             return (Node *) blexpr;
   19242             :         }
   19243             :     }
   19244      116982 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19245             : }
   19246             : 
   19247             : static Node *
   19248       15930 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19249             : {
   19250             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19251       15930 :     if (IsA(lexpr, BoolExpr))
   19252             :     {
   19253        6550 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19254             : 
   19255        6550 :         if (blexpr->boolop == OR_EXPR)
   19256             :         {
   19257        3704 :             blexpr->args = lappend(blexpr->args, rexpr);
   19258        3704 :             return (Node *) blexpr;
   19259             :         }
   19260             :     }
   19261       12226 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19262             : }
   19263             : 
   19264             : static Node *
   19265       14612 : makeNotExpr(Node *expr, int location)
   19266             : {
   19267       14612 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19268             : }
   19269             : 
   19270             : static Node *
   19271        7886 : makeAArrayExpr(List *elements, int location)
   19272             : {
   19273        7886 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19274             : 
   19275        7886 :     n->elements = elements;
   19276        7886 :     n->location = location;
   19277        7886 :     return (Node *) n;
   19278             : }
   19279             : 
   19280             : static Node *
   19281        2768 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19282             : {
   19283        2768 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19284             : 
   19285        2768 :     svf->op = op;
   19286             :     /* svf->type will be filled during parse analysis */
   19287        2768 :     svf->typmod = typmod;
   19288        2768 :     svf->location = location;
   19289        2768 :     return (Node *) svf;
   19290             : }
   19291             : 
   19292             : static Node *
   19293         596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19294             :             int location)
   19295             : {
   19296         596 :     XmlExpr    *x = makeNode(XmlExpr);
   19297             : 
   19298         596 :     x->op = op;
   19299         596 :     x->name = name;
   19300             : 
   19301             :     /*
   19302             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19303             :      * expression and name lists in transformXmlExpr().
   19304             :      */
   19305         596 :     x->named_args = named_args;
   19306         596 :     x->arg_names = NIL;
   19307         596 :     x->args = args;
   19308             :     /* xmloption, if relevant, must be filled in by caller */
   19309             :     /* type and typmod will be filled in during parse analysis */
   19310         596 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19311         596 :     x->location = location;
   19312         596 :     return (Node *) x;
   19313             : }
   19314             : 
   19315             : /*
   19316             :  * Merge the input and output parameters of a table function.
   19317             :  */
   19318             : static List *
   19319         188 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19320             : {
   19321             :     ListCell   *lc;
   19322             : 
   19323             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19324         382 :     foreach(lc, func_args)
   19325             :     {
   19326         194 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19327             : 
   19328         194 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19329           0 :             p->mode != FUNC_PARAM_IN &&
   19330           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19331           0 :             ereport(ERROR,
   19332             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19333             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19334             :                      parser_errposition(p->location)));
   19335             :     }
   19336             : 
   19337         188 :     return list_concat(func_args, columns);
   19338             : }
   19339             : 
   19340             : /*
   19341             :  * Determine return type of a TABLE function.  A single result column
   19342             :  * returns setof that column's type; otherwise return setof record.
   19343             :  */
   19344             : static TypeName *
   19345         188 : TableFuncTypeName(List *columns)
   19346             : {
   19347             :     TypeName   *result;
   19348             : 
   19349         188 :     if (list_length(columns) == 1)
   19350             :     {
   19351          62 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19352             : 
   19353          62 :         result = copyObject(p->argType);
   19354             :     }
   19355             :     else
   19356         126 :         result = SystemTypeName("record");
   19357             : 
   19358         188 :     result->setof = true;
   19359             : 
   19360         188 :     return result;
   19361             : }
   19362             : 
   19363             : /*
   19364             :  * Convert a list of (dotted) names to a RangeVar (like
   19365             :  * makeRangeVarFromNameList, but with position support).  The
   19366             :  * "AnyName" refers to the any_name production in the grammar.
   19367             :  */
   19368             : static RangeVar *
   19369        4724 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19370             : {
   19371        4724 :     RangeVar   *r = makeNode(RangeVar);
   19372             : 
   19373        4724 :     switch (list_length(names))
   19374             :     {
   19375        4634 :         case 1:
   19376        4634 :             r->catalogname = NULL;
   19377        4634 :             r->schemaname = NULL;
   19378        4634 :             r->relname = strVal(linitial(names));
   19379        4634 :             break;
   19380          90 :         case 2:
   19381          90 :             r->catalogname = NULL;
   19382          90 :             r->schemaname = strVal(linitial(names));
   19383          90 :             r->relname = strVal(lsecond(names));
   19384          90 :             break;
   19385           0 :         case 3:
   19386           0 :             r->catalogname = strVal(linitial(names));
   19387           0 :             r->schemaname = strVal(lsecond(names));
   19388           0 :             r->relname = strVal(lthird(names));
   19389           0 :             break;
   19390           0 :         default:
   19391           0 :             ereport(ERROR,
   19392             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19393             :                      errmsg("improper qualified name (too many dotted names): %s",
   19394             :                             NameListToString(names)),
   19395             :                      parser_errposition(position)));
   19396             :             break;
   19397             :     }
   19398             : 
   19399        4724 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19400        4724 :     r->location = position;
   19401             : 
   19402        4724 :     return r;
   19403             : }
   19404             : 
   19405             : /*
   19406             :  * Convert a relation_name with name and namelist to a RangeVar using
   19407             :  * makeRangeVar.
   19408             :  */
   19409             : static RangeVar *
   19410      229550 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19411             :                               core_yyscan_t yyscanner)
   19412             : {
   19413             :     RangeVar   *r;
   19414             : 
   19415      229550 :     check_qualified_name(namelist, yyscanner);
   19416      229550 :     r = makeRangeVar(NULL, NULL, location);
   19417             : 
   19418      229550 :     switch (list_length(namelist))
   19419             :     {
   19420      229550 :         case 1:
   19421      229550 :             r->catalogname = NULL;
   19422      229550 :             r->schemaname = name;
   19423      229550 :             r->relname = strVal(linitial(namelist));
   19424      229550 :             break;
   19425           0 :         case 2:
   19426           0 :             r->catalogname = name;
   19427           0 :             r->schemaname = strVal(linitial(namelist));
   19428           0 :             r->relname = strVal(lsecond(namelist));
   19429           0 :             break;
   19430           0 :         default:
   19431           0 :             ereport(ERROR,
   19432             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19433             :                     errmsg("improper qualified name (too many dotted names): %s",
   19434             :                            NameListToString(lcons(makeString(name), namelist))),
   19435             :                     parser_errposition(location));
   19436             :             break;
   19437             :     }
   19438             : 
   19439      229550 :     return r;
   19440             : }
   19441             : 
   19442             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19443             : static void
   19444       67358 : SplitColQualList(List *qualList,
   19445             :                  List **constraintList, CollateClause **collClause,
   19446             :                  core_yyscan_t yyscanner)
   19447             : {
   19448             :     ListCell   *cell;
   19449             : 
   19450       67358 :     *collClause = NULL;
   19451       86484 :     foreach(cell, qualList)
   19452             :     {
   19453       19126 :         Node       *n = (Node *) lfirst(cell);
   19454             : 
   19455       19126 :         if (IsA(n, Constraint))
   19456             :         {
   19457             :             /* keep it in list */
   19458       18384 :             continue;
   19459             :         }
   19460         742 :         if (IsA(n, CollateClause))
   19461             :         {
   19462         742 :             CollateClause *c = (CollateClause *) n;
   19463             : 
   19464         742 :             if (*collClause)
   19465           0 :                 ereport(ERROR,
   19466             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19467             :                          errmsg("multiple COLLATE clauses not allowed"),
   19468             :                          parser_errposition(c->location)));
   19469         742 :             *collClause = c;
   19470             :         }
   19471             :         else
   19472           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19473             :         /* remove non-Constraint nodes from qualList */
   19474         742 :         qualList = foreach_delete_current(qualList, cell);
   19475             :     }
   19476       67358 :     *constraintList = qualList;
   19477       67358 : }
   19478             : 
   19479             : /*
   19480             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19481             :  * in the output command node.  Pass NULL for any flags the particular
   19482             :  * command doesn't support.
   19483             :  */
   19484             : static void
   19485       16288 : processCASbits(int cas_bits, int location, const char *constrType,
   19486             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19487             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19488             : {
   19489             :     /* defaults */
   19490       16288 :     if (deferrable)
   19491       14514 :         *deferrable = false;
   19492       16288 :     if (initdeferred)
   19493       14514 :         *initdeferred = false;
   19494       16288 :     if (not_valid)
   19495        3144 :         *not_valid = false;
   19496       16288 :     if (is_enforced)
   19497        1190 :         *is_enforced = true;
   19498             : 
   19499       16288 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19500             :     {
   19501         248 :         if (deferrable)
   19502         248 :             *deferrable = true;
   19503             :         else
   19504           0 :             ereport(ERROR,
   19505             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19506             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19507             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19508             :                             constrType),
   19509             :                      parser_errposition(location)));
   19510             :     }
   19511             : 
   19512       16288 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19513             :     {
   19514         164 :         if (initdeferred)
   19515         164 :             *initdeferred = true;
   19516             :         else
   19517           0 :             ereport(ERROR,
   19518             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19519             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19520             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19521             :                             constrType),
   19522             :                      parser_errposition(location)));
   19523             :     }
   19524             : 
   19525       16288 :     if (cas_bits & CAS_NOT_VALID)
   19526             :     {
   19527         542 :         if (not_valid)
   19528         542 :             *not_valid = true;
   19529             :         else
   19530           0 :             ereport(ERROR,
   19531             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19532             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19533             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19534             :                             constrType),
   19535             :                      parser_errposition(location)));
   19536             :     }
   19537             : 
   19538       16288 :     if (cas_bits & CAS_NO_INHERIT)
   19539             :     {
   19540         190 :         if (no_inherit)
   19541         190 :             *no_inherit = true;
   19542             :         else
   19543           0 :             ereport(ERROR,
   19544             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19545             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19546             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19547             :                             constrType),
   19548             :                      parser_errposition(location)));
   19549             :     }
   19550             : 
   19551       16288 :     if (cas_bits & CAS_NOT_ENFORCED)
   19552             :     {
   19553          84 :         if (is_enforced)
   19554          72 :             *is_enforced = false;
   19555             :         else
   19556          12 :             ereport(ERROR,
   19557             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19558             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19559             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19560             :                             constrType),
   19561             :                      parser_errposition(location)));
   19562             : 
   19563             :         /*
   19564             :          * NB: The validated status is irrelevant when the constraint is set to
   19565             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19566             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19567             :          * will automatically be in the correct NOT VALIDATED state.
   19568             :          */
   19569          72 :         if (not_valid)
   19570          72 :             *not_valid = true;
   19571             :     }
   19572             : 
   19573       16276 :     if (cas_bits & CAS_ENFORCED)
   19574             :     {
   19575          42 :         if (is_enforced)
   19576          30 :             *is_enforced = true;
   19577             :         else
   19578          12 :             ereport(ERROR,
   19579             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19580             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19581             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19582             :                             constrType),
   19583             :                      parser_errposition(location)));
   19584             :     }
   19585       16264 : }
   19586             : 
   19587             : /*
   19588             :  * Parse a user-supplied partition strategy string into parse node
   19589             :  * PartitionStrategy representation, or die trying.
   19590             :  */
   19591             : static PartitionStrategy
   19592        4906 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19593             : {
   19594        4906 :     if (pg_strcasecmp(strategy, "list") == 0)
   19595        2502 :         return PARTITION_STRATEGY_LIST;
   19596        2404 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19597        2158 :         return PARTITION_STRATEGY_RANGE;
   19598         246 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19599         240 :         return PARTITION_STRATEGY_HASH;
   19600             : 
   19601           6 :     ereport(ERROR,
   19602             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19603             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19604             :              parser_errposition(location)));
   19605             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19606             : 
   19607             : }
   19608             : 
   19609             : /*
   19610             :  * Process pubobjspec_list to check for errors in any of the objects and
   19611             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19612             :  */
   19613             : static void
   19614        1572 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19615             : {
   19616             :     ListCell   *cell;
   19617             :     PublicationObjSpec *pubobj;
   19618        1572 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19619             : 
   19620        1572 :     if (!pubobjspec_list)
   19621           0 :         return;
   19622             : 
   19623        1572 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19624        1572 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19625          12 :         ereport(ERROR,
   19626             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19627             :                 errmsg("invalid publication object list"),
   19628             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19629             :                 parser_errposition(pubobj->location));
   19630             : 
   19631        3318 :     foreach(cell, pubobjspec_list)
   19632             :     {
   19633        1782 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19634             : 
   19635        1782 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19636         172 :             pubobj->pubobjtype = prevobjtype;
   19637             : 
   19638        1782 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19639             :         {
   19640             :             /* relation name or pubtable must be set for this type of object */
   19641        1378 :             if (!pubobj->name && !pubobj->pubtable)
   19642           6 :                 ereport(ERROR,
   19643             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19644             :                         errmsg("invalid table name"),
   19645             :                         parser_errposition(pubobj->location));
   19646             : 
   19647        1372 :             if (pubobj->name)
   19648             :             {
   19649             :                 /* convert it to PublicationTable */
   19650          56 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19651             : 
   19652          56 :                 pubtable->relation =
   19653          56 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19654          56 :                 pubobj->pubtable = pubtable;
   19655          56 :                 pubobj->name = NULL;
   19656             :             }
   19657             :         }
   19658         404 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19659          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19660             :         {
   19661             :             /* WHERE clause is not allowed on a schema object */
   19662         404 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19663           6 :                 ereport(ERROR,
   19664             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19665             :                         errmsg("WHERE clause not allowed for schema"),
   19666             :                         parser_errposition(pubobj->location));
   19667             : 
   19668             :             /* Column list is not allowed on a schema object */
   19669         398 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19670           6 :                 ereport(ERROR,
   19671             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19672             :                         errmsg("column specification not allowed for schema"),
   19673             :                         parser_errposition(pubobj->location));
   19674             : 
   19675             :             /*
   19676             :              * We can distinguish between the different type of schema objects
   19677             :              * based on whether name and pubtable is set.
   19678             :              */
   19679         392 :             if (pubobj->name)
   19680         362 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19681          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19682          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19683             :             else
   19684           6 :                 ereport(ERROR,
   19685             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19686             :                         errmsg("invalid schema name"),
   19687             :                         parser_errposition(pubobj->location));
   19688             :         }
   19689             : 
   19690        1758 :         prevobjtype = pubobj->pubobjtype;
   19691             :     }
   19692             : }
   19693             : 
   19694             : /*----------
   19695             :  * Recursive view transformation
   19696             :  *
   19697             :  * Convert
   19698             :  *
   19699             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19700             :  *
   19701             :  * to
   19702             :  *
   19703             :  *     CREATE VIEW relname (aliases) AS
   19704             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19705             :  *         SELECT aliases FROM relname
   19706             :  *
   19707             :  * Actually, just the WITH ... part, which is then inserted into the original
   19708             :  * view definition as the query.
   19709             :  * ----------
   19710             :  */
   19711             : static Node *
   19712          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19713             : {
   19714          14 :     SelectStmt *s = makeNode(SelectStmt);
   19715          14 :     WithClause *w = makeNode(WithClause);
   19716          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19717          14 :     List       *tl = NIL;
   19718             :     ListCell   *lc;
   19719             : 
   19720             :     /* create common table expression */
   19721          14 :     cte->ctename = relname;
   19722          14 :     cte->aliascolnames = aliases;
   19723          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19724          14 :     cte->ctequery = query;
   19725          14 :     cte->location = -1;
   19726             : 
   19727             :     /* create WITH clause and attach CTE */
   19728          14 :     w->recursive = true;
   19729          14 :     w->ctes = list_make1(cte);
   19730          14 :     w->location = -1;
   19731             : 
   19732             :     /*
   19733             :      * create target list for the new SELECT from the alias list of the
   19734             :      * recursive view specification
   19735             :      */
   19736          28 :     foreach(lc, aliases)
   19737             :     {
   19738          14 :         ResTarget  *rt = makeNode(ResTarget);
   19739             : 
   19740          14 :         rt->name = NULL;
   19741          14 :         rt->indirection = NIL;
   19742          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19743          14 :         rt->location = -1;
   19744             : 
   19745          14 :         tl = lappend(tl, rt);
   19746             :     }
   19747             : 
   19748             :     /*
   19749             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19750             :      * clause
   19751             :      */
   19752          14 :     s->withClause = w;
   19753          14 :     s->targetList = tl;
   19754          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19755             : 
   19756          14 :     return (Node *) s;
   19757             : }
   19758             : 
   19759             : /* parser_init()
   19760             :  * Initialize to parse one query string
   19761             :  */
   19762             : void
   19763      769346 : parser_init(base_yy_extra_type *yyext)
   19764             : {
   19765      769346 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19766      769346 : }

Generated by: LCOV version 1.14