LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 19devel Lines: 6784 7491 90.6 %
Date: 2025-09-07 07:18:02 Functions: 41 41 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 Node *makeColumnRef(char *colname, List *indirection,
     158             :                            int location, core_yyscan_t yyscanner);
     159             : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     160             : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     161             : static Node *makeIntConst(int val, int location);
     162             : static Node *makeFloatConst(char *str, int location);
     163             : static Node *makeBoolAConst(bool state, int location);
     164             : static Node *makeBitStringConst(char *str, int location);
     165             : static Node *makeNullAConst(int location);
     166             : static Node *makeAConst(Node *v, int location);
     167             : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     168             : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     169             : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     170             : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     171             : static List *extractArgTypes(List *parameters);
     172             : static List *extractAggrArgTypes(List *aggrargs);
     173             : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     174             :                                 core_yyscan_t yyscanner);
     175             : static void insertSelectOptions(SelectStmt *stmt,
     176             :                                 List *sortClause, List *lockingClause,
     177             :                                 SelectLimit *limitClause,
     178             :                                 WithClause *withClause,
     179             :                                 core_yyscan_t yyscanner);
     180             : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     181             : static Node *doNegate(Node *n, int location);
     182             : static void doNegateFloat(Float *v);
     183             : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     184             : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     185             : static Node *makeNotExpr(Node *expr, int location);
     186             : static Node *makeAArrayExpr(List *elements, int location, int end_location);
     187             : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     188             :                                   int location);
     189             : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     190             :                          List *args, int location);
     191             : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
     192             : static TypeName *TableFuncTypeName(List *columns);
     193             : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     194             : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     195             :                                                core_yyscan_t yyscanner);
     196             : static void SplitColQualList(List *qualList,
     197             :                              List **constraintList, CollateClause **collClause,
     198             :                              core_yyscan_t yyscanner);
     199             : static void processCASbits(int cas_bits, int location, const char *constrType,
     200             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
     201             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
     202             : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
     203             :                                                 core_yyscan_t yyscanner);
     204             : static void preprocess_pubobj_list(List *pubobjspec_list,
     205             :                                    core_yyscan_t yyscanner);
     206             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     207             : 
     208             : %}
     209             : 
     210             : %pure-parser
     211             : %expect 0
     212             : %name-prefix="base_yy"
     213             : %locations
     214             : 
     215             : %parse-param {core_yyscan_t yyscanner}
     216             : %lex-param   {core_yyscan_t yyscanner}
     217             : 
     218             : %union
     219             : {
     220             :     core_YYSTYPE core_yystype;
     221             :     /* these fields must match core_YYSTYPE: */
     222             :     int         ival;
     223             :     char       *str;
     224             :     const char *keyword;
     225             : 
     226             :     char        chr;
     227             :     bool        boolean;
     228             :     JoinType    jtype;
     229             :     DropBehavior dbehavior;
     230             :     OnCommitAction oncommit;
     231             :     List       *list;
     232             :     Node       *node;
     233             :     ObjectType  objtype;
     234             :     TypeName   *typnam;
     235             :     FunctionParameter *fun_param;
     236             :     FunctionParameterMode fun_param_mode;
     237             :     ObjectWithArgs *objwithargs;
     238             :     DefElem    *defelt;
     239             :     SortBy     *sortby;
     240             :     WindowDef  *windef;
     241             :     JoinExpr   *jexpr;
     242             :     IndexElem  *ielem;
     243             :     StatsElem  *selem;
     244             :     Alias      *alias;
     245             :     RangeVar   *range;
     246             :     IntoClause *into;
     247             :     WithClause *with;
     248             :     InferClause *infer;
     249             :     OnConflictClause *onconflict;
     250             :     A_Indices  *aind;
     251             :     ResTarget  *target;
     252             :     struct PrivTarget *privtarget;
     253             :     AccessPriv *accesspriv;
     254             :     struct ImportQual *importqual;
     255             :     InsertStmt *istmt;
     256             :     VariableSetStmt *vsetstmt;
     257             :     PartitionElem *partelem;
     258             :     PartitionSpec *partspec;
     259             :     PartitionBoundSpec *partboundspec;
     260             :     RoleSpec   *rolespec;
     261             :     PublicationObjSpec *publicationobjectspec;
     262             :     struct SelectLimit *selectlimit;
     263             :     SetQuantifier setquantifier;
     264             :     struct GroupClause *groupclause;
     265             :     MergeMatchKind mergematch;
     266             :     MergeWhenClause *mergewhen;
     267             :     struct KeyActions *keyactions;
     268             :     struct KeyAction *keyaction;
     269             :     ReturningClause *retclause;
     270             :     ReturningOptionKind retoptionkind;
     271             : }
     272             : 
     273             : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     274             :         AlterEventTrigStmt AlterCollationStmt
     275             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     276             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     277             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     278             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     279             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     280             :         AlterCompositeTypeStmt AlterUserMappingStmt
     281             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     282             :         AlterDefaultPrivilegesStmt DefACLAction
     283             :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     284             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     285             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     286             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     287             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     288             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     289             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     290             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     291             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     292             :         DropOpClassStmt DropOpFamilyStmt DropStmt
     293             :         DropCastStmt DropRoleStmt
     294             :         DropdbStmt DropTableSpaceStmt
     295             :         DropTransformStmt
     296             :         DropUserMappingStmt ExplainStmt FetchStmt
     297             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     298             :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     299             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     300             :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     301             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     302             :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     303             :         UnlistenStmt UpdateStmt VacuumStmt
     304             :         VariableResetStmt VariableSetStmt VariableShowStmt
     305             :         ViewStmt CheckPointStmt CreateConversionStmt
     306             :         DeallocateStmt PrepareStmt ExecuteStmt
     307             :         DropOwnedStmt ReassignOwnedStmt
     308             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     309             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     310             :         CreatePublicationStmt AlterPublicationStmt
     311             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     312             : 
     313             : %type <node>  select_no_parens select_with_parens select_clause
     314             :                 simple_select values_clause
     315             :                 PLpgSQL_Expr PLAssignStmt
     316             : 
     317             : %type <str>           opt_single_name
     318             : %type <list>      opt_qualified_name
     319             : %type <boolean>       opt_concurrently
     320             : %type <dbehavior> opt_drop_behavior
     321             : %type <list>      opt_utility_option_list
     322             : %type <list>      utility_option_list
     323             : %type <defelt>        utility_option_elem
     324             : %type <str>           utility_option_name
     325             : %type <node>      utility_option_arg
     326             : 
     327             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     328             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     329             : 
     330             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     331             :        replica_identity partition_cmd index_partition_cmd
     332             : %type <list>  alter_table_cmds alter_type_cmds
     333             : %type <list>    alter_identity_column_option_list
     334             : %type <defelt>  alter_identity_column_option
     335             : %type <node>  set_statistics_value
     336             : %type <str>       set_access_method_name
     337             : 
     338             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     339             :                 transaction_mode_list
     340             :                 create_extension_opt_list alter_extension_opt_list
     341             : %type <defelt>    createdb_opt_item copy_opt_item
     342             :                 transaction_mode_item
     343             :                 create_extension_opt_item alter_extension_opt_item
     344             : 
     345             : %type <ival>  opt_lock lock_type cast_context
     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 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             : 
     561             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     562             : %type <defelt>    copy_generic_opt_elem
     563             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     564             : %type <list>  copy_options
     565             : 
     566             : %type <typnam>    Typename SimpleTypename ConstTypename
     567             :                 GenericType Numeric opt_float JsonType
     568             :                 Character ConstCharacter
     569             :                 CharacterWithLength CharacterWithoutLength
     570             :                 ConstDatetime ConstInterval
     571             :                 Bit ConstBit BitWithLength BitWithoutLength
     572             : %type <str>       character
     573             : %type <str>       extract_arg
     574             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     575             : 
     576             : %type <ival>  Iconst SignedIconst
     577             : %type <str>       Sconst comment_text notify_payload
     578             : %type <str>       RoleId opt_boolean_or_string
     579             : %type <list>  var_list
     580             : %type <str>       ColId ColLabel BareColLabel
     581             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     582             : %type <str>       var_name type_function_name param_name
     583             : %type <str>       createdb_opt_name plassign_target
     584             : %type <node>  var_value zone_value
     585             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     586             : %type <publicationobjectspec> PublicationObjSpec
     587             : 
     588             : %type <keyword> unreserved_keyword type_func_name_keyword
     589             : %type <keyword> col_name_keyword reserved_keyword
     590             : %type <keyword> bare_label_keyword
     591             : 
     592             : %type <node>  DomainConstraint TableConstraint TableLikeClause
     593             : %type <ival>  TableLikeOptionList TableLikeOption
     594             : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     595             : %type <list>  ColQualList
     596             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     597             : %type <ival>  key_match
     598             : %type <keyaction> key_delete key_update key_action
     599             : %type <keyactions> key_actions
     600             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     601             : %type <str>       ExistingIndex
     602             : 
     603             : %type <list>  constraints_set_list
     604             : %type <boolean> constraints_set_mode
     605             : %type <str>       OptTableSpace OptConsTableSpace
     606             : %type <rolespec> OptTableSpaceOwner
     607             : %type <ival>  opt_check_option
     608             : 
     609             : %type <str>       opt_provider security_label
     610             : 
     611             : %type <target>    xml_attribute_el
     612             : %type <list>  xml_attribute_list xml_attributes
     613             : %type <node>  xml_root_version opt_xml_root_standalone
     614             : %type <node>  xmlexists_argument
     615             : %type <ival>  document_or_content
     616             : %type <boolean>   xml_indent_option xml_whitespace_option
     617             : %type <list>  xmltable_column_list xmltable_column_option_list
     618             : %type <node>  xmltable_column_el
     619             : %type <defelt>    xmltable_column_option_el
     620             : %type <list>  xml_namespace_list
     621             : %type <target>    xml_namespace_el
     622             : 
     623             : %type <node>  func_application func_expr_common_subexpr
     624             : %type <node>  func_expr func_expr_windowless
     625             : %type <node>  common_table_expr
     626             : %type <with>  with_clause opt_with_clause
     627             : %type <list>  cte_list
     628             : 
     629             : %type <list>  within_group_clause
     630             : %type <node>  filter_clause
     631             : %type <list>  window_clause window_definition_list opt_partition_clause
     632             : %type <windef>    window_definition over_clause window_specification
     633             :                 opt_frame_clause frame_extent frame_bound
     634             : %type <ival>  opt_window_exclusion_clause
     635             : %type <str>       opt_existing_window_name
     636             : %type <boolean> opt_if_not_exists
     637             : %type <boolean> opt_unique_null_treatment
     638             : %type <ival>  generated_when override_kind opt_virtual_or_stored
     639             : %type <partspec>  PartitionSpec OptPartitionSpec
     640             : %type <partelem>  part_elem
     641             : %type <list>      part_params
     642             : %type <partboundspec> PartitionBoundSpec
     643             : %type <list>      hash_partbound
     644             : %type <defelt>        hash_partbound_elem
     645             : 
     646             : %type <node>  json_format_clause
     647             :                 json_format_clause_opt
     648             :                 json_value_expr
     649             :                 json_returning_clause_opt
     650             :                 json_name_and_value
     651             :                 json_aggregate_func
     652             :                 json_argument
     653             :                 json_behavior
     654             :                 json_on_error_clause_opt
     655             :                 json_table
     656             :                 json_table_column_definition
     657             :                 json_table_column_path_clause_opt
     658             : %type <list>  json_name_and_value_list
     659             :                 json_value_expr_list
     660             :                 json_array_aggregate_order_by_clause_opt
     661             :                 json_arguments
     662             :                 json_behavior_clause_opt
     663             :                 json_passing_clause_opt
     664             :                 json_table_column_definition_list
     665             : %type <str>       json_table_path_name_opt
     666             : %type <ival>  json_behavior_type
     667             :                 json_predicate_type_constraint
     668             :                 json_quotes_clause_opt
     669             :                 json_wrapper_behavior
     670             : %type <boolean>   json_key_uniqueness_constraint_opt
     671             :                 json_object_constructor_null_clause_opt
     672             :                 json_array_constructor_null_clause_opt
     673             : 
     674             : 
     675             : /*
     676             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     677             :  * They must be listed first so that their numeric codes do not depend on
     678             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     679             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     680             :  *
     681             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     682             :  * they need no productions here; but we must assign token codes to them.
     683             :  *
     684             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     685             :  * parse errors.  It is needed by PL/pgSQL.
     686             :  */
     687             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     688             : %token <ival> ICONST PARAM
     689             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     690             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     691             : 
     692             : /*
     693             :  * If you want to make any keyword changes, update the keyword table in
     694             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     695             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     696             :  * this file for "Keyword category lists".
     697             :  */
     698             : 
     699             : /* ordinary key words in alphabetical order */
     700             : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     701             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     702             :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     703             : 
     704             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     705             :     BOOLEAN_P BOTH BREADTH BY
     706             : 
     707             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     708             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     709             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     710             :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     711             :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     712             :     COST CREATE CROSS CSV CUBE CURRENT_P
     713             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     714             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     715             : 
     716             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     717             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     718             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     719             :     DOUBLE_P DROP
     720             : 
     721             :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
     722             :     ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
     723             :     EXPRESSION EXTENSION EXTERNAL EXTRACT
     724             : 
     725             :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     726             :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     727             : 
     728             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     729             : 
     730             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     731             : 
     732             :     IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     733             :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     734             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     735             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     736             : 
     737             :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     738             :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
     739             : 
     740             :     KEEP KEY KEYS
     741             : 
     742             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     743             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     744             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     745             : 
     746             :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     747             :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     748             : 
     749             :     NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
     750             :     NONE NORMALIZE NORMALIZED
     751             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     752             :     NULLS_P NUMERIC
     753             : 
     754             :     OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     755             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     756             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     757             : 
     758             :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
     759             :     PERIOD PLACING PLAN PLANS POLICY
     760             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     761             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     762             : 
     763             :     QUOTE QUOTES
     764             : 
     765             :     RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
     766             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     767             :     RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     768             :     ROUTINE ROUTINES ROW ROWS RULE
     769             : 
     770             :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     771             :     SEQUENCE SEQUENCES
     772             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     773             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
     774             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     775             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     776             : 
     777             :     TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
     778             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     779             :     TREAT TRIGGER TRIM TRUE_P
     780             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     781             : 
     782             :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     783             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     784             : 
     785             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     786             :     VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
     787             : 
     788             :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     789             : 
     790             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     791             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     792             : 
     793             :     YEAR_P YES_P
     794             : 
     795             :     ZONE
     796             : 
     797             : /*
     798             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     799             :  * list and so can never be entered directly.  The filter in parser.c
     800             :  * creates these tokens when required (based on looking one token ahead).
     801             :  *
     802             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     803             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     804             :  * as NOT, at least with respect to their left-hand subexpression.
     805             :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     806             :  * LALR(1).
     807             :  */
     808             : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     809             : 
     810             : /*
     811             :  * The grammar likewise thinks these tokens are keywords, but they are never
     812             :  * generated by the scanner.  Rather, they can be injected by parser.c as
     813             :  * the initial token of the string (using the lookahead-token mechanism
     814             :  * implemented there).  This provides a way to tell the grammar to parse
     815             :  * something other than the usual list of SQL commands.
     816             :  */
     817             : %token      MODE_TYPE_NAME
     818             : %token      MODE_PLPGSQL_EXPR
     819             : %token      MODE_PLPGSQL_ASSIGN1
     820             : %token      MODE_PLPGSQL_ASSIGN2
     821             : %token      MODE_PLPGSQL_ASSIGN3
     822             : 
     823             : 
     824             : /* Precedence: lowest to highest */
     825             : %left       UNION EXCEPT
     826             : %left       INTERSECT
     827             : %left       OR
     828             : %left       AND
     829             : %right      NOT
     830             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     831             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     832             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     833             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     834             : 
     835             : /*
     836             :  * Sometimes it is necessary to assign precedence to keywords that are not
     837             :  * really part of the operator hierarchy, in order to resolve grammar
     838             :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     839             :  * assignments have global effect and may hide ambiguities besides the one
     840             :  * you intended to solve.  (Attaching a precedence to a single rule with
     841             :  * %prec is far safer and should be preferred.)  If you must give precedence
     842             :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     843             :  * If the keyword has IDENT's precedence then it clearly acts the same as
     844             :  * non-keywords and other similar keywords, thus reducing the risk of
     845             :  * unexpected precedence effects.
     846             :  *
     847             :  * We used to need to assign IDENT an explicit precedence just less than Op,
     848             :  * to support target_el without AS.  While that's not really necessary since
     849             :  * we removed postfix operators, we continue to do so because it provides a
     850             :  * reference point for a precedence level that we can assign to other
     851             :  * keywords that lack a natural precedence level.
     852             :  *
     853             :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     854             :  * opt_existing_window_name (see comment there).
     855             :  *
     856             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     857             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     858             :  * there is no principled way to distinguish these from the productions
     859             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     860             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     861             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     862             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     863             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     864             :  *
     865             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     866             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     867             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     868             :  * Using the same precedence as IDENT seems right for the reasons given above.
     869             :  *
     870             :  * SET is likewise assigned the same precedence as IDENT, to support the
     871             :  * relation_expr_opt_alias production (see comment there).
     872             :  *
     873             :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     874             :  * the same precedence as IDENT.  This allows resolving conflicts in the
     875             :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     876             :  * productions (see comments there).
     877             :  *
     878             :  * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
     879             :  * precedence than PATH to fix ambiguity in the json_table production.
     880             :  */
     881             : %nonassoc   UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
     882             : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     883             :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
     884             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     885             : %left       '+' '-'
     886             : %left       '*' '/' '%'
     887             : %left       '^'
     888             : /* Unary Operators */
     889             : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     890             : %left       COLLATE
     891             : %right      UMINUS
     892             : %left       '[' ']'
     893             : %left       '(' ')'
     894             : %left       TYPECAST
     895             : %left       '.'
     896             : /*
     897             :  * These might seem to be low-precedence, but actually they are not part
     898             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     899             :  * We make them high-precedence to support their use as function names.
     900             :  * They wouldn't be given a precedence at all, were it not that we need
     901             :  * left-associativity among the JOIN rules themselves.
     902             :  */
     903             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     904             : 
     905             : %%
     906             : 
     907             : /*
     908             :  *  The target production for the whole parse.
     909             :  *
     910             :  * Ordinarily we parse a list of statements, but if we see one of the
     911             :  * special MODE_XXX symbols as first token, we parse something else.
     912             :  * The options here correspond to enum RawParseMode, which see for details.
     913             :  */
     914             : parse_toplevel:
     915             :             stmtmulti
     916             :             {
     917      711574 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     918             :                 (void) yynerrs;     /* suppress compiler warning */
     919             :             }
     920             :             | MODE_TYPE_NAME Typename
     921             :             {
     922        9652 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     923             :             }
     924             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     925             :             {
     926       33346 :                 pg_yyget_extra(yyscanner)->parsetree =
     927       33346 :                     list_make1(makeRawStmt($2, @2));
     928             :             }
     929             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     930             :             {
     931        6342 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     932             : 
     933        6342 :                 n->nnames = 1;
     934        6342 :                 pg_yyget_extra(yyscanner)->parsetree =
     935        6342 :                     list_make1(makeRawStmt((Node *) n, @2));
     936             :             }
     937             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     938             :             {
     939         674 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     940             : 
     941         674 :                 n->nnames = 2;
     942         674 :                 pg_yyget_extra(yyscanner)->parsetree =
     943         674 :                     list_make1(makeRawStmt((Node *) n, @2));
     944             :             }
     945             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     946             :             {
     947          28 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     948             : 
     949          28 :                 n->nnames = 3;
     950          28 :                 pg_yyget_extra(yyscanner)->parsetree =
     951          28 :                     list_make1(makeRawStmt((Node *) n, @2));
     952             :             }
     953             :         ;
     954             : 
     955             : /*
     956             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     957             :  * and length of the stmt's text.
     958             :  * We also take care to discard empty statements entirely (which among other
     959             :  * things dodges the problem of assigning them a location).
     960             :  */
     961             : stmtmulti:  stmtmulti ';' toplevel_stmt
     962             :                 {
     963      579876 :                     if ($1 != NIL)
     964             :                     {
     965             :                         /* update length of previous stmt */
     966      579310 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     967             :                     }
     968      579876 :                     if ($3 != NULL)
     969       58238 :                         $$ = lappend($1, makeRawStmt($3, @3));
     970             :                     else
     971      521638 :                         $$ = $1;
     972             :                 }
     973             :             | toplevel_stmt
     974             :                 {
     975      711582 :                     if ($1 != NULL)
     976      710264 :                         $$ = list_make1(makeRawStmt($1, @1));
     977             :                     else
     978        1318 :                         $$ = NIL;
     979             :                 }
     980             :         ;
     981             : 
     982             : /*
     983             :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     984             :  * those words have different meanings in function bodies.
     985             :  */
     986             : toplevel_stmt:
     987             :             stmt
     988             :             | TransactionStmtLegacy
     989             :         ;
     990             : 
     991             : stmt:
     992             :             AlterEventTrigStmt
     993             :             | AlterCollationStmt
     994             :             | AlterDatabaseStmt
     995             :             | AlterDatabaseSetStmt
     996             :             | AlterDefaultPrivilegesStmt
     997             :             | AlterDomainStmt
     998             :             | AlterEnumStmt
     999             :             | AlterExtensionStmt
    1000             :             | AlterExtensionContentsStmt
    1001             :             | AlterFdwStmt
    1002             :             | AlterForeignServerStmt
    1003             :             | AlterFunctionStmt
    1004             :             | AlterGroupStmt
    1005             :             | AlterObjectDependsStmt
    1006             :             | AlterObjectSchemaStmt
    1007             :             | AlterOwnerStmt
    1008             :             | AlterOperatorStmt
    1009             :             | AlterTypeStmt
    1010             :             | AlterPolicyStmt
    1011             :             | AlterSeqStmt
    1012             :             | AlterSystemStmt
    1013             :             | AlterTableStmt
    1014             :             | AlterTblSpcStmt
    1015             :             | AlterCompositeTypeStmt
    1016             :             | AlterPublicationStmt
    1017             :             | AlterRoleSetStmt
    1018             :             | AlterRoleStmt
    1019             :             | AlterSubscriptionStmt
    1020             :             | AlterStatsStmt
    1021             :             | AlterTSConfigurationStmt
    1022             :             | AlterTSDictionaryStmt
    1023             :             | AlterUserMappingStmt
    1024             :             | AnalyzeStmt
    1025             :             | CallStmt
    1026             :             | CheckPointStmt
    1027             :             | ClosePortalStmt
    1028             :             | ClusterStmt
    1029             :             | CommentStmt
    1030             :             | ConstraintsSetStmt
    1031             :             | CopyStmt
    1032             :             | CreateAmStmt
    1033             :             | CreateAsStmt
    1034             :             | CreateAssertionStmt
    1035             :             | CreateCastStmt
    1036             :             | CreateConversionStmt
    1037             :             | CreateDomainStmt
    1038             :             | CreateExtensionStmt
    1039             :             | CreateFdwStmt
    1040             :             | CreateForeignServerStmt
    1041             :             | CreateForeignTableStmt
    1042             :             | CreateFunctionStmt
    1043             :             | CreateGroupStmt
    1044             :             | CreateMatViewStmt
    1045             :             | CreateOpClassStmt
    1046             :             | CreateOpFamilyStmt
    1047             :             | CreatePublicationStmt
    1048             :             | AlterOpFamilyStmt
    1049             :             | CreatePolicyStmt
    1050             :             | CreatePLangStmt
    1051             :             | CreateSchemaStmt
    1052             :             | CreateSeqStmt
    1053             :             | CreateStmt
    1054             :             | CreateSubscriptionStmt
    1055             :             | CreateStatsStmt
    1056             :             | CreateTableSpaceStmt
    1057             :             | CreateTransformStmt
    1058             :             | CreateTrigStmt
    1059             :             | CreateEventTrigStmt
    1060             :             | CreateRoleStmt
    1061             :             | CreateUserStmt
    1062             :             | CreateUserMappingStmt
    1063             :             | CreatedbStmt
    1064             :             | DeallocateStmt
    1065             :             | DeclareCursorStmt
    1066             :             | DefineStmt
    1067             :             | DeleteStmt
    1068             :             | DiscardStmt
    1069             :             | DoStmt
    1070             :             | DropCastStmt
    1071             :             | DropOpClassStmt
    1072             :             | DropOpFamilyStmt
    1073             :             | DropOwnedStmt
    1074             :             | DropStmt
    1075             :             | DropSubscriptionStmt
    1076             :             | DropTableSpaceStmt
    1077             :             | DropTransformStmt
    1078             :             | DropRoleStmt
    1079             :             | DropUserMappingStmt
    1080             :             | DropdbStmt
    1081             :             | ExecuteStmt
    1082             :             | ExplainStmt
    1083             :             | FetchStmt
    1084             :             | GrantStmt
    1085             :             | GrantRoleStmt
    1086             :             | ImportForeignSchemaStmt
    1087             :             | IndexStmt
    1088             :             | InsertStmt
    1089             :             | ListenStmt
    1090             :             | RefreshMatViewStmt
    1091             :             | LoadStmt
    1092             :             | LockStmt
    1093             :             | MergeStmt
    1094             :             | NotifyStmt
    1095             :             | PrepareStmt
    1096             :             | ReassignOwnedStmt
    1097             :             | ReindexStmt
    1098             :             | RemoveAggrStmt
    1099             :             | RemoveFuncStmt
    1100             :             | RemoveOperStmt
    1101             :             | RenameStmt
    1102             :             | RevokeStmt
    1103             :             | RevokeRoleStmt
    1104             :             | RuleStmt
    1105             :             | SecLabelStmt
    1106             :             | SelectStmt
    1107             :             | TransactionStmt
    1108             :             | TruncateStmt
    1109             :             | UnlistenStmt
    1110             :             | UpdateStmt
    1111             :             | VacuumStmt
    1112             :             | VariableResetStmt
    1113             :             | VariableSetStmt
    1114             :             | VariableShowStmt
    1115             :             | ViewStmt
    1116             :             | /*EMPTY*/
    1117      522974 :                 { $$ = NULL; }
    1118             :         ;
    1119             : 
    1120             : /*
    1121             :  * Generic supporting productions for DDL
    1122             :  */
    1123             : opt_single_name:
    1124        5334 :             ColId                           { $$ = $1; }
    1125        1554 :             | /* EMPTY */                   { $$ = NULL; }
    1126             :         ;
    1127             : 
    1128             : opt_qualified_name:
    1129        1876 :             any_name                        { $$ = $1; }
    1130       15204 :             | /*EMPTY*/                     { $$ = NIL; }
    1131             :         ;
    1132             : 
    1133             : opt_concurrently:
    1134        1024 :             CONCURRENTLY                    { $$ = true; }
    1135        7628 :             | /*EMPTY*/                     { $$ = false; }
    1136             :         ;
    1137             : 
    1138             : opt_drop_behavior:
    1139        1964 :             CASCADE                         { $$ = DROP_CASCADE; }
    1140         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1141       39086 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1142             :         ;
    1143             : 
    1144             : opt_utility_option_list:
    1145         366 :             '(' utility_option_list ')'     { $$ = $2; }
    1146        5720 :             | /* EMPTY */                   { $$ = NULL; }
    1147             :         ;
    1148             : 
    1149             : utility_option_list:
    1150             :             utility_option_elem
    1151             :                 {
    1152       22070 :                     $$ = list_make1($1);
    1153             :                 }
    1154             :             | utility_option_list ',' utility_option_elem
    1155             :                 {
    1156       12588 :                     $$ = lappend($1, $3);
    1157             :                 }
    1158             :         ;
    1159             : 
    1160             : utility_option_elem:
    1161             :             utility_option_name utility_option_arg
    1162             :                 {
    1163       34658 :                     $$ = makeDefElem($1, $2, @1);
    1164             :                 }
    1165             :         ;
    1166             : 
    1167             : utility_option_name:
    1168       30864 :             NonReservedWord                 { $$ = $1; }
    1169        3652 :             | analyze_keyword               { $$ = "analyze"; }
    1170         148 :             | FORMAT_LA                     { $$ = "format"; }
    1171             :         ;
    1172             : 
    1173             : utility_option_arg:
    1174       17692 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    1175         382 :             | NumericOnly                   { $$ = (Node *) $1; }
    1176       16584 :             | /* EMPTY */                   { $$ = NULL; }
    1177             :         ;
    1178             : 
    1179             : /*****************************************************************************
    1180             :  *
    1181             :  * CALL statement
    1182             :  *
    1183             :  *****************************************************************************/
    1184             : 
    1185             : CallStmt:   CALL func_application
    1186             :                 {
    1187         628 :                     CallStmt   *n = makeNode(CallStmt);
    1188             : 
    1189         628 :                     n->funccall = castNode(FuncCall, $2);
    1190         628 :                     $$ = (Node *) n;
    1191             :                 }
    1192             :         ;
    1193             : 
    1194             : /*****************************************************************************
    1195             :  *
    1196             :  * Create a new Postgres DBMS role
    1197             :  *
    1198             :  *****************************************************************************/
    1199             : 
    1200             : CreateRoleStmt:
    1201             :             CREATE ROLE RoleId opt_with OptRoleList
    1202             :                 {
    1203        1348 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1204             : 
    1205        1348 :                     n->stmt_type = ROLESTMT_ROLE;
    1206        1348 :                     n->role = $3;
    1207        1348 :                     n->options = $5;
    1208        1348 :                     $$ = (Node *) n;
    1209             :                 }
    1210             :         ;
    1211             : 
    1212             : 
    1213             : opt_with:   WITH
    1214             :             | WITH_LA
    1215             :             | /*EMPTY*/
    1216             :         ;
    1217             : 
    1218             : /*
    1219             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1220             :  * for backwards compatibility).  Note: the only option required by SQL99
    1221             :  * is "WITH ADMIN name".
    1222             :  */
    1223             : OptRoleList:
    1224        1160 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1225        1828 :             | /* EMPTY */                           { $$ = NIL; }
    1226             :         ;
    1227             : 
    1228             : AlterOptRoleList:
    1229         658 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1230         418 :             | /* EMPTY */                           { $$ = NIL; }
    1231             :         ;
    1232             : 
    1233             : AlterOptRoleElem:
    1234             :             PASSWORD Sconst
    1235             :                 {
    1236         188 :                     $$ = makeDefElem("password",
    1237         188 :                                      (Node *) makeString($2), @1);
    1238             :                 }
    1239             :             | PASSWORD NULL_P
    1240             :                 {
    1241          12 :                     $$ = makeDefElem("password", NULL, @1);
    1242             :                 }
    1243             :             | ENCRYPTED PASSWORD Sconst
    1244             :                 {
    1245             :                     /*
    1246             :                      * These days, passwords are always stored in encrypted
    1247             :                      * form, so there is no difference between PASSWORD and
    1248             :                      * ENCRYPTED PASSWORD.
    1249             :                      */
    1250          16 :                     $$ = makeDefElem("password",
    1251          16 :                                      (Node *) makeString($3), @1);
    1252             :                 }
    1253             :             | UNENCRYPTED PASSWORD Sconst
    1254             :                 {
    1255           0 :                     ereport(ERROR,
    1256             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1257             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1258             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1259             :                              parser_errposition(@1)));
    1260             :                 }
    1261             :             | INHERIT
    1262             :                 {
    1263          92 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1264             :                 }
    1265             :             | CONNECTION LIMIT SignedIconst
    1266             :                 {
    1267          24 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1268             :                 }
    1269             :             | VALID UNTIL Sconst
    1270             :                 {
    1271           2 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1272             :                 }
    1273             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1274             :             | USER role_list
    1275             :                 {
    1276           6 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1277             :                 }
    1278             :             | IDENT
    1279             :                 {
    1280             :                     /*
    1281             :                      * We handle identifiers that aren't parser keywords with
    1282             :                      * the following special-case codes, to avoid bloating the
    1283             :                      * size of the main parser.
    1284             :                      */
    1285        1330 :                     if (strcmp($1, "superuser") == 0)
    1286         192 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1287        1138 :                     else if (strcmp($1, "nosuperuser") == 0)
    1288          96 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1289        1042 :                     else if (strcmp($1, "createrole") == 0)
    1290         102 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1291         940 :                     else if (strcmp($1, "nocreaterole") == 0)
    1292          34 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1293         906 :                     else if (strcmp($1, "replication") == 0)
    1294         130 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1295         776 :                     else if (strcmp($1, "noreplication") == 0)
    1296          92 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1297         684 :                     else if (strcmp($1, "createdb") == 0)
    1298          92 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1299         592 :                     else if (strcmp($1, "nocreatedb") == 0)
    1300          42 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1301         550 :                     else if (strcmp($1, "login") == 0)
    1302         282 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1303         268 :                     else if (strcmp($1, "nologin") == 0)
    1304          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1305         182 :                     else if (strcmp($1, "bypassrls") == 0)
    1306          82 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1307         100 :                     else if (strcmp($1, "nobypassrls") == 0)
    1308          64 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1309          36 :                     else if (strcmp($1, "noinherit") == 0)
    1310             :                     {
    1311             :                         /*
    1312             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1313             :                          * NOINHERIT is handled here.
    1314             :                          */
    1315          36 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1316             :                     }
    1317             :                     else
    1318           0 :                         ereport(ERROR,
    1319             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1320             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1321             :                                      parser_errposition(@1)));
    1322             :                 }
    1323             :         ;
    1324             : 
    1325             : CreateOptRoleElem:
    1326        1012 :             AlterOptRoleElem            { $$ = $1; }
    1327             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1328             :             | SYSID Iconst
    1329             :                 {
    1330           6 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1331             :                 }
    1332             :             | ADMIN role_list
    1333             :                 {
    1334          22 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1335             :                 }
    1336             :             | ROLE role_list
    1337             :                 {
    1338          22 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1339             :                 }
    1340             :             | IN_P ROLE role_list
    1341             :                 {
    1342          98 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1343             :                 }
    1344             :             | IN_P GROUP_P role_list
    1345             :                 {
    1346           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1347             :                 }
    1348             :         ;
    1349             : 
    1350             : 
    1351             : /*****************************************************************************
    1352             :  *
    1353             :  * Create a new Postgres DBMS user (role with implied login ability)
    1354             :  *
    1355             :  *****************************************************************************/
    1356             : 
    1357             : CreateUserStmt:
    1358             :             CREATE USER RoleId opt_with OptRoleList
    1359             :                 {
    1360         456 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1361             : 
    1362         456 :                     n->stmt_type = ROLESTMT_USER;
    1363         456 :                     n->role = $3;
    1364         456 :                     n->options = $5;
    1365         456 :                     $$ = (Node *) n;
    1366             :                 }
    1367             :         ;
    1368             : 
    1369             : 
    1370             : /*****************************************************************************
    1371             :  *
    1372             :  * Alter a postgresql DBMS role
    1373             :  *
    1374             :  *****************************************************************************/
    1375             : 
    1376             : AlterRoleStmt:
    1377             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1378             :                  {
    1379         326 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1380             : 
    1381         326 :                     n->role = $3;
    1382         326 :                     n->action = +1;  /* add, if there are members */
    1383         326 :                     n->options = $5;
    1384         326 :                     $$ = (Node *) n;
    1385             :                  }
    1386             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1387             :                  {
    1388          92 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1389             : 
    1390          92 :                     n->role = $3;
    1391          92 :                     n->action = +1;  /* add, if there are members */
    1392          92 :                     n->options = $5;
    1393          92 :                     $$ = (Node *) n;
    1394             :                  }
    1395             :         ;
    1396             : 
    1397             : opt_in_database:
    1398          92 :                /* EMPTY */                  { $$ = NULL; }
    1399           4 :             | IN_P DATABASE name    { $$ = $3; }
    1400             :         ;
    1401             : 
    1402             : AlterRoleSetStmt:
    1403             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1404             :                 {
    1405          58 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1406             : 
    1407          58 :                     n->role = $3;
    1408          58 :                     n->database = $4;
    1409          58 :                     n->setstmt = $5;
    1410          58 :                     $$ = (Node *) n;
    1411             :                 }
    1412             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1413             :                 {
    1414           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1415             : 
    1416           4 :                     n->role = NULL;
    1417           4 :                     n->database = $4;
    1418           4 :                     n->setstmt = $5;
    1419           4 :                     $$ = (Node *) n;
    1420             :                 }
    1421             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1422             :                 {
    1423          26 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1424             : 
    1425          26 :                     n->role = $3;
    1426          26 :                     n->database = $4;
    1427          26 :                     n->setstmt = $5;
    1428          26 :                     $$ = (Node *) n;
    1429             :                 }
    1430             :             | ALTER USER ALL opt_in_database SetResetClause
    1431             :                 {
    1432           4 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1433             : 
    1434           4 :                     n->role = NULL;
    1435           4 :                     n->database = $4;
    1436           4 :                     n->setstmt = $5;
    1437           4 :                     $$ = (Node *) n;
    1438             :                 }
    1439             :         ;
    1440             : 
    1441             : 
    1442             : /*****************************************************************************
    1443             :  *
    1444             :  * Drop a postgresql DBMS role
    1445             :  *
    1446             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1447             :  * might own objects in multiple databases, and there is presently no way to
    1448             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1449             :  *****************************************************************************/
    1450             : 
    1451             : DropRoleStmt:
    1452             :             DROP ROLE role_list
    1453             :                 {
    1454        1106 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1455             : 
    1456        1106 :                     n->missing_ok = false;
    1457        1106 :                     n->roles = $3;
    1458        1106 :                     $$ = (Node *) n;
    1459             :                 }
    1460             :             | DROP ROLE IF_P EXISTS role_list
    1461             :                 {
    1462         134 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1463             : 
    1464         134 :                     n->missing_ok = true;
    1465         134 :                     n->roles = $5;
    1466         134 :                     $$ = (Node *) n;
    1467             :                 }
    1468             :             | DROP USER role_list
    1469             :                 {
    1470         404 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1471             : 
    1472         404 :                     n->missing_ok = false;
    1473         404 :                     n->roles = $3;
    1474         404 :                     $$ = (Node *) n;
    1475             :                 }
    1476             :             | DROP USER IF_P EXISTS role_list
    1477             :                 {
    1478          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1479             : 
    1480          36 :                     n->roles = $5;
    1481          36 :                     n->missing_ok = true;
    1482          36 :                     $$ = (Node *) n;
    1483             :                 }
    1484             :             | DROP GROUP_P role_list
    1485             :                 {
    1486          36 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1487             : 
    1488          36 :                     n->missing_ok = false;
    1489          36 :                     n->roles = $3;
    1490          36 :                     $$ = (Node *) n;
    1491             :                 }
    1492             :             | DROP GROUP_P IF_P EXISTS role_list
    1493             :                 {
    1494           6 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1495             : 
    1496           6 :                     n->missing_ok = true;
    1497           6 :                     n->roles = $5;
    1498           6 :                     $$ = (Node *) n;
    1499             :                 }
    1500             :             ;
    1501             : 
    1502             : 
    1503             : /*****************************************************************************
    1504             :  *
    1505             :  * Create a postgresql group (role without login ability)
    1506             :  *
    1507             :  *****************************************************************************/
    1508             : 
    1509             : CreateGroupStmt:
    1510             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1511             :                 {
    1512          24 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1513             : 
    1514          24 :                     n->stmt_type = ROLESTMT_GROUP;
    1515          24 :                     n->role = $3;
    1516          24 :                     n->options = $5;
    1517          24 :                     $$ = (Node *) n;
    1518             :                 }
    1519             :         ;
    1520             : 
    1521             : 
    1522             : /*****************************************************************************
    1523             :  *
    1524             :  * Alter a postgresql group
    1525             :  *
    1526             :  *****************************************************************************/
    1527             : 
    1528             : AlterGroupStmt:
    1529             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1530             :                 {
    1531          42 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1532             : 
    1533          42 :                     n->role = $3;
    1534          42 :                     n->action = $4;
    1535          42 :                     n->options = list_make1(makeDefElem("rolemembers",
    1536             :                                                         (Node *) $6, @6));
    1537          42 :                     $$ = (Node *) n;
    1538             :                 }
    1539             :         ;
    1540             : 
    1541          86 : add_drop:   ADD_P                                   { $$ = +1; }
    1542         222 :             | DROP                                  { $$ = -1; }
    1543             :         ;
    1544             : 
    1545             : 
    1546             : /*****************************************************************************
    1547             :  *
    1548             :  * Manipulate a schema
    1549             :  *
    1550             :  *****************************************************************************/
    1551             : 
    1552             : CreateSchemaStmt:
    1553             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1554             :                 {
    1555         158 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1556             : 
    1557             :                     /* One can omit the schema name or the authorization id. */
    1558         158 :                     n->schemaname = $3;
    1559         158 :                     n->authrole = $5;
    1560         158 :                     n->schemaElts = $6;
    1561         158 :                     n->if_not_exists = false;
    1562         158 :                     $$ = (Node *) n;
    1563             :                 }
    1564             :             | CREATE SCHEMA ColId OptSchemaEltList
    1565             :                 {
    1566         874 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1567             : 
    1568             :                     /* ...but not both */
    1569         874 :                     n->schemaname = $3;
    1570         874 :                     n->authrole = NULL;
    1571         874 :                     n->schemaElts = $4;
    1572         874 :                     n->if_not_exists = false;
    1573         874 :                     $$ = (Node *) n;
    1574             :                 }
    1575             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1576             :                 {
    1577          18 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1578             : 
    1579             :                     /* schema name can be omitted here, too */
    1580          18 :                     n->schemaname = $6;
    1581          18 :                     n->authrole = $8;
    1582          18 :                     if ($9 != NIL)
    1583           0 :                         ereport(ERROR,
    1584             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1585             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1586             :                                  parser_errposition(@9)));
    1587          18 :                     n->schemaElts = $9;
    1588          18 :                     n->if_not_exists = true;
    1589          18 :                     $$ = (Node *) n;
    1590             :                 }
    1591             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1592             :                 {
    1593          34 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1594             : 
    1595             :                     /* ...but not here */
    1596          34 :                     n->schemaname = $6;
    1597          34 :                     n->authrole = NULL;
    1598          34 :                     if ($7 != NIL)
    1599           6 :                         ereport(ERROR,
    1600             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1601             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1602             :                                  parser_errposition(@7)));
    1603          28 :                     n->schemaElts = $7;
    1604          28 :                     n->if_not_exists = true;
    1605          28 :                     $$ = (Node *) n;
    1606             :                 }
    1607             :         ;
    1608             : 
    1609             : OptSchemaEltList:
    1610             :             OptSchemaEltList schema_stmt
    1611             :                 {
    1612         564 :                     $$ = lappend($1, $2);
    1613             :                 }
    1614             :             | /* EMPTY */
    1615        1084 :                 { $$ = NIL; }
    1616             :         ;
    1617             : 
    1618             : /*
    1619             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1620             :  *  statement (in addition to by themselves).
    1621             :  */
    1622             : schema_stmt:
    1623             :             CreateStmt
    1624             :             | IndexStmt
    1625             :             | CreateSeqStmt
    1626             :             | CreateTrigStmt
    1627             :             | GrantStmt
    1628             :             | ViewStmt
    1629             :         ;
    1630             : 
    1631             : 
    1632             : /*****************************************************************************
    1633             :  *
    1634             :  * Set PG internal variable
    1635             :  *    SET name TO 'var_value'
    1636             :  * Include SQL syntax (thomas 1997-10-22):
    1637             :  *    SET TIME ZONE 'var_value'
    1638             :  *
    1639             :  *****************************************************************************/
    1640             : 
    1641             : VariableSetStmt:
    1642             :             SET set_rest
    1643             :                 {
    1644       21552 :                     VariableSetStmt *n = $2;
    1645             : 
    1646       21552 :                     n->is_local = false;
    1647       21552 :                     $$ = (Node *) n;
    1648             :                 }
    1649             :             | SET LOCAL set_rest
    1650             :                 {
    1651        1236 :                     VariableSetStmt *n = $3;
    1652             : 
    1653        1236 :                     n->is_local = true;
    1654        1236 :                     $$ = (Node *) n;
    1655             :                 }
    1656             :             | SET SESSION set_rest
    1657             :                 {
    1658          84 :                     VariableSetStmt *n = $3;
    1659             : 
    1660          84 :                     n->is_local = false;
    1661          84 :                     $$ = (Node *) n;
    1662             :                 }
    1663             :         ;
    1664             : 
    1665             : set_rest:
    1666             :             TRANSACTION transaction_mode_list
    1667             :                 {
    1668         576 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1669             : 
    1670         576 :                     n->kind = VAR_SET_MULTI;
    1671         576 :                     n->name = "TRANSACTION";
    1672         576 :                     n->args = $2;
    1673         576 :                     n->jumble_args = true;
    1674         576 :                     n->location = -1;
    1675         576 :                     $$ = n;
    1676             :                 }
    1677             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1678             :                 {
    1679          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1680             : 
    1681          18 :                     n->kind = VAR_SET_MULTI;
    1682          18 :                     n->name = "SESSION CHARACTERISTICS";
    1683          18 :                     n->args = $5;
    1684          18 :                     n->jumble_args = true;
    1685          18 :                     n->location = -1;
    1686          18 :                     $$ = n;
    1687             :                 }
    1688             :             | set_rest_more
    1689             :             ;
    1690             : 
    1691             : generic_set:
    1692             :             var_name TO var_list
    1693             :                 {
    1694        5084 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1695             : 
    1696        5084 :                     n->kind = VAR_SET_VALUE;
    1697        5084 :                     n->name = $1;
    1698        5084 :                     n->args = $3;
    1699        5084 :                     n->location = @3;
    1700        5084 :                     $$ = n;
    1701             :                 }
    1702             :             | var_name '=' var_list
    1703             :                 {
    1704       14844 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1705             : 
    1706       14844 :                     n->kind = VAR_SET_VALUE;
    1707       14844 :                     n->name = $1;
    1708       14844 :                     n->args = $3;
    1709       14844 :                     n->location = @3;
    1710       14844 :                     $$ = n;
    1711             :                 }
    1712             :             | var_name TO DEFAULT
    1713             :                 {
    1714         136 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1715             : 
    1716         136 :                     n->kind = VAR_SET_DEFAULT;
    1717         136 :                     n->name = $1;
    1718         136 :                     n->location = -1;
    1719         136 :                     $$ = n;
    1720             :                 }
    1721             :             | var_name '=' DEFAULT
    1722             :                 {
    1723          10 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1724             : 
    1725          10 :                     n->kind = VAR_SET_DEFAULT;
    1726          10 :                     n->name = $1;
    1727          10 :                     n->location = -1;
    1728          10 :                     $$ = n;
    1729             :                 }
    1730             :         ;
    1731             : 
    1732             : set_rest_more:  /* Generic SET syntaxes: */
    1733       19946 :             generic_set                         {$$ = $1;}
    1734             :             | var_name FROM CURRENT_P
    1735             :                 {
    1736           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1737             : 
    1738           4 :                     n->kind = VAR_SET_CURRENT;
    1739           4 :                     n->name = $1;
    1740           4 :                     n->location = -1;
    1741           4 :                     $$ = n;
    1742             :                 }
    1743             :             /* Special syntaxes mandated by SQL standard: */
    1744             :             | TIME ZONE zone_value
    1745             :                 {
    1746         104 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1747             : 
    1748         104 :                     n->kind = VAR_SET_VALUE;
    1749         104 :                     n->name = "timezone";
    1750         104 :                     n->location = -1;
    1751         104 :                     n->jumble_args = true;
    1752         104 :                     if ($3 != NULL)
    1753          88 :                         n->args = list_make1($3);
    1754             :                     else
    1755          16 :                         n->kind = VAR_SET_DEFAULT;
    1756         104 :                     $$ = n;
    1757             :                 }
    1758             :             | CATALOG_P Sconst
    1759             :                 {
    1760           0 :                     ereport(ERROR,
    1761             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1762             :                              errmsg("current database cannot be changed"),
    1763             :                              parser_errposition(@2)));
    1764             :                     $$ = NULL; /*not reached*/
    1765             :                 }
    1766             :             | SCHEMA Sconst
    1767             :                 {
    1768           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1769             : 
    1770           4 :                     n->kind = VAR_SET_VALUE;
    1771           4 :                     n->name = "search_path";
    1772           4 :                     n->args = list_make1(makeStringConst($2, @2));
    1773           4 :                     n->location = @2;
    1774           4 :                     $$ = n;
    1775             :                 }
    1776             :             | NAMES opt_encoding
    1777             :                 {
    1778           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1779             : 
    1780           0 :                     n->kind = VAR_SET_VALUE;
    1781           0 :                     n->name = "client_encoding";
    1782           0 :                     n->location = @2;
    1783           0 :                     if ($2 != NULL)
    1784           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1785             :                     else
    1786           0 :                         n->kind = VAR_SET_DEFAULT;
    1787           0 :                     $$ = n;
    1788             :                 }
    1789             :             | ROLE NonReservedWord_or_Sconst
    1790             :                 {
    1791         960 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1792             : 
    1793         960 :                     n->kind = VAR_SET_VALUE;
    1794         960 :                     n->name = "role";
    1795         960 :                     n->args = list_make1(makeStringConst($2, @2));
    1796         960 :                     n->location = @2;
    1797         960 :                     $$ = n;
    1798             :                 }
    1799             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1800             :                 {
    1801        2586 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1802             : 
    1803        2586 :                     n->kind = VAR_SET_VALUE;
    1804        2586 :                     n->name = "session_authorization";
    1805        2586 :                     n->args = list_make1(makeStringConst($3, @3));
    1806        2586 :                     n->location = @3;
    1807        2586 :                     $$ = n;
    1808             :                 }
    1809             :             | SESSION AUTHORIZATION DEFAULT
    1810             :                 {
    1811           4 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1812             : 
    1813           4 :                     n->kind = VAR_SET_DEFAULT;
    1814           4 :                     n->name = "session_authorization";
    1815           4 :                     n->location = -1;
    1816           4 :                     $$ = n;
    1817             :                 }
    1818             :             | XML_P OPTION document_or_content
    1819             :                 {
    1820          16 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1821             : 
    1822          16 :                     n->kind = VAR_SET_VALUE;
    1823          16 :                     n->name = "xmloption";
    1824          16 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1825          16 :                     n->jumble_args = true;
    1826          16 :                     n->location = -1;
    1827          16 :                     $$ = n;
    1828             :                 }
    1829             :             /* Special syntaxes invented by PostgreSQL: */
    1830             :             | TRANSACTION SNAPSHOT Sconst
    1831             :                 {
    1832          44 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1833             : 
    1834          44 :                     n->kind = VAR_SET_MULTI;
    1835          44 :                     n->name = "TRANSACTION SNAPSHOT";
    1836          44 :                     n->args = list_make1(makeStringConst($3, @3));
    1837          44 :                     n->location = @3;
    1838          44 :                     $$ = n;
    1839             :                 }
    1840             :         ;
    1841             : 
    1842       24784 : var_name:   ColId                               { $$ = $1; }
    1843             :             | var_name '.' ColId
    1844         496 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1845             :         ;
    1846             : 
    1847       19928 : var_list:   var_value                               { $$ = list_make1($1); }
    1848         182 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1849             :         ;
    1850             : 
    1851             : var_value:  opt_boolean_or_string
    1852       14874 :                 { $$ = makeStringConst($1, @1); }
    1853             :             | NumericOnly
    1854        5236 :                 { $$ = makeAConst($1, @1); }
    1855             :         ;
    1856             : 
    1857           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1858         932 :             | READ COMMITTED                        { $$ = "read committed"; }
    1859        2602 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1860        3196 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1861             :         ;
    1862             : 
    1863             : opt_boolean_or_string:
    1864         690 :             TRUE_P                                  { $$ = "true"; }
    1865        1486 :             | FALSE_P                               { $$ = "false"; }
    1866        2242 :             | ON                                    { $$ = "on"; }
    1867             :             /*
    1868             :              * OFF is also accepted as a boolean value, but is handled by
    1869             :              * the NonReservedWord rule.  The action for booleans and strings
    1870             :              * is the same, so we don't need to distinguish them here.
    1871             :              */
    1872       30486 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1873             :         ;
    1874             : 
    1875             : /* Timezone values can be:
    1876             :  * - a string such as 'pst8pdt'
    1877             :  * - an identifier such as "pst8pdt"
    1878             :  * - an integer or floating point number
    1879             :  * - a time interval per SQL99
    1880             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1881             :  * so use IDENT (meaning we reject anything that is a key word).
    1882             :  */
    1883             : zone_value:
    1884             :             Sconst
    1885             :                 {
    1886          60 :                     $$ = makeStringConst($1, @1);
    1887             :                 }
    1888             :             | IDENT
    1889             :                 {
    1890           4 :                     $$ = makeStringConst($1, @1);
    1891             :                 }
    1892             :             | ConstInterval Sconst opt_interval
    1893             :                 {
    1894           0 :                     TypeName   *t = $1;
    1895             : 
    1896           0 :                     if ($3 != NIL)
    1897             :                     {
    1898           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1899             : 
    1900           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1901           0 :                             ereport(ERROR,
    1902             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1903             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1904             :                                      parser_errposition(@3)));
    1905             :                     }
    1906           0 :                     t->typmods = $3;
    1907           0 :                     $$ = makeStringConstCast($2, @2, t);
    1908             :                 }
    1909             :             | ConstInterval '(' Iconst ')' Sconst
    1910             :                 {
    1911           0 :                     TypeName   *t = $1;
    1912             : 
    1913           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1914             :                                             makeIntConst($3, @3));
    1915           0 :                     $$ = makeStringConstCast($5, @5, t);
    1916             :                 }
    1917          24 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1918          14 :             | DEFAULT                               { $$ = NULL; }
    1919           2 :             | LOCAL                                 { $$ = NULL; }
    1920             :         ;
    1921             : 
    1922             : opt_encoding:
    1923           0 :             Sconst                                  { $$ = $1; }
    1924           0 :             | DEFAULT                               { $$ = NULL; }
    1925           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1926             :         ;
    1927             : 
    1928             : NonReservedWord_or_Sconst:
    1929       54048 :             NonReservedWord                         { $$ = $1; }
    1930        5568 :             | Sconst                                { $$ = $1; }
    1931             :         ;
    1932             : 
    1933             : VariableResetStmt:
    1934        4618 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1935             :         ;
    1936             : 
    1937             : reset_rest:
    1938        3814 :             generic_reset                           { $$ = $1; }
    1939             :             | TIME ZONE
    1940             :                 {
    1941          14 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1942             : 
    1943          14 :                     n->kind = VAR_RESET;
    1944          14 :                     n->name = "timezone";
    1945          14 :                     n->location = -1;
    1946          14 :                     $$ = n;
    1947             :                 }
    1948             :             | TRANSACTION ISOLATION LEVEL
    1949             :                 {
    1950           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1951             : 
    1952           0 :                     n->kind = VAR_RESET;
    1953           0 :                     n->name = "transaction_isolation";
    1954           0 :                     n->location = -1;
    1955           0 :                     $$ = n;
    1956             :                 }
    1957             :             | SESSION AUTHORIZATION
    1958             :                 {
    1959         790 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1960             : 
    1961         790 :                     n->kind = VAR_RESET;
    1962         790 :                     n->name = "session_authorization";
    1963         790 :                     n->location = -1;
    1964         790 :                     $$ = n;
    1965             :                 }
    1966             :         ;
    1967             : 
    1968             : generic_reset:
    1969             :             var_name
    1970             :                 {
    1971        3842 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1972             : 
    1973        3842 :                     n->kind = VAR_RESET;
    1974        3842 :                     n->name = $1;
    1975        3842 :                     n->location = -1;
    1976        3842 :                     $$ = n;
    1977             :                 }
    1978             :             | ALL
    1979             :                 {
    1980          28 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1981             : 
    1982          28 :                     n->kind = VAR_RESET_ALL;
    1983          28 :                     n->location = -1;
    1984          28 :                     $$ = n;
    1985             :                 }
    1986             :         ;
    1987             : 
    1988             : /* SetResetClause allows SET or RESET without LOCAL */
    1989             : SetResetClause:
    1990        1256 :             SET set_rest                    { $$ = $2; }
    1991          50 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1992             :         ;
    1993             : 
    1994             : /* SetResetClause allows SET or RESET without LOCAL */
    1995             : FunctionSetResetClause:
    1996         134 :             SET set_rest_more               { $$ = $2; }
    1997          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1998             :         ;
    1999             : 
    2000             : 
    2001             : VariableShowStmt:
    2002             :             SHOW var_name
    2003             :                 {
    2004         864 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2005             : 
    2006         864 :                     n->name = $2;
    2007         864 :                     $$ = (Node *) n;
    2008             :                 }
    2009             :             | SHOW TIME ZONE
    2010             :                 {
    2011          10 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2012             : 
    2013          10 :                     n->name = "timezone";
    2014          10 :                     $$ = (Node *) n;
    2015             :                 }
    2016             :             | SHOW TRANSACTION ISOLATION LEVEL
    2017             :                 {
    2018           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2019             : 
    2020           4 :                     n->name = "transaction_isolation";
    2021           4 :                     $$ = (Node *) n;
    2022             :                 }
    2023             :             | SHOW SESSION AUTHORIZATION
    2024             :                 {
    2025           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2026             : 
    2027           0 :                     n->name = "session_authorization";
    2028           0 :                     $$ = (Node *) n;
    2029             :                 }
    2030             :             | SHOW ALL
    2031             :                 {
    2032           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2033             : 
    2034           0 :                     n->name = "all";
    2035           0 :                     $$ = (Node *) n;
    2036             :                 }
    2037             :         ;
    2038             : 
    2039             : 
    2040             : ConstraintsSetStmt:
    2041             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    2042             :                 {
    2043         104 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2044             : 
    2045         104 :                     n->constraints = $3;
    2046         104 :                     n->deferred = $4;
    2047         104 :                     $$ = (Node *) n;
    2048             :                 }
    2049             :         ;
    2050             : 
    2051             : constraints_set_list:
    2052          56 :             ALL                                     { $$ = NIL; }
    2053          48 :             | qualified_name_list                   { $$ = $1; }
    2054             :         ;
    2055             : 
    2056             : constraints_set_mode:
    2057          68 :             DEFERRED                                { $$ = true; }
    2058          36 :             | IMMEDIATE                             { $$ = false; }
    2059             :         ;
    2060             : 
    2061             : 
    2062             : /*
    2063             :  * Checkpoint statement
    2064             :  */
    2065             : CheckPointStmt:
    2066             :             CHECKPOINT opt_utility_option_list
    2067             :                 {
    2068         240 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2069             : 
    2070         240 :                     $$ = (Node *) n;
    2071         240 :                     n->options = $2;
    2072             :                 }
    2073             :         ;
    2074             : 
    2075             : 
    2076             : /*****************************************************************************
    2077             :  *
    2078             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2079             :  *
    2080             :  *****************************************************************************/
    2081             : 
    2082             : DiscardStmt:
    2083             :             DISCARD ALL
    2084             :                 {
    2085           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2086             : 
    2087           6 :                     n->target = DISCARD_ALL;
    2088           6 :                     $$ = (Node *) n;
    2089             :                 }
    2090             :             | DISCARD TEMP
    2091             :                 {
    2092           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2093             : 
    2094           8 :                     n->target = DISCARD_TEMP;
    2095           8 :                     $$ = (Node *) n;
    2096             :                 }
    2097             :             | DISCARD TEMPORARY
    2098             :                 {
    2099           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2100             : 
    2101           0 :                     n->target = DISCARD_TEMP;
    2102           0 :                     $$ = (Node *) n;
    2103             :                 }
    2104             :             | DISCARD PLANS
    2105             :                 {
    2106           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2107             : 
    2108           4 :                     n->target = DISCARD_PLANS;
    2109           4 :                     $$ = (Node *) n;
    2110             :                 }
    2111             :             | DISCARD SEQUENCES
    2112             :                 {
    2113          12 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2114             : 
    2115          12 :                     n->target = DISCARD_SEQUENCES;
    2116          12 :                     $$ = (Node *) n;
    2117             :                 }
    2118             : 
    2119             :         ;
    2120             : 
    2121             : 
    2122             : /*****************************************************************************
    2123             :  *
    2124             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2125             :  *
    2126             :  * Note: we accept all subcommands for each of the variants, and sort
    2127             :  * out what's really legal at execution time.
    2128             :  *****************************************************************************/
    2129             : 
    2130             : AlterTableStmt:
    2131             :             ALTER TABLE relation_expr alter_table_cmds
    2132             :                 {
    2133       26330 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2134             : 
    2135       26330 :                     n->relation = $3;
    2136       26330 :                     n->cmds = $4;
    2137       26330 :                     n->objtype = OBJECT_TABLE;
    2138       26330 :                     n->missing_ok = false;
    2139       26330 :                     $$ = (Node *) n;
    2140             :                 }
    2141             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2142             :                 {
    2143          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2144             : 
    2145          54 :                     n->relation = $5;
    2146          54 :                     n->cmds = $6;
    2147          54 :                     n->objtype = OBJECT_TABLE;
    2148          54 :                     n->missing_ok = true;
    2149          54 :                     $$ = (Node *) n;
    2150             :                 }
    2151             :         |   ALTER TABLE relation_expr partition_cmd
    2152             :                 {
    2153        3052 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2154             : 
    2155        3052 :                     n->relation = $3;
    2156        3052 :                     n->cmds = list_make1($4);
    2157        3052 :                     n->objtype = OBJECT_TABLE;
    2158        3052 :                     n->missing_ok = false;
    2159        3052 :                     $$ = (Node *) n;
    2160             :                 }
    2161             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2162             :                 {
    2163           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2164             : 
    2165           0 :                     n->relation = $5;
    2166           0 :                     n->cmds = list_make1($6);
    2167           0 :                     n->objtype = OBJECT_TABLE;
    2168           0 :                     n->missing_ok = true;
    2169           0 :                     $$ = (Node *) n;
    2170             :                 }
    2171             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2172             :                 {
    2173             :                     AlterTableMoveAllStmt *n =
    2174          12 :                         makeNode(AlterTableMoveAllStmt);
    2175             : 
    2176          12 :                     n->orig_tablespacename = $6;
    2177          12 :                     n->objtype = OBJECT_TABLE;
    2178          12 :                     n->roles = NIL;
    2179          12 :                     n->new_tablespacename = $9;
    2180          12 :                     n->nowait = $10;
    2181          12 :                     $$ = (Node *) n;
    2182             :                 }
    2183             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2184             :                 {
    2185             :                     AlterTableMoveAllStmt *n =
    2186           0 :                         makeNode(AlterTableMoveAllStmt);
    2187             : 
    2188           0 :                     n->orig_tablespacename = $6;
    2189           0 :                     n->objtype = OBJECT_TABLE;
    2190           0 :                     n->roles = $9;
    2191           0 :                     n->new_tablespacename = $12;
    2192           0 :                     n->nowait = $13;
    2193           0 :                     $$ = (Node *) n;
    2194             :                 }
    2195             :         |   ALTER INDEX qualified_name alter_table_cmds
    2196             :                 {
    2197         228 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2198             : 
    2199         228 :                     n->relation = $3;
    2200         228 :                     n->cmds = $4;
    2201         228 :                     n->objtype = OBJECT_INDEX;
    2202         228 :                     n->missing_ok = false;
    2203         228 :                     $$ = (Node *) n;
    2204             :                 }
    2205             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2206             :                 {
    2207           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2208             : 
    2209           0 :                     n->relation = $5;
    2210           0 :                     n->cmds = $6;
    2211           0 :                     n->objtype = OBJECT_INDEX;
    2212           0 :                     n->missing_ok = true;
    2213           0 :                     $$ = (Node *) n;
    2214             :                 }
    2215             :         |   ALTER INDEX qualified_name index_partition_cmd
    2216             :                 {
    2217         386 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2218             : 
    2219         386 :                     n->relation = $3;
    2220         386 :                     n->cmds = list_make1($4);
    2221         386 :                     n->objtype = OBJECT_INDEX;
    2222         386 :                     n->missing_ok = false;
    2223         386 :                     $$ = (Node *) n;
    2224             :                 }
    2225             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2226             :                 {
    2227             :                     AlterTableMoveAllStmt *n =
    2228           6 :                         makeNode(AlterTableMoveAllStmt);
    2229             : 
    2230           6 :                     n->orig_tablespacename = $6;
    2231           6 :                     n->objtype = OBJECT_INDEX;
    2232           6 :                     n->roles = NIL;
    2233           6 :                     n->new_tablespacename = $9;
    2234           6 :                     n->nowait = $10;
    2235           6 :                     $$ = (Node *) n;
    2236             :                 }
    2237             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2238             :                 {
    2239             :                     AlterTableMoveAllStmt *n =
    2240           0 :                         makeNode(AlterTableMoveAllStmt);
    2241             : 
    2242           0 :                     n->orig_tablespacename = $6;
    2243           0 :                     n->objtype = OBJECT_INDEX;
    2244           0 :                     n->roles = $9;
    2245           0 :                     n->new_tablespacename = $12;
    2246           0 :                     n->nowait = $13;
    2247           0 :                     $$ = (Node *) n;
    2248             :                 }
    2249             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2250             :                 {
    2251          94 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2252             : 
    2253          94 :                     n->relation = $3;
    2254          94 :                     n->cmds = $4;
    2255          94 :                     n->objtype = OBJECT_SEQUENCE;
    2256          94 :                     n->missing_ok = false;
    2257          94 :                     $$ = (Node *) n;
    2258             :                 }
    2259             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2260             :                 {
    2261           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2262             : 
    2263           0 :                     n->relation = $5;
    2264           0 :                     n->cmds = $6;
    2265           0 :                     n->objtype = OBJECT_SEQUENCE;
    2266           0 :                     n->missing_ok = true;
    2267           0 :                     $$ = (Node *) n;
    2268             :                 }
    2269             :         |   ALTER VIEW qualified_name alter_table_cmds
    2270             :                 {
    2271         254 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2272             : 
    2273         254 :                     n->relation = $3;
    2274         254 :                     n->cmds = $4;
    2275         254 :                     n->objtype = OBJECT_VIEW;
    2276         254 :                     n->missing_ok = false;
    2277         254 :                     $$ = (Node *) n;
    2278             :                 }
    2279             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2280             :                 {
    2281           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2282             : 
    2283           0 :                     n->relation = $5;
    2284           0 :                     n->cmds = $6;
    2285           0 :                     n->objtype = OBJECT_VIEW;
    2286           0 :                     n->missing_ok = true;
    2287           0 :                     $$ = (Node *) n;
    2288             :                 }
    2289             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2290             :                 {
    2291          48 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2292             : 
    2293          48 :                     n->relation = $4;
    2294          48 :                     n->cmds = $5;
    2295          48 :                     n->objtype = OBJECT_MATVIEW;
    2296          48 :                     n->missing_ok = false;
    2297          48 :                     $$ = (Node *) n;
    2298             :                 }
    2299             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2300             :                 {
    2301           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2302             : 
    2303           0 :                     n->relation = $6;
    2304           0 :                     n->cmds = $7;
    2305           0 :                     n->objtype = OBJECT_MATVIEW;
    2306           0 :                     n->missing_ok = true;
    2307           0 :                     $$ = (Node *) n;
    2308             :                 }
    2309             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2310             :                 {
    2311             :                     AlterTableMoveAllStmt *n =
    2312          12 :                         makeNode(AlterTableMoveAllStmt);
    2313             : 
    2314          12 :                     n->orig_tablespacename = $7;
    2315          12 :                     n->objtype = OBJECT_MATVIEW;
    2316          12 :                     n->roles = NIL;
    2317          12 :                     n->new_tablespacename = $10;
    2318          12 :                     n->nowait = $11;
    2319          12 :                     $$ = (Node *) n;
    2320             :                 }
    2321             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2322             :                 {
    2323             :                     AlterTableMoveAllStmt *n =
    2324           0 :                         makeNode(AlterTableMoveAllStmt);
    2325             : 
    2326           0 :                     n->orig_tablespacename = $7;
    2327           0 :                     n->objtype = OBJECT_MATVIEW;
    2328           0 :                     n->roles = $10;
    2329           0 :                     n->new_tablespacename = $13;
    2330           0 :                     n->nowait = $14;
    2331           0 :                     $$ = (Node *) n;
    2332             :                 }
    2333             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2334             :                 {
    2335         378 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2336             : 
    2337         378 :                     n->relation = $4;
    2338         378 :                     n->cmds = $5;
    2339         378 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2340         378 :                     n->missing_ok = false;
    2341         378 :                     $$ = (Node *) n;
    2342             :                 }
    2343             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2344             :                 {
    2345         108 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2346             : 
    2347         108 :                     n->relation = $6;
    2348         108 :                     n->cmds = $7;
    2349         108 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2350         108 :                     n->missing_ok = true;
    2351         108 :                     $$ = (Node *) n;
    2352             :                 }
    2353             :         ;
    2354             : 
    2355             : alter_table_cmds:
    2356       27494 :             alter_table_cmd                         { $$ = list_make1($1); }
    2357        1020 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2358             :         ;
    2359             : 
    2360             : partition_cmd:
    2361             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2362             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2363             :                 {
    2364        2430 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2365        2430 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2366             : 
    2367        2430 :                     n->subtype = AT_AttachPartition;
    2368        2430 :                     cmd->name = $3;
    2369        2430 :                     cmd->bound = $4;
    2370        2430 :                     cmd->concurrent = false;
    2371        2430 :                     n->def = (Node *) cmd;
    2372             : 
    2373        2430 :                     $$ = (Node *) n;
    2374             :                 }
    2375             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2376             :             | DETACH PARTITION qualified_name opt_concurrently
    2377             :                 {
    2378         602 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2379         602 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2380             : 
    2381         602 :                     n->subtype = AT_DetachPartition;
    2382         602 :                     cmd->name = $3;
    2383         602 :                     cmd->bound = NULL;
    2384         602 :                     cmd->concurrent = $4;
    2385         602 :                     n->def = (Node *) cmd;
    2386             : 
    2387         602 :                     $$ = (Node *) n;
    2388             :                 }
    2389             :             | DETACH PARTITION qualified_name FINALIZE
    2390             :                 {
    2391          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2392          20 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2393             : 
    2394          20 :                     n->subtype = AT_DetachPartitionFinalize;
    2395          20 :                     cmd->name = $3;
    2396          20 :                     cmd->bound = NULL;
    2397          20 :                     cmd->concurrent = false;
    2398          20 :                     n->def = (Node *) cmd;
    2399          20 :                     $$ = (Node *) n;
    2400             :                 }
    2401             :         ;
    2402             : 
    2403             : index_partition_cmd:
    2404             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2405             :             ATTACH PARTITION qualified_name
    2406             :                 {
    2407         386 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2408         386 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2409             : 
    2410         386 :                     n->subtype = AT_AttachPartition;
    2411         386 :                     cmd->name = $3;
    2412         386 :                     cmd->bound = NULL;
    2413         386 :                     cmd->concurrent = false;
    2414         386 :                     n->def = (Node *) cmd;
    2415             : 
    2416         386 :                     $$ = (Node *) n;
    2417             :                 }
    2418             :         ;
    2419             : 
    2420             : alter_table_cmd:
    2421             :             /* ALTER TABLE <name> ADD <coldef> */
    2422             :             ADD_P columnDef
    2423             :                 {
    2424         192 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2425             : 
    2426         192 :                     n->subtype = AT_AddColumn;
    2427         192 :                     n->def = $2;
    2428         192 :                     n->missing_ok = false;
    2429         192 :                     $$ = (Node *) n;
    2430             :                 }
    2431             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2432             :             | ADD_P IF_P NOT EXISTS columnDef
    2433             :                 {
    2434           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2435             : 
    2436           0 :                     n->subtype = AT_AddColumn;
    2437           0 :                     n->def = $5;
    2438           0 :                     n->missing_ok = true;
    2439           0 :                     $$ = (Node *) n;
    2440             :                 }
    2441             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2442             :             | ADD_P COLUMN columnDef
    2443             :                 {
    2444        1898 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2445             : 
    2446        1898 :                     n->subtype = AT_AddColumn;
    2447        1898 :                     n->def = $3;
    2448        1898 :                     n->missing_ok = false;
    2449        1898 :                     $$ = (Node *) n;
    2450             :                 }
    2451             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2452             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2453             :                 {
    2454          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2455             : 
    2456          60 :                     n->subtype = AT_AddColumn;
    2457          60 :                     n->def = $6;
    2458          60 :                     n->missing_ok = true;
    2459          60 :                     $$ = (Node *) n;
    2460             :                 }
    2461             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2462             :             | ALTER opt_column ColId alter_column_default
    2463             :                 {
    2464         550 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2465             : 
    2466         550 :                     n->subtype = AT_ColumnDefault;
    2467         550 :                     n->name = $3;
    2468         550 :                     n->def = $4;
    2469         550 :                     $$ = (Node *) n;
    2470             :                 }
    2471             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2472             :             | ALTER opt_column ColId DROP NOT NULL_P
    2473             :                 {
    2474         294 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2475             : 
    2476         294 :                     n->subtype = AT_DropNotNull;
    2477         294 :                     n->name = $3;
    2478         294 :                     $$ = (Node *) n;
    2479             :                 }
    2480             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2481             :             | ALTER opt_column ColId SET NOT NULL_P
    2482             :                 {
    2483         434 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2484             : 
    2485         434 :                     n->subtype = AT_SetNotNull;
    2486         434 :                     n->name = $3;
    2487         434 :                     $$ = (Node *) n;
    2488             :                 }
    2489             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2490             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2491             :                 {
    2492         168 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2493             : 
    2494         168 :                     n->subtype = AT_SetExpression;
    2495         168 :                     n->name = $3;
    2496         168 :                     n->def = $8;
    2497         168 :                     $$ = (Node *) n;
    2498             :                 }
    2499             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2500             :             | ALTER opt_column ColId DROP EXPRESSION
    2501             :                 {
    2502          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2503             : 
    2504          62 :                     n->subtype = AT_DropExpression;
    2505          62 :                     n->name = $3;
    2506          62 :                     $$ = (Node *) n;
    2507             :                 }
    2508             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2509             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2510             :                 {
    2511          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2512             : 
    2513          12 :                     n->subtype = AT_DropExpression;
    2514          12 :                     n->name = $3;
    2515          12 :                     n->missing_ok = true;
    2516          12 :                     $$ = (Node *) n;
    2517             :                 }
    2518             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2519             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2520             :                 {
    2521          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2522             : 
    2523          62 :                     n->subtype = AT_SetStatistics;
    2524          62 :                     n->name = $3;
    2525          62 :                     n->def = $6;
    2526          62 :                     $$ = (Node *) n;
    2527             :                 }
    2528             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2529             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2530             :                 {
    2531          70 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2532             : 
    2533          70 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2534           6 :                         ereport(ERROR,
    2535             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2536             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2537             :                                  parser_errposition(@3)));
    2538             : 
    2539          64 :                     n->subtype = AT_SetStatistics;
    2540          64 :                     n->num = (int16) $3;
    2541          64 :                     n->def = $6;
    2542          64 :                     $$ = (Node *) n;
    2543             :                 }
    2544             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2545             :             | ALTER opt_column ColId SET reloptions
    2546             :                 {
    2547          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2548             : 
    2549          38 :                     n->subtype = AT_SetOptions;
    2550          38 :                     n->name = $3;
    2551          38 :                     n->def = (Node *) $5;
    2552          38 :                     $$ = (Node *) n;
    2553             :                 }
    2554             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2555             :             | ALTER opt_column ColId RESET reloptions
    2556             :                 {
    2557           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2558             : 
    2559           6 :                     n->subtype = AT_ResetOptions;
    2560           6 :                     n->name = $3;
    2561           6 :                     n->def = (Node *) $5;
    2562           6 :                     $$ = (Node *) n;
    2563             :                 }
    2564             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2565             :             | ALTER opt_column ColId SET column_storage
    2566             :                 {
    2567         238 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2568             : 
    2569         238 :                     n->subtype = AT_SetStorage;
    2570         238 :                     n->name = $3;
    2571         238 :                     n->def = (Node *) makeString($5);
    2572         238 :                     $$ = (Node *) n;
    2573             :                 }
    2574             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2575             :             | ALTER opt_column ColId SET column_compression
    2576             :                 {
    2577          78 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2578             : 
    2579          78 :                     n->subtype = AT_SetCompression;
    2580          78 :                     n->name = $3;
    2581          78 :                     n->def = (Node *) makeString($5);
    2582          78 :                     $$ = (Node *) n;
    2583             :                 }
    2584             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2585             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2586             :                 {
    2587         166 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2588         166 :                     Constraint *c = makeNode(Constraint);
    2589             : 
    2590         166 :                     c->contype = CONSTR_IDENTITY;
    2591         166 :                     c->generated_when = $6;
    2592         166 :                     c->options = $9;
    2593         166 :                     c->location = @5;
    2594             : 
    2595         166 :                     n->subtype = AT_AddIdentity;
    2596         166 :                     n->name = $3;
    2597         166 :                     n->def = (Node *) c;
    2598             : 
    2599         166 :                     $$ = (Node *) n;
    2600             :                 }
    2601             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2602             :             | ALTER opt_column ColId alter_identity_column_option_list
    2603             :                 {
    2604          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2605             : 
    2606          62 :                     n->subtype = AT_SetIdentity;
    2607          62 :                     n->name = $3;
    2608          62 :                     n->def = (Node *) $4;
    2609          62 :                     $$ = (Node *) n;
    2610             :                 }
    2611             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2612             :             | ALTER opt_column ColId DROP IDENTITY_P
    2613             :                 {
    2614          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2615             : 
    2616          50 :                     n->subtype = AT_DropIdentity;
    2617          50 :                     n->name = $3;
    2618          50 :                     n->missing_ok = false;
    2619          50 :                     $$ = (Node *) n;
    2620             :                 }
    2621             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2622             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2623             :                 {
    2624           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2625             : 
    2626           6 :                     n->subtype = AT_DropIdentity;
    2627           6 :                     n->name = $3;
    2628           6 :                     n->missing_ok = true;
    2629           6 :                     $$ = (Node *) n;
    2630             :                 }
    2631             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2632             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2633             :                 {
    2634          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2635             : 
    2636          18 :                     n->subtype = AT_DropColumn;
    2637          18 :                     n->name = $5;
    2638          18 :                     n->behavior = $6;
    2639          18 :                     n->missing_ok = true;
    2640          18 :                     $$ = (Node *) n;
    2641             :                 }
    2642             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2643             :             | DROP opt_column ColId opt_drop_behavior
    2644             :                 {
    2645        1574 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2646             : 
    2647        1574 :                     n->subtype = AT_DropColumn;
    2648        1574 :                     n->name = $3;
    2649        1574 :                     n->behavior = $4;
    2650        1574 :                     n->missing_ok = false;
    2651        1574 :                     $$ = (Node *) n;
    2652             :                 }
    2653             :             /*
    2654             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2655             :              *      [ USING <expression> ]
    2656             :              */
    2657             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2658             :                 {
    2659        1024 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2660        1024 :                     ColumnDef *def = makeNode(ColumnDef);
    2661             : 
    2662        1024 :                     n->subtype = AT_AlterColumnType;
    2663        1024 :                     n->name = $3;
    2664        1024 :                     n->def = (Node *) def;
    2665             :                     /* We only use these fields of the ColumnDef node */
    2666        1024 :                     def->typeName = $6;
    2667        1024 :                     def->collClause = (CollateClause *) $7;
    2668        1024 :                     def->raw_default = $8;
    2669        1024 :                     def->location = @3;
    2670        1024 :                     $$ = (Node *) n;
    2671             :                 }
    2672             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2673             :             | ALTER opt_column ColId alter_generic_options
    2674             :                 {
    2675          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2676             : 
    2677          50 :                     n->subtype = AT_AlterColumnGenericOptions;
    2678          50 :                     n->name = $3;
    2679          50 :                     n->def = (Node *) $4;
    2680          50 :                     $$ = (Node *) n;
    2681             :                 }
    2682             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2683             :             | ADD_P TableConstraint
    2684             :                 {
    2685       14554 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2686             : 
    2687       14554 :                     n->subtype = AT_AddConstraint;
    2688       14554 :                     n->def = $2;
    2689       14554 :                     $$ = (Node *) n;
    2690             :                 }
    2691             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2692             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2693             :                 {
    2694         240 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2695         240 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2696             : 
    2697         240 :                     n->subtype = AT_AlterConstraint;
    2698         240 :                     n->def = (Node *) c;
    2699         240 :                     c->conname = $3;
    2700         240 :                     if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
    2701          84 :                         c->alterEnforceability = true;
    2702         240 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2703             :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2704         120 :                         c->alterDeferrability = true;
    2705         240 :                     if ($4 & CAS_NO_INHERIT)
    2706          30 :                         c->alterInheritability = true;
    2707             :                     /* handle unsupported case with specific error message */
    2708         240 :                     if ($4 & CAS_NOT_VALID)
    2709          12 :                         ereport(ERROR,
    2710             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    2711             :                                 errmsg("constraints cannot be altered to be NOT VALID"),
    2712             :                                 parser_errposition(@4));
    2713         228 :                     processCASbits($4, @4, "FOREIGN KEY",
    2714             :                                     &c->deferrable,
    2715             :                                     &c->initdeferred,
    2716             :                                     &c->is_enforced,
    2717             :                                     NULL,
    2718             :                                     &c->noinherit,
    2719             :                                     yyscanner);
    2720         228 :                     $$ = (Node *) n;
    2721             :                 }
    2722             :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2723             :             | ALTER CONSTRAINT name INHERIT
    2724             :                 {
    2725          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2726          66 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2727             : 
    2728          66 :                     n->subtype = AT_AlterConstraint;
    2729          66 :                     n->def = (Node *) c;
    2730          66 :                     c->conname = $3;
    2731          66 :                     c->alterInheritability = true;
    2732          66 :                     c->noinherit = false;
    2733             : 
    2734          66 :                     $$ = (Node *) n;
    2735             :                 }
    2736             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2737             :             | VALIDATE CONSTRAINT name
    2738             :                 {
    2739         476 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2740             : 
    2741         476 :                     n->subtype = AT_ValidateConstraint;
    2742         476 :                     n->name = $3;
    2743         476 :                     $$ = (Node *) n;
    2744             :                 }
    2745             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2746             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2747             :                 {
    2748          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2749             : 
    2750          18 :                     n->subtype = AT_DropConstraint;
    2751          18 :                     n->name = $5;
    2752          18 :                     n->behavior = $6;
    2753          18 :                     n->missing_ok = true;
    2754          18 :                     $$ = (Node *) n;
    2755             :                 }
    2756             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2757             :             | DROP CONSTRAINT name opt_drop_behavior
    2758             :                 {
    2759         818 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2760             : 
    2761         818 :                     n->subtype = AT_DropConstraint;
    2762         818 :                     n->name = $3;
    2763         818 :                     n->behavior = $4;
    2764         818 :                     n->missing_ok = false;
    2765         818 :                     $$ = (Node *) n;
    2766             :                 }
    2767             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2768             :             | SET WITHOUT OIDS
    2769             :                 {
    2770           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2771             : 
    2772           6 :                     n->subtype = AT_DropOids;
    2773           6 :                     $$ = (Node *) n;
    2774             :                 }
    2775             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2776             :             | CLUSTER ON name
    2777             :                 {
    2778          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2779             : 
    2780          46 :                     n->subtype = AT_ClusterOn;
    2781          46 :                     n->name = $3;
    2782          46 :                     $$ = (Node *) n;
    2783             :                 }
    2784             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2785             :             | SET WITHOUT CLUSTER
    2786             :                 {
    2787          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2788             : 
    2789          18 :                     n->subtype = AT_DropCluster;
    2790          18 :                     n->name = NULL;
    2791          18 :                     $$ = (Node *) n;
    2792             :                 }
    2793             :             /* ALTER TABLE <name> SET LOGGED */
    2794             :             | SET LOGGED
    2795             :                 {
    2796          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2797             : 
    2798          50 :                     n->subtype = AT_SetLogged;
    2799          50 :                     $$ = (Node *) n;
    2800             :                 }
    2801             :             /* ALTER TABLE <name> SET UNLOGGED */
    2802             :             | SET UNLOGGED
    2803             :                 {
    2804          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2805             : 
    2806          62 :                     n->subtype = AT_SetUnLogged;
    2807          62 :                     $$ = (Node *) n;
    2808             :                 }
    2809             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2810             :             | ENABLE_P TRIGGER name
    2811             :                 {
    2812         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2813             : 
    2814         122 :                     n->subtype = AT_EnableTrig;
    2815         122 :                     n->name = $3;
    2816         122 :                     $$ = (Node *) n;
    2817             :                 }
    2818             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2819             :             | ENABLE_P ALWAYS TRIGGER name
    2820             :                 {
    2821          42 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2822             : 
    2823          42 :                     n->subtype = AT_EnableAlwaysTrig;
    2824          42 :                     n->name = $4;
    2825          42 :                     $$ = (Node *) n;
    2826             :                 }
    2827             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2828             :             | ENABLE_P REPLICA TRIGGER name
    2829             :                 {
    2830          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2831             : 
    2832          16 :                     n->subtype = AT_EnableReplicaTrig;
    2833          16 :                     n->name = $4;
    2834          16 :                     $$ = (Node *) n;
    2835             :                 }
    2836             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2837             :             | ENABLE_P TRIGGER ALL
    2838             :                 {
    2839           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2840             : 
    2841           0 :                     n->subtype = AT_EnableTrigAll;
    2842           0 :                     $$ = (Node *) n;
    2843             :                 }
    2844             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2845             :             | ENABLE_P TRIGGER USER
    2846             :                 {
    2847           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2848             : 
    2849           0 :                     n->subtype = AT_EnableTrigUser;
    2850           0 :                     $$ = (Node *) n;
    2851             :                 }
    2852             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2853             :             | DISABLE_P TRIGGER name
    2854             :                 {
    2855         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2856             : 
    2857         138 :                     n->subtype = AT_DisableTrig;
    2858         138 :                     n->name = $3;
    2859         138 :                     $$ = (Node *) n;
    2860             :                 }
    2861             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2862             :             | DISABLE_P TRIGGER ALL
    2863             :                 {
    2864          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2865             : 
    2866          12 :                     n->subtype = AT_DisableTrigAll;
    2867          12 :                     $$ = (Node *) n;
    2868             :                 }
    2869             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2870             :             | DISABLE_P TRIGGER USER
    2871             :                 {
    2872          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2873             : 
    2874          12 :                     n->subtype = AT_DisableTrigUser;
    2875          12 :                     $$ = (Node *) n;
    2876             :                 }
    2877             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2878             :             | ENABLE_P RULE name
    2879             :                 {
    2880           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2881             : 
    2882           8 :                     n->subtype = AT_EnableRule;
    2883           8 :                     n->name = $3;
    2884           8 :                     $$ = (Node *) n;
    2885             :                 }
    2886             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2887             :             | ENABLE_P ALWAYS RULE name
    2888             :                 {
    2889           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2890             : 
    2891           0 :                     n->subtype = AT_EnableAlwaysRule;
    2892           0 :                     n->name = $4;
    2893           0 :                     $$ = (Node *) n;
    2894             :                 }
    2895             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2896             :             | ENABLE_P REPLICA RULE name
    2897             :                 {
    2898           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2899             : 
    2900           6 :                     n->subtype = AT_EnableReplicaRule;
    2901           6 :                     n->name = $4;
    2902           6 :                     $$ = (Node *) n;
    2903             :                 }
    2904             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2905             :             | DISABLE_P RULE name
    2906             :                 {
    2907          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2908             : 
    2909          32 :                     n->subtype = AT_DisableRule;
    2910          32 :                     n->name = $3;
    2911          32 :                     $$ = (Node *) n;
    2912             :                 }
    2913             :             /* ALTER TABLE <name> INHERIT <parent> */
    2914             :             | INHERIT qualified_name
    2915             :                 {
    2916         462 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2917             : 
    2918         462 :                     n->subtype = AT_AddInherit;
    2919         462 :                     n->def = (Node *) $2;
    2920         462 :                     $$ = (Node *) n;
    2921             :                 }
    2922             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2923             :             | NO INHERIT qualified_name
    2924             :                 {
    2925          94 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2926             : 
    2927          94 :                     n->subtype = AT_DropInherit;
    2928          94 :                     n->def = (Node *) $3;
    2929          94 :                     $$ = (Node *) n;
    2930             :                 }
    2931             :             /* ALTER TABLE <name> OF <type_name> */
    2932             :             | OF any_name
    2933             :                 {
    2934          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2935          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2936             : 
    2937          66 :                     def->location = @2;
    2938          66 :                     n->subtype = AT_AddOf;
    2939          66 :                     n->def = (Node *) def;
    2940          66 :                     $$ = (Node *) n;
    2941             :                 }
    2942             :             /* ALTER TABLE <name> NOT OF */
    2943             :             | NOT OF
    2944             :                 {
    2945           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2946             : 
    2947           6 :                     n->subtype = AT_DropOf;
    2948           6 :                     $$ = (Node *) n;
    2949             :                 }
    2950             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2951             :             | OWNER TO RoleSpec
    2952             :                 {
    2953        2022 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2954             : 
    2955        2022 :                     n->subtype = AT_ChangeOwner;
    2956        2022 :                     n->newowner = $3;
    2957        2022 :                     $$ = (Node *) n;
    2958             :                 }
    2959             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2960             :             | SET ACCESS METHOD set_access_method_name
    2961             :                 {
    2962         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2963             : 
    2964         128 :                     n->subtype = AT_SetAccessMethod;
    2965         128 :                     n->name = $4;
    2966         128 :                     $$ = (Node *) n;
    2967             :                 }
    2968             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2969             :             | SET TABLESPACE name
    2970             :                 {
    2971         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2972             : 
    2973         104 :                     n->subtype = AT_SetTableSpace;
    2974         104 :                     n->name = $3;
    2975         104 :                     $$ = (Node *) n;
    2976             :                 }
    2977             :             /* ALTER TABLE <name> SET (...) */
    2978             :             | SET reloptions
    2979             :                 {
    2980         600 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2981             : 
    2982         600 :                     n->subtype = AT_SetRelOptions;
    2983         600 :                     n->def = (Node *) $2;
    2984         600 :                     $$ = (Node *) n;
    2985             :                 }
    2986             :             /* ALTER TABLE <name> RESET (...) */
    2987             :             | RESET reloptions
    2988             :                 {
    2989         170 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2990             : 
    2991         170 :                     n->subtype = AT_ResetRelOptions;
    2992         170 :                     n->def = (Node *) $2;
    2993         170 :                     $$ = (Node *) n;
    2994             :                 }
    2995             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2996             :             | REPLICA IDENTITY_P replica_identity
    2997             :                 {
    2998         494 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2999             : 
    3000         494 :                     n->subtype = AT_ReplicaIdentity;
    3001         494 :                     n->def = $3;
    3002         494 :                     $$ = (Node *) n;
    3003             :                 }
    3004             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    3005             :             | ENABLE_P ROW LEVEL SECURITY
    3006             :                 {
    3007         326 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3008             : 
    3009         326 :                     n->subtype = AT_EnableRowSecurity;
    3010         326 :                     $$ = (Node *) n;
    3011             :                 }
    3012             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    3013             :             | DISABLE_P ROW LEVEL SECURITY
    3014             :                 {
    3015          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3016             : 
    3017          10 :                     n->subtype = AT_DisableRowSecurity;
    3018          10 :                     $$ = (Node *) n;
    3019             :                 }
    3020             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    3021             :             | FORCE ROW LEVEL SECURITY
    3022             :                 {
    3023         100 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3024             : 
    3025         100 :                     n->subtype = AT_ForceRowSecurity;
    3026         100 :                     $$ = (Node *) n;
    3027             :                 }
    3028             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    3029             :             | NO FORCE ROW LEVEL SECURITY
    3030             :                 {
    3031          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3032             : 
    3033          32 :                     n->subtype = AT_NoForceRowSecurity;
    3034          32 :                     $$ = (Node *) n;
    3035             :                 }
    3036             :             | alter_generic_options
    3037             :                 {
    3038          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3039             : 
    3040          64 :                     n->subtype = AT_GenericOptions;
    3041          64 :                     n->def = (Node *) $1;
    3042          64 :                     $$ = (Node *) n;
    3043             :                 }
    3044             :         ;
    3045             : 
    3046             : alter_column_default:
    3047         378 :             SET DEFAULT a_expr          { $$ = $3; }
    3048         186 :             | DROP DEFAULT              { $$ = NULL; }
    3049             :         ;
    3050             : 
    3051             : opt_collate_clause:
    3052             :             COLLATE any_name
    3053             :                 {
    3054          18 :                     CollateClause *n = makeNode(CollateClause);
    3055             : 
    3056          18 :                     n->arg = NULL;
    3057          18 :                     n->collname = $2;
    3058          18 :                     n->location = @1;
    3059          18 :                     $$ = (Node *) n;
    3060             :                 }
    3061        4728 :             | /* EMPTY */               { $$ = NULL; }
    3062             :         ;
    3063             : 
    3064             : alter_using:
    3065         180 :             USING a_expr                { $$ = $2; }
    3066         844 :             | /* EMPTY */               { $$ = NULL; }
    3067             :         ;
    3068             : 
    3069             : replica_identity:
    3070             :             NOTHING
    3071             :                 {
    3072          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3073             : 
    3074          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3075          48 :                     n->name = NULL;
    3076          48 :                     $$ = (Node *) n;
    3077             :                 }
    3078             :             | FULL
    3079             :                 {
    3080         170 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3081             : 
    3082         170 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3083         170 :                     n->name = NULL;
    3084         170 :                     $$ = (Node *) n;
    3085             :                 }
    3086             :             | DEFAULT
    3087             :                 {
    3088           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3089             : 
    3090           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3091           6 :                     n->name = NULL;
    3092           6 :                     $$ = (Node *) n;
    3093             :                 }
    3094             :             | USING INDEX name
    3095             :                 {
    3096         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3097             : 
    3098         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3099         270 :                     n->name = $3;
    3100         270 :                     $$ = (Node *) n;
    3101             :                 }
    3102             : ;
    3103             : 
    3104             : reloptions:
    3105        2698 :             '(' reloption_list ')'                  { $$ = $2; }
    3106             :         ;
    3107             : 
    3108         964 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3109       23370 :              |      /* EMPTY */                     { $$ = NIL; }
    3110             :         ;
    3111             : 
    3112             : reloption_list:
    3113        2698 :             reloption_elem                          { $$ = list_make1($1); }
    3114         250 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3115             :         ;
    3116             : 
    3117             : /* This should match def_elem and also allow qualified names */
    3118             : reloption_elem:
    3119             :             ColLabel '=' def_arg
    3120             :                 {
    3121        2286 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3122             :                 }
    3123             :             | ColLabel
    3124             :                 {
    3125         584 :                     $$ = makeDefElem($1, NULL, @1);
    3126             :                 }
    3127             :             | ColLabel '.' ColLabel '=' def_arg
    3128             :                 {
    3129          72 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3130          72 :                                              DEFELEM_UNSPEC, @1);
    3131             :                 }
    3132             :             | ColLabel '.' ColLabel
    3133             :                 {
    3134           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3135             :                 }
    3136             :         ;
    3137             : 
    3138             : alter_identity_column_option_list:
    3139             :             alter_identity_column_option
    3140          62 :                 { $$ = list_make1($1); }
    3141             :             | alter_identity_column_option_list alter_identity_column_option
    3142          60 :                 { $$ = lappend($1, $2); }
    3143             :         ;
    3144             : 
    3145             : alter_identity_column_option:
    3146             :             RESTART
    3147             :                 {
    3148          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3149             :                 }
    3150             :             | RESTART opt_with NumericOnly
    3151             :                 {
    3152           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3153             :                 }
    3154             :             | SET SeqOptElem
    3155             :                 {
    3156          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3157          54 :                         strcmp($2->defname, "restart") == 0 ||
    3158          54 :                         strcmp($2->defname, "owned_by") == 0)
    3159           0 :                         ereport(ERROR,
    3160             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3161             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3162             :                                  parser_errposition(@2)));
    3163          54 :                     $$ = $2;
    3164             :                 }
    3165             :             | SET GENERATED generated_when
    3166             :                 {
    3167          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3168             :                 }
    3169             :         ;
    3170             : 
    3171             : set_statistics_value:
    3172         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3173           0 :             | DEFAULT                       { $$ = NULL; }
    3174             :         ;
    3175             : 
    3176             : set_access_method_name:
    3177          92 :             ColId                           { $$ = $1; }
    3178          36 :             | DEFAULT                       { $$ = NULL; }
    3179             :         ;
    3180             : 
    3181             : PartitionBoundSpec:
    3182             :             /* a HASH partition */
    3183             :             FOR VALUES WITH '(' hash_partbound ')'
    3184             :                 {
    3185             :                     ListCell   *lc;
    3186         726 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3187             : 
    3188         726 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3189         726 :                     n->modulus = n->remainder = -1;
    3190             : 
    3191        2178 :                     foreach (lc, $5)
    3192             :                     {
    3193        1452 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3194             : 
    3195        1452 :                         if (strcmp(opt->defname, "modulus") == 0)
    3196             :                         {
    3197         726 :                             if (n->modulus != -1)
    3198           0 :                                 ereport(ERROR,
    3199             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3200             :                                          errmsg("modulus for hash partition provided more than once"),
    3201             :                                          parser_errposition(opt->location)));
    3202         726 :                             n->modulus = defGetInt32(opt);
    3203             :                         }
    3204         726 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3205             :                         {
    3206         726 :                             if (n->remainder != -1)
    3207           0 :                                 ereport(ERROR,
    3208             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3209             :                                          errmsg("remainder for hash partition provided more than once"),
    3210             :                                          parser_errposition(opt->location)));
    3211         726 :                             n->remainder = defGetInt32(opt);
    3212             :                         }
    3213             :                         else
    3214           0 :                             ereport(ERROR,
    3215             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3216             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3217             :                                             opt->defname),
    3218             :                                      parser_errposition(opt->location)));
    3219             :                     }
    3220             : 
    3221         726 :                     if (n->modulus == -1)
    3222           0 :                         ereport(ERROR,
    3223             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3224             :                                  errmsg("modulus for hash partition must be specified"),
    3225             :                                  parser_errposition(@3)));
    3226         726 :                     if (n->remainder == -1)
    3227           0 :                         ereport(ERROR,
    3228             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3229             :                                  errmsg("remainder for hash partition must be specified"),
    3230             :                                  parser_errposition(@3)));
    3231             : 
    3232         726 :                     n->location = @3;
    3233             : 
    3234         726 :                     $$ = n;
    3235             :                 }
    3236             : 
    3237             :             /* a LIST partition */
    3238             :             | FOR VALUES IN_P '(' expr_list ')'
    3239             :                 {
    3240        4946 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3241             : 
    3242        4946 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3243        4946 :                     n->is_default = false;
    3244        4946 :                     n->listdatums = $5;
    3245        4946 :                     n->location = @3;
    3246             : 
    3247        4946 :                     $$ = n;
    3248             :                 }
    3249             : 
    3250             :             /* a RANGE partition */
    3251             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3252             :                 {
    3253        4226 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3254             : 
    3255        4226 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3256        4226 :                     n->is_default = false;
    3257        4226 :                     n->lowerdatums = $5;
    3258        4226 :                     n->upperdatums = $9;
    3259        4226 :                     n->location = @3;
    3260             : 
    3261        4226 :                     $$ = n;
    3262             :                 }
    3263             : 
    3264             :             /* a DEFAULT partition */
    3265             :             | DEFAULT
    3266             :                 {
    3267         598 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3268             : 
    3269         598 :                     n->is_default = true;
    3270         598 :                     n->location = @1;
    3271             : 
    3272         598 :                     $$ = n;
    3273             :                 }
    3274             :         ;
    3275             : 
    3276             : hash_partbound_elem:
    3277             :         NonReservedWord Iconst
    3278             :             {
    3279        1452 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3280             :             }
    3281             :         ;
    3282             : 
    3283             : hash_partbound:
    3284             :         hash_partbound_elem
    3285             :             {
    3286         726 :                 $$ = list_make1($1);
    3287             :             }
    3288             :         | hash_partbound ',' hash_partbound_elem
    3289             :             {
    3290         726 :                 $$ = lappend($1, $3);
    3291             :             }
    3292             :         ;
    3293             : 
    3294             : /*****************************************************************************
    3295             :  *
    3296             :  *  ALTER TYPE
    3297             :  *
    3298             :  * really variants of the ALTER TABLE subcommands with different spellings
    3299             :  *****************************************************************************/
    3300             : 
    3301             : AlterCompositeTypeStmt:
    3302             :             ALTER TYPE_P any_name alter_type_cmds
    3303             :                 {
    3304         210 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3305             : 
    3306             :                     /* can't use qualified_name, sigh */
    3307         210 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3308         210 :                     n->cmds = $4;
    3309         210 :                     n->objtype = OBJECT_TYPE;
    3310         210 :                     $$ = (Node *) n;
    3311             :                 }
    3312             :             ;
    3313             : 
    3314             : alter_type_cmds:
    3315         210 :             alter_type_cmd                          { $$ = list_make1($1); }
    3316          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3317             :         ;
    3318             : 
    3319             : alter_type_cmd:
    3320             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3321             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3322             :                 {
    3323          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3324             : 
    3325          64 :                     n->subtype = AT_AddColumn;
    3326          64 :                     n->def = $3;
    3327          64 :                     n->behavior = $4;
    3328          64 :                     $$ = (Node *) n;
    3329             :                 }
    3330             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3331             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3332             :                 {
    3333           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3334             : 
    3335           6 :                     n->subtype = AT_DropColumn;
    3336           6 :                     n->name = $5;
    3337           6 :                     n->behavior = $6;
    3338           6 :                     n->missing_ok = true;
    3339           6 :                     $$ = (Node *) n;
    3340             :                 }
    3341             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3342             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3343             :                 {
    3344          78 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3345             : 
    3346          78 :                     n->subtype = AT_DropColumn;
    3347          78 :                     n->name = $3;
    3348          78 :                     n->behavior = $4;
    3349          78 :                     n->missing_ok = false;
    3350          78 :                     $$ = (Node *) n;
    3351             :                 }
    3352             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3353             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3354             :                 {
    3355          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3356          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3357             : 
    3358          74 :                     n->subtype = AT_AlterColumnType;
    3359          74 :                     n->name = $3;
    3360          74 :                     n->def = (Node *) def;
    3361          74 :                     n->behavior = $8;
    3362             :                     /* We only use these fields of the ColumnDef node */
    3363          74 :                     def->typeName = $6;
    3364          74 :                     def->collClause = (CollateClause *) $7;
    3365          74 :                     def->raw_default = NULL;
    3366          74 :                     def->location = @3;
    3367          74 :                     $$ = (Node *) n;
    3368             :                 }
    3369             :         ;
    3370             : 
    3371             : 
    3372             : /*****************************************************************************
    3373             :  *
    3374             :  *      QUERY :
    3375             :  *              close <portalname>
    3376             :  *
    3377             :  *****************************************************************************/
    3378             : 
    3379             : ClosePortalStmt:
    3380             :             CLOSE cursor_name
    3381             :                 {
    3382        2230 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3383             : 
    3384        2230 :                     n->portalname = $2;
    3385        2230 :                     $$ = (Node *) n;
    3386             :                 }
    3387             :             | CLOSE ALL
    3388             :                 {
    3389          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3390             : 
    3391          12 :                     n->portalname = NULL;
    3392          12 :                     $$ = (Node *) n;
    3393             :                 }
    3394             :         ;
    3395             : 
    3396             : 
    3397             : /*****************************************************************************
    3398             :  *
    3399             :  *      QUERY :
    3400             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3401             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3402             :  *
    3403             :  *              where 'query' can be one of:
    3404             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3405             :  *
    3406             :  *              and 'file' can be one of:
    3407             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3408             :  *
    3409             :  *              In the preferred syntax the options are comma-separated
    3410             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3411             :  *              syntax had a hard-wired, space-separated set of options.
    3412             :  *
    3413             :  *              Really old syntax, from versions 7.2 and prior:
    3414             :  *              COPY [ BINARY ] table FROM/TO file
    3415             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3416             :  *                  [ WITH NULL AS 'null string' ]
    3417             :  *              This option placement is not supported with COPY (query...).
    3418             :  *
    3419             :  *****************************************************************************/
    3420             : 
    3421             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3422             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3423             :             copy_options where_clause
    3424             :                 {
    3425       11060 :                     CopyStmt *n = makeNode(CopyStmt);
    3426             : 
    3427       11060 :                     n->relation = $3;
    3428       11060 :                     n->query = NULL;
    3429       11060 :                     n->attlist = $4;
    3430       11060 :                     n->is_from = $5;
    3431       11060 :                     n->is_program = $6;
    3432       11060 :                     n->filename = $7;
    3433       11060 :                     n->whereClause = $11;
    3434             : 
    3435       11060 :                     if (n->is_program && n->filename == NULL)
    3436           0 :                         ereport(ERROR,
    3437             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3438             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3439             :                                  parser_errposition(@8)));
    3440             : 
    3441       11060 :                     if (!n->is_from && n->whereClause != NULL)
    3442           6 :                         ereport(ERROR,
    3443             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3444             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3445             :                                  errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
    3446             :                                  parser_errposition(@11)));
    3447             : 
    3448       11054 :                     n->options = NIL;
    3449             :                     /* Concatenate user-supplied flags */
    3450       11054 :                     if ($2)
    3451          12 :                         n->options = lappend(n->options, $2);
    3452       11054 :                     if ($8)
    3453           0 :                         n->options = lappend(n->options, $8);
    3454       11054 :                     if ($10)
    3455         968 :                         n->options = list_concat(n->options, $10);
    3456       11054 :                     $$ = (Node *) n;
    3457             :                 }
    3458             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3459             :                 {
    3460         536 :                     CopyStmt *n = makeNode(CopyStmt);
    3461             : 
    3462         536 :                     n->relation = NULL;
    3463         536 :                     n->query = $3;
    3464         536 :                     n->attlist = NIL;
    3465         536 :                     n->is_from = false;
    3466         536 :                     n->is_program = $6;
    3467         536 :                     n->filename = $7;
    3468         536 :                     n->options = $9;
    3469             : 
    3470         536 :                     if (n->is_program && n->filename == NULL)
    3471           0 :                         ereport(ERROR,
    3472             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3473             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3474             :                                  parser_errposition(@5)));
    3475             : 
    3476         536 :                     $$ = (Node *) n;
    3477             :                 }
    3478             :         ;
    3479             : 
    3480             : copy_from:
    3481        1856 :             FROM                                    { $$ = true; }
    3482        9204 :             | TO                                    { $$ = false; }
    3483             :         ;
    3484             : 
    3485             : opt_program:
    3486           0 :             PROGRAM                                 { $$ = true; }
    3487       11596 :             | /* EMPTY */                           { $$ = false; }
    3488             :         ;
    3489             : 
    3490             : /*
    3491             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3492             :  * used depends on the direction. (It really doesn't make sense to copy from
    3493             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3494             :  */
    3495             : copy_file_name:
    3496         452 :             Sconst                                  { $$ = $1; }
    3497        1468 :             | STDIN                                 { $$ = NULL; }
    3498        9676 :             | STDOUT                                { $$ = NULL; }
    3499             :         ;
    3500             : 
    3501       10898 : copy_options: copy_opt_list                         { $$ = $1; }
    3502         698 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3503             :         ;
    3504             : 
    3505             : /* old COPY option syntax */
    3506             : copy_opt_list:
    3507         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3508       10898 :             | /* EMPTY */                           { $$ = NIL; }
    3509             :         ;
    3510             : 
    3511             : copy_opt_item:
    3512             :             BINARY
    3513             :                 {
    3514           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3515             :                 }
    3516             :             | FREEZE
    3517             :                 {
    3518          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3519             :                 }
    3520             :             | DELIMITER opt_as Sconst
    3521             :                 {
    3522         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3523             :                 }
    3524             :             | NULL_P opt_as Sconst
    3525             :                 {
    3526          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3527             :                 }
    3528             :             | CSV
    3529             :                 {
    3530         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3531             :                 }
    3532             :             | HEADER_P
    3533             :                 {
    3534          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3535             :                 }
    3536             :             | QUOTE opt_as Sconst
    3537             :                 {
    3538          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3539             :                 }
    3540             :             | ESCAPE opt_as Sconst
    3541             :                 {
    3542          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3543             :                 }
    3544             :             | FORCE QUOTE columnList
    3545             :                 {
    3546          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3547             :                 }
    3548             :             | FORCE QUOTE '*'
    3549             :                 {
    3550           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3551             :                 }
    3552             :             | FORCE NOT NULL_P columnList
    3553             :                 {
    3554           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3555             :                 }
    3556             :             | FORCE NOT NULL_P '*'
    3557             :                 {
    3558           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3559             :                 }
    3560             :             | FORCE NULL_P columnList
    3561             :                 {
    3562           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3563             :                 }
    3564             :             | FORCE NULL_P '*'
    3565             :                 {
    3566           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3567             :                 }
    3568             :             | ENCODING Sconst
    3569             :                 {
    3570          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3571             :                 }
    3572             :         ;
    3573             : 
    3574             : /* The following exist for backward compatibility with very old versions */
    3575             : 
    3576             : opt_binary:
    3577             :             BINARY
    3578             :                 {
    3579          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3580             :                 }
    3581       11048 :             | /*EMPTY*/                             { $$ = NULL; }
    3582             :         ;
    3583             : 
    3584             : copy_delimiter:
    3585             :             opt_using DELIMITERS Sconst
    3586             :                 {
    3587           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3588             :                 }
    3589       11060 :             | /*EMPTY*/                             { $$ = NULL; }
    3590             :         ;
    3591             : 
    3592             : opt_using:
    3593             :             USING
    3594             :             | /*EMPTY*/
    3595             :         ;
    3596             : 
    3597             : /* new COPY option syntax */
    3598             : copy_generic_opt_list:
    3599             :             copy_generic_opt_elem
    3600             :                 {
    3601         698 :                     $$ = list_make1($1);
    3602             :                 }
    3603             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3604             :                 {
    3605         468 :                     $$ = lappend($1, $3);
    3606             :                 }
    3607             :         ;
    3608             : 
    3609             : copy_generic_opt_elem:
    3610             :             ColLabel copy_generic_opt_arg
    3611             :                 {
    3612        1166 :                     $$ = makeDefElem($1, $2, @1);
    3613             :                 }
    3614             :         ;
    3615             : 
    3616             : copy_generic_opt_arg:
    3617         818 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3618          60 :             | NumericOnly                   { $$ = (Node *) $1; }
    3619          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3620           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3621         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3622          42 :             | /* EMPTY */                   { $$ = NULL; }
    3623             :         ;
    3624             : 
    3625             : copy_generic_opt_arg_list:
    3626             :               copy_generic_opt_arg_list_item
    3627             :                 {
    3628         150 :                     $$ = list_make1($1);
    3629             :                 }
    3630             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3631             :                 {
    3632          12 :                     $$ = lappend($1, $3);
    3633             :                 }
    3634             :         ;
    3635             : 
    3636             : /* beware of emitting non-string list elements here; see commands/define.c */
    3637             : copy_generic_opt_arg_list_item:
    3638         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3639             :         ;
    3640             : 
    3641             : 
    3642             : /*****************************************************************************
    3643             :  *
    3644             :  *      QUERY :
    3645             :  *              CREATE TABLE relname
    3646             :  *
    3647             :  *****************************************************************************/
    3648             : 
    3649             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3650             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3651             :             OnCommitOption OptTableSpace
    3652             :                 {
    3653       29614 :                     CreateStmt *n = makeNode(CreateStmt);
    3654             : 
    3655       29614 :                     $4->relpersistence = $2;
    3656       29614 :                     n->relation = $4;
    3657       29614 :                     n->tableElts = $6;
    3658       29614 :                     n->inhRelations = $8;
    3659       29614 :                     n->partspec = $9;
    3660       29614 :                     n->ofTypename = NULL;
    3661       29614 :                     n->constraints = NIL;
    3662       29614 :                     n->accessMethod = $10;
    3663       29614 :                     n->options = $11;
    3664       29614 :                     n->oncommit = $12;
    3665       29614 :                     n->tablespacename = $13;
    3666       29614 :                     n->if_not_exists = false;
    3667       29614 :                     $$ = (Node *) n;
    3668             :                 }
    3669             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3670             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3671             :             OptWith OnCommitOption OptTableSpace
    3672             :                 {
    3673          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3674             : 
    3675          30 :                     $7->relpersistence = $2;
    3676          30 :                     n->relation = $7;
    3677          30 :                     n->tableElts = $9;
    3678          30 :                     n->inhRelations = $11;
    3679          30 :                     n->partspec = $12;
    3680          30 :                     n->ofTypename = NULL;
    3681          30 :                     n->constraints = NIL;
    3682          30 :                     n->accessMethod = $13;
    3683          30 :                     n->options = $14;
    3684          30 :                     n->oncommit = $15;
    3685          30 :                     n->tablespacename = $16;
    3686          30 :                     n->if_not_exists = true;
    3687          30 :                     $$ = (Node *) n;
    3688             :                 }
    3689             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3690             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3691             :             OptWith OnCommitOption OptTableSpace
    3692             :                 {
    3693         122 :                     CreateStmt *n = makeNode(CreateStmt);
    3694             : 
    3695         122 :                     $4->relpersistence = $2;
    3696         122 :                     n->relation = $4;
    3697         122 :                     n->tableElts = $7;
    3698         122 :                     n->inhRelations = NIL;
    3699         122 :                     n->partspec = $8;
    3700         122 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3701         122 :                     n->ofTypename->location = @6;
    3702         122 :                     n->constraints = NIL;
    3703         122 :                     n->accessMethod = $9;
    3704         122 :                     n->options = $10;
    3705         122 :                     n->oncommit = $11;
    3706         122 :                     n->tablespacename = $12;
    3707         122 :                     n->if_not_exists = false;
    3708         122 :                     $$ = (Node *) n;
    3709             :                 }
    3710             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3711             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3712             :             OptWith OnCommitOption OptTableSpace
    3713             :                 {
    3714           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3715             : 
    3716           6 :                     $7->relpersistence = $2;
    3717           6 :                     n->relation = $7;
    3718           6 :                     n->tableElts = $10;
    3719           6 :                     n->inhRelations = NIL;
    3720           6 :                     n->partspec = $11;
    3721           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3722           6 :                     n->ofTypename->location = @9;
    3723           6 :                     n->constraints = NIL;
    3724           6 :                     n->accessMethod = $12;
    3725           6 :                     n->options = $13;
    3726           6 :                     n->oncommit = $14;
    3727           6 :                     n->tablespacename = $15;
    3728           6 :                     n->if_not_exists = true;
    3729           6 :                     $$ = (Node *) n;
    3730             :                 }
    3731             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3732             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3733             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3734             :                 {
    3735        7976 :                     CreateStmt *n = makeNode(CreateStmt);
    3736             : 
    3737        7976 :                     $4->relpersistence = $2;
    3738        7976 :                     n->relation = $4;
    3739        7976 :                     n->tableElts = $8;
    3740        7976 :                     n->inhRelations = list_make1($7);
    3741        7976 :                     n->partbound = $9;
    3742        7976 :                     n->partspec = $10;
    3743        7976 :                     n->ofTypename = NULL;
    3744        7976 :                     n->constraints = NIL;
    3745        7976 :                     n->accessMethod = $11;
    3746        7976 :                     n->options = $12;
    3747        7976 :                     n->oncommit = $13;
    3748        7976 :                     n->tablespacename = $14;
    3749        7976 :                     n->if_not_exists = false;
    3750        7976 :                     $$ = (Node *) n;
    3751             :                 }
    3752             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3753             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3754             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3755             :                 {
    3756           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3757             : 
    3758           0 :                     $7->relpersistence = $2;
    3759           0 :                     n->relation = $7;
    3760           0 :                     n->tableElts = $11;
    3761           0 :                     n->inhRelations = list_make1($10);
    3762           0 :                     n->partbound = $12;
    3763           0 :                     n->partspec = $13;
    3764           0 :                     n->ofTypename = NULL;
    3765           0 :                     n->constraints = NIL;
    3766           0 :                     n->accessMethod = $14;
    3767           0 :                     n->options = $15;
    3768           0 :                     n->oncommit = $16;
    3769           0 :                     n->tablespacename = $17;
    3770           0 :                     n->if_not_exists = true;
    3771           0 :                     $$ = (Node *) n;
    3772             :                 }
    3773             :         ;
    3774             : 
    3775             : /*
    3776             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3777             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3778             :  *
    3779             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3780             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3781             :  * temp table behavior, so warn about that.  Since we have no modules the
    3782             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3783             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3784             :  * so we'll probably continue to treat LOCAL as a noise word.
    3785             :  */
    3786         346 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3787        2768 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3788           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3789           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3790             :             | GLOBAL TEMPORARY
    3791             :                 {
    3792           0 :                     ereport(WARNING,
    3793             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3794             :                              parser_errposition(@1)));
    3795           0 :                     $$ = RELPERSISTENCE_TEMP;
    3796             :                 }
    3797             :             | GLOBAL TEMP
    3798             :                 {
    3799           0 :                     ereport(WARNING,
    3800             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3801             :                              parser_errposition(@1)));
    3802           0 :                     $$ = RELPERSISTENCE_TEMP;
    3803             :                 }
    3804         160 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3805       53598 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3806             :         ;
    3807             : 
    3808             : OptTableElementList:
    3809       28456 :             TableElementList                    { $$ = $1; }
    3810        1626 :             | /*EMPTY*/                         { $$ = NIL; }
    3811             :         ;
    3812             : 
    3813             : OptTypedTableElementList:
    3814         348 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3815        7852 :             | /*EMPTY*/                         { $$ = NIL; }
    3816             :         ;
    3817             : 
    3818             : TableElementList:
    3819             :             TableElement
    3820             :                 {
    3821       28510 :                     $$ = list_make1($1);
    3822             :                 }
    3823             :             | TableElementList ',' TableElement
    3824             :                 {
    3825       40342 :                     $$ = lappend($1, $3);
    3826             :                 }
    3827             :         ;
    3828             : 
    3829             : TypedTableElementList:
    3830             :             TypedTableElement
    3831             :                 {
    3832         348 :                     $$ = list_make1($1);
    3833             :                 }
    3834             :             | TypedTableElementList ',' TypedTableElement
    3835             :                 {
    3836          68 :                     $$ = lappend($1, $3);
    3837             :                 }
    3838             :         ;
    3839             : 
    3840             : TableElement:
    3841       65394 :             columnDef                           { $$ = $1; }
    3842         774 :             | TableLikeClause                   { $$ = $1; }
    3843        2684 :             | TableConstraint                   { $$ = $1; }
    3844             :         ;
    3845             : 
    3846             : TypedTableElement:
    3847         346 :             columnOptions                       { $$ = $1; }
    3848          70 :             | TableConstraint                   { $$ = $1; }
    3849             :         ;
    3850             : 
    3851             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3852             :                 {
    3853       67544 :                     ColumnDef *n = makeNode(ColumnDef);
    3854             : 
    3855       67544 :                     n->colname = $1;
    3856       67544 :                     n->typeName = $2;
    3857       67544 :                     n->storage_name = $3;
    3858       67544 :                     n->compression = $4;
    3859       67544 :                     n->inhcount = 0;
    3860       67544 :                     n->is_local = true;
    3861       67544 :                     n->is_not_null = false;
    3862       67544 :                     n->is_from_type = false;
    3863       67544 :                     n->storage = 0;
    3864       67544 :                     n->raw_default = NULL;
    3865       67544 :                     n->cooked_default = NULL;
    3866       67544 :                     n->collOid = InvalidOid;
    3867       67544 :                     n->fdwoptions = $5;
    3868       67544 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3869             :                                      yyscanner);
    3870       67544 :                     n->location = @1;
    3871       67544 :                     $$ = (Node *) n;
    3872             :                 }
    3873             :         ;
    3874             : 
    3875             : columnOptions:  ColId ColQualList
    3876             :                 {
    3877         138 :                     ColumnDef *n = makeNode(ColumnDef);
    3878             : 
    3879         138 :                     n->colname = $1;
    3880         138 :                     n->typeName = NULL;
    3881         138 :                     n->inhcount = 0;
    3882         138 :                     n->is_local = true;
    3883         138 :                     n->is_not_null = false;
    3884         138 :                     n->is_from_type = false;
    3885         138 :                     n->storage = 0;
    3886         138 :                     n->raw_default = NULL;
    3887         138 :                     n->cooked_default = NULL;
    3888         138 :                     n->collOid = InvalidOid;
    3889         138 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3890             :                                      yyscanner);
    3891         138 :                     n->location = @1;
    3892         138 :                     $$ = (Node *) n;
    3893             :                 }
    3894             :                 | ColId WITH OPTIONS ColQualList
    3895             :                 {
    3896         208 :                     ColumnDef *n = makeNode(ColumnDef);
    3897             : 
    3898         208 :                     n->colname = $1;
    3899         208 :                     n->typeName = NULL;
    3900         208 :                     n->inhcount = 0;
    3901         208 :                     n->is_local = true;
    3902         208 :                     n->is_not_null = false;
    3903         208 :                     n->is_from_type = false;
    3904         208 :                     n->storage = 0;
    3905         208 :                     n->raw_default = NULL;
    3906         208 :                     n->cooked_default = NULL;
    3907         208 :                     n->collOid = InvalidOid;
    3908         208 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3909             :                                      yyscanner);
    3910         208 :                     n->location = @1;
    3911         208 :                     $$ = (Node *) n;
    3912             :                 }
    3913             :         ;
    3914             : 
    3915             : column_compression:
    3916         166 :             COMPRESSION ColId                       { $$ = $2; }
    3917           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3918             :         ;
    3919             : 
    3920             : opt_column_compression:
    3921          94 :             column_compression                      { $$ = $1; }
    3922       67516 :             | /*EMPTY*/                             { $$ = NULL; }
    3923             :         ;
    3924             : 
    3925             : column_storage:
    3926         258 :             STORAGE ColId                           { $$ = $2; }
    3927           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3928             :         ;
    3929             : 
    3930             : opt_column_storage:
    3931          26 :             column_storage                          { $$ = $1; }
    3932       67584 :             | /*EMPTY*/                             { $$ = NULL; }
    3933             :         ;
    3934             : 
    3935             : ColQualList:
    3936       19804 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3937       69408 :             | /*EMPTY*/                             { $$ = NIL; }
    3938             :         ;
    3939             : 
    3940             : ColConstraint:
    3941             :             CONSTRAINT name ColConstraintElem
    3942             :                 {
    3943         802 :                     Constraint *n = castNode(Constraint, $3);
    3944             : 
    3945         802 :                     n->conname = $2;
    3946         802 :                     n->location = @1;
    3947         802 :                     $$ = (Node *) n;
    3948             :                 }
    3949       17946 :             | ColConstraintElem                     { $$ = $1; }
    3950         294 :             | ConstraintAttr                        { $$ = $1; }
    3951             :             | COLLATE any_name
    3952             :                 {
    3953             :                     /*
    3954             :                      * Note: the CollateClause is momentarily included in
    3955             :                      * the list built by ColQualList, but we split it out
    3956             :                      * again in SplitColQualList.
    3957             :                      */
    3958         762 :                     CollateClause *n = makeNode(CollateClause);
    3959             : 
    3960         762 :                     n->arg = NULL;
    3961         762 :                     n->collname = $2;
    3962         762 :                     n->location = @1;
    3963         762 :                     $$ = (Node *) n;
    3964             :                 }
    3965             :         ;
    3966             : 
    3967             : /* DEFAULT NULL is already the default for Postgres.
    3968             :  * But define it here and carry it forward into the system
    3969             :  * to make it explicit.
    3970             :  * - thomas 1998-09-13
    3971             :  *
    3972             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3973             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3974             :  * that a column may have that value. WITH NULL leads to
    3975             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3976             :  * - thomas 1999-01-08
    3977             :  *
    3978             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3979             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3980             :  * or be part of a_expr NOT LIKE or similar constructs).
    3981             :  */
    3982             : ColConstraintElem:
    3983             :             NOT NULL_P opt_no_inherit
    3984             :                 {
    3985        6690 :                     Constraint *n = makeNode(Constraint);
    3986             : 
    3987        6690 :                     n->contype = CONSTR_NOTNULL;
    3988        6690 :                     n->location = @1;
    3989        6690 :                     n->is_no_inherit = $3;
    3990        6690 :                     n->is_enforced = true;
    3991        6690 :                     n->skip_validation = false;
    3992        6690 :                     n->initially_valid = true;
    3993        6690 :                     $$ = (Node *) n;
    3994             :                 }
    3995             :             | NULL_P
    3996             :                 {
    3997          30 :                     Constraint *n = makeNode(Constraint);
    3998             : 
    3999          30 :                     n->contype = CONSTR_NULL;
    4000          30 :                     n->location = @1;
    4001          30 :                     $$ = (Node *) n;
    4002             :                 }
    4003             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    4004             :                 {
    4005         462 :                     Constraint *n = makeNode(Constraint);
    4006             : 
    4007         462 :                     n->contype = CONSTR_UNIQUE;
    4008         462 :                     n->location = @1;
    4009         462 :                     n->nulls_not_distinct = !$2;
    4010         462 :                     n->keys = NULL;
    4011         462 :                     n->options = $3;
    4012         462 :                     n->indexname = NULL;
    4013         462 :                     n->indexspace = $4;
    4014         462 :                     $$ = (Node *) n;
    4015             :                 }
    4016             :             | PRIMARY KEY opt_definition OptConsTableSpace
    4017             :                 {
    4018        5808 :                     Constraint *n = makeNode(Constraint);
    4019             : 
    4020        5808 :                     n->contype = CONSTR_PRIMARY;
    4021        5808 :                     n->location = @1;
    4022        5808 :                     n->keys = NULL;
    4023        5808 :                     n->options = $3;
    4024        5808 :                     n->indexname = NULL;
    4025        5808 :                     n->indexspace = $4;
    4026        5808 :                     $$ = (Node *) n;
    4027             :                 }
    4028             :             | CHECK '(' a_expr ')' opt_no_inherit
    4029             :                 {
    4030        1086 :                     Constraint *n = makeNode(Constraint);
    4031             : 
    4032        1086 :                     n->contype = CONSTR_CHECK;
    4033        1086 :                     n->location = @1;
    4034        1086 :                     n->is_no_inherit = $5;
    4035        1086 :                     n->raw_expr = $3;
    4036        1086 :                     n->cooked_expr = NULL;
    4037        1086 :                     n->is_enforced = true;
    4038        1086 :                     n->skip_validation = false;
    4039        1086 :                     n->initially_valid = true;
    4040        1086 :                     $$ = (Node *) n;
    4041             :                 }
    4042             :             | DEFAULT b_expr
    4043             :                 {
    4044        1814 :                     Constraint *n = makeNode(Constraint);
    4045             : 
    4046        1814 :                     n->contype = CONSTR_DEFAULT;
    4047        1814 :                     n->location = @1;
    4048        1814 :                     n->raw_expr = $2;
    4049        1814 :                     n->cooked_expr = NULL;
    4050        1814 :                     $$ = (Node *) n;
    4051             :                 }
    4052             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4053             :                 {
    4054         332 :                     Constraint *n = makeNode(Constraint);
    4055             : 
    4056         332 :                     n->contype = CONSTR_IDENTITY;
    4057         332 :                     n->generated_when = $2;
    4058         332 :                     n->options = $5;
    4059         332 :                     n->location = @1;
    4060         332 :                     $$ = (Node *) n;
    4061             :                 }
    4062             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4063             :                 {
    4064        1710 :                     Constraint *n = makeNode(Constraint);
    4065             : 
    4066        1710 :                     n->contype = CONSTR_GENERATED;
    4067        1710 :                     n->generated_when = $2;
    4068        1710 :                     n->raw_expr = $5;
    4069        1710 :                     n->cooked_expr = NULL;
    4070        1710 :                     n->generated_kind = $7;
    4071        1710 :                     n->location = @1;
    4072             : 
    4073             :                     /*
    4074             :                      * Can't do this in the grammar because of shift/reduce
    4075             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4076             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4077             :                      * can also give a more useful error message and location.
    4078             :                      */
    4079        1710 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4080          12 :                         ereport(ERROR,
    4081             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4082             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4083             :                                  parser_errposition(@2)));
    4084             : 
    4085        1698 :                     $$ = (Node *) n;
    4086             :                 }
    4087             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4088             :                 {
    4089         828 :                     Constraint *n = makeNode(Constraint);
    4090             : 
    4091         828 :                     n->contype = CONSTR_FOREIGN;
    4092         828 :                     n->location = @1;
    4093         828 :                     n->pktable = $2;
    4094         828 :                     n->fk_attrs = NIL;
    4095         828 :                     n->pk_attrs = $3;
    4096         828 :                     n->fk_matchtype = $4;
    4097         828 :                     n->fk_upd_action = ($5)->updateAction->action;
    4098         828 :                     n->fk_del_action = ($5)->deleteAction->action;
    4099         828 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4100         828 :                     n->is_enforced = true;
    4101         828 :                     n->skip_validation = false;
    4102         828 :                     n->initially_valid = true;
    4103         828 :                     $$ = (Node *) n;
    4104             :                 }
    4105             :         ;
    4106             : 
    4107             : opt_unique_null_treatment:
    4108          12 :             NULLS_P DISTINCT        { $$ = true; }
    4109          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4110        7670 :             | /*EMPTY*/             { $$ = true; }
    4111             :         ;
    4112             : 
    4113             : generated_when:
    4114        2070 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4115         182 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4116             :         ;
    4117             : 
    4118             : opt_virtual_or_stored:
    4119         968 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4120         634 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4121         108 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4122             :         ;
    4123             : 
    4124             : /*
    4125             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4126             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4127             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4128             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4129             :  * attribute information to the preceding "real" constraint node, and for
    4130             :  * complaining if attribute clauses appear in the wrong place or wrong
    4131             :  * combinations.
    4132             :  *
    4133             :  * See also ConstraintAttributeSpec, which can be used in places where
    4134             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4135             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4136             :  * might need to allow them here too, but for the moment it doesn't seem
    4137             :  * useful in the statements that use ConstraintAttr.)
    4138             :  */
    4139             : ConstraintAttr:
    4140             :             DEFERRABLE
    4141             :                 {
    4142         102 :                     Constraint *n = makeNode(Constraint);
    4143             : 
    4144         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4145         102 :                     n->location = @1;
    4146         102 :                     $$ = (Node *) n;
    4147             :                 }
    4148             :             | NOT DEFERRABLE
    4149             :                 {
    4150           0 :                     Constraint *n = makeNode(Constraint);
    4151             : 
    4152           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4153           0 :                     n->location = @1;
    4154           0 :                     $$ = (Node *) n;
    4155             :                 }
    4156             :             | INITIALLY DEFERRED
    4157             :                 {
    4158          78 :                     Constraint *n = makeNode(Constraint);
    4159             : 
    4160          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4161          78 :                     n->location = @1;
    4162          78 :                     $$ = (Node *) n;
    4163             :                 }
    4164             :             | INITIALLY IMMEDIATE
    4165             :                 {
    4166           6 :                     Constraint *n = makeNode(Constraint);
    4167             : 
    4168           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4169           6 :                     n->location = @1;
    4170           6 :                     $$ = (Node *) n;
    4171             :                 }
    4172             :             | ENFORCED
    4173             :                 {
    4174          42 :                     Constraint *n = makeNode(Constraint);
    4175             : 
    4176          42 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4177          42 :                     n->location = @1;
    4178          42 :                     $$ = (Node *) n;
    4179             :                 }
    4180             :             | NOT ENFORCED
    4181             :                 {
    4182          66 :                     Constraint *n = makeNode(Constraint);
    4183             : 
    4184          66 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4185          66 :                     n->location = @1;
    4186          66 :                     $$ = (Node *) n;
    4187             :                 }
    4188             :         ;
    4189             : 
    4190             : 
    4191             : TableLikeClause:
    4192             :             LIKE qualified_name TableLikeOptionList
    4193             :                 {
    4194         774 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4195             : 
    4196         774 :                     n->relation = $2;
    4197         774 :                     n->options = $3;
    4198         774 :                     n->relationOid = InvalidOid;
    4199         774 :                     $$ = (Node *) n;
    4200             :                 }
    4201             :         ;
    4202             : 
    4203             : TableLikeOptionList:
    4204         288 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4205           8 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4206         774 :                 | /* EMPTY */                       { $$ = 0; }
    4207             :         ;
    4208             : 
    4209             : TableLikeOption:
    4210          30 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4211           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4212          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4213          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4214          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4215          30 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4216          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4217           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4218          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4219          68 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4220             :         ;
    4221             : 
    4222             : 
    4223             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4224             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4225             :  * - thomas 1997-12-03
    4226             :  */
    4227             : TableConstraint:
    4228             :             CONSTRAINT name ConstraintElem
    4229             :                 {
    4230        4102 :                     Constraint *n = castNode(Constraint, $3);
    4231             : 
    4232        4102 :                     n->conname = $2;
    4233        4102 :                     n->location = @1;
    4234        4102 :                     $$ = (Node *) n;
    4235             :                 }
    4236       13206 :             | ConstraintElem                        { $$ = $1; }
    4237             :         ;
    4238             : 
    4239             : ConstraintElem:
    4240             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4241             :                 {
    4242        1266 :                     Constraint *n = makeNode(Constraint);
    4243             : 
    4244        1266 :                     n->contype = CONSTR_CHECK;
    4245        1266 :                     n->location = @1;
    4246        1266 :                     n->raw_expr = $3;
    4247        1266 :                     n->cooked_expr = NULL;
    4248        1266 :                     processCASbits($5, @5, "CHECK",
    4249             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4250             :                                    &n->is_no_inherit, yyscanner);
    4251        1266 :                     n->initially_valid = !n->skip_validation;
    4252        1266 :                     $$ = (Node *) n;
    4253             :                 }
    4254             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4255             :                 {
    4256         598 :                     Constraint *n = makeNode(Constraint);
    4257             : 
    4258         598 :                     n->contype = CONSTR_NOTNULL;
    4259         598 :                     n->location = @1;
    4260         598 :                     n->keys = list_make1(makeString($3));
    4261         598 :                     processCASbits($4, @4, "NOT NULL",
    4262             :                                    NULL, NULL, NULL, &n->skip_validation,
    4263             :                                    &n->is_no_inherit, yyscanner);
    4264         598 :                     n->initially_valid = !n->skip_validation;
    4265         598 :                     $$ = (Node *) n;
    4266             :                 }
    4267             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4268             :                 ConstraintAttributeSpec
    4269             :                 {
    4270         598 :                     Constraint *n = makeNode(Constraint);
    4271             : 
    4272         598 :                     n->contype = CONSTR_UNIQUE;
    4273         598 :                     n->location = @1;
    4274         598 :                     n->nulls_not_distinct = !$2;
    4275         598 :                     n->keys = $4;
    4276         598 :                     n->without_overlaps = $5;
    4277         598 :                     n->including = $7;
    4278         598 :                     n->options = $8;
    4279         598 :                     n->indexname = NULL;
    4280         598 :                     n->indexspace = $9;
    4281         598 :                     processCASbits($10, @10, "UNIQUE",
    4282             :                                    &n->deferrable, &n->initdeferred, NULL,
    4283             :                                    NULL, NULL, yyscanner);
    4284         598 :                     $$ = (Node *) n;
    4285             :                 }
    4286             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4287             :                 {
    4288        4648 :                     Constraint *n = makeNode(Constraint);
    4289             : 
    4290        4648 :                     n->contype = CONSTR_UNIQUE;
    4291        4648 :                     n->location = @1;
    4292        4648 :                     n->keys = NIL;
    4293        4648 :                     n->including = NIL;
    4294        4648 :                     n->options = NIL;
    4295        4648 :                     n->indexname = $2;
    4296        4648 :                     n->indexspace = NULL;
    4297        4648 :                     processCASbits($3, @3, "UNIQUE",
    4298             :                                    &n->deferrable, &n->initdeferred, NULL,
    4299             :                                    NULL, NULL, yyscanner);
    4300        4648 :                     $$ = (Node *) n;
    4301             :                 }
    4302             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4303             :                 ConstraintAttributeSpec
    4304             :                 {
    4305        2138 :                     Constraint *n = makeNode(Constraint);
    4306             : 
    4307        2138 :                     n->contype = CONSTR_PRIMARY;
    4308        2138 :                     n->location = @1;
    4309        2138 :                     n->keys = $4;
    4310        2138 :                     n->without_overlaps = $5;
    4311        2138 :                     n->including = $7;
    4312        2138 :                     n->options = $8;
    4313        2138 :                     n->indexname = NULL;
    4314        2138 :                     n->indexspace = $9;
    4315        2138 :                     processCASbits($10, @10, "PRIMARY KEY",
    4316             :                                    &n->deferrable, &n->initdeferred, NULL,
    4317             :                                    NULL, NULL, yyscanner);
    4318        2138 :                     $$ = (Node *) n;
    4319             :                 }
    4320             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4321             :                 {
    4322        6018 :                     Constraint *n = makeNode(Constraint);
    4323             : 
    4324        6018 :                     n->contype = CONSTR_PRIMARY;
    4325        6018 :                     n->location = @1;
    4326        6018 :                     n->keys = NIL;
    4327        6018 :                     n->including = NIL;
    4328        6018 :                     n->options = NIL;
    4329        6018 :                     n->indexname = $3;
    4330        6018 :                     n->indexspace = NULL;
    4331        6018 :                     processCASbits($4, @4, "PRIMARY KEY",
    4332             :                                    &n->deferrable, &n->initdeferred, NULL,
    4333             :                                    NULL, NULL, yyscanner);
    4334        6018 :                     $$ = (Node *) n;
    4335             :                 }
    4336             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4337             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4338             :                 ConstraintAttributeSpec
    4339             :                 {
    4340         234 :                     Constraint *n = makeNode(Constraint);
    4341             : 
    4342         234 :                     n->contype = CONSTR_EXCLUSION;
    4343         234 :                     n->location = @1;
    4344         234 :                     n->access_method = $2;
    4345         234 :                     n->exclusions = $4;
    4346         234 :                     n->including = $6;
    4347         234 :                     n->options = $7;
    4348         234 :                     n->indexname = NULL;
    4349         234 :                     n->indexspace = $8;
    4350         234 :                     n->where_clause = $9;
    4351         234 :                     processCASbits($10, @10, "EXCLUDE",
    4352             :                                    &n->deferrable, &n->initdeferred, NULL,
    4353             :                                    NULL, NULL, yyscanner);
    4354         234 :                     $$ = (Node *) n;
    4355             :                 }
    4356             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4357             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4358             :                 {
    4359        1808 :                     Constraint *n = makeNode(Constraint);
    4360             : 
    4361        1808 :                     n->contype = CONSTR_FOREIGN;
    4362        1808 :                     n->location = @1;
    4363        1808 :                     n->pktable = $8;
    4364        1808 :                     n->fk_attrs = $4;
    4365        1808 :                     if ($5)
    4366             :                     {
    4367         290 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4368         290 :                         n->fk_with_period = true;
    4369             :                     }
    4370        1808 :                     n->pk_attrs = linitial($9);
    4371        1808 :                     if (lsecond($9))
    4372             :                     {
    4373         170 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4374         170 :                         n->pk_with_period = true;
    4375             :                     }
    4376        1808 :                     n->fk_matchtype = $10;
    4377        1808 :                     n->fk_upd_action = ($11)->updateAction->action;
    4378        1808 :                     n->fk_del_action = ($11)->deleteAction->action;
    4379        1808 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4380        1808 :                     processCASbits($12, @12, "FOREIGN KEY",
    4381             :                                    &n->deferrable, &n->initdeferred,
    4382             :                                    &n->is_enforced, &n->skip_validation, NULL,
    4383             :                                    yyscanner);
    4384        1808 :                     n->initially_valid = !n->skip_validation;
    4385        1808 :                     $$ = (Node *) n;
    4386             :                 }
    4387             :         ;
    4388             : 
    4389             : /*
    4390             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4391             :  * NOT NULL constraints is different.  For table constraints, we need to
    4392             :  * accept a column name, but for domain constraints, we don't.  (We could
    4393             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4394             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4395             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4396             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4397             :  * standard; we are just living with the bits of inconsistency that have built
    4398             :  * up over time.
    4399             :  */
    4400             : DomainConstraint:
    4401             :             CONSTRAINT name DomainConstraintElem
    4402             :                 {
    4403         164 :                     Constraint *n = castNode(Constraint, $3);
    4404             : 
    4405         164 :                     n->conname = $2;
    4406         164 :                     n->location = @1;
    4407         164 :                     $$ = (Node *) n;
    4408             :                 }
    4409          18 :             | DomainConstraintElem                  { $$ = $1; }
    4410             :         ;
    4411             : 
    4412             : DomainConstraintElem:
    4413             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4414             :                 {
    4415         164 :                     Constraint *n = makeNode(Constraint);
    4416             : 
    4417         164 :                     n->contype = CONSTR_CHECK;
    4418         164 :                     n->location = @1;
    4419         164 :                     n->raw_expr = $3;
    4420         164 :                     n->cooked_expr = NULL;
    4421         164 :                     processCASbits($5, @5, "CHECK",
    4422             :                                    NULL, NULL, NULL, &n->skip_validation,
    4423             :                                    &n->is_no_inherit, yyscanner);
    4424         152 :                     n->is_enforced = true;
    4425         152 :                     n->initially_valid = !n->skip_validation;
    4426         152 :                     $$ = (Node *) n;
    4427             :                 }
    4428             :             | NOT NULL_P ConstraintAttributeSpec
    4429             :                 {
    4430          30 :                     Constraint *n = makeNode(Constraint);
    4431             : 
    4432          30 :                     n->contype = CONSTR_NOTNULL;
    4433          30 :                     n->location = @1;
    4434          30 :                     n->keys = list_make1(makeString("value"));
    4435             :                     /* no NOT VALID, NO INHERIT support */
    4436          30 :                     processCASbits($3, @3, "NOT NULL",
    4437             :                                    NULL, NULL, NULL,
    4438             :                                    NULL, NULL, yyscanner);
    4439          30 :                     n->initially_valid = true;
    4440          30 :                     $$ = (Node *) n;
    4441             :                 }
    4442             :         ;
    4443             : 
    4444         138 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4445        7638 :             | /* EMPTY */                           {  $$ = false; }
    4446             :         ;
    4447             : 
    4448             : opt_without_overlaps:
    4449         554 :             WITHOUT OVERLAPS                        { $$ = true; }
    4450        2182 :             | /*EMPTY*/                             { $$ = false; }
    4451             :     ;
    4452             : 
    4453             : opt_column_list:
    4454       10612 :             '(' columnList ')'                      { $$ = $2; }
    4455       42956 :             | /*EMPTY*/                             { $$ = NIL; }
    4456             :         ;
    4457             : 
    4458             : columnList:
    4459       16850 :             columnElem                              { $$ = list_make1($1); }
    4460       28860 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4461             :         ;
    4462             : 
    4463             : optionalPeriodName:
    4464         460 :             ',' PERIOD columnElem { $$ = $3; }
    4465        2478 :             | /*EMPTY*/               { $$ = NULL; }
    4466             :     ;
    4467             : 
    4468             : opt_column_and_period_list:
    4469        1124 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4470         690 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4471             :         ;
    4472             : 
    4473             : columnElem: ColId
    4474             :                 {
    4475       46170 :                     $$ = (Node *) makeString($1);
    4476             :                 }
    4477             :         ;
    4478             : 
    4479         168 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4480        2802 :              |      /* EMPTY */                     { $$ = NIL; }
    4481             :         ;
    4482             : 
    4483             : key_match:  MATCH FULL
    4484             :             {
    4485          98 :                 $$ = FKCONSTR_MATCH_FULL;
    4486             :             }
    4487             :         | MATCH PARTIAL
    4488             :             {
    4489           0 :                 ereport(ERROR,
    4490             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4491             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4492             :                          parser_errposition(@1)));
    4493             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4494             :             }
    4495             :         | MATCH SIMPLE
    4496             :             {
    4497           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4498             :             }
    4499             :         | /*EMPTY*/
    4500             :             {
    4501        2538 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4502             :             }
    4503             :         ;
    4504             : 
    4505             : ExclusionConstraintList:
    4506         234 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4507             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4508         106 :                                                     { $$ = lappend($1, $3); }
    4509             :         ;
    4510             : 
    4511             : ExclusionConstraintElem: index_elem WITH any_operator
    4512             :             {
    4513         340 :                 $$ = list_make2($1, $3);
    4514             :             }
    4515             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4516             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4517             :             {
    4518           0 :                 $$ = list_make2($1, $5);
    4519             :             }
    4520             :         ;
    4521             : 
    4522             : OptWhereClause:
    4523         464 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4524        1260 :             | /*EMPTY*/                             { $$ = NULL; }
    4525             :         ;
    4526             : 
    4527             : key_actions:
    4528             :             key_update
    4529             :                 {
    4530          74 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4531             : 
    4532          74 :                     n->updateAction = $1;
    4533          74 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4534          74 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4535          74 :                     n->deleteAction->cols = NIL;
    4536          74 :                     $$ = n;
    4537             :                 }
    4538             :             | key_delete
    4539             :                 {
    4540         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4541             : 
    4542         150 :                     n->updateAction = palloc(sizeof(KeyAction));
    4543         150 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4544         150 :                     n->updateAction->cols = NIL;
    4545         150 :                     n->deleteAction = $1;
    4546         150 :                     $$ = n;
    4547             :                 }
    4548             :             | key_update key_delete
    4549             :                 {
    4550         156 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4551             : 
    4552         156 :                     n->updateAction = $1;
    4553         156 :                     n->deleteAction = $2;
    4554         156 :                     $$ = n;
    4555             :                 }
    4556             :             | key_delete key_update
    4557             :                 {
    4558         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4559             : 
    4560         150 :                     n->updateAction = $2;
    4561         150 :                     n->deleteAction = $1;
    4562         150 :                     $$ = n;
    4563             :                 }
    4564             :             | /*EMPTY*/
    4565             :                 {
    4566        2106 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4567             : 
    4568        2106 :                     n->updateAction = palloc(sizeof(KeyAction));
    4569        2106 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4570        2106 :                     n->updateAction->cols = NIL;
    4571        2106 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4572        2106 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4573        2106 :                     n->deleteAction->cols = NIL;
    4574        2106 :                     $$ = n;
    4575             :                 }
    4576             :         ;
    4577             : 
    4578             : key_update: ON UPDATE key_action
    4579             :                 {
    4580         386 :                     if (($3)->cols)
    4581           6 :                         ereport(ERROR,
    4582             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4583             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4584             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4585             :                                  parser_errposition(@1)));
    4586         380 :                     $$ = $3;
    4587             :                 }
    4588             :         ;
    4589             : 
    4590             : key_delete: ON DELETE_P key_action
    4591             :                 {
    4592         456 :                     $$ = $3;
    4593             :                 }
    4594             :         ;
    4595             : 
    4596             : key_action:
    4597             :             NO ACTION
    4598             :                 {
    4599          80 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4600             : 
    4601          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4602          80 :                     n->cols = NIL;
    4603          80 :                     $$ = n;
    4604             :                 }
    4605             :             | RESTRICT
    4606             :                 {
    4607          48 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4608             : 
    4609          48 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4610          48 :                     n->cols = NIL;
    4611          48 :                     $$ = n;
    4612             :                 }
    4613             :             | CASCADE
    4614             :                 {
    4615         422 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4616             : 
    4617         422 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4618         422 :                     n->cols = NIL;
    4619         422 :                     $$ = n;
    4620             :                 }
    4621             :             | SET NULL_P opt_column_list
    4622             :                 {
    4623         190 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4624             : 
    4625         190 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4626         190 :                     n->cols = $3;
    4627         190 :                     $$ = n;
    4628             :                 }
    4629             :             | SET DEFAULT opt_column_list
    4630             :                 {
    4631         102 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4632             : 
    4633         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4634         102 :                     n->cols = $3;
    4635         102 :                     $$ = n;
    4636             :                 }
    4637             :         ;
    4638             : 
    4639        2090 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4640       27974 :             | /*EMPTY*/                             { $$ = NIL; }
    4641             :         ;
    4642             : 
    4643             : /* Optional partition key specification */
    4644        5028 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4645       32732 :             | /*EMPTY*/         { $$ = NULL; }
    4646             :         ;
    4647             : 
    4648             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4649             :                 {
    4650        5034 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4651             : 
    4652        5034 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4653        5028 :                     n->partParams = $5;
    4654        5028 :                     n->location = @1;
    4655             : 
    4656        5028 :                     $$ = n;
    4657             :                 }
    4658             :         ;
    4659             : 
    4660        5034 : part_params:    part_elem                       { $$ = list_make1($1); }
    4661         456 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4662             :         ;
    4663             : 
    4664             : part_elem: ColId opt_collate opt_qualified_name
    4665             :                 {
    4666        5186 :                     PartitionElem *n = makeNode(PartitionElem);
    4667             : 
    4668        5186 :                     n->name = $1;
    4669        5186 :                     n->expr = NULL;
    4670        5186 :                     n->collation = $2;
    4671        5186 :                     n->opclass = $3;
    4672        5186 :                     n->location = @1;
    4673        5186 :                     $$ = n;
    4674             :                 }
    4675             :             | func_expr_windowless opt_collate opt_qualified_name
    4676             :                 {
    4677         130 :                     PartitionElem *n = makeNode(PartitionElem);
    4678             : 
    4679         130 :                     n->name = NULL;
    4680         130 :                     n->expr = $1;
    4681         130 :                     n->collation = $2;
    4682         130 :                     n->opclass = $3;
    4683         130 :                     n->location = @1;
    4684         130 :                     $$ = n;
    4685             :                 }
    4686             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4687             :                 {
    4688         174 :                     PartitionElem *n = makeNode(PartitionElem);
    4689             : 
    4690         174 :                     n->name = NULL;
    4691         174 :                     n->expr = $2;
    4692         174 :                     n->collation = $4;
    4693         174 :                     n->opclass = $5;
    4694         174 :                     n->location = @1;
    4695         174 :                     $$ = n;
    4696             :                 }
    4697             :         ;
    4698             : 
    4699             : table_access_method_clause:
    4700         122 :             USING name                          { $$ = $2; }
    4701       39568 :             | /*EMPTY*/                         { $$ = NULL; }
    4702             :         ;
    4703             : 
    4704             : /* WITHOUT OIDS is legacy only */
    4705             : OptWith:
    4706         754 :             WITH reloptions             { $$ = $2; }
    4707          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4708       38324 :             | /*EMPTY*/                 { $$ = NIL; }
    4709             :         ;
    4710             : 
    4711          60 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4712         104 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4713          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4714       38914 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4715             :         ;
    4716             : 
    4717         216 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4718       46126 :             | /*EMPTY*/                             { $$ = NULL; }
    4719             :         ;
    4720             : 
    4721          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4722        9174 :             | /*EMPTY*/                             { $$ = NULL; }
    4723             :         ;
    4724             : 
    4725       10666 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4726             :         ;
    4727             : 
    4728             : /*****************************************************************************
    4729             :  *
    4730             :  *      QUERY :
    4731             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4732             :  *                  ON expression-list FROM from_list
    4733             :  *
    4734             :  * Note: the expectation here is that the clauses after ON are a subset of
    4735             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4736             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4737             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4738             :  * errors as necessary at execution.
    4739             :  *
    4740             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4741             :  *
    4742             :  *****************************************************************************/
    4743             : 
    4744             : CreateStatsStmt:
    4745             :             CREATE STATISTICS opt_qualified_name
    4746             :             opt_name_list ON stats_params FROM from_list
    4747             :                 {
    4748         724 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4749             : 
    4750         724 :                     n->defnames = $3;
    4751         724 :                     n->stat_types = $4;
    4752         724 :                     n->exprs = $6;
    4753         724 :                     n->relations = $8;
    4754         724 :                     n->stxcomment = NULL;
    4755         724 :                     n->if_not_exists = false;
    4756         724 :                     $$ = (Node *) n;
    4757             :                 }
    4758             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4759             :             opt_name_list ON stats_params FROM from_list
    4760             :                 {
    4761          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4762             : 
    4763          12 :                     n->defnames = $6;
    4764          12 :                     n->stat_types = $7;
    4765          12 :                     n->exprs = $9;
    4766          12 :                     n->relations = $11;
    4767          12 :                     n->stxcomment = NULL;
    4768          12 :                     n->if_not_exists = true;
    4769          12 :                     $$ = (Node *) n;
    4770             :                 }
    4771             :             ;
    4772             : 
    4773             : /*
    4774             :  * Statistics attributes can be either simple column references, or arbitrary
    4775             :  * expressions in parens.  For compatibility with index attributes permitted
    4776             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4777             :  * written without parens.
    4778             :  */
    4779             : 
    4780         748 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4781         972 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4782             :         ;
    4783             : 
    4784             : stats_param:    ColId
    4785             :                 {
    4786        1216 :                     $$ = makeNode(StatsElem);
    4787        1216 :                     $$->name = $1;
    4788        1216 :                     $$->expr = NULL;
    4789             :                 }
    4790             :             | func_expr_windowless
    4791             :                 {
    4792          32 :                     $$ = makeNode(StatsElem);
    4793          32 :                     $$->name = NULL;
    4794          32 :                     $$->expr = $1;
    4795             :                 }
    4796             :             | '(' a_expr ')'
    4797             :                 {
    4798         472 :                     $$ = makeNode(StatsElem);
    4799         472 :                     $$->name = NULL;
    4800         472 :                     $$->expr = $2;
    4801             :                 }
    4802             :         ;
    4803             : 
    4804             : /*****************************************************************************
    4805             :  *
    4806             :  *      QUERY :
    4807             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4808             :  *                  SET STATISTICS  <SignedIconst>
    4809             :  *
    4810             :  *****************************************************************************/
    4811             : 
    4812             : AlterStatsStmt:
    4813             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4814             :                 {
    4815          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4816             : 
    4817          20 :                     n->defnames = $3;
    4818          20 :                     n->missing_ok = false;
    4819          20 :                     n->stxstattarget = $6;
    4820          20 :                     $$ = (Node *) n;
    4821             :                 }
    4822             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4823             :                 {
    4824           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4825             : 
    4826           6 :                     n->defnames = $5;
    4827           6 :                     n->missing_ok = true;
    4828           6 :                     n->stxstattarget = $8;
    4829           6 :                     $$ = (Node *) n;
    4830             :                 }
    4831             :             ;
    4832             : 
    4833             : /*****************************************************************************
    4834             :  *
    4835             :  *      QUERY :
    4836             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4837             :  *
    4838             :  *
    4839             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4840             :  *
    4841             :  *****************************************************************************/
    4842             : 
    4843             : CreateAsStmt:
    4844             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4845             :                 {
    4846        1214 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4847             : 
    4848        1214 :                     ctas->query = $6;
    4849        1214 :                     ctas->into = $4;
    4850        1214 :                     ctas->objtype = OBJECT_TABLE;
    4851        1214 :                     ctas->is_select_into = false;
    4852        1214 :                     ctas->if_not_exists = false;
    4853             :                     /* cram additional flags into the IntoClause */
    4854        1214 :                     $4->rel->relpersistence = $2;
    4855        1214 :                     $4->skipData = !($7);
    4856        1214 :                     $$ = (Node *) ctas;
    4857             :                 }
    4858             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4859             :                 {
    4860          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4861             : 
    4862          52 :                     ctas->query = $9;
    4863          52 :                     ctas->into = $7;
    4864          52 :                     ctas->objtype = OBJECT_TABLE;
    4865          52 :                     ctas->is_select_into = false;
    4866          52 :                     ctas->if_not_exists = true;
    4867             :                     /* cram additional flags into the IntoClause */
    4868          52 :                     $7->rel->relpersistence = $2;
    4869          52 :                     $7->skipData = !($10);
    4870          52 :                     $$ = (Node *) ctas;
    4871             :                 }
    4872             :         ;
    4873             : 
    4874             : create_as_target:
    4875             :             qualified_name opt_column_list table_access_method_clause
    4876             :             OptWith OnCommitOption OptTableSpace
    4877             :                 {
    4878        1354 :                     $$ = makeNode(IntoClause);
    4879        1354 :                     $$->rel = $1;
    4880        1354 :                     $$->colNames = $2;
    4881        1354 :                     $$->accessMethod = $3;
    4882        1354 :                     $$->options = $4;
    4883        1354 :                     $$->onCommit = $5;
    4884        1354 :                     $$->tableSpaceName = $6;
    4885        1354 :                     $$->viewQuery = NULL;
    4886        1354 :                     $$->skipData = false;        /* might get changed later */
    4887             :                 }
    4888             :         ;
    4889             : 
    4890             : opt_with_data:
    4891          36 :             WITH DATA_P                             { $$ = true; }
    4892         218 :             | WITH NO DATA_P                        { $$ = false; }
    4893        1950 :             | /*EMPTY*/                             { $$ = true; }
    4894             :         ;
    4895             : 
    4896             : 
    4897             : /*****************************************************************************
    4898             :  *
    4899             :  *      QUERY :
    4900             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4901             :  *
    4902             :  *****************************************************************************/
    4903             : 
    4904             : CreateMatViewStmt:
    4905             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4906             :                 {
    4907         534 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4908             : 
    4909         534 :                     ctas->query = $7;
    4910         534 :                     ctas->into = $5;
    4911         534 :                     ctas->objtype = OBJECT_MATVIEW;
    4912         534 :                     ctas->is_select_into = false;
    4913         534 :                     ctas->if_not_exists = false;
    4914             :                     /* cram additional flags into the IntoClause */
    4915         534 :                     $5->rel->relpersistence = $2;
    4916         534 :                     $5->skipData = !($8);
    4917         534 :                     $$ = (Node *) ctas;
    4918             :                 }
    4919             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4920             :                 {
    4921          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4922             : 
    4923          48 :                     ctas->query = $10;
    4924          48 :                     ctas->into = $8;
    4925          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4926          48 :                     ctas->is_select_into = false;
    4927          48 :                     ctas->if_not_exists = true;
    4928             :                     /* cram additional flags into the IntoClause */
    4929          48 :                     $8->rel->relpersistence = $2;
    4930          48 :                     $8->skipData = !($11);
    4931          48 :                     $$ = (Node *) ctas;
    4932             :                 }
    4933             :         ;
    4934             : 
    4935             : create_mv_target:
    4936             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4937             :                 {
    4938         582 :                     $$ = makeNode(IntoClause);
    4939         582 :                     $$->rel = $1;
    4940         582 :                     $$->colNames = $2;
    4941         582 :                     $$->accessMethod = $3;
    4942         582 :                     $$->options = $4;
    4943         582 :                     $$->onCommit = ONCOMMIT_NOOP;
    4944         582 :                     $$->tableSpaceName = $5;
    4945         582 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4946         582 :                     $$->skipData = false;        /* might get changed later */
    4947             :                 }
    4948             :         ;
    4949             : 
    4950           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4951         582 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4952             :         ;
    4953             : 
    4954             : 
    4955             : /*****************************************************************************
    4956             :  *
    4957             :  *      QUERY :
    4958             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4959             :  *
    4960             :  *****************************************************************************/
    4961             : 
    4962             : RefreshMatViewStmt:
    4963             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4964             :                 {
    4965         268 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4966             : 
    4967         268 :                     n->concurrent = $4;
    4968         268 :                     n->relation = $5;
    4969         268 :                     n->skipData = !($6);
    4970         268 :                     $$ = (Node *) n;
    4971             :                 }
    4972             :         ;
    4973             : 
    4974             : 
    4975             : /*****************************************************************************
    4976             :  *
    4977             :  *      QUERY :
    4978             :  *              CREATE SEQUENCE seqname
    4979             :  *              ALTER SEQUENCE seqname
    4980             :  *
    4981             :  *****************************************************************************/
    4982             : 
    4983             : CreateSeqStmt:
    4984             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4985             :                 {
    4986         656 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4987             : 
    4988         656 :                     $4->relpersistence = $2;
    4989         656 :                     n->sequence = $4;
    4990         656 :                     n->options = $5;
    4991         656 :                     n->ownerId = InvalidOid;
    4992         656 :                     n->if_not_exists = false;
    4993         656 :                     $$ = (Node *) n;
    4994             :                 }
    4995             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4996             :                 {
    4997          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4998             : 
    4999          24 :                     $7->relpersistence = $2;
    5000          24 :                     n->sequence = $7;
    5001          24 :                     n->options = $8;
    5002          24 :                     n->ownerId = InvalidOid;
    5003          24 :                     n->if_not_exists = true;
    5004          24 :                     $$ = (Node *) n;
    5005             :                 }
    5006             :         ;
    5007             : 
    5008             : AlterSeqStmt:
    5009             :             ALTER SEQUENCE qualified_name SeqOptList
    5010             :                 {
    5011         184 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5012             : 
    5013         184 :                     n->sequence = $3;
    5014         184 :                     n->options = $4;
    5015         184 :                     n->missing_ok = false;
    5016         184 :                     $$ = (Node *) n;
    5017             :                 }
    5018             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    5019             :                 {
    5020          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5021             : 
    5022          12 :                     n->sequence = $5;
    5023          12 :                     n->options = $6;
    5024          12 :                     n->missing_ok = true;
    5025          12 :                     $$ = (Node *) n;
    5026             :                 }
    5027             : 
    5028             :         ;
    5029             : 
    5030         262 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    5031         418 :             | /*EMPTY*/                             { $$ = NIL; }
    5032             :         ;
    5033             : 
    5034          74 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    5035         424 :             | /*EMPTY*/                             { $$ = NIL; }
    5036             :         ;
    5037             : 
    5038         532 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    5039         802 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    5040             :         ;
    5041             : 
    5042             : SeqOptElem: AS SimpleTypename
    5043             :                 {
    5044         190 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5045             :                 }
    5046             :             | CACHE NumericOnly
    5047             :                 {
    5048         130 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5049             :                 }
    5050             :             | CYCLE
    5051             :                 {
    5052          34 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5053             :                 }
    5054             :             | NO CYCLE
    5055             :                 {
    5056          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5057             :                 }
    5058             :             | INCREMENT opt_by NumericOnly
    5059             :                 {
    5060         246 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5061             :                 }
    5062             :             | LOGGED
    5063             :                 {
    5064           2 :                     $$ = makeDefElem("logged", NULL, @1);
    5065             :                 }
    5066             :             | MAXVALUE NumericOnly
    5067             :                 {
    5068          68 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5069             :                 }
    5070             :             | MINVALUE NumericOnly
    5071             :                 {
    5072          68 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5073             :                 }
    5074             :             | NO MAXVALUE
    5075             :                 {
    5076         108 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5077             :                 }
    5078             :             | NO MINVALUE
    5079             :                 {
    5080         108 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5081             :                 }
    5082             :             | OWNED BY any_name
    5083             :                 {
    5084          72 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5085             :                 }
    5086             :             | SEQUENCE NAME_P any_name
    5087             :                 {
    5088          44 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5089             :                 }
    5090             :             | START opt_with NumericOnly
    5091             :                 {
    5092         236 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5093             :                 }
    5094             :             | RESTART
    5095             :                 {
    5096           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5097             :                 }
    5098             :             | RESTART opt_with NumericOnly
    5099             :                 {
    5100          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5101             :                 }
    5102             :             | UNLOGGED
    5103             :                 {
    5104           2 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5105             :                 }
    5106             :         ;
    5107             : 
    5108             : opt_by:     BY
    5109             :             | /* EMPTY */
    5110             :       ;
    5111             : 
    5112             : NumericOnly:
    5113         324 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5114           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5115             :             | '-' FCONST
    5116             :                 {
    5117          20 :                     Float      *f = makeFloat($2);
    5118             : 
    5119          20 :                     doNegateFloat(f);
    5120          20 :                     $$ = (Node *) f;
    5121             :                 }
    5122       12840 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5123             :         ;
    5124             : 
    5125          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5126           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5127             :         ;
    5128             : 
    5129             : /*****************************************************************************
    5130             :  *
    5131             :  *      QUERIES :
    5132             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5133             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5134             :  *
    5135             :  *****************************************************************************/
    5136             : 
    5137             : CreatePLangStmt:
    5138             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5139             :             {
    5140             :                 /*
    5141             :                  * We now interpret parameterless CREATE LANGUAGE as
    5142             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5143             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5144             :                  * seems more useful than throwing an error.  We just
    5145             :                  * ignore TRUSTED, as the previous code would have too.
    5146             :                  */
    5147           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5148             : 
    5149           0 :                 n->if_not_exists = $2;
    5150           0 :                 n->extname = $6;
    5151           0 :                 n->options = NIL;
    5152           0 :                 $$ = (Node *) n;
    5153             :             }
    5154             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5155             :               HANDLER handler_name opt_inline_handler opt_validator
    5156             :             {
    5157         142 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5158             : 
    5159         142 :                 n->replace = $2;
    5160         142 :                 n->plname = $6;
    5161         142 :                 n->plhandler = $8;
    5162         142 :                 n->plinline = $9;
    5163         142 :                 n->plvalidator = $10;
    5164         142 :                 n->pltrusted = $3;
    5165         142 :                 $$ = (Node *) n;
    5166             :             }
    5167             :         ;
    5168             : 
    5169             : opt_trusted:
    5170         112 :             TRUSTED                                 { $$ = true; }
    5171          38 :             | /*EMPTY*/                             { $$ = false; }
    5172             :         ;
    5173             : 
    5174             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5175             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5176             :  * Work around by using simple names, instead.
    5177             :  */
    5178             : handler_name:
    5179         554 :             name                        { $$ = list_make1(makeString($1)); }
    5180           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5181             :         ;
    5182             : 
    5183             : opt_inline_handler:
    5184         124 :             INLINE_P handler_name                   { $$ = $2; }
    5185          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5186             :         ;
    5187             : 
    5188             : validator_clause:
    5189         124 :             VALIDATOR handler_name                  { $$ = $2; }
    5190           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5191             :         ;
    5192             : 
    5193             : opt_validator:
    5194         124 :             validator_clause                        { $$ = $1; }
    5195          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5196             :         ;
    5197             : 
    5198             : opt_procedural:
    5199             :             PROCEDURAL
    5200             :             | /*EMPTY*/
    5201             :         ;
    5202             : 
    5203             : /*****************************************************************************
    5204             :  *
    5205             :  *      QUERY:
    5206             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5207             :  *
    5208             :  *****************************************************************************/
    5209             : 
    5210             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5211             :                 {
    5212         130 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5213             : 
    5214         130 :                     n->tablespacename = $3;
    5215         130 :                     n->owner = $4;
    5216         130 :                     n->location = $6;
    5217         130 :                     n->options = $7;
    5218         130 :                     $$ = (Node *) n;
    5219             :                 }
    5220             :         ;
    5221             : 
    5222          10 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5223         120 :             | /*EMPTY */                { $$ = NULL; }
    5224             :         ;
    5225             : 
    5226             : /*****************************************************************************
    5227             :  *
    5228             :  *      QUERY :
    5229             :  *              DROP TABLESPACE <tablespace>
    5230             :  *
    5231             :  *      No need for drop behaviour as we cannot implement dependencies for
    5232             :  *      objects in other databases; we can only support RESTRICT.
    5233             :  *
    5234             :  ****************************************************************************/
    5235             : 
    5236             : DropTableSpaceStmt: DROP TABLESPACE name
    5237             :                 {
    5238          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5239             : 
    5240          64 :                     n->tablespacename = $3;
    5241          64 :                     n->missing_ok = false;
    5242          64 :                     $$ = (Node *) n;
    5243             :                 }
    5244             :                 |  DROP TABLESPACE IF_P EXISTS name
    5245             :                 {
    5246           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5247             : 
    5248           0 :                     n->tablespacename = $5;
    5249           0 :                     n->missing_ok = true;
    5250           0 :                     $$ = (Node *) n;
    5251             :                 }
    5252             :         ;
    5253             : 
    5254             : /*****************************************************************************
    5255             :  *
    5256             :  *      QUERY:
    5257             :  *             CREATE EXTENSION extension
    5258             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5259             :  *
    5260             :  *****************************************************************************/
    5261             : 
    5262             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5263             :                 {
    5264         524 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5265             : 
    5266         524 :                     n->extname = $3;
    5267         524 :                     n->if_not_exists = false;
    5268         524 :                     n->options = $5;
    5269         524 :                     $$ = (Node *) n;
    5270             :                 }
    5271             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5272             :                 {
    5273          18 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5274             : 
    5275          18 :                     n->extname = $6;
    5276          18 :                     n->if_not_exists = true;
    5277          18 :                     n->options = $8;
    5278          18 :                     $$ = (Node *) n;
    5279             :                 }
    5280             :         ;
    5281             : 
    5282             : create_extension_opt_list:
    5283             :             create_extension_opt_list create_extension_opt_item
    5284          98 :                 { $$ = lappend($1, $2); }
    5285             :             | /* EMPTY */
    5286         542 :                 { $$ = NIL; }
    5287             :         ;
    5288             : 
    5289             : create_extension_opt_item:
    5290             :             SCHEMA name
    5291             :                 {
    5292          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5293             :                 }
    5294             :             | VERSION_P NonReservedWord_or_Sconst
    5295             :                 {
    5296          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5297             :                 }
    5298             :             | FROM NonReservedWord_or_Sconst
    5299             :                 {
    5300           0 :                     ereport(ERROR,
    5301             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5302             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5303             :                              parser_errposition(@1)));
    5304             :                 }
    5305             :             | CASCADE
    5306             :                 {
    5307          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5308             :                 }
    5309             :         ;
    5310             : 
    5311             : /*****************************************************************************
    5312             :  *
    5313             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5314             :  *
    5315             :  *****************************************************************************/
    5316             : 
    5317             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5318             :                 {
    5319          40 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5320             : 
    5321          40 :                     n->extname = $3;
    5322          40 :                     n->options = $5;
    5323          40 :                     $$ = (Node *) n;
    5324             :                 }
    5325             :         ;
    5326             : 
    5327             : alter_extension_opt_list:
    5328             :             alter_extension_opt_list alter_extension_opt_item
    5329          40 :                 { $$ = lappend($1, $2); }
    5330             :             | /* EMPTY */
    5331          40 :                 { $$ = NIL; }
    5332             :         ;
    5333             : 
    5334             : alter_extension_opt_item:
    5335             :             TO NonReservedWord_or_Sconst
    5336             :                 {
    5337          40 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5338             :                 }
    5339             :         ;
    5340             : 
    5341             : /*****************************************************************************
    5342             :  *
    5343             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5344             :  *
    5345             :  *****************************************************************************/
    5346             : 
    5347             : AlterExtensionContentsStmt:
    5348             :             ALTER EXTENSION name add_drop object_type_name name
    5349             :                 {
    5350          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5351             : 
    5352          18 :                     n->extname = $3;
    5353          18 :                     n->action = $4;
    5354          18 :                     n->objtype = $5;
    5355          18 :                     n->object = (Node *) makeString($6);
    5356          18 :                     $$ = (Node *) n;
    5357             :                 }
    5358             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5359             :                 {
    5360          88 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5361             : 
    5362          88 :                     n->extname = $3;
    5363          88 :                     n->action = $4;
    5364          88 :                     n->objtype = $5;
    5365          88 :                     n->object = (Node *) $6;
    5366          88 :                     $$ = (Node *) n;
    5367             :                 }
    5368             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5369             :                 {
    5370           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5371             : 
    5372           8 :                     n->extname = $3;
    5373           8 :                     n->action = $4;
    5374           8 :                     n->objtype = OBJECT_AGGREGATE;
    5375           8 :                     n->object = (Node *) $6;
    5376           8 :                     $$ = (Node *) n;
    5377             :                 }
    5378             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5379             :                 {
    5380           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5381             : 
    5382           4 :                     n->extname = $3;
    5383           4 :                     n->action = $4;
    5384           4 :                     n->objtype = OBJECT_CAST;
    5385           4 :                     n->object = (Node *) list_make2($7, $9);
    5386           4 :                     $$ = (Node *) n;
    5387             :                 }
    5388             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5389             :                 {
    5390           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5391             : 
    5392           0 :                     n->extname = $3;
    5393           0 :                     n->action = $4;
    5394           0 :                     n->objtype = OBJECT_DOMAIN;
    5395           0 :                     n->object = (Node *) $6;
    5396           0 :                     $$ = (Node *) n;
    5397             :                 }
    5398             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5399             :                 {
    5400         110 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5401             : 
    5402         110 :                     n->extname = $3;
    5403         110 :                     n->action = $4;
    5404         110 :                     n->objtype = OBJECT_FUNCTION;
    5405         110 :                     n->object = (Node *) $6;
    5406         110 :                     $$ = (Node *) n;
    5407             :                 }
    5408             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5409             :                 {
    5410          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5411             : 
    5412          18 :                     n->extname = $3;
    5413          18 :                     n->action = $4;
    5414          18 :                     n->objtype = OBJECT_OPERATOR;
    5415          18 :                     n->object = (Node *) $6;
    5416          18 :                     $$ = (Node *) n;
    5417             :                 }
    5418             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5419             :                 {
    5420           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5421             : 
    5422           4 :                     n->extname = $3;
    5423           4 :                     n->action = $4;
    5424           4 :                     n->objtype = OBJECT_OPCLASS;
    5425           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5426           4 :                     $$ = (Node *) n;
    5427             :                 }
    5428             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5429             :                 {
    5430           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5431             : 
    5432           4 :                     n->extname = $3;
    5433           4 :                     n->action = $4;
    5434           4 :                     n->objtype = OBJECT_OPFAMILY;
    5435           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5436           4 :                     $$ = (Node *) n;
    5437             :                 }
    5438             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5439             :                 {
    5440           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5441             : 
    5442           0 :                     n->extname = $3;
    5443           0 :                     n->action = $4;
    5444           0 :                     n->objtype = OBJECT_PROCEDURE;
    5445           0 :                     n->object = (Node *) $6;
    5446           0 :                     $$ = (Node *) n;
    5447             :                 }
    5448             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5449             :                 {
    5450           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5451             : 
    5452           0 :                     n->extname = $3;
    5453           0 :                     n->action = $4;
    5454           0 :                     n->objtype = OBJECT_ROUTINE;
    5455           0 :                     n->object = (Node *) $6;
    5456           0 :                     $$ = (Node *) n;
    5457             :                 }
    5458             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5459             :                 {
    5460           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5461             : 
    5462           4 :                     n->extname = $3;
    5463           4 :                     n->action = $4;
    5464           4 :                     n->objtype = OBJECT_TRANSFORM;
    5465           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5466           4 :                     $$ = (Node *) n;
    5467             :                 }
    5468             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5469             :                 {
    5470           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5471             : 
    5472           8 :                     n->extname = $3;
    5473           8 :                     n->action = $4;
    5474           8 :                     n->objtype = OBJECT_TYPE;
    5475           8 :                     n->object = (Node *) $6;
    5476           8 :                     $$ = (Node *) n;
    5477             :                 }
    5478             :         ;
    5479             : 
    5480             : /*****************************************************************************
    5481             :  *
    5482             :  *      QUERY:
    5483             :  *             CREATE FOREIGN DATA WRAPPER name options
    5484             :  *
    5485             :  *****************************************************************************/
    5486             : 
    5487             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5488             :                 {
    5489         206 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5490             : 
    5491         206 :                     n->fdwname = $5;
    5492         206 :                     n->func_options = $6;
    5493         206 :                     n->options = $7;
    5494         206 :                     $$ = (Node *) n;
    5495             :                 }
    5496             :         ;
    5497             : 
    5498             : fdw_option:
    5499          56 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5500           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5501          48 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5502           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5503             :         ;
    5504             : 
    5505             : fdw_options:
    5506          90 :             fdw_option                          { $$ = list_make1($1); }
    5507          20 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5508             :         ;
    5509             : 
    5510             : opt_fdw_options:
    5511          54 :             fdw_options                         { $$ = $1; }
    5512         244 :             | /*EMPTY*/                         { $$ = NIL; }
    5513             :         ;
    5514             : 
    5515             : /*****************************************************************************
    5516             :  *
    5517             :  *      QUERY :
    5518             :  *              ALTER FOREIGN DATA WRAPPER name options
    5519             :  *
    5520             :  ****************************************************************************/
    5521             : 
    5522             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5523             :                 {
    5524          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5525             : 
    5526          86 :                     n->fdwname = $5;
    5527          86 :                     n->func_options = $6;
    5528          86 :                     n->options = $7;
    5529          86 :                     $$ = (Node *) n;
    5530             :                 }
    5531             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5532             :                 {
    5533          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5534             : 
    5535          36 :                     n->fdwname = $5;
    5536          36 :                     n->func_options = $6;
    5537          36 :                     n->options = NIL;
    5538          36 :                     $$ = (Node *) n;
    5539             :                 }
    5540             :         ;
    5541             : 
    5542             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5543             : create_generic_options:
    5544         740 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5545       68158 :             | /*EMPTY*/                                 { $$ = NIL; }
    5546             :         ;
    5547             : 
    5548             : generic_option_list:
    5549             :             generic_option_elem
    5550             :                 {
    5551         740 :                     $$ = list_make1($1);
    5552             :                 }
    5553             :             | generic_option_list ',' generic_option_elem
    5554             :                 {
    5555         480 :                     $$ = lappend($1, $3);
    5556             :                 }
    5557             :         ;
    5558             : 
    5559             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5560             : alter_generic_options:
    5561         508 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5562             :         ;
    5563             : 
    5564             : alter_generic_option_list:
    5565             :             alter_generic_option_elem
    5566             :                 {
    5567         508 :                     $$ = list_make1($1);
    5568             :                 }
    5569             :             | alter_generic_option_list ',' alter_generic_option_elem
    5570             :                 {
    5571         168 :                     $$ = lappend($1, $3);
    5572             :                 }
    5573             :         ;
    5574             : 
    5575             : alter_generic_option_elem:
    5576             :             generic_option_elem
    5577             :                 {
    5578         200 :                     $$ = $1;
    5579             :                 }
    5580             :             | SET generic_option_elem
    5581             :                 {
    5582         128 :                     $$ = $2;
    5583         128 :                     $$->defaction = DEFELEM_SET;
    5584             :                 }
    5585             :             | ADD_P generic_option_elem
    5586             :                 {
    5587         220 :                     $$ = $2;
    5588         220 :                     $$->defaction = DEFELEM_ADD;
    5589             :                 }
    5590             :             | DROP generic_option_name
    5591             :                 {
    5592         128 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5593             :                 }
    5594             :         ;
    5595             : 
    5596             : generic_option_elem:
    5597             :             generic_option_name generic_option_arg
    5598             :                 {
    5599        1768 :                     $$ = makeDefElem($1, $2, @1);
    5600             :                 }
    5601             :         ;
    5602             : 
    5603             : generic_option_name:
    5604        1896 :                 ColLabel            { $$ = $1; }
    5605             :         ;
    5606             : 
    5607             : /* We could use def_arg here, but the spec only requires string literals */
    5608             : generic_option_arg:
    5609        1768 :                 Sconst              { $$ = (Node *) makeString($1); }
    5610             :         ;
    5611             : 
    5612             : /*****************************************************************************
    5613             :  *
    5614             :  *      QUERY:
    5615             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5616             :  *
    5617             :  *****************************************************************************/
    5618             : 
    5619             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5620             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5621             :                 {
    5622         272 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5623             : 
    5624         272 :                     n->servername = $3;
    5625         272 :                     n->servertype = $4;
    5626         272 :                     n->version = $5;
    5627         272 :                     n->fdwname = $9;
    5628         272 :                     n->options = $10;
    5629         272 :                     n->if_not_exists = false;
    5630         272 :                     $$ = (Node *) n;
    5631             :                 }
    5632             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5633             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5634             :                 {
    5635          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5636             : 
    5637          24 :                     n->servername = $6;
    5638          24 :                     n->servertype = $7;
    5639          24 :                     n->version = $8;
    5640          24 :                     n->fdwname = $12;
    5641          24 :                     n->options = $13;
    5642          24 :                     n->if_not_exists = true;
    5643          24 :                     $$ = (Node *) n;
    5644             :                 }
    5645             :         ;
    5646             : 
    5647             : opt_type:
    5648          18 :             TYPE_P Sconst           { $$ = $2; }
    5649         278 :             | /*EMPTY*/             { $$ = NULL; }
    5650             :         ;
    5651             : 
    5652             : 
    5653             : foreign_server_version:
    5654          66 :             VERSION_P Sconst        { $$ = $2; }
    5655           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5656             :         ;
    5657             : 
    5658             : opt_foreign_server_version:
    5659          18 :             foreign_server_version  { $$ = $1; }
    5660         278 :             | /*EMPTY*/             { $$ = NULL; }
    5661             :         ;
    5662             : 
    5663             : /*****************************************************************************
    5664             :  *
    5665             :  *      QUERY :
    5666             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5667             :  *
    5668             :  ****************************************************************************/
    5669             : 
    5670             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5671             :                 {
    5672           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5673             : 
    5674           6 :                     n->servername = $3;
    5675           6 :                     n->version = $4;
    5676           6 :                     n->options = $5;
    5677           6 :                     n->has_version = true;
    5678           6 :                     $$ = (Node *) n;
    5679             :                 }
    5680             :             | ALTER SERVER name foreign_server_version
    5681             :                 {
    5682          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5683             : 
    5684          42 :                     n->servername = $3;
    5685          42 :                     n->version = $4;
    5686          42 :                     n->has_version = true;
    5687          42 :                     $$ = (Node *) n;
    5688             :                 }
    5689             :             | ALTER SERVER name alter_generic_options
    5690             :                 {
    5691         184 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5692             : 
    5693         184 :                     n->servername = $3;
    5694         184 :                     n->options = $4;
    5695         184 :                     $$ = (Node *) n;
    5696             :                 }
    5697             :         ;
    5698             : 
    5699             : /*****************************************************************************
    5700             :  *
    5701             :  *      QUERY:
    5702             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5703             :  *
    5704             :  *****************************************************************************/
    5705             : 
    5706             : CreateForeignTableStmt:
    5707             :         CREATE FOREIGN TABLE qualified_name
    5708             :             '(' OptTableElementList ')'
    5709             :             OptInherit SERVER name create_generic_options
    5710             :                 {
    5711         396 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5712             : 
    5713         396 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5714         396 :                     n->base.relation = $4;
    5715         396 :                     n->base.tableElts = $6;
    5716         396 :                     n->base.inhRelations = $8;
    5717         396 :                     n->base.ofTypename = NULL;
    5718         396 :                     n->base.constraints = NIL;
    5719         396 :                     n->base.options = NIL;
    5720         396 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5721         396 :                     n->base.tablespacename = NULL;
    5722         396 :                     n->base.if_not_exists = false;
    5723             :                     /* FDW-specific data */
    5724         396 :                     n->servername = $10;
    5725         396 :                     n->options = $11;
    5726         396 :                     $$ = (Node *) n;
    5727             :                 }
    5728             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5729             :             '(' OptTableElementList ')'
    5730             :             OptInherit SERVER name create_generic_options
    5731             :                 {
    5732           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5733             : 
    5734           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5735           0 :                     n->base.relation = $7;
    5736           0 :                     n->base.tableElts = $9;
    5737           0 :                     n->base.inhRelations = $11;
    5738           0 :                     n->base.ofTypename = NULL;
    5739           0 :                     n->base.constraints = NIL;
    5740           0 :                     n->base.options = NIL;
    5741           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5742           0 :                     n->base.tablespacename = NULL;
    5743           0 :                     n->base.if_not_exists = true;
    5744             :                     /* FDW-specific data */
    5745           0 :                     n->servername = $13;
    5746           0 :                     n->options = $14;
    5747           0 :                     $$ = (Node *) n;
    5748             :                 }
    5749             :         | CREATE FOREIGN TABLE qualified_name
    5750             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5751             :             SERVER name create_generic_options
    5752             :                 {
    5753          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5754             : 
    5755          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5756          90 :                     n->base.relation = $4;
    5757          90 :                     n->base.inhRelations = list_make1($7);
    5758          90 :                     n->base.tableElts = $8;
    5759          90 :                     n->base.partbound = $9;
    5760          90 :                     n->base.ofTypename = NULL;
    5761          90 :                     n->base.constraints = NIL;
    5762          90 :                     n->base.options = NIL;
    5763          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5764          90 :                     n->base.tablespacename = NULL;
    5765          90 :                     n->base.if_not_exists = false;
    5766             :                     /* FDW-specific data */
    5767          90 :                     n->servername = $11;
    5768          90 :                     n->options = $12;
    5769          90 :                     $$ = (Node *) n;
    5770             :                 }
    5771             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5772             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5773             :             SERVER name create_generic_options
    5774             :                 {
    5775           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5776             : 
    5777           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5778           0 :                     n->base.relation = $7;
    5779           0 :                     n->base.inhRelations = list_make1($10);
    5780           0 :                     n->base.tableElts = $11;
    5781           0 :                     n->base.partbound = $12;
    5782           0 :                     n->base.ofTypename = NULL;
    5783           0 :                     n->base.constraints = NIL;
    5784           0 :                     n->base.options = NIL;
    5785           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5786           0 :                     n->base.tablespacename = NULL;
    5787           0 :                     n->base.if_not_exists = true;
    5788             :                     /* FDW-specific data */
    5789           0 :                     n->servername = $14;
    5790           0 :                     n->options = $15;
    5791           0 :                     $$ = (Node *) n;
    5792             :                 }
    5793             :         ;
    5794             : 
    5795             : /*****************************************************************************
    5796             :  *
    5797             :  *      QUERY:
    5798             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5799             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5800             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5801             :  *
    5802             :  ****************************************************************************/
    5803             : 
    5804             : ImportForeignSchemaStmt:
    5805             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5806             :           FROM SERVER name INTO name create_generic_options
    5807             :             {
    5808          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5809             : 
    5810          48 :                 n->server_name = $8;
    5811          48 :                 n->remote_schema = $4;
    5812          48 :                 n->local_schema = $10;
    5813          48 :                 n->list_type = $5->type;
    5814          48 :                 n->table_list = $5->table_names;
    5815          48 :                 n->options = $11;
    5816          48 :                 $$ = (Node *) n;
    5817             :             }
    5818             :         ;
    5819             : 
    5820             : import_qualification_type:
    5821          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5822          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5823             :         ;
    5824             : 
    5825             : import_qualification:
    5826             :         import_qualification_type '(' relation_expr_list ')'
    5827             :             {
    5828          28 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5829             : 
    5830          28 :                 n->type = $1;
    5831          28 :                 n->table_names = $3;
    5832          28 :                 $$ = n;
    5833             :             }
    5834             :         | /*EMPTY*/
    5835             :             {
    5836          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5837          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5838          20 :                 n->table_names = NIL;
    5839          20 :                 $$ = n;
    5840             :             }
    5841             :         ;
    5842             : 
    5843             : /*****************************************************************************
    5844             :  *
    5845             :  *      QUERY:
    5846             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5847             :  *
    5848             :  *****************************************************************************/
    5849             : 
    5850             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5851             :                 {
    5852         246 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5853             : 
    5854         246 :                     n->user = $5;
    5855         246 :                     n->servername = $7;
    5856         246 :                     n->options = $8;
    5857         246 :                     n->if_not_exists = false;
    5858         246 :                     $$ = (Node *) n;
    5859             :                 }
    5860             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5861             :                 {
    5862           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5863             : 
    5864           6 :                     n->user = $8;
    5865           6 :                     n->servername = $10;
    5866           6 :                     n->options = $11;
    5867           6 :                     n->if_not_exists = true;
    5868           6 :                     $$ = (Node *) n;
    5869             :                 }
    5870             :         ;
    5871             : 
    5872             : /* User mapping authorization identifier */
    5873         450 : auth_ident: RoleSpec            { $$ = $1; }
    5874          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5875             :         ;
    5876             : 
    5877             : /*****************************************************************************
    5878             :  *
    5879             :  *      QUERY :
    5880             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5881             :  *
    5882             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5883             :  * only pro forma; but the SQL standard doesn't show one.
    5884             :  ****************************************************************************/
    5885             : 
    5886             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5887             :                 {
    5888          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5889             : 
    5890          88 :                     n->user = $5;
    5891          88 :                     n->servername = $7;
    5892          88 :                     n->missing_ok = false;
    5893          88 :                     $$ = (Node *) n;
    5894             :                 }
    5895             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5896             :                 {
    5897          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5898             : 
    5899          38 :                     n->user = $7;
    5900          38 :                     n->servername = $9;
    5901          38 :                     n->missing_ok = true;
    5902          38 :                     $$ = (Node *) n;
    5903             :                 }
    5904             :         ;
    5905             : 
    5906             : /*****************************************************************************
    5907             :  *
    5908             :  *      QUERY :
    5909             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5910             :  *
    5911             :  ****************************************************************************/
    5912             : 
    5913             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5914             :                 {
    5915         118 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5916             : 
    5917         118 :                     n->user = $5;
    5918         118 :                     n->servername = $7;
    5919         118 :                     n->options = $8;
    5920         118 :                     $$ = (Node *) n;
    5921             :                 }
    5922             :         ;
    5923             : 
    5924             : /*****************************************************************************
    5925             :  *
    5926             :  *      QUERIES:
    5927             :  *              CREATE POLICY name ON table
    5928             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5929             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5930             :  *                  [TO role, ...]
    5931             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5932             :  *              ALTER POLICY name ON table [TO role, ...]
    5933             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5934             :  *
    5935             :  *****************************************************************************/
    5936             : 
    5937             : CreatePolicyStmt:
    5938             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5939             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5940             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5941             :                 {
    5942         724 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5943             : 
    5944         724 :                     n->policy_name = $3;
    5945         724 :                     n->table = $5;
    5946         724 :                     n->permissive = $6;
    5947         724 :                     n->cmd_name = $7;
    5948         724 :                     n->roles = $8;
    5949         724 :                     n->qual = $9;
    5950         724 :                     n->with_check = $10;
    5951         724 :                     $$ = (Node *) n;
    5952             :                 }
    5953             :         ;
    5954             : 
    5955             : AlterPolicyStmt:
    5956             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5957             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5958             :                 {
    5959          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5960             : 
    5961          84 :                     n->policy_name = $3;
    5962          84 :                     n->table = $5;
    5963          84 :                     n->roles = $6;
    5964          84 :                     n->qual = $7;
    5965          84 :                     n->with_check = $8;
    5966          84 :                     $$ = (Node *) n;
    5967             :                 }
    5968             :         ;
    5969             : 
    5970             : RowSecurityOptionalExpr:
    5971         750 :             USING '(' a_expr ')'    { $$ = $3; }
    5972          58 :             | /* EMPTY */           { $$ = NULL; }
    5973             :         ;
    5974             : 
    5975             : RowSecurityOptionalWithCheck:
    5976         122 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5977         686 :             | /* EMPTY */                   { $$ = NULL; }
    5978             :         ;
    5979             : 
    5980             : RowSecurityDefaultToRole:
    5981         130 :             TO role_list            { $$ = $2; }
    5982         594 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5983             :         ;
    5984             : 
    5985             : RowSecurityOptionalToRole:
    5986          12 :             TO role_list            { $$ = $2; }
    5987          72 :             | /* EMPTY */           { $$ = NULL; }
    5988             :         ;
    5989             : 
    5990             : RowSecurityDefaultPermissive:
    5991             :             AS IDENT
    5992             :                 {
    5993          98 :                     if (strcmp($2, "permissive") == 0)
    5994          24 :                         $$ = true;
    5995          74 :                     else if (strcmp($2, "restrictive") == 0)
    5996          68 :                         $$ = false;
    5997             :                     else
    5998           6 :                         ereport(ERROR,
    5999             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6000             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    6001             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    6002             :                                  parser_errposition(@2)));
    6003             : 
    6004             :                 }
    6005         632 :             | /* EMPTY */           { $$ = true; }
    6006             :         ;
    6007             : 
    6008             : RowSecurityDefaultForCmd:
    6009         320 :             FOR row_security_cmd    { $$ = $2; }
    6010         404 :             | /* EMPTY */           { $$ = "all"; }
    6011             :         ;
    6012             : 
    6013             : row_security_cmd:
    6014          44 :             ALL             { $$ = "all"; }
    6015         112 :         |   SELECT          { $$ = "select"; }
    6016          44 :         |   INSERT          { $$ = "insert"; }
    6017          78 :         |   UPDATE          { $$ = "update"; }
    6018          42 :         |   DELETE_P        { $$ = "delete"; }
    6019             :         ;
    6020             : 
    6021             : /*****************************************************************************
    6022             :  *
    6023             :  *      QUERY:
    6024             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    6025             :  *
    6026             :  *****************************************************************************/
    6027             : 
    6028             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    6029             :                 {
    6030          62 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    6031             : 
    6032          62 :                     n->amname = $4;
    6033          62 :                     n->handler_name = $8;
    6034          62 :                     n->amtype = $6;
    6035          62 :                     $$ = (Node *) n;
    6036             :                 }
    6037             :         ;
    6038             : 
    6039             : am_type:
    6040          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    6041          28 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    6042             :         ;
    6043             : 
    6044             : /*****************************************************************************
    6045             :  *
    6046             :  *      QUERIES :
    6047             :  *              CREATE TRIGGER ...
    6048             :  *
    6049             :  *****************************************************************************/
    6050             : 
    6051             : CreateTrigStmt:
    6052             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    6053             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    6054             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6055             :                 {
    6056        3156 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6057             : 
    6058        3156 :                     n->replace = $2;
    6059        3156 :                     n->isconstraint = false;
    6060        3156 :                     n->trigname = $4;
    6061        3156 :                     n->relation = $8;
    6062        3156 :                     n->funcname = $14;
    6063        3156 :                     n->args = $16;
    6064        3156 :                     n->row = $10;
    6065        3156 :                     n->timing = $5;
    6066        3156 :                     n->events = intVal(linitial($6));
    6067        3156 :                     n->columns = (List *) lsecond($6);
    6068        3156 :                     n->whenClause = $11;
    6069        3156 :                     n->transitionRels = $9;
    6070        3156 :                     n->deferrable = false;
    6071        3156 :                     n->initdeferred = false;
    6072        3156 :                     n->constrrel = NULL;
    6073        3156 :                     $$ = (Node *) n;
    6074             :                 }
    6075             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6076             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6077             :             FOR EACH ROW TriggerWhen
    6078             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6079             :                 {
    6080          80 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6081             :                     bool        dummy;
    6082             : 
    6083          80 :                     if (($11 & CAS_NOT_VALID) != 0)
    6084           6 :                         ereport(ERROR,
    6085             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6086             :                                 errmsg("constraint triggers cannot be marked %s",
    6087             :                                        "NOT VALID"),
    6088             :                                 parser_errposition(@11));
    6089          74 :                     if (($11 & CAS_NO_INHERIT) != 0)
    6090           6 :                         ereport(ERROR,
    6091             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6092             :                                 errmsg("constraint triggers cannot be marked %s",
    6093             :                                        "NO INHERIT"),
    6094             :                                 parser_errposition(@11));
    6095          68 :                     if (($11 & CAS_NOT_ENFORCED) != 0)
    6096           6 :                         ereport(ERROR,
    6097             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6098             :                                 errmsg("constraint triggers cannot be marked %s",
    6099             :                                        "NOT ENFORCED"),
    6100             :                                 parser_errposition(@11));
    6101             : 
    6102          62 :                     n->replace = $2;
    6103          62 :                     if (n->replace) /* not supported, see CreateTrigger */
    6104           0 :                         ereport(ERROR,
    6105             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6106             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6107             :                                  parser_errposition(@1)));
    6108          62 :                     n->isconstraint = true;
    6109          62 :                     n->trigname = $5;
    6110          62 :                     n->relation = $9;
    6111          62 :                     n->funcname = $18;
    6112          62 :                     n->args = $20;
    6113          62 :                     n->row = true;
    6114          62 :                     n->timing = TRIGGER_TYPE_AFTER;
    6115          62 :                     n->events = intVal(linitial($7));
    6116          62 :                     n->columns = (List *) lsecond($7);
    6117          62 :                     n->whenClause = $15;
    6118          62 :                     n->transitionRels = NIL;
    6119          62 :                     processCASbits($11, @11, "TRIGGER",
    6120             :                                    &n->deferrable, &n->initdeferred, &dummy,
    6121             :                                    NULL, NULL, yyscanner);
    6122          62 :                     n->constrrel = $10;
    6123          62 :                     $$ = (Node *) n;
    6124             :                 }
    6125             :         ;
    6126             : 
    6127             : TriggerActionTime:
    6128        1424 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6129        1600 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6130         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6131             :         ;
    6132             : 
    6133             : TriggerEvents:
    6134             :             TriggerOneEvent
    6135        3248 :                 { $$ = $1; }
    6136             :             | TriggerEvents OR TriggerOneEvent
    6137             :                 {
    6138        1156 :                     int         events1 = intVal(linitial($1));
    6139        1156 :                     int         events2 = intVal(linitial($3));
    6140        1156 :                     List       *columns1 = (List *) lsecond($1);
    6141        1156 :                     List       *columns2 = (List *) lsecond($3);
    6142             : 
    6143        1156 :                     if (events1 & events2)
    6144           6 :                         parser_yyerror("duplicate trigger events specified");
    6145             :                     /*
    6146             :                      * concat'ing the columns lists loses information about
    6147             :                      * which columns went with which event, but so long as
    6148             :                      * only UPDATE carries columns and we disallow multiple
    6149             :                      * UPDATE items, it doesn't matter.  Command execution
    6150             :                      * should just ignore the columns for non-UPDATE events.
    6151             :                      */
    6152        1150 :                     $$ = list_make2(makeInteger(events1 | events2),
    6153             :                                     list_concat(columns1, columns2));
    6154             :                 }
    6155             :         ;
    6156             : 
    6157             : TriggerOneEvent:
    6158             :             INSERT
    6159        1662 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6160             :             | DELETE_P
    6161         886 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6162             :             | UPDATE
    6163        1718 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6164             :             | UPDATE OF columnList
    6165         100 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6166             :             | TRUNCATE
    6167          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6168             :         ;
    6169             : 
    6170             : TriggerReferencing:
    6171         464 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6172        2692 :             | /*EMPTY*/                             { $$ = NIL; }
    6173             :         ;
    6174             : 
    6175             : TriggerTransitions:
    6176         464 :             TriggerTransition                       { $$ = list_make1($1); }
    6177         142 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6178             :         ;
    6179             : 
    6180             : TriggerTransition:
    6181             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6182             :                 {
    6183         606 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6184             : 
    6185         606 :                     n->name = $4;
    6186         606 :                     n->isNew = $1;
    6187         606 :                     n->isTable = $2;
    6188         606 :                     $$ = (Node *) n;
    6189             :                 }
    6190             :         ;
    6191             : 
    6192             : TransitionOldOrNew:
    6193         330 :             NEW                                     { $$ = true; }
    6194         276 :             | OLD                                   { $$ = false; }
    6195             :         ;
    6196             : 
    6197             : TransitionRowOrTable:
    6198         606 :             TABLE                                   { $$ = true; }
    6199             :             /*
    6200             :              * According to the standard, lack of a keyword here implies ROW.
    6201             :              * Support for that would require prohibiting ROW entirely here,
    6202             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6203             :              * allowing it to be optional, as the standard specifies) as the
    6204             :              * next token.  Requiring ROW seems cleanest and easiest to
    6205             :              * explain.
    6206             :              */
    6207           0 :             | ROW                                   { $$ = false; }
    6208             :         ;
    6209             : 
    6210             : TransitionRelName:
    6211         606 :             ColId                                   { $$ = $1; }
    6212             :         ;
    6213             : 
    6214             : TriggerForSpec:
    6215             :             FOR TriggerForOptEach TriggerForType
    6216             :                 {
    6217        2928 :                     $$ = $3;
    6218             :                 }
    6219             :             | /* EMPTY */
    6220             :                 {
    6221             :                     /*
    6222             :                      * If ROW/STATEMENT not specified, default to
    6223             :                      * STATEMENT, per SQL
    6224             :                      */
    6225         228 :                     $$ = false;
    6226             :                 }
    6227             :         ;
    6228             : 
    6229             : TriggerForOptEach:
    6230             :             EACH
    6231             :             | /*EMPTY*/
    6232             :         ;
    6233             : 
    6234             : TriggerForType:
    6235        2108 :             ROW                                     { $$ = true; }
    6236         820 :             | STATEMENT                             { $$ = false; }
    6237             :         ;
    6238             : 
    6239             : TriggerWhen:
    6240         190 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6241        3046 :             | /*EMPTY*/                             { $$ = NULL; }
    6242             :         ;
    6243             : 
    6244             : FUNCTION_or_PROCEDURE:
    6245             :             FUNCTION
    6246             :         |   PROCEDURE
    6247             :         ;
    6248             : 
    6249             : TriggerFuncArgs:
    6250         546 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6251         162 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6252        2690 :             | /*EMPTY*/                             { $$ = NIL; }
    6253             :         ;
    6254             : 
    6255             : TriggerFuncArg:
    6256             :             Iconst
    6257             :                 {
    6258          94 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6259             :                 }
    6260           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6261         592 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6262          22 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6263             :         ;
    6264             : 
    6265             : OptConstrFromTable:
    6266          12 :             FROM qualified_name                     { $$ = $2; }
    6267          68 :             | /*EMPTY*/                             { $$ = NULL; }
    6268             :         ;
    6269             : 
    6270             : ConstraintAttributeSpec:
    6271             :             /*EMPTY*/
    6272       17834 :                 { $$ = 0; }
    6273             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6274             :                 {
    6275             :                     /*
    6276             :                      * We must complain about conflicting options.
    6277             :                      * We could, but choose not to, complain about redundant
    6278             :                      * options (ie, where $2's bit is already set in $1).
    6279             :                      */
    6280        1676 :                     int     newspec = $1 | $2;
    6281             : 
    6282             :                     /* special message for this case */
    6283        1676 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6284           6 :                         ereport(ERROR,
    6285             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6286             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6287             :                                  parser_errposition(@2)));
    6288             :                     /* generic message for other conflicts */
    6289        1670 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6290        1670 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6291        1670 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6292           6 :                         ereport(ERROR,
    6293             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6294             :                                  errmsg("conflicting constraint properties"),
    6295             :                                  parser_errposition(@2)));
    6296        1664 :                     $$ = newspec;
    6297             :                 }
    6298             :         ;
    6299             : 
    6300             : ConstraintAttributeElem:
    6301          42 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6302         200 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6303          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6304         152 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6305         726 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6306         250 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6307         168 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6308         108 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6309             :         ;
    6310             : 
    6311             : 
    6312             : /*****************************************************************************
    6313             :  *
    6314             :  *      QUERIES :
    6315             :  *              CREATE EVENT TRIGGER ...
    6316             :  *              ALTER EVENT TRIGGER ...
    6317             :  *
    6318             :  *****************************************************************************/
    6319             : 
    6320             : CreateEventTrigStmt:
    6321             :             CREATE EVENT TRIGGER name ON ColLabel
    6322             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6323             :                 {
    6324         102 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6325             : 
    6326         102 :                     n->trigname = $4;
    6327         102 :                     n->eventname = $6;
    6328         102 :                     n->whenclause = NULL;
    6329         102 :                     n->funcname = $9;
    6330         102 :                     $$ = (Node *) n;
    6331             :                 }
    6332             :           | CREATE EVENT TRIGGER name ON ColLabel
    6333             :             WHEN event_trigger_when_list
    6334             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6335             :                 {
    6336          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6337             : 
    6338          98 :                     n->trigname = $4;
    6339          98 :                     n->eventname = $6;
    6340          98 :                     n->whenclause = $8;
    6341          98 :                     n->funcname = $11;
    6342          98 :                     $$ = (Node *) n;
    6343             :                 }
    6344             :         ;
    6345             : 
    6346             : event_trigger_when_list:
    6347             :           event_trigger_when_item
    6348          98 :             { $$ = list_make1($1); }
    6349             :         | event_trigger_when_list AND event_trigger_when_item
    6350           6 :             { $$ = lappend($1, $3); }
    6351             :         ;
    6352             : 
    6353             : event_trigger_when_item:
    6354             :         ColId IN_P '(' event_trigger_value_list ')'
    6355         104 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6356             :         ;
    6357             : 
    6358             : event_trigger_value_list:
    6359             :           SCONST
    6360         104 :             { $$ = list_make1(makeString($1)); }
    6361             :         | event_trigger_value_list ',' SCONST
    6362          66 :             { $$ = lappend($1, makeString($3)); }
    6363             :         ;
    6364             : 
    6365             : AlterEventTrigStmt:
    6366             :             ALTER EVENT TRIGGER name enable_trigger
    6367             :                 {
    6368          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6369             : 
    6370          48 :                     n->trigname = $4;
    6371          48 :                     n->tgenabled = $5;
    6372          48 :                     $$ = (Node *) n;
    6373             :                 }
    6374             :         ;
    6375             : 
    6376             : enable_trigger:
    6377           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6378           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6379          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6380          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6381             :         ;
    6382             : 
    6383             : /*****************************************************************************
    6384             :  *
    6385             :  *      QUERY :
    6386             :  *              CREATE ASSERTION ...
    6387             :  *
    6388             :  *****************************************************************************/
    6389             : 
    6390             : CreateAssertionStmt:
    6391             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6392             :                 {
    6393           0 :                     ereport(ERROR,
    6394             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6395             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6396             :                              parser_errposition(@1)));
    6397             : 
    6398             :                     $$ = NULL;
    6399             :                 }
    6400             :         ;
    6401             : 
    6402             : 
    6403             : /*****************************************************************************
    6404             :  *
    6405             :  *      QUERY :
    6406             :  *              define (aggregate,operator,type)
    6407             :  *
    6408             :  *****************************************************************************/
    6409             : 
    6410             : DefineStmt:
    6411             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6412             :                 {
    6413         544 :                     DefineStmt *n = makeNode(DefineStmt);
    6414             : 
    6415         544 :                     n->kind = OBJECT_AGGREGATE;
    6416         544 :                     n->oldstyle = false;
    6417         544 :                     n->replace = $2;
    6418         544 :                     n->defnames = $4;
    6419         544 :                     n->args = $5;
    6420         544 :                     n->definition = $6;
    6421         544 :                     $$ = (Node *) n;
    6422             :                 }
    6423             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6424             :                 {
    6425             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6426         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6427             : 
    6428         362 :                     n->kind = OBJECT_AGGREGATE;
    6429         362 :                     n->oldstyle = true;
    6430         362 :                     n->replace = $2;
    6431         362 :                     n->defnames = $4;
    6432         362 :                     n->args = NIL;
    6433         362 :                     n->definition = $5;
    6434         362 :                     $$ = (Node *) n;
    6435             :                 }
    6436             :             | CREATE OPERATOR any_operator definition
    6437             :                 {
    6438        1642 :                     DefineStmt *n = makeNode(DefineStmt);
    6439             : 
    6440        1642 :                     n->kind = OBJECT_OPERATOR;
    6441        1642 :                     n->oldstyle = false;
    6442        1642 :                     n->defnames = $3;
    6443        1642 :                     n->args = NIL;
    6444        1642 :                     n->definition = $4;
    6445        1642 :                     $$ = (Node *) n;
    6446             :                 }
    6447             :             | CREATE TYPE_P any_name definition
    6448             :                 {
    6449         240 :                     DefineStmt *n = makeNode(DefineStmt);
    6450             : 
    6451         240 :                     n->kind = OBJECT_TYPE;
    6452         240 :                     n->oldstyle = false;
    6453         240 :                     n->defnames = $3;
    6454         240 :                     n->args = NIL;
    6455         240 :                     n->definition = $4;
    6456         240 :                     $$ = (Node *) n;
    6457             :                 }
    6458             :             | CREATE TYPE_P any_name
    6459             :                 {
    6460             :                     /* Shell type (identified by lack of definition) */
    6461         156 :                     DefineStmt *n = makeNode(DefineStmt);
    6462             : 
    6463         156 :                     n->kind = OBJECT_TYPE;
    6464         156 :                     n->oldstyle = false;
    6465         156 :                     n->defnames = $3;
    6466         156 :                     n->args = NIL;
    6467         156 :                     n->definition = NIL;
    6468         156 :                     $$ = (Node *) n;
    6469             :                 }
    6470             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6471             :                 {
    6472        4502 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6473             : 
    6474             :                     /* can't use qualified_name, sigh */
    6475        4502 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6476        4502 :                     n->coldeflist = $6;
    6477        4502 :                     $$ = (Node *) n;
    6478             :                 }
    6479             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6480             :                 {
    6481         208 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6482             : 
    6483         208 :                     n->typeName = $3;
    6484         208 :                     n->vals = $7;
    6485         208 :                     $$ = (Node *) n;
    6486             :                 }
    6487             :             | CREATE TYPE_P any_name AS RANGE definition
    6488             :                 {
    6489         184 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6490             : 
    6491         184 :                     n->typeName = $3;
    6492         184 :                     n->params = $6;
    6493         184 :                     $$ = (Node *) n;
    6494             :                 }
    6495             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6496             :                 {
    6497          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6498             : 
    6499          40 :                     n->kind = OBJECT_TSPARSER;
    6500          40 :                     n->args = NIL;
    6501          40 :                     n->defnames = $5;
    6502          40 :                     n->definition = $6;
    6503          40 :                     $$ = (Node *) n;
    6504             :                 }
    6505             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6506             :                 {
    6507        2930 :                     DefineStmt *n = makeNode(DefineStmt);
    6508             : 
    6509        2930 :                     n->kind = OBJECT_TSDICTIONARY;
    6510        2930 :                     n->args = NIL;
    6511        2930 :                     n->defnames = $5;
    6512        2930 :                     n->definition = $6;
    6513        2930 :                     $$ = (Node *) n;
    6514             :                 }
    6515             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6516             :                 {
    6517         140 :                     DefineStmt *n = makeNode(DefineStmt);
    6518             : 
    6519         140 :                     n->kind = OBJECT_TSTEMPLATE;
    6520         140 :                     n->args = NIL;
    6521         140 :                     n->defnames = $5;
    6522         140 :                     n->definition = $6;
    6523         140 :                     $$ = (Node *) n;
    6524             :                 }
    6525             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6526             :                 {
    6527        2872 :                     DefineStmt *n = makeNode(DefineStmt);
    6528             : 
    6529        2872 :                     n->kind = OBJECT_TSCONFIGURATION;
    6530        2872 :                     n->args = NIL;
    6531        2872 :                     n->defnames = $5;
    6532        2872 :                     n->definition = $6;
    6533        2872 :                     $$ = (Node *) n;
    6534             :                 }
    6535             :             | CREATE COLLATION any_name definition
    6536             :                 {
    6537         292 :                     DefineStmt *n = makeNode(DefineStmt);
    6538             : 
    6539         292 :                     n->kind = OBJECT_COLLATION;
    6540         292 :                     n->args = NIL;
    6541         292 :                     n->defnames = $3;
    6542         292 :                     n->definition = $4;
    6543         292 :                     $$ = (Node *) n;
    6544             :                 }
    6545             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6546             :                 {
    6547          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6548             : 
    6549          18 :                     n->kind = OBJECT_COLLATION;
    6550          18 :                     n->args = NIL;
    6551          18 :                     n->defnames = $6;
    6552          18 :                     n->definition = $7;
    6553          18 :                     n->if_not_exists = true;
    6554          18 :                     $$ = (Node *) n;
    6555             :                 }
    6556             :             | CREATE COLLATION any_name FROM any_name
    6557             :                 {
    6558          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6559             : 
    6560          54 :                     n->kind = OBJECT_COLLATION;
    6561          54 :                     n->args = NIL;
    6562          54 :                     n->defnames = $3;
    6563          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6564          54 :                     $$ = (Node *) n;
    6565             :                 }
    6566             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6567             :                 {
    6568           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6569             : 
    6570           0 :                     n->kind = OBJECT_COLLATION;
    6571           0 :                     n->args = NIL;
    6572           0 :                     n->defnames = $6;
    6573           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6574           0 :                     n->if_not_exists = true;
    6575           0 :                     $$ = (Node *) n;
    6576             :                 }
    6577             :         ;
    6578             : 
    6579        9952 : definition: '(' def_list ')'                        { $$ = $2; }
    6580             :         ;
    6581             : 
    6582        9952 : def_list:   def_elem                                { $$ = list_make1($1); }
    6583       14814 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6584             :         ;
    6585             : 
    6586             : def_elem:   ColLabel '=' def_arg
    6587             :                 {
    6588       24428 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6589             :                 }
    6590             :             | ColLabel
    6591             :                 {
    6592         338 :                     $$ = makeDefElem($1, NULL, @1);
    6593             :                 }
    6594             :         ;
    6595             : 
    6596             : /* Note: any simple identifier will be returned as a type name! */
    6597       19732 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6598        4126 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6599        1176 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6600        1332 :             | NumericOnly                   { $$ = (Node *) $1; }
    6601        1892 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6602         182 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6603             :         ;
    6604             : 
    6605         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6606             :         ;
    6607             : 
    6608         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6609        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6610             :         ;
    6611             : 
    6612             : /*
    6613             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6614             :  * the item names needed in old aggregate definitions are likely to become
    6615             :  * SQL keywords.
    6616             :  */
    6617             : old_aggr_elem:  IDENT '=' def_arg
    6618             :                 {
    6619        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6620             :                 }
    6621             :         ;
    6622             : 
    6623             : opt_enum_val_list:
    6624         200 :         enum_val_list                           { $$ = $1; }
    6625           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6626             :         ;
    6627             : 
    6628             : enum_val_list:  Sconst
    6629         200 :                 { $$ = list_make1(makeString($1)); }
    6630             :             | enum_val_list ',' Sconst
    6631       10420 :                 { $$ = lappend($1, makeString($3)); }
    6632             :         ;
    6633             : 
    6634             : /*****************************************************************************
    6635             :  *
    6636             :  *  ALTER TYPE enumtype ADD ...
    6637             :  *
    6638             :  *****************************************************************************/
    6639             : 
    6640             : AlterEnumStmt:
    6641             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6642             :             {
    6643         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6644             : 
    6645         154 :                 n->typeName = $3;
    6646         154 :                 n->oldVal = NULL;
    6647         154 :                 n->newVal = $7;
    6648         154 :                 n->newValNeighbor = NULL;
    6649         154 :                 n->newValIsAfter = true;
    6650         154 :                 n->skipIfNewValExists = $6;
    6651         154 :                 $$ = (Node *) n;
    6652             :             }
    6653             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6654             :             {
    6655         196 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6656             : 
    6657         196 :                 n->typeName = $3;
    6658         196 :                 n->oldVal = NULL;
    6659         196 :                 n->newVal = $7;
    6660         196 :                 n->newValNeighbor = $9;
    6661         196 :                 n->newValIsAfter = false;
    6662         196 :                 n->skipIfNewValExists = $6;
    6663         196 :                 $$ = (Node *) n;
    6664             :             }
    6665             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6666             :             {
    6667          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6668             : 
    6669          22 :                 n->typeName = $3;
    6670          22 :                 n->oldVal = NULL;
    6671          22 :                 n->newVal = $7;
    6672          22 :                 n->newValNeighbor = $9;
    6673          22 :                 n->newValIsAfter = true;
    6674          22 :                 n->skipIfNewValExists = $6;
    6675          22 :                 $$ = (Node *) n;
    6676             :             }
    6677             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6678             :             {
    6679          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6680             : 
    6681          24 :                 n->typeName = $3;
    6682          24 :                 n->oldVal = $6;
    6683          24 :                 n->newVal = $8;
    6684          24 :                 n->newValNeighbor = NULL;
    6685          24 :                 n->newValIsAfter = false;
    6686          24 :                 n->skipIfNewValExists = false;
    6687          24 :                 $$ = (Node *) n;
    6688             :             }
    6689             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6690             :             {
    6691             :                 /*
    6692             :                  * The following problems must be solved before this can be
    6693             :                  * implemented:
    6694             :                  *
    6695             :                  * - There must be no instance of the target value in
    6696             :                  *   any table.
    6697             :                  *
    6698             :                  * - The value must not appear in any catalog metadata,
    6699             :                  *   such as stored view expressions or column defaults.
    6700             :                  *
    6701             :                  * - The value must not appear in any non-leaf page of a
    6702             :                  *   btree (and similar issues with other index types).
    6703             :                  *   This is problematic because a value could persist
    6704             :                  *   there long after it's gone from user-visible data.
    6705             :                  *
    6706             :                  * - Concurrent sessions must not be able to insert the
    6707             :                  *   value while the preceding conditions are being checked.
    6708             :                  *
    6709             :                  * - Possibly more...
    6710             :                  */
    6711           0 :                 ereport(ERROR,
    6712             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6713             :                          errmsg("dropping an enum value is not implemented"),
    6714             :                          parser_errposition(@4)));
    6715             :             }
    6716             :          ;
    6717             : 
    6718          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6719         360 :         | /* EMPTY */                          { $$ = false; }
    6720             :         ;
    6721             : 
    6722             : 
    6723             : /*****************************************************************************
    6724             :  *
    6725             :  *      QUERIES :
    6726             :  *              CREATE OPERATOR CLASS ...
    6727             :  *              CREATE OPERATOR FAMILY ...
    6728             :  *              ALTER OPERATOR FAMILY ...
    6729             :  *              DROP OPERATOR CLASS ...
    6730             :  *              DROP OPERATOR FAMILY ...
    6731             :  *
    6732             :  *****************************************************************************/
    6733             : 
    6734             : CreateOpClassStmt:
    6735             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6736             :             USING name opt_opfamily AS opclass_item_list
    6737             :                 {
    6738         556 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6739             : 
    6740         556 :                     n->opclassname = $4;
    6741         556 :                     n->isDefault = $5;
    6742         556 :                     n->datatype = $8;
    6743         556 :                     n->amname = $10;
    6744         556 :                     n->opfamilyname = $11;
    6745         556 :                     n->items = $13;
    6746         556 :                     $$ = (Node *) n;
    6747             :                 }
    6748             :         ;
    6749             : 
    6750             : opclass_item_list:
    6751        1412 :             opclass_item                            { $$ = list_make1($1); }
    6752        5388 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6753             :         ;
    6754             : 
    6755             : opclass_item:
    6756             :             OPERATOR Iconst any_operator opclass_purpose
    6757             :                 {
    6758        1866 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6759        1866 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6760             : 
    6761        1866 :                     owa->objname = $3;
    6762        1866 :                     owa->objargs = NIL;
    6763        1866 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6764        1866 :                     n->name = owa;
    6765        1866 :                     n->number = $2;
    6766        1866 :                     n->order_family = $4;
    6767        1866 :                     $$ = (Node *) n;
    6768             :                 }
    6769             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6770             :                 {
    6771        1570 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6772             : 
    6773        1570 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6774        1570 :                     n->name = $3;
    6775        1570 :                     n->number = $2;
    6776        1570 :                     n->order_family = $4;
    6777        1570 :                     $$ = (Node *) n;
    6778             :                 }
    6779             :             | FUNCTION Iconst function_with_argtypes
    6780             :                 {
    6781        2414 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6782             : 
    6783        2414 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6784        2414 :                     n->name = $3;
    6785        2414 :                     n->number = $2;
    6786        2414 :                     $$ = (Node *) n;
    6787             :                 }
    6788             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6789             :                 {
    6790         590 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6791             : 
    6792         590 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6793         590 :                     n->name = $6;
    6794         590 :                     n->number = $2;
    6795         590 :                     n->class_args = $4;
    6796         590 :                     $$ = (Node *) n;
    6797             :                 }
    6798             :             | STORAGE Typename
    6799             :                 {
    6800         360 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6801             : 
    6802         360 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6803         360 :                     n->storedtype = $2;
    6804         360 :                     $$ = (Node *) n;
    6805             :                 }
    6806             :         ;
    6807             : 
    6808         452 : opt_default:    DEFAULT                     { $$ = true; }
    6809         168 :             | /*EMPTY*/                     { $$ = false; }
    6810             :         ;
    6811             : 
    6812          44 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6813         512 :             | /*EMPTY*/                     { $$ = NIL; }
    6814             :         ;
    6815             : 
    6816           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6817         120 :             | FOR ORDER BY any_name         { $$ = $4; }
    6818        3316 :             | /*EMPTY*/                     { $$ = NIL; }
    6819             :         ;
    6820             : 
    6821             : 
    6822             : CreateOpFamilyStmt:
    6823             :             CREATE OPERATOR FAMILY any_name USING name
    6824             :                 {
    6825         148 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6826             : 
    6827         148 :                     n->opfamilyname = $4;
    6828         148 :                     n->amname = $6;
    6829         148 :                     $$ = (Node *) n;
    6830             :                 }
    6831             :         ;
    6832             : 
    6833             : AlterOpFamilyStmt:
    6834             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6835             :                 {
    6836         856 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6837             : 
    6838         856 :                     n->opfamilyname = $4;
    6839         856 :                     n->amname = $6;
    6840         856 :                     n->isDrop = false;
    6841         856 :                     n->items = $8;
    6842         856 :                     $$ = (Node *) n;
    6843             :                 }
    6844             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6845             :                 {
    6846          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6847             : 
    6848          64 :                     n->opfamilyname = $4;
    6849          64 :                     n->amname = $6;
    6850          64 :                     n->isDrop = true;
    6851          64 :                     n->items = $8;
    6852          64 :                     $$ = (Node *) n;
    6853             :                 }
    6854             :         ;
    6855             : 
    6856             : opclass_drop_list:
    6857          64 :             opclass_drop                            { $$ = list_make1($1); }
    6858          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6859             :         ;
    6860             : 
    6861             : opclass_drop:
    6862             :             OPERATOR Iconst '(' type_list ')'
    6863             :                 {
    6864          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6865             : 
    6866          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6867          56 :                     n->number = $2;
    6868          56 :                     n->class_args = $4;
    6869          56 :                     $$ = (Node *) n;
    6870             :                 }
    6871             :             | FUNCTION Iconst '(' type_list ')'
    6872             :                 {
    6873          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6874             : 
    6875          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6876          38 :                     n->number = $2;
    6877          38 :                     n->class_args = $4;
    6878          38 :                     $$ = (Node *) n;
    6879             :                 }
    6880             :         ;
    6881             : 
    6882             : 
    6883             : DropOpClassStmt:
    6884             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6885             :                 {
    6886          38 :                     DropStmt *n = makeNode(DropStmt);
    6887             : 
    6888          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6889          38 :                     n->removeType = OBJECT_OPCLASS;
    6890          38 :                     n->behavior = $7;
    6891          38 :                     n->missing_ok = false;
    6892          38 :                     n->concurrent = false;
    6893          38 :                     $$ = (Node *) n;
    6894             :                 }
    6895             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6896             :                 {
    6897          18 :                     DropStmt *n = makeNode(DropStmt);
    6898             : 
    6899          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6900          18 :                     n->removeType = OBJECT_OPCLASS;
    6901          18 :                     n->behavior = $9;
    6902          18 :                     n->missing_ok = true;
    6903          18 :                     n->concurrent = false;
    6904          18 :                     $$ = (Node *) n;
    6905             :                 }
    6906             :         ;
    6907             : 
    6908             : DropOpFamilyStmt:
    6909             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6910             :                 {
    6911         110 :                     DropStmt *n = makeNode(DropStmt);
    6912             : 
    6913         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6914         110 :                     n->removeType = OBJECT_OPFAMILY;
    6915         110 :                     n->behavior = $7;
    6916         110 :                     n->missing_ok = false;
    6917         110 :                     n->concurrent = false;
    6918         110 :                     $$ = (Node *) n;
    6919             :                 }
    6920             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6921             :                 {
    6922          18 :                     DropStmt *n = makeNode(DropStmt);
    6923             : 
    6924          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6925          18 :                     n->removeType = OBJECT_OPFAMILY;
    6926          18 :                     n->behavior = $9;
    6927          18 :                     n->missing_ok = true;
    6928          18 :                     n->concurrent = false;
    6929          18 :                     $$ = (Node *) n;
    6930             :                 }
    6931             :         ;
    6932             : 
    6933             : 
    6934             : /*****************************************************************************
    6935             :  *
    6936             :  *      QUERY:
    6937             :  *
    6938             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6939             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6940             :  *
    6941             :  *****************************************************************************/
    6942             : DropOwnedStmt:
    6943             :             DROP OWNED BY role_list opt_drop_behavior
    6944             :                 {
    6945         154 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6946             : 
    6947         154 :                     n->roles = $4;
    6948         154 :                     n->behavior = $5;
    6949         154 :                     $$ = (Node *) n;
    6950             :                 }
    6951             :         ;
    6952             : 
    6953             : ReassignOwnedStmt:
    6954             :             REASSIGN OWNED BY role_list TO RoleSpec
    6955             :                 {
    6956          52 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6957             : 
    6958          52 :                     n->roles = $4;
    6959          52 :                     n->newrole = $6;
    6960          52 :                     $$ = (Node *) n;
    6961             :                 }
    6962             :         ;
    6963             : 
    6964             : /*****************************************************************************
    6965             :  *
    6966             :  *      QUERY:
    6967             :  *
    6968             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6969             :  *           [ RESTRICT | CASCADE ]
    6970             :  *
    6971             :  *****************************************************************************/
    6972             : 
    6973             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6974             :                 {
    6975        1352 :                     DropStmt *n = makeNode(DropStmt);
    6976             : 
    6977        1352 :                     n->removeType = $2;
    6978        1352 :                     n->missing_ok = true;
    6979        1352 :                     n->objects = $5;
    6980        1352 :                     n->behavior = $6;
    6981        1352 :                     n->concurrent = false;
    6982        1352 :                     $$ = (Node *) n;
    6983             :                 }
    6984             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6985             :                 {
    6986       16162 :                     DropStmt *n = makeNode(DropStmt);
    6987             : 
    6988       16162 :                     n->removeType = $2;
    6989       16162 :                     n->missing_ok = false;
    6990       16162 :                     n->objects = $3;
    6991       16162 :                     n->behavior = $4;
    6992       16162 :                     n->concurrent = false;
    6993       16162 :                     $$ = (Node *) n;
    6994             :                 }
    6995             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6996             :                 {
    6997          78 :                     DropStmt *n = makeNode(DropStmt);
    6998             : 
    6999          78 :                     n->removeType = $2;
    7000          78 :                     n->missing_ok = true;
    7001          78 :                     n->objects = $5;
    7002          78 :                     n->behavior = $6;
    7003          78 :                     n->concurrent = false;
    7004          78 :                     $$ = (Node *) n;
    7005             :                 }
    7006             :             | DROP drop_type_name name_list opt_drop_behavior
    7007             :                 {
    7008        1430 :                     DropStmt *n = makeNode(DropStmt);
    7009             : 
    7010        1430 :                     n->removeType = $2;
    7011        1430 :                     n->missing_ok = false;
    7012        1430 :                     n->objects = $3;
    7013        1430 :                     n->behavior = $4;
    7014        1430 :                     n->concurrent = false;
    7015        1430 :                     $$ = (Node *) n;
    7016             :                 }
    7017             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    7018             :                 {
    7019        1130 :                     DropStmt *n = makeNode(DropStmt);
    7020             : 
    7021        1130 :                     n->removeType = $2;
    7022        1130 :                     n->objects = list_make1(lappend($5, makeString($3)));
    7023        1130 :                     n->behavior = $6;
    7024        1130 :                     n->missing_ok = false;
    7025        1130 :                     n->concurrent = false;
    7026        1130 :                     $$ = (Node *) n;
    7027             :                 }
    7028             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    7029             :                 {
    7030          48 :                     DropStmt *n = makeNode(DropStmt);
    7031             : 
    7032          48 :                     n->removeType = $2;
    7033          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    7034          48 :                     n->behavior = $8;
    7035          48 :                     n->missing_ok = true;
    7036          48 :                     n->concurrent = false;
    7037          48 :                     $$ = (Node *) n;
    7038             :                 }
    7039             :             | DROP TYPE_P type_name_list opt_drop_behavior
    7040             :                 {
    7041         560 :                     DropStmt *n = makeNode(DropStmt);
    7042             : 
    7043         560 :                     n->removeType = OBJECT_TYPE;
    7044         560 :                     n->missing_ok = false;
    7045         560 :                     n->objects = $3;
    7046         560 :                     n->behavior = $4;
    7047         560 :                     n->concurrent = false;
    7048         560 :                     $$ = (Node *) n;
    7049             :                 }
    7050             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    7051             :                 {
    7052          26 :                     DropStmt *n = makeNode(DropStmt);
    7053             : 
    7054          26 :                     n->removeType = OBJECT_TYPE;
    7055          26 :                     n->missing_ok = true;
    7056          26 :                     n->objects = $5;
    7057          26 :                     n->behavior = $6;
    7058          26 :                     n->concurrent = false;
    7059          26 :                     $$ = (Node *) n;
    7060             :                 }
    7061             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    7062             :                 {
    7063         464 :                     DropStmt *n = makeNode(DropStmt);
    7064             : 
    7065         464 :                     n->removeType = OBJECT_DOMAIN;
    7066         464 :                     n->missing_ok = false;
    7067         464 :                     n->objects = $3;
    7068         464 :                     n->behavior = $4;
    7069         464 :                     n->concurrent = false;
    7070         464 :                     $$ = (Node *) n;
    7071             :                 }
    7072             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7073             :                 {
    7074          18 :                     DropStmt *n = makeNode(DropStmt);
    7075             : 
    7076          18 :                     n->removeType = OBJECT_DOMAIN;
    7077          18 :                     n->missing_ok = true;
    7078          18 :                     n->objects = $5;
    7079          18 :                     n->behavior = $6;
    7080          18 :                     n->concurrent = false;
    7081          18 :                     $$ = (Node *) n;
    7082             :                 }
    7083             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7084             :                 {
    7085         126 :                     DropStmt *n = makeNode(DropStmt);
    7086             : 
    7087         126 :                     n->removeType = OBJECT_INDEX;
    7088         126 :                     n->missing_ok = false;
    7089         126 :                     n->objects = $4;
    7090         126 :                     n->behavior = $5;
    7091         126 :                     n->concurrent = true;
    7092         126 :                     $$ = (Node *) n;
    7093             :                 }
    7094             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7095             :                 {
    7096          12 :                     DropStmt *n = makeNode(DropStmt);
    7097             : 
    7098          12 :                     n->removeType = OBJECT_INDEX;
    7099          12 :                     n->missing_ok = true;
    7100          12 :                     n->objects = $6;
    7101          12 :                     n->behavior = $7;
    7102          12 :                     n->concurrent = true;
    7103          12 :                     $$ = (Node *) n;
    7104             :                 }
    7105             :         ;
    7106             : 
    7107             : /* object types taking any_name/any_name_list */
    7108             : object_type_any_name:
    7109       15110 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7110         192 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7111        1040 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7112         130 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7113         778 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7114         186 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7115          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7116          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7117         210 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7118          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7119        2814 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7120         116 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7121        2818 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7122             :         ;
    7123             : 
    7124             : /*
    7125             :  * object types taking name/name_list
    7126             :  *
    7127             :  * DROP handles some of them separately
    7128             :  */
    7129             : 
    7130             : object_type_name:
    7131         240 :             drop_type_name                          { $$ = $1; }
    7132         238 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7133          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7134          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7135           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7136             :         ;
    7137             : 
    7138             : drop_type_name:
    7139          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7140         128 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7141         156 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7142         154 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7143         154 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7144         390 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7145         590 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7146         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7147             :         ;
    7148             : 
    7149             : /* object types attached to a table */
    7150             : object_type_name_on_any_name:
    7151         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7152         268 :             | RULE                                  { $$ = OBJECT_RULE; }
    7153         798 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7154             :         ;
    7155             : 
    7156             : any_name_list:
    7157       26334 :             any_name                                { $$ = list_make1($1); }
    7158        4186 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7159             :         ;
    7160             : 
    7161       67366 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7162        8948 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7163             :         ;
    7164             : 
    7165             : attrs:      '.' attr_name
    7166      125214 :                     { $$ = list_make1(makeString($2)); }
    7167             :             | attrs '.' attr_name
    7168          64 :                     { $$ = lappend($1, makeString($3)); }
    7169             :         ;
    7170             : 
    7171             : type_name_list:
    7172        1068 :             Typename                                { $$ = list_make1($1); }
    7173          96 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7174             :         ;
    7175             : 
    7176             : /*****************************************************************************
    7177             :  *
    7178             :  *      QUERY:
    7179             :  *              truncate table relname1, relname2, ...
    7180             :  *
    7181             :  *****************************************************************************/
    7182             : 
    7183             : TruncateStmt:
    7184             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7185             :                 {
    7186        1692 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7187             : 
    7188        1692 :                     n->relations = $3;
    7189        1692 :                     n->restart_seqs = $4;
    7190        1692 :                     n->behavior = $5;
    7191        1692 :                     $$ = (Node *) n;
    7192             :                 }
    7193             :         ;
    7194             : 
    7195             : opt_restart_seqs:
    7196          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7197          22 :             | RESTART IDENTITY_P        { $$ = true; }
    7198        1646 :             | /* EMPTY */               { $$ = false; }
    7199             :         ;
    7200             : 
    7201             : /*****************************************************************************
    7202             :  *
    7203             :  * COMMENT ON <object> IS <text>
    7204             :  *
    7205             :  *****************************************************************************/
    7206             : 
    7207             : CommentStmt:
    7208             :             COMMENT ON object_type_any_name any_name IS comment_text
    7209             :                 {
    7210        5898 :                     CommentStmt *n = makeNode(CommentStmt);
    7211             : 
    7212        5898 :                     n->objtype = $3;
    7213        5898 :                     n->object = (Node *) $4;
    7214        5898 :                     n->comment = $6;
    7215        5898 :                     $$ = (Node *) n;
    7216             :                 }
    7217             :             | COMMENT ON COLUMN any_name IS comment_text
    7218             :                 {
    7219         114 :                     CommentStmt *n = makeNode(CommentStmt);
    7220             : 
    7221         114 :                     n->objtype = OBJECT_COLUMN;
    7222         114 :                     n->object = (Node *) $4;
    7223         114 :                     n->comment = $6;
    7224         114 :                     $$ = (Node *) n;
    7225             :                 }
    7226             :             | COMMENT ON object_type_name name IS comment_text
    7227             :                 {
    7228         478 :                     CommentStmt *n = makeNode(CommentStmt);
    7229             : 
    7230         478 :                     n->objtype = $3;
    7231         478 :                     n->object = (Node *) makeString($4);
    7232         478 :                     n->comment = $6;
    7233         478 :                     $$ = (Node *) n;
    7234             :                 }
    7235             :             | COMMENT ON TYPE_P Typename IS comment_text
    7236             :                 {
    7237          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7238             : 
    7239          56 :                     n->objtype = OBJECT_TYPE;
    7240          56 :                     n->object = (Node *) $4;
    7241          56 :                     n->comment = $6;
    7242          56 :                     $$ = (Node *) n;
    7243             :                 }
    7244             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7245             :                 {
    7246           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7247             : 
    7248           8 :                     n->objtype = OBJECT_DOMAIN;
    7249           8 :                     n->object = (Node *) $4;
    7250           8 :                     n->comment = $6;
    7251           8 :                     $$ = (Node *) n;
    7252             :                 }
    7253             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7254             :                 {
    7255          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7256             : 
    7257          40 :                     n->objtype = OBJECT_AGGREGATE;
    7258          40 :                     n->object = (Node *) $4;
    7259          40 :                     n->comment = $6;
    7260          40 :                     $$ = (Node *) n;
    7261             :                 }
    7262             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7263             :                 {
    7264         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7265             : 
    7266         170 :                     n->objtype = OBJECT_FUNCTION;
    7267         170 :                     n->object = (Node *) $4;
    7268         170 :                     n->comment = $6;
    7269         170 :                     $$ = (Node *) n;
    7270             :                 }
    7271             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7272             :                 {
    7273          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7274             : 
    7275          18 :                     n->objtype = OBJECT_OPERATOR;
    7276          18 :                     n->object = (Node *) $4;
    7277          18 :                     n->comment = $6;
    7278          18 :                     $$ = (Node *) n;
    7279             :                 }
    7280             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7281             :                 {
    7282         150 :                     CommentStmt *n = makeNode(CommentStmt);
    7283             : 
    7284         150 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7285         150 :                     n->object = (Node *) lappend($6, makeString($4));
    7286         150 :                     n->comment = $8;
    7287         150 :                     $$ = (Node *) n;
    7288             :                 }
    7289             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7290             :                 {
    7291          48 :                     CommentStmt *n = makeNode(CommentStmt);
    7292             : 
    7293          48 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7294             :                     /*
    7295             :                      * should use Typename not any_name in the production, but
    7296             :                      * there's a shift/reduce conflict if we do that, so fix it
    7297             :                      * up here.
    7298             :                      */
    7299          48 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7300          48 :                     n->comment = $9;
    7301          48 :                     $$ = (Node *) n;
    7302             :                 }
    7303             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7304             :                 {
    7305          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7306             : 
    7307          40 :                     n->objtype = $3;
    7308          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7309          40 :                     n->comment = $8;
    7310          40 :                     $$ = (Node *) n;
    7311             :                 }
    7312             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7313             :                 {
    7314           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7315             : 
    7316           0 :                     n->objtype = OBJECT_PROCEDURE;
    7317           0 :                     n->object = (Node *) $4;
    7318           0 :                     n->comment = $6;
    7319           0 :                     $$ = (Node *) n;
    7320             :                 }
    7321             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7322             :                 {
    7323           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7324             : 
    7325           0 :                     n->objtype = OBJECT_ROUTINE;
    7326           0 :                     n->object = (Node *) $4;
    7327           0 :                     n->comment = $6;
    7328           0 :                     $$ = (Node *) n;
    7329             :                 }
    7330             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7331             :                 {
    7332          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7333             : 
    7334          14 :                     n->objtype = OBJECT_TRANSFORM;
    7335          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7336          14 :                     n->comment = $9;
    7337          14 :                     $$ = (Node *) n;
    7338             :                 }
    7339             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7340             :                 {
    7341           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7342             : 
    7343           0 :                     n->objtype = OBJECT_OPCLASS;
    7344           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7345           0 :                     n->comment = $9;
    7346           0 :                     $$ = (Node *) n;
    7347             :                 }
    7348             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7349             :                 {
    7350           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7351             : 
    7352           0 :                     n->objtype = OBJECT_OPFAMILY;
    7353           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7354           0 :                     n->comment = $9;
    7355           0 :                     $$ = (Node *) n;
    7356             :                 }
    7357             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7358             :                 {
    7359          24 :                     CommentStmt *n = makeNode(CommentStmt);
    7360             : 
    7361          24 :                     n->objtype = OBJECT_LARGEOBJECT;
    7362          24 :                     n->object = (Node *) $5;
    7363          24 :                     n->comment = $7;
    7364          24 :                     $$ = (Node *) n;
    7365             :                 }
    7366             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7367             :                 {
    7368           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7369             : 
    7370           0 :                     n->objtype = OBJECT_CAST;
    7371           0 :                     n->object = (Node *) list_make2($5, $7);
    7372           0 :                     n->comment = $10;
    7373           0 :                     $$ = (Node *) n;
    7374             :                 }
    7375             :         ;
    7376             : 
    7377             : comment_text:
    7378        6954 :             Sconst                              { $$ = $1; }
    7379         104 :             | NULL_P                            { $$ = NULL; }
    7380             :         ;
    7381             : 
    7382             : 
    7383             : /*****************************************************************************
    7384             :  *
    7385             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7386             :  *
    7387             :  *  As with COMMENT ON, <object> can refer to various types of database
    7388             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7389             :  *
    7390             :  *****************************************************************************/
    7391             : 
    7392             : SecLabelStmt:
    7393             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7394             :             IS security_label
    7395             :                 {
    7396          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7397             : 
    7398          48 :                     n->provider = $3;
    7399          48 :                     n->objtype = $5;
    7400          48 :                     n->object = (Node *) $6;
    7401          48 :                     n->label = $8;
    7402          48 :                     $$ = (Node *) n;
    7403             :                 }
    7404             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7405             :               IS security_label
    7406             :                 {
    7407           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7408             : 
    7409           4 :                     n->provider = $3;
    7410           4 :                     n->objtype = OBJECT_COLUMN;
    7411           4 :                     n->object = (Node *) $6;
    7412           4 :                     n->label = $8;
    7413           4 :                     $$ = (Node *) n;
    7414             :                 }
    7415             :             | SECURITY LABEL opt_provider ON object_type_name name
    7416             :               IS security_label
    7417             :                 {
    7418          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7419             : 
    7420          44 :                     n->provider = $3;
    7421          44 :                     n->objtype = $5;
    7422          44 :                     n->object = (Node *) makeString($6);
    7423          44 :                     n->label = $8;
    7424          44 :                     $$ = (Node *) n;
    7425             :                 }
    7426             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7427             :               IS security_label
    7428             :                 {
    7429           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7430             : 
    7431           0 :                     n->provider = $3;
    7432           0 :                     n->objtype = OBJECT_TYPE;
    7433           0 :                     n->object = (Node *) $6;
    7434           0 :                     n->label = $8;
    7435           0 :                     $$ = (Node *) n;
    7436             :                 }
    7437             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7438             :               IS security_label
    7439             :                 {
    7440           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7441             : 
    7442           2 :                     n->provider = $3;
    7443           2 :                     n->objtype = OBJECT_DOMAIN;
    7444           2 :                     n->object = (Node *) $6;
    7445           2 :                     n->label = $8;
    7446           2 :                     $$ = (Node *) n;
    7447             :                 }
    7448             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7449             :               IS security_label
    7450             :                 {
    7451           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7452             : 
    7453           0 :                     n->provider = $3;
    7454           0 :                     n->objtype = OBJECT_AGGREGATE;
    7455           0 :                     n->object = (Node *) $6;
    7456           0 :                     n->label = $8;
    7457           0 :                     $$ = (Node *) n;
    7458             :                 }
    7459             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7460             :               IS security_label
    7461             :                 {
    7462           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7463             : 
    7464           2 :                     n->provider = $3;
    7465           2 :                     n->objtype = OBJECT_FUNCTION;
    7466           2 :                     n->object = (Node *) $6;
    7467           2 :                     n->label = $8;
    7468           2 :                     $$ = (Node *) n;
    7469             :                 }
    7470             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7471             :               IS security_label
    7472             :                 {
    7473           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7474             : 
    7475           0 :                     n->provider = $3;
    7476           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7477           0 :                     n->object = (Node *) $7;
    7478           0 :                     n->label = $9;
    7479           0 :                     $$ = (Node *) n;
    7480             :                 }
    7481             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7482             :               IS security_label
    7483             :                 {
    7484           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7485             : 
    7486           0 :                     n->provider = $3;
    7487           0 :                     n->objtype = OBJECT_PROCEDURE;
    7488           0 :                     n->object = (Node *) $6;
    7489           0 :                     n->label = $8;
    7490           0 :                     $$ = (Node *) n;
    7491             :                 }
    7492             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7493             :               IS security_label
    7494             :                 {
    7495           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7496             : 
    7497           0 :                     n->provider = $3;
    7498           0 :                     n->objtype = OBJECT_ROUTINE;
    7499           0 :                     n->object = (Node *) $6;
    7500           0 :                     n->label = $8;
    7501           0 :                     $$ = (Node *) n;
    7502             :                 }
    7503             :         ;
    7504             : 
    7505          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7506          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7507             :         ;
    7508             : 
    7509         100 : security_label: Sconst              { $$ = $1; }
    7510           0 :                 | NULL_P            { $$ = NULL; }
    7511             :         ;
    7512             : 
    7513             : /*****************************************************************************
    7514             :  *
    7515             :  *      QUERY:
    7516             :  *          fetch/move
    7517             :  *
    7518             :  *****************************************************************************/
    7519             : 
    7520             : FetchStmt:  FETCH fetch_args
    7521             :                 {
    7522        7644 :                     FetchStmt *n = (FetchStmt *) $2;
    7523             : 
    7524        7644 :                     n->ismove = false;
    7525        7644 :                     $$ = (Node *) n;
    7526             :                 }
    7527             :             | MOVE fetch_args
    7528             :                 {
    7529          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7530             : 
    7531          68 :                     n->ismove = true;
    7532          68 :                     $$ = (Node *) n;
    7533             :                 }
    7534             :         ;
    7535             : 
    7536             : fetch_args: cursor_name
    7537             :                 {
    7538         272 :                     FetchStmt *n = makeNode(FetchStmt);
    7539             : 
    7540         272 :                     n->portalname = $1;
    7541         272 :                     n->direction = FETCH_FORWARD;
    7542         272 :                     n->howMany = 1;
    7543         272 :                     n->location = -1;
    7544         272 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7545         272 :                     $$ = (Node *) n;
    7546             :                 }
    7547             :             | from_in cursor_name
    7548             :                 {
    7549         218 :                     FetchStmt *n = makeNode(FetchStmt);
    7550             : 
    7551         218 :                     n->portalname = $2;
    7552         218 :                     n->direction = FETCH_FORWARD;
    7553         218 :                     n->howMany = 1;
    7554         218 :                     n->location = -1;
    7555         218 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7556         218 :                     $$ = (Node *) n;
    7557             :                 }
    7558             :             | SignedIconst opt_from_in cursor_name
    7559             :                 {
    7560        4278 :                     FetchStmt *n = makeNode(FetchStmt);
    7561             : 
    7562        4278 :                     n->portalname = $3;
    7563        4278 :                     n->direction = FETCH_FORWARD;
    7564        4278 :                     n->howMany = $1;
    7565        4278 :                     n->location = @1;
    7566        4278 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7567        4278 :                     $$ = (Node *) n;
    7568             :                 }
    7569             :             | NEXT opt_from_in cursor_name
    7570             :                 {
    7571        2010 :                     FetchStmt *n = makeNode(FetchStmt);
    7572             : 
    7573        2010 :                     n->portalname = $3;
    7574        2010 :                     n->direction = FETCH_FORWARD;
    7575        2010 :                     n->howMany = 1;
    7576        2010 :                     n->location = -1;
    7577        2010 :                     n->direction_keyword = FETCH_KEYWORD_NEXT;
    7578        2010 :                     $$ = (Node *) n;
    7579             :                 }
    7580             :             | PRIOR opt_from_in cursor_name
    7581             :                 {
    7582          32 :                     FetchStmt *n = makeNode(FetchStmt);
    7583             : 
    7584          32 :                     n->portalname = $3;
    7585          32 :                     n->direction = FETCH_BACKWARD;
    7586          32 :                     n->howMany = 1;
    7587          32 :                     n->location = -1;
    7588          32 :                     n->direction_keyword = FETCH_KEYWORD_PRIOR;
    7589          32 :                     $$ = (Node *) n;
    7590             :                 }
    7591             :             | FIRST_P opt_from_in cursor_name
    7592             :                 {
    7593          26 :                     FetchStmt *n = makeNode(FetchStmt);
    7594             : 
    7595          26 :                     n->portalname = $3;
    7596          26 :                     n->direction = FETCH_ABSOLUTE;
    7597          26 :                     n->howMany = 1;
    7598          26 :                     n->location = -1;
    7599          26 :                     n->direction_keyword = FETCH_KEYWORD_FIRST;
    7600          26 :                     $$ = (Node *) n;
    7601             :                 }
    7602             :             | LAST_P opt_from_in cursor_name
    7603             :                 {
    7604          20 :                     FetchStmt *n = makeNode(FetchStmt);
    7605             : 
    7606          20 :                     n->portalname = $3;
    7607          20 :                     n->direction = FETCH_ABSOLUTE;
    7608          20 :                     n->howMany = -1;
    7609          20 :                     n->location = -1;
    7610          20 :                     n->direction_keyword = FETCH_KEYWORD_LAST;
    7611          20 :                     $$ = (Node *) n;
    7612             :                 }
    7613             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7614             :                 {
    7615          94 :                     FetchStmt *n = makeNode(FetchStmt);
    7616             : 
    7617          94 :                     n->portalname = $4;
    7618          94 :                     n->direction = FETCH_ABSOLUTE;
    7619          94 :                     n->howMany = $2;
    7620          94 :                     n->location = @2;
    7621          94 :                     n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
    7622          94 :                     $$ = (Node *) n;
    7623             :                 }
    7624             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7625             :                 {
    7626          36 :                     FetchStmt *n = makeNode(FetchStmt);
    7627             : 
    7628          36 :                     n->portalname = $4;
    7629          36 :                     n->direction = FETCH_RELATIVE;
    7630          36 :                     n->howMany = $2;
    7631          36 :                     n->location = @2;
    7632          36 :                     n->direction_keyword = FETCH_KEYWORD_RELATIVE;
    7633          36 :                     $$ = (Node *) n;
    7634             :                 }
    7635             :             | ALL opt_from_in cursor_name
    7636             :                 {
    7637         270 :                     FetchStmt *n = makeNode(FetchStmt);
    7638             : 
    7639         270 :                     n->portalname = $3;
    7640         270 :                     n->direction = FETCH_FORWARD;
    7641         270 :                     n->howMany = FETCH_ALL;
    7642         270 :                     n->location = -1;
    7643         270 :                     n->direction_keyword = FETCH_KEYWORD_ALL;
    7644         270 :                     $$ = (Node *) n;
    7645             :                 }
    7646             :             | FORWARD opt_from_in cursor_name
    7647             :                 {
    7648          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7649             : 
    7650          30 :                     n->portalname = $3;
    7651          30 :                     n->direction = FETCH_FORWARD;
    7652          30 :                     n->howMany = 1;
    7653          30 :                     n->location = -1;
    7654          30 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7655          30 :                     $$ = (Node *) n;
    7656             :                 }
    7657             :             | FORWARD SignedIconst opt_from_in cursor_name
    7658             :                 {
    7659          12 :                     FetchStmt *n = makeNode(FetchStmt);
    7660             : 
    7661          12 :                     n->portalname = $4;
    7662          12 :                     n->direction = FETCH_FORWARD;
    7663          12 :                     n->howMany = $2;
    7664          12 :                     n->location = @2;
    7665          12 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7666          12 :                     $$ = (Node *) n;
    7667             :                 }
    7668             :             | FORWARD ALL opt_from_in cursor_name
    7669             :                 {
    7670          16 :                     FetchStmt *n = makeNode(FetchStmt);
    7671             : 
    7672          16 :                     n->portalname = $4;
    7673          16 :                     n->direction = FETCH_FORWARD;
    7674          16 :                     n->howMany = FETCH_ALL;
    7675          16 :                     n->location = -1;
    7676          16 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
    7677          16 :                     $$ = (Node *) n;
    7678             :                 }
    7679             :             | BACKWARD opt_from_in cursor_name
    7680             :                 {
    7681          80 :                     FetchStmt *n = makeNode(FetchStmt);
    7682             : 
    7683          80 :                     n->portalname = $3;
    7684          80 :                     n->direction = FETCH_BACKWARD;
    7685          80 :                     n->howMany = 1;
    7686          80 :                     n->location = -1;
    7687          80 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7688          80 :                     $$ = (Node *) n;
    7689             :                 }
    7690             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7691             :                 {
    7692         226 :                     FetchStmt *n = makeNode(FetchStmt);
    7693             : 
    7694         226 :                     n->portalname = $4;
    7695         226 :                     n->direction = FETCH_BACKWARD;
    7696         226 :                     n->howMany = $2;
    7697         226 :                     n->location = @2;
    7698         226 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7699         226 :                     $$ = (Node *) n;
    7700             :                 }
    7701             :             | BACKWARD ALL opt_from_in cursor_name
    7702             :                 {
    7703          92 :                     FetchStmt *n = makeNode(FetchStmt);
    7704             : 
    7705          92 :                     n->portalname = $4;
    7706          92 :                     n->direction = FETCH_BACKWARD;
    7707          92 :                     n->howMany = FETCH_ALL;
    7708          92 :                     n->location = -1;
    7709          92 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
    7710          92 :                     $$ = (Node *) n;
    7711             :                 }
    7712             :         ;
    7713             : 
    7714             : from_in:    FROM
    7715             :             | IN_P
    7716             :         ;
    7717             : 
    7718             : opt_from_in:    from_in
    7719             :             | /* EMPTY */
    7720             :         ;
    7721             : 
    7722             : 
    7723             : /*****************************************************************************
    7724             :  *
    7725             :  * GRANT and REVOKE statements
    7726             :  *
    7727             :  *****************************************************************************/
    7728             : 
    7729             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7730             :             opt_grant_grant_option opt_granted_by
    7731             :                 {
    7732       11748 :                     GrantStmt *n = makeNode(GrantStmt);
    7733             : 
    7734       11748 :                     n->is_grant = true;
    7735       11748 :                     n->privileges = $2;
    7736       11748 :                     n->targtype = ($4)->targtype;
    7737       11748 :                     n->objtype = ($4)->objtype;
    7738       11748 :                     n->objects = ($4)->objs;
    7739       11748 :                     n->grantees = $6;
    7740       11748 :                     n->grant_option = $7;
    7741       11748 :                     n->grantor = $8;
    7742       11748 :                     $$ = (Node *) n;
    7743             :                 }
    7744             :         ;
    7745             : 
    7746             : RevokeStmt:
    7747             :             REVOKE privileges ON privilege_target
    7748             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7749             :                 {
    7750       10414 :                     GrantStmt *n = makeNode(GrantStmt);
    7751             : 
    7752       10414 :                     n->is_grant = false;
    7753       10414 :                     n->grant_option = false;
    7754       10414 :                     n->privileges = $2;
    7755       10414 :                     n->targtype = ($4)->targtype;
    7756       10414 :                     n->objtype = ($4)->objtype;
    7757       10414 :                     n->objects = ($4)->objs;
    7758       10414 :                     n->grantees = $6;
    7759       10414 :                     n->grantor = $7;
    7760       10414 :                     n->behavior = $8;
    7761       10414 :                     $$ = (Node *) n;
    7762             :                 }
    7763             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7764             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7765             :                 {
    7766          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7767             : 
    7768          16 :                     n->is_grant = false;
    7769          16 :                     n->grant_option = true;
    7770          16 :                     n->privileges = $5;
    7771          16 :                     n->targtype = ($7)->targtype;
    7772          16 :                     n->objtype = ($7)->objtype;
    7773          16 :                     n->objects = ($7)->objs;
    7774          16 :                     n->grantees = $9;
    7775          16 :                     n->grantor = $10;
    7776          16 :                     n->behavior = $11;
    7777          16 :                     $$ = (Node *) n;
    7778             :                 }
    7779             :         ;
    7780             : 
    7781             : 
    7782             : /*
    7783             :  * Privilege names are represented as strings; the validity of the privilege
    7784             :  * names gets checked at execution.  This is a bit annoying but we have little
    7785             :  * choice because of the syntactic conflict with lists of role names in
    7786             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7787             :  * production any reserved keywords that need to be usable as privilege names.
    7788             :  */
    7789             : 
    7790             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7791             : privileges: privilege_list
    7792       19564 :                 { $$ = $1; }
    7793             :             | ALL
    7794        2694 :                 { $$ = NIL; }
    7795             :             | ALL PRIVILEGES
    7796         120 :                 { $$ = NIL; }
    7797             :             | ALL '(' columnList ')'
    7798             :                 {
    7799          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7800             : 
    7801          18 :                     n->priv_name = NULL;
    7802          18 :                     n->cols = $3;
    7803          18 :                     $$ = list_make1(n);
    7804             :                 }
    7805             :             | ALL PRIVILEGES '(' columnList ')'
    7806             :                 {
    7807           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7808             : 
    7809           0 :                     n->priv_name = NULL;
    7810           0 :                     n->cols = $4;
    7811           0 :                     $$ = list_make1(n);
    7812             :                 }
    7813             :         ;
    7814             : 
    7815       20486 : privilege_list: privilege                           { $$ = list_make1($1); }
    7816         550 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7817             :         ;
    7818             : 
    7819             : privilege:  SELECT opt_column_list
    7820             :             {
    7821        9508 :                 AccessPriv *n = makeNode(AccessPriv);
    7822             : 
    7823        9508 :                 n->priv_name = pstrdup($1);
    7824        9508 :                 n->cols = $2;
    7825        9508 :                 $$ = n;
    7826             :             }
    7827             :         | REFERENCES opt_column_list
    7828             :             {
    7829          14 :                 AccessPriv *n = makeNode(AccessPriv);
    7830             : 
    7831          14 :                 n->priv_name = pstrdup($1);
    7832          14 :                 n->cols = $2;
    7833          14 :                 $$ = n;
    7834             :             }
    7835             :         | CREATE opt_column_list
    7836             :             {
    7837         290 :                 AccessPriv *n = makeNode(AccessPriv);
    7838             : 
    7839         290 :                 n->priv_name = pstrdup($1);
    7840         290 :                 n->cols = $2;
    7841         290 :                 $$ = n;
    7842             :             }
    7843             :         | ALTER SYSTEM_P
    7844             :             {
    7845          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7846          24 :                 n->priv_name = pstrdup("alter system");
    7847          24 :                 n->cols = NIL;
    7848          24 :                 $$ = n;
    7849             :             }
    7850             :         | ColId opt_column_list
    7851             :             {
    7852       11200 :                 AccessPriv *n = makeNode(AccessPriv);
    7853             : 
    7854       11200 :                 n->priv_name = $1;
    7855       11200 :                 n->cols = $2;
    7856       11200 :                 $$ = n;
    7857             :             }
    7858             :         ;
    7859             : 
    7860             : parameter_name_list:
    7861             :         parameter_name
    7862             :             {
    7863          74 :                 $$ = list_make1(makeString($1));
    7864             :             }
    7865             :         | parameter_name_list ',' parameter_name
    7866             :             {
    7867          50 :                 $$ = lappend($1, makeString($3));
    7868             :             }
    7869             :         ;
    7870             : 
    7871             : parameter_name:
    7872             :         ColId
    7873             :             {
    7874         124 :                 $$ = $1;
    7875             :             }
    7876             :         | parameter_name '.' ColId
    7877             :             {
    7878          30 :                 $$ = psprintf("%s.%s", $1, $3);
    7879             :             }
    7880             :         ;
    7881             : 
    7882             : 
    7883             : /* Don't bother trying to fold the first two rules into one using
    7884             :  * opt_table.  You're going to get conflicts.
    7885             :  */
    7886             : privilege_target:
    7887             :             qualified_name_list
    7888             :                 {
    7889       11548 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7890             : 
    7891       11548 :                     n->targtype = ACL_TARGET_OBJECT;
    7892       11548 :                     n->objtype = OBJECT_TABLE;
    7893       11548 :                     n->objs = $1;
    7894       11548 :                     $$ = n;
    7895             :                 }
    7896             :             | TABLE qualified_name_list
    7897             :                 {
    7898         388 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7899             : 
    7900         388 :                     n->targtype = ACL_TARGET_OBJECT;
    7901         388 :                     n->objtype = OBJECT_TABLE;
    7902         388 :                     n->objs = $2;
    7903         388 :                     $$ = n;
    7904             :                 }
    7905             :             | SEQUENCE qualified_name_list
    7906             :                 {
    7907          22 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7908             : 
    7909          22 :                     n->targtype = ACL_TARGET_OBJECT;
    7910          22 :                     n->objtype = OBJECT_SEQUENCE;
    7911          22 :                     n->objs = $2;
    7912          22 :                     $$ = n;
    7913             :                 }
    7914             :             | FOREIGN DATA_P WRAPPER name_list
    7915             :                 {
    7916          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7917             : 
    7918          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7919          92 :                     n->objtype = OBJECT_FDW;
    7920          92 :                     n->objs = $4;
    7921          92 :                     $$ = n;
    7922             :                 }
    7923             :             | FOREIGN SERVER name_list
    7924             :                 {
    7925          88 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7926             : 
    7927          88 :                     n->targtype = ACL_TARGET_OBJECT;
    7928          88 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7929          88 :                     n->objs = $3;
    7930          88 :                     $$ = n;
    7931             :                 }
    7932             :             | FUNCTION function_with_argtypes_list
    7933             :                 {
    7934        8932 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7935             : 
    7936        8932 :                     n->targtype = ACL_TARGET_OBJECT;
    7937        8932 :                     n->objtype = OBJECT_FUNCTION;
    7938        8932 :                     n->objs = $2;
    7939        8932 :                     $$ = n;
    7940             :                 }
    7941             :             | PROCEDURE function_with_argtypes_list
    7942             :                 {
    7943          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7944             : 
    7945          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7946          42 :                     n->objtype = OBJECT_PROCEDURE;
    7947          42 :                     n->objs = $2;
    7948          42 :                     $$ = n;
    7949             :                 }
    7950             :             | ROUTINE function_with_argtypes_list
    7951             :                 {
    7952           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7953             : 
    7954           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7955           0 :                     n->objtype = OBJECT_ROUTINE;
    7956           0 :                     n->objs = $2;
    7957           0 :                     $$ = n;
    7958             :                 }
    7959             :             | DATABASE name_list
    7960             :                 {
    7961         346 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7962             : 
    7963         346 :                     n->targtype = ACL_TARGET_OBJECT;
    7964         346 :                     n->objtype = OBJECT_DATABASE;
    7965         346 :                     n->objs = $2;
    7966         346 :                     $$ = n;
    7967             :                 }
    7968             :             | DOMAIN_P any_name_list
    7969             :                 {
    7970          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7971             : 
    7972          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7973          26 :                     n->objtype = OBJECT_DOMAIN;
    7974          26 :                     n->objs = $2;
    7975          26 :                     $$ = n;
    7976             :                 }
    7977             :             | LANGUAGE name_list
    7978             :                 {
    7979          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7980             : 
    7981          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7982          42 :                     n->objtype = OBJECT_LANGUAGE;
    7983          42 :                     n->objs = $2;
    7984          42 :                     $$ = n;
    7985             :                 }
    7986             :             | LARGE_P OBJECT_P NumericOnly_list
    7987             :                 {
    7988          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7989             : 
    7990          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7991          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7992          80 :                     n->objs = $3;
    7993          80 :                     $$ = n;
    7994             :                 }
    7995             :             | PARAMETER parameter_name_list
    7996             :                 {
    7997          74 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7998          74 :                     n->targtype = ACL_TARGET_OBJECT;
    7999          74 :                     n->objtype = OBJECT_PARAMETER_ACL;
    8000          74 :                     n->objs = $2;
    8001          74 :                     $$ = n;
    8002             :                 }
    8003             :             | SCHEMA name_list
    8004             :                 {
    8005         362 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8006             : 
    8007         362 :                     n->targtype = ACL_TARGET_OBJECT;
    8008         362 :                     n->objtype = OBJECT_SCHEMA;
    8009         362 :                     n->objs = $2;
    8010         362 :                     $$ = n;
    8011             :                 }
    8012             :             | TABLESPACE name_list
    8013             :                 {
    8014           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8015             : 
    8016           6 :                     n->targtype = ACL_TARGET_OBJECT;
    8017           6 :                     n->objtype = OBJECT_TABLESPACE;
    8018           6 :                     n->objs = $2;
    8019           6 :                     $$ = n;
    8020             :                 }
    8021             :             | TYPE_P any_name_list
    8022             :                 {
    8023         112 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8024             : 
    8025         112 :                     n->targtype = ACL_TARGET_OBJECT;
    8026         112 :                     n->objtype = OBJECT_TYPE;
    8027         112 :                     n->objs = $2;
    8028         112 :                     $$ = n;
    8029             :                 }
    8030             :             | ALL TABLES IN_P SCHEMA name_list
    8031             :                 {
    8032          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8033             : 
    8034          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8035          12 :                     n->objtype = OBJECT_TABLE;
    8036          12 :                     n->objs = $5;
    8037          12 :                     $$ = n;
    8038             :                 }
    8039             :             | ALL SEQUENCES IN_P SCHEMA name_list
    8040             :                 {
    8041           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8042             : 
    8043           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8044           0 :                     n->objtype = OBJECT_SEQUENCE;
    8045           0 :                     n->objs = $5;
    8046           0 :                     $$ = n;
    8047             :                 }
    8048             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    8049             :                 {
    8050           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8051             : 
    8052           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8053           6 :                     n->objtype = OBJECT_FUNCTION;
    8054           6 :                     n->objs = $5;
    8055           6 :                     $$ = n;
    8056             :                 }
    8057             :             | ALL PROCEDURES IN_P SCHEMA name_list
    8058             :                 {
    8059           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8060             : 
    8061           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8062           6 :                     n->objtype = OBJECT_PROCEDURE;
    8063           6 :                     n->objs = $5;
    8064           6 :                     $$ = n;
    8065             :                 }
    8066             :             | ALL ROUTINES IN_P SCHEMA name_list
    8067             :                 {
    8068           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    8069             : 
    8070           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8071           6 :                     n->objtype = OBJECT_ROUTINE;
    8072           6 :                     n->objs = $5;
    8073           6 :                     $$ = n;
    8074             :                 }
    8075             :         ;
    8076             : 
    8077             : 
    8078             : grantee_list:
    8079       22384 :             grantee                                 { $$ = list_make1($1); }
    8080         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    8081             :         ;
    8082             : 
    8083             : grantee:
    8084       22468 :             RoleSpec                                { $$ = $1; }
    8085          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    8086             :         ;
    8087             : 
    8088             : 
    8089             : opt_grant_grant_option:
    8090         102 :             WITH GRANT OPTION { $$ = true; }
    8091       11770 :             | /*EMPTY*/ { $$ = false; }
    8092             :         ;
    8093             : 
    8094             : /*****************************************************************************
    8095             :  *
    8096             :  * GRANT and REVOKE ROLE statements
    8097             :  *
    8098             :  *****************************************************************************/
    8099             : 
    8100             : GrantRoleStmt:
    8101             :             GRANT privilege_list TO role_list opt_granted_by
    8102             :                 {
    8103         588 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8104             : 
    8105         588 :                     n->is_grant = true;
    8106         588 :                     n->granted_roles = $2;
    8107         588 :                     n->grantee_roles = $4;
    8108         588 :                     n->opt = NIL;
    8109         588 :                     n->grantor = $5;
    8110         588 :                     $$ = (Node *) n;
    8111             :                 }
    8112             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8113             :                 {
    8114         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8115             : 
    8116         178 :                     n->is_grant = true;
    8117         178 :                     n->granted_roles = $2;
    8118         178 :                     n->grantee_roles = $4;
    8119         178 :                     n->opt = $6;
    8120         178 :                     n->grantor = $7;
    8121         178 :                     $$ = (Node *) n;
    8122             :                 }
    8123             :         ;
    8124             : 
    8125             : RevokeRoleStmt:
    8126             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8127             :                 {
    8128          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8129             : 
    8130          90 :                     n->is_grant = false;
    8131          90 :                     n->opt = NIL;
    8132          90 :                     n->granted_roles = $2;
    8133          90 :                     n->grantee_roles = $4;
    8134          90 :                     n->grantor = $5;
    8135          90 :                     n->behavior = $6;
    8136          90 :                     $$ = (Node *) n;
    8137             :                 }
    8138             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8139             :                 {
    8140          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8141             :                     DefElem *opt;
    8142             : 
    8143          66 :                     opt = makeDefElem(pstrdup($2),
    8144          66 :                                       (Node *) makeBoolean(false), @2);
    8145          66 :                     n->is_grant = false;
    8146          66 :                     n->opt = list_make1(opt);
    8147          66 :                     n->granted_roles = $5;
    8148          66 :                     n->grantee_roles = $7;
    8149          66 :                     n->grantor = $8;
    8150          66 :                     n->behavior = $9;
    8151          66 :                     $$ = (Node *) n;
    8152             :                 }
    8153             :         ;
    8154             : 
    8155             : grant_role_opt_list:
    8156         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8157         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8158             :         ;
    8159             : 
    8160             : grant_role_opt:
    8161             :         ColLabel grant_role_opt_value
    8162             :             {
    8163         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8164             :             }
    8165             :         ;
    8166             : 
    8167             : grant_role_opt_value:
    8168          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8169         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8170         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8171             :         ;
    8172             : 
    8173         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8174       22962 :             | /*EMPTY*/                                 { $$ = NULL; }
    8175             :         ;
    8176             : 
    8177             : /*****************************************************************************
    8178             :  *
    8179             :  * ALTER DEFAULT PRIVILEGES statement
    8180             :  *
    8181             :  *****************************************************************************/
    8182             : 
    8183             : AlterDefaultPrivilegesStmt:
    8184             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8185             :                 {
    8186         206 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8187             : 
    8188         206 :                     n->options = $4;
    8189         206 :                     n->action = (GrantStmt *) $5;
    8190         206 :                     $$ = (Node *) n;
    8191             :                 }
    8192             :         ;
    8193             : 
    8194             : DefACLOptionList:
    8195         144 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8196         206 :             | /* EMPTY */                           { $$ = NIL; }
    8197             :         ;
    8198             : 
    8199             : DefACLOption:
    8200             :             IN_P SCHEMA name_list
    8201             :                 {
    8202          60 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8203             :                 }
    8204             :             | FOR ROLE role_list
    8205             :                 {
    8206          84 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8207             :                 }
    8208             :             | FOR USER role_list
    8209             :                 {
    8210           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8211             :                 }
    8212             :         ;
    8213             : 
    8214             : /*
    8215             :  * This should match GRANT/REVOKE, except that individual target objects
    8216             :  * are not mentioned and we only allow a subset of object types.
    8217             :  */
    8218             : DefACLAction:
    8219             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8220             :             opt_grant_grant_option
    8221             :                 {
    8222         124 :                     GrantStmt *n = makeNode(GrantStmt);
    8223             : 
    8224         124 :                     n->is_grant = true;
    8225         124 :                     n->privileges = $2;
    8226         124 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8227         124 :                     n->objtype = $4;
    8228         124 :                     n->objects = NIL;
    8229         124 :                     n->grantees = $6;
    8230         124 :                     n->grant_option = $7;
    8231         124 :                     $$ = (Node *) n;
    8232             :                 }
    8233             :             | REVOKE privileges ON defacl_privilege_target
    8234             :             FROM grantee_list opt_drop_behavior
    8235             :                 {
    8236          82 :                     GrantStmt *n = makeNode(GrantStmt);
    8237             : 
    8238          82 :                     n->is_grant = false;
    8239          82 :                     n->grant_option = false;
    8240          82 :                     n->privileges = $2;
    8241          82 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8242          82 :                     n->objtype = $4;
    8243          82 :                     n->objects = NIL;
    8244          82 :                     n->grantees = $6;
    8245          82 :                     n->behavior = $7;
    8246          82 :                     $$ = (Node *) n;
    8247             :                 }
    8248             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8249             :             FROM grantee_list opt_drop_behavior
    8250             :                 {
    8251           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8252             : 
    8253           0 :                     n->is_grant = false;
    8254           0 :                     n->grant_option = true;
    8255           0 :                     n->privileges = $5;
    8256           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8257           0 :                     n->objtype = $7;
    8258           0 :                     n->objects = NIL;
    8259           0 :                     n->grantees = $9;
    8260           0 :                     n->behavior = $10;
    8261           0 :                     $$ = (Node *) n;
    8262             :                 }
    8263             :         ;
    8264             : 
    8265             : defacl_privilege_target:
    8266          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8267          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8268           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8269           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8270          34 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8271          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8272          30 :             | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
    8273             :         ;
    8274             : 
    8275             : 
    8276             : /*****************************************************************************
    8277             :  *
    8278             :  *      QUERY: CREATE INDEX
    8279             :  *
    8280             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8281             :  * willing to make TABLESPACE a fully reserved word.
    8282             :  *****************************************************************************/
    8283             : 
    8284             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8285             :             ON relation_expr access_method_clause '(' index_params ')'
    8286             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8287             :                 {
    8288        6640 :                     IndexStmt *n = makeNode(IndexStmt);
    8289             : 
    8290        6640 :                     n->unique = $2;
    8291        6640 :                     n->concurrent = $4;
    8292        6640 :                     n->idxname = $5;
    8293        6640 :                     n->relation = $7;
    8294        6640 :                     n->accessMethod = $8;
    8295        6640 :                     n->indexParams = $10;
    8296        6640 :                     n->indexIncludingParams = $12;
    8297        6640 :                     n->nulls_not_distinct = !$13;
    8298        6640 :                     n->options = $14;
    8299        6640 :                     n->tableSpace = $15;
    8300        6640 :                     n->whereClause = $16;
    8301        6640 :                     n->excludeOpNames = NIL;
    8302        6640 :                     n->idxcomment = NULL;
    8303        6640 :                     n->indexOid = InvalidOid;
    8304        6640 :                     n->oldNumber = InvalidRelFileNumber;
    8305        6640 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8306        6640 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8307        6640 :                     n->primary = false;
    8308        6640 :                     n->isconstraint = false;
    8309        6640 :                     n->deferrable = false;
    8310        6640 :                     n->initdeferred = false;
    8311        6640 :                     n->transformed = false;
    8312        6640 :                     n->if_not_exists = false;
    8313        6640 :                     n->reset_default_tblspc = false;
    8314        6640 :                     $$ = (Node *) n;
    8315             :                 }
    8316             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8317             :             ON relation_expr access_method_clause '(' index_params ')'
    8318             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8319             :                 {
    8320          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8321             : 
    8322          18 :                     n->unique = $2;
    8323          18 :                     n->concurrent = $4;
    8324          18 :                     n->idxname = $8;
    8325          18 :                     n->relation = $10;
    8326          18 :                     n->accessMethod = $11;
    8327          18 :                     n->indexParams = $13;
    8328          18 :                     n->indexIncludingParams = $15;
    8329          18 :                     n->nulls_not_distinct = !$16;
    8330          18 :                     n->options = $17;
    8331          18 :                     n->tableSpace = $18;
    8332          18 :                     n->whereClause = $19;
    8333          18 :                     n->excludeOpNames = NIL;
    8334          18 :                     n->idxcomment = NULL;
    8335          18 :                     n->indexOid = InvalidOid;
    8336          18 :                     n->oldNumber = InvalidRelFileNumber;
    8337          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8338          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8339          18 :                     n->primary = false;
    8340          18 :                     n->isconstraint = false;
    8341          18 :                     n->deferrable = false;
    8342          18 :                     n->initdeferred = false;
    8343          18 :                     n->transformed = false;
    8344          18 :                     n->if_not_exists = true;
    8345          18 :                     n->reset_default_tblspc = false;
    8346          18 :                     $$ = (Node *) n;
    8347             :                 }
    8348             :         ;
    8349             : 
    8350             : opt_unique:
    8351        1294 :             UNIQUE                                  { $$ = true; }
    8352        5370 :             | /*EMPTY*/                             { $$ = false; }
    8353             :         ;
    8354             : 
    8355             : access_method_clause:
    8356        3010 :             USING name                              { $$ = $2; }
    8357        3882 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8358             :         ;
    8359             : 
    8360        8096 : index_params:   index_elem                          { $$ = list_make1($1); }
    8361        2158 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8362             :         ;
    8363             : 
    8364             : 
    8365             : index_elem_options:
    8366             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8367             :         {
    8368       10836 :             $$ = makeNode(IndexElem);
    8369       10836 :             $$->name = NULL;
    8370       10836 :             $$->expr = NULL;
    8371       10836 :             $$->indexcolname = NULL;
    8372       10836 :             $$->collation = $1;
    8373       10836 :             $$->opclass = $2;
    8374       10836 :             $$->opclassopts = NIL;
    8375       10836 :             $$->ordering = $3;
    8376       10836 :             $$->nulls_ordering = $4;
    8377             :         }
    8378             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8379             :         {
    8380         142 :             $$ = makeNode(IndexElem);
    8381         142 :             $$->name = NULL;
    8382         142 :             $$->expr = NULL;
    8383         142 :             $$->indexcolname = NULL;
    8384         142 :             $$->collation = $1;
    8385         142 :             $$->opclass = $2;
    8386         142 :             $$->opclassopts = $3;
    8387         142 :             $$->ordering = $4;
    8388         142 :             $$->nulls_ordering = $5;
    8389             :         }
    8390             :     ;
    8391             : 
    8392             : /*
    8393             :  * Index attributes can be either simple column references, or arbitrary
    8394             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8395             :  * an expression that's just a function call to be written without parens.
    8396             :  */
    8397             : index_elem: ColId index_elem_options
    8398             :                 {
    8399        9852 :                     $$ = $2;
    8400        9852 :                     $$->name = $1;
    8401             :                 }
    8402             :             | func_expr_windowless index_elem_options
    8403             :                 {
    8404         610 :                     $$ = $2;
    8405         610 :                     $$->expr = $1;
    8406             :                 }
    8407             :             | '(' a_expr ')' index_elem_options
    8408             :                 {
    8409         516 :                     $$ = $4;
    8410         516 :                     $$->expr = $2;
    8411             :                 }
    8412             :         ;
    8413             : 
    8414         218 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8415        6440 :              |      /* EMPTY */                     { $$ = NIL; }
    8416             :         ;
    8417             : 
    8418         218 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8419         166 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8420             :         ;
    8421             : 
    8422         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8423       16276 :             | /*EMPTY*/                             { $$ = NIL; }
    8424             :         ;
    8425             : 
    8426             : 
    8427        1820 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8428        3556 :             | DESC                          { $$ = SORTBY_DESC; }
    8429      112758 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8430             :         ;
    8431             : 
    8432         344 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8433        1732 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8434      116278 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8435             :         ;
    8436             : 
    8437             : 
    8438             : /*****************************************************************************
    8439             :  *
    8440             :  *      QUERY:
    8441             :  *              create [or replace] function <fname>
    8442             :  *                      [(<type-1> { , <type-n>})]
    8443             :  *                      returns <type-r>
    8444             :  *                      as <filename or code in language as appropriate>
    8445             :  *                      language <lang> [with parameters]
    8446             :  *
    8447             :  *****************************************************************************/
    8448             : 
    8449             : CreateFunctionStmt:
    8450             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8451             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8452             :                 {
    8453       24336 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8454             : 
    8455       24336 :                     n->is_procedure = false;
    8456       24336 :                     n->replace = $2;
    8457       24336 :                     n->funcname = $4;
    8458       24336 :                     n->parameters = $5;
    8459       24336 :                     n->returnType = $7;
    8460       24336 :                     n->options = $8;
    8461       24336 :                     n->sql_body = $9;
    8462       24336 :                     $$ = (Node *) n;
    8463             :                 }
    8464             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8465             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8466             :                 {
    8467         194 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8468             : 
    8469         194 :                     n->is_procedure = false;
    8470         194 :                     n->replace = $2;
    8471         194 :                     n->funcname = $4;
    8472         194 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8473         194 :                     n->returnType = TableFuncTypeName($9);
    8474         194 :                     n->returnType->location = @7;
    8475         194 :                     n->options = $11;
    8476         194 :                     n->sql_body = $12;
    8477         194 :                     $$ = (Node *) n;
    8478             :                 }
    8479             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8480             :               opt_createfunc_opt_list opt_routine_body
    8481             :                 {
    8482         488 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8483             : 
    8484         488 :                     n->is_procedure = false;
    8485         488 :                     n->replace = $2;
    8486         488 :                     n->funcname = $4;
    8487         488 :                     n->parameters = $5;
    8488         488 :                     n->returnType = NULL;
    8489         488 :                     n->options = $6;
    8490         488 :                     n->sql_body = $7;
    8491         488 :                     $$ = (Node *) n;
    8492             :                 }
    8493             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8494             :               opt_createfunc_opt_list opt_routine_body
    8495             :                 {
    8496         370 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8497             : 
    8498         370 :                     n->is_procedure = true;
    8499         370 :                     n->replace = $2;
    8500         370 :                     n->funcname = $4;
    8501         370 :                     n->parameters = $5;
    8502         370 :                     n->returnType = NULL;
    8503         370 :                     n->options = $6;
    8504         370 :                     n->sql_body = $7;
    8505         370 :                     $$ = (Node *) n;
    8506             :                 }
    8507             :         ;
    8508             : 
    8509             : opt_or_replace:
    8510        9994 :             OR REPLACE                              { $$ = true; }
    8511       20840 :             | /*EMPTY*/                             { $$ = false; }
    8512             :         ;
    8513             : 
    8514       12086 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8515        5890 :             | '(' ')'                               { $$ = NIL; }
    8516             :         ;
    8517             : 
    8518             : func_args_list:
    8519       12086 :             func_arg                                { $$ = list_make1($1); }
    8520       11264 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8521             :         ;
    8522             : 
    8523             : function_with_argtypes_list:
    8524       12700 :             function_with_argtypes                  { $$ = list_make1($1); }
    8525             :             | function_with_argtypes_list ',' function_with_argtypes
    8526          84 :                                                     { $$ = lappend($1, $3); }
    8527             :         ;
    8528             : 
    8529             : function_with_argtypes:
    8530             :             func_name func_args
    8531             :                 {
    8532       17976 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8533             : 
    8534       17976 :                     n->objname = $1;
    8535       17976 :                     n->objargs = extractArgTypes($2);
    8536       17976 :                     n->objfuncargs = $2;
    8537       17976 :                     $$ = n;
    8538             :                 }
    8539             :             /*
    8540             :              * Because of reduce/reduce conflicts, we can't use func_name
    8541             :              * below, but we can write it out the long way, which actually
    8542             :              * allows more cases.
    8543             :              */
    8544             :             | type_func_name_keyword
    8545             :                 {
    8546           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8547             : 
    8548           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8549           0 :                     n->args_unspecified = true;
    8550           0 :                     $$ = n;
    8551             :                 }
    8552             :             | ColId
    8553             :                 {
    8554         370 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8555             : 
    8556         370 :                     n->objname = list_make1(makeString($1));
    8557         370 :                     n->args_unspecified = true;
    8558         370 :                     $$ = n;
    8559             :                 }
    8560             :             | ColId indirection
    8561             :                 {
    8562          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8563             : 
    8564          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8565             :                                                   yyscanner);
    8566          28 :                     n->args_unspecified = true;
    8567          28 :                     $$ = n;
    8568             :                 }
    8569             :         ;
    8570             : 
    8571             : /*
    8572             :  * func_args_with_defaults is separate because we only want to accept
    8573             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8574             :  */
    8575             : func_args_with_defaults:
    8576       20860 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8577        4528 :         | '(' ')'                                   { $$ = NIL; }
    8578             :         ;
    8579             : 
    8580             : func_args_with_defaults_list:
    8581       20860 :         func_arg_with_default                       { $$ = list_make1($1); }
    8582             :         | func_args_with_defaults_list ',' func_arg_with_default
    8583       35752 :                                                     { $$ = lappend($1, $3); }
    8584             :         ;
    8585             : 
    8586             : /*
    8587             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8588             :  * param_name first; accept both since it's likely people will try both
    8589             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8590             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8591             :  *
    8592             :  * We can catch over-specified arguments here if we want to,
    8593             :  * but for now better to silently swallow typmod, etc.
    8594             :  * - thomas 2000-03-22
    8595             :  */
    8596             : func_arg:
    8597             :             arg_class param_name func_type
    8598             :                 {
    8599       16930 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8600             : 
    8601       16930 :                     n->name = $2;
    8602       16930 :                     n->argType = $3;
    8603       16930 :                     n->mode = $1;
    8604       16930 :                     n->defexpr = NULL;
    8605       16930 :                     n->location = @1;
    8606       16930 :                     $$ = n;
    8607             :                 }
    8608             :             | param_name arg_class func_type
    8609             :                 {
    8610         420 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8611             : 
    8612         420 :                     n->name = $1;
    8613         420 :                     n->argType = $3;
    8614         420 :                     n->mode = $2;
    8615         420 :                     n->defexpr = NULL;
    8616         420 :                     n->location = @1;
    8617         420 :                     $$ = n;
    8618             :                 }
    8619             :             | param_name func_type
    8620             :                 {
    8621       15652 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8622             : 
    8623       15652 :                     n->name = $1;
    8624       15652 :                     n->argType = $2;
    8625       15652 :                     n->mode = FUNC_PARAM_DEFAULT;
    8626       15652 :                     n->defexpr = NULL;
    8627       15652 :                     n->location = @1;
    8628       15652 :                     $$ = n;
    8629             :                 }
    8630             :             | arg_class func_type
    8631             :                 {
    8632         328 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8633             : 
    8634         328 :                     n->name = NULL;
    8635         328 :                     n->argType = $2;
    8636         328 :                     n->mode = $1;
    8637         328 :                     n->defexpr = NULL;
    8638         328 :                     n->location = @1;
    8639         328 :                     $$ = n;
    8640             :                 }
    8641             :             | func_type
    8642             :                 {
    8643       47532 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8644             : 
    8645       47532 :                     n->name = NULL;
    8646       47532 :                     n->argType = $1;
    8647       47532 :                     n->mode = FUNC_PARAM_DEFAULT;
    8648       47532 :                     n->defexpr = NULL;
    8649       47532 :                     n->location = @1;
    8650       47532 :                     $$ = n;
    8651             :                 }
    8652             :         ;
    8653             : 
    8654             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8655        4018 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8656       12896 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8657         198 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8658           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8659         566 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8660             :         ;
    8661             : 
    8662             : /*
    8663             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8664             :  */
    8665             : param_name: type_function_name
    8666             :         ;
    8667             : 
    8668             : func_return:
    8669             :             func_type
    8670             :                 {
    8671             :                     /* We can catch over-specified results here if we want to,
    8672             :                      * but for now better to silently swallow typmod, etc.
    8673             :                      * - thomas 2000-03-22
    8674             :                      */
    8675       24336 :                     $$ = $1;
    8676             :                 }
    8677             :         ;
    8678             : 
    8679             : /*
    8680             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8681             :  * but that causes reduce/reduce conflicts.  type_function_name
    8682             :  * is next best choice.
    8683             :  */
    8684      126392 : func_type:  Typename                                { $$ = $1; }
    8685             :             | type_function_name attrs '%' TYPE_P
    8686             :                 {
    8687          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8688          18 :                     $$->pct_type = true;
    8689          18 :                     $$->location = @1;
    8690             :                 }
    8691             :             | SETOF type_function_name attrs '%' TYPE_P
    8692             :                 {
    8693           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8694           6 :                     $$->pct_type = true;
    8695           6 :                     $$->setof = true;
    8696           6 :                     $$->location = @2;
    8697             :                 }
    8698             :         ;
    8699             : 
    8700             : func_arg_with_default:
    8701             :         func_arg
    8702             :                 {
    8703       50178 :                     $$ = $1;
    8704             :                 }
    8705             :         | func_arg DEFAULT a_expr
    8706             :                 {
    8707        6238 :                     $$ = $1;
    8708        6238 :                     $$->defexpr = $3;
    8709             :                 }
    8710             :         | func_arg '=' a_expr
    8711             :                 {
    8712         196 :                     $$ = $1;
    8713         196 :                     $$->defexpr = $3;
    8714             :                 }
    8715             :         ;
    8716             : 
    8717             : /* Aggregate args can be most things that function args can be */
    8718             : aggr_arg:   func_arg
    8719             :                 {
    8720         900 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8721          60 :                           $1->mode == FUNC_PARAM_IN ||
    8722          60 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8723           0 :                         ereport(ERROR,
    8724             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8725             :                                  errmsg("aggregates cannot have output arguments"),
    8726             :                                  parser_errposition(@1)));
    8727         900 :                     $$ = $1;
    8728             :                 }
    8729             :         ;
    8730             : 
    8731             : /*
    8732             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8733             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8734             :  *
    8735             :  * (*)                                  - normal agg with no args
    8736             :  * (aggr_arg,...)                       - normal agg with args
    8737             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8738             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8739             :  *
    8740             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8741             :  *
    8742             :  * An additional restriction is that if the direct-args list ends in a
    8743             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8744             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8745             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8746             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8747             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8748             :  * in cases such as DROP AGGREGATE.
    8749             :  *
    8750             :  * The return value of this production is a two-element list, in which the
    8751             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8752             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8753             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8754             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8755             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8756             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8757             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8758             :  * sublist.
    8759             :  */
    8760             : aggr_args:  '(' '*' ')'
    8761             :                 {
    8762         136 :                     $$ = list_make2(NIL, makeInteger(-1));
    8763             :                 }
    8764             :             | '(' aggr_args_list ')'
    8765             :                 {
    8766         732 :                     $$ = list_make2($2, makeInteger(-1));
    8767             :                 }
    8768             :             | '(' ORDER BY aggr_args_list ')'
    8769             :                 {
    8770           6 :                     $$ = list_make2($4, makeInteger(0));
    8771             :                 }
    8772             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8773             :                 {
    8774             :                     /* this is the only case requiring consistency checking */
    8775          32 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8776             :                 }
    8777             :         ;
    8778             : 
    8779             : aggr_args_list:
    8780         802 :             aggr_arg                                { $$ = list_make1($1); }
    8781          98 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8782             :         ;
    8783             : 
    8784             : aggregate_with_argtypes:
    8785             :             func_name aggr_args
    8786             :                 {
    8787         362 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8788             : 
    8789         362 :                     n->objname = $1;
    8790         362 :                     n->objargs = extractAggrArgTypes($2);
    8791         362 :                     n->objfuncargs = (List *) linitial($2);
    8792         362 :                     $$ = n;
    8793             :                 }
    8794             :         ;
    8795             : 
    8796             : aggregate_with_argtypes_list:
    8797         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8798             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8799           0 :                                                     { $$ = lappend($1, $3); }
    8800             :         ;
    8801             : 
    8802             : opt_createfunc_opt_list:
    8803             :             createfunc_opt_list
    8804          54 :             | /*EMPTY*/ { $$ = NIL; }
    8805             :     ;
    8806             : 
    8807             : createfunc_opt_list:
    8808             :             /* Must be at least one to prevent conflict */
    8809       25334 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8810       67422 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8811             :     ;
    8812             : 
    8813             : /*
    8814             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8815             :  */
    8816             : common_func_opt_item:
    8817             :             CALLED ON NULL_P INPUT_P
    8818             :                 {
    8819         380 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8820             :                 }
    8821             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8822             :                 {
    8823         882 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8824             :                 }
    8825             :             | STRICT_P
    8826             :                 {
    8827       13772 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8828             :                 }
    8829             :             | IMMUTABLE
    8830             :                 {
    8831       10200 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8832             :                 }
    8833             :             | STABLE
    8834             :                 {
    8835        2524 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8836             :                 }
    8837             :             | VOLATILE
    8838             :                 {
    8839        1748 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8840             :                 }
    8841             :             | EXTERNAL SECURITY DEFINER
    8842             :                 {
    8843           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8844             :                 }
    8845             :             | EXTERNAL SECURITY INVOKER
    8846             :                 {
    8847           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8848             :                 }
    8849             :             | SECURITY DEFINER
    8850             :                 {
    8851          58 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8852             :                 }
    8853             :             | SECURITY INVOKER
    8854             :                 {
    8855          18 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8856             :                 }
    8857             :             | LEAKPROOF
    8858             :                 {
    8859          46 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8860             :                 }
    8861             :             | NOT LEAKPROOF
    8862             :                 {
    8863          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8864             :                 }
    8865             :             | COST NumericOnly
    8866             :                 {
    8867        4360 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8868             :                 }
    8869             :             | ROWS NumericOnly
    8870             :                 {
    8871         600 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8872             :                 }
    8873             :             | SUPPORT any_name
    8874             :                 {
    8875         114 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8876             :                 }
    8877             :             | FunctionSetResetClause
    8878             :                 {
    8879             :                     /* we abuse the normal content of a DefElem here */
    8880         146 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8881             :                 }
    8882             :             | PARALLEL ColId
    8883             :                 {
    8884       14124 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8885             :                 }
    8886             :         ;
    8887             : 
    8888             : createfunc_opt_item:
    8889             :             AS func_as
    8890             :                 {
    8891       19714 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8892             :                 }
    8893             :             | LANGUAGE NonReservedWord_or_Sconst
    8894             :                 {
    8895       25314 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8896             :                 }
    8897             :             | TRANSFORM transform_type_list
    8898             :                 {
    8899         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8900             :                 }
    8901             :             | WINDOW
    8902             :                 {
    8903          20 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8904             :                 }
    8905             :             | common_func_opt_item
    8906             :                 {
    8907       47590 :                     $$ = $1;
    8908             :                 }
    8909             :         ;
    8910             : 
    8911       16424 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8912             :             | Sconst ',' Sconst
    8913             :                 {
    8914        3290 :                     $$ = list_make2(makeString($1), makeString($3));
    8915             :                 }
    8916             :         ;
    8917             : 
    8918             : ReturnStmt: RETURN a_expr
    8919             :                 {
    8920        4878 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8921             : 
    8922        4878 :                     r->returnval = (Node *) $2;
    8923        4878 :                     $$ = (Node *) r;
    8924             :                 }
    8925             :         ;
    8926             : 
    8927             : opt_routine_body:
    8928             :             ReturnStmt
    8929             :                 {
    8930        4872 :                     $$ = $1;
    8931             :                 }
    8932             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8933             :                 {
    8934             :                     /*
    8935             :                      * A compound statement is stored as a single-item list
    8936             :                      * containing the list of statements as its member.  That
    8937             :                      * way, the parse analysis code can tell apart an empty
    8938             :                      * body from no body at all.
    8939             :                      */
    8940         808 :                     $$ = (Node *) list_make1($3);
    8941             :                 }
    8942             :             | /*EMPTY*/
    8943             :                 {
    8944       19708 :                     $$ = NULL;
    8945             :                 }
    8946             :         ;
    8947             : 
    8948             : routine_body_stmt_list:
    8949             :             routine_body_stmt_list routine_body_stmt ';'
    8950             :                 {
    8951             :                     /* As in stmtmulti, discard empty statements */
    8952         824 :                     if ($2 != NULL)
    8953         806 :                         $$ = lappend($1, $2);
    8954             :                     else
    8955          18 :                         $$ = $1;
    8956             :                 }
    8957             :             | /*EMPTY*/
    8958             :                 {
    8959         808 :                     $$ = NIL;
    8960             :                 }
    8961             :         ;
    8962             : 
    8963             : routine_body_stmt:
    8964             :             stmt
    8965             :             | ReturnStmt
    8966             :         ;
    8967             : 
    8968             : transform_type_list:
    8969         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8970           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8971             :         ;
    8972             : 
    8973             : opt_definition:
    8974         654 :             WITH definition                         { $$ = $2; }
    8975       10126 :             | /*EMPTY*/                             { $$ = NIL; }
    8976             :         ;
    8977             : 
    8978             : table_func_column:  param_name func_type
    8979             :                 {
    8980         454 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8981             : 
    8982         454 :                     n->name = $1;
    8983         454 :                     n->argType = $2;
    8984         454 :                     n->mode = FUNC_PARAM_TABLE;
    8985         454 :                     n->defexpr = NULL;
    8986         454 :                     n->location = @1;
    8987         454 :                     $$ = n;
    8988             :                 }
    8989             :         ;
    8990             : 
    8991             : table_func_column_list:
    8992             :             table_func_column
    8993             :                 {
    8994         194 :                     $$ = list_make1($1);
    8995             :                 }
    8996             :             | table_func_column_list ',' table_func_column
    8997             :                 {
    8998         260 :                     $$ = lappend($1, $3);
    8999             :                 }
    9000             :         ;
    9001             : 
    9002             : /*****************************************************************************
    9003             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    9004             :  *
    9005             :  * RENAME and OWNER subcommands are already provided by the generic
    9006             :  * ALTER infrastructure, here we just specify alterations that can
    9007             :  * only be applied to functions.
    9008             :  *
    9009             :  *****************************************************************************/
    9010             : AlterFunctionStmt:
    9011             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    9012             :                 {
    9013        1372 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9014             : 
    9015        1372 :                     n->objtype = OBJECT_FUNCTION;
    9016        1372 :                     n->func = $3;
    9017        1372 :                     n->actions = $4;
    9018        1372 :                     $$ = (Node *) n;
    9019             :                 }
    9020             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    9021             :                 {
    9022          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9023             : 
    9024          18 :                     n->objtype = OBJECT_PROCEDURE;
    9025          18 :                     n->func = $3;
    9026          18 :                     n->actions = $4;
    9027          18 :                     $$ = (Node *) n;
    9028             :                 }
    9029             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    9030             :                 {
    9031           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9032             : 
    9033           0 :                     n->objtype = OBJECT_ROUTINE;
    9034           0 :                     n->func = $3;
    9035           0 :                     n->actions = $4;
    9036           0 :                     $$ = (Node *) n;
    9037             :                 }
    9038             :         ;
    9039             : 
    9040             : alterfunc_opt_list:
    9041             :             /* At least one option must be specified */
    9042        1390 :             common_func_opt_item                    { $$ = list_make1($1); }
    9043           4 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    9044             :         ;
    9045             : 
    9046             : /* Ignored, merely for SQL compliance */
    9047             : opt_restrict:
    9048             :             RESTRICT
    9049             :             | /* EMPTY */
    9050             :         ;
    9051             : 
    9052             : 
    9053             : /*****************************************************************************
    9054             :  *
    9055             :  *      QUERY:
    9056             :  *
    9057             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9058             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9059             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9060             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    9061             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    9062             :  *
    9063             :  *****************************************************************************/
    9064             : 
    9065             : RemoveFuncStmt:
    9066             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    9067             :                 {
    9068        3302 :                     DropStmt *n = makeNode(DropStmt);
    9069             : 
    9070        3302 :                     n->removeType = OBJECT_FUNCTION;
    9071        3302 :                     n->objects = $3;
    9072        3302 :                     n->behavior = $4;
    9073        3302 :                     n->missing_ok = false;
    9074        3302 :                     n->concurrent = false;
    9075        3302 :                     $$ = (Node *) n;
    9076             :                 }
    9077             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9078             :                 {
    9079         260 :                     DropStmt *n = makeNode(DropStmt);
    9080             : 
    9081         260 :                     n->removeType = OBJECT_FUNCTION;
    9082         260 :                     n->objects = $5;
    9083         260 :                     n->behavior = $6;
    9084         260 :                     n->missing_ok = true;
    9085         260 :                     n->concurrent = false;
    9086         260 :                     $$ = (Node *) n;
    9087             :                 }
    9088             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    9089             :                 {
    9090         140 :                     DropStmt *n = makeNode(DropStmt);
    9091             : 
    9092         140 :                     n->removeType = OBJECT_PROCEDURE;
    9093         140 :                     n->objects = $3;
    9094         140 :                     n->behavior = $4;
    9095         140 :                     n->missing_ok = false;
    9096         140 :                     n->concurrent = false;
    9097         140 :                     $$ = (Node *) n;
    9098             :                 }
    9099             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9100             :                 {
    9101           6 :                     DropStmt *n = makeNode(DropStmt);
    9102             : 
    9103           6 :                     n->removeType = OBJECT_PROCEDURE;
    9104           6 :                     n->objects = $5;
    9105           6 :                     n->behavior = $6;
    9106           6 :                     n->missing_ok = true;
    9107           6 :                     n->concurrent = false;
    9108           6 :                     $$ = (Node *) n;
    9109             :                 }
    9110             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9111             :                 {
    9112          12 :                     DropStmt *n = makeNode(DropStmt);
    9113             : 
    9114          12 :                     n->removeType = OBJECT_ROUTINE;
    9115          12 :                     n->objects = $3;
    9116          12 :                     n->behavior = $4;
    9117          12 :                     n->missing_ok = false;
    9118          12 :                     n->concurrent = false;
    9119          12 :                     $$ = (Node *) n;
    9120             :                 }
    9121             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9122             :                 {
    9123           6 :                     DropStmt *n = makeNode(DropStmt);
    9124             : 
    9125           6 :                     n->removeType = OBJECT_ROUTINE;
    9126           6 :                     n->objects = $5;
    9127           6 :                     n->behavior = $6;
    9128           6 :                     n->missing_ok = true;
    9129           6 :                     n->concurrent = false;
    9130           6 :                     $$ = (Node *) n;
    9131             :                 }
    9132             :         ;
    9133             : 
    9134             : RemoveAggrStmt:
    9135             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9136             :                 {
    9137          74 :                     DropStmt *n = makeNode(DropStmt);
    9138             : 
    9139          74 :                     n->removeType = OBJECT_AGGREGATE;
    9140          74 :                     n->objects = $3;
    9141          74 :                     n->behavior = $4;
    9142          74 :                     n->missing_ok = false;
    9143          74 :                     n->concurrent = false;
    9144          74 :                     $$ = (Node *) n;
    9145             :                 }
    9146             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9147             :                 {
    9148          30 :                     DropStmt *n = makeNode(DropStmt);
    9149             : 
    9150          30 :                     n->removeType = OBJECT_AGGREGATE;
    9151          30 :                     n->objects = $5;
    9152          30 :                     n->behavior = $6;
    9153          30 :                     n->missing_ok = true;
    9154          30 :                     n->concurrent = false;
    9155          30 :                     $$ = (Node *) n;
    9156             :                 }
    9157             :         ;
    9158             : 
    9159             : RemoveOperStmt:
    9160             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9161             :                 {
    9162         200 :                     DropStmt *n = makeNode(DropStmt);
    9163             : 
    9164         200 :                     n->removeType = OBJECT_OPERATOR;
    9165         200 :                     n->objects = $3;
    9166         200 :                     n->behavior = $4;
    9167         200 :                     n->missing_ok = false;
    9168         200 :                     n->concurrent = false;
    9169         200 :                     $$ = (Node *) n;
    9170             :                 }
    9171             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9172             :                 {
    9173          30 :                     DropStmt *n = makeNode(DropStmt);
    9174             : 
    9175          30 :                     n->removeType = OBJECT_OPERATOR;
    9176          30 :                     n->objects = $5;
    9177          30 :                     n->behavior = $6;
    9178          30 :                     n->missing_ok = true;
    9179          30 :                     n->concurrent = false;
    9180          30 :                     $$ = (Node *) n;
    9181             :                 }
    9182             :         ;
    9183             : 
    9184             : oper_argtypes:
    9185             :             '(' Typename ')'
    9186             :                 {
    9187          12 :                    ereport(ERROR,
    9188             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9189             :                             errmsg("missing argument"),
    9190             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9191             :                             parser_errposition(@3)));
    9192             :                 }
    9193             :             | '(' Typename ',' Typename ')'
    9194        2464 :                     { $$ = list_make2($2, $4); }
    9195             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9196          32 :                     { $$ = list_make2(NULL, $4); }
    9197             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9198          12 :                     { $$ = list_make2($2, NULL); }
    9199             :         ;
    9200             : 
    9201             : any_operator:
    9202             :             all_Op
    9203       22160 :                     { $$ = list_make1(makeString($1)); }
    9204             :             | ColId '.' any_operator
    9205       15910 :                     { $$ = lcons(makeString($1), $3); }
    9206             :         ;
    9207             : 
    9208             : operator_with_argtypes_list:
    9209         230 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9210             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9211           0 :                                                     { $$ = lappend($1, $3); }
    9212             :         ;
    9213             : 
    9214             : operator_with_argtypes:
    9215             :             any_operator oper_argtypes
    9216             :                 {
    9217        2508 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9218             : 
    9219        2508 :                     n->objname = $1;
    9220        2508 :                     n->objargs = $2;
    9221        2508 :                     $$ = n;
    9222             :                 }
    9223             :         ;
    9224             : 
    9225             : /*****************************************************************************
    9226             :  *
    9227             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9228             :  *
    9229             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9230             :  * in the clause order.
    9231             :  *
    9232             :  *****************************************************************************/
    9233             : 
    9234             : DoStmt: DO dostmt_opt_list
    9235             :                 {
    9236        1138 :                     DoStmt *n = makeNode(DoStmt);
    9237             : 
    9238        1138 :                     n->args = $2;
    9239        1138 :                     $$ = (Node *) n;
    9240             :                 }
    9241             :         ;
    9242             : 
    9243             : dostmt_opt_list:
    9244        1138 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9245         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9246             :         ;
    9247             : 
    9248             : dostmt_opt_item:
    9249             :             Sconst
    9250             :                 {
    9251        1138 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9252             :                 }
    9253             :             | LANGUAGE NonReservedWord_or_Sconst
    9254             :                 {
    9255         198 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9256             :                 }
    9257             :         ;
    9258             : 
    9259             : /*****************************************************************************
    9260             :  *
    9261             :  *      CREATE CAST / DROP CAST
    9262             :  *
    9263             :  *****************************************************************************/
    9264             : 
    9265             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9266             :                     WITH FUNCTION function_with_argtypes cast_context
    9267             :                 {
    9268         108 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9269             : 
    9270         108 :                     n->sourcetype = $4;
    9271         108 :                     n->targettype = $6;
    9272         108 :                     n->func = $10;
    9273         108 :                     n->context = (CoercionContext) $11;
    9274         108 :                     n->inout = false;
    9275         108 :                     $$ = (Node *) n;
    9276             :                 }
    9277             :             | CREATE CAST '(' Typename AS Typename ')'
    9278             :                     WITHOUT FUNCTION cast_context
    9279             :                 {
    9280         162 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9281             : 
    9282         162 :                     n->sourcetype = $4;
    9283         162 :                     n->targettype = $6;
    9284         162 :                     n->func = NULL;
    9285         162 :                     n->context = (CoercionContext) $10;
    9286         162 :                     n->inout = false;
    9287         162 :                     $$ = (Node *) n;
    9288             :                 }
    9289             :             | CREATE CAST '(' Typename AS Typename ')'
    9290             :                     WITH INOUT cast_context
    9291             :                 {
    9292           8 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9293             : 
    9294           8 :                     n->sourcetype = $4;
    9295           8 :                     n->targettype = $6;
    9296           8 :                     n->func = NULL;
    9297           8 :                     n->context = (CoercionContext) $10;
    9298           8 :                     n->inout = true;
    9299           8 :                     $$ = (Node *) n;
    9300             :                 }
    9301             :         ;
    9302             : 
    9303          36 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9304          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9305         184 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9306             :         ;
    9307             : 
    9308             : 
    9309             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9310             :                 {
    9311          60 :                     DropStmt *n = makeNode(DropStmt);
    9312             : 
    9313          60 :                     n->removeType = OBJECT_CAST;
    9314          60 :                     n->objects = list_make1(list_make2($5, $7));
    9315          60 :                     n->behavior = $9;
    9316          60 :                     n->missing_ok = $3;
    9317          60 :                     n->concurrent = false;
    9318          60 :                     $$ = (Node *) n;
    9319             :                 }
    9320             :         ;
    9321             : 
    9322          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9323          38 :         | /*EMPTY*/                             { $$ = false; }
    9324             :         ;
    9325             : 
    9326             : 
    9327             : /*****************************************************************************
    9328             :  *
    9329             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9330             :  *
    9331             :  *****************************************************************************/
    9332             : 
    9333             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9334             :                 {
    9335          50 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9336             : 
    9337          50 :                     n->replace = $2;
    9338          50 :                     n->type_name = $5;
    9339          50 :                     n->lang = $7;
    9340          50 :                     n->fromsql = linitial($9);
    9341          50 :                     n->tosql = lsecond($9);
    9342          50 :                     $$ = (Node *) n;
    9343             :                 }
    9344             :         ;
    9345             : 
    9346             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9347             :                 {
    9348          44 :                     $$ = list_make2($5, $11);
    9349             :                 }
    9350             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9351             :                 {
    9352           0 :                     $$ = list_make2($11, $5);
    9353             :                 }
    9354             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9355             :                 {
    9356           4 :                     $$ = list_make2($5, NULL);
    9357             :                 }
    9358             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9359             :                 {
    9360           2 :                     $$ = list_make2(NULL, $5);
    9361             :                 }
    9362             :         ;
    9363             : 
    9364             : 
    9365             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9366             :                 {
    9367          14 :                     DropStmt *n = makeNode(DropStmt);
    9368             : 
    9369          14 :                     n->removeType = OBJECT_TRANSFORM;
    9370          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9371          14 :                     n->behavior = $8;
    9372          14 :                     n->missing_ok = $3;
    9373          14 :                     $$ = (Node *) n;
    9374             :                 }
    9375             :         ;
    9376             : 
    9377             : 
    9378             : /*****************************************************************************
    9379             :  *
    9380             :  *      QUERY:
    9381             :  *
    9382             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9383             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9384             :  *****************************************************************************/
    9385             : 
    9386             : ReindexStmt:
    9387             :             REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
    9388             :                 {
    9389         940 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9390             : 
    9391         940 :                     n->kind = $3;
    9392         940 :                     n->relation = $5;
    9393         940 :                     n->name = NULL;
    9394         940 :                     n->params = $2;
    9395         940 :                     if ($4)
    9396         536 :                         n->params = lappend(n->params,
    9397         536 :                                             makeDefElem("concurrently", NULL, @4));
    9398         940 :                     $$ = (Node *) n;
    9399             :                 }
    9400             :             | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
    9401             :                 {
    9402         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9403             : 
    9404         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9405         114 :                     n->relation = NULL;
    9406         114 :                     n->name = $5;
    9407         114 :                     n->params = $2;
    9408         114 :                     if ($4)
    9409          40 :                         n->params = lappend(n->params,
    9410          40 :                                             makeDefElem("concurrently", NULL, @4));
    9411         114 :                     $$ = (Node *) n;
    9412             :                 }
    9413             :             | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
    9414             :                 {
    9415          64 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9416             : 
    9417          64 :                     n->kind = $3;
    9418          64 :                     n->relation = NULL;
    9419          64 :                     n->name = $5;
    9420          64 :                     n->params = $2;
    9421          64 :                     if ($4)
    9422          10 :                         n->params = lappend(n->params,
    9423          10 :                                             makeDefElem("concurrently", NULL, @4));
    9424          64 :                     $$ = (Node *) n;
    9425             :                 }
    9426             :         ;
    9427             : reindex_target_relation:
    9428         412 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9429         528 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9430             :         ;
    9431             : reindex_target_all:
    9432          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9433          30 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9434             :         ;
    9435             : 
    9436             : /*****************************************************************************
    9437             :  *
    9438             :  * ALTER TABLESPACE
    9439             :  *
    9440             :  *****************************************************************************/
    9441             : 
    9442             : AlterTblSpcStmt:
    9443             :             ALTER TABLESPACE name SET reloptions
    9444             :                 {
    9445             :                     AlterTableSpaceOptionsStmt *n =
    9446          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9447             : 
    9448          12 :                     n->tablespacename = $3;
    9449          12 :                     n->options = $5;
    9450          12 :                     n->isReset = false;
    9451          12 :                     $$ = (Node *) n;
    9452             :                 }
    9453             :             | ALTER TABLESPACE name RESET reloptions
    9454             :                 {
    9455             :                     AlterTableSpaceOptionsStmt *n =
    9456          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9457             : 
    9458          12 :                     n->tablespacename = $3;
    9459          12 :                     n->options = $5;
    9460          12 :                     n->isReset = true;
    9461          12 :                     $$ = (Node *) n;
    9462             :                 }
    9463             :         ;
    9464             : 
    9465             : /*****************************************************************************
    9466             :  *
    9467             :  * ALTER THING name RENAME TO newname
    9468             :  *
    9469             :  *****************************************************************************/
    9470             : 
    9471             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9472             :                 {
    9473          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9474             : 
    9475          42 :                     n->renameType = OBJECT_AGGREGATE;
    9476          42 :                     n->object = (Node *) $3;
    9477          42 :                     n->newname = $6;
    9478          42 :                     n->missing_ok = false;
    9479          42 :                     $$ = (Node *) n;
    9480             :                 }
    9481             :             | ALTER COLLATION any_name RENAME TO name
    9482             :                 {
    9483          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9484             : 
    9485          18 :                     n->renameType = OBJECT_COLLATION;
    9486          18 :                     n->object = (Node *) $3;
    9487          18 :                     n->newname = $6;
    9488          18 :                     n->missing_ok = false;
    9489          18 :                     $$ = (Node *) n;
    9490             :                 }
    9491             :             | ALTER CONVERSION_P any_name RENAME TO name
    9492             :                 {
    9493          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9494             : 
    9495          24 :                     n->renameType = OBJECT_CONVERSION;
    9496          24 :                     n->object = (Node *) $3;
    9497          24 :                     n->newname = $6;
    9498          24 :                     n->missing_ok = false;
    9499          24 :                     $$ = (Node *) n;
    9500             :                 }
    9501             :             | ALTER DATABASE name RENAME TO name
    9502             :                 {
    9503           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9504             : 
    9505           6 :                     n->renameType = OBJECT_DATABASE;
    9506           6 :                     n->subname = $3;
    9507           6 :                     n->newname = $6;
    9508           6 :                     n->missing_ok = false;
    9509           6 :                     $$ = (Node *) n;
    9510             :                 }
    9511             :             | ALTER DOMAIN_P any_name RENAME TO name
    9512             :                 {
    9513           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9514             : 
    9515           6 :                     n->renameType = OBJECT_DOMAIN;
    9516           6 :                     n->object = (Node *) $3;
    9517           6 :                     n->newname = $6;
    9518           6 :                     n->missing_ok = false;
    9519           6 :                     $$ = (Node *) n;
    9520             :                 }
    9521             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9522             :                 {
    9523           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9524             : 
    9525           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9526           6 :                     n->object = (Node *) $3;
    9527           6 :                     n->subname = $6;
    9528           6 :                     n->newname = $8;
    9529           6 :                     $$ = (Node *) n;
    9530             :                 }
    9531             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9532             :                 {
    9533          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9534             : 
    9535          24 :                     n->renameType = OBJECT_FDW;
    9536          24 :                     n->object = (Node *) makeString($5);
    9537          24 :                     n->newname = $8;
    9538          24 :                     n->missing_ok = false;
    9539          24 :                     $$ = (Node *) n;
    9540             :                 }
    9541             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9542             :                 {
    9543          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9544             : 
    9545          24 :                     n->renameType = OBJECT_FUNCTION;
    9546          24 :                     n->object = (Node *) $3;
    9547          24 :                     n->newname = $6;
    9548          24 :                     n->missing_ok = false;
    9549          24 :                     $$ = (Node *) n;
    9550             :                 }
    9551             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9552             :                 {
    9553           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9554             : 
    9555           0 :                     n->renameType = OBJECT_ROLE;
    9556           0 :                     n->subname = $3;
    9557           0 :                     n->newname = $6;
    9558           0 :                     n->missing_ok = false;
    9559           0 :                     $$ = (Node *) n;
    9560             :                 }
    9561             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9562             :                 {
    9563          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9564             : 
    9565          18 :                     n->renameType = OBJECT_LANGUAGE;
    9566          18 :                     n->object = (Node *) makeString($4);
    9567          18 :                     n->newname = $7;
    9568          18 :                     n->missing_ok = false;
    9569          18 :                     $$ = (Node *) n;
    9570             :                 }
    9571             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9572             :                 {
    9573          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9574             : 
    9575          24 :                     n->renameType = OBJECT_OPCLASS;
    9576          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9577          24 :                     n->newname = $9;
    9578          24 :                     n->missing_ok = false;
    9579          24 :                     $$ = (Node *) n;
    9580             :                 }
    9581             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9582             :                 {
    9583          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9584             : 
    9585          24 :                     n->renameType = OBJECT_OPFAMILY;
    9586          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9587          24 :                     n->newname = $9;
    9588          24 :                     n->missing_ok = false;
    9589          24 :                     $$ = (Node *) n;
    9590             :                 }
    9591             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9592             :                 {
    9593          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9594             : 
    9595          18 :                     n->renameType = OBJECT_POLICY;
    9596          18 :                     n->relation = $5;
    9597          18 :                     n->subname = $3;
    9598          18 :                     n->newname = $8;
    9599          18 :                     n->missing_ok = false;
    9600          18 :                     $$ = (Node *) n;
    9601             :                 }
    9602             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9603             :                 {
    9604           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9605             : 
    9606           0 :                     n->renameType = OBJECT_POLICY;
    9607           0 :                     n->relation = $7;
    9608           0 :                     n->subname = $5;
    9609           0 :                     n->newname = $10;
    9610           0 :                     n->missing_ok = true;
    9611           0 :                     $$ = (Node *) n;
    9612             :                 }
    9613             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9614             :                 {
    9615           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9616             : 
    9617           0 :                     n->renameType = OBJECT_PROCEDURE;
    9618           0 :                     n->object = (Node *) $3;
    9619           0 :                     n->newname = $6;
    9620           0 :                     n->missing_ok = false;
    9621           0 :                     $$ = (Node *) n;
    9622             :                 }
    9623             :             | ALTER PUBLICATION name RENAME TO name
    9624             :                 {
    9625          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9626             : 
    9627          42 :                     n->renameType = OBJECT_PUBLICATION;
    9628          42 :                     n->object = (Node *) makeString($3);
    9629          42 :                     n->newname = $6;
    9630          42 :                     n->missing_ok = false;
    9631          42 :                     $$ = (Node *) n;
    9632             :                 }
    9633             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9634             :                 {
    9635          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9636             : 
    9637          24 :                     n->renameType = OBJECT_ROUTINE;
    9638          24 :                     n->object = (Node *) $3;
    9639          24 :                     n->newname = $6;
    9640          24 :                     n->missing_ok = false;
    9641          24 :                     $$ = (Node *) n;
    9642             :                 }
    9643             :             | ALTER SCHEMA name RENAME TO name
    9644             :                 {
    9645          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9646             : 
    9647          20 :                     n->renameType = OBJECT_SCHEMA;
    9648          20 :                     n->subname = $3;
    9649          20 :                     n->newname = $6;
    9650          20 :                     n->missing_ok = false;
    9651          20 :                     $$ = (Node *) n;
    9652             :                 }
    9653             :             | ALTER SERVER name RENAME TO name
    9654             :                 {
    9655          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9656             : 
    9657          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9658          24 :                     n->object = (Node *) makeString($3);
    9659          24 :                     n->newname = $6;
    9660          24 :                     n->missing_ok = false;
    9661          24 :                     $$ = (Node *) n;
    9662             :                 }
    9663             :             | ALTER SUBSCRIPTION name RENAME TO name
    9664             :                 {
    9665          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9666             : 
    9667          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9668          38 :                     n->object = (Node *) makeString($3);
    9669          38 :                     n->newname = $6;
    9670          38 :                     n->missing_ok = false;
    9671          38 :                     $$ = (Node *) n;
    9672             :                 }
    9673             :             | ALTER TABLE relation_expr RENAME TO name
    9674             :                 {
    9675         288 :                     RenameStmt *n = makeNode(RenameStmt);
    9676             : 
    9677         288 :                     n->renameType = OBJECT_TABLE;
    9678         288 :                     n->relation = $3;
    9679         288 :                     n->subname = NULL;
    9680         288 :                     n->newname = $6;
    9681         288 :                     n->missing_ok = false;
    9682         288 :                     $$ = (Node *) n;
    9683             :                 }
    9684             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9685             :                 {
    9686           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9687             : 
    9688           0 :                     n->renameType = OBJECT_TABLE;
    9689           0 :                     n->relation = $5;
    9690           0 :                     n->subname = NULL;
    9691           0 :                     n->newname = $8;
    9692           0 :                     n->missing_ok = true;
    9693           0 :                     $$ = (Node *) n;
    9694             :                 }
    9695             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9696             :                 {
    9697           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9698             : 
    9699           2 :                     n->renameType = OBJECT_SEQUENCE;
    9700           2 :                     n->relation = $3;
    9701           2 :                     n->subname = NULL;
    9702           2 :                     n->newname = $6;
    9703           2 :                     n->missing_ok = false;
    9704           2 :                     $$ = (Node *) n;
    9705             :                 }
    9706             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9707             :                 {
    9708           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9709             : 
    9710           0 :                     n->renameType = OBJECT_SEQUENCE;
    9711           0 :                     n->relation = $5;
    9712           0 :                     n->subname = NULL;
    9713           0 :                     n->newname = $8;
    9714           0 :                     n->missing_ok = true;
    9715           0 :                     $$ = (Node *) n;
    9716             :                 }
    9717             :             | ALTER VIEW qualified_name RENAME TO name
    9718             :                 {
    9719           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9720             : 
    9721           6 :                     n->renameType = OBJECT_VIEW;
    9722           6 :                     n->relation = $3;
    9723           6 :                     n->subname = NULL;
    9724           6 :                     n->newname = $6;
    9725           6 :                     n->missing_ok = false;
    9726           6 :                     $$ = (Node *) n;
    9727             :                 }
    9728             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9729             :                 {
    9730           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9731             : 
    9732           0 :                     n->renameType = OBJECT_VIEW;
    9733           0 :                     n->relation = $5;
    9734           0 :                     n->subname = NULL;
    9735           0 :                     n->newname = $8;
    9736           0 :                     n->missing_ok = true;
    9737           0 :                     $$ = (Node *) n;
    9738             :                 }
    9739             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9740             :                 {
    9741           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9742             : 
    9743           0 :                     n->renameType = OBJECT_MATVIEW;
    9744           0 :                     n->relation = $4;
    9745           0 :                     n->subname = NULL;
    9746           0 :                     n->newname = $7;
    9747           0 :                     n->missing_ok = false;
    9748           0 :                     $$ = (Node *) n;
    9749             :                 }
    9750             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9751             :                 {
    9752           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9753             : 
    9754           0 :                     n->renameType = OBJECT_MATVIEW;
    9755           0 :                     n->relation = $6;
    9756           0 :                     n->subname = NULL;
    9757           0 :                     n->newname = $9;
    9758           0 :                     n->missing_ok = true;
    9759           0 :                     $$ = (Node *) n;
    9760             :                 }
    9761             :             | ALTER INDEX qualified_name RENAME TO name
    9762             :                 {
    9763         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9764             : 
    9765         192 :                     n->renameType = OBJECT_INDEX;
    9766         192 :                     n->relation = $3;
    9767         192 :                     n->subname = NULL;
    9768         192 :                     n->newname = $6;
    9769         192 :                     n->missing_ok = false;
    9770         192 :                     $$ = (Node *) n;
    9771             :                 }
    9772             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9773             :                 {
    9774          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9775             : 
    9776          12 :                     n->renameType = OBJECT_INDEX;
    9777          12 :                     n->relation = $5;
    9778          12 :                     n->subname = NULL;
    9779          12 :                     n->newname = $8;
    9780          12 :                     n->missing_ok = true;
    9781          12 :                     $$ = (Node *) n;
    9782             :                 }
    9783             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9784             :                 {
    9785           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9786             : 
    9787           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9788           6 :                     n->relation = $4;
    9789           6 :                     n->subname = NULL;
    9790           6 :                     n->newname = $7;
    9791           6 :                     n->missing_ok = false;
    9792           6 :                     $$ = (Node *) n;
    9793             :                 }
    9794             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9795             :                 {
    9796           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9797             : 
    9798           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9799           6 :                     n->relation = $6;
    9800           6 :                     n->subname = NULL;
    9801           6 :                     n->newname = $9;
    9802           6 :                     n->missing_ok = true;
    9803           6 :                     $$ = (Node *) n;
    9804             :                 }
    9805             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9806             :                 {
    9807         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9808             : 
    9809         238 :                     n->renameType = OBJECT_COLUMN;
    9810         238 :                     n->relationType = OBJECT_TABLE;
    9811         238 :                     n->relation = $3;
    9812         238 :                     n->subname = $6;
    9813         238 :                     n->newname = $8;
    9814         238 :                     n->missing_ok = false;
    9815         238 :                     $$ = (Node *) n;
    9816             :                 }
    9817             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9818             :                 {
    9819          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9820             : 
    9821          24 :                     n->renameType = OBJECT_COLUMN;
    9822          24 :                     n->relationType = OBJECT_TABLE;
    9823          24 :                     n->relation = $5;
    9824          24 :                     n->subname = $8;
    9825          24 :                     n->newname = $10;
    9826          24 :                     n->missing_ok = true;
    9827          24 :                     $$ = (Node *) n;
    9828             :                 }
    9829             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9830             :                 {
    9831          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9832             : 
    9833          18 :                     n->renameType = OBJECT_COLUMN;
    9834          18 :                     n->relationType = OBJECT_VIEW;
    9835          18 :                     n->relation = $3;
    9836          18 :                     n->subname = $6;
    9837          18 :                     n->newname = $8;
    9838          18 :                     n->missing_ok = false;
    9839          18 :                     $$ = (Node *) n;
    9840             :                 }
    9841             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9842             :                 {
    9843           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9844             : 
    9845           0 :                     n->renameType = OBJECT_COLUMN;
    9846           0 :                     n->relationType = OBJECT_VIEW;
    9847           0 :                     n->relation = $5;
    9848           0 :                     n->subname = $8;
    9849           0 :                     n->newname = $10;
    9850           0 :                     n->missing_ok = true;
    9851           0 :                     $$ = (Node *) n;
    9852             :                 }
    9853             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9854             :                 {
    9855           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9856             : 
    9857           0 :                     n->renameType = OBJECT_COLUMN;
    9858           0 :                     n->relationType = OBJECT_MATVIEW;
    9859           0 :                     n->relation = $4;
    9860           0 :                     n->subname = $7;
    9861           0 :                     n->newname = $9;
    9862           0 :                     n->missing_ok = false;
    9863           0 :                     $$ = (Node *) n;
    9864             :                 }
    9865             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9866             :                 {
    9867           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9868             : 
    9869           0 :                     n->renameType = OBJECT_COLUMN;
    9870           0 :                     n->relationType = OBJECT_MATVIEW;
    9871           0 :                     n->relation = $6;
    9872           0 :                     n->subname = $9;
    9873           0 :                     n->newname = $11;
    9874           0 :                     n->missing_ok = true;
    9875           0 :                     $$ = (Node *) n;
    9876             :                 }
    9877             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9878             :                 {
    9879          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9880             : 
    9881          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9882          72 :                     n->relation = $3;
    9883          72 :                     n->subname = $6;
    9884          72 :                     n->newname = $8;
    9885          72 :                     n->missing_ok = false;
    9886          72 :                     $$ = (Node *) n;
    9887             :                 }
    9888             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9889             :                 {
    9890           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9891             : 
    9892           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9893           6 :                     n->relation = $5;
    9894           6 :                     n->subname = $8;
    9895           6 :                     n->newname = $10;
    9896           6 :                     n->missing_ok = true;
    9897           6 :                     $$ = (Node *) n;
    9898             :                 }
    9899             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9900             :                 {
    9901           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9902             : 
    9903           6 :                     n->renameType = OBJECT_COLUMN;
    9904           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9905           6 :                     n->relation = $4;
    9906           6 :                     n->subname = $7;
    9907           6 :                     n->newname = $9;
    9908           6 :                     n->missing_ok = false;
    9909           6 :                     $$ = (Node *) n;
    9910             :                 }
    9911             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9912             :                 {
    9913           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9914             : 
    9915           6 :                     n->renameType = OBJECT_COLUMN;
    9916           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9917           6 :                     n->relation = $6;
    9918           6 :                     n->subname = $9;
    9919           6 :                     n->newname = $11;
    9920           6 :                     n->missing_ok = true;
    9921           6 :                     $$ = (Node *) n;
    9922             :                 }
    9923             :             | ALTER RULE name ON qualified_name RENAME TO name
    9924             :                 {
    9925          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9926             : 
    9927          34 :                     n->renameType = OBJECT_RULE;
    9928          34 :                     n->relation = $5;
    9929          34 :                     n->subname = $3;
    9930          34 :                     n->newname = $8;
    9931          34 :                     n->missing_ok = false;
    9932          34 :                     $$ = (Node *) n;
    9933             :                 }
    9934             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9935             :                 {
    9936          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9937             : 
    9938          40 :                     n->renameType = OBJECT_TRIGGER;
    9939          40 :                     n->relation = $5;
    9940          40 :                     n->subname = $3;
    9941          40 :                     n->newname = $8;
    9942          40 :                     n->missing_ok = false;
    9943          40 :                     $$ = (Node *) n;
    9944             :                 }
    9945             :             | ALTER EVENT TRIGGER name RENAME TO name
    9946             :                 {
    9947          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9948             : 
    9949          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9950          12 :                     n->object = (Node *) makeString($4);
    9951          12 :                     n->newname = $7;
    9952          12 :                     $$ = (Node *) n;
    9953             :                 }
    9954             :             | ALTER ROLE RoleId RENAME TO RoleId
    9955             :                 {
    9956          32 :                     RenameStmt *n = makeNode(RenameStmt);
    9957             : 
    9958          32 :                     n->renameType = OBJECT_ROLE;
    9959          32 :                     n->subname = $3;
    9960          32 :                     n->newname = $6;
    9961          32 :                     n->missing_ok = false;
    9962          32 :                     $$ = (Node *) n;
    9963             :                 }
    9964             :             | ALTER USER RoleId RENAME TO RoleId
    9965             :                 {
    9966           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9967             : 
    9968           0 :                     n->renameType = OBJECT_ROLE;
    9969           0 :                     n->subname = $3;
    9970           0 :                     n->newname = $6;
    9971           0 :                     n->missing_ok = false;
    9972           0 :                     $$ = (Node *) n;
    9973             :                 }
    9974             :             | ALTER TABLESPACE name RENAME TO name
    9975             :                 {
    9976           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9977             : 
    9978           6 :                     n->renameType = OBJECT_TABLESPACE;
    9979           6 :                     n->subname = $3;
    9980           6 :                     n->newname = $6;
    9981           6 :                     n->missing_ok = false;
    9982           6 :                     $$ = (Node *) n;
    9983             :                 }
    9984             :             | ALTER STATISTICS any_name RENAME TO name
    9985             :                 {
    9986          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9987             : 
    9988          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9989          30 :                     n->object = (Node *) $3;
    9990          30 :                     n->newname = $6;
    9991          30 :                     n->missing_ok = false;
    9992          30 :                     $$ = (Node *) n;
    9993             :                 }
    9994             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9995             :                 {
    9996          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9997             : 
    9998          12 :                     n->renameType = OBJECT_TSPARSER;
    9999          12 :                     n->object = (Node *) $5;
   10000          12 :                     n->newname = $8;
   10001          12 :                     n->missing_ok = false;
   10002          12 :                     $$ = (Node *) n;
   10003             :                 }
   10004             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
   10005             :                 {
   10006          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10007             : 
   10008          24 :                     n->renameType = OBJECT_TSDICTIONARY;
   10009          24 :                     n->object = (Node *) $5;
   10010          24 :                     n->newname = $8;
   10011          24 :                     n->missing_ok = false;
   10012          24 :                     $$ = (Node *) n;
   10013             :                 }
   10014             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
   10015             :                 {
   10016          12 :                     RenameStmt *n = makeNode(RenameStmt);
   10017             : 
   10018          12 :                     n->renameType = OBJECT_TSTEMPLATE;
   10019          12 :                     n->object = (Node *) $5;
   10020          12 :                     n->newname = $8;
   10021          12 :                     n->missing_ok = false;
   10022          12 :                     $$ = (Node *) n;
   10023             :                 }
   10024             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
   10025             :                 {
   10026          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10027             : 
   10028          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
   10029          24 :                     n->object = (Node *) $5;
   10030          24 :                     n->newname = $8;
   10031          24 :                     n->missing_ok = false;
   10032          24 :                     $$ = (Node *) n;
   10033             :                 }
   10034             :             | ALTER TYPE_P any_name RENAME TO name
   10035             :                 {
   10036          26 :                     RenameStmt *n = makeNode(RenameStmt);
   10037             : 
   10038          26 :                     n->renameType = OBJECT_TYPE;
   10039          26 :                     n->object = (Node *) $3;
   10040          26 :                     n->newname = $6;
   10041          26 :                     n->missing_ok = false;
   10042          26 :                     $$ = (Node *) n;
   10043             :                 }
   10044             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
   10045             :                 {
   10046          24 :                     RenameStmt *n = makeNode(RenameStmt);
   10047             : 
   10048          24 :                     n->renameType = OBJECT_ATTRIBUTE;
   10049          24 :                     n->relationType = OBJECT_TYPE;
   10050          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
   10051          24 :                     n->subname = $6;
   10052          24 :                     n->newname = $8;
   10053          24 :                     n->behavior = $9;
   10054          24 :                     n->missing_ok = false;
   10055          24 :                     $$ = (Node *) n;
   10056             :                 }
   10057             :         ;
   10058             : 
   10059             : opt_column: COLUMN
   10060             :             | /*EMPTY*/
   10061             :         ;
   10062             : 
   10063         184 : opt_set_data: SET DATA_P                            { $$ = 1; }
   10064         914 :             | /*EMPTY*/                             { $$ = 0; }
   10065             :         ;
   10066             : 
   10067             : /*****************************************************************************
   10068             :  *
   10069             :  * ALTER THING name DEPENDS ON EXTENSION name
   10070             :  *
   10071             :  *****************************************************************************/
   10072             : 
   10073             : AlterObjectDependsStmt:
   10074             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10075             :                 {
   10076          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10077             : 
   10078          12 :                     n->objectType = OBJECT_FUNCTION;
   10079          12 :                     n->object = (Node *) $3;
   10080          12 :                     n->extname = makeString($8);
   10081          12 :                     n->remove = $4;
   10082          12 :                     $$ = (Node *) n;
   10083             :                 }
   10084             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10085             :                 {
   10086           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10087             : 
   10088           0 :                     n->objectType = OBJECT_PROCEDURE;
   10089           0 :                     n->object = (Node *) $3;
   10090           0 :                     n->extname = makeString($8);
   10091           0 :                     n->remove = $4;
   10092           0 :                     $$ = (Node *) n;
   10093             :                 }
   10094             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10095             :                 {
   10096           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10097             : 
   10098           0 :                     n->objectType = OBJECT_ROUTINE;
   10099           0 :                     n->object = (Node *) $3;
   10100           0 :                     n->extname = makeString($8);
   10101           0 :                     n->remove = $4;
   10102           0 :                     $$ = (Node *) n;
   10103             :                 }
   10104             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10105             :                 {
   10106          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10107             : 
   10108          10 :                     n->objectType = OBJECT_TRIGGER;
   10109          10 :                     n->relation = $5;
   10110          10 :                     n->object = (Node *) list_make1(makeString($3));
   10111          10 :                     n->extname = makeString($10);
   10112          10 :                     n->remove = $6;
   10113          10 :                     $$ = (Node *) n;
   10114             :                 }
   10115             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10116             :                 {
   10117          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10118             : 
   10119          10 :                     n->objectType = OBJECT_MATVIEW;
   10120          10 :                     n->relation = $4;
   10121          10 :                     n->extname = makeString($9);
   10122          10 :                     n->remove = $5;
   10123          10 :                     $$ = (Node *) n;
   10124             :                 }
   10125             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10126             :                 {
   10127          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10128             : 
   10129          14 :                     n->objectType = OBJECT_INDEX;
   10130          14 :                     n->relation = $3;
   10131          14 :                     n->extname = makeString($8);
   10132          14 :                     n->remove = $4;
   10133          14 :                     $$ = (Node *) n;
   10134             :                 }
   10135             :         ;
   10136             : 
   10137           8 : opt_no:     NO              { $$ = true; }
   10138          38 :             | /* EMPTY */   { $$ = false;   }
   10139             :         ;
   10140             : 
   10141             : /*****************************************************************************
   10142             :  *
   10143             :  * ALTER THING name SET SCHEMA name
   10144             :  *
   10145             :  *****************************************************************************/
   10146             : 
   10147             : AlterObjectSchemaStmt:
   10148             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10149             :                 {
   10150          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10151             : 
   10152          24 :                     n->objectType = OBJECT_AGGREGATE;
   10153          24 :                     n->object = (Node *) $3;
   10154          24 :                     n->newschema = $6;
   10155          24 :                     n->missing_ok = false;
   10156          24 :                     $$ = (Node *) n;
   10157             :                 }
   10158             :             | ALTER COLLATION any_name SET SCHEMA name
   10159             :                 {
   10160           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10161             : 
   10162           6 :                     n->objectType = OBJECT_COLLATION;
   10163           6 :                     n->object = (Node *) $3;
   10164           6 :                     n->newschema = $6;
   10165           6 :                     n->missing_ok = false;
   10166           6 :                     $$ = (Node *) n;
   10167             :                 }
   10168             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10169             :                 {
   10170          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10171             : 
   10172          24 :                     n->objectType = OBJECT_CONVERSION;
   10173          24 :                     n->object = (Node *) $3;
   10174          24 :                     n->newschema = $6;
   10175          24 :                     n->missing_ok = false;
   10176          24 :                     $$ = (Node *) n;
   10177             :                 }
   10178             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10179             :                 {
   10180           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10181             : 
   10182           6 :                     n->objectType = OBJECT_DOMAIN;
   10183           6 :                     n->object = (Node *) $3;
   10184           6 :                     n->newschema = $6;
   10185           6 :                     n->missing_ok = false;
   10186           6 :                     $$ = (Node *) n;
   10187             :                 }
   10188             :             | ALTER EXTENSION name SET SCHEMA name
   10189             :                 {
   10190          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10191             : 
   10192          12 :                     n->objectType = OBJECT_EXTENSION;
   10193          12 :                     n->object = (Node *) makeString($3);
   10194          12 :                     n->newschema = $6;
   10195          12 :                     n->missing_ok = false;
   10196          12 :                     $$ = (Node *) n;
   10197             :                 }
   10198             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10199             :                 {
   10200          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10201             : 
   10202          42 :                     n->objectType = OBJECT_FUNCTION;
   10203          42 :                     n->object = (Node *) $3;
   10204          42 :                     n->newschema = $6;
   10205          42 :                     n->missing_ok = false;
   10206          42 :                     $$ = (Node *) n;
   10207             :                 }
   10208             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10209             :                 {
   10210          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10211             : 
   10212          18 :                     n->objectType = OBJECT_OPERATOR;
   10213          18 :                     n->object = (Node *) $3;
   10214          18 :                     n->newschema = $6;
   10215          18 :                     n->missing_ok = false;
   10216          18 :                     $$ = (Node *) n;
   10217             :                 }
   10218             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10219             :                 {
   10220          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10221             : 
   10222          24 :                     n->objectType = OBJECT_OPCLASS;
   10223          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10224          24 :                     n->newschema = $9;
   10225          24 :                     n->missing_ok = false;
   10226          24 :                     $$ = (Node *) n;
   10227             :                 }
   10228             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10229             :                 {
   10230          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10231             : 
   10232          24 :                     n->objectType = OBJECT_OPFAMILY;
   10233          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10234          24 :                     n->newschema = $9;
   10235          24 :                     n->missing_ok = false;
   10236          24 :                     $$ = (Node *) n;
   10237             :                 }
   10238             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10239             :                 {
   10240           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10241             : 
   10242           0 :                     n->objectType = OBJECT_PROCEDURE;
   10243           0 :                     n->object = (Node *) $3;
   10244           0 :                     n->newschema = $6;
   10245           0 :                     n->missing_ok = false;
   10246           0 :                     $$ = (Node *) n;
   10247             :                 }
   10248             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10249             :                 {
   10250           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10251             : 
   10252           0 :                     n->objectType = OBJECT_ROUTINE;
   10253           0 :                     n->object = (Node *) $3;
   10254           0 :                     n->newschema = $6;
   10255           0 :                     n->missing_ok = false;
   10256           0 :                     $$ = (Node *) n;
   10257             :                 }
   10258             :             | ALTER TABLE relation_expr SET SCHEMA name
   10259             :                 {
   10260          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10261             : 
   10262          66 :                     n->objectType = OBJECT_TABLE;
   10263          66 :                     n->relation = $3;
   10264          66 :                     n->newschema = $6;
   10265          66 :                     n->missing_ok = false;
   10266          66 :                     $$ = (Node *) n;
   10267             :                 }
   10268             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10269             :                 {
   10270          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10271             : 
   10272          12 :                     n->objectType = OBJECT_TABLE;
   10273          12 :                     n->relation = $5;
   10274          12 :                     n->newschema = $8;
   10275          12 :                     n->missing_ok = true;
   10276          12 :                     $$ = (Node *) n;
   10277             :                 }
   10278             :             | ALTER STATISTICS any_name SET SCHEMA name
   10279             :                 {
   10280          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10281             : 
   10282          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10283          18 :                     n->object = (Node *) $3;
   10284          18 :                     n->newschema = $6;
   10285          18 :                     n->missing_ok = false;
   10286          18 :                     $$ = (Node *) n;
   10287             :                 }
   10288             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10289             :                 {
   10290          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10291             : 
   10292          18 :                     n->objectType = OBJECT_TSPARSER;
   10293          18 :                     n->object = (Node *) $5;
   10294          18 :                     n->newschema = $8;
   10295          18 :                     n->missing_ok = false;
   10296          18 :                     $$ = (Node *) n;
   10297             :                 }
   10298             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10299             :                 {
   10300          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10301             : 
   10302          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10303          24 :                     n->object = (Node *) $5;
   10304          24 :                     n->newschema = $8;
   10305          24 :                     n->missing_ok = false;
   10306          24 :                     $$ = (Node *) n;
   10307             :                 }
   10308             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10309             :                 {
   10310          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10311             : 
   10312          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10313          18 :                     n->object = (Node *) $5;
   10314          18 :                     n->newschema = $8;
   10315          18 :                     n->missing_ok = false;
   10316          18 :                     $$ = (Node *) n;
   10317             :                 }
   10318             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10319             :                 {
   10320          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10321             : 
   10322          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10323          24 :                     n->object = (Node *) $5;
   10324          24 :                     n->newschema = $8;
   10325          24 :                     n->missing_ok = false;
   10326          24 :                     $$ = (Node *) n;
   10327             :                 }
   10328             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10329             :                 {
   10330           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10331             : 
   10332           8 :                     n->objectType = OBJECT_SEQUENCE;
   10333           8 :                     n->relation = $3;
   10334           8 :                     n->newschema = $6;
   10335           8 :                     n->missing_ok = false;
   10336           8 :                     $$ = (Node *) n;
   10337             :                 }
   10338             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10339             :                 {
   10340           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10341             : 
   10342           0 :                     n->objectType = OBJECT_SEQUENCE;
   10343           0 :                     n->relation = $5;
   10344           0 :                     n->newschema = $8;
   10345           0 :                     n->missing_ok = true;
   10346           0 :                     $$ = (Node *) n;
   10347             :                 }
   10348             :             | ALTER VIEW qualified_name SET SCHEMA name
   10349             :                 {
   10350           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10351             : 
   10352           0 :                     n->objectType = OBJECT_VIEW;
   10353           0 :                     n->relation = $3;
   10354           0 :                     n->newschema = $6;
   10355           0 :                     n->missing_ok = false;
   10356           0 :                     $$ = (Node *) n;
   10357             :                 }
   10358             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10359             :                 {
   10360           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10361             : 
   10362           0 :                     n->objectType = OBJECT_VIEW;
   10363           0 :                     n->relation = $5;
   10364           0 :                     n->newschema = $8;
   10365           0 :                     n->missing_ok = true;
   10366           0 :                     $$ = (Node *) n;
   10367             :                 }
   10368             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10369             :                 {
   10370           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10371             : 
   10372           6 :                     n->objectType = OBJECT_MATVIEW;
   10373           6 :                     n->relation = $4;
   10374           6 :                     n->newschema = $7;
   10375           6 :                     n->missing_ok = false;
   10376           6 :                     $$ = (Node *) n;
   10377             :                 }
   10378             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10379             :                 {
   10380           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10381             : 
   10382           0 :                     n->objectType = OBJECT_MATVIEW;
   10383           0 :                     n->relation = $6;
   10384           0 :                     n->newschema = $9;
   10385           0 :                     n->missing_ok = true;
   10386           0 :                     $$ = (Node *) n;
   10387             :                 }
   10388             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10389             :                 {
   10390           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10391             : 
   10392           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10393           6 :                     n->relation = $4;
   10394           6 :                     n->newschema = $7;
   10395           6 :                     n->missing_ok = false;
   10396           6 :                     $$ = (Node *) n;
   10397             :                 }
   10398             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10399             :                 {
   10400           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10401             : 
   10402           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10403           6 :                     n->relation = $6;
   10404           6 :                     n->newschema = $9;
   10405           6 :                     n->missing_ok = true;
   10406           6 :                     $$ = (Node *) n;
   10407             :                 }
   10408             :             | ALTER TYPE_P any_name SET SCHEMA name
   10409             :                 {
   10410          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10411             : 
   10412          12 :                     n->objectType = OBJECT_TYPE;
   10413          12 :                     n->object = (Node *) $3;
   10414          12 :                     n->newschema = $6;
   10415          12 :                     n->missing_ok = false;
   10416          12 :                     $$ = (Node *) n;
   10417             :                 }
   10418             :         ;
   10419             : 
   10420             : /*****************************************************************************
   10421             :  *
   10422             :  * ALTER OPERATOR name SET define
   10423             :  *
   10424             :  *****************************************************************************/
   10425             : 
   10426             : AlterOperatorStmt:
   10427             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10428             :                 {
   10429         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10430             : 
   10431         608 :                     n->opername = $3;
   10432         608 :                     n->options = $6;
   10433         608 :                     $$ = (Node *) n;
   10434             :                 }
   10435             :         ;
   10436             : 
   10437         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10438         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10439             :         ;
   10440             : 
   10441             : operator_def_elem: ColLabel '=' NONE
   10442          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10443             :                    | ColLabel '=' operator_def_arg
   10444        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10445             :                    | ColLabel
   10446          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10447             :         ;
   10448             : 
   10449             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10450             : operator_def_arg:
   10451        1032 :             func_type                       { $$ = (Node *) $1; }
   10452          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10453          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10454           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10455           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10456             :         ;
   10457             : 
   10458             : /*****************************************************************************
   10459             :  *
   10460             :  * ALTER TYPE name SET define
   10461             :  *
   10462             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10463             :  *
   10464             :  *****************************************************************************/
   10465             : 
   10466             : AlterTypeStmt:
   10467             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10468             :                 {
   10469          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10470             : 
   10471          60 :                     n->typeName = $3;
   10472          60 :                     n->options = $6;
   10473          60 :                     $$ = (Node *) n;
   10474             :                 }
   10475             :         ;
   10476             : 
   10477             : /*****************************************************************************
   10478             :  *
   10479             :  * ALTER THING name OWNER TO newname
   10480             :  *
   10481             :  *****************************************************************************/
   10482             : 
   10483             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10484             :                 {
   10485         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10486             : 
   10487         142 :                     n->objectType = OBJECT_AGGREGATE;
   10488         142 :                     n->object = (Node *) $3;
   10489         142 :                     n->newowner = $6;
   10490         142 :                     $$ = (Node *) n;
   10491             :                 }
   10492             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10493             :                 {
   10494          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10495             : 
   10496          18 :                     n->objectType = OBJECT_COLLATION;
   10497          18 :                     n->object = (Node *) $3;
   10498          18 :                     n->newowner = $6;
   10499          18 :                     $$ = (Node *) n;
   10500             :                 }
   10501             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10502             :                 {
   10503          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10504             : 
   10505          24 :                     n->objectType = OBJECT_CONVERSION;
   10506          24 :                     n->object = (Node *) $3;
   10507          24 :                     n->newowner = $6;
   10508          24 :                     $$ = (Node *) n;
   10509             :                 }
   10510             :             | ALTER DATABASE name OWNER TO RoleSpec
   10511             :                 {
   10512          86 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10513             : 
   10514          86 :                     n->objectType = OBJECT_DATABASE;
   10515          86 :                     n->object = (Node *) makeString($3);
   10516          86 :                     n->newowner = $6;
   10517          86 :                     $$ = (Node *) n;
   10518             :                 }
   10519             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10520             :                 {
   10521          48 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10522             : 
   10523          48 :                     n->objectType = OBJECT_DOMAIN;
   10524          48 :                     n->object = (Node *) $3;
   10525          48 :                     n->newowner = $6;
   10526          48 :                     $$ = (Node *) n;
   10527             :                 }
   10528             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10529             :                 {
   10530         586 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10531             : 
   10532         586 :                     n->objectType = OBJECT_FUNCTION;
   10533         586 :                     n->object = (Node *) $3;
   10534         586 :                     n->newowner = $6;
   10535         586 :                     $$ = (Node *) n;
   10536             :                 }
   10537             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10538             :                 {
   10539         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10540             : 
   10541         142 :                     n->objectType = OBJECT_LANGUAGE;
   10542         142 :                     n->object = (Node *) makeString($4);
   10543         142 :                     n->newowner = $7;
   10544         142 :                     $$ = (Node *) n;
   10545             :                 }
   10546             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10547             :                 {
   10548           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10549             : 
   10550           6 :                     n->objectType = OBJECT_LARGEOBJECT;
   10551           6 :                     n->object = (Node *) $4;
   10552           6 :                     n->newowner = $7;
   10553           6 :                     $$ = (Node *) n;
   10554             :                 }
   10555             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10556             :                 {
   10557          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10558             : 
   10559          46 :                     n->objectType = OBJECT_OPERATOR;
   10560          46 :                     n->object = (Node *) $3;
   10561          46 :                     n->newowner = $6;
   10562          46 :                     $$ = (Node *) n;
   10563             :                 }
   10564             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10565             :                 {
   10566          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10567             : 
   10568          54 :                     n->objectType = OBJECT_OPCLASS;
   10569          54 :                     n->object = (Node *) lcons(makeString($6), $4);
   10570          54 :                     n->newowner = $9;
   10571          54 :                     $$ = (Node *) n;
   10572             :                 }
   10573             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10574             :                 {
   10575          62 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10576             : 
   10577          62 :                     n->objectType = OBJECT_OPFAMILY;
   10578          62 :                     n->object = (Node *) lcons(makeString($6), $4);
   10579          62 :                     n->newowner = $9;
   10580          62 :                     $$ = (Node *) n;
   10581             :                 }
   10582             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10583             :                 {
   10584          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10585             : 
   10586          24 :                     n->objectType = OBJECT_PROCEDURE;
   10587          24 :                     n->object = (Node *) $3;
   10588          24 :                     n->newowner = $6;
   10589          24 :                     $$ = (Node *) n;
   10590             :                 }
   10591             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10592             :                 {
   10593           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10594             : 
   10595           0 :                     n->objectType = OBJECT_ROUTINE;
   10596           0 :                     n->object = (Node *) $3;
   10597           0 :                     n->newowner = $6;
   10598           0 :                     $$ = (Node *) n;
   10599             :                 }
   10600             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10601             :                 {
   10602          64 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10603             : 
   10604          64 :                     n->objectType = OBJECT_SCHEMA;
   10605          64 :                     n->object = (Node *) makeString($3);
   10606          64 :                     n->newowner = $6;
   10607          64 :                     $$ = (Node *) n;
   10608             :                 }
   10609             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10610             :                 {
   10611          84 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10612             : 
   10613          84 :                     n->objectType = OBJECT_TYPE;
   10614          84 :                     n->object = (Node *) $3;
   10615          84 :                     n->newowner = $6;
   10616          84 :                     $$ = (Node *) n;
   10617             :                 }
   10618             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10619             :                 {
   10620           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10621             : 
   10622           6 :                     n->objectType = OBJECT_TABLESPACE;
   10623           6 :                     n->object = (Node *) makeString($3);
   10624           6 :                     n->newowner = $6;
   10625           6 :                     $$ = (Node *) n;
   10626             :                 }
   10627             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10628             :                 {
   10629          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10630             : 
   10631          32 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10632          32 :                     n->object = (Node *) $3;
   10633          32 :                     n->newowner = $6;
   10634          32 :                     $$ = (Node *) n;
   10635             :                 }
   10636             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10637             :                 {
   10638          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10639             : 
   10640          42 :                     n->objectType = OBJECT_TSDICTIONARY;
   10641          42 :                     n->object = (Node *) $5;
   10642          42 :                     n->newowner = $8;
   10643          42 :                     $$ = (Node *) n;
   10644             :                 }
   10645             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10646             :                 {
   10647          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10648             : 
   10649          32 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10650          32 :                     n->object = (Node *) $5;
   10651          32 :                     n->newowner = $8;
   10652          32 :                     $$ = (Node *) n;
   10653             :                 }
   10654             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10655             :                 {
   10656          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10657             : 
   10658          20 :                     n->objectType = OBJECT_FDW;
   10659          20 :                     n->object = (Node *) makeString($5);
   10660          20 :                     n->newowner = $8;
   10661          20 :                     $$ = (Node *) n;
   10662             :                 }
   10663             :             | ALTER SERVER name OWNER TO RoleSpec
   10664             :                 {
   10665          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10666             : 
   10667          68 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10668          68 :                     n->object = (Node *) makeString($3);
   10669          68 :                     n->newowner = $6;
   10670          68 :                     $$ = (Node *) n;
   10671             :                 }
   10672             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10673             :                 {
   10674          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10675             : 
   10676          14 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10677          14 :                     n->object = (Node *) makeString($4);
   10678          14 :                     n->newowner = $7;
   10679          14 :                     $$ = (Node *) n;
   10680             :                 }
   10681             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10682             :                 {
   10683          36 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10684             : 
   10685          36 :                     n->objectType = OBJECT_PUBLICATION;
   10686          36 :                     n->object = (Node *) makeString($3);
   10687          36 :                     n->newowner = $6;
   10688          36 :                     $$ = (Node *) n;
   10689             :                 }
   10690             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10691             :                 {
   10692          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10693             : 
   10694          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10695          18 :                     n->object = (Node *) makeString($3);
   10696          18 :                     n->newowner = $6;
   10697          18 :                     $$ = (Node *) n;
   10698             :                 }
   10699             :         ;
   10700             : 
   10701             : 
   10702             : /*****************************************************************************
   10703             :  *
   10704             :  * CREATE PUBLICATION name [WITH options]
   10705             :  *
   10706             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10707             :  *
   10708             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10709             :  *
   10710             :  * pub_obj is one of:
   10711             :  *
   10712             :  *      TABLE table [, ...]
   10713             :  *      TABLES IN SCHEMA schema [, ...]
   10714             :  *
   10715             :  *****************************************************************************/
   10716             : 
   10717             : CreatePublicationStmt:
   10718             :             CREATE PUBLICATION name opt_definition
   10719             :                 {
   10720         146 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10721             : 
   10722         146 :                     n->pubname = $3;
   10723         146 :                     n->options = $4;
   10724         146 :                     $$ = (Node *) n;
   10725             :                 }
   10726             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10727             :                 {
   10728         100 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10729             : 
   10730         100 :                     n->pubname = $3;
   10731         100 :                     n->options = $7;
   10732         100 :                     n->for_all_tables = true;
   10733         100 :                     $$ = (Node *) n;
   10734             :                 }
   10735             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10736             :                 {
   10737         658 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10738             : 
   10739         658 :                     n->pubname = $3;
   10740         658 :                     n->options = $6;
   10741         658 :                     n->pubobjects = (List *) $5;
   10742         658 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10743         628 :                     $$ = (Node *) n;
   10744             :                 }
   10745             :         ;
   10746             : 
   10747             : /*
   10748             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10749             :  *
   10750             :  * This rule parses publication objects with and without keyword prefixes.
   10751             :  *
   10752             :  * The actual type of the object without keyword prefix depends on the previous
   10753             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10754             :  *
   10755             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10756             :  * because some extended expressions in relation_expr cannot be used as a
   10757             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10758             :  * relation_expr here.
   10759             :  */
   10760             : PublicationObjSpec:
   10761             :             TABLE relation_expr opt_column_list OptWhereClause
   10762             :                 {
   10763        1322 :                     $$ = makeNode(PublicationObjSpec);
   10764        1322 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10765        1322 :                     $$->pubtable = makeNode(PublicationTable);
   10766        1322 :                     $$->pubtable->relation = $2;
   10767        1322 :                     $$->pubtable->columns = $3;
   10768        1322 :                     $$->pubtable->whereClause = $4;
   10769             :                 }
   10770             :             | TABLES IN_P SCHEMA ColId
   10771             :                 {
   10772         372 :                     $$ = makeNode(PublicationObjSpec);
   10773         372 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10774         372 :                     $$->name = $4;
   10775         372 :                     $$->location = @4;
   10776             :                 }
   10777             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10778             :                 {
   10779          18 :                     $$ = makeNode(PublicationObjSpec);
   10780          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10781          18 :                     $$->location = @4;
   10782             :                 }
   10783             :             | ColId opt_column_list OptWhereClause
   10784             :                 {
   10785         130 :                     $$ = makeNode(PublicationObjSpec);
   10786         130 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10787             :                     /*
   10788             :                      * If either a row filter or column list is specified, create
   10789             :                      * a PublicationTable object.
   10790             :                      */
   10791         130 :                     if ($2 || $3)
   10792             :                     {
   10793             :                         /*
   10794             :                          * The OptWhereClause must be stored here but it is
   10795             :                          * valid only for tables. For non-table objects, an
   10796             :                          * error will be thrown later via
   10797             :                          * preprocess_pubobj_list().
   10798             :                          */
   10799          42 :                         $$->pubtable = makeNode(PublicationTable);
   10800          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10801          42 :                         $$->pubtable->columns = $2;
   10802          42 :                         $$->pubtable->whereClause = $3;
   10803             :                     }
   10804             :                     else
   10805             :                     {
   10806          88 :                         $$->name = $1;
   10807             :                     }
   10808         130 :                     $$->location = @1;
   10809             :                 }
   10810             :             | ColId indirection opt_column_list OptWhereClause
   10811             :                 {
   10812          32 :                     $$ = makeNode(PublicationObjSpec);
   10813          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10814          32 :                     $$->pubtable = makeNode(PublicationTable);
   10815          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10816          32 :                     $$->pubtable->columns = $3;
   10817          32 :                     $$->pubtable->whereClause = $4;
   10818          32 :                     $$->location = @1;
   10819             :                 }
   10820             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10821             :             | extended_relation_expr opt_column_list OptWhereClause
   10822             :                 {
   10823           6 :                     $$ = makeNode(PublicationObjSpec);
   10824           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10825           6 :                     $$->pubtable = makeNode(PublicationTable);
   10826           6 :                     $$->pubtable->relation = $1;
   10827           6 :                     $$->pubtable->columns = $2;
   10828           6 :                     $$->pubtable->whereClause = $3;
   10829             :                 }
   10830             :             | CURRENT_SCHEMA
   10831             :                 {
   10832          18 :                     $$ = makeNode(PublicationObjSpec);
   10833          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10834          18 :                     $$->location = @1;
   10835             :                 }
   10836             :                 ;
   10837             : 
   10838             : pub_obj_list:   PublicationObjSpec
   10839        1644 :                     { $$ = list_make1($1); }
   10840             :             | pub_obj_list ',' PublicationObjSpec
   10841         254 :                     { $$ = lappend($1, $3); }
   10842             :     ;
   10843             : 
   10844             : /*****************************************************************************
   10845             :  *
   10846             :  * ALTER PUBLICATION name SET ( options )
   10847             :  *
   10848             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10849             :  *
   10850             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10851             :  *
   10852             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10853             :  *
   10854             :  * pub_obj is one of:
   10855             :  *
   10856             :  *      TABLE table_name [, ...]
   10857             :  *      TABLES IN SCHEMA schema_name [, ...]
   10858             :  *
   10859             :  *****************************************************************************/
   10860             : 
   10861             : AlterPublicationStmt:
   10862             :             ALTER PUBLICATION name SET definition
   10863             :                 {
   10864         116 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10865             : 
   10866         116 :                     n->pubname = $3;
   10867         116 :                     n->options = $5;
   10868         116 :                     $$ = (Node *) n;
   10869             :                 }
   10870             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10871             :                 {
   10872         368 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10873             : 
   10874         368 :                     n->pubname = $3;
   10875         368 :                     n->pubobjects = $5;
   10876         368 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10877         362 :                     n->action = AP_AddObjects;
   10878         362 :                     $$ = (Node *) n;
   10879             :                 }
   10880             :             | ALTER PUBLICATION name SET pub_obj_list
   10881             :                 {
   10882         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10883             : 
   10884         464 :                     n->pubname = $3;
   10885         464 :                     n->pubobjects = $5;
   10886         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10887         464 :                     n->action = AP_SetObjects;
   10888         464 :                     $$ = (Node *) n;
   10889             :                 }
   10890             :             | ALTER PUBLICATION name DROP pub_obj_list
   10891             :                 {
   10892         154 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10893             : 
   10894         154 :                     n->pubname = $3;
   10895         154 :                     n->pubobjects = $5;
   10896         154 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10897         154 :                     n->action = AP_DropObjects;
   10898         154 :                     $$ = (Node *) n;
   10899             :                 }
   10900             :         ;
   10901             : 
   10902             : /*****************************************************************************
   10903             :  *
   10904             :  * CREATE SUBSCRIPTION name ...
   10905             :  *
   10906             :  *****************************************************************************/
   10907             : 
   10908             : CreateSubscriptionStmt:
   10909             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10910             :                 {
   10911             :                     CreateSubscriptionStmt *n =
   10912         480 :                         makeNode(CreateSubscriptionStmt);
   10913         480 :                     n->subname = $3;
   10914         480 :                     n->conninfo = $5;
   10915         480 :                     n->publication = $7;
   10916         480 :                     n->options = $8;
   10917         480 :                     $$ = (Node *) n;
   10918             :                 }
   10919             :         ;
   10920             : 
   10921             : /*****************************************************************************
   10922             :  *
   10923             :  * ALTER SUBSCRIPTION name ...
   10924             :  *
   10925             :  *****************************************************************************/
   10926             : 
   10927             : AlterSubscriptionStmt:
   10928             :             ALTER SUBSCRIPTION name SET definition
   10929             :                 {
   10930             :                     AlterSubscriptionStmt *n =
   10931         216 :                         makeNode(AlterSubscriptionStmt);
   10932             : 
   10933         216 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10934         216 :                     n->subname = $3;
   10935         216 :                     n->options = $5;
   10936         216 :                     $$ = (Node *) n;
   10937             :                 }
   10938             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10939             :                 {
   10940             :                     AlterSubscriptionStmt *n =
   10941          26 :                         makeNode(AlterSubscriptionStmt);
   10942             : 
   10943          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10944          26 :                     n->subname = $3;
   10945          26 :                     n->conninfo = $5;
   10946          26 :                     $$ = (Node *) n;
   10947             :                 }
   10948             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10949             :                 {
   10950             :                     AlterSubscriptionStmt *n =
   10951          58 :                         makeNode(AlterSubscriptionStmt);
   10952             : 
   10953          58 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10954          58 :                     n->subname = $3;
   10955          58 :                     n->options = $6;
   10956          58 :                     $$ = (Node *) n;
   10957             :                 }
   10958             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10959             :                 {
   10960             :                     AlterSubscriptionStmt *n =
   10961          28 :                         makeNode(AlterSubscriptionStmt);
   10962             : 
   10963          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10964          28 :                     n->subname = $3;
   10965          28 :                     n->publication = $6;
   10966          28 :                     n->options = $7;
   10967          28 :                     $$ = (Node *) n;
   10968             :                 }
   10969             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10970             :                 {
   10971             :                     AlterSubscriptionStmt *n =
   10972          26 :                         makeNode(AlterSubscriptionStmt);
   10973             : 
   10974          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10975          26 :                     n->subname = $3;
   10976          26 :                     n->publication = $6;
   10977          26 :                     n->options = $7;
   10978          26 :                     $$ = (Node *) n;
   10979             :                 }
   10980             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10981             :                 {
   10982             :                     AlterSubscriptionStmt *n =
   10983          44 :                         makeNode(AlterSubscriptionStmt);
   10984             : 
   10985          44 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10986          44 :                     n->subname = $3;
   10987          44 :                     n->publication = $6;
   10988          44 :                     n->options = $7;
   10989          44 :                     $$ = (Node *) n;
   10990             :                 }
   10991             :             | ALTER SUBSCRIPTION name ENABLE_P
   10992             :                 {
   10993             :                     AlterSubscriptionStmt *n =
   10994          58 :                         makeNode(AlterSubscriptionStmt);
   10995             : 
   10996          58 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10997          58 :                     n->subname = $3;
   10998          58 :                     n->options = list_make1(makeDefElem("enabled",
   10999             :                                             (Node *) makeBoolean(true), @1));
   11000          58 :                     $$ = (Node *) n;
   11001             :                 }
   11002             :             | ALTER SUBSCRIPTION name DISABLE_P
   11003             :                 {
   11004             :                     AlterSubscriptionStmt *n =
   11005          42 :                         makeNode(AlterSubscriptionStmt);
   11006             : 
   11007          42 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11008          42 :                     n->subname = $3;
   11009          42 :                     n->options = list_make1(makeDefElem("enabled",
   11010             :                                             (Node *) makeBoolean(false), @1));
   11011          42 :                     $$ = (Node *) n;
   11012             :                 }
   11013             :             | ALTER SUBSCRIPTION name SKIP definition
   11014             :                 {
   11015             :                     AlterSubscriptionStmt *n =
   11016          24 :                         makeNode(AlterSubscriptionStmt);
   11017             : 
   11018          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   11019          24 :                     n->subname = $3;
   11020          24 :                     n->options = $5;
   11021          24 :                     $$ = (Node *) n;
   11022             :                 }
   11023             :         ;
   11024             : 
   11025             : /*****************************************************************************
   11026             :  *
   11027             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   11028             :  *
   11029             :  *****************************************************************************/
   11030             : 
   11031             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   11032             :                 {
   11033         242 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11034             : 
   11035         242 :                     n->subname = $3;
   11036         242 :                     n->missing_ok = false;
   11037         242 :                     n->behavior = $4;
   11038         242 :                     $$ = (Node *) n;
   11039             :                 }
   11040             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   11041             :                 {
   11042           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11043             : 
   11044           6 :                     n->subname = $5;
   11045           6 :                     n->missing_ok = true;
   11046           6 :                     n->behavior = $6;
   11047           6 :                     $$ = (Node *) n;
   11048             :                 }
   11049             :         ;
   11050             : 
   11051             : /*****************************************************************************
   11052             :  *
   11053             :  *      QUERY:  Define Rewrite Rule
   11054             :  *
   11055             :  *****************************************************************************/
   11056             : 
   11057             : RuleStmt:   CREATE opt_or_replace RULE name AS
   11058             :             ON event TO qualified_name where_clause
   11059             :             DO opt_instead RuleActionList
   11060             :                 {
   11061        1092 :                     RuleStmt   *n = makeNode(RuleStmt);
   11062             : 
   11063        1092 :                     n->replace = $2;
   11064        1092 :                     n->relation = $9;
   11065        1092 :                     n->rulename = $4;
   11066        1092 :                     n->whereClause = $10;
   11067        1092 :                     n->event = $7;
   11068        1092 :                     n->instead = $12;
   11069        1092 :                     n->actions = $13;
   11070        1092 :                     $$ = (Node *) n;
   11071             :                 }
   11072             :         ;
   11073             : 
   11074             : RuleActionList:
   11075         162 :             NOTHING                                 { $$ = NIL; }
   11076         884 :             | RuleActionStmt                        { $$ = list_make1($1); }
   11077          46 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   11078             :         ;
   11079             : 
   11080             : /* the thrashing around here is to discard "empty" statements... */
   11081             : RuleActionMulti:
   11082             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   11083          62 :                 { if ($3 != NULL)
   11084          46 :                     $$ = lappend($1, $3);
   11085             :                   else
   11086          16 :                     $$ = $1;
   11087             :                 }
   11088             :             | RuleActionStmtOrEmpty
   11089          46 :                 { if ($1 != NULL)
   11090          46 :                     $$ = list_make1($1);
   11091             :                   else
   11092           0 :                     $$ = NIL;
   11093             :                 }
   11094             :         ;
   11095             : 
   11096             : RuleActionStmt:
   11097             :             SelectStmt
   11098             :             | InsertStmt
   11099             :             | UpdateStmt
   11100             :             | DeleteStmt
   11101             :             | NotifyStmt
   11102             :         ;
   11103             : 
   11104             : RuleActionStmtOrEmpty:
   11105          92 :             RuleActionStmt                          { $$ = $1; }
   11106          16 :             |   /*EMPTY*/                           { $$ = NULL; }
   11107             :         ;
   11108             : 
   11109          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11110         432 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11111         164 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11112         478 :             | INSERT                                { $$ = CMD_INSERT; }
   11113             :          ;
   11114             : 
   11115             : opt_instead:
   11116         752 :             INSTEAD                                 { $$ = true; }
   11117         156 :             | ALSO                                  { $$ = false; }
   11118         184 :             | /*EMPTY*/                             { $$ = false; }
   11119             :         ;
   11120             : 
   11121             : 
   11122             : /*****************************************************************************
   11123             :  *
   11124             :  *      QUERY:
   11125             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11126             :  *              as a query-level command
   11127             :  *
   11128             :  *****************************************************************************/
   11129             : 
   11130             : NotifyStmt: NOTIFY ColId notify_payload
   11131             :                 {
   11132         128 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11133             : 
   11134         128 :                     n->conditionname = $2;
   11135         128 :                     n->payload = $3;
   11136         128 :                     $$ = (Node *) n;
   11137             :                 }
   11138             :         ;
   11139             : 
   11140             : notify_payload:
   11141          62 :             ',' Sconst                          { $$ = $2; }
   11142          66 :             | /*EMPTY*/                         { $$ = NULL; }
   11143             :         ;
   11144             : 
   11145             : ListenStmt: LISTEN ColId
   11146             :                 {
   11147          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11148             : 
   11149          74 :                     n->conditionname = $2;
   11150          74 :                     $$ = (Node *) n;
   11151             :                 }
   11152             :         ;
   11153             : 
   11154             : UnlistenStmt:
   11155             :             UNLISTEN ColId
   11156             :                 {
   11157           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11158             : 
   11159           6 :                     n->conditionname = $2;
   11160           6 :                     $$ = (Node *) n;
   11161             :                 }
   11162             :             | UNLISTEN '*'
   11163             :                 {
   11164          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11165             : 
   11166          32 :                     n->conditionname = NULL;
   11167          32 :                     $$ = (Node *) n;
   11168             :                 }
   11169             :         ;
   11170             : 
   11171             : 
   11172             : /*****************************************************************************
   11173             :  *
   11174             :  *      Transactions:
   11175             :  *
   11176             :  *      BEGIN / COMMIT / ROLLBACK
   11177             :  *      (also older versions END / ABORT)
   11178             :  *
   11179             :  *****************************************************************************/
   11180             : 
   11181             : TransactionStmt:
   11182             :             ABORT_P opt_transaction opt_transaction_chain
   11183             :                 {
   11184         232 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11185             : 
   11186         232 :                     n->kind = TRANS_STMT_ROLLBACK;
   11187         232 :                     n->options = NIL;
   11188         232 :                     n->chain = $3;
   11189         232 :                     n->location = -1;
   11190         232 :                     $$ = (Node *) n;
   11191             :                 }
   11192             :             | START TRANSACTION transaction_mode_list_or_empty
   11193             :                 {
   11194        1638 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11195             : 
   11196        1638 :                     n->kind = TRANS_STMT_START;
   11197        1638 :                     n->options = $3;
   11198        1638 :                     n->location = -1;
   11199        1638 :                     $$ = (Node *) n;
   11200             :                 }
   11201             :             | COMMIT opt_transaction opt_transaction_chain
   11202             :                 {
   11203       11920 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11204             : 
   11205       11920 :                     n->kind = TRANS_STMT_COMMIT;
   11206       11920 :                     n->options = NIL;
   11207       11920 :                     n->chain = $3;
   11208       11920 :                     n->location = -1;
   11209       11920 :                     $$ = (Node *) n;
   11210             :                 }
   11211             :             | ROLLBACK opt_transaction opt_transaction_chain
   11212             :                 {
   11213        2668 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11214             : 
   11215        2668 :                     n->kind = TRANS_STMT_ROLLBACK;
   11216        2668 :                     n->options = NIL;
   11217        2668 :                     n->chain = $3;
   11218        2668 :                     n->location = -1;
   11219        2668 :                     $$ = (Node *) n;
   11220             :                 }
   11221             :             | SAVEPOINT ColId
   11222             :                 {
   11223        1968 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11224             : 
   11225        1968 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11226        1968 :                     n->savepoint_name = $2;
   11227        1968 :                     n->location = @2;
   11228        1968 :                     $$ = (Node *) n;
   11229             :                 }
   11230             :             | RELEASE SAVEPOINT ColId
   11231             :                 {
   11232         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11233             : 
   11234         208 :                     n->kind = TRANS_STMT_RELEASE;
   11235         208 :                     n->savepoint_name = $3;
   11236         208 :                     n->location = @3;
   11237         208 :                     $$ = (Node *) n;
   11238             :                 }
   11239             :             | RELEASE ColId
   11240             :                 {
   11241          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11242             : 
   11243          86 :                     n->kind = TRANS_STMT_RELEASE;
   11244          86 :                     n->savepoint_name = $2;
   11245          86 :                     n->location = @2;
   11246          86 :                     $$ = (Node *) n;
   11247             :                 }
   11248             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11249             :                 {
   11250         228 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11251             : 
   11252         228 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11253         228 :                     n->savepoint_name = $5;
   11254         228 :                     n->location = @5;
   11255         228 :                     $$ = (Node *) n;
   11256             :                 }
   11257             :             | ROLLBACK opt_transaction TO ColId
   11258             :                 {
   11259         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11260             : 
   11261         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11262         496 :                     n->savepoint_name = $4;
   11263         496 :                     n->location = @4;
   11264         496 :                     $$ = (Node *) n;
   11265             :                 }
   11266             :             | PREPARE TRANSACTION Sconst
   11267             :                 {
   11268         642 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11269             : 
   11270         642 :                     n->kind = TRANS_STMT_PREPARE;
   11271         642 :                     n->gid = $3;
   11272         642 :                     n->location = @3;
   11273         642 :                     $$ = (Node *) n;
   11274             :                 }
   11275             :             | COMMIT PREPARED Sconst
   11276             :                 {
   11277         484 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11278             : 
   11279         484 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11280         484 :                     n->gid = $3;
   11281         484 :                     n->location = @3;
   11282         484 :                     $$ = (Node *) n;
   11283             :                 }
   11284             :             | ROLLBACK PREPARED Sconst
   11285             :                 {
   11286          74 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11287             : 
   11288          74 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11289          74 :                     n->gid = $3;
   11290          74 :                     n->location = @3;
   11291          74 :                     $$ = (Node *) n;
   11292             :                 }
   11293             :         ;
   11294             : 
   11295             : TransactionStmtLegacy:
   11296             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11297             :                 {
   11298       14534 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11299             : 
   11300       14534 :                     n->kind = TRANS_STMT_BEGIN;
   11301       14534 :                     n->options = $3;
   11302       14534 :                     n->location = -1;
   11303       14534 :                     $$ = (Node *) n;
   11304             :                 }
   11305             :             | END_P opt_transaction opt_transaction_chain
   11306             :                 {
   11307         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11308             : 
   11309         360 :                     n->kind = TRANS_STMT_COMMIT;
   11310         360 :                     n->options = NIL;
   11311         360 :                     n->chain = $3;
   11312         360 :                     n->location = -1;
   11313         360 :                     $$ = (Node *) n;
   11314             :                 }
   11315             :         ;
   11316             : 
   11317             : opt_transaction:    WORK
   11318             :             | TRANSACTION
   11319             :             | /*EMPTY*/
   11320             :         ;
   11321             : 
   11322             : transaction_mode_item:
   11323             :             ISOLATION LEVEL iso_level
   11324        6730 :                     { $$ = makeDefElem("transaction_isolation",
   11325        6730 :                                        makeStringConst($3, @3), @1); }
   11326             :             | READ ONLY
   11327        1404 :                     { $$ = makeDefElem("transaction_read_only",
   11328        1404 :                                        makeIntConst(true, @1), @1); }
   11329             :             | READ WRITE
   11330          90 :                     { $$ = makeDefElem("transaction_read_only",
   11331          90 :                                        makeIntConst(false, @1), @1); }
   11332             :             | DEFERRABLE
   11333          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11334             :                                        makeIntConst(true, @1), @1); }
   11335             :             | NOT DEFERRABLE
   11336          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11337          10 :                                        makeIntConst(false, @1), @1); }
   11338             :         ;
   11339             : 
   11340             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11341             : transaction_mode_list:
   11342             :             transaction_mode_item
   11343        6946 :                     { $$ = list_make1($1); }
   11344             :             | transaction_mode_list ',' transaction_mode_item
   11345         934 :                     { $$ = lappend($1, $3); }
   11346             :             | transaction_mode_list transaction_mode_item
   11347         398 :                     { $$ = lappend($1, $2); }
   11348             :         ;
   11349             : 
   11350             : transaction_mode_list_or_empty:
   11351             :             transaction_mode_list
   11352             :             | /* EMPTY */
   11353        9820 :                     { $$ = NIL; }
   11354             :         ;
   11355             : 
   11356             : opt_transaction_chain:
   11357         120 :             AND CHAIN       { $$ = true; }
   11358           2 :             | AND NO CHAIN  { $$ = false; }
   11359       15058 :             | /* EMPTY */   { $$ = false; }
   11360             :         ;
   11361             : 
   11362             : 
   11363             : /*****************************************************************************
   11364             :  *
   11365             :  *  QUERY:
   11366             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11367             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11368             :  *
   11369             :  *****************************************************************************/
   11370             : 
   11371             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11372             :                 AS SelectStmt opt_check_option
   11373             :                 {
   11374       16700 :                     ViewStmt   *n = makeNode(ViewStmt);
   11375             : 
   11376       16700 :                     n->view = $4;
   11377       16700 :                     n->view->relpersistence = $2;
   11378       16700 :                     n->aliases = $5;
   11379       16700 :                     n->query = $8;
   11380       16700 :                     n->replace = false;
   11381       16700 :                     n->options = $6;
   11382       16700 :                     n->withCheckOption = $9;
   11383       16700 :                     $$ = (Node *) n;
   11384             :                 }
   11385             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11386             :                 AS SelectStmt opt_check_option
   11387             :                 {
   11388         244 :                     ViewStmt   *n = makeNode(ViewStmt);
   11389             : 
   11390         244 :                     n->view = $6;
   11391         244 :                     n->view->relpersistence = $4;
   11392         244 :                     n->aliases = $7;
   11393         244 :                     n->query = $10;
   11394         244 :                     n->replace = true;
   11395         244 :                     n->options = $8;
   11396         244 :                     n->withCheckOption = $11;
   11397         244 :                     $$ = (Node *) n;
   11398             :                 }
   11399             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11400             :                 AS SelectStmt opt_check_option
   11401             :                 {
   11402           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11403             : 
   11404           8 :                     n->view = $5;
   11405           8 :                     n->view->relpersistence = $2;
   11406           8 :                     n->aliases = $7;
   11407           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11408           8 :                     n->replace = false;
   11409           8 :                     n->options = $9;
   11410           8 :                     n->withCheckOption = $12;
   11411           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11412           0 :                         ereport(ERROR,
   11413             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11414             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11415             :                                  parser_errposition(@12)));
   11416           8 :                     $$ = (Node *) n;
   11417             :                 }
   11418             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11419             :                 AS SelectStmt opt_check_option
   11420             :                 {
   11421           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11422             : 
   11423           6 :                     n->view = $7;
   11424           6 :                     n->view->relpersistence = $4;
   11425           6 :                     n->aliases = $9;
   11426           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11427           6 :                     n->replace = true;
   11428           6 :                     n->options = $11;
   11429           6 :                     n->withCheckOption = $14;
   11430           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11431           0 :                         ereport(ERROR,
   11432             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11433             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11434             :                                  parser_errposition(@14)));
   11435           6 :                     $$ = (Node *) n;
   11436             :                 }
   11437             :         ;
   11438             : 
   11439             : opt_check_option:
   11440          96 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11441           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11442          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11443       16832 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11444             :         ;
   11445             : 
   11446             : /*****************************************************************************
   11447             :  *
   11448             :  *      QUERY:
   11449             :  *              LOAD "filename"
   11450             :  *
   11451             :  *****************************************************************************/
   11452             : 
   11453             : LoadStmt:   LOAD file_name
   11454             :                 {
   11455          54 :                     LoadStmt   *n = makeNode(LoadStmt);
   11456             : 
   11457          54 :                     n->filename = $2;
   11458          54 :                     $$ = (Node *) n;
   11459             :                 }
   11460             :         ;
   11461             : 
   11462             : 
   11463             : /*****************************************************************************
   11464             :  *
   11465             :  *      CREATE DATABASE
   11466             :  *
   11467             :  *****************************************************************************/
   11468             : 
   11469             : CreatedbStmt:
   11470             :             CREATE DATABASE name opt_with createdb_opt_list
   11471             :                 {
   11472         794 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11473             : 
   11474         794 :                     n->dbname = $3;
   11475         794 :                     n->options = $5;
   11476         794 :                     $$ = (Node *) n;
   11477             :                 }
   11478             :         ;
   11479             : 
   11480             : createdb_opt_list:
   11481         646 :             createdb_opt_items                      { $$ = $1; }
   11482         208 :             | /* EMPTY */                           { $$ = NIL; }
   11483             :         ;
   11484             : 
   11485             : createdb_opt_items:
   11486         646 :             createdb_opt_item                       { $$ = list_make1($1); }
   11487         978 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11488             :         ;
   11489             : 
   11490             : createdb_opt_item:
   11491             :             createdb_opt_name opt_equal NumericOnly
   11492             :                 {
   11493         266 :                     $$ = makeDefElem($1, $3, @1);
   11494             :                 }
   11495             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11496             :                 {
   11497        1358 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11498             :                 }
   11499             :             | createdb_opt_name opt_equal DEFAULT
   11500             :                 {
   11501           0 :                     $$ = makeDefElem($1, NULL, @1);
   11502             :                 }
   11503             :         ;
   11504             : 
   11505             : /*
   11506             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11507             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11508             :  * we need, and allow IDENT so that database option names don't have to be
   11509             :  * parser keywords unless they are already keywords for other reasons.
   11510             :  *
   11511             :  * XXX this coding technique is fragile since if someone makes a formerly
   11512             :  * non-keyword option name into a keyword and forgets to add it here, the
   11513             :  * option will silently break.  Best defense is to provide a regression test
   11514             :  * exercising every such option, at least at the syntax level.
   11515             :  */
   11516             : createdb_opt_name:
   11517        1136 :             IDENT                           { $$ = $1; }
   11518           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11519         102 :             | ENCODING                      { $$ = pstrdup($1); }
   11520           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11521           0 :             | OWNER                         { $$ = pstrdup($1); }
   11522          34 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11523         350 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11524             :         ;
   11525             : 
   11526             : /*
   11527             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11528             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11529             :  */
   11530             : opt_equal:  '='
   11531             :             | /*EMPTY*/
   11532             :         ;
   11533             : 
   11534             : 
   11535             : /*****************************************************************************
   11536             :  *
   11537             :  *      ALTER DATABASE
   11538             :  *
   11539             :  *****************************************************************************/
   11540             : 
   11541             : AlterDatabaseStmt:
   11542             :             ALTER DATABASE name WITH createdb_opt_list
   11543             :                  {
   11544           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11545             : 
   11546           0 :                     n->dbname = $3;
   11547           0 :                     n->options = $5;
   11548           0 :                     $$ = (Node *) n;
   11549             :                  }
   11550             :             | ALTER DATABASE name createdb_opt_list
   11551             :                  {
   11552          60 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11553             : 
   11554          60 :                     n->dbname = $3;
   11555          60 :                     n->options = $4;
   11556          60 :                     $$ = (Node *) n;
   11557             :                  }
   11558             :             | ALTER DATABASE name SET TABLESPACE name
   11559             :                  {
   11560          16 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11561             : 
   11562          16 :                     n->dbname = $3;
   11563          16 :                     n->options = list_make1(makeDefElem("tablespace",
   11564             :                                                         (Node *) makeString($6), @6));
   11565          16 :                     $$ = (Node *) n;
   11566             :                  }
   11567             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11568             :                  {
   11569           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11570             : 
   11571           6 :                     n->dbname = $3;
   11572           6 :                     $$ = (Node *) n;
   11573             :                  }
   11574             :         ;
   11575             : 
   11576             : AlterDatabaseSetStmt:
   11577             :             ALTER DATABASE name SetResetClause
   11578             :                 {
   11579        1214 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11580             : 
   11581        1214 :                     n->dbname = $3;
   11582        1214 :                     n->setstmt = $4;
   11583        1214 :                     $$ = (Node *) n;
   11584             :                 }
   11585             :         ;
   11586             : 
   11587             : 
   11588             : /*****************************************************************************
   11589             :  *
   11590             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11591             :  *
   11592             :  * This is implicitly CASCADE, no need for drop behavior
   11593             :  *****************************************************************************/
   11594             : 
   11595             : DropdbStmt: DROP DATABASE name
   11596             :                 {
   11597          92 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11598             : 
   11599          92 :                     n->dbname = $3;
   11600          92 :                     n->missing_ok = false;
   11601          92 :                     n->options = NULL;
   11602          92 :                     $$ = (Node *) n;
   11603             :                 }
   11604             :             | DROP DATABASE IF_P EXISTS name
   11605             :                 {
   11606           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11607             : 
   11608           4 :                     n->dbname = $5;
   11609           4 :                     n->missing_ok = true;
   11610           4 :                     n->options = NULL;
   11611           4 :                     $$ = (Node *) n;
   11612             :                 }
   11613             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11614             :                 {
   11615          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11616             : 
   11617          12 :                     n->dbname = $3;
   11618          12 :                     n->missing_ok = false;
   11619          12 :                     n->options = $6;
   11620          12 :                     $$ = (Node *) n;
   11621             :                 }
   11622             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11623             :                 {
   11624          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11625             : 
   11626          12 :                     n->dbname = $5;
   11627          12 :                     n->missing_ok = true;
   11628          12 :                     n->options = $8;
   11629          12 :                     $$ = (Node *) n;
   11630             :                 }
   11631             :         ;
   11632             : 
   11633             : drop_option_list:
   11634             :             drop_option
   11635             :                 {
   11636          24 :                     $$ = list_make1((Node *) $1);
   11637             :                 }
   11638             :             | drop_option_list ',' drop_option
   11639             :                 {
   11640           0 :                     $$ = lappend($1, (Node *) $3);
   11641             :                 }
   11642             :         ;
   11643             : 
   11644             : /*
   11645             :  * Currently only the FORCE option is supported, but the syntax is designed
   11646             :  * to be extensible so that we can add more options in the future if required.
   11647             :  */
   11648             : drop_option:
   11649             :             FORCE
   11650             :                 {
   11651          24 :                     $$ = makeDefElem("force", NULL, @1);
   11652             :                 }
   11653             :         ;
   11654             : 
   11655             : /*****************************************************************************
   11656             :  *
   11657             :  *      ALTER COLLATION
   11658             :  *
   11659             :  *****************************************************************************/
   11660             : 
   11661             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11662             :                 {
   11663           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11664             : 
   11665           6 :                     n->collname = $3;
   11666           6 :                     $$ = (Node *) n;
   11667             :                 }
   11668             :         ;
   11669             : 
   11670             : 
   11671             : /*****************************************************************************
   11672             :  *
   11673             :  *      ALTER SYSTEM
   11674             :  *
   11675             :  * This is used to change configuration parameters persistently.
   11676             :  *****************************************************************************/
   11677             : 
   11678             : AlterSystemStmt:
   11679             :             ALTER SYSTEM_P SET generic_set
   11680             :                 {
   11681         128 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11682             : 
   11683         128 :                     n->setstmt = $4;
   11684         128 :                     $$ = (Node *) n;
   11685             :                 }
   11686             :             | ALTER SYSTEM_P RESET generic_reset
   11687             :                 {
   11688          56 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11689             : 
   11690          56 :                     n->setstmt = $4;
   11691          56 :                     $$ = (Node *) n;
   11692             :                 }
   11693             :         ;
   11694             : 
   11695             : 
   11696             : /*****************************************************************************
   11697             :  *
   11698             :  * Manipulate a domain
   11699             :  *
   11700             :  *****************************************************************************/
   11701             : 
   11702             : CreateDomainStmt:
   11703             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11704             :                 {
   11705        1452 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11706             : 
   11707        1452 :                     n->domainname = $3;
   11708        1452 :                     n->typeName = $5;
   11709        1452 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11710             :                                      yyscanner);
   11711        1452 :                     $$ = (Node *) n;
   11712             :                 }
   11713             :         ;
   11714             : 
   11715             : AlterDomainStmt:
   11716             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11717             :             ALTER DOMAIN_P any_name alter_column_default
   11718             :                 {
   11719          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11720             : 
   11721          14 :                     n->subtype = AD_AlterDefault;
   11722          14 :                     n->typeName = $3;
   11723          14 :                     n->def = $4;
   11724          14 :                     $$ = (Node *) n;
   11725             :                 }
   11726             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11727             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11728             :                 {
   11729          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11730             : 
   11731          12 :                     n->subtype = AD_DropNotNull;
   11732          12 :                     n->typeName = $3;
   11733          12 :                     $$ = (Node *) n;
   11734             :                 }
   11735             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11736             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11737             :                 {
   11738          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11739             : 
   11740          24 :                     n->subtype = AD_SetNotNull;
   11741          24 :                     n->typeName = $3;
   11742          24 :                     $$ = (Node *) n;
   11743             :                 }
   11744             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11745             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11746             :                 {
   11747         182 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11748             : 
   11749         182 :                     n->subtype = AD_AddConstraint;
   11750         182 :                     n->typeName = $3;
   11751         182 :                     n->def = $5;
   11752         182 :                     $$ = (Node *) n;
   11753             :                 }
   11754             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11755             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11756             :                 {
   11757          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11758             : 
   11759          54 :                     n->subtype = AD_DropConstraint;
   11760          54 :                     n->typeName = $3;
   11761          54 :                     n->name = $6;
   11762          54 :                     n->behavior = $7;
   11763          54 :                     n->missing_ok = false;
   11764          54 :                     $$ = (Node *) n;
   11765             :                 }
   11766             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11767             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11768             :                 {
   11769           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11770             : 
   11771           6 :                     n->subtype = AD_DropConstraint;
   11772           6 :                     n->typeName = $3;
   11773           6 :                     n->name = $8;
   11774           6 :                     n->behavior = $9;
   11775           6 :                     n->missing_ok = true;
   11776           6 :                     $$ = (Node *) n;
   11777             :                 }
   11778             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11779             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11780             :                 {
   11781          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11782             : 
   11783          12 :                     n->subtype = AD_ValidateConstraint;
   11784          12 :                     n->typeName = $3;
   11785          12 :                     n->name = $6;
   11786          12 :                     $$ = (Node *) n;
   11787             :                 }
   11788             :             ;
   11789             : 
   11790             : opt_as:     AS
   11791             :             | /* EMPTY */
   11792             :         ;
   11793             : 
   11794             : 
   11795             : /*****************************************************************************
   11796             :  *
   11797             :  * Manipulate a text search dictionary or configuration
   11798             :  *
   11799             :  *****************************************************************************/
   11800             : 
   11801             : AlterTSDictionaryStmt:
   11802             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11803             :                 {
   11804          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11805             : 
   11806          40 :                     n->dictname = $5;
   11807          40 :                     n->options = $6;
   11808          40 :                     $$ = (Node *) n;
   11809             :                 }
   11810             :         ;
   11811             : 
   11812             : AlterTSConfigurationStmt:
   11813             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11814             :                 {
   11815        8518 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11816             : 
   11817        8518 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11818        8518 :                     n->cfgname = $5;
   11819        8518 :                     n->tokentype = $9;
   11820        8518 :                     n->dicts = $11;
   11821        8518 :                     n->override = false;
   11822        8518 :                     n->replace = false;
   11823        8518 :                     $$ = (Node *) n;
   11824             :                 }
   11825             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11826             :                 {
   11827          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11828             : 
   11829          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11830          26 :                     n->cfgname = $5;
   11831          26 :                     n->tokentype = $9;
   11832          26 :                     n->dicts = $11;
   11833          26 :                     n->override = true;
   11834          26 :                     n->replace = false;
   11835          26 :                     $$ = (Node *) n;
   11836             :                 }
   11837             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11838             :                 {
   11839          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11840             : 
   11841          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11842          18 :                     n->cfgname = $5;
   11843          18 :                     n->tokentype = NIL;
   11844          18 :                     n->dicts = list_make2($9,$11);
   11845          18 :                     n->override = false;
   11846          18 :                     n->replace = true;
   11847          18 :                     $$ = (Node *) n;
   11848             :                 }
   11849             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11850             :                 {
   11851           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11852             : 
   11853           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11854           0 :                     n->cfgname = $5;
   11855           0 :                     n->tokentype = $9;
   11856           0 :                     n->dicts = list_make2($11,$13);
   11857           0 :                     n->override = false;
   11858           0 :                     n->replace = true;
   11859           0 :                     $$ = (Node *) n;
   11860             :                 }
   11861             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11862             :                 {
   11863          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11864             : 
   11865          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11866          18 :                     n->cfgname = $5;
   11867          18 :                     n->tokentype = $9;
   11868          18 :                     n->missing_ok = false;
   11869          18 :                     $$ = (Node *) n;
   11870             :                 }
   11871             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11872             :                 {
   11873          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11874             : 
   11875          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11876          12 :                     n->cfgname = $5;
   11877          12 :                     n->tokentype = $11;
   11878          12 :                     n->missing_ok = true;
   11879          12 :                     $$ = (Node *) n;
   11880             :                 }
   11881             :         ;
   11882             : 
   11883             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11884             : any_with:   WITH
   11885             :             | WITH_LA
   11886             :         ;
   11887             : 
   11888             : 
   11889             : /*****************************************************************************
   11890             :  *
   11891             :  * Manipulate a conversion
   11892             :  *
   11893             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11894             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11895             :  *
   11896             :  *****************************************************************************/
   11897             : 
   11898             : CreateConversionStmt:
   11899             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11900             :             TO Sconst FROM any_name
   11901             :             {
   11902          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11903             : 
   11904          64 :                 n->conversion_name = $4;
   11905          64 :                 n->for_encoding_name = $6;
   11906          64 :                 n->to_encoding_name = $8;
   11907          64 :                 n->func_name = $10;
   11908          64 :                 n->def = $2;
   11909          64 :                 $$ = (Node *) n;
   11910             :             }
   11911             :         ;
   11912             : 
   11913             : /*****************************************************************************
   11914             :  *
   11915             :  *      QUERY:
   11916             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11917             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11918             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11919             :  *
   11920             :  *****************************************************************************/
   11921             : 
   11922             : ClusterStmt:
   11923             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11924             :                 {
   11925           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11926             : 
   11927           0 :                     n->relation = $5;
   11928           0 :                     n->indexname = $6;
   11929           0 :                     n->params = $3;
   11930           0 :                     $$ = (Node *) n;
   11931             :                 }
   11932             :             | CLUSTER opt_utility_option_list
   11933             :                 {
   11934          16 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11935             : 
   11936          16 :                     n->relation = NULL;
   11937          16 :                     n->indexname = NULL;
   11938          16 :                     n->params = $2;
   11939          16 :                     $$ = (Node *) n;
   11940             :                 }
   11941             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11942             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11943             :                 {
   11944         190 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11945             : 
   11946         190 :                     n->relation = $3;
   11947         190 :                     n->indexname = $4;
   11948         190 :                     if ($2)
   11949           0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   11950         190 :                     $$ = (Node *) n;
   11951             :                 }
   11952             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11953             :             | CLUSTER VERBOSE
   11954             :                 {
   11955           6 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11956             : 
   11957           6 :                     n->relation = NULL;
   11958           6 :                     n->indexname = NULL;
   11959           6 :                     n->params = list_make1(makeDefElem("verbose", NULL, @2));
   11960           6 :                     $$ = (Node *) n;
   11961             :                 }
   11962             :             /* kept for pre-8.3 compatibility */
   11963             :             | CLUSTER opt_verbose name ON qualified_name
   11964             :                 {
   11965          20 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11966             : 
   11967          20 :                     n->relation = $5;
   11968          20 :                     n->indexname = $3;
   11969          20 :                     if ($2)
   11970           0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   11971          20 :                     $$ = (Node *) n;
   11972             :                 }
   11973             :         ;
   11974             : 
   11975             : cluster_index_specification:
   11976         156 :             USING name              { $$ = $2; }
   11977          34 :             | /*EMPTY*/             { $$ = NULL; }
   11978             :         ;
   11979             : 
   11980             : 
   11981             : /*****************************************************************************
   11982             :  *
   11983             :  *      QUERY:
   11984             :  *              VACUUM
   11985             :  *              ANALYZE
   11986             :  *
   11987             :  *****************************************************************************/
   11988             : 
   11989             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11990             :                 {
   11991        1234 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11992             : 
   11993        1234 :                     n->options = NIL;
   11994        1234 :                     if ($2)
   11995         152 :                         n->options = lappend(n->options,
   11996         152 :                                              makeDefElem("full", NULL, @2));
   11997        1234 :                     if ($3)
   11998         162 :                         n->options = lappend(n->options,
   11999         162 :                                              makeDefElem("freeze", NULL, @3));
   12000        1234 :                     if ($4)
   12001          18 :                         n->options = lappend(n->options,
   12002          18 :                                              makeDefElem("verbose", NULL, @4));
   12003        1234 :                     if ($5)
   12004         292 :                         n->options = lappend(n->options,
   12005         292 :                                              makeDefElem("analyze", NULL, @5));
   12006        1234 :                     n->rels = $6;
   12007        1234 :                     n->is_vacuumcmd = true;
   12008        1234 :                     $$ = (Node *) n;
   12009             :                 }
   12010             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   12011             :                 {
   12012        7650 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12013             : 
   12014        7650 :                     n->options = $3;
   12015        7650 :                     n->rels = $5;
   12016        7650 :                     n->is_vacuumcmd = true;
   12017        7650 :                     $$ = (Node *) n;
   12018             :                 }
   12019             :         ;
   12020             : 
   12021             : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
   12022             :                 {
   12023        4712 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12024             : 
   12025        4712 :                     n->options = $2;
   12026        4712 :                     n->rels = $3;
   12027        4712 :                     n->is_vacuumcmd = false;
   12028        4712 :                     $$ = (Node *) n;
   12029             :                 }
   12030             :             | analyze_keyword VERBOSE opt_vacuum_relation_list
   12031             :                 {
   12032           0 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12033             : 
   12034           0 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12035           0 :                     n->rels = $3;
   12036           0 :                     n->is_vacuumcmd = false;
   12037           0 :                     $$ = (Node *) n;
   12038             :                 }
   12039             :         ;
   12040             : 
   12041             : analyze_keyword:
   12042             :             ANALYZE
   12043             :             | ANALYSE /* British */
   12044             :         ;
   12045             : 
   12046             : opt_analyze:
   12047         292 :             analyze_keyword                         { $$ = true; }
   12048         942 :             | /*EMPTY*/                             { $$ = false; }
   12049             :         ;
   12050             : 
   12051             : opt_verbose:
   12052          18 :             VERBOSE                                 { $$ = true; }
   12053        3730 :             | /*EMPTY*/                             { $$ = false; }
   12054             :         ;
   12055             : 
   12056         152 : opt_full:   FULL                                    { $$ = true; }
   12057        1082 :             | /*EMPTY*/                             { $$ = false; }
   12058             :         ;
   12059             : 
   12060         162 : opt_freeze: FREEZE                                  { $$ = true; }
   12061        1072 :             | /*EMPTY*/                             { $$ = false; }
   12062             :         ;
   12063             : 
   12064             : opt_name_list:
   12065        2856 :             '(' name_list ')'                       { $$ = $2; }
   12066       15852 :             | /*EMPTY*/                             { $$ = NIL; }
   12067             :         ;
   12068             : 
   12069             : vacuum_relation:
   12070             :             relation_expr opt_name_list
   12071             :                 {
   12072       13374 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12073             :                 }
   12074             :         ;
   12075             : 
   12076             : vacuum_relation_list:
   12077             :             vacuum_relation
   12078       13210 :                     { $$ = list_make1($1); }
   12079             :             | vacuum_relation_list ',' vacuum_relation
   12080         164 :                     { $$ = lappend($1, $3); }
   12081             :         ;
   12082             : 
   12083             : opt_vacuum_relation_list:
   12084       13210 :             vacuum_relation_list                    { $$ = $1; }
   12085         386 :             | /*EMPTY*/                             { $$ = NIL; }
   12086             :         ;
   12087             : 
   12088             : 
   12089             : /*****************************************************************************
   12090             :  *
   12091             :  *      QUERY:
   12092             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12093             :  *              EXPLAIN ( options ) query
   12094             :  *
   12095             :  *****************************************************************************/
   12096             : 
   12097             : ExplainStmt:
   12098             :         EXPLAIN ExplainableStmt
   12099             :                 {
   12100        7718 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12101             : 
   12102        7718 :                     n->query = $2;
   12103        7718 :                     n->options = NIL;
   12104        7718 :                     $$ = (Node *) n;
   12105             :                 }
   12106             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12107             :                 {
   12108        2304 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12109             : 
   12110        2304 :                     n->query = $4;
   12111        2304 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12112        2304 :                     if ($3)
   12113           0 :                         n->options = lappend(n->options,
   12114           0 :                                              makeDefElem("verbose", NULL, @3));
   12115        2304 :                     $$ = (Node *) n;
   12116             :                 }
   12117             :         | EXPLAIN VERBOSE ExplainableStmt
   12118             :                 {
   12119          12 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12120             : 
   12121          12 :                     n->query = $3;
   12122          12 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12123          12 :                     $$ = (Node *) n;
   12124             :                 }
   12125             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12126             :                 {
   12127       14054 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12128             : 
   12129       14054 :                     n->query = $5;
   12130       14054 :                     n->options = $3;
   12131       14054 :                     $$ = (Node *) n;
   12132             :                 }
   12133             :         ;
   12134             : 
   12135             : ExplainableStmt:
   12136             :             SelectStmt
   12137             :             | InsertStmt
   12138             :             | UpdateStmt
   12139             :             | DeleteStmt
   12140             :             | MergeStmt
   12141             :             | DeclareCursorStmt
   12142             :             | CreateAsStmt
   12143             :             | CreateMatViewStmt
   12144             :             | RefreshMatViewStmt
   12145             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12146             :         ;
   12147             : 
   12148             : /*****************************************************************************
   12149             :  *
   12150             :  *      QUERY:
   12151             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12152             :  *
   12153             :  *****************************************************************************/
   12154             : 
   12155             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12156             :                 {
   12157        1960 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12158             : 
   12159        1960 :                     n->name = $2;
   12160        1960 :                     n->argtypes = $3;
   12161        1960 :                     n->query = $5;
   12162        1960 :                     $$ = (Node *) n;
   12163             :                 }
   12164             :         ;
   12165             : 
   12166        1648 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12167         330 :                 | /* EMPTY */               { $$ = NIL; }
   12168             :         ;
   12169             : 
   12170             : PreparableStmt:
   12171             :             SelectStmt
   12172             :             | InsertStmt
   12173             :             | UpdateStmt
   12174             :             | DeleteStmt
   12175             :             | MergeStmt                     /* by default all are $$=$1 */
   12176             :         ;
   12177             : 
   12178             : /*****************************************************************************
   12179             :  *
   12180             :  * EXECUTE <plan_name> [(params, ...)]
   12181             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12182             :  *
   12183             :  *****************************************************************************/
   12184             : 
   12185             : ExecuteStmt: EXECUTE name execute_param_clause
   12186             :                 {
   12187       16304 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12188             : 
   12189       16304 :                     n->name = $2;
   12190       16304 :                     n->params = $3;
   12191       16304 :                     $$ = (Node *) n;
   12192             :                 }
   12193             :             | CREATE OptTemp TABLE create_as_target AS
   12194             :                 EXECUTE name execute_param_clause opt_with_data
   12195             :                 {
   12196          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12197          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12198             : 
   12199          76 :                     n->name = $7;
   12200          76 :                     n->params = $8;
   12201          76 :                     ctas->query = (Node *) n;
   12202          76 :                     ctas->into = $4;
   12203          76 :                     ctas->objtype = OBJECT_TABLE;
   12204          76 :                     ctas->is_select_into = false;
   12205          76 :                     ctas->if_not_exists = false;
   12206             :                     /* cram additional flags into the IntoClause */
   12207          76 :                     $4->rel->relpersistence = $2;
   12208          76 :                     $4->skipData = !($9);
   12209          76 :                     $$ = (Node *) ctas;
   12210             :                 }
   12211             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12212             :                 EXECUTE name execute_param_clause opt_with_data
   12213             :                 {
   12214          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12215          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12216             : 
   12217          12 :                     n->name = $10;
   12218          12 :                     n->params = $11;
   12219          12 :                     ctas->query = (Node *) n;
   12220          12 :                     ctas->into = $7;
   12221          12 :                     ctas->objtype = OBJECT_TABLE;
   12222          12 :                     ctas->is_select_into = false;
   12223          12 :                     ctas->if_not_exists = true;
   12224             :                     /* cram additional flags into the IntoClause */
   12225          12 :                     $7->rel->relpersistence = $2;
   12226          12 :                     $7->skipData = !($12);
   12227          12 :                     $$ = (Node *) ctas;
   12228             :                 }
   12229             :         ;
   12230             : 
   12231       15250 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12232        1142 :                     | /* EMPTY */                   { $$ = NIL; }
   12233             :                     ;
   12234             : 
   12235             : /*****************************************************************************
   12236             :  *
   12237             :  *      QUERY:
   12238             :  *              DEALLOCATE [PREPARE] <plan_name>
   12239             :  *
   12240             :  *****************************************************************************/
   12241             : 
   12242             : DeallocateStmt: DEALLOCATE name
   12243             :                     {
   12244        3996 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12245             : 
   12246        3996 :                         n->name = $2;
   12247        3996 :                         n->isall = false;
   12248        3996 :                         n->location = @2;
   12249        3996 :                         $$ = (Node *) n;
   12250             :                     }
   12251             :                 | DEALLOCATE PREPARE name
   12252             :                     {
   12253          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12254             : 
   12255          20 :                         n->name = $3;
   12256          20 :                         n->isall = false;
   12257          20 :                         n->location = @3;
   12258          20 :                         $$ = (Node *) n;
   12259             :                     }
   12260             :                 | DEALLOCATE ALL
   12261             :                     {
   12262          70 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12263             : 
   12264          70 :                         n->name = NULL;
   12265          70 :                         n->isall = true;
   12266          70 :                         n->location = -1;
   12267          70 :                         $$ = (Node *) n;
   12268             :                     }
   12269             :                 | DEALLOCATE PREPARE ALL
   12270             :                     {
   12271           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12272             : 
   12273           2 :                         n->name = NULL;
   12274           2 :                         n->isall = true;
   12275           2 :                         n->location = -1;
   12276           2 :                         $$ = (Node *) n;
   12277             :                     }
   12278             :         ;
   12279             : 
   12280             : /*****************************************************************************
   12281             :  *
   12282             :  *      QUERY:
   12283             :  *              INSERT STATEMENTS
   12284             :  *
   12285             :  *****************************************************************************/
   12286             : 
   12287             : InsertStmt:
   12288             :             opt_with_clause INSERT INTO insert_target insert_rest
   12289             :             opt_on_conflict returning_clause
   12290             :                 {
   12291       68550 :                     $5->relation = $4;
   12292       68550 :                     $5->onConflictClause = $6;
   12293       68550 :                     $5->returningClause = $7;
   12294       68550 :                     $5->withClause = $1;
   12295       68550 :                     $$ = (Node *) $5;
   12296             :                 }
   12297             :         ;
   12298             : 
   12299             : /*
   12300             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12301             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12302             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12303             :  * divergence from other places.  So just require AS for now.
   12304             :  */
   12305             : insert_target:
   12306             :             qualified_name
   12307             :                 {
   12308       68424 :                     $$ = $1;
   12309             :                 }
   12310             :             | qualified_name AS ColId
   12311             :                 {
   12312         132 :                     $1->alias = makeAlias($3, NIL);
   12313         132 :                     $$ = $1;
   12314             :                 }
   12315             :         ;
   12316             : 
   12317             : insert_rest:
   12318             :             SelectStmt
   12319             :                 {
   12320       43364 :                     $$ = makeNode(InsertStmt);
   12321       43364 :                     $$->cols = NIL;
   12322       43364 :                     $$->selectStmt = $1;
   12323             :                 }
   12324             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12325             :                 {
   12326          96 :                     $$ = makeNode(InsertStmt);
   12327          96 :                     $$->cols = NIL;
   12328          96 :                     $$->override = $2;
   12329          96 :                     $$->selectStmt = $4;
   12330             :                 }
   12331             :             | '(' insert_column_list ')' SelectStmt
   12332             :                 {
   12333       14288 :                     $$ = makeNode(InsertStmt);
   12334       14288 :                     $$->cols = $2;
   12335       14288 :                     $$->selectStmt = $4;
   12336             :                 }
   12337             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12338             :                 {
   12339           0 :                     $$ = makeNode(InsertStmt);
   12340           0 :                     $$->cols = $2;
   12341           0 :                     $$->override = $5;
   12342           0 :                     $$->selectStmt = $7;
   12343             :                 }
   12344             :             | DEFAULT VALUES
   12345             :                 {
   12346       10808 :                     $$ = makeNode(InsertStmt);
   12347       10808 :                     $$->cols = NIL;
   12348       10808 :                     $$->selectStmt = NULL;
   12349             :                 }
   12350             :         ;
   12351             : 
   12352             : override_kind:
   12353          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12354          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12355             :         ;
   12356             : 
   12357             : insert_column_list:
   12358             :             insert_column_item
   12359       14622 :                     { $$ = list_make1($1); }
   12360             :             | insert_column_list ',' insert_column_item
   12361       16150 :                     { $$ = lappend($1, $3); }
   12362             :         ;
   12363             : 
   12364             : insert_column_item:
   12365             :             ColId opt_indirection
   12366             :                 {
   12367       30772 :                     $$ = makeNode(ResTarget);
   12368       30772 :                     $$->name = $1;
   12369       30772 :                     $$->indirection = check_indirection($2, yyscanner);
   12370       30772 :                     $$->val = NULL;
   12371       30772 :                     $$->location = @1;
   12372             :                 }
   12373             :         ;
   12374             : 
   12375             : opt_on_conflict:
   12376             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12377             :                 {
   12378        1314 :                     $$ = makeNode(OnConflictClause);
   12379        1314 :                     $$->action = ONCONFLICT_UPDATE;
   12380        1314 :                     $$->infer = $3;
   12381        1314 :                     $$->targetList = $7;
   12382        1314 :                     $$->whereClause = $8;
   12383        1314 :                     $$->location = @1;
   12384             :                 }
   12385             :             |
   12386             :             ON CONFLICT opt_conf_expr DO NOTHING
   12387             :                 {
   12388         562 :                     $$ = makeNode(OnConflictClause);
   12389         562 :                     $$->action = ONCONFLICT_NOTHING;
   12390         562 :                     $$->infer = $3;
   12391         562 :                     $$->targetList = NIL;
   12392         562 :                     $$->whereClause = NULL;
   12393         562 :                     $$->location = @1;
   12394             :                 }
   12395             :             | /*EMPTY*/
   12396             :                 {
   12397       66680 :                     $$ = NULL;
   12398             :                 }
   12399             :         ;
   12400             : 
   12401             : opt_conf_expr:
   12402             :             '(' index_params ')' where_clause
   12403             :                 {
   12404        1438 :                     $$ = makeNode(InferClause);
   12405        1438 :                     $$->indexElems = $2;
   12406        1438 :                     $$->whereClause = $4;
   12407        1438 :                     $$->conname = NULL;
   12408        1438 :                     $$->location = @1;
   12409             :                 }
   12410             :             |
   12411             :             ON CONSTRAINT name
   12412             :                 {
   12413         192 :                     $$ = makeNode(InferClause);
   12414         192 :                     $$->indexElems = NIL;
   12415         192 :                     $$->whereClause = NULL;
   12416         192 :                     $$->conname = $3;
   12417         192 :                     $$->location = @1;
   12418             :                 }
   12419             :             | /*EMPTY*/
   12420             :                 {
   12421         246 :                     $$ = NULL;
   12422             :                 }
   12423             :         ;
   12424             : 
   12425             : returning_clause:
   12426             :             RETURNING returning_with_clause target_list
   12427             :                 {
   12428        3150 :                     ReturningClause *n = makeNode(ReturningClause);
   12429             : 
   12430        3150 :                     n->options = $2;
   12431        3150 :                     n->exprs = $3;
   12432        3150 :                     $$ = n;
   12433             :                 }
   12434             :             | /* EMPTY */
   12435             :                 {
   12436       86308 :                     $$ = NULL;
   12437             :                 }
   12438             :         ;
   12439             : 
   12440             : returning_with_clause:
   12441          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12442        3078 :             | /* EMPTY */                       { $$ = NIL; }
   12443             :         ;
   12444             : 
   12445             : returning_options:
   12446          72 :             returning_option                            { $$ = list_make1($1); }
   12447          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12448             :         ;
   12449             : 
   12450             : returning_option:
   12451             :             returning_option_kind AS ColId
   12452             :                 {
   12453         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12454             : 
   12455         126 :                     n->option = $1;
   12456         126 :                     n->value = $3;
   12457         126 :                     n->location = @1;
   12458         126 :                     $$ = (Node *) n;
   12459             :                 }
   12460             :         ;
   12461             : 
   12462             : returning_option_kind:
   12463          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12464          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12465             :         ;
   12466             : 
   12467             : 
   12468             : /*****************************************************************************
   12469             :  *
   12470             :  *      QUERY:
   12471             :  *              DELETE STATEMENTS
   12472             :  *
   12473             :  *****************************************************************************/
   12474             : 
   12475             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12476             :             using_clause where_or_current_clause returning_clause
   12477             :                 {
   12478        4652 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12479             : 
   12480        4652 :                     n->relation = $4;
   12481        4652 :                     n->usingClause = $5;
   12482        4652 :                     n->whereClause = $6;
   12483        4652 :                     n->returningClause = $7;
   12484        4652 :                     n->withClause = $1;
   12485        4652 :                     $$ = (Node *) n;
   12486             :                 }
   12487             :         ;
   12488             : 
   12489             : using_clause:
   12490         108 :                 USING from_list                     { $$ = $2; }
   12491        4544 :             | /*EMPTY*/                             { $$ = NIL; }
   12492             :         ;
   12493             : 
   12494             : 
   12495             : /*****************************************************************************
   12496             :  *
   12497             :  *      QUERY:
   12498             :  *              LOCK TABLE
   12499             :  *
   12500             :  *****************************************************************************/
   12501             : 
   12502             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12503             :                 {
   12504        1188 :                     LockStmt   *n = makeNode(LockStmt);
   12505             : 
   12506        1188 :                     n->relations = $3;
   12507        1188 :                     n->mode = $4;
   12508        1188 :                     n->nowait = $5;
   12509        1188 :                     $$ = (Node *) n;
   12510             :                 }
   12511             :         ;
   12512             : 
   12513        1080 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12514         108 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12515             :         ;
   12516             : 
   12517         590 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12518          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12519          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12520          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12521          80 :             | SHARE                         { $$ = ShareLock; }
   12522          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12523         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12524         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12525             :         ;
   12526             : 
   12527         334 : opt_nowait: NOWAIT                          { $$ = true; }
   12528         884 :             | /*EMPTY*/                     { $$ = false; }
   12529             :         ;
   12530             : 
   12531             : opt_nowait_or_skip:
   12532          50 :             NOWAIT                          { $$ = LockWaitError; }
   12533         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12534        4982 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12535             :         ;
   12536             : 
   12537             : 
   12538             : /*****************************************************************************
   12539             :  *
   12540             :  *      QUERY:
   12541             :  *              UpdateStmt (UPDATE)
   12542             :  *
   12543             :  *****************************************************************************/
   12544             : 
   12545             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12546             :             SET set_clause_list
   12547             :             from_clause
   12548             :             where_or_current_clause
   12549             :             returning_clause
   12550             :                 {
   12551       14138 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12552             : 
   12553       14138 :                     n->relation = $3;
   12554       14138 :                     n->targetList = $5;
   12555       14138 :                     n->fromClause = $6;
   12556       14138 :                     n->whereClause = $7;
   12557       14138 :                     n->returningClause = $8;
   12558       14138 :                     n->withClause = $1;
   12559       14138 :                     $$ = (Node *) n;
   12560             :                 }
   12561             :         ;
   12562             : 
   12563             : set_clause_list:
   12564       17050 :             set_clause                          { $$ = $1; }
   12565        4212 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12566             :         ;
   12567             : 
   12568             : set_clause:
   12569             :             set_target '=' a_expr
   12570             :                 {
   12571       21078 :                     $1->val = (Node *) $3;
   12572       21078 :                     $$ = list_make1($1);
   12573             :                 }
   12574             :             | '(' set_target_list ')' '=' a_expr
   12575             :                 {
   12576         184 :                     int         ncolumns = list_length($2);
   12577         184 :                     int         i = 1;
   12578             :                     ListCell   *col_cell;
   12579             : 
   12580             :                     /* Create a MultiAssignRef source for each target */
   12581         568 :                     foreach(col_cell, $2)
   12582             :                     {
   12583         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12584         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12585             : 
   12586         384 :                         r->source = (Node *) $5;
   12587         384 :                         r->colno = i;
   12588         384 :                         r->ncolumns = ncolumns;
   12589         384 :                         res_col->val = (Node *) r;
   12590         384 :                         i++;
   12591             :                     }
   12592             : 
   12593         184 :                     $$ = $2;
   12594             :                 }
   12595             :         ;
   12596             : 
   12597             : set_target:
   12598             :             ColId opt_indirection
   12599             :                 {
   12600       21468 :                     $$ = makeNode(ResTarget);
   12601       21468 :                     $$->name = $1;
   12602       21468 :                     $$->indirection = check_indirection($2, yyscanner);
   12603       21468 :                     $$->val = NULL;  /* upper production sets this */
   12604       21468 :                     $$->location = @1;
   12605             :                 }
   12606             :         ;
   12607             : 
   12608             : set_target_list:
   12609         190 :             set_target                              { $$ = list_make1($1); }
   12610         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12611             :         ;
   12612             : 
   12613             : 
   12614             : /*****************************************************************************
   12615             :  *
   12616             :  *      QUERY:
   12617             :  *              MERGE
   12618             :  *
   12619             :  *****************************************************************************/
   12620             : 
   12621             : MergeStmt:
   12622             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12623             :             USING table_ref
   12624             :             ON a_expr
   12625             :             merge_when_list
   12626             :             returning_clause
   12627             :                 {
   12628        2118 :                     MergeStmt  *m = makeNode(MergeStmt);
   12629             : 
   12630        2118 :                     m->withClause = $1;
   12631        2118 :                     m->relation = $4;
   12632        2118 :                     m->sourceRelation = $6;
   12633        2118 :                     m->joinCondition = $8;
   12634        2118 :                     m->mergeWhenClauses = $9;
   12635        2118 :                     m->returningClause = $10;
   12636             : 
   12637        2118 :                     $$ = (Node *) m;
   12638             :                 }
   12639             :         ;
   12640             : 
   12641             : merge_when_list:
   12642        2118 :             merge_when_clause                       { $$ = list_make1($1); }
   12643        1200 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12644             :         ;
   12645             : 
   12646             : /*
   12647             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12648             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12649             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12650             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12651             :  */
   12652             : merge_when_clause:
   12653             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12654             :                 {
   12655        1598 :                     $4->matchKind = $1;
   12656        1598 :                     $4->condition = $2;
   12657             : 
   12658        1598 :                     $$ = (Node *) $4;
   12659             :                 }
   12660             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12661             :                 {
   12662         530 :                     $4->matchKind = $1;
   12663         530 :                     $4->condition = $2;
   12664             : 
   12665         530 :                     $$ = (Node *) $4;
   12666             :                 }
   12667             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12668             :                 {
   12669        1100 :                     $4->matchKind = $1;
   12670        1100 :                     $4->condition = $2;
   12671             : 
   12672        1100 :                     $$ = (Node *) $4;
   12673             :                 }
   12674             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12675             :                 {
   12676          70 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12677             : 
   12678          70 :                     m->matchKind = $1;
   12679          70 :                     m->commandType = CMD_NOTHING;
   12680          70 :                     m->condition = $2;
   12681             : 
   12682          70 :                     $$ = (Node *) m;
   12683             :                 }
   12684             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12685             :                 {
   12686          20 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12687             : 
   12688          20 :                     m->matchKind = $1;
   12689          20 :                     m->commandType = CMD_NOTHING;
   12690          20 :                     m->condition = $2;
   12691             : 
   12692          20 :                     $$ = (Node *) m;
   12693             :                 }
   12694             :         ;
   12695             : 
   12696             : merge_when_tgt_matched:
   12697        2036 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12698         180 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12699             :         ;
   12700             : 
   12701             : merge_when_tgt_not_matched:
   12702        1126 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12703          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12704             :         ;
   12705             : 
   12706             : opt_merge_when_condition:
   12707         850 :             AND a_expr              { $$ = $2; }
   12708        2510 :             |                       { $$ = NULL; }
   12709             :         ;
   12710             : 
   12711             : merge_update:
   12712             :             UPDATE SET set_clause_list
   12713             :                 {
   12714        1598 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12715        1598 :                     n->commandType = CMD_UPDATE;
   12716        1598 :                     n->override = OVERRIDING_NOT_SET;
   12717        1598 :                     n->targetList = $3;
   12718        1598 :                     n->values = NIL;
   12719             : 
   12720        1598 :                     $$ = n;
   12721             :                 }
   12722             :         ;
   12723             : 
   12724             : merge_delete:
   12725             :             DELETE_P
   12726             :                 {
   12727         530 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12728         530 :                     n->commandType = CMD_DELETE;
   12729         530 :                     n->override = OVERRIDING_NOT_SET;
   12730         530 :                     n->targetList = NIL;
   12731         530 :                     n->values = NIL;
   12732             : 
   12733         530 :                     $$ = n;
   12734             :                 }
   12735             :         ;
   12736             : 
   12737             : merge_insert:
   12738             :             INSERT merge_values_clause
   12739             :                 {
   12740         730 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12741         730 :                     n->commandType = CMD_INSERT;
   12742         730 :                     n->override = OVERRIDING_NOT_SET;
   12743         730 :                     n->targetList = NIL;
   12744         730 :                     n->values = $2;
   12745         730 :                     $$ = n;
   12746             :                 }
   12747             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12748             :                 {
   12749           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12750           0 :                     n->commandType = CMD_INSERT;
   12751           0 :                     n->override = $3;
   12752           0 :                     n->targetList = NIL;
   12753           0 :                     n->values = $5;
   12754           0 :                     $$ = n;
   12755             :                 }
   12756             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12757             :                 {
   12758         304 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12759         304 :                     n->commandType = CMD_INSERT;
   12760         304 :                     n->override = OVERRIDING_NOT_SET;
   12761         304 :                     n->targetList = $3;
   12762         304 :                     n->values = $5;
   12763         304 :                     $$ = n;
   12764             :                 }
   12765             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12766             :                 {
   12767          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12768          30 :                     n->commandType = CMD_INSERT;
   12769          30 :                     n->override = $6;
   12770          30 :                     n->targetList = $3;
   12771          30 :                     n->values = $8;
   12772          30 :                     $$ = n;
   12773             :                 }
   12774             :             | INSERT DEFAULT VALUES
   12775             :                 {
   12776          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12777          36 :                     n->commandType = CMD_INSERT;
   12778          36 :                     n->override = OVERRIDING_NOT_SET;
   12779          36 :                     n->targetList = NIL;
   12780          36 :                     n->values = NIL;
   12781          36 :                     $$ = n;
   12782             :                 }
   12783             :         ;
   12784             : 
   12785             : merge_values_clause:
   12786             :             VALUES '(' expr_list ')'
   12787             :                 {
   12788        1064 :                     $$ = $3;
   12789             :                 }
   12790             :         ;
   12791             : 
   12792             : /*****************************************************************************
   12793             :  *
   12794             :  *      QUERY:
   12795             :  *              CURSOR STATEMENTS
   12796             :  *
   12797             :  *****************************************************************************/
   12798             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12799             :                 {
   12800        4608 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12801             : 
   12802        4608 :                     n->portalname = $2;
   12803             :                     /* currently we always set FAST_PLAN option */
   12804        4608 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12805        4608 :                     n->query = $7;
   12806        4608 :                     $$ = (Node *) n;
   12807             :                 }
   12808             :         ;
   12809             : 
   12810       14816 : cursor_name:    name                        { $$ = $1; }
   12811             :         ;
   12812             : 
   12813        4608 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12814          28 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12815         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12816          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12817           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12818           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12819             :         ;
   12820             : 
   12821        4510 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12822          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12823           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12824             :         ;
   12825             : 
   12826             : /*****************************************************************************
   12827             :  *
   12828             :  *      QUERY:
   12829             :  *              SELECT STATEMENTS
   12830             :  *
   12831             :  *****************************************************************************/
   12832             : 
   12833             : /* A complete SELECT statement looks like this.
   12834             :  *
   12835             :  * The rule returns either a single SelectStmt node or a tree of them,
   12836             :  * representing a set-operation tree.
   12837             :  *
   12838             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12839             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12840             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12841             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12842             :  * the decision is staved off as long as possible: as long as we can keep
   12843             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12844             :  * it's no longer possible to do that will we decide that parens belong to
   12845             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12846             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12847             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12848             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12849             :  * SELECT viewpoint when we see the UNION.
   12850             :  *
   12851             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12852             :  * which represents a SELECT with at least one outer layer of parentheses,
   12853             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12854             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12855             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12856             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12857             :  * conflict with the select_with_parens productions are manually given
   12858             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12859             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12860             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12861             :  * precedence for this, which is a fairly arbitrary choice.
   12862             :  *
   12863             :  * To be able to define select_with_parens itself without ambiguity, we need
   12864             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12865             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12866             :  *
   12867             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12868             :  * with or without outer parentheses.
   12869             :  */
   12870             : 
   12871             : SelectStmt: select_no_parens            %prec UMINUS
   12872             :             | select_with_parens        %prec UMINUS
   12873             :         ;
   12874             : 
   12875             : select_with_parens:
   12876       64734 :             '(' select_no_parens ')'                { $$ = $2; }
   12877         156 :             | '(' select_with_parens ')'            { $$ = $2; }
   12878             :         ;
   12879             : 
   12880             : /*
   12881             :  * This rule parses the equivalent of the standard's <query expression>.
   12882             :  * The duplicative productions are annoying, but hard to get rid of without
   12883             :  * creating shift/reduce conflicts.
   12884             :  *
   12885             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12886             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12887             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12888             :  * clause.
   12889             :  *  2002-08-28 bjm
   12890             :  */
   12891             : select_no_parens:
   12892      388348 :             simple_select                       { $$ = $1; }
   12893             :             | select_clause sort_clause
   12894             :                 {
   12895       70390 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12896             :                                         NULL, NULL,
   12897             :                                         yyscanner);
   12898       70390 :                     $$ = $1;
   12899             :                 }
   12900             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12901             :                 {
   12902        4774 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12903        4774 :                                         $4,
   12904             :                                         NULL,
   12905             :                                         yyscanner);
   12906        4774 :                     $$ = $1;
   12907             :                 }
   12908             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12909             :                 {
   12910        4898 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12911        4898 :                                         $3,
   12912             :                                         NULL,
   12913             :                                         yyscanner);
   12914        4886 :                     $$ = $1;
   12915             :                 }
   12916             :             | with_clause select_clause
   12917             :                 {
   12918        2188 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12919             :                                         NULL,
   12920        2188 :                                         $1,
   12921             :                                         yyscanner);
   12922        2188 :                     $$ = $2;
   12923             :                 }
   12924             :             | with_clause select_clause sort_clause
   12925             :                 {
   12926         608 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12927             :                                         NULL,
   12928         608 :                                         $1,
   12929             :                                         yyscanner);
   12930         608 :                     $$ = $2;
   12931             :                 }
   12932             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12933             :                 {
   12934           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12935           6 :                                         $5,
   12936           6 :                                         $1,
   12937             :                                         yyscanner);
   12938           6 :                     $$ = $2;
   12939             :                 }
   12940             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12941             :                 {
   12942          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12943          64 :                                         $4,
   12944          64 :                                         $1,
   12945             :                                         yyscanner);
   12946          64 :                     $$ = $2;
   12947             :                 }
   12948             :         ;
   12949             : 
   12950             : select_clause:
   12951      120952 :             simple_select                           { $$ = $1; }
   12952         588 :             | select_with_parens                    { $$ = $1; }
   12953             :         ;
   12954             : 
   12955             : /*
   12956             :  * This rule parses SELECT statements that can appear within set operations,
   12957             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12958             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12959             :  * operations to be ordered per the precedence specs at the head of this file.
   12960             :  *
   12961             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12962             :  * but can have parenthesized subclauses.
   12963             :  *
   12964             :  * It might appear that we could fold the first two alternatives into one
   12965             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12966             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12967             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12968             :  *
   12969             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12970             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12971             :  * to be parsed as
   12972             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12973             :  * not
   12974             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12975             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12976             :  * described as part of the select_no_parens production, not simple_select.
   12977             :  * This does not limit functionality, because you can reintroduce these
   12978             :  * clauses inside parentheses.
   12979             :  *
   12980             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12981             :  * However, this is not checked by the grammar; parse analysis must check it.
   12982             :  */
   12983             : simple_select:
   12984             :             SELECT opt_all_clause opt_target_list
   12985             :             into_clause from_clause where_clause
   12986             :             group_clause having_clause window_clause
   12987             :                 {
   12988      427044 :                     SelectStmt *n = makeNode(SelectStmt);
   12989             : 
   12990      427042 :                     n->targetList = $3;
   12991      427042 :                     n->intoClause = $4;
   12992      427042 :                     n->fromClause = $5;
   12993      427042 :                     n->whereClause = $6;
   12994      427042 :                     n->groupClause = ($7)->list;
   12995      427042 :                     n->groupDistinct = ($7)->distinct;
   12996      427042 :                     n->havingClause = $8;
   12997      427042 :                     n->windowClause = $9;
   12998      427042 :                     $$ = (Node *) n;
   12999             :                 }
   13000             :             | SELECT distinct_clause target_list
   13001             :             into_clause from_clause where_clause
   13002             :             group_clause having_clause window_clause
   13003             :                 {
   13004        3660 :                     SelectStmt *n = makeNode(SelectStmt);
   13005             : 
   13006        3660 :                     n->distinctClause = $2;
   13007        3660 :                     n->targetList = $3;
   13008        3660 :                     n->intoClause = $4;
   13009        3660 :                     n->fromClause = $5;
   13010        3660 :                     n->whereClause = $6;
   13011        3660 :                     n->groupClause = ($7)->list;
   13012        3660 :                     n->groupDistinct = ($7)->distinct;
   13013        3660 :                     n->havingClause = $8;
   13014        3660 :                     n->windowClause = $9;
   13015        3660 :                     $$ = (Node *) n;
   13016             :                 }
   13017       58988 :             | values_clause                         { $$ = $1; }
   13018             :             | TABLE relation_expr
   13019             :                 {
   13020             :                     /* same as SELECT * FROM relation_expr */
   13021         308 :                     ColumnRef  *cr = makeNode(ColumnRef);
   13022         308 :                     ResTarget  *rt = makeNode(ResTarget);
   13023         308 :                     SelectStmt *n = makeNode(SelectStmt);
   13024             : 
   13025         308 :                     cr->fields = list_make1(makeNode(A_Star));
   13026         308 :                     cr->location = -1;
   13027             : 
   13028         308 :                     rt->name = NULL;
   13029         308 :                     rt->indirection = NIL;
   13030         308 :                     rt->val = (Node *) cr;
   13031         308 :                     rt->location = -1;
   13032             : 
   13033         308 :                     n->targetList = list_make1(rt);
   13034         308 :                     n->fromClause = list_make1($2);
   13035         308 :                     $$ = (Node *) n;
   13036             :                 }
   13037             :             | select_clause UNION set_quantifier select_clause
   13038             :                 {
   13039       18566 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13040             :                 }
   13041             :             | select_clause INTERSECT set_quantifier select_clause
   13042             :                 {
   13043         258 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13044             :                 }
   13045             :             | select_clause EXCEPT set_quantifier select_clause
   13046             :                 {
   13047         476 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13048             :                 }
   13049             :         ;
   13050             : 
   13051             : /*
   13052             :  * SQL standard WITH clause looks like:
   13053             :  *
   13054             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13055             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13056             :  *
   13057             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13058             :  */
   13059             : with_clause:
   13060             :         WITH cte_list
   13061             :             {
   13062        2068 :                 $$ = makeNode(WithClause);
   13063        2068 :                 $$->ctes = $2;
   13064        2068 :                 $$->recursive = false;
   13065        2068 :                 $$->location = @1;
   13066             :             }
   13067             :         | WITH_LA cte_list
   13068             :             {
   13069           6 :                 $$ = makeNode(WithClause);
   13070           6 :                 $$->ctes = $2;
   13071           6 :                 $$->recursive = false;
   13072           6 :                 $$->location = @1;
   13073             :             }
   13074             :         | WITH RECURSIVE cte_list
   13075             :             {
   13076        1242 :                 $$ = makeNode(WithClause);
   13077        1242 :                 $$->ctes = $3;
   13078        1242 :                 $$->recursive = true;
   13079        1242 :                 $$->location = @1;
   13080             :             }
   13081             :         ;
   13082             : 
   13083             : cte_list:
   13084        3316 :         common_table_expr                       { $$ = list_make1($1); }
   13085        1252 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13086             :         ;
   13087             : 
   13088             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13089             :             {
   13090        4568 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13091             : 
   13092        4568 :                 n->ctename = $1;
   13093        4568 :                 n->aliascolnames = $2;
   13094        4568 :                 n->ctematerialized = $4;
   13095        4568 :                 n->ctequery = $6;
   13096        4568 :                 n->search_clause = castNode(CTESearchClause, $8);
   13097        4568 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13098        4568 :                 n->location = @1;
   13099        4568 :                 $$ = (Node *) n;
   13100             :             }
   13101             :         ;
   13102             : 
   13103             : opt_materialized:
   13104         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13105          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13106        4342 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13107             :         ;
   13108             : 
   13109             : opt_search_clause:
   13110             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13111             :             {
   13112          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13113             : 
   13114          90 :                 n->search_col_list = $5;
   13115          90 :                 n->search_breadth_first = false;
   13116          90 :                 n->search_seq_column = $7;
   13117          90 :                 n->location = @1;
   13118          90 :                 $$ = (Node *) n;
   13119             :             }
   13120             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13121             :             {
   13122          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13123             : 
   13124          36 :                 n->search_col_list = $5;
   13125          36 :                 n->search_breadth_first = true;
   13126          36 :                 n->search_seq_column = $7;
   13127          36 :                 n->location = @1;
   13128          36 :                 $$ = (Node *) n;
   13129             :             }
   13130             :         | /*EMPTY*/
   13131             :             {
   13132        4442 :                 $$ = NULL;
   13133             :             }
   13134             :         ;
   13135             : 
   13136             : opt_cycle_clause:
   13137             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13138             :             {
   13139          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13140             : 
   13141          66 :                 n->cycle_col_list = $2;
   13142          66 :                 n->cycle_mark_column = $4;
   13143          66 :                 n->cycle_mark_value = $6;
   13144          66 :                 n->cycle_mark_default = $8;
   13145          66 :                 n->cycle_path_column = $10;
   13146          66 :                 n->location = @1;
   13147          66 :                 $$ = (Node *) n;
   13148             :             }
   13149             :         | CYCLE columnList SET ColId USING ColId
   13150             :             {
   13151          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13152             : 
   13153          60 :                 n->cycle_col_list = $2;
   13154          60 :                 n->cycle_mark_column = $4;
   13155          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13156          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13157          60 :                 n->cycle_path_column = $6;
   13158          60 :                 n->location = @1;
   13159          60 :                 $$ = (Node *) n;
   13160             :             }
   13161             :         | /*EMPTY*/
   13162             :             {
   13163        4442 :                 $$ = NULL;
   13164             :             }
   13165             :         ;
   13166             : 
   13167             : opt_with_clause:
   13168         450 :         with_clause                             { $$ = $1; }
   13169       89124 :         | /*EMPTY*/                             { $$ = NULL; }
   13170             :         ;
   13171             : 
   13172             : into_clause:
   13173             :             INTO OptTempTableName
   13174             :                 {
   13175         138 :                     $$ = makeNode(IntoClause);
   13176         138 :                     $$->rel = $2;
   13177         138 :                     $$->colNames = NIL;
   13178         138 :                     $$->options = NIL;
   13179         138 :                     $$->onCommit = ONCOMMIT_NOOP;
   13180         138 :                     $$->tableSpaceName = NULL;
   13181         138 :                     $$->viewQuery = NULL;
   13182         138 :                     $$->skipData = false;
   13183             :                 }
   13184             :             | /*EMPTY*/
   13185      430596 :                 { $$ = NULL; }
   13186             :         ;
   13187             : 
   13188             : /*
   13189             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13190             :  * since TEMP is not a reserved word.  See also OptTemp.
   13191             :  */
   13192             : OptTempTableName:
   13193             :             TEMPORARY opt_table qualified_name
   13194             :                 {
   13195           0 :                     $$ = $3;
   13196           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13197             :                 }
   13198             :             | TEMP opt_table qualified_name
   13199             :                 {
   13200           6 :                     $$ = $3;
   13201           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13202             :                 }
   13203             :             | LOCAL TEMPORARY opt_table qualified_name
   13204             :                 {
   13205           0 :                     $$ = $4;
   13206           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13207             :                 }
   13208             :             | LOCAL TEMP opt_table qualified_name
   13209             :                 {
   13210           0 :                     $$ = $4;
   13211           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13212             :                 }
   13213             :             | GLOBAL TEMPORARY opt_table qualified_name
   13214             :                 {
   13215           0 :                     ereport(WARNING,
   13216             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13217             :                              parser_errposition(@1)));
   13218           0 :                     $$ = $4;
   13219           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13220             :                 }
   13221             :             | GLOBAL TEMP opt_table qualified_name
   13222             :                 {
   13223           0 :                     ereport(WARNING,
   13224             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13225             :                              parser_errposition(@1)));
   13226           0 :                     $$ = $4;
   13227           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13228             :                 }
   13229             :             | UNLOGGED opt_table qualified_name
   13230             :                 {
   13231           0 :                     $$ = $3;
   13232           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13233             :                 }
   13234             :             | TABLE qualified_name
   13235             :                 {
   13236          30 :                     $$ = $2;
   13237          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13238             :                 }
   13239             :             | qualified_name
   13240             :                 {
   13241         102 :                     $$ = $1;
   13242         102 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13243             :                 }
   13244             :         ;
   13245             : 
   13246             : opt_table:  TABLE
   13247             :             | /*EMPTY*/
   13248             :         ;
   13249             : 
   13250             : set_quantifier:
   13251       10756 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13252          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13253       13148 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13254             :         ;
   13255             : 
   13256             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13257             :  * should be placed in the DISTINCT list during parsetree analysis.
   13258             :  */
   13259             : distinct_clause:
   13260        3406 :             DISTINCT                                { $$ = list_make1(NIL); }
   13261         260 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13262             :         ;
   13263             : 
   13264             : opt_all_clause:
   13265             :             ALL
   13266             :             | /*EMPTY*/
   13267             :         ;
   13268             : 
   13269             : opt_distinct_clause:
   13270           0 :             distinct_clause                         { $$ = $1; }
   13271       40390 :             | opt_all_clause                        { $$ = NIL; }
   13272             :         ;
   13273             : 
   13274             : opt_sort_clause:
   13275        7378 :             sort_clause                             { $$ = $1; }
   13276      361600 :             | /*EMPTY*/                             { $$ = NIL; }
   13277             :         ;
   13278             : 
   13279             : sort_clause:
   13280       78724 :             ORDER BY sortby_list                    { $$ = $3; }
   13281             :         ;
   13282             : 
   13283             : sortby_list:
   13284       78742 :             sortby                                  { $$ = list_make1($1); }
   13285       28634 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13286             :         ;
   13287             : 
   13288             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13289             :                 {
   13290         220 :                     $$ = makeNode(SortBy);
   13291         220 :                     $$->node = $1;
   13292         220 :                     $$->sortby_dir = SORTBY_USING;
   13293         220 :                     $$->sortby_nulls = $4;
   13294         220 :                     $$->useOp = $3;
   13295         220 :                     $$->location = @3;
   13296             :                 }
   13297             :             | a_expr opt_asc_desc opt_nulls_order
   13298             :                 {
   13299      107156 :                     $$ = makeNode(SortBy);
   13300      107156 :                     $$->node = $1;
   13301      107156 :                     $$->sortby_dir = $2;
   13302      107156 :                     $$->sortby_nulls = $3;
   13303      107156 :                     $$->useOp = NIL;
   13304      107156 :                     $$->location = -1;       /* no operator */
   13305             :                 }
   13306             :         ;
   13307             : 
   13308             : 
   13309             : select_limit:
   13310             :             limit_clause offset_clause
   13311             :                 {
   13312         172 :                     $$ = $1;
   13313         172 :                     ($$)->limitOffset = $2;
   13314         172 :                     ($$)->offsetLoc = @2;
   13315             :                 }
   13316             :             | offset_clause limit_clause
   13317             :                 {
   13318         222 :                     $$ = $2;
   13319         222 :                     ($$)->limitOffset = $1;
   13320         222 :                     ($$)->offsetLoc = @1;
   13321             :                 }
   13322             :             | limit_clause
   13323             :                 {
   13324        4308 :                     $$ = $1;
   13325             :                 }
   13326             :             | offset_clause
   13327             :                 {
   13328         450 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13329             : 
   13330         450 :                     n->limitOffset = $1;
   13331         450 :                     n->limitCount = NULL;
   13332         450 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13333         450 :                     n->offsetLoc = @1;
   13334         450 :                     n->countLoc = -1;
   13335         450 :                     n->optionLoc = -1;
   13336         450 :                     $$ = n;
   13337             :                 }
   13338             :         ;
   13339             : 
   13340             : opt_select_limit:
   13341         190 :             select_limit                        { $$ = $1; }
   13342       44980 :             | /* EMPTY */                       { $$ = NULL; }
   13343             :         ;
   13344             : 
   13345             : limit_clause:
   13346             :             LIMIT select_limit_value
   13347             :                 {
   13348        4606 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13349             : 
   13350        4606 :                     n->limitOffset = NULL;
   13351        4606 :                     n->limitCount = $2;
   13352        4606 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13353        4606 :                     n->offsetLoc = -1;
   13354        4606 :                     n->countLoc = @1;
   13355        4606 :                     n->optionLoc = -1;
   13356        4606 :                     $$ = n;
   13357             :                 }
   13358             :             | LIMIT select_limit_value ',' select_offset_value
   13359             :                 {
   13360             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13361           0 :                     ereport(ERROR,
   13362             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13363             :                              errmsg("LIMIT #,# syntax is not supported"),
   13364             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13365             :                              parser_errposition(@1)));
   13366             :                 }
   13367             :             /* SQL:2008 syntax */
   13368             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13369             :              * a separate production rather than an opt_ expression.  The fact
   13370             :              * that ONLY is fully reserved means that this way, we defer any
   13371             :              * decision about what rule reduces ROW or ROWS to the point where
   13372             :              * we can see the ONLY token in the lookahead slot.
   13373             :              */
   13374             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13375             :                 {
   13376          24 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13377             : 
   13378          24 :                     n->limitOffset = NULL;
   13379          24 :                     n->limitCount = $3;
   13380          24 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13381          24 :                     n->offsetLoc = -1;
   13382          24 :                     n->countLoc = @1;
   13383          24 :                     n->optionLoc = -1;
   13384          24 :                     $$ = n;
   13385             :                 }
   13386             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13387             :                 {
   13388          66 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13389             : 
   13390          66 :                     n->limitOffset = NULL;
   13391          66 :                     n->limitCount = $3;
   13392          66 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13393          66 :                     n->offsetLoc = -1;
   13394          66 :                     n->countLoc = @1;
   13395          66 :                     n->optionLoc = @5;
   13396          66 :                     $$ = n;
   13397             :                 }
   13398             :             | FETCH first_or_next row_or_rows ONLY
   13399             :                 {
   13400           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13401             : 
   13402           0 :                     n->limitOffset = NULL;
   13403           0 :                     n->limitCount = makeIntConst(1, -1);
   13404           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13405           0 :                     n->offsetLoc = -1;
   13406           0 :                     n->countLoc = @1;
   13407           0 :                     n->optionLoc = -1;
   13408           0 :                     $$ = n;
   13409             :                 }
   13410             :             | FETCH first_or_next row_or_rows WITH TIES
   13411             :                 {
   13412           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13413             : 
   13414           6 :                     n->limitOffset = NULL;
   13415           6 :                     n->limitCount = makeIntConst(1, -1);
   13416           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13417           6 :                     n->offsetLoc = -1;
   13418           6 :                     n->countLoc = @1;
   13419           6 :                     n->optionLoc = @4;
   13420           6 :                     $$ = n;
   13421             :                 }
   13422             :         ;
   13423             : 
   13424             : offset_clause:
   13425             :             OFFSET select_offset_value
   13426         844 :                 { $$ = $2; }
   13427             :             /* SQL:2008 syntax */
   13428             :             | OFFSET select_fetch_first_value row_or_rows
   13429           0 :                 { $$ = $2; }
   13430             :         ;
   13431             : 
   13432             : select_limit_value:
   13433        4604 :             a_expr                                  { $$ = $1; }
   13434             :             | ALL
   13435             :                 {
   13436             :                     /* LIMIT ALL is represented as a NULL constant */
   13437           2 :                     $$ = makeNullAConst(@1);
   13438             :                 }
   13439             :         ;
   13440             : 
   13441             : select_offset_value:
   13442         844 :             a_expr                                  { $$ = $1; }
   13443             :         ;
   13444             : 
   13445             : /*
   13446             :  * Allowing full expressions without parentheses causes various parsing
   13447             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13448             :  * <simple value specification>, which is either a literal or a parameter (but
   13449             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13450             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13451             :  * to determine whether the expression is missing rather than trying to make it
   13452             :  * optional in this rule.
   13453             :  *
   13454             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13455             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13456             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13457             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13458             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13459             :  * builds.)
   13460             :  */
   13461             : select_fetch_first_value:
   13462          90 :             c_expr                                  { $$ = $1; }
   13463             :             | '+' I_or_F_const
   13464           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13465             :             | '-' I_or_F_const
   13466           0 :                 { $$ = doNegate($2, @1); }
   13467             :         ;
   13468             : 
   13469             : I_or_F_const:
   13470           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13471           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13472             :         ;
   13473             : 
   13474             : /* noise words */
   13475          36 : row_or_rows: ROW                                    { $$ = 0; }
   13476          60 :             | ROWS                                  { $$ = 0; }
   13477             :         ;
   13478             : 
   13479          96 : first_or_next: FIRST_P                              { $$ = 0; }
   13480           0 :             | NEXT                                  { $$ = 0; }
   13481             :         ;
   13482             : 
   13483             : 
   13484             : /*
   13485             :  * This syntax for group_clause tries to follow the spec quite closely.
   13486             :  * However, the spec allows only column references, not expressions,
   13487             :  * which introduces an ambiguity between implicit row constructors
   13488             :  * (a,b) and lists of column references.
   13489             :  *
   13490             :  * We handle this by using the a_expr production for what the spec calls
   13491             :  * <ordinary grouping set>, which in the spec represents either one column
   13492             :  * reference or a parenthesized list of column references. Then, we check the
   13493             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13494             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13495             :  * not here)
   13496             :  *
   13497             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13498             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13499             :  * in a group clause, but if they have a reason to, we make it possible.)
   13500             :  *
   13501             :  * Each item in the group_clause list is either an expression tree or a
   13502             :  * GroupingSet node of some type.
   13503             :  */
   13504             : group_clause:
   13505             :             GROUP_P BY set_quantifier group_by_list
   13506             :                 {
   13507        4624 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13508             : 
   13509        4624 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13510        4624 :                     n->list = $4;
   13511        4624 :                     $$ = n;
   13512             :                 }
   13513             :             | /*EMPTY*/
   13514             :                 {
   13515      466470 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13516             : 
   13517      466466 :                     n->distinct = false;
   13518      466466 :                     n->list = NIL;
   13519      466466 :                     $$ = n;
   13520             :                 }
   13521             :         ;
   13522             : 
   13523             : group_by_list:
   13524        5222 :             group_by_item                           { $$ = list_make1($1); }
   13525        3026 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13526             :         ;
   13527             : 
   13528             : group_by_item:
   13529        6958 :             a_expr                                  { $$ = $1; }
   13530         222 :             | empty_grouping_set                    { $$ = $1; }
   13531         184 :             | cube_clause                           { $$ = $1; }
   13532         286 :             | rollup_clause                         { $$ = $1; }
   13533         598 :             | grouping_sets_clause                  { $$ = $1; }
   13534             :         ;
   13535             : 
   13536             : empty_grouping_set:
   13537             :             '(' ')'
   13538             :                 {
   13539         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13540             :                 }
   13541             :         ;
   13542             : 
   13543             : /*
   13544             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13545             :  * so that they shift in these rules rather than reducing the conflicting
   13546             :  * unreserved_keyword rule.
   13547             :  */
   13548             : 
   13549             : rollup_clause:
   13550             :             ROLLUP '(' expr_list ')'
   13551             :                 {
   13552         286 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13553             :                 }
   13554             :         ;
   13555             : 
   13556             : cube_clause:
   13557             :             CUBE '(' expr_list ')'
   13558             :                 {
   13559         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13560             :                 }
   13561             :         ;
   13562             : 
   13563             : grouping_sets_clause:
   13564             :             GROUPING SETS '(' group_by_list ')'
   13565             :                 {
   13566         598 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13567             :                 }
   13568             :         ;
   13569             : 
   13570             : having_clause:
   13571         678 :             HAVING a_expr                           { $$ = $2; }
   13572      470416 :             | /*EMPTY*/                             { $$ = NULL; }
   13573             :         ;
   13574             : 
   13575             : for_locking_clause:
   13576        5120 :             for_locking_items                       { $$ = $1; }
   13577           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13578             :         ;
   13579             : 
   13580             : opt_for_locking_clause:
   13581         340 :             for_locking_clause                      { $$ = $1; }
   13582       45012 :             | /* EMPTY */                           { $$ = NIL; }
   13583             :         ;
   13584             : 
   13585             : for_locking_items:
   13586        5120 :             for_locking_item                        { $$ = list_make1($1); }
   13587         102 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13588             :         ;
   13589             : 
   13590             : for_locking_item:
   13591             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13592             :                 {
   13593        5222 :                     LockingClause *n = makeNode(LockingClause);
   13594             : 
   13595        5222 :                     n->lockedRels = $2;
   13596        5222 :                     n->strength = $1;
   13597        5222 :                     n->waitPolicy = $3;
   13598        5222 :                     $$ = (Node *) n;
   13599             :                 }
   13600             :         ;
   13601             : 
   13602             : for_locking_strength:
   13603        1534 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13604          76 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13605         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13606        3398 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13607             :         ;
   13608             : 
   13609             : locked_rels_list:
   13610        3424 :             OF qualified_name_list                  { $$ = $2; }
   13611        1798 :             | /* EMPTY */                           { $$ = NIL; }
   13612             :         ;
   13613             : 
   13614             : 
   13615             : /*
   13616             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13617             :  * making VALUES a fully reserved word, which will probably break more apps
   13618             :  * than allowing the noise-word is worth.
   13619             :  */
   13620             : values_clause:
   13621             :             VALUES '(' expr_list ')'
   13622             :                 {
   13623       58988 :                     SelectStmt *n = makeNode(SelectStmt);
   13624             : 
   13625       58988 :                     n->valuesLists = list_make1($3);
   13626       58988 :                     $$ = (Node *) n;
   13627             :                 }
   13628             :             | values_clause ',' '(' expr_list ')'
   13629             :                 {
   13630       25116 :                     SelectStmt *n = (SelectStmt *) $1;
   13631             : 
   13632       25116 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13633       25116 :                     $$ = (Node *) n;
   13634             :                 }
   13635             :         ;
   13636             : 
   13637             : 
   13638             : /*****************************************************************************
   13639             :  *
   13640             :  *  clauses common to all Optimizable Stmts:
   13641             :  *      from_clause     - allow list of both JOIN expressions and table names
   13642             :  *      where_clause    - qualifications for joins or restrictions
   13643             :  *
   13644             :  *****************************************************************************/
   13645             : 
   13646             : from_clause:
   13647      313018 :             FROM from_list                          { $$ = $2; }
   13648      172214 :             | /*EMPTY*/                             { $$ = NIL; }
   13649             :         ;
   13650             : 
   13651             : from_list:
   13652      313862 :             table_ref                               { $$ = list_make1($1); }
   13653       61158 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13654             :         ;
   13655             : 
   13656             : /*
   13657             :  * table_ref is where an alias clause can be attached.
   13658             :  */
   13659             : table_ref:  relation_expr opt_alias_clause
   13660             :                 {
   13661      395768 :                     $1->alias = $2;
   13662      395768 :                     $$ = (Node *) $1;
   13663             :                 }
   13664             :             | relation_expr opt_alias_clause tablesample_clause
   13665             :                 {
   13666         266 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13667             : 
   13668         266 :                     $1->alias = $2;
   13669             :                     /* relation_expr goes inside the RangeTableSample node */
   13670         266 :                     n->relation = (Node *) $1;
   13671         266 :                     $$ = (Node *) n;
   13672             :                 }
   13673             :             | func_table func_alias_clause
   13674             :                 {
   13675       46368 :                     RangeFunction *n = (RangeFunction *) $1;
   13676             : 
   13677       46368 :                     n->alias = linitial($2);
   13678       46368 :                     n->coldeflist = lsecond($2);
   13679       46368 :                     $$ = (Node *) n;
   13680             :                 }
   13681             :             | LATERAL_P func_table func_alias_clause
   13682             :                 {
   13683        1162 :                     RangeFunction *n = (RangeFunction *) $2;
   13684             : 
   13685        1162 :                     n->lateral = true;
   13686        1162 :                     n->alias = linitial($3);
   13687        1162 :                     n->coldeflist = lsecond($3);
   13688        1162 :                     $$ = (Node *) n;
   13689             :                 }
   13690             :             | xmltable opt_alias_clause
   13691             :                 {
   13692          86 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13693             : 
   13694          86 :                     n->alias = $2;
   13695          86 :                     $$ = (Node *) n;
   13696             :                 }
   13697             :             | LATERAL_P xmltable opt_alias_clause
   13698             :                 {
   13699         140 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13700             : 
   13701         140 :                     n->lateral = true;
   13702         140 :                     n->alias = $3;
   13703         140 :                     $$ = (Node *) n;
   13704             :                 }
   13705             :             | select_with_parens opt_alias_clause
   13706             :                 {
   13707       14082 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13708             : 
   13709       14082 :                     n->lateral = false;
   13710       14082 :                     n->subquery = $1;
   13711       14082 :                     n->alias = $2;
   13712       14082 :                     $$ = (Node *) n;
   13713             :                 }
   13714             :             | LATERAL_P select_with_parens opt_alias_clause
   13715             :                 {
   13716        1898 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13717             : 
   13718        1898 :                     n->lateral = true;
   13719        1898 :                     n->subquery = $2;
   13720        1898 :                     n->alias = $3;
   13721        1898 :                     $$ = (Node *) n;
   13722             :                 }
   13723             :             | joined_table
   13724             :                 {
   13725       82946 :                     $$ = (Node *) $1;
   13726             :                 }
   13727             :             | '(' joined_table ')' alias_clause
   13728             :                 {
   13729         174 :                     $2->alias = $4;
   13730         174 :                     $$ = (Node *) $2;
   13731             :                 }
   13732             :             | json_table opt_alias_clause
   13733             :                 {
   13734         530 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13735             : 
   13736         530 :                     jt->alias = $2;
   13737         530 :                     $$ = (Node *) jt;
   13738             :                 }
   13739             :             | LATERAL_P json_table opt_alias_clause
   13740             :                 {
   13741           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13742             : 
   13743           0 :                     jt->alias = $3;
   13744           0 :                     jt->lateral = true;
   13745           0 :                     $$ = (Node *) jt;
   13746             :                 }
   13747             :         ;
   13748             : 
   13749             : 
   13750             : /*
   13751             :  * It may seem silly to separate joined_table from table_ref, but there is
   13752             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13753             :  * reduce conflicts, because it's not clear to the parser generator whether
   13754             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13755             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13756             :  * join_type to expand to empty; if we try it, the parser generator can't
   13757             :  * figure out when to reduce an empty join_type right after table_ref.
   13758             :  *
   13759             :  * Note that a CROSS JOIN is the same as an unqualified
   13760             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13761             :  * but a qualification expression to limit membership.
   13762             :  * A NATURAL JOIN implicitly matches column names between
   13763             :  * tables and the shape is determined by which columns are
   13764             :  * in common. We'll collect columns during the later transformations.
   13765             :  */
   13766             : 
   13767             : joined_table:
   13768             :             '(' joined_table ')'
   13769             :                 {
   13770        3962 :                     $$ = $2;
   13771             :                 }
   13772             :             | table_ref CROSS JOIN table_ref
   13773             :                 {
   13774             :                     /* CROSS JOIN is same as unqualified inner join */
   13775         506 :                     JoinExpr   *n = makeNode(JoinExpr);
   13776             : 
   13777         506 :                     n->jointype = JOIN_INNER;
   13778         506 :                     n->isNatural = false;
   13779         506 :                     n->larg = $1;
   13780         506 :                     n->rarg = $4;
   13781         506 :                     n->usingClause = NIL;
   13782         506 :                     n->join_using_alias = NULL;
   13783         506 :                     n->quals = NULL;
   13784         506 :                     $$ = n;
   13785             :                 }
   13786             :             | table_ref join_type JOIN table_ref join_qual
   13787             :                 {
   13788       47078 :                     JoinExpr   *n = makeNode(JoinExpr);
   13789             : 
   13790       47078 :                     n->jointype = $2;
   13791       47078 :                     n->isNatural = false;
   13792       47078 :                     n->larg = $1;
   13793       47078 :                     n->rarg = $4;
   13794       47078 :                     if ($5 != NULL && IsA($5, List))
   13795             :                     {
   13796             :                          /* USING clause */
   13797         498 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13798         498 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13799             :                     }
   13800             :                     else
   13801             :                     {
   13802             :                         /* ON clause */
   13803       46580 :                         n->quals = $5;
   13804             :                     }
   13805       47078 :                     $$ = n;
   13806             :                 }
   13807             :             | table_ref JOIN table_ref join_qual
   13808             :                 {
   13809             :                     /* letting join_type reduce to empty doesn't work */
   13810       35272 :                     JoinExpr   *n = makeNode(JoinExpr);
   13811             : 
   13812       35272 :                     n->jointype = JOIN_INNER;
   13813       35272 :                     n->isNatural = false;
   13814       35272 :                     n->larg = $1;
   13815       35272 :                     n->rarg = $3;
   13816       35272 :                     if ($4 != NULL && IsA($4, List))
   13817             :                     {
   13818             :                         /* USING clause */
   13819         744 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13820         744 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13821             :                     }
   13822             :                     else
   13823             :                     {
   13824             :                         /* ON clause */
   13825       34528 :                         n->quals = $4;
   13826             :                     }
   13827       35272 :                     $$ = n;
   13828             :                 }
   13829             :             | table_ref NATURAL join_type JOIN table_ref
   13830             :                 {
   13831          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13832             : 
   13833          78 :                     n->jointype = $3;
   13834          78 :                     n->isNatural = true;
   13835          78 :                     n->larg = $1;
   13836          78 :                     n->rarg = $5;
   13837          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13838          78 :                     n->join_using_alias = NULL;
   13839          78 :                     n->quals = NULL; /* fill later */
   13840          78 :                     $$ = n;
   13841             :                 }
   13842             :             | table_ref NATURAL JOIN table_ref
   13843             :                 {
   13844             :                     /* letting join_type reduce to empty doesn't work */
   13845         186 :                     JoinExpr   *n = makeNode(JoinExpr);
   13846             : 
   13847         186 :                     n->jointype = JOIN_INNER;
   13848         186 :                     n->isNatural = true;
   13849         186 :                     n->larg = $1;
   13850         186 :                     n->rarg = $4;
   13851         186 :                     n->usingClause = NIL; /* figure out which columns later... */
   13852         186 :                     n->join_using_alias = NULL;
   13853         186 :                     n->quals = NULL; /* fill later */
   13854         186 :                     $$ = n;
   13855             :                 }
   13856             :         ;
   13857             : 
   13858             : alias_clause:
   13859             :             AS ColId '(' name_list ')'
   13860             :                 {
   13861        6630 :                     $$ = makeNode(Alias);
   13862        6630 :                     $$->aliasname = $2;
   13863        6630 :                     $$->colnames = $4;
   13864             :                 }
   13865             :             | AS ColId
   13866             :                 {
   13867       10896 :                     $$ = makeNode(Alias);
   13868       10896 :                     $$->aliasname = $2;
   13869             :                 }
   13870             :             | ColId '(' name_list ')'
   13871             :                 {
   13872        5834 :                     $$ = makeNode(Alias);
   13873        5834 :                     $$->aliasname = $1;
   13874        5834 :                     $$->colnames = $3;
   13875             :                 }
   13876             :             | ColId
   13877             :                 {
   13878      262064 :                     $$ = makeNode(Alias);
   13879      262064 :                     $$->aliasname = $1;
   13880             :                 }
   13881             :         ;
   13882             : 
   13883      256676 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13884      156094 :             | /*EMPTY*/                             { $$ = NULL; }
   13885             :         ;
   13886             : 
   13887             : /*
   13888             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13889             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13890             :  * don't seem to be useful, and it might lead to parser problems in the
   13891             :  * future.)
   13892             :  */
   13893             : opt_alias_clause_for_join_using:
   13894             :             AS ColId
   13895             :                 {
   13896          84 :                     $$ = makeNode(Alias);
   13897          84 :                     $$->aliasname = $2;
   13898             :                     /* the column name list will be inserted later */
   13899             :                 }
   13900        1158 :             | /*EMPTY*/                             { $$ = NULL; }
   13901             :         ;
   13902             : 
   13903             : /*
   13904             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13905             :  * return a 2-element list that gets disassembled by calling production.
   13906             :  */
   13907             : func_alias_clause:
   13908             :             alias_clause
   13909             :                 {
   13910       28574 :                     $$ = list_make2($1, NIL);
   13911             :                 }
   13912             :             | AS '(' TableFuncElementList ')'
   13913             :                 {
   13914         114 :                     $$ = list_make2(NULL, $3);
   13915             :                 }
   13916             :             | AS ColId '(' TableFuncElementList ')'
   13917             :                 {
   13918         594 :                     Alias      *a = makeNode(Alias);
   13919             : 
   13920         594 :                     a->aliasname = $2;
   13921         594 :                     $$ = list_make2(a, $4);
   13922             :                 }
   13923             :             | ColId '(' TableFuncElementList ')'
   13924             :                 {
   13925          50 :                     Alias      *a = makeNode(Alias);
   13926             : 
   13927          50 :                     a->aliasname = $1;
   13928          50 :                     $$ = list_make2(a, $3);
   13929             :                 }
   13930             :             | /*EMPTY*/
   13931             :                 {
   13932       18198 :                     $$ = list_make2(NULL, NIL);
   13933             :                 }
   13934             :         ;
   13935             : 
   13936        1042 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13937       41774 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13938         378 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13939        3962 :             | INNER_P                               { $$ = JOIN_INNER; }
   13940             :         ;
   13941             : 
   13942             : /* OUTER is just noise... */
   13943             : opt_outer: OUTER_P
   13944             :             | /*EMPTY*/
   13945             :         ;
   13946             : 
   13947             : /* JOIN qualification clauses
   13948             :  * Possibilities are:
   13949             :  *  USING ( column list ) [ AS alias ]
   13950             :  *                        allows only unqualified column names,
   13951             :  *                        which must match between tables.
   13952             :  *  ON expr allows more general qualifications.
   13953             :  *
   13954             :  * We return USING as a two-element List (the first item being a sub-List
   13955             :  * of the common column names, and the second either an Alias item or NULL).
   13956             :  * An ON-expr will not be a List, so it can be told apart that way.
   13957             :  */
   13958             : 
   13959             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13960             :                 {
   13961        1242 :                     $$ = (Node *) list_make2($3, $5);
   13962             :                 }
   13963             :             | ON a_expr
   13964             :                 {
   13965       81108 :                     $$ = $2;
   13966             :                 }
   13967             :         ;
   13968             : 
   13969             : 
   13970             : relation_expr:
   13971             :             qualified_name
   13972             :                 {
   13973             :                     /* inheritance query, implicitly */
   13974      476696 :                     $$ = $1;
   13975      476696 :                     $$->inh = true;
   13976      476696 :                     $$->alias = NULL;
   13977             :                 }
   13978             :             | extended_relation_expr
   13979             :                 {
   13980        7162 :                     $$ = $1;
   13981             :                 }
   13982             :         ;
   13983             : 
   13984             : extended_relation_expr:
   13985             :             qualified_name '*'
   13986             :                 {
   13987             :                     /* inheritance query, explicitly */
   13988         204 :                     $$ = $1;
   13989         204 :                     $$->inh = true;
   13990         204 :                     $$->alias = NULL;
   13991             :                 }
   13992             :             | ONLY qualified_name
   13993             :                 {
   13994             :                     /* no inheritance */
   13995        6964 :                     $$ = $2;
   13996        6964 :                     $$->inh = false;
   13997        6964 :                     $$->alias = NULL;
   13998             :                 }
   13999             :             | ONLY '(' qualified_name ')'
   14000             :                 {
   14001             :                     /* no inheritance, SQL99-style syntax */
   14002           0 :                     $$ = $3;
   14003           0 :                     $$->inh = false;
   14004           0 :                     $$->alias = NULL;
   14005             :                 }
   14006             :         ;
   14007             : 
   14008             : 
   14009             : relation_expr_list:
   14010        2908 :             relation_expr                           { $$ = list_make1($1); }
   14011       11590 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   14012             :         ;
   14013             : 
   14014             : 
   14015             : /*
   14016             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   14017             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   14018             :  * keyword.  Since "set" is allowed as a column name both interpretations
   14019             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   14020             :  * relation_expr_opt_alias production a higher precedence than the SET token
   14021             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   14022             :  * SET is not an alias.
   14023             :  */
   14024             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   14025             :                 {
   14026       18622 :                     $$ = $1;
   14027             :                 }
   14028             :             | relation_expr ColId
   14029             :                 {
   14030        2250 :                     Alias      *alias = makeNode(Alias);
   14031             : 
   14032        2250 :                     alias->aliasname = $2;
   14033        2250 :                     $1->alias = alias;
   14034        2250 :                     $$ = $1;
   14035             :                 }
   14036             :             | relation_expr AS ColId
   14037             :                 {
   14038          90 :                     Alias      *alias = makeNode(Alias);
   14039             : 
   14040          90 :                     alias->aliasname = $3;
   14041          90 :                     $1->alias = alias;
   14042          90 :                     $$ = $1;
   14043             :                 }
   14044             :         ;
   14045             : 
   14046             : /*
   14047             :  * TABLESAMPLE decoration in a FROM item
   14048             :  */
   14049             : tablesample_clause:
   14050             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14051             :                 {
   14052         266 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14053             : 
   14054             :                     /* n->relation will be filled in later */
   14055         266 :                     n->method = $2;
   14056         266 :                     n->args = $4;
   14057         266 :                     n->repeatable = $6;
   14058         266 :                     n->location = @2;
   14059         266 :                     $$ = (Node *) n;
   14060             :                 }
   14061             :         ;
   14062             : 
   14063             : opt_repeatable_clause:
   14064         108 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14065         158 :             | /*EMPTY*/                 { $$ = NULL; }
   14066             :         ;
   14067             : 
   14068             : /*
   14069             :  * func_table represents a function invocation in a FROM list. It can be
   14070             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14071             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14072             :  * optionally with WITH ORDINALITY attached.
   14073             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14074             :  * function, for example:
   14075             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14076             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14077             :  * It's also possible to attach a column definition list to the RangeFunction
   14078             :  * as a whole, but that's handled by the table_ref production.
   14079             :  */
   14080             : func_table: func_expr_windowless opt_ordinality
   14081             :                 {
   14082       47404 :                     RangeFunction *n = makeNode(RangeFunction);
   14083             : 
   14084       47404 :                     n->lateral = false;
   14085       47404 :                     n->ordinality = $2;
   14086       47404 :                     n->is_rowsfrom = false;
   14087       47404 :                     n->functions = list_make1(list_make2($1, NIL));
   14088             :                     /* alias and coldeflist are set by table_ref production */
   14089       47404 :                     $$ = (Node *) n;
   14090             :                 }
   14091             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14092             :                 {
   14093         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14094             : 
   14095         132 :                     n->lateral = false;
   14096         132 :                     n->ordinality = $6;
   14097         132 :                     n->is_rowsfrom = true;
   14098         132 :                     n->functions = $4;
   14099             :                     /* alias and coldeflist are set by table_ref production */
   14100         132 :                     $$ = (Node *) n;
   14101             :                 }
   14102             :         ;
   14103             : 
   14104             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14105         318 :                 { $$ = list_make2($1, $2); }
   14106             :         ;
   14107             : 
   14108             : rowsfrom_list:
   14109         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14110         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14111             :         ;
   14112             : 
   14113          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14114         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14115             :         ;
   14116             : 
   14117         914 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14118       46622 :             | /*EMPTY*/                             { $$ = false; }
   14119             :         ;
   14120             : 
   14121             : 
   14122             : where_clause:
   14123      211014 :             WHERE a_expr                            { $$ = $2; }
   14124      281642 :             | /*EMPTY*/                             { $$ = NULL; }
   14125             :         ;
   14126             : 
   14127             : /* variant for UPDATE and DELETE */
   14128             : where_or_current_clause:
   14129       13456 :             WHERE a_expr                            { $$ = $2; }
   14130             :             | WHERE CURRENT_P OF cursor_name
   14131             :                 {
   14132         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14133             : 
   14134             :                     /* cvarno is filled in by parse analysis */
   14135         266 :                     n->cursor_name = $4;
   14136         266 :                     n->cursor_param = 0;
   14137         266 :                     $$ = (Node *) n;
   14138             :                 }
   14139        5068 :             | /*EMPTY*/                             { $$ = NULL; }
   14140             :         ;
   14141             : 
   14142             : 
   14143             : OptTableFuncElementList:
   14144         716 :             TableFuncElementList                { $$ = $1; }
   14145        3786 :             | /*EMPTY*/                         { $$ = NIL; }
   14146             :         ;
   14147             : 
   14148             : TableFuncElementList:
   14149             :             TableFuncElement
   14150             :                 {
   14151        1528 :                     $$ = list_make1($1);
   14152             :                 }
   14153             :             | TableFuncElementList ',' TableFuncElement
   14154             :                 {
   14155        2056 :                     $$ = lappend($1, $3);
   14156             :                 }
   14157             :         ;
   14158             : 
   14159             : TableFuncElement:   ColId Typename opt_collate_clause
   14160             :                 {
   14161        3648 :                     ColumnDef *n = makeNode(ColumnDef);
   14162             : 
   14163        3648 :                     n->colname = $1;
   14164        3648 :                     n->typeName = $2;
   14165        3648 :                     n->inhcount = 0;
   14166        3648 :                     n->is_local = true;
   14167        3648 :                     n->is_not_null = false;
   14168        3648 :                     n->is_from_type = false;
   14169        3648 :                     n->storage = 0;
   14170        3648 :                     n->raw_default = NULL;
   14171        3648 :                     n->cooked_default = NULL;
   14172        3648 :                     n->collClause = (CollateClause *) $3;
   14173        3648 :                     n->collOid = InvalidOid;
   14174        3648 :                     n->constraints = NIL;
   14175        3648 :                     n->location = @1;
   14176        3648 :                     $$ = (Node *) n;
   14177             :                 }
   14178             :         ;
   14179             : 
   14180             : /*
   14181             :  * XMLTABLE
   14182             :  */
   14183             : xmltable:
   14184             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14185             :                 {
   14186         206 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14187             : 
   14188         206 :                     n->rowexpr = $3;
   14189         206 :                     n->docexpr = $4;
   14190         206 :                     n->columns = $6;
   14191         206 :                     n->namespaces = NIL;
   14192         206 :                     n->location = @1;
   14193         206 :                     $$ = (Node *) n;
   14194             :                 }
   14195             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14196             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14197             :                 {
   14198          20 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14199             : 
   14200          20 :                     n->rowexpr = $8;
   14201          20 :                     n->docexpr = $9;
   14202          20 :                     n->columns = $11;
   14203          20 :                     n->namespaces = $5;
   14204          20 :                     n->location = @1;
   14205          20 :                     $$ = (Node *) n;
   14206             :                 }
   14207             :         ;
   14208             : 
   14209         226 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14210         530 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14211             :         ;
   14212             : 
   14213             : xmltable_column_el:
   14214             :             ColId Typename
   14215             :                 {
   14216         204 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14217             : 
   14218         204 :                     fc->colname = $1;
   14219         204 :                     fc->for_ordinality = false;
   14220         204 :                     fc->typeName = $2;
   14221         204 :                     fc->is_not_null = false;
   14222         204 :                     fc->colexpr = NULL;
   14223         204 :                     fc->coldefexpr = NULL;
   14224         204 :                     fc->location = @1;
   14225             : 
   14226         204 :                     $$ = (Node *) fc;
   14227             :                 }
   14228             :             | ColId Typename xmltable_column_option_list
   14229             :                 {
   14230         490 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14231             :                     ListCell   *option;
   14232         490 :                     bool        nullability_seen = false;
   14233             : 
   14234         490 :                     fc->colname = $1;
   14235         490 :                     fc->typeName = $2;
   14236         490 :                     fc->for_ordinality = false;
   14237         490 :                     fc->is_not_null = false;
   14238         490 :                     fc->colexpr = NULL;
   14239         490 :                     fc->coldefexpr = NULL;
   14240         490 :                     fc->location = @1;
   14241             : 
   14242        1092 :                     foreach(option, $3)
   14243             :                     {
   14244         602 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14245             : 
   14246         602 :                         if (strcmp(defel->defname, "default") == 0)
   14247             :                         {
   14248          56 :                             if (fc->coldefexpr != NULL)
   14249           0 :                                 ereport(ERROR,
   14250             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14251             :                                          errmsg("only one DEFAULT value is allowed"),
   14252             :                                          parser_errposition(defel->location)));
   14253          56 :                             fc->coldefexpr = defel->arg;
   14254             :                         }
   14255         546 :                         else if (strcmp(defel->defname, "path") == 0)
   14256             :                         {
   14257         490 :                             if (fc->colexpr != NULL)
   14258           0 :                                 ereport(ERROR,
   14259             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14260             :                                          errmsg("only one PATH value per column is allowed"),
   14261             :                                          parser_errposition(defel->location)));
   14262         490 :                             fc->colexpr = defel->arg;
   14263             :                         }
   14264          56 :                         else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
   14265             :                         {
   14266          56 :                             if (nullability_seen)
   14267           0 :                                 ereport(ERROR,
   14268             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14269             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14270             :                                          parser_errposition(defel->location)));
   14271          56 :                             fc->is_not_null = boolVal(defel->arg);
   14272          56 :                             nullability_seen = true;
   14273             :                         }
   14274             :                         else
   14275             :                         {
   14276           0 :                             ereport(ERROR,
   14277             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14278             :                                      errmsg("unrecognized column option \"%s\"",
   14279             :                                             defel->defname),
   14280             :                                      parser_errposition(defel->location)));
   14281             :                         }
   14282             :                     }
   14283         490 :                     $$ = (Node *) fc;
   14284             :                 }
   14285             :             | ColId FOR ORDINALITY
   14286             :                 {
   14287          62 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14288             : 
   14289          62 :                     fc->colname = $1;
   14290          62 :                     fc->for_ordinality = true;
   14291             :                     /* other fields are ignored, initialized by makeNode */
   14292          62 :                     fc->location = @1;
   14293             : 
   14294          62 :                     $$ = (Node *) fc;
   14295             :                 }
   14296             :         ;
   14297             : 
   14298             : xmltable_column_option_list:
   14299             :             xmltable_column_option_el
   14300         490 :                 { $$ = list_make1($1); }
   14301             :             | xmltable_column_option_list xmltable_column_option_el
   14302         112 :                 { $$ = lappend($1, $2); }
   14303             :         ;
   14304             : 
   14305             : xmltable_column_option_el:
   14306             :             IDENT b_expr
   14307             :                 {
   14308           6 :                     if (strcmp($1, "__pg__is_not_null") == 0)
   14309           6 :                         ereport(ERROR,
   14310             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14311             :                                  errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
   14312             :                                  parser_errposition(@1)));
   14313           0 :                     $$ = makeDefElem($1, $2, @1);
   14314             :                 }
   14315             :             | DEFAULT b_expr
   14316          56 :                 { $$ = makeDefElem("default", $2, @1); }
   14317             :             | NOT NULL_P
   14318          56 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
   14319             :             | NULL_P
   14320           0 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
   14321             :             | PATH b_expr
   14322         490 :                 { $$ = makeDefElem("path", $2, @1); }
   14323             :         ;
   14324             : 
   14325             : xml_namespace_list:
   14326             :             xml_namespace_el
   14327          20 :                 { $$ = list_make1($1); }
   14328             :             | xml_namespace_list ',' xml_namespace_el
   14329           0 :                 { $$ = lappend($1, $3); }
   14330             :         ;
   14331             : 
   14332             : xml_namespace_el:
   14333             :             b_expr AS ColLabel
   14334             :                 {
   14335          14 :                     $$ = makeNode(ResTarget);
   14336          14 :                     $$->name = $3;
   14337          14 :                     $$->indirection = NIL;
   14338          14 :                     $$->val = $1;
   14339          14 :                     $$->location = @1;
   14340             :                 }
   14341             :             | DEFAULT b_expr
   14342             :                 {
   14343           6 :                     $$ = makeNode(ResTarget);
   14344           6 :                     $$->name = NULL;
   14345           6 :                     $$->indirection = NIL;
   14346           6 :                     $$->val = $2;
   14347           6 :                     $$->location = @1;
   14348             :                 }
   14349             :         ;
   14350             : 
   14351             : json_table:
   14352             :             JSON_TABLE '('
   14353             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14354             :                 json_passing_clause_opt
   14355             :                 COLUMNS '(' json_table_column_definition_list ')'
   14356             :                 json_on_error_clause_opt
   14357             :             ')'
   14358             :                 {
   14359         536 :                     JsonTable *n = makeNode(JsonTable);
   14360             :                     char      *pathstring;
   14361             : 
   14362         536 :                     n->context_item = (JsonValueExpr *) $3;
   14363         536 :                     if (!IsA($5, A_Const) ||
   14364         530 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14365           6 :                         ereport(ERROR,
   14366             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14367             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14368             :                                 parser_errposition(@5));
   14369         530 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14370         530 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14371         530 :                     n->passing = $7;
   14372         530 :                     n->columns = $10;
   14373         530 :                     n->on_error = (JsonBehavior *) $12;
   14374         530 :                     n->location = @1;
   14375         530 :                     $$ = (Node *) n;
   14376             :                 }
   14377             :         ;
   14378             : 
   14379             : json_table_path_name_opt:
   14380          62 :             AS name         { $$ = $2; }
   14381         486 :             | /* empty */   { $$ = NULL; }
   14382             :         ;
   14383             : 
   14384             : json_table_column_definition_list:
   14385             :             json_table_column_definition
   14386         826 :                 { $$ = list_make1($1); }
   14387             :             | json_table_column_definition_list ',' json_table_column_definition
   14388         528 :                 { $$ = lappend($1, $3); }
   14389             :         ;
   14390             : 
   14391             : json_table_column_definition:
   14392             :             ColId FOR ORDINALITY
   14393             :                 {
   14394          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14395             : 
   14396          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14397          84 :                     n->name = $1;
   14398          84 :                     n->location = @1;
   14399          84 :                     $$ = (Node *) n;
   14400             :                 }
   14401             :             | ColId Typename
   14402             :                 json_table_column_path_clause_opt
   14403             :                 json_wrapper_behavior
   14404             :                 json_quotes_clause_opt
   14405             :                 json_behavior_clause_opt
   14406             :                 {
   14407         734 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14408             : 
   14409         734 :                     n->coltype = JTC_REGULAR;
   14410         734 :                     n->name = $1;
   14411         734 :                     n->typeName = $2;
   14412         734 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14413         734 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14414         734 :                     n->wrapper = $4;
   14415         734 :                     n->quotes = $5;
   14416         734 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14417         734 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14418         734 :                     n->location = @1;
   14419         734 :                     $$ = (Node *) n;
   14420             :                 }
   14421             :             | ColId Typename json_format_clause
   14422             :                 json_table_column_path_clause_opt
   14423             :                 json_wrapper_behavior
   14424             :                 json_quotes_clause_opt
   14425             :                 json_behavior_clause_opt
   14426             :                 {
   14427         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14428             : 
   14429         108 :                     n->coltype = JTC_FORMATTED;
   14430         108 :                     n->name = $1;
   14431         108 :                     n->typeName = $2;
   14432         108 :                     n->format = (JsonFormat *) $3;
   14433         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14434         108 :                     n->wrapper = $5;
   14435         108 :                     n->quotes = $6;
   14436         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14437         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14438         108 :                     n->location = @1;
   14439         108 :                     $$ = (Node *) n;
   14440             :                 }
   14441             :             | ColId Typename
   14442             :                 EXISTS json_table_column_path_clause_opt
   14443             :                 json_on_error_clause_opt
   14444             :                 {
   14445         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14446             : 
   14447         138 :                     n->coltype = JTC_EXISTS;
   14448         138 :                     n->name = $1;
   14449         138 :                     n->typeName = $2;
   14450         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14451         138 :                     n->wrapper = JSW_NONE;
   14452         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14453         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14454         138 :                     n->on_empty = NULL;
   14455         138 :                     n->on_error = (JsonBehavior *) $5;
   14456         138 :                     n->location = @1;
   14457         138 :                     $$ = (Node *) n;
   14458             :                 }
   14459             :             | NESTED path_opt Sconst
   14460             :                 COLUMNS '(' json_table_column_definition_list ')'
   14461             :                 {
   14462         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14463             : 
   14464         144 :                     n->coltype = JTC_NESTED;
   14465         288 :                     n->pathspec = (JsonTablePathSpec *)
   14466         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14467         144 :                     n->columns = $6;
   14468         144 :                     n->location = @1;
   14469         144 :                     $$ = (Node *) n;
   14470             :                 }
   14471             :             | NESTED path_opt Sconst AS name
   14472             :                 COLUMNS '(' json_table_column_definition_list ')'
   14473             :                 {
   14474         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14475             : 
   14476         146 :                     n->coltype = JTC_NESTED;
   14477         292 :                     n->pathspec = (JsonTablePathSpec *)
   14478         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14479         146 :                     n->columns = $8;
   14480         146 :                     n->location = @1;
   14481         146 :                     $$ = (Node *) n;
   14482             :                 }
   14483             :         ;
   14484             : 
   14485             : path_opt:
   14486             :             PATH
   14487             :             | /* EMPTY */
   14488             :         ;
   14489             : 
   14490             : json_table_column_path_clause_opt:
   14491             :             PATH Sconst
   14492         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14493             :             | /* EMPTY */
   14494         158 :                 { $$ = NULL; }
   14495             :         ;
   14496             : 
   14497             : /*****************************************************************************
   14498             :  *
   14499             :  *  Type syntax
   14500             :  *      SQL introduces a large amount of type-specific syntax.
   14501             :  *      Define individual clauses to handle these cases, and use
   14502             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14503             :  *      - thomas 1997-10-10
   14504             :  *
   14505             :  *****************************************************************************/
   14506             : 
   14507             : Typename:   SimpleTypename opt_array_bounds
   14508             :                 {
   14509      518506 :                     $$ = $1;
   14510      518506 :                     $$->arrayBounds = $2;
   14511             :                 }
   14512             :             | SETOF SimpleTypename opt_array_bounds
   14513             :                 {
   14514        2356 :                     $$ = $2;
   14515        2356 :                     $$->arrayBounds = $3;
   14516        2356 :                     $$->setof = true;
   14517             :                 }
   14518             :             /* SQL standard syntax, currently only one-dimensional */
   14519             :             | SimpleTypename ARRAY '[' Iconst ']'
   14520             :                 {
   14521           6 :                     $$ = $1;
   14522           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14523             :                 }
   14524             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14525             :                 {
   14526           0 :                     $$ = $2;
   14527           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14528           0 :                     $$->setof = true;
   14529             :                 }
   14530             :             | SimpleTypename ARRAY
   14531             :                 {
   14532           0 :                     $$ = $1;
   14533           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14534             :                 }
   14535             :             | SETOF SimpleTypename ARRAY
   14536             :                 {
   14537           0 :                     $$ = $2;
   14538           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14539           0 :                     $$->setof = true;
   14540             :                 }
   14541             :         ;
   14542             : 
   14543             : opt_array_bounds:
   14544             :             opt_array_bounds '[' ']'
   14545       14486 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14546             :             | opt_array_bounds '[' Iconst ']'
   14547          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14548             :             | /*EMPTY*/
   14549      520862 :                     {  $$ = NIL; }
   14550             :         ;
   14551             : 
   14552             : SimpleTypename:
   14553      408044 :             GenericType                             { $$ = $1; }
   14554       97172 :             | Numeric                               { $$ = $1; }
   14555        1972 :             | Bit                                   { $$ = $1; }
   14556        3014 :             | Character                             { $$ = $1; }
   14557        5318 :             | ConstDatetime                         { $$ = $1; }
   14558             :             | ConstInterval opt_interval
   14559             :                 {
   14560        3866 :                     $$ = $1;
   14561        3866 :                     $$->typmods = $2;
   14562             :                 }
   14563             :             | ConstInterval '(' Iconst ')'
   14564             :                 {
   14565           0 :                     $$ = $1;
   14566           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14567             :                                              makeIntConst($3, @3));
   14568             :                 }
   14569        1890 :             | JsonType                              { $$ = $1; }
   14570             :         ;
   14571             : 
   14572             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14573             :  * types such as CHAR() and BIT() to an unspecified length.
   14574             :  * SQL9x requires that these default to a length of one, but this
   14575             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14576             :  * where there is an obvious better choice to make.
   14577             :  * Note that ConstInterval is not included here since it must
   14578             :  * be pushed up higher in the rules to accommodate the postfix
   14579             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14580             :  * the generic-type-name case in AexprConst to avoid premature
   14581             :  * reduce/reduce conflicts against function names.
   14582             :  */
   14583             : ConstTypename:
   14584          78 :             Numeric                                 { $$ = $1; }
   14585           0 :             | ConstBit                              { $$ = $1; }
   14586          34 :             | ConstCharacter                        { $$ = $1; }
   14587        2798 :             | ConstDatetime                         { $$ = $1; }
   14588         264 :             | JsonType                              { $$ = $1; }
   14589             :         ;
   14590             : 
   14591             : /*
   14592             :  * GenericType covers all type names that don't have special syntax mandated
   14593             :  * by the standard, including qualified names.  We also allow type modifiers.
   14594             :  * To avoid parsing conflicts against function invocations, the modifiers
   14595             :  * have to be shown as expr_list here, but parse analysis will only accept
   14596             :  * constants for them.
   14597             :  */
   14598             : GenericType:
   14599             :             type_function_name opt_type_modifiers
   14600             :                 {
   14601      291804 :                     $$ = makeTypeName($1);
   14602      291804 :                     $$->typmods = $2;
   14603      291804 :                     $$->location = @1;
   14604             :                 }
   14605             :             | type_function_name attrs opt_type_modifiers
   14606             :                 {
   14607      116240 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14608      116240 :                     $$->typmods = $3;
   14609      116240 :                     $$->location = @1;
   14610             :                 }
   14611             :         ;
   14612             : 
   14613        1350 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14614      412890 :                     | /* EMPTY */                   { $$ = NIL; }
   14615             :         ;
   14616             : 
   14617             : /*
   14618             :  * SQL numeric data types
   14619             :  */
   14620             : Numeric:    INT_P
   14621             :                 {
   14622       38662 :                     $$ = SystemTypeName("int4");
   14623       38662 :                     $$->location = @1;
   14624             :                 }
   14625             :             | INTEGER
   14626             :                 {
   14627       24974 :                     $$ = SystemTypeName("int4");
   14628       24974 :                     $$->location = @1;
   14629             :                 }
   14630             :             | SMALLINT
   14631             :                 {
   14632        1422 :                     $$ = SystemTypeName("int2");
   14633        1422 :                     $$->location = @1;
   14634             :                 }
   14635             :             | BIGINT
   14636             :                 {
   14637        5106 :                     $$ = SystemTypeName("int8");
   14638        5106 :                     $$->location = @1;
   14639             :                 }
   14640             :             | REAL
   14641             :                 {
   14642        6928 :                     $$ = SystemTypeName("float4");
   14643        6928 :                     $$->location = @1;
   14644             :                 }
   14645             :             | FLOAT_P opt_float
   14646             :                 {
   14647         538 :                     $$ = $2;
   14648         538 :                     $$->location = @1;
   14649             :                 }
   14650             :             | DOUBLE_P PRECISION
   14651             :                 {
   14652         766 :                     $$ = SystemTypeName("float8");
   14653         766 :                     $$->location = @1;
   14654             :                 }
   14655             :             | DECIMAL_P opt_type_modifiers
   14656             :                 {
   14657          36 :                     $$ = SystemTypeName("numeric");
   14658          36 :                     $$->typmods = $2;
   14659          36 :                     $$->location = @1;
   14660             :                 }
   14661             :             | DEC opt_type_modifiers
   14662             :                 {
   14663           0 :                     $$ = SystemTypeName("numeric");
   14664           0 :                     $$->typmods = $2;
   14665           0 :                     $$->location = @1;
   14666             :                 }
   14667             :             | NUMERIC opt_type_modifiers
   14668             :                 {
   14669        6160 :                     $$ = SystemTypeName("numeric");
   14670        6160 :                     $$->typmods = $2;
   14671        6160 :                     $$->location = @1;
   14672             :                 }
   14673             :             | BOOLEAN_P
   14674             :                 {
   14675       12658 :                     $$ = SystemTypeName("bool");
   14676       12658 :                     $$->location = @1;
   14677             :                 }
   14678             :         ;
   14679             : 
   14680             : opt_float:  '(' Iconst ')'
   14681             :                 {
   14682             :                     /*
   14683             :                      * Check FLOAT() precision limits assuming IEEE floating
   14684             :                      * types - thomas 1997-09-18
   14685             :                      */
   14686           2 :                     if ($2 < 1)
   14687           0 :                         ereport(ERROR,
   14688             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14689             :                                  errmsg("precision for type float must be at least 1 bit"),
   14690             :                                  parser_errposition(@2)));
   14691           2 :                     else if ($2 <= 24)
   14692           2 :                         $$ = SystemTypeName("float4");
   14693           0 :                     else if ($2 <= 53)
   14694           0 :                         $$ = SystemTypeName("float8");
   14695             :                     else
   14696           0 :                         ereport(ERROR,
   14697             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14698             :                                  errmsg("precision for type float must be less than 54 bits"),
   14699             :                                  parser_errposition(@2)));
   14700             :                 }
   14701             :             | /*EMPTY*/
   14702             :                 {
   14703         536 :                     $$ = SystemTypeName("float8");
   14704             :                 }
   14705             :         ;
   14706             : 
   14707             : /*
   14708             :  * SQL bit-field data types
   14709             :  * The following implements BIT() and BIT VARYING().
   14710             :  */
   14711             : Bit:        BitWithLength
   14712             :                 {
   14713        1696 :                     $$ = $1;
   14714             :                 }
   14715             :             | BitWithoutLength
   14716             :                 {
   14717         276 :                     $$ = $1;
   14718             :                 }
   14719             :         ;
   14720             : 
   14721             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14722             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14723             : ConstBit:   BitWithLength
   14724             :                 {
   14725           0 :                     $$ = $1;
   14726             :                 }
   14727             :             | BitWithoutLength
   14728             :                 {
   14729           0 :                     $$ = $1;
   14730           0 :                     $$->typmods = NIL;
   14731             :                 }
   14732             :         ;
   14733             : 
   14734             : BitWithLength:
   14735             :             BIT opt_varying '(' expr_list ')'
   14736             :                 {
   14737             :                     char *typname;
   14738             : 
   14739        1696 :                     typname = $2 ? "varbit" : "bit";
   14740        1696 :                     $$ = SystemTypeName(typname);
   14741        1696 :                     $$->typmods = $4;
   14742        1696 :                     $$->location = @1;
   14743             :                 }
   14744             :         ;
   14745             : 
   14746             : BitWithoutLength:
   14747             :             BIT opt_varying
   14748             :                 {
   14749             :                     /* bit defaults to bit(1), varbit to no limit */
   14750         276 :                     if ($2)
   14751             :                     {
   14752          20 :                         $$ = SystemTypeName("varbit");
   14753             :                     }
   14754             :                     else
   14755             :                     {
   14756         256 :                         $$ = SystemTypeName("bit");
   14757         256 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14758             :                     }
   14759         276 :                     $$->location = @1;
   14760             :                 }
   14761             :         ;
   14762             : 
   14763             : 
   14764             : /*
   14765             :  * SQL character data types
   14766             :  * The following implements CHAR() and VARCHAR().
   14767             :  */
   14768             : Character:  CharacterWithLength
   14769             :                 {
   14770        1724 :                     $$ = $1;
   14771             :                 }
   14772             :             | CharacterWithoutLength
   14773             :                 {
   14774        1290 :                     $$ = $1;
   14775             :                 }
   14776             :         ;
   14777             : 
   14778             : ConstCharacter:  CharacterWithLength
   14779             :                 {
   14780          12 :                     $$ = $1;
   14781             :                 }
   14782             :             | CharacterWithoutLength
   14783             :                 {
   14784             :                     /* Length was not specified so allow to be unrestricted.
   14785             :                      * This handles problems with fixed-length (bpchar) strings
   14786             :                      * which in column definitions must default to a length
   14787             :                      * of one, but should not be constrained if the length
   14788             :                      * was not specified.
   14789             :                      */
   14790          22 :                     $$ = $1;
   14791          22 :                     $$->typmods = NIL;
   14792             :                 }
   14793             :         ;
   14794             : 
   14795             : CharacterWithLength:  character '(' Iconst ')'
   14796             :                 {
   14797        1736 :                     $$ = SystemTypeName($1);
   14798        1736 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14799        1736 :                     $$->location = @1;
   14800             :                 }
   14801             :         ;
   14802             : 
   14803             : CharacterWithoutLength:  character
   14804             :                 {
   14805        1312 :                     $$ = SystemTypeName($1);
   14806             :                     /* char defaults to char(1), varchar to no limit */
   14807        1312 :                     if (strcmp($1, "bpchar") == 0)
   14808         256 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14809        1312 :                     $$->location = @1;
   14810             :                 }
   14811             :         ;
   14812             : 
   14813             : character:  CHARACTER opt_varying
   14814         566 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14815             :             | CHAR_P opt_varying
   14816        1172 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14817             :             | VARCHAR
   14818        1306 :                                         { $$ = "varchar"; }
   14819             :             | NATIONAL CHARACTER opt_varying
   14820           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14821             :             | NATIONAL CHAR_P opt_varying
   14822           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14823             :             | NCHAR opt_varying
   14824           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14825             :         ;
   14826             : 
   14827             : opt_varying:
   14828         458 :             VARYING                                 { $$ = true; }
   14829        3256 :             | /*EMPTY*/                             { $$ = false; }
   14830             :         ;
   14831             : 
   14832             : /*
   14833             :  * SQL date/time types
   14834             :  */
   14835             : ConstDatetime:
   14836             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14837             :                 {
   14838         134 :                     if ($5)
   14839         110 :                         $$ = SystemTypeName("timestamptz");
   14840             :                     else
   14841          24 :                         $$ = SystemTypeName("timestamp");
   14842         134 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14843         134 :                     $$->location = @1;
   14844             :                 }
   14845             :             | TIMESTAMP opt_timezone
   14846             :                 {
   14847        5368 :                     if ($2)
   14848        1456 :                         $$ = SystemTypeName("timestamptz");
   14849             :                     else
   14850        3912 :                         $$ = SystemTypeName("timestamp");
   14851        5368 :                     $$->location = @1;
   14852             :                 }
   14853             :             | TIME '(' Iconst ')' opt_timezone
   14854             :                 {
   14855          22 :                     if ($5)
   14856           8 :                         $$ = SystemTypeName("timetz");
   14857             :                     else
   14858          14 :                         $$ = SystemTypeName("time");
   14859          22 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14860          22 :                     $$->location = @1;
   14861             :                 }
   14862             :             | TIME opt_timezone
   14863             :                 {
   14864        2592 :                     if ($2)
   14865         348 :                         $$ = SystemTypeName("timetz");
   14866             :                     else
   14867        2244 :                         $$ = SystemTypeName("time");
   14868        2592 :                     $$->location = @1;
   14869             :                 }
   14870             :         ;
   14871             : 
   14872             : ConstInterval:
   14873             :             INTERVAL
   14874             :                 {
   14875        7176 :                     $$ = SystemTypeName("interval");
   14876        7176 :                     $$->location = @1;
   14877             :                 }
   14878             :         ;
   14879             : 
   14880             : opt_timezone:
   14881        1922 :             WITH_LA TIME ZONE                       { $$ = true; }
   14882         624 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14883        5570 :             | /*EMPTY*/                             { $$ = false; }
   14884             :         ;
   14885             : 
   14886             : opt_interval:
   14887             :             YEAR_P
   14888          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14889             :             | MONTH_P
   14890          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14891             :             | DAY_P
   14892          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14893             :             | HOUR_P
   14894          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14895             :             | MINUTE_P
   14896          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14897             :             | interval_second
   14898          36 :                 { $$ = $1; }
   14899             :             | YEAR_P TO MONTH_P
   14900             :                 {
   14901          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14902             :                                                  INTERVAL_MASK(MONTH), @1));
   14903             :                 }
   14904             :             | DAY_P TO HOUR_P
   14905             :                 {
   14906          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14907             :                                                  INTERVAL_MASK(HOUR), @1));
   14908             :                 }
   14909             :             | DAY_P TO MINUTE_P
   14910             :                 {
   14911          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14912             :                                                  INTERVAL_MASK(HOUR) |
   14913             :                                                  INTERVAL_MASK(MINUTE), @1));
   14914             :                 }
   14915             :             | DAY_P TO interval_second
   14916             :                 {
   14917          48 :                     $$ = $3;
   14918          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14919             :                                                 INTERVAL_MASK(HOUR) |
   14920             :                                                 INTERVAL_MASK(MINUTE) |
   14921          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14922             :                 }
   14923             :             | HOUR_P TO MINUTE_P
   14924             :                 {
   14925          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14926             :                                                  INTERVAL_MASK(MINUTE), @1));
   14927             :                 }
   14928             :             | HOUR_P TO interval_second
   14929             :                 {
   14930          36 :                     $$ = $3;
   14931          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14932             :                                                 INTERVAL_MASK(MINUTE) |
   14933          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14934             :                 }
   14935             :             | MINUTE_P TO interval_second
   14936             :                 {
   14937          66 :                     $$ = $3;
   14938          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14939          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14940             :                 }
   14941             :             | /*EMPTY*/
   14942        6822 :                 { $$ = NIL; }
   14943             :         ;
   14944             : 
   14945             : interval_second:
   14946             :             SECOND_P
   14947             :                 {
   14948         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14949             :                 }
   14950             :             | SECOND_P '(' Iconst ')'
   14951             :                 {
   14952          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14953             :                                     makeIntConst($3, @3));
   14954             :                 }
   14955             :         ;
   14956             : 
   14957             : JsonType:
   14958             :             JSON
   14959             :                 {
   14960        2154 :                     $$ = SystemTypeName("json");
   14961        2154 :                     $$->location = @1;
   14962             :                 }
   14963             :         ;
   14964             : 
   14965             : /*****************************************************************************
   14966             :  *
   14967             :  *  expression grammar
   14968             :  *
   14969             :  *****************************************************************************/
   14970             : 
   14971             : /*
   14972             :  * General expressions
   14973             :  * This is the heart of the expression syntax.
   14974             :  *
   14975             :  * We have two expression types: a_expr is the unrestricted kind, and
   14976             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14977             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14978             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14979             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14980             :  *
   14981             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14982             :  * always be used by surrounding it with parens.
   14983             :  *
   14984             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14985             :  * it's factored out just to eliminate redundant coding.
   14986             :  *
   14987             :  * Be careful of productions involving more than one terminal token.
   14988             :  * By default, bison will assign such productions the precedence of their
   14989             :  * last terminal, but in nearly all cases you want it to be the precedence
   14990             :  * of the first terminal instead; otherwise you will not get the behavior
   14991             :  * you expect!  So we use %prec annotations freely to set precedences.
   14992             :  */
   14993     3646374 : a_expr:     c_expr                                  { $$ = $1; }
   14994             :             | a_expr TYPECAST Typename
   14995      233878 :                     { $$ = makeTypeCast($1, $3, @2); }
   14996             :             | a_expr COLLATE any_name
   14997             :                 {
   14998        9020 :                     CollateClause *n = makeNode(CollateClause);
   14999             : 
   15000        9020 :                     n->arg = $1;
   15001        9020 :                     n->collname = $3;
   15002        9020 :                     n->location = @2;
   15003        9020 :                     $$ = (Node *) n;
   15004             :                 }
   15005             :             | a_expr AT TIME ZONE a_expr            %prec AT
   15006             :                 {
   15007         408 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15008         408 :                                                list_make2($5, $1),
   15009             :                                                COERCE_SQL_SYNTAX,
   15010         408 :                                                @2);
   15011             :                 }
   15012             :             | a_expr AT LOCAL                       %prec AT
   15013             :                 {
   15014          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15015          42 :                                                list_make1($1),
   15016             :                                                COERCE_SQL_SYNTAX,
   15017             :                                                -1);
   15018             :                 }
   15019             :         /*
   15020             :          * These operators must be called out explicitly in order to make use
   15021             :          * of bison's automatic operator-precedence handling.  All other
   15022             :          * operator names are handled by the generic productions using "Op",
   15023             :          * below; and all those operators will have the same precedence.
   15024             :          *
   15025             :          * If you add more explicitly-known operators, be sure to add them
   15026             :          * also to b_expr and to the MathOp list below.
   15027             :          */
   15028             :             | '+' a_expr                    %prec UMINUS
   15029          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15030             :             | '-' a_expr                    %prec UMINUS
   15031        9186 :                 { $$ = doNegate($2, @1); }
   15032             :             | a_expr '+' a_expr
   15033       14192 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15034             :             | a_expr '-' a_expr
   15035        4530 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15036             :             | a_expr '*' a_expr
   15037        6330 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15038             :             | a_expr '/' a_expr
   15039        3442 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15040             :             | a_expr '%' a_expr
   15041        2862 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15042             :             | a_expr '^' a_expr
   15043         476 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15044             :             | a_expr '<' a_expr
   15045       10596 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15046             :             | a_expr '>' a_expr
   15047       16600 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15048             :             | a_expr '=' a_expr
   15049      388388 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15050             :             | a_expr LESS_EQUALS a_expr
   15051        5532 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15052             :             | a_expr GREATER_EQUALS a_expr
   15053        7136 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15054             :             | a_expr NOT_EQUALS a_expr
   15055       39674 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15056             : 
   15057             :             | a_expr qual_Op a_expr             %prec Op
   15058       58778 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15059             :             | qual_Op a_expr                    %prec Op
   15060         228 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15061             : 
   15062             :             | a_expr AND a_expr
   15063      232330 :                 { $$ = makeAndExpr($1, $3, @2); }
   15064             :             | a_expr OR a_expr
   15065       16002 :                 { $$ = makeOrExpr($1, $3, @2); }
   15066             :             | NOT a_expr
   15067       16042 :                 { $$ = makeNotExpr($2, @1); }
   15068             :             | NOT_LA a_expr                     %prec NOT
   15069           0 :                 { $$ = makeNotExpr($2, @1); }
   15070             : 
   15071             :             | a_expr LIKE a_expr
   15072             :                 {
   15073        1964 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15074        1964 :                                                    $1, $3, @2);
   15075             :                 }
   15076             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15077             :                 {
   15078          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15079          96 :                                                  list_make2($3, $5),
   15080             :                                                  COERCE_EXPLICIT_CALL,
   15081          96 :                                                  @2);
   15082          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15083          96 :                                                    $1, (Node *) n, @2);
   15084             :                 }
   15085             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15086             :                 {
   15087         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15088         198 :                                                    $1, $4, @2);
   15089             :                 }
   15090             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15091             :                 {
   15092          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15093          96 :                                                  list_make2($4, $6),
   15094             :                                                  COERCE_EXPLICIT_CALL,
   15095          96 :                                                  @2);
   15096          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15097          96 :                                                    $1, (Node *) n, @2);
   15098             :                 }
   15099             :             | a_expr ILIKE a_expr
   15100             :                 {
   15101         170 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15102         170 :                                                    $1, $3, @2);
   15103             :                 }
   15104             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15105             :                 {
   15106           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15107           0 :                                                  list_make2($3, $5),
   15108             :                                                  COERCE_EXPLICIT_CALL,
   15109           0 :                                                  @2);
   15110           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15111           0 :                                                    $1, (Node *) n, @2);
   15112             :                 }
   15113             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15114             :                 {
   15115          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15116          30 :                                                    $1, $4, @2);
   15117             :                 }
   15118             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15119             :                 {
   15120           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15121           0 :                                                  list_make2($4, $6),
   15122             :                                                  COERCE_EXPLICIT_CALL,
   15123           0 :                                                  @2);
   15124           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15125           0 :                                                    $1, (Node *) n, @2);
   15126             :                 }
   15127             : 
   15128             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15129             :                 {
   15130          88 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15131          88 :                                                  list_make1($4),
   15132             :                                                  COERCE_EXPLICIT_CALL,
   15133          88 :                                                  @2);
   15134          88 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15135          88 :                                                    $1, (Node *) n, @2);
   15136             :                 }
   15137             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15138             :                 {
   15139          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15140          30 :                                                  list_make2($4, $6),
   15141             :                                                  COERCE_EXPLICIT_CALL,
   15142          30 :                                                  @2);
   15143          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15144          30 :                                                    $1, (Node *) n, @2);
   15145             :                 }
   15146             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15147             :                 {
   15148           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15149           0 :                                                  list_make1($5),
   15150             :                                                  COERCE_EXPLICIT_CALL,
   15151           0 :                                                  @2);
   15152           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15153           0 :                                                    $1, (Node *) n, @2);
   15154             :                 }
   15155             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15156             :                 {
   15157           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15158           0 :                                                  list_make2($5, $7),
   15159             :                                                  COERCE_EXPLICIT_CALL,
   15160           0 :                                                  @2);
   15161           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15162           0 :                                                    $1, (Node *) n, @2);
   15163             :                 }
   15164             : 
   15165             :             /* NullTest clause
   15166             :              * Define SQL-style Null test clause.
   15167             :              * Allow two forms described in the standard:
   15168             :              *  a IS NULL
   15169             :              *  a IS NOT NULL
   15170             :              * Allow two SQL extensions
   15171             :              *  a ISNULL
   15172             :              *  a NOTNULL
   15173             :              */
   15174             :             | a_expr IS NULL_P                          %prec IS
   15175             :                 {
   15176        5260 :                     NullTest   *n = makeNode(NullTest);
   15177             : 
   15178        5260 :                     n->arg = (Expr *) $1;
   15179        5260 :                     n->nulltesttype = IS_NULL;
   15180        5260 :                     n->location = @2;
   15181        5260 :                     $$ = (Node *) n;
   15182             :                 }
   15183             :             | a_expr ISNULL
   15184             :                 {
   15185          96 :                     NullTest   *n = makeNode(NullTest);
   15186             : 
   15187          96 :                     n->arg = (Expr *) $1;
   15188          96 :                     n->nulltesttype = IS_NULL;
   15189          96 :                     n->location = @2;
   15190          96 :                     $$ = (Node *) n;
   15191             :                 }
   15192             :             | a_expr IS NOT NULL_P                      %prec IS
   15193             :                 {
   15194       12902 :                     NullTest   *n = makeNode(NullTest);
   15195             : 
   15196       12900 :                     n->arg = (Expr *) $1;
   15197       12900 :                     n->nulltesttype = IS_NOT_NULL;
   15198       12900 :                     n->location = @2;
   15199       12900 :                     $$ = (Node *) n;
   15200             :                 }
   15201             :             | a_expr NOTNULL
   15202             :                 {
   15203           6 :                     NullTest   *n = makeNode(NullTest);
   15204             : 
   15205           6 :                     n->arg = (Expr *) $1;
   15206           6 :                     n->nulltesttype = IS_NOT_NULL;
   15207           6 :                     n->location = @2;
   15208           6 :                     $$ = (Node *) n;
   15209             :                 }
   15210             :             | row OVERLAPS row
   15211             :                 {
   15212         966 :                     if (list_length($1) != 2)
   15213           0 :                         ereport(ERROR,
   15214             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15215             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15216             :                                  parser_errposition(@1)));
   15217         966 :                     if (list_length($3) != 2)
   15218           0 :                         ereport(ERROR,
   15219             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15220             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15221             :                                  parser_errposition(@3)));
   15222         966 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15223         966 :                                                list_concat($1, $3),
   15224             :                                                COERCE_SQL_SYNTAX,
   15225         966 :                                                @2);
   15226             :                 }
   15227             :             | a_expr IS TRUE_P                          %prec IS
   15228             :                 {
   15229         428 :                     BooleanTest *b = makeNode(BooleanTest);
   15230             : 
   15231         428 :                     b->arg = (Expr *) $1;
   15232         428 :                     b->booltesttype = IS_TRUE;
   15233         428 :                     b->location = @2;
   15234         428 :                     $$ = (Node *) b;
   15235             :                 }
   15236             :             | a_expr IS NOT TRUE_P                      %prec IS
   15237             :                 {
   15238         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15239             : 
   15240         140 :                     b->arg = (Expr *) $1;
   15241         140 :                     b->booltesttype = IS_NOT_TRUE;
   15242         140 :                     b->location = @2;
   15243         140 :                     $$ = (Node *) b;
   15244             :                 }
   15245             :             | a_expr IS FALSE_P                         %prec IS
   15246             :                 {
   15247         154 :                     BooleanTest *b = makeNode(BooleanTest);
   15248             : 
   15249         154 :                     b->arg = (Expr *) $1;
   15250         154 :                     b->booltesttype = IS_FALSE;
   15251         154 :                     b->location = @2;
   15252         154 :                     $$ = (Node *) b;
   15253             :                 }
   15254             :             | a_expr IS NOT FALSE_P                     %prec IS
   15255             :                 {
   15256          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15257             : 
   15258          92 :                     b->arg = (Expr *) $1;
   15259          92 :                     b->booltesttype = IS_NOT_FALSE;
   15260          92 :                     b->location = @2;
   15261          92 :                     $$ = (Node *) b;
   15262             :                 }
   15263             :             | a_expr IS UNKNOWN                         %prec IS
   15264             :                 {
   15265          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15266             : 
   15267          52 :                     b->arg = (Expr *) $1;
   15268          52 :                     b->booltesttype = IS_UNKNOWN;
   15269          52 :                     b->location = @2;
   15270          52 :                     $$ = (Node *) b;
   15271             :                 }
   15272             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15273             :                 {
   15274          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15275             : 
   15276          48 :                     b->arg = (Expr *) $1;
   15277          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15278          48 :                     b->location = @2;
   15279          48 :                     $$ = (Node *) b;
   15280             :                 }
   15281             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15282             :                 {
   15283        1068 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15284             :                 }
   15285             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15286             :                 {
   15287          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15288             :                 }
   15289             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15290             :                 {
   15291         466 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15292             :                                                    "BETWEEN",
   15293         466 :                                                    $1,
   15294         466 :                                                    (Node *) list_make2($4, $6),
   15295         466 :                                                    @2);
   15296             :                 }
   15297             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15298             :                 {
   15299          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15300             :                                                    "NOT BETWEEN",
   15301          12 :                                                    $1,
   15302          12 :                                                    (Node *) list_make2($5, $7),
   15303          12 :                                                    @2);
   15304             :                 }
   15305             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15306             :                 {
   15307          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15308             :                                                    "BETWEEN SYMMETRIC",
   15309          12 :                                                    $1,
   15310          12 :                                                    (Node *) list_make2($4, $6),
   15311          12 :                                                    @2);
   15312             :                 }
   15313             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15314             :                 {
   15315          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15316             :                                                    "NOT BETWEEN SYMMETRIC",
   15317          12 :                                                    $1,
   15318          12 :                                                    (Node *) list_make2($5, $7),
   15319          12 :                                                    @2);
   15320             :                 }
   15321             :             | a_expr IN_P select_with_parens
   15322             :                 {
   15323             :                     /* generate foo = ANY (subquery) */
   15324        5510 :                     SubLink    *n = makeNode(SubLink);
   15325             : 
   15326        5510 :                     n->subselect = $3;
   15327        5510 :                     n->subLinkType = ANY_SUBLINK;
   15328        5510 :                     n->subLinkId = 0;
   15329        5510 :                     n->testexpr = $1;
   15330        5510 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15331        5510 :                     n->location = @2;
   15332        5510 :                     $$ = (Node *) n;
   15333             :                 }
   15334             :             | a_expr IN_P '(' expr_list ')'
   15335             :                 {
   15336             :                     /* generate scalar IN expression */
   15337       18908 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
   15338             : 
   15339       18908 :                     n->rexpr_list_start = @3;
   15340       18908 :                     n->rexpr_list_end = @5;
   15341       18908 :                     $$ = (Node *) n;
   15342             :                 }
   15343             :             | a_expr NOT_LA IN_P select_with_parens         %prec NOT_LA
   15344             :                 {
   15345             :                     /* generate NOT (foo = ANY (subquery)) */
   15346         120 :                     SubLink    *n = makeNode(SubLink);
   15347             : 
   15348         120 :                     n->subselect = $4;
   15349         120 :                     n->subLinkType = ANY_SUBLINK;
   15350         120 :                     n->subLinkId = 0;
   15351         120 :                     n->testexpr = $1;
   15352         120 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15353         120 :                     n->location = @2;
   15354             :                     /* Stick a NOT on top; must have same parse location */
   15355         120 :                     $$ = makeNotExpr((Node *) n, @2);
   15356             :                 }
   15357             :             | a_expr NOT_LA IN_P '(' expr_list ')'
   15358             :                 {
   15359             :                     /* generate scalar NOT IN expression */
   15360        2658 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
   15361             : 
   15362        2658 :                     n->rexpr_list_start = @4;
   15363        2658 :                     n->rexpr_list_end = @6;
   15364        2658 :                     $$ = (Node *) n;
   15365             :                 }
   15366             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15367             :                 {
   15368         180 :                     SubLink    *n = makeNode(SubLink);
   15369             : 
   15370         180 :                     n->subLinkType = $3;
   15371         180 :                     n->subLinkId = 0;
   15372         180 :                     n->testexpr = $1;
   15373         180 :                     n->operName = $2;
   15374         180 :                     n->subselect = $4;
   15375         180 :                     n->location = @2;
   15376         180 :                     $$ = (Node *) n;
   15377             :                 }
   15378             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15379             :                 {
   15380       16842 :                     if ($3 == ANY_SUBLINK)
   15381       16542 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15382             :                     else
   15383         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15384             :                 }
   15385             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15386             :                 {
   15387             :                     /* Not sure how to get rid of the parentheses
   15388             :                      * but there are lots of shift/reduce errors without them.
   15389             :                      *
   15390             :                      * Should be able to implement this by plopping the entire
   15391             :                      * select into a node, then transforming the target expressions
   15392             :                      * from whatever they are into count(*), and testing the
   15393             :                      * entire result equal to one.
   15394             :                      * But, will probably implement a separate node in the executor.
   15395             :                      */
   15396           0 :                     ereport(ERROR,
   15397             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15398             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15399             :                              parser_errposition(@1)));
   15400             :                 }
   15401             :             | a_expr IS DOCUMENT_P                  %prec IS
   15402             :                 {
   15403          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15404          18 :                                      list_make1($1), @2);
   15405             :                 }
   15406             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15407             :                 {
   15408          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15409          18 :                                                  list_make1($1), @2),
   15410          18 :                                      @2);
   15411             :                 }
   15412             :             | a_expr IS NORMALIZED                              %prec IS
   15413             :                 {
   15414          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15415          12 :                                                list_make1($1),
   15416             :                                                COERCE_SQL_SYNTAX,
   15417          12 :                                                @2);
   15418             :                 }
   15419             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15420             :                 {
   15421          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15422          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15423             :                                                COERCE_SQL_SYNTAX,
   15424          36 :                                                @2);
   15425             :                 }
   15426             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15427             :                 {
   15428           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15429           0 :                                                            list_make1($1),
   15430             :                                                            COERCE_SQL_SYNTAX,
   15431           0 :                                                            @2),
   15432           0 :                                      @2);
   15433             :                 }
   15434             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15435             :                 {
   15436           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15437           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15438             :                                                            COERCE_SQL_SYNTAX,
   15439           0 :                                                            @2),
   15440           0 :                                      @2);
   15441             :                 }
   15442             :             | a_expr IS json_predicate_type_constraint
   15443             :                     json_key_uniqueness_constraint_opt      %prec IS
   15444             :                 {
   15445         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15446             : 
   15447         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15448             :                 }
   15449             :             /*
   15450             :              * Required by SQL/JSON, but there are conflicts
   15451             :             | a_expr
   15452             :                 json_format_clause
   15453             :                 IS  json_predicate_type_constraint
   15454             :                     json_key_uniqueness_constraint_opt      %prec IS
   15455             :                 {
   15456             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15457             :                 }
   15458             :             */
   15459             :             | a_expr IS NOT
   15460             :                     json_predicate_type_constraint
   15461             :                     json_key_uniqueness_constraint_opt      %prec IS
   15462             :                 {
   15463          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15464             : 
   15465          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15466             :                 }
   15467             :             /*
   15468             :              * Required by SQL/JSON, but there are conflicts
   15469             :             | a_expr
   15470             :                 json_format_clause
   15471             :                 IS NOT
   15472             :                     json_predicate_type_constraint
   15473             :                     json_key_uniqueness_constraint_opt      %prec IS
   15474             :                 {
   15475             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15476             :                 }
   15477             :             */
   15478             :             | DEFAULT
   15479             :                 {
   15480             :                     /*
   15481             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15482             :                      * expressions", but for us, it's easier to allow it in
   15483             :                      * any a_expr and then throw error during parse analysis
   15484             :                      * if it's in an inappropriate context.  This way also
   15485             :                      * lets us say something smarter than "syntax error".
   15486             :                      */
   15487        1530 :                     SetToDefault *n = makeNode(SetToDefault);
   15488             : 
   15489             :                     /* parse analysis will fill in the rest */
   15490        1530 :                     n->location = @1;
   15491        1530 :                     $$ = (Node *) n;
   15492             :                 }
   15493             :         ;
   15494             : 
   15495             : /*
   15496             :  * Restricted expressions
   15497             :  *
   15498             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15499             :  *
   15500             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15501             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15502             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15503             :  */
   15504             : b_expr:     c_expr
   15505        3766 :                 { $$ = $1; }
   15506             :             | b_expr TYPECAST Typename
   15507         212 :                 { $$ = makeTypeCast($1, $3, @2); }
   15508             :             | '+' b_expr                    %prec UMINUS
   15509           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15510             :             | '-' b_expr                    %prec UMINUS
   15511          66 :                 { $$ = doNegate($2, @1); }
   15512             :             | b_expr '+' b_expr
   15513          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15514             :             | b_expr '-' b_expr
   15515          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15516             :             | b_expr '*' b_expr
   15517          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15518             :             | b_expr '/' b_expr
   15519           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15520             :             | b_expr '%' b_expr
   15521           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15522             :             | b_expr '^' b_expr
   15523           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15524             :             | b_expr '<' b_expr
   15525           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15526             :             | b_expr '>' b_expr
   15527           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15528             :             | b_expr '=' b_expr
   15529           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15530             :             | b_expr LESS_EQUALS b_expr
   15531           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15532             :             | b_expr GREATER_EQUALS b_expr
   15533           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15534             :             | b_expr NOT_EQUALS b_expr
   15535           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15536             :             | b_expr qual_Op b_expr             %prec Op
   15537          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15538             :             | qual_Op b_expr                    %prec Op
   15539           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15540             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15541             :                 {
   15542           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15543             :                 }
   15544             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15545             :                 {
   15546           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15547             :                 }
   15548             :             | b_expr IS DOCUMENT_P                  %prec IS
   15549             :                 {
   15550           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15551           0 :                                      list_make1($1), @2);
   15552             :                 }
   15553             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15554             :                 {
   15555           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15556           0 :                                                  list_make1($1), @2),
   15557           0 :                                      @2);
   15558             :                 }
   15559             :         ;
   15560             : 
   15561             : /*
   15562             :  * Productions that can be used in both a_expr and b_expr.
   15563             :  *
   15564             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15565             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15566             :  * inside parentheses, such as function arguments; that cannot introduce
   15567             :  * ambiguity to the b_expr syntax.
   15568             :  */
   15569     1798858 : c_expr:     columnref                               { $$ = $1; }
   15570     1232258 :             | AexprConst                            { $$ = $1; }
   15571             :             | PARAM opt_indirection
   15572             :                 {
   15573       45940 :                     ParamRef   *p = makeNode(ParamRef);
   15574             : 
   15575       45940 :                     p->number = $1;
   15576       45940 :                     p->location = @1;
   15577       45940 :                     if ($2)
   15578             :                     {
   15579        1084 :                         A_Indirection *n = makeNode(A_Indirection);
   15580             : 
   15581        1084 :                         n->arg = (Node *) p;
   15582        1084 :                         n->indirection = check_indirection($2, yyscanner);
   15583        1084 :                         $$ = (Node *) n;
   15584             :                     }
   15585             :                     else
   15586       44856 :                         $$ = (Node *) p;
   15587             :                 }
   15588             :             | '(' a_expr ')' opt_indirection
   15589             :                 {
   15590       89500 :                     if ($4)
   15591             :                     {
   15592       12344 :                         A_Indirection *n = makeNode(A_Indirection);
   15593             : 
   15594       12344 :                         n->arg = $2;
   15595       12344 :                         n->indirection = check_indirection($4, yyscanner);
   15596       12344 :                         $$ = (Node *) n;
   15597             :                     }
   15598             :                     else
   15599       77156 :                         $$ = $2;
   15600             :                 }
   15601             :             | case_expr
   15602       39052 :                 { $$ = $1; }
   15603             :             | func_expr
   15604      388982 :                 { $$ = $1; }
   15605             :             | select_with_parens            %prec UMINUS
   15606             :                 {
   15607       27394 :                     SubLink    *n = makeNode(SubLink);
   15608             : 
   15609       27394 :                     n->subLinkType = EXPR_SUBLINK;
   15610       27394 :                     n->subLinkId = 0;
   15611       27394 :                     n->testexpr = NULL;
   15612       27394 :                     n->operName = NIL;
   15613       27394 :                     n->subselect = $1;
   15614       27394 :                     n->location = @1;
   15615       27394 :                     $$ = (Node *) n;
   15616             :                 }
   15617             :             | select_with_parens indirection
   15618             :                 {
   15619             :                     /*
   15620             :                      * Because the select_with_parens nonterminal is designed
   15621             :                      * to "eat" as many levels of parens as possible, the
   15622             :                      * '(' a_expr ')' opt_indirection production above will
   15623             :                      * fail to match a sub-SELECT with indirection decoration;
   15624             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15625             :                      * as there are parens around it.  To support applying
   15626             :                      * subscripting or field selection to a sub-SELECT result,
   15627             :                      * we need this redundant-looking production.
   15628             :                      */
   15629          18 :                     SubLink    *n = makeNode(SubLink);
   15630          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15631             : 
   15632          18 :                     n->subLinkType = EXPR_SUBLINK;
   15633          18 :                     n->subLinkId = 0;
   15634          18 :                     n->testexpr = NULL;
   15635          18 :                     n->operName = NIL;
   15636          18 :                     n->subselect = $1;
   15637          18 :                     n->location = @1;
   15638          18 :                     a->arg = (Node *) n;
   15639          18 :                     a->indirection = check_indirection($2, yyscanner);
   15640          18 :                     $$ = (Node *) a;
   15641             :                 }
   15642             :             | EXISTS select_with_parens
   15643             :                 {
   15644        6154 :                     SubLink    *n = makeNode(SubLink);
   15645             : 
   15646        6154 :                     n->subLinkType = EXISTS_SUBLINK;
   15647        6154 :                     n->subLinkId = 0;
   15648        6154 :                     n->testexpr = NULL;
   15649        6154 :                     n->operName = NIL;
   15650        6154 :                     n->subselect = $2;
   15651        6154 :                     n->location = @1;
   15652        6154 :                     $$ = (Node *) n;
   15653             :                 }
   15654             :             | ARRAY select_with_parens
   15655             :                 {
   15656        8408 :                     SubLink    *n = makeNode(SubLink);
   15657             : 
   15658        8408 :                     n->subLinkType = ARRAY_SUBLINK;
   15659        8408 :                     n->subLinkId = 0;
   15660        8408 :                     n->testexpr = NULL;
   15661        8408 :                     n->operName = NIL;
   15662        8408 :                     n->subselect = $2;
   15663        8408 :                     n->location = @1;
   15664        8408 :                     $$ = (Node *) n;
   15665             :                 }
   15666             :             | ARRAY array_expr
   15667             :                 {
   15668        7378 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15669             : 
   15670             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15671        7378 :                     n->location = @1;
   15672        7378 :                     $$ = (Node *) n;
   15673             :                 }
   15674             :             | explicit_row
   15675             :                 {
   15676        3816 :                     RowExpr    *r = makeNode(RowExpr);
   15677             : 
   15678        3816 :                     r->args = $1;
   15679        3816 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15680        3816 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15681        3816 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15682        3816 :                     r->location = @1;
   15683        3816 :                     $$ = (Node *) r;
   15684             :                 }
   15685             :             | implicit_row
   15686             :                 {
   15687        2706 :                     RowExpr    *r = makeNode(RowExpr);
   15688             : 
   15689        2706 :                     r->args = $1;
   15690        2706 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15691        2706 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15692        2706 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15693        2706 :                     r->location = @1;
   15694        2706 :                     $$ = (Node *) r;
   15695             :                 }
   15696             :             | GROUPING '(' expr_list ')'
   15697             :               {
   15698         362 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15699             : 
   15700         362 :                   g->args = $3;
   15701         362 :                   g->location = @1;
   15702         362 :                   $$ = (Node *) g;
   15703             :               }
   15704             :         ;
   15705             : 
   15706             : func_application: func_name '(' ')'
   15707             :                 {
   15708       32712 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15709             :                                                COERCE_EXPLICIT_CALL,
   15710       32712 :                                                @1);
   15711             :                 }
   15712             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15713             :                 {
   15714      314388 :                     FuncCall   *n = makeFuncCall($1, $3,
   15715             :                                                  COERCE_EXPLICIT_CALL,
   15716      314388 :                                                  @1);
   15717             : 
   15718      314384 :                     n->agg_order = $4;
   15719      314384 :                     $$ = (Node *) n;
   15720             :                 }
   15721             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15722             :                 {
   15723         620 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15724             :                                                  COERCE_EXPLICIT_CALL,
   15725         620 :                                                  @1);
   15726             : 
   15727         620 :                     n->func_variadic = true;
   15728         620 :                     n->agg_order = $5;
   15729         620 :                     $$ = (Node *) n;
   15730             :                 }
   15731             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15732             :                 {
   15733         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15734             :                                                  COERCE_EXPLICIT_CALL,
   15735         120 :                                                  @1);
   15736             : 
   15737         120 :                     n->func_variadic = true;
   15738         120 :                     n->agg_order = $7;
   15739         120 :                     $$ = (Node *) n;
   15740             :                 }
   15741             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15742             :                 {
   15743           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15744             :                                                  COERCE_EXPLICIT_CALL,
   15745           0 :                                                  @1);
   15746             : 
   15747           0 :                     n->agg_order = $5;
   15748             :                     /* Ideally we'd mark the FuncCall node to indicate
   15749             :                      * "must be an aggregate", but there's no provision
   15750             :                      * for that in FuncCall at the moment.
   15751             :                      */
   15752           0 :                     $$ = (Node *) n;
   15753             :                 }
   15754             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15755             :                 {
   15756         550 :                     FuncCall   *n = makeFuncCall($1, $4,
   15757             :                                                  COERCE_EXPLICIT_CALL,
   15758         550 :                                                  @1);
   15759             : 
   15760         550 :                     n->agg_order = $5;
   15761         550 :                     n->agg_distinct = true;
   15762         550 :                     $$ = (Node *) n;
   15763             :                 }
   15764             :             | func_name '(' '*' ')'
   15765             :                 {
   15766             :                     /*
   15767             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15768             :                      * aggregate.  This does the right thing for COUNT(*),
   15769             :                      * and there are no other aggregates in SQL that accept
   15770             :                      * '*' as parameter.
   15771             :                      *
   15772             :                      * The FuncCall node is also marked agg_star = true,
   15773             :                      * so that later processing can detect what the argument
   15774             :                      * really was.
   15775             :                      */
   15776       12714 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15777             :                                                  COERCE_EXPLICIT_CALL,
   15778       12714 :                                                  @1);
   15779             : 
   15780       12712 :                     n->agg_star = true;
   15781       12712 :                     $$ = (Node *) n;
   15782             :                 }
   15783             :         ;
   15784             : 
   15785             : 
   15786             : /*
   15787             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15788             :  * so that we have classifications for "everything that is a function call or
   15789             :  * looks like one".  This isn't very important, but it saves us having to
   15790             :  * document which variants are legal in places like "FROM function()" or the
   15791             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15792             :  * (Note that many of the special SQL functions wouldn't actually make any
   15793             :  * sense as functional index entries, but we ignore that consideration here.)
   15794             :  */
   15795             : func_expr: func_application within_group_clause filter_clause over_clause
   15796             :                 {
   15797      312378 :                     FuncCall   *n = (FuncCall *) $1;
   15798             : 
   15799             :                     /*
   15800             :                      * The order clause for WITHIN GROUP and the one for
   15801             :                      * plain-aggregate ORDER BY share a field, so we have to
   15802             :                      * check here that at most one is present.  We also check
   15803             :                      * for DISTINCT and VARIADIC here to give a better error
   15804             :                      * location.  Other consistency checks are deferred to
   15805             :                      * parse analysis.
   15806             :                      */
   15807      312378 :                     if ($2 != NIL)
   15808             :                     {
   15809         348 :                         if (n->agg_order != NIL)
   15810           6 :                             ereport(ERROR,
   15811             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15812             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15813             :                                      parser_errposition(@2)));
   15814         342 :                         if (n->agg_distinct)
   15815           0 :                             ereport(ERROR,
   15816             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15817             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15818             :                                      parser_errposition(@2)));
   15819         342 :                         if (n->func_variadic)
   15820           0 :                             ereport(ERROR,
   15821             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15822             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15823             :                                      parser_errposition(@2)));
   15824         342 :                         n->agg_order = $2;
   15825         342 :                         n->agg_within_group = true;
   15826             :                     }
   15827      312372 :                     n->agg_filter = $3;
   15828      312372 :                     n->over = $4;
   15829      312372 :                     $$ = (Node *) n;
   15830             :                 }
   15831             :             | json_aggregate_func filter_clause over_clause
   15832             :                 {
   15833         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15834         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15835         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15836             : 
   15837         360 :                     n->agg_filter = $2;
   15838         360 :                     n->over = $3;
   15839         360 :                     $$ = (Node *) $1;
   15840             :                 }
   15841             :             | func_expr_common_subexpr
   15842       76250 :                 { $$ = $1; }
   15843             :         ;
   15844             : 
   15845             : /*
   15846             :  * Like func_expr but does not accept WINDOW functions directly
   15847             :  * (but they can still be contained in arguments for functions etc).
   15848             :  * Use this when window expressions are not allowed, where needed to
   15849             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15850             :  */
   15851             : func_expr_windowless:
   15852       48092 :             func_application                        { $$ = $1; }
   15853         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15854           0 :             | json_aggregate_func                   { $$ = $1; }
   15855             :         ;
   15856             : 
   15857             : /*
   15858             :  * Special expressions that are considered to be functions.
   15859             :  */
   15860             : func_expr_common_subexpr:
   15861             :             COLLATION FOR '(' a_expr ')'
   15862             :                 {
   15863          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15864          30 :                                                list_make1($4),
   15865             :                                                COERCE_SQL_SYNTAX,
   15866          30 :                                                @1);
   15867             :                 }
   15868             :             | CURRENT_DATE
   15869             :                 {
   15870         308 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15871             :                 }
   15872             :             | CURRENT_TIME
   15873             :                 {
   15874          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15875             :                 }
   15876             :             | CURRENT_TIME '(' Iconst ')'
   15877             :                 {
   15878          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15879             :                 }
   15880             :             | CURRENT_TIMESTAMP
   15881             :                 {
   15882         286 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15883             :                 }
   15884             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15885             :                 {
   15886         174 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15887             :                 }
   15888             :             | LOCALTIME
   15889             :                 {
   15890          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15891             :                 }
   15892             :             | LOCALTIME '(' Iconst ')'
   15893             :                 {
   15894          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15895             :                 }
   15896             :             | LOCALTIMESTAMP
   15897             :                 {
   15898          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15899             :                 }
   15900             :             | LOCALTIMESTAMP '(' Iconst ')'
   15901             :                 {
   15902          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15903             :                 }
   15904             :             | CURRENT_ROLE
   15905             :                 {
   15906          68 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15907             :                 }
   15908             :             | CURRENT_USER
   15909             :                 {
   15910        1060 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15911             :                 }
   15912             :             | SESSION_USER
   15913             :                 {
   15914         574 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15915             :                 }
   15916             :             | SYSTEM_USER
   15917             :                 {
   15918          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15919             :                                                NIL,
   15920             :                                                COERCE_SQL_SYNTAX,
   15921             :                                                @1);
   15922             :                 }
   15923             :             | USER
   15924             :                 {
   15925          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15926             :                 }
   15927             :             | CURRENT_CATALOG
   15928             :                 {
   15929          52 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15930             :                 }
   15931             :             | CURRENT_SCHEMA
   15932             :                 {
   15933          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15934             :                 }
   15935             :             | CAST '(' a_expr AS Typename ')'
   15936       62472 :                 { $$ = makeTypeCast($3, $5, @1); }
   15937             :             | EXTRACT '(' extract_list ')'
   15938             :                 {
   15939        1382 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15940        1382 :                                                $3,
   15941             :                                                COERCE_SQL_SYNTAX,
   15942        1382 :                                                @1);
   15943             :                 }
   15944             :             | NORMALIZE '(' a_expr ')'
   15945             :                 {
   15946          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15947          18 :                                                list_make1($3),
   15948             :                                                COERCE_SQL_SYNTAX,
   15949          18 :                                                @1);
   15950             :                 }
   15951             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15952             :                 {
   15953          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15954          42 :                                                list_make2($3, makeStringConst($5, @5)),
   15955             :                                                COERCE_SQL_SYNTAX,
   15956          42 :                                                @1);
   15957             :                 }
   15958             :             | OVERLAY '(' overlay_list ')'
   15959             :                 {
   15960          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15961          82 :                                                $3,
   15962             :                                                COERCE_SQL_SYNTAX,
   15963          82 :                                                @1);
   15964             :                 }
   15965             :             | OVERLAY '(' func_arg_list_opt ')'
   15966             :                 {
   15967             :                     /*
   15968             :                      * allow functions named overlay() to be called without
   15969             :                      * special syntax
   15970             :                      */
   15971           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15972           0 :                                                $3,
   15973             :                                                COERCE_EXPLICIT_CALL,
   15974           0 :                                                @1);
   15975             :                 }
   15976             :             | POSITION '(' position_list ')'
   15977             :                 {
   15978             :                     /*
   15979             :                      * position(A in B) is converted to position(B, A)
   15980             :                      *
   15981             :                      * We deliberately don't offer a "plain syntax" option
   15982             :                      * for position(), because the reversal of the arguments
   15983             :                      * creates too much risk of confusion.
   15984             :                      */
   15985         400 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15986         400 :                                                $3,
   15987             :                                                COERCE_SQL_SYNTAX,
   15988         400 :                                                @1);
   15989             :                 }
   15990             :             | SUBSTRING '(' substr_list ')'
   15991             :                 {
   15992             :                     /* substring(A from B for C) is converted to
   15993             :                      * substring(A, B, C) - thomas 2000-11-28
   15994             :                      */
   15995         710 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   15996         710 :                                                $3,
   15997             :                                                COERCE_SQL_SYNTAX,
   15998         710 :                                                @1);
   15999             :                 }
   16000             :             | SUBSTRING '(' func_arg_list_opt ')'
   16001             :                 {
   16002             :                     /*
   16003             :                      * allow functions named substring() to be called without
   16004             :                      * special syntax
   16005             :                      */
   16006         252 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   16007         252 :                                                $3,
   16008             :                                                COERCE_EXPLICIT_CALL,
   16009         252 :                                                @1);
   16010             :                 }
   16011             :             | TREAT '(' a_expr AS Typename ')'
   16012             :                 {
   16013             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   16014             :                      * which is defined to be a subtype of the original expression.
   16015             :                      * In SQL99, this is intended for use with structured UDTs,
   16016             :                      * but let's make this a generally useful form allowing stronger
   16017             :                      * coercions than are handled by implicit casting.
   16018             :                      *
   16019             :                      * Convert SystemTypeName() to SystemFuncName() even though
   16020             :                      * at the moment they result in the same thing.
   16021             :                      */
   16022           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   16023           0 :                                                list_make1($3),
   16024             :                                                COERCE_EXPLICIT_CALL,
   16025           0 :                                                @1);
   16026             :                 }
   16027             :             | TRIM '(' BOTH trim_list ')'
   16028             :                 {
   16029             :                     /* various trim expressions are defined in SQL
   16030             :                      * - thomas 1997-07-19
   16031             :                      */
   16032          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16033          12 :                                                $4,
   16034             :                                                COERCE_SQL_SYNTAX,
   16035          12 :                                                @1);
   16036             :                 }
   16037             :             | TRIM '(' LEADING trim_list ')'
   16038             :                 {
   16039          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   16040          24 :                                                $4,
   16041             :                                                COERCE_SQL_SYNTAX,
   16042          24 :                                                @1);
   16043             :                 }
   16044             :             | TRIM '(' TRAILING trim_list ')'
   16045             :                 {
   16046         580 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16047         580 :                                                $4,
   16048             :                                                COERCE_SQL_SYNTAX,
   16049         580 :                                                @1);
   16050             :                 }
   16051             :             | TRIM '(' trim_list ')'
   16052             :                 {
   16053          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16054          98 :                                                $3,
   16055             :                                                COERCE_SQL_SYNTAX,
   16056          98 :                                                @1);
   16057             :                 }
   16058             :             | NULLIF '(' a_expr ',' a_expr ')'
   16059             :                 {
   16060         386 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16061             :                 }
   16062             :             | COALESCE '(' expr_list ')'
   16063             :                 {
   16064        3204 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16065             : 
   16066        3204 :                     c->args = $3;
   16067        3204 :                     c->location = @1;
   16068        3204 :                     $$ = (Node *) c;
   16069             :                 }
   16070             :             | GREATEST '(' expr_list ')'
   16071             :                 {
   16072         146 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16073             : 
   16074         146 :                     v->args = $3;
   16075         146 :                     v->op = IS_GREATEST;
   16076         146 :                     v->location = @1;
   16077         146 :                     $$ = (Node *) v;
   16078             :                 }
   16079             :             | LEAST '(' expr_list ')'
   16080             :                 {
   16081         124 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16082             : 
   16083         124 :                     v->args = $3;
   16084         124 :                     v->op = IS_LEAST;
   16085         124 :                     v->location = @1;
   16086         124 :                     $$ = (Node *) v;
   16087             :                 }
   16088             :             | XMLCONCAT '(' expr_list ')'
   16089             :                 {
   16090          62 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16091             :                 }
   16092             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16093             :                 {
   16094           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16095             :                 }
   16096             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16097             :                 {
   16098          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16099             :                 }
   16100             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16101             :                 {
   16102         116 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16103             :                 }
   16104             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16105             :                 {
   16106          20 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16107             :                 }
   16108             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16109             :                 {
   16110             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16111             :                      * converted to xmlexists(A, B)*/
   16112          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16113          54 :                                                list_make2($3, $4),
   16114             :                                                COERCE_SQL_SYNTAX,
   16115          54 :                                                @1);
   16116             :                 }
   16117             :             | XMLFOREST '(' xml_attribute_list ')'
   16118             :                 {
   16119          32 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16120             :                 }
   16121             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16122             :                 {
   16123             :                     XmlExpr *x = (XmlExpr *)
   16124         140 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16125         140 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16126         140 :                                     @1);
   16127             : 
   16128         140 :                     x->xmloption = $3;
   16129         140 :                     $$ = (Node *) x;
   16130             :                 }
   16131             :             | XMLPI '(' NAME_P ColLabel ')'
   16132             :                 {
   16133          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16134             :                 }
   16135             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16136             :                 {
   16137          50 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16138             :                 }
   16139             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16140             :                 {
   16141          68 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16142          68 :                                      list_make3($3, $5, $6), @1);
   16143             :                 }
   16144             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16145             :                 {
   16146         218 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16147             : 
   16148         218 :                     n->xmloption = $3;
   16149         218 :                     n->expr = $4;
   16150         218 :                     n->typeName = $6;
   16151         218 :                     n->indent = $7;
   16152         218 :                     n->location = @1;
   16153         218 :                     $$ = (Node *) n;
   16154             :                 }
   16155             :             | JSON_OBJECT '(' func_arg_list ')'
   16156             :                 {
   16157             :                     /* Support for legacy (non-standard) json_object() */
   16158          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16159          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16160             :                 }
   16161             :             | JSON_OBJECT '(' json_name_and_value_list
   16162             :                 json_object_constructor_null_clause_opt
   16163             :                 json_key_uniqueness_constraint_opt
   16164             :                 json_returning_clause_opt ')'
   16165             :                 {
   16166         348 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16167             : 
   16168         348 :                     n->exprs = $3;
   16169         348 :                     n->absent_on_null = $4;
   16170         348 :                     n->unique = $5;
   16171         348 :                     n->output = (JsonOutput *) $6;
   16172         348 :                     n->location = @1;
   16173         348 :                     $$ = (Node *) n;
   16174             :                 }
   16175             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16176             :                 {
   16177          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16178             : 
   16179          92 :                     n->exprs = NULL;
   16180          92 :                     n->absent_on_null = false;
   16181          92 :                     n->unique = false;
   16182          92 :                     n->output = (JsonOutput *) $3;
   16183          92 :                     n->location = @1;
   16184          92 :                     $$ = (Node *) n;
   16185             :                 }
   16186             :             | JSON_ARRAY '('
   16187             :                 json_value_expr_list
   16188             :                 json_array_constructor_null_clause_opt
   16189             :                 json_returning_clause_opt
   16190             :             ')'
   16191             :                 {
   16192         108 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16193             : 
   16194         108 :                     n->exprs = $3;
   16195         108 :                     n->absent_on_null = $4;
   16196         108 :                     n->output = (JsonOutput *) $5;
   16197         108 :                     n->location = @1;
   16198         108 :                     $$ = (Node *) n;
   16199             :                 }
   16200             :             | JSON_ARRAY '('
   16201             :                 select_no_parens
   16202             :                 json_format_clause_opt
   16203             :                 /* json_array_constructor_null_clause_opt */
   16204             :                 json_returning_clause_opt
   16205             :             ')'
   16206             :                 {
   16207          60 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16208             : 
   16209          60 :                     n->query = $3;
   16210          60 :                     n->format = (JsonFormat *) $4;
   16211          60 :                     n->absent_on_null = true;    /* XXX */
   16212          60 :                     n->output = (JsonOutput *) $5;
   16213          60 :                     n->location = @1;
   16214          60 :                     $$ = (Node *) n;
   16215             :                 }
   16216             :             | JSON_ARRAY '('
   16217             :                 json_returning_clause_opt
   16218             :             ')'
   16219             :                 {
   16220          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16221             : 
   16222          86 :                     n->exprs = NIL;
   16223          86 :                     n->absent_on_null = true;
   16224          86 :                     n->output = (JsonOutput *) $3;
   16225          86 :                     n->location = @1;
   16226          86 :                     $$ = (Node *) n;
   16227             :                 }
   16228             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16229             :                 {
   16230         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16231             : 
   16232         164 :                     n->expr = (JsonValueExpr *) $3;
   16233         164 :                     n->unique_keys = $4;
   16234         164 :                     n->output = NULL;
   16235         164 :                     n->location = @1;
   16236         164 :                     $$ = (Node *) n;
   16237             :                 }
   16238             :             | JSON_SCALAR '(' a_expr ')'
   16239             :                 {
   16240         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16241             : 
   16242         112 :                     n->expr = (Expr *) $3;
   16243         112 :                     n->output = NULL;
   16244         112 :                     n->location = @1;
   16245         112 :                     $$ = (Node *) n;
   16246             :                 }
   16247             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16248             :                 {
   16249         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16250             : 
   16251         108 :                     n->expr = (JsonValueExpr *) $3;
   16252         108 :                     n->output = (JsonOutput *) $4;
   16253         108 :                     n->location = @1;
   16254         108 :                     $$ = (Node *) n;
   16255             :                 }
   16256             :             | MERGE_ACTION '(' ')'
   16257             :                 {
   16258         210 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16259             : 
   16260         210 :                     m->msftype = TEXTOID;
   16261         210 :                     m->location = @1;
   16262         210 :                     $$ = (Node *) m;
   16263             :                 }
   16264             :             | JSON_QUERY '('
   16265             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16266             :                 json_returning_clause_opt
   16267             :                 json_wrapper_behavior
   16268             :                 json_quotes_clause_opt
   16269             :                 json_behavior_clause_opt
   16270             :             ')'
   16271             :                 {
   16272         984 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16273             : 
   16274         984 :                     n->op = JSON_QUERY_OP;
   16275         984 :                     n->context_item = (JsonValueExpr *) $3;
   16276         984 :                     n->pathspec = $5;
   16277         984 :                     n->passing = $6;
   16278         984 :                     n->output = (JsonOutput *) $7;
   16279         984 :                     n->wrapper = $8;
   16280         984 :                     n->quotes = $9;
   16281         984 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16282         984 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16283         984 :                     n->location = @1;
   16284         984 :                     $$ = (Node *) n;
   16285             :                 }
   16286             :             | JSON_EXISTS '('
   16287             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16288             :                 json_on_error_clause_opt
   16289             :             ')'
   16290             :                 {
   16291         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16292             : 
   16293         168 :                     n->op = JSON_EXISTS_OP;
   16294         168 :                     n->context_item = (JsonValueExpr *) $3;
   16295         168 :                     n->pathspec = $5;
   16296         168 :                     n->passing = $6;
   16297         168 :                     n->output = NULL;
   16298         168 :                     n->on_error = (JsonBehavior *) $7;
   16299         168 :                     n->location = @1;
   16300         168 :                     $$ = (Node *) n;
   16301             :                 }
   16302             :             | JSON_VALUE '('
   16303             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16304             :                 json_returning_clause_opt
   16305             :                 json_behavior_clause_opt
   16306             :             ')'
   16307             :                 {
   16308         576 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16309             : 
   16310         576 :                     n->op = JSON_VALUE_OP;
   16311         576 :                     n->context_item = (JsonValueExpr *) $3;
   16312         576 :                     n->pathspec = $5;
   16313         576 :                     n->passing = $6;
   16314         576 :                     n->output = (JsonOutput *) $7;
   16315         576 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16316         576 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16317         576 :                     n->location = @1;
   16318         576 :                     $$ = (Node *) n;
   16319             :                 }
   16320             :             ;
   16321             : 
   16322             : 
   16323             : /*
   16324             :  * SQL/XML support
   16325             :  */
   16326             : xml_root_version: VERSION_P a_expr
   16327          24 :                 { $$ = $2; }
   16328             :             | VERSION_P NO VALUE_P
   16329          44 :                 { $$ = makeNullAConst(-1); }
   16330             :         ;
   16331             : 
   16332             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16333          26 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16334             :             | ',' STANDALONE_P NO
   16335          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16336             :             | ',' STANDALONE_P NO VALUE_P
   16337          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16338             :             | /*EMPTY*/
   16339          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16340             :         ;
   16341             : 
   16342          56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16343             :         ;
   16344             : 
   16345          88 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16346         144 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16347             :         ;
   16348             : 
   16349             : xml_attribute_el: a_expr AS ColLabel
   16350             :                 {
   16351         106 :                     $$ = makeNode(ResTarget);
   16352         106 :                     $$->name = $3;
   16353         106 :                     $$->indirection = NIL;
   16354         106 :                     $$->val = (Node *) $1;
   16355         106 :                     $$->location = @1;
   16356             :                 }
   16357             :             | a_expr
   16358             :                 {
   16359         126 :                     $$ = makeNode(ResTarget);
   16360         126 :                     $$->name = NULL;
   16361         126 :                     $$->indirection = NIL;
   16362         126 :                     $$->val = (Node *) $1;
   16363         126 :                     $$->location = @1;
   16364             :                 }
   16365             :         ;
   16366             : 
   16367         186 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16368         188 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16369             :         ;
   16370             : 
   16371         140 : xml_indent_option: INDENT                           { $$ = true; }
   16372          36 :             | NO INDENT                             { $$ = false; }
   16373          42 :             | /*EMPTY*/                             { $$ = false; }
   16374             :         ;
   16375             : 
   16376           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16377           2 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16378         138 :             | /*EMPTY*/                             { $$ = false; }
   16379             :         ;
   16380             : 
   16381             : /* We allow several variants for SQL and other compatibility. */
   16382             : xmlexists_argument:
   16383             :             PASSING c_expr
   16384             :                 {
   16385         238 :                     $$ = $2;
   16386             :                 }
   16387             :             | PASSING c_expr xml_passing_mech
   16388             :                 {
   16389           0 :                     $$ = $2;
   16390             :                 }
   16391             :             | PASSING xml_passing_mech c_expr
   16392             :                 {
   16393          42 :                     $$ = $3;
   16394             :                 }
   16395             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16396             :                 {
   16397           6 :                     $$ = $3;
   16398             :                 }
   16399             :         ;
   16400             : 
   16401             : xml_passing_mech:
   16402             :             BY REF_P
   16403             :             | BY VALUE_P
   16404             :         ;
   16405             : 
   16406             : 
   16407             : /*
   16408             :  * Aggregate decoration clauses
   16409             :  */
   16410             : within_group_clause:
   16411         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16412      312036 :             | /*EMPTY*/                             { $$ = NIL; }
   16413             :         ;
   16414             : 
   16415             : filter_clause:
   16416         862 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16417      311882 :             | /*EMPTY*/                             { $$ = NULL; }
   16418             :         ;
   16419             : 
   16420             : 
   16421             : /*
   16422             :  * Window Definitions
   16423             :  */
   16424             : window_clause:
   16425         540 :             WINDOW window_definition_list           { $$ = $2; }
   16426      470554 :             | /*EMPTY*/                             { $$ = NIL; }
   16427             :         ;
   16428             : 
   16429             : window_definition_list:
   16430         540 :             window_definition                       { $$ = list_make1($1); }
   16431             :             | window_definition_list ',' window_definition
   16432          12 :                                                     { $$ = lappend($1, $3); }
   16433             :         ;
   16434             : 
   16435             : window_definition:
   16436             :             ColId AS window_specification
   16437             :                 {
   16438         552 :                     WindowDef  *n = $3;
   16439             : 
   16440         552 :                     n->name = $1;
   16441         552 :                     $$ = n;
   16442             :                 }
   16443             :         ;
   16444             : 
   16445             : over_clause: OVER window_specification
   16446        2616 :                 { $$ = $2; }
   16447             :             | OVER ColId
   16448             :                 {
   16449         954 :                     WindowDef  *n = makeNode(WindowDef);
   16450             : 
   16451         954 :                     n->name = $2;
   16452         954 :                     n->refname = NULL;
   16453         954 :                     n->partitionClause = NIL;
   16454         954 :                     n->orderClause = NIL;
   16455         954 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16456         954 :                     n->startOffset = NULL;
   16457         954 :                     n->endOffset = NULL;
   16458         954 :                     n->location = @2;
   16459         954 :                     $$ = n;
   16460             :                 }
   16461             :             | /*EMPTY*/
   16462      309168 :                 { $$ = NULL; }
   16463             :         ;
   16464             : 
   16465             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16466             :                         opt_sort_clause opt_frame_clause ')'
   16467             :                 {
   16468        3168 :                     WindowDef  *n = makeNode(WindowDef);
   16469             : 
   16470        3168 :                     n->name = NULL;
   16471        3168 :                     n->refname = $2;
   16472        3168 :                     n->partitionClause = $3;
   16473        3168 :                     n->orderClause = $4;
   16474             :                     /* copy relevant fields of opt_frame_clause */
   16475        3168 :                     n->frameOptions = $5->frameOptions;
   16476        3168 :                     n->startOffset = $5->startOffset;
   16477        3168 :                     n->endOffset = $5->endOffset;
   16478        3168 :                     n->location = @1;
   16479        3168 :                     $$ = n;
   16480             :                 }
   16481             :         ;
   16482             : 
   16483             : /*
   16484             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16485             :  * of a window_specification, we want the assumption to be that there is
   16486             :  * no existing_window_name; but those keywords are unreserved and so could
   16487             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16488             :  * and giving the empty production here a slightly higher precedence, so
   16489             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16490             :  * These keywords are thus precluded from being an existing_window_name but
   16491             :  * are not reserved for any other purpose.
   16492             :  */
   16493          54 : opt_existing_window_name: ColId                     { $$ = $1; }
   16494        3120 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16495             :         ;
   16496             : 
   16497         920 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16498        2248 :             | /*EMPTY*/                             { $$ = NIL; }
   16499             :         ;
   16500             : 
   16501             : /*
   16502             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16503             :  * frameOptions, startOffset, and endOffset.
   16504             :  */
   16505             : opt_frame_clause:
   16506             :             RANGE frame_extent opt_window_exclusion_clause
   16507             :                 {
   16508         796 :                     WindowDef  *n = $2;
   16509             : 
   16510         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16511         796 :                     n->frameOptions |= $3;
   16512         796 :                     $$ = n;
   16513             :                 }
   16514             :             | ROWS frame_extent opt_window_exclusion_clause
   16515             :                 {
   16516         624 :                     WindowDef  *n = $2;
   16517             : 
   16518         624 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16519         624 :                     n->frameOptions |= $3;
   16520         624 :                     $$ = n;
   16521             :                 }
   16522             :             | GROUPS frame_extent opt_window_exclusion_clause
   16523             :                 {
   16524         204 :                     WindowDef  *n = $2;
   16525             : 
   16526         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16527         204 :                     n->frameOptions |= $3;
   16528         204 :                     $$ = n;
   16529             :                 }
   16530             :             | /*EMPTY*/
   16531             :                 {
   16532        1544 :                     WindowDef  *n = makeNode(WindowDef);
   16533             : 
   16534        1544 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16535        1544 :                     n->startOffset = NULL;
   16536        1544 :                     n->endOffset = NULL;
   16537        1544 :                     $$ = n;
   16538             :                 }
   16539             :         ;
   16540             : 
   16541             : frame_extent: frame_bound
   16542             :                 {
   16543          12 :                     WindowDef  *n = $1;
   16544             : 
   16545             :                     /* reject invalid cases */
   16546          12 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16547           0 :                         ereport(ERROR,
   16548             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16549             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16550             :                                  parser_errposition(@1)));
   16551          12 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16552           0 :                         ereport(ERROR,
   16553             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16554             :                                  errmsg("frame starting from following row cannot end with current row"),
   16555             :                                  parser_errposition(@1)));
   16556          12 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16557          12 :                     $$ = n;
   16558             :                 }
   16559             :             | BETWEEN frame_bound AND frame_bound
   16560             :                 {
   16561        1612 :                     WindowDef  *n1 = $2;
   16562        1612 :                     WindowDef  *n2 = $4;
   16563             : 
   16564             :                     /* form merged options */
   16565        1612 :                     int     frameOptions = n1->frameOptions;
   16566             :                     /* shift converts START_ options to END_ options */
   16567        1612 :                     frameOptions |= n2->frameOptions << 1;
   16568        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16569             :                     /* reject invalid cases */
   16570        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16571           0 :                         ereport(ERROR,
   16572             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16573             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16574             :                                  parser_errposition(@2)));
   16575        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16576           0 :                         ereport(ERROR,
   16577             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16578             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16579             :                                  parser_errposition(@4)));
   16580        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16581         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16582           0 :                         ereport(ERROR,
   16583             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16584             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16585             :                                  parser_errposition(@4)));
   16586        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16587         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16588             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16589           0 :                         ereport(ERROR,
   16590             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16591             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16592             :                                  parser_errposition(@4)));
   16593        1612 :                     n1->frameOptions = frameOptions;
   16594        1612 :                     n1->endOffset = n2->startOffset;
   16595        1612 :                     $$ = n1;
   16596             :                 }
   16597             :         ;
   16598             : 
   16599             : /*
   16600             :  * This is used for both frame start and frame end, with output set up on
   16601             :  * the assumption it's frame start; the frame_extent productions must reject
   16602             :  * invalid cases.
   16603             :  */
   16604             : frame_bound:
   16605             :             UNBOUNDED PRECEDING
   16606             :                 {
   16607         198 :                     WindowDef  *n = makeNode(WindowDef);
   16608             : 
   16609         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16610         198 :                     n->startOffset = NULL;
   16611         198 :                     n->endOffset = NULL;
   16612         198 :                     $$ = n;
   16613             :                 }
   16614             :             | UNBOUNDED FOLLOWING
   16615             :                 {
   16616         376 :                     WindowDef  *n = makeNode(WindowDef);
   16617             : 
   16618         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16619         376 :                     n->startOffset = NULL;
   16620         376 :                     n->endOffset = NULL;
   16621         376 :                     $$ = n;
   16622             :                 }
   16623             :             | CURRENT_P ROW
   16624             :                 {
   16625         604 :                     WindowDef  *n = makeNode(WindowDef);
   16626             : 
   16627         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16628         604 :                     n->startOffset = NULL;
   16629         604 :                     n->endOffset = NULL;
   16630         604 :                     $$ = n;
   16631             :                 }
   16632             :             | a_expr PRECEDING
   16633             :                 {
   16634         906 :                     WindowDef  *n = makeNode(WindowDef);
   16635             : 
   16636         906 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16637         906 :                     n->startOffset = $1;
   16638         906 :                     n->endOffset = NULL;
   16639         906 :                     $$ = n;
   16640             :                 }
   16641             :             | a_expr FOLLOWING
   16642             :                 {
   16643        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16644             : 
   16645        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16646        1152 :                     n->startOffset = $1;
   16647        1152 :                     n->endOffset = NULL;
   16648        1152 :                     $$ = n;
   16649             :                 }
   16650             :         ;
   16651             : 
   16652             : opt_window_exclusion_clause:
   16653          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16654          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16655         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16656          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16657        1276 :             | /*EMPTY*/             { $$ = 0; }
   16658             :         ;
   16659             : 
   16660             : 
   16661             : /*
   16662             :  * Supporting nonterminals for expressions.
   16663             :  */
   16664             : 
   16665             : /* Explicit row production.
   16666             :  *
   16667             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16668             :  * without conflicting with the parenthesized a_expr production.  Without the
   16669             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16670             :  */
   16671           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16672           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16673        1932 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16674             :         ;
   16675             : 
   16676        3780 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16677          36 :             | ROW '(' ')'                           { $$ = NIL; }
   16678             :         ;
   16679             : 
   16680        2706 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16681             :         ;
   16682             : 
   16683       16698 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16684           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16685         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16686             :         ;
   16687             : 
   16688       11208 : all_Op:     Op                                      { $$ = $1; }
   16689       29086 :             | MathOp                                { $$ = $1; }
   16690             :         ;
   16691             : 
   16692          40 : MathOp:      '+'                                    { $$ = "+"; }
   16693          66 :             | '-'                                   { $$ = "-"; }
   16694         114 :             | '*'                                   { $$ = "*"; }
   16695           0 :             | '/'                                   { $$ = "/"; }
   16696           8 :             | '%'                                   { $$ = "%"; }
   16697           0 :             | '^'                                   { $$ = "^"; }
   16698         978 :             | '<'                                    { $$ = "<"; }
   16699         880 :             | '>'                                    { $$ = ">"; }
   16700       24538 :             | '='                                   { $$ = "="; }
   16701         844 :             | LESS_EQUALS                           { $$ = "<="; }
   16702         836 :             | GREATER_EQUALS                        { $$ = ">="; }
   16703         782 :             | NOT_EQUALS                            { $$ = "<>"; }
   16704             :         ;
   16705             : 
   16706             : qual_Op:    Op
   16707       43562 :                     { $$ = list_make1(makeString($1)); }
   16708             :             | OPERATOR '(' any_operator ')'
   16709       15462 :                     { $$ = $3; }
   16710             :         ;
   16711             : 
   16712             : qual_all_Op:
   16713             :             all_Op
   16714        1416 :                     { $$ = list_make1(makeString($1)); }
   16715             :             | OPERATOR '(' any_operator ')'
   16716          34 :                     { $$ = $3; }
   16717             :         ;
   16718             : 
   16719             : subquery_Op:
   16720             :             all_Op
   16721       16718 :                     { $$ = list_make1(makeString($1)); }
   16722             :             | OPERATOR '(' any_operator ')'
   16723         272 :                     { $$ = $3; }
   16724             :             | LIKE
   16725          24 :                     { $$ = list_make1(makeString("~~")); }
   16726             :             | NOT_LA LIKE
   16727          12 :                     { $$ = list_make1(makeString("!~~")); }
   16728             :             | ILIKE
   16729          12 :                     { $$ = list_make1(makeString("~~*")); }
   16730             :             | NOT_LA ILIKE
   16731           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16732             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16733             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16734             :  * and the ~ operator for posix regular expressions is used.
   16735             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16736             :  * this transformation is made on the fly by the parser upwards.
   16737             :  * however the SubLink structure which handles any/some/all stuff
   16738             :  * is not ready for such a thing.
   16739             :  */
   16740             :             ;
   16741             : 
   16742             : expr_list:  a_expr
   16743             :                 {
   16744      161154 :                     $$ = list_make1($1);
   16745             :                 }
   16746             :             | expr_list ',' a_expr
   16747             :                 {
   16748      145544 :                     $$ = lappend($1, $3);
   16749             :                 }
   16750             :         ;
   16751             : 
   16752             : /* function arguments can have names */
   16753             : func_arg_list:  func_arg_expr
   16754             :                 {
   16755      315400 :                     $$ = list_make1($1);
   16756             :                 }
   16757             :             | func_arg_list ',' func_arg_expr
   16758             :                 {
   16759      279346 :                     $$ = lappend($1, $3);
   16760             :                 }
   16761             :         ;
   16762             : 
   16763             : func_arg_expr:  a_expr
   16764             :                 {
   16765      548360 :                     $$ = $1;
   16766             :                 }
   16767             :             | param_name COLON_EQUALS a_expr
   16768             :                 {
   16769       45514 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16770             : 
   16771       45514 :                     na->name = $1;
   16772       45514 :                     na->arg = (Expr *) $3;
   16773       45514 :                     na->argnumber = -1;      /* until determined */
   16774       45514 :                     na->location = @1;
   16775       45514 :                     $$ = (Node *) na;
   16776             :                 }
   16777             :             | param_name EQUALS_GREATER a_expr
   16778             :                 {
   16779        1612 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16780             : 
   16781        1612 :                     na->name = $1;
   16782        1612 :                     na->arg = (Expr *) $3;
   16783        1612 :                     na->argnumber = -1;      /* until determined */
   16784        1612 :                     na->location = @1;
   16785        1612 :                     $$ = (Node *) na;
   16786             :                 }
   16787             :         ;
   16788             : 
   16789         252 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16790           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16791             :         ;
   16792             : 
   16793        2332 : type_list:  Typename                                { $$ = list_make1($1); }
   16794         936 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16795             :         ;
   16796             : 
   16797             : array_expr: '[' expr_list ']'
   16798             :                 {
   16799        7632 :                     $$ = makeAArrayExpr($2, @1, @3);
   16800             :                 }
   16801             :             | '[' array_expr_list ']'
   16802             :                 {
   16803         412 :                     $$ = makeAArrayExpr($2, @1, @3);
   16804             :                 }
   16805             :             | '[' ']'
   16806             :                 {
   16807          88 :                     $$ = makeAArrayExpr(NIL, @1, @2);
   16808             :                 }
   16809             :         ;
   16810             : 
   16811         412 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16812         342 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16813             :         ;
   16814             : 
   16815             : 
   16816             : extract_list:
   16817             :             extract_arg FROM a_expr
   16818             :                 {
   16819        1382 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16820             :                 }
   16821             :         ;
   16822             : 
   16823             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16824             :  * - thomas 2001-04-12
   16825             :  */
   16826             : extract_arg:
   16827        1124 :             IDENT                                   { $$ = $1; }
   16828          72 :             | YEAR_P                                { $$ = "year"; }
   16829          42 :             | MONTH_P                               { $$ = "month"; }
   16830          54 :             | DAY_P                                 { $$ = "day"; }
   16831          30 :             | HOUR_P                                { $$ = "hour"; }
   16832          30 :             | MINUTE_P                              { $$ = "minute"; }
   16833          30 :             | SECOND_P                              { $$ = "second"; }
   16834           0 :             | Sconst                                { $$ = $1; }
   16835             :         ;
   16836             : 
   16837             : unicode_normal_form:
   16838          24 :             NFC                                     { $$ = "NFC"; }
   16839          18 :             | NFD                                   { $$ = "NFD"; }
   16840          18 :             | NFKC                                  { $$ = "NFKC"; }
   16841          18 :             | NFKD                                  { $$ = "NFKD"; }
   16842             :         ;
   16843             : 
   16844             : /* OVERLAY() arguments */
   16845             : overlay_list:
   16846             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16847             :                 {
   16848             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16849          34 :                     $$ = list_make4($1, $3, $5, $7);
   16850             :                 }
   16851             :             | a_expr PLACING a_expr FROM a_expr
   16852             :                 {
   16853             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16854          48 :                     $$ = list_make3($1, $3, $5);
   16855             :                 }
   16856             :         ;
   16857             : 
   16858             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16859             : position_list:
   16860         400 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16861             :         ;
   16862             : 
   16863             : /*
   16864             :  * SUBSTRING() arguments
   16865             :  *
   16866             :  * Note that SQL:1999 has both
   16867             :  *     text FROM int FOR int
   16868             :  * and
   16869             :  *     text FROM pattern FOR escape
   16870             :  *
   16871             :  * In the parser we map them both to a call to the substring() function and
   16872             :  * rely on type resolution to pick the right one.
   16873             :  *
   16874             :  * In SQL:2003, the second variant was changed to
   16875             :  *     text SIMILAR pattern ESCAPE escape
   16876             :  * We could in theory map that to a different function internally, but
   16877             :  * since we still support the SQL:1999 version, we don't.  However,
   16878             :  * ruleutils.c will reverse-list the call in the newer style.
   16879             :  */
   16880             : substr_list:
   16881             :             a_expr FROM a_expr FOR a_expr
   16882             :                 {
   16883         122 :                     $$ = list_make3($1, $3, $5);
   16884             :                 }
   16885             :             | a_expr FOR a_expr FROM a_expr
   16886             :                 {
   16887             :                     /* not legal per SQL, but might as well allow it */
   16888           0 :                     $$ = list_make3($1, $5, $3);
   16889             :                 }
   16890             :             | a_expr FROM a_expr
   16891             :                 {
   16892             :                     /*
   16893             :                      * Because we aren't restricting data types here, this
   16894             :                      * syntax can end up resolving to textregexsubstr().
   16895             :                      * We've historically allowed that to happen, so continue
   16896             :                      * to accept it.  However, ruleutils.c will reverse-list
   16897             :                      * such a call in regular function call syntax.
   16898             :                      */
   16899         370 :                     $$ = list_make2($1, $3);
   16900             :                 }
   16901             :             | a_expr FOR a_expr
   16902             :                 {
   16903             :                     /* not legal per SQL */
   16904             : 
   16905             :                     /*
   16906             :                      * Since there are no cases where this syntax allows
   16907             :                      * a textual FOR value, we forcibly cast the argument
   16908             :                      * to int4.  The possible matches in pg_proc are
   16909             :                      * substring(text,int4) and substring(text,text),
   16910             :                      * and we don't want the parser to choose the latter,
   16911             :                      * which it is likely to do if the second argument
   16912             :                      * is unknown or doesn't have an implicit cast to int4.
   16913             :                      */
   16914          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16915             :                                     makeTypeCast($3,
   16916             :                                                  SystemTypeName("int4"), -1));
   16917             :                 }
   16918             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16919             :                 {
   16920         182 :                     $$ = list_make3($1, $3, $5);
   16921             :                 }
   16922             :         ;
   16923             : 
   16924         604 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16925          24 :             | FROM expr_list                        { $$ = $2; }
   16926          86 :             | expr_list                             { $$ = $1; }
   16927             :         ;
   16928             : 
   16929             : /*
   16930             :  * Define SQL-style CASE clause.
   16931             :  * - Full specification
   16932             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16933             :  * - Implicit argument
   16934             :  *  CASE a WHEN b THEN c ... ELSE d END
   16935             :  */
   16936             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16937             :                 {
   16938       39052 :                     CaseExpr   *c = makeNode(CaseExpr);
   16939             : 
   16940       39052 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16941       39052 :                     c->arg = (Expr *) $2;
   16942       39052 :                     c->args = $3;
   16943       39052 :                     c->defresult = (Expr *) $4;
   16944       39052 :                     c->location = @1;
   16945       39052 :                     $$ = (Node *) c;
   16946             :                 }
   16947             :         ;
   16948             : 
   16949             : when_clause_list:
   16950             :             /* There must be at least one */
   16951       39052 :             when_clause                             { $$ = list_make1($1); }
   16952       29052 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16953             :         ;
   16954             : 
   16955             : when_clause:
   16956             :             WHEN a_expr THEN a_expr
   16957             :                 {
   16958       68104 :                     CaseWhen   *w = makeNode(CaseWhen);
   16959             : 
   16960       68104 :                     w->expr = (Expr *) $2;
   16961       68104 :                     w->result = (Expr *) $4;
   16962       68104 :                     w->location = @1;
   16963       68104 :                     $$ = (Node *) w;
   16964             :                 }
   16965             :         ;
   16966             : 
   16967             : case_default:
   16968       29324 :             ELSE a_expr                             { $$ = $2; }
   16969        9728 :             | /*EMPTY*/                             { $$ = NULL; }
   16970             :         ;
   16971             : 
   16972        6758 : case_arg:   a_expr                                  { $$ = $1; }
   16973       32294 :             | /*EMPTY*/                             { $$ = NULL; }
   16974             :         ;
   16975             : 
   16976             : columnref:  ColId
   16977             :                 {
   16978      744512 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16979             :                 }
   16980             :             | ColId indirection
   16981             :                 {
   16982     1054346 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16983             :                 }
   16984             :         ;
   16985             : 
   16986             : indirection_el:
   16987             :             '.' attr_name
   16988             :                 {
   16989     1424346 :                     $$ = (Node *) makeString($2);
   16990             :                 }
   16991             :             | '.' '*'
   16992             :                 {
   16993        6972 :                     $$ = (Node *) makeNode(A_Star);
   16994             :                 }
   16995             :             | '[' a_expr ']'
   16996             :                 {
   16997       12874 :                     A_Indices *ai = makeNode(A_Indices);
   16998             : 
   16999       12874 :                     ai->is_slice = false;
   17000       12874 :                     ai->lidx = NULL;
   17001       12874 :                     ai->uidx = $2;
   17002       12874 :                     $$ = (Node *) ai;
   17003             :                 }
   17004             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   17005             :                 {
   17006         588 :                     A_Indices *ai = makeNode(A_Indices);
   17007             : 
   17008         588 :                     ai->is_slice = true;
   17009         588 :                     ai->lidx = $2;
   17010         588 :                     ai->uidx = $4;
   17011         588 :                     $$ = (Node *) ai;
   17012             :                 }
   17013             :         ;
   17014             : 
   17015             : opt_slice_bound:
   17016         996 :             a_expr                                  { $$ = $1; }
   17017         180 :             | /*EMPTY*/                             { $$ = NULL; }
   17018             :         ;
   17019             : 
   17020             : indirection:
   17021     1424296 :             indirection_el                          { $$ = list_make1($1); }
   17022        3084 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   17023             :         ;
   17024             : 
   17025             : opt_indirection:
   17026      194724 :             /*EMPTY*/                               { $$ = NIL; }
   17027       17400 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   17028             :         ;
   17029             : 
   17030             : opt_asymmetric: ASYMMETRIC
   17031             :             | /*EMPTY*/
   17032             :         ;
   17033             : 
   17034             : /* SQL/JSON support */
   17035             : json_passing_clause_opt:
   17036         336 :             PASSING json_arguments                  { $$ = $2; }
   17037        1940 :             | /*EMPTY*/                             { $$ = NIL; }
   17038             :         ;
   17039             : 
   17040             : json_arguments:
   17041         336 :             json_argument                           { $$ = list_make1($1); }
   17042         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17043             :         ;
   17044             : 
   17045             : json_argument:
   17046             :             json_value_expr AS ColLabel
   17047             :             {
   17048         462 :                 JsonArgument *n = makeNode(JsonArgument);
   17049             : 
   17050         462 :                 n->val = (JsonValueExpr *) $1;
   17051         462 :                 n->name = $3;
   17052         462 :                 $$ = (Node *) n;
   17053             :             }
   17054             :         ;
   17055             : 
   17056             : /* ARRAY is a noise word */
   17057             : json_wrapper_behavior:
   17058          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17059           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17060          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17061          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17062           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17063          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17064          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17065           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17066        1640 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17067             :         ;
   17068             : 
   17069             : json_behavior:
   17070             :             DEFAULT a_expr
   17071         384 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17072             :             | json_behavior_type
   17073         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17074             :         ;
   17075             : 
   17076             : json_behavior_type:
   17077         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17078          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17079          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17080          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17081          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17082          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17083          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17084             :             /* non-standard, for Oracle compatibility only */
   17085          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17086             :         ;
   17087             : 
   17088             : json_behavior_clause_opt:
   17089             :             json_behavior ON EMPTY_P
   17090         174 :                 { $$ = list_make2($1, NULL); }
   17091             :             | json_behavior ON ERROR_P
   17092         552 :                 { $$ = list_make2(NULL, $1); }
   17093             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17094         102 :                 { $$ = list_make2($1, $4); }
   17095             :             | /* EMPTY */
   17096        1574 :                 { $$ = list_make2(NULL, NULL); }
   17097             :         ;
   17098             : 
   17099             : json_on_error_clause_opt:
   17100             :             json_behavior ON ERROR_P
   17101         150 :                 { $$ = $1; }
   17102             :             | /* EMPTY */
   17103         692 :                 { $$ = NULL; }
   17104             :         ;
   17105             : 
   17106             : json_value_expr:
   17107             :             a_expr json_format_clause_opt
   17108             :             {
   17109             :                 /* formatted_expr will be set during parse-analysis. */
   17110        4208 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17111        4208 :                                                 castNode(JsonFormat, $2));
   17112             :             }
   17113             :         ;
   17114             : 
   17115             : json_format_clause:
   17116             :             FORMAT_LA JSON ENCODING name
   17117             :                 {
   17118             :                     int     encoding;
   17119             : 
   17120         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17121          64 :                         encoding = JS_ENC_UTF8;
   17122          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17123          12 :                         encoding = JS_ENC_UTF16;
   17124          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17125          12 :                         encoding = JS_ENC_UTF32;
   17126             :                     else
   17127          12 :                         ereport(ERROR,
   17128             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17129             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17130             :                                  parser_errposition(@4)));
   17131             : 
   17132          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17133             :                 }
   17134             :             | FORMAT_LA JSON
   17135             :                 {
   17136         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17137             :                 }
   17138             :         ;
   17139             : 
   17140             : json_format_clause_opt:
   17141             :             json_format_clause
   17142             :                 {
   17143         392 :                     $$ = $1;
   17144             :                 }
   17145             :             | /* EMPTY */
   17146             :                 {
   17147        5320 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17148             :                 }
   17149             :         ;
   17150             : 
   17151             : json_quotes_clause_opt:
   17152          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17153          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17154          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17155         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17156        1544 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17157             :         ;
   17158             : 
   17159             : json_returning_clause_opt:
   17160             :             RETURNING Typename json_format_clause_opt
   17161             :                 {
   17162        1444 :                     JsonOutput *n = makeNode(JsonOutput);
   17163             : 
   17164        1444 :                     n->typeName = $2;
   17165        1444 :                     n->returning = makeNode(JsonReturning);
   17166        1444 :                     n->returning->format = (JsonFormat *) $3;
   17167        1444 :                     $$ = (Node *) n;
   17168             :                 }
   17169        1278 :             | /* EMPTY */                           { $$ = NULL; }
   17170             :         ;
   17171             : 
   17172             : /*
   17173             :  * We must assign the only-JSON production a precedence less than IDENT in
   17174             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17175             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17176             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17177             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17178             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17179             :  * really related to this syntax, but it's a convenient choice because it
   17180             :  * already has a precedence less than IDENT for other reasons.
   17181             :  */
   17182             : json_predicate_type_constraint:
   17183         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17184          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17185          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17186          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17187          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17188             :         ;
   17189             : 
   17190             : /*
   17191             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17192             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17193             :  * This prevents reducing them when the next token is KEYS.
   17194             :  */
   17195             : json_key_uniqueness_constraint_opt:
   17196         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17197         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17198          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17199          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17200         798 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17201             :         ;
   17202             : 
   17203             : json_name_and_value_list:
   17204             :             json_name_and_value
   17205         348 :                 { $$ = list_make1($1); }
   17206             :             | json_name_and_value_list ',' json_name_and_value
   17207         256 :                 { $$ = lappend($1, $3); }
   17208             :         ;
   17209             : 
   17210             : json_name_and_value:
   17211             : /* Supporting this syntax seems to require major surgery
   17212             :             KEY c_expr VALUE_P json_value_expr
   17213             :                 { $$ = makeJsonKeyValue($2, $4); }
   17214             :             |
   17215             : */
   17216             :             c_expr VALUE_P json_value_expr
   17217          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17218             :             |
   17219             :             a_expr ':' json_value_expr
   17220         784 :                 { $$ = makeJsonKeyValue($1, $3); }
   17221             :         ;
   17222             : 
   17223             : /* empty means false for objects, true for arrays */
   17224             : json_object_constructor_null_clause_opt:
   17225          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17226         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17227         412 :             | /* EMPTY */                       { $$ = false; }
   17228             :         ;
   17229             : 
   17230             : json_array_constructor_null_clause_opt:
   17231          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17232          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17233         168 :             | /* EMPTY */                           { $$ = true; }
   17234             :         ;
   17235             : 
   17236             : json_value_expr_list:
   17237         108 :             json_value_expr                             { $$ = list_make1($1); }
   17238         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17239             :         ;
   17240             : 
   17241             : json_aggregate_func:
   17242             :             JSON_OBJECTAGG '('
   17243             :                 json_name_and_value
   17244             :                 json_object_constructor_null_clause_opt
   17245             :                 json_key_uniqueness_constraint_opt
   17246             :                 json_returning_clause_opt
   17247             :             ')'
   17248             :                 {
   17249         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17250             : 
   17251         204 :                     n->arg = (JsonKeyValue *) $3;
   17252         204 :                     n->absent_on_null = $4;
   17253         204 :                     n->unique = $5;
   17254         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17255         204 :                     n->constructor->output = (JsonOutput *) $6;
   17256         204 :                     n->constructor->agg_order = NULL;
   17257         204 :                     n->constructor->location = @1;
   17258         204 :                     $$ = (Node *) n;
   17259             :                 }
   17260             :             | JSON_ARRAYAGG '('
   17261             :                 json_value_expr
   17262             :                 json_array_aggregate_order_by_clause_opt
   17263             :                 json_array_constructor_null_clause_opt
   17264             :                 json_returning_clause_opt
   17265             :             ')'
   17266             :                 {
   17267         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17268             : 
   17269         156 :                     n->arg = (JsonValueExpr *) $3;
   17270         156 :                     n->absent_on_null = $5;
   17271         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17272         156 :                     n->constructor->agg_order = $4;
   17273         156 :                     n->constructor->output = (JsonOutput *) $6;
   17274         156 :                     n->constructor->location = @1;
   17275         156 :                     $$ = (Node *) n;
   17276             :                 }
   17277             :         ;
   17278             : 
   17279             : json_array_aggregate_order_by_clause_opt:
   17280          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17281         138 :             | /* EMPTY */                           { $$ = NIL; }
   17282             :         ;
   17283             : 
   17284             : /*****************************************************************************
   17285             :  *
   17286             :  *  target list for SELECT
   17287             :  *
   17288             :  *****************************************************************************/
   17289             : 
   17290      466918 : opt_target_list: target_list                        { $$ = $1; }
   17291         546 :             | /* EMPTY */                           { $$ = NIL; }
   17292             :         ;
   17293             : 
   17294             : target_list:
   17295      473734 :             target_el                               { $$ = list_make1($1); }
   17296      672148 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17297             :         ;
   17298             : 
   17299             : target_el:  a_expr AS ColLabel
   17300             :                 {
   17301      234644 :                     $$ = makeNode(ResTarget);
   17302      234644 :                     $$->name = $3;
   17303      234644 :                     $$->indirection = NIL;
   17304      234644 :                     $$->val = (Node *) $1;
   17305      234644 :                     $$->location = @1;
   17306             :                 }
   17307             :             | a_expr BareColLabel
   17308             :                 {
   17309        3520 :                     $$ = makeNode(ResTarget);
   17310        3520 :                     $$->name = $2;
   17311        3520 :                     $$->indirection = NIL;
   17312        3520 :                     $$->val = (Node *) $1;
   17313        3520 :                     $$->location = @1;
   17314             :                 }
   17315             :             | a_expr
   17316             :                 {
   17317      851418 :                     $$ = makeNode(ResTarget);
   17318      851414 :                     $$->name = NULL;
   17319      851414 :                     $$->indirection = NIL;
   17320      851414 :                     $$->val = (Node *) $1;
   17321      851414 :                     $$->location = @1;
   17322             :                 }
   17323             :             | '*'
   17324             :                 {
   17325       56300 :                     ColumnRef  *n = makeNode(ColumnRef);
   17326             : 
   17327       56300 :                     n->fields = list_make1(makeNode(A_Star));
   17328       56300 :                     n->location = @1;
   17329             : 
   17330       56300 :                     $$ = makeNode(ResTarget);
   17331       56300 :                     $$->name = NULL;
   17332       56300 :                     $$->indirection = NIL;
   17333       56300 :                     $$->val = (Node *) n;
   17334       56300 :                     $$->location = @1;
   17335             :                 }
   17336             :         ;
   17337             : 
   17338             : 
   17339             : /*****************************************************************************
   17340             :  *
   17341             :  *  Names and constants
   17342             :  *
   17343             :  *****************************************************************************/
   17344             : 
   17345             : qualified_name_list:
   17346       17520 :             qualified_name                          { $$ = list_make1($1); }
   17347         454 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17348             :         ;
   17349             : 
   17350             : /*
   17351             :  * The production for a qualified relation name has to exactly match the
   17352             :  * production for a qualified func_name, because in a FROM clause we cannot
   17353             :  * tell which we are parsing until we see what comes after it ('(' for a
   17354             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17355             :  * which may contain subscripts, and reject that case in the C code.
   17356             :  */
   17357             : qualified_name:
   17358             :             ColId
   17359             :                 {
   17360      419318 :                     $$ = makeRangeVar(NULL, $1, @1);
   17361             :                 }
   17362             :             | ColId indirection
   17363             :                 {
   17364      243844 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17365             :                 }
   17366             :         ;
   17367             : 
   17368             : name_list:  name
   17369       28248 :                     { $$ = list_make1(makeString($1)); }
   17370             :             | name_list ',' name
   17371       61542 :                     { $$ = lappend($1, makeString($3)); }
   17372             :         ;
   17373             : 
   17374             : 
   17375      176330 : name:       ColId                                   { $$ = $1; };
   17376             : 
   17377     1549624 : attr_name:  ColLabel                                { $$ = $1; };
   17378             : 
   17379          54 : file_name:  Sconst                                  { $$ = $1; };
   17380             : 
   17381             : /*
   17382             :  * The production for a qualified func_name has to exactly match the
   17383             :  * production for a qualified columnref, because we cannot tell which we
   17384             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17385             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17386             :  * may contain subscripts, and reject that case in the C code.  (If we
   17387             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17388             :  */
   17389             : func_name:  type_function_name
   17390      293258 :                     { $$ = list_make1(makeString($1)); }
   17391             :             | ColId indirection
   17392             :                     {
   17393      126028 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17394             :                                              yyscanner);
   17395             :                     }
   17396             :         ;
   17397             : 
   17398             : 
   17399             : /*
   17400             :  * Constants
   17401             :  */
   17402             : AexprConst: Iconst
   17403             :                 {
   17404      375574 :                     $$ = makeIntConst($1, @1);
   17405             :                 }
   17406             :             | FCONST
   17407             :                 {
   17408       11404 :                     $$ = makeFloatConst($1, @1);
   17409             :                 }
   17410             :             | Sconst
   17411             :                 {
   17412      691284 :                     $$ = makeStringConst($1, @1);
   17413             :                 }
   17414             :             | BCONST
   17415             :                 {
   17416         754 :                     $$ = makeBitStringConst($1, @1);
   17417             :                 }
   17418             :             | XCONST
   17419             :                 {
   17420             :                     /* This is a bit constant per SQL99:
   17421             :                      * Without Feature F511, "BIT data type",
   17422             :                      * a <general literal> shall not be a
   17423             :                      * <bit string literal> or a <hex string literal>.
   17424             :                      */
   17425        3302 :                     $$ = makeBitStringConst($1, @1);
   17426             :                 }
   17427             :             | func_name Sconst
   17428             :                 {
   17429             :                     /* generic type 'literal' syntax */
   17430        9842 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17431             : 
   17432        9842 :                     t->location = @1;
   17433        9842 :                     $$ = makeStringConstCast($2, @2, t);
   17434             :                 }
   17435             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17436             :                 {
   17437             :                     /* generic syntax with a type modifier */
   17438           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17439             :                     ListCell   *lc;
   17440             : 
   17441             :                     /*
   17442             :                      * We must use func_arg_list and opt_sort_clause in the
   17443             :                      * production to avoid reduce/reduce conflicts, but we
   17444             :                      * don't actually wish to allow NamedArgExpr in this
   17445             :                      * context, nor ORDER BY.
   17446             :                      */
   17447           0 :                     foreach(lc, $3)
   17448             :                     {
   17449           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17450             : 
   17451           0 :                         if (IsA(arg, NamedArgExpr))
   17452           0 :                             ereport(ERROR,
   17453             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17454             :                                      errmsg("type modifier cannot have parameter name"),
   17455             :                                      parser_errposition(arg->location)));
   17456             :                     }
   17457           0 :                     if ($4 != NIL)
   17458           0 :                             ereport(ERROR,
   17459             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17460             :                                      errmsg("type modifier cannot have ORDER BY"),
   17461             :                                      parser_errposition(@4)));
   17462             : 
   17463           0 :                     t->typmods = $3;
   17464           0 :                     t->location = @1;
   17465           0 :                     $$ = makeStringConstCast($6, @6, t);
   17466             :                 }
   17467             :             | ConstTypename Sconst
   17468             :                 {
   17469        3174 :                     $$ = makeStringConstCast($2, @2, $1);
   17470             :                 }
   17471             :             | ConstInterval Sconst opt_interval
   17472             :                 {
   17473        3298 :                     TypeName   *t = $1;
   17474             : 
   17475        3298 :                     t->typmods = $3;
   17476        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17477             :                 }
   17478             :             | ConstInterval '(' Iconst ')' Sconst
   17479             :                 {
   17480          12 :                     TypeName   *t = $1;
   17481             : 
   17482          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17483             :                                             makeIntConst($3, @3));
   17484          12 :                     $$ = makeStringConstCast($5, @5, t);
   17485             :                 }
   17486             :             | TRUE_P
   17487             :                 {
   17488       31118 :                     $$ = makeBoolAConst(true, @1);
   17489             :                 }
   17490             :             | FALSE_P
   17491             :                 {
   17492       35678 :                     $$ = makeBoolAConst(false, @1);
   17493             :                 }
   17494             :             | NULL_P
   17495             :                 {
   17496       66950 :                     $$ = makeNullAConst(@1);
   17497             :                 }
   17498             :         ;
   17499             : 
   17500      403702 : Iconst:     ICONST                                  { $$ = $1; };
   17501      764206 : Sconst:     SCONST                                  { $$ = $1; };
   17502             : 
   17503       17380 : SignedIconst: Iconst                                { $$ = $1; }
   17504           0 :             | '+' Iconst                            { $$ = + $2; }
   17505         288 :             | '-' Iconst                            { $$ = - $2; }
   17506             :         ;
   17507             : 
   17508             : /* Role specifications */
   17509             : RoleId:     RoleSpec
   17510             :                 {
   17511        1902 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17512             : 
   17513        1902 :                     switch (spc->roletype)
   17514             :                     {
   17515        1892 :                         case ROLESPEC_CSTRING:
   17516        1892 :                             $$ = spc->rolename;
   17517        1892 :                             break;
   17518           4 :                         case ROLESPEC_PUBLIC:
   17519           4 :                             ereport(ERROR,
   17520             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17521             :                                      errmsg("role name \"%s\" is reserved",
   17522             :                                             "public"),
   17523             :                                      parser_errposition(@1)));
   17524             :                             break;
   17525           2 :                         case ROLESPEC_SESSION_USER:
   17526           2 :                             ereport(ERROR,
   17527             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17528             :                                      errmsg("%s cannot be used as a role name here",
   17529             :                                             "SESSION_USER"),
   17530             :                                      parser_errposition(@1)));
   17531             :                             break;
   17532           2 :                         case ROLESPEC_CURRENT_USER:
   17533           2 :                             ereport(ERROR,
   17534             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17535             :                                      errmsg("%s cannot be used as a role name here",
   17536             :                                             "CURRENT_USER"),
   17537             :                                      parser_errposition(@1)));
   17538             :                             break;
   17539           2 :                         case ROLESPEC_CURRENT_ROLE:
   17540           2 :                             ereport(ERROR,
   17541             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17542             :                                      errmsg("%s cannot be used as a role name here",
   17543             :                                             "CURRENT_ROLE"),
   17544             :                                      parser_errposition(@1)));
   17545             :                             break;
   17546             :                     }
   17547             :                 }
   17548             :             ;
   17549             : 
   17550             : RoleSpec:   NonReservedWord
   17551             :                 {
   17552             :                     /*
   17553             :                      * "public" and "none" are not keywords, but they must
   17554             :                      * be treated specially here.
   17555             :                      */
   17556             :                     RoleSpec   *n;
   17557             : 
   17558       32608 :                     if (strcmp($1, "public") == 0)
   17559             :                     {
   17560       17786 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17561       17786 :                         n->roletype = ROLESPEC_PUBLIC;
   17562             :                     }
   17563       14822 :                     else if (strcmp($1, "none") == 0)
   17564             :                     {
   17565          26 :                         ereport(ERROR,
   17566             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17567             :                                  errmsg("role name \"%s\" is reserved",
   17568             :                                         "none"),
   17569             :                                  parser_errposition(@1)));
   17570             :                     }
   17571             :                     else
   17572             :                     {
   17573       14796 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17574       14796 :                         n->rolename = pstrdup($1);
   17575             :                     }
   17576       32582 :                     $$ = n;
   17577             :                 }
   17578             :             | CURRENT_ROLE
   17579             :                 {
   17580         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17581             :                 }
   17582             :             | CURRENT_USER
   17583             :                 {
   17584         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17585             :                 }
   17586             :             | SESSION_USER
   17587             :                 {
   17588          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17589             :                 }
   17590             :         ;
   17591             : 
   17592             : role_list:  RoleSpec
   17593        3266 :                 { $$ = list_make1($1); }
   17594             :             | role_list ',' RoleSpec
   17595         270 :                 { $$ = lappend($1, $3); }
   17596             :         ;
   17597             : 
   17598             : 
   17599             : /*****************************************************************************
   17600             :  *
   17601             :  * PL/pgSQL extensions
   17602             :  *
   17603             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17604             :  * historically it can include just about anything that can follow SELECT.
   17605             :  * Therefore the returned struct is a SelectStmt.
   17606             :  *****************************************************************************/
   17607             : 
   17608             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17609             :             from_clause where_clause
   17610             :             group_clause having_clause window_clause
   17611             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17612             :                 {
   17613       40390 :                     SelectStmt *n = makeNode(SelectStmt);
   17614             : 
   17615       40390 :                     n->distinctClause = $1;
   17616       40390 :                     n->targetList = $2;
   17617       40390 :                     n->fromClause = $3;
   17618       40390 :                     n->whereClause = $4;
   17619       40390 :                     n->groupClause = ($5)->list;
   17620       40390 :                     n->groupDistinct = ($5)->distinct;
   17621       40390 :                     n->havingClause = $6;
   17622       40390 :                     n->windowClause = $7;
   17623       40390 :                     n->sortClause = $8;
   17624       40390 :                     if ($9)
   17625             :                     {
   17626           4 :                         n->limitOffset = $9->limitOffset;
   17627           4 :                         n->limitCount = $9->limitCount;
   17628           4 :                         if (!n->sortClause &&
   17629           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17630           0 :                             ereport(ERROR,
   17631             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17632             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17633             :                                      parser_errposition($9->optionLoc)));
   17634           4 :                         n->limitOption = $9->limitOption;
   17635             :                     }
   17636       40390 :                     n->lockingClause = $10;
   17637       40390 :                     $$ = (Node *) n;
   17638             :                 }
   17639             :         ;
   17640             : 
   17641             : /*
   17642             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17643             :  */
   17644             : 
   17645             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17646             :                 {
   17647        7044 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17648             : 
   17649        7044 :                     n->name = $1;
   17650        7044 :                     n->indirection = check_indirection($2, yyscanner);
   17651             :                     /* nnames will be filled by calling production */
   17652        6876 :                     n->val = (SelectStmt *) $4;
   17653        6876 :                     n->location = @1;
   17654        6876 :                     $$ = (Node *) n;
   17655             :                 }
   17656             :         ;
   17657             : 
   17658        7020 : plassign_target: ColId                          { $$ = $1; }
   17659          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17660             :         ;
   17661             : 
   17662             : plassign_equals: COLON_EQUALS
   17663             :             | '='
   17664             :         ;
   17665             : 
   17666             : 
   17667             : /*
   17668             :  * Name classification hierarchy.
   17669             :  *
   17670             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17671             :  * no known keyword.  In most cases, we can accept certain keywords as
   17672             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17673             :  * as possible to minimize the impact of "reserved words" on programmers.
   17674             :  * So, we divide names into several possible classes.  The classification
   17675             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17676             :  */
   17677             : 
   17678             : /* Column identifier --- names that can be column, table, etc names.
   17679             :  */
   17680     3351656 : ColId:      IDENT                                   { $$ = $1; }
   17681       57706 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17682        6172 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17683             :         ;
   17684             : 
   17685             : /* Type/function identifier --- names that can be type or function names.
   17686             :  */
   17687      707516 : type_function_name: IDENT                           { $$ = $1; }
   17688       74326 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17689          66 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17690             :         ;
   17691             : 
   17692             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17693             :  */
   17694       83286 : NonReservedWord:    IDENT                           { $$ = $1; }
   17695       30242 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17696         178 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17697        5266 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17698             :         ;
   17699             : 
   17700             : /* Column label --- allowed labels in "AS" clauses.
   17701             :  * This presently includes *all* Postgres keywords.
   17702             :  */
   17703     1768296 : ColLabel:   IDENT                                   { $$ = $1; }
   17704       39794 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17705         284 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17706        1778 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17707        7510 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17708             :         ;
   17709             : 
   17710             : /* Bare column label --- names that can be column labels without writing "AS".
   17711             :  * This classification is orthogonal to the other keyword categories.
   17712             :  */
   17713        3506 : BareColLabel:   IDENT                               { $$ = $1; }
   17714          14 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17715             :         ;
   17716             : 
   17717             : 
   17718             : /*
   17719             :  * Keyword category lists.  Generally, every keyword present in
   17720             :  * the Postgres grammar should appear in exactly one of these lists.
   17721             :  *
   17722             :  * Put a new keyword into the first list that it can go into without causing
   17723             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17724             :  * categories of keywords.
   17725             :  *
   17726             :  * Make sure that each keyword's category in kwlist.h matches where
   17727             :  * it is listed here.  (Someday we may be able to generate these lists and
   17728             :  * kwlist.h's table from one source of truth.)
   17729             :  */
   17730             : 
   17731             : /* "Unreserved" keywords --- available for use as any kind of name.
   17732             :  */
   17733             : unreserved_keyword:
   17734             :               ABORT_P
   17735             :             | ABSENT
   17736             :             | ABSOLUTE_P
   17737             :             | ACCESS
   17738             :             | ACTION
   17739             :             | ADD_P
   17740             :             | ADMIN
   17741             :             | AFTER
   17742             :             | AGGREGATE
   17743             :             | ALSO
   17744             :             | ALTER
   17745             :             | ALWAYS
   17746             :             | ASENSITIVE
   17747             :             | ASSERTION
   17748             :             | ASSIGNMENT
   17749             :             | AT
   17750             :             | ATOMIC
   17751             :             | ATTACH
   17752             :             | ATTRIBUTE
   17753             :             | BACKWARD
   17754             :             | BEFORE
   17755             :             | BEGIN_P
   17756             :             | BREADTH
   17757             :             | BY
   17758             :             | CACHE
   17759             :             | CALL
   17760             :             | CALLED
   17761             :             | CASCADE
   17762             :             | CASCADED
   17763             :             | CATALOG_P
   17764             :             | CHAIN
   17765             :             | CHARACTERISTICS
   17766             :             | CHECKPOINT
   17767             :             | CLASS
   17768             :             | CLOSE
   17769             :             | CLUSTER
   17770             :             | COLUMNS
   17771             :             | COMMENT
   17772             :             | COMMENTS
   17773             :             | COMMIT
   17774             :             | COMMITTED
   17775             :             | COMPRESSION
   17776             :             | CONDITIONAL
   17777             :             | CONFIGURATION
   17778             :             | CONFLICT
   17779             :             | CONNECTION
   17780             :             | CONSTRAINTS
   17781             :             | CONTENT_P
   17782             :             | CONTINUE_P
   17783             :             | CONVERSION_P
   17784             :             | COPY
   17785             :             | COST
   17786             :             | CSV
   17787             :             | CUBE
   17788             :             | CURRENT_P
   17789             :             | CURSOR
   17790             :             | CYCLE
   17791             :             | DATA_P
   17792             :             | DATABASE
   17793             :             | DAY_P
   17794             :             | DEALLOCATE
   17795             :             | DECLARE
   17796             :             | DEFAULTS
   17797             :             | DEFERRED
   17798             :             | DEFINER
   17799             :             | DELETE_P
   17800             :             | DELIMITER
   17801             :             | DELIMITERS
   17802             :             | DEPENDS
   17803             :             | DEPTH
   17804             :             | DETACH
   17805             :             | DICTIONARY
   17806             :             | DISABLE_P
   17807             :             | DISCARD
   17808             :             | DOCUMENT_P
   17809             :             | DOMAIN_P
   17810             :             | DOUBLE_P
   17811             :             | DROP
   17812             :             | EACH
   17813             :             | EMPTY_P
   17814             :             | ENABLE_P
   17815             :             | ENCODING
   17816             :             | ENCRYPTED
   17817             :             | ENFORCED
   17818             :             | ENUM_P
   17819             :             | ERROR_P
   17820             :             | ESCAPE
   17821             :             | EVENT
   17822             :             | EXCLUDE
   17823             :             | EXCLUDING
   17824             :             | EXCLUSIVE
   17825             :             | EXECUTE
   17826             :             | EXPLAIN
   17827             :             | EXPRESSION
   17828             :             | EXTENSION
   17829             :             | EXTERNAL
   17830             :             | FAMILY
   17831             :             | FILTER
   17832             :             | FINALIZE
   17833             :             | FIRST_P
   17834             :             | FOLLOWING
   17835             :             | FORCE
   17836             :             | FORMAT
   17837             :             | FORWARD
   17838             :             | FUNCTION
   17839             :             | FUNCTIONS
   17840             :             | GENERATED
   17841             :             | GLOBAL
   17842             :             | GRANTED
   17843             :             | GROUPS
   17844             :             | HANDLER
   17845             :             | HEADER_P
   17846             :             | HOLD
   17847             :             | HOUR_P
   17848             :             | IDENTITY_P
   17849             :             | IF_P
   17850             :             | IMMEDIATE
   17851             :             | IMMUTABLE
   17852             :             | IMPLICIT_P
   17853             :             | IMPORT_P
   17854             :             | INCLUDE
   17855             :             | INCLUDING
   17856             :             | INCREMENT
   17857             :             | INDENT
   17858             :             | INDEX
   17859             :             | INDEXES
   17860             :             | INHERIT
   17861             :             | INHERITS
   17862             :             | INLINE_P
   17863             :             | INPUT_P
   17864             :             | INSENSITIVE
   17865             :             | INSERT
   17866             :             | INSTEAD
   17867             :             | INVOKER
   17868             :             | ISOLATION
   17869             :             | KEEP
   17870             :             | KEY
   17871             :             | KEYS
   17872             :             | LABEL
   17873             :             | LANGUAGE
   17874             :             | LARGE_P
   17875             :             | LAST_P
   17876             :             | LEAKPROOF
   17877             :             | LEVEL
   17878             :             | LISTEN
   17879             :             | LOAD
   17880             :             | LOCAL
   17881             :             | LOCATION
   17882             :             | LOCK_P
   17883             :             | LOCKED
   17884             :             | LOGGED
   17885             :             | MAPPING
   17886             :             | MATCH
   17887             :             | MATCHED
   17888             :             | MATERIALIZED
   17889             :             | MAXVALUE
   17890             :             | MERGE
   17891             :             | METHOD
   17892             :             | MINUTE_P
   17893             :             | MINVALUE
   17894             :             | MODE
   17895             :             | MONTH_P
   17896             :             | MOVE
   17897             :             | NAME_P
   17898             :             | NAMES
   17899             :             | NESTED
   17900             :             | NEW
   17901             :             | NEXT
   17902             :             | NFC
   17903             :             | NFD
   17904             :             | NFKC
   17905             :             | NFKD
   17906             :             | NO
   17907             :             | NORMALIZED
   17908             :             | NOTHING
   17909             :             | NOTIFY
   17910             :             | NOWAIT
   17911             :             | NULLS_P
   17912             :             | OBJECT_P
   17913             :             | OBJECTS_P
   17914             :             | OF
   17915             :             | OFF
   17916             :             | OIDS
   17917             :             | OLD
   17918             :             | OMIT
   17919             :             | OPERATOR
   17920             :             | OPTION
   17921             :             | OPTIONS
   17922             :             | ORDINALITY
   17923             :             | OTHERS
   17924             :             | OVER
   17925             :             | OVERRIDING
   17926             :             | OWNED
   17927             :             | OWNER
   17928             :             | PARALLEL
   17929             :             | PARAMETER
   17930             :             | PARSER
   17931             :             | PARTIAL
   17932             :             | PARTITION
   17933             :             | PASSING
   17934             :             | PASSWORD
   17935             :             | PATH
   17936             :             | PERIOD
   17937             :             | PLAN
   17938             :             | PLANS
   17939             :             | POLICY
   17940             :             | PRECEDING
   17941             :             | PREPARE
   17942             :             | PREPARED
   17943             :             | PRESERVE
   17944             :             | PRIOR
   17945             :             | PRIVILEGES
   17946             :             | PROCEDURAL
   17947             :             | PROCEDURE
   17948             :             | PROCEDURES
   17949             :             | PROGRAM
   17950             :             | PUBLICATION
   17951             :             | QUOTE
   17952             :             | QUOTES
   17953             :             | RANGE
   17954             :             | READ
   17955             :             | REASSIGN
   17956             :             | RECURSIVE
   17957             :             | REF_P
   17958             :             | REFERENCING
   17959             :             | REFRESH
   17960             :             | REINDEX
   17961             :             | RELATIVE_P
   17962             :             | RELEASE
   17963             :             | RENAME
   17964             :             | REPEATABLE
   17965             :             | REPLACE
   17966             :             | REPLICA
   17967             :             | RESET
   17968             :             | RESTART
   17969             :             | RESTRICT
   17970             :             | RETURN
   17971             :             | RETURNS
   17972             :             | REVOKE
   17973             :             | ROLE
   17974             :             | ROLLBACK
   17975             :             | ROLLUP
   17976             :             | ROUTINE
   17977             :             | ROUTINES
   17978             :             | ROWS
   17979             :             | RULE
   17980             :             | SAVEPOINT
   17981             :             | SCALAR
   17982             :             | SCHEMA
   17983             :             | SCHEMAS
   17984             :             | SCROLL
   17985             :             | SEARCH
   17986             :             | SECOND_P
   17987             :             | SECURITY
   17988             :             | SEQUENCE
   17989             :             | SEQUENCES
   17990             :             | SERIALIZABLE
   17991             :             | SERVER
   17992             :             | SESSION
   17993             :             | SET
   17994             :             | SETS
   17995             :             | SHARE
   17996             :             | SHOW
   17997             :             | SIMPLE
   17998             :             | SKIP
   17999             :             | SNAPSHOT
   18000             :             | SOURCE
   18001             :             | SQL_P
   18002             :             | STABLE
   18003             :             | STANDALONE_P
   18004             :             | START
   18005             :             | STATEMENT
   18006             :             | STATISTICS
   18007             :             | STDIN
   18008             :             | STDOUT
   18009             :             | STORAGE
   18010             :             | STORED
   18011             :             | STRICT_P
   18012             :             | STRING_P
   18013             :             | STRIP_P
   18014             :             | SUBSCRIPTION
   18015             :             | SUPPORT
   18016             :             | SYSID
   18017             :             | SYSTEM_P
   18018             :             | TABLES
   18019             :             | TABLESPACE
   18020             :             | TARGET
   18021             :             | TEMP
   18022             :             | TEMPLATE
   18023             :             | TEMPORARY
   18024             :             | TEXT_P
   18025             :             | TIES
   18026             :             | TRANSACTION
   18027             :             | TRANSFORM
   18028             :             | TRIGGER
   18029             :             | TRUNCATE
   18030             :             | TRUSTED
   18031             :             | TYPE_P
   18032             :             | TYPES_P
   18033             :             | UESCAPE
   18034             :             | UNBOUNDED
   18035             :             | UNCOMMITTED
   18036             :             | UNCONDITIONAL
   18037             :             | UNENCRYPTED
   18038             :             | UNKNOWN
   18039             :             | UNLISTEN
   18040             :             | UNLOGGED
   18041             :             | UNTIL
   18042             :             | UPDATE
   18043             :             | VACUUM
   18044             :             | VALID
   18045             :             | VALIDATE
   18046             :             | VALIDATOR
   18047             :             | VALUE_P
   18048             :             | VARYING
   18049             :             | VERSION_P
   18050             :             | VIEW
   18051             :             | VIEWS
   18052             :             | VIRTUAL
   18053             :             | VOLATILE
   18054             :             | WHITESPACE_P
   18055             :             | WITHIN
   18056             :             | WITHOUT
   18057             :             | WORK
   18058             :             | WRAPPER
   18059             :             | WRITE
   18060             :             | XML_P
   18061             :             | YEAR_P
   18062             :             | YES_P
   18063             :             | ZONE
   18064             :         ;
   18065             : 
   18066             : /* Column identifier --- keywords that can be column, table, etc names.
   18067             :  *
   18068             :  * Many of these keywords will in fact be recognized as type or function
   18069             :  * names too; but they have special productions for the purpose, and so
   18070             :  * can't be treated as "generic" type or function names.
   18071             :  *
   18072             :  * The type names appearing here are not usable as function names
   18073             :  * because they can be followed by '(' in typename productions, which
   18074             :  * looks too much like a function call for an LR(1) parser.
   18075             :  */
   18076             : col_name_keyword:
   18077             :               BETWEEN
   18078             :             | BIGINT
   18079             :             | BIT
   18080             :             | BOOLEAN_P
   18081             :             | CHAR_P
   18082             :             | CHARACTER
   18083             :             | COALESCE
   18084             :             | DEC
   18085             :             | DECIMAL_P
   18086             :             | EXISTS
   18087             :             | EXTRACT
   18088             :             | FLOAT_P
   18089             :             | GREATEST
   18090             :             | GROUPING
   18091             :             | INOUT
   18092             :             | INT_P
   18093             :             | INTEGER
   18094             :             | INTERVAL
   18095             :             | JSON
   18096             :             | JSON_ARRAY
   18097             :             | JSON_ARRAYAGG
   18098             :             | JSON_EXISTS
   18099             :             | JSON_OBJECT
   18100             :             | JSON_OBJECTAGG
   18101             :             | JSON_QUERY
   18102             :             | JSON_SCALAR
   18103             :             | JSON_SERIALIZE
   18104             :             | JSON_TABLE
   18105             :             | JSON_VALUE
   18106             :             | LEAST
   18107             :             | MERGE_ACTION
   18108             :             | NATIONAL
   18109             :             | NCHAR
   18110             :             | NONE
   18111             :             | NORMALIZE
   18112             :             | NULLIF
   18113             :             | NUMERIC
   18114             :             | OUT_P
   18115             :             | OVERLAY
   18116             :             | POSITION
   18117             :             | PRECISION
   18118             :             | REAL
   18119             :             | ROW
   18120             :             | SETOF
   18121             :             | SMALLINT
   18122             :             | SUBSTRING
   18123             :             | TIME
   18124             :             | TIMESTAMP
   18125             :             | TREAT
   18126             :             | TRIM
   18127             :             | VALUES
   18128             :             | VARCHAR
   18129             :             | XMLATTRIBUTES
   18130             :             | XMLCONCAT
   18131             :             | XMLELEMENT
   18132             :             | XMLEXISTS
   18133             :             | XMLFOREST
   18134             :             | XMLNAMESPACES
   18135             :             | XMLPARSE
   18136             :             | XMLPI
   18137             :             | XMLROOT
   18138             :             | XMLSERIALIZE
   18139             :             | XMLTABLE
   18140             :         ;
   18141             : 
   18142             : /* Type/function identifier --- keywords that can be type or function names.
   18143             :  *
   18144             :  * Most of these are keywords that are used as operators in expressions;
   18145             :  * in general such keywords can't be column names because they would be
   18146             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18147             :  *
   18148             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18149             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18150             :  * - thomas 2000-11-28
   18151             :  */
   18152             : type_func_name_keyword:
   18153             :               AUTHORIZATION
   18154             :             | BINARY
   18155             :             | COLLATION
   18156             :             | CONCURRENTLY
   18157             :             | CROSS
   18158             :             | CURRENT_SCHEMA
   18159             :             | FREEZE
   18160             :             | FULL
   18161             :             | ILIKE
   18162             :             | INNER_P
   18163             :             | IS
   18164             :             | ISNULL
   18165             :             | JOIN
   18166             :             | LEFT
   18167             :             | LIKE
   18168             :             | NATURAL
   18169             :             | NOTNULL
   18170             :             | OUTER_P
   18171             :             | OVERLAPS
   18172             :             | RIGHT
   18173             :             | SIMILAR
   18174             :             | TABLESAMPLE
   18175             :             | VERBOSE
   18176             :         ;
   18177             : 
   18178             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18179             :  *
   18180             :  * Keywords appear here if they could not be distinguished from variable,
   18181             :  * type, or function names in some contexts.  Don't put things here unless
   18182             :  * forced to.
   18183             :  */
   18184             : reserved_keyword:
   18185             :               ALL
   18186             :             | ANALYSE
   18187             :             | ANALYZE
   18188             :             | AND
   18189             :             | ANY
   18190             :             | ARRAY
   18191             :             | AS
   18192             :             | ASC
   18193             :             | ASYMMETRIC
   18194             :             | BOTH
   18195             :             | CASE
   18196             :             | CAST
   18197             :             | CHECK
   18198             :             | COLLATE
   18199             :             | COLUMN
   18200             :             | CONSTRAINT
   18201             :             | CREATE
   18202             :             | CURRENT_CATALOG
   18203             :             | CURRENT_DATE
   18204             :             | CURRENT_ROLE
   18205             :             | CURRENT_TIME
   18206             :             | CURRENT_TIMESTAMP
   18207             :             | CURRENT_USER
   18208             :             | DEFAULT
   18209             :             | DEFERRABLE
   18210             :             | DESC
   18211             :             | DISTINCT
   18212             :             | DO
   18213             :             | ELSE
   18214             :             | END_P
   18215             :             | EXCEPT
   18216             :             | FALSE_P
   18217             :             | FETCH
   18218             :             | FOR
   18219             :             | FOREIGN
   18220             :             | FROM
   18221             :             | GRANT
   18222             :             | GROUP_P
   18223             :             | HAVING
   18224             :             | IN_P
   18225             :             | INITIALLY
   18226             :             | INTERSECT
   18227             :             | INTO
   18228             :             | LATERAL_P
   18229             :             | LEADING
   18230             :             | LIMIT
   18231             :             | LOCALTIME
   18232             :             | LOCALTIMESTAMP
   18233             :             | NOT
   18234             :             | NULL_P
   18235             :             | OFFSET
   18236             :             | ON
   18237             :             | ONLY
   18238             :             | OR
   18239             :             | ORDER
   18240             :             | PLACING
   18241             :             | PRIMARY
   18242             :             | REFERENCES
   18243             :             | RETURNING
   18244             :             | SELECT
   18245             :             | SESSION_USER
   18246             :             | SOME
   18247             :             | SYMMETRIC
   18248             :             | SYSTEM_USER
   18249             :             | TABLE
   18250             :             | THEN
   18251             :             | TO
   18252             :             | TRAILING
   18253             :             | TRUE_P
   18254             :             | UNION
   18255             :             | UNIQUE
   18256             :             | USER
   18257             :             | USING
   18258             :             | VARIADIC
   18259             :             | WHEN
   18260             :             | WHERE
   18261             :             | WINDOW
   18262             :             | WITH
   18263             :         ;
   18264             : 
   18265             : /*
   18266             :  * While all keywords can be used as column labels when preceded by AS,
   18267             :  * not all of them can be used as a "bare" column label without AS.
   18268             :  * Those that can be used as a bare label must be listed here,
   18269             :  * in addition to appearing in one of the category lists above.
   18270             :  *
   18271             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18272             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18273             :  */
   18274             : bare_label_keyword:
   18275             :               ABORT_P
   18276             :             | ABSENT
   18277             :             | ABSOLUTE_P
   18278             :             | ACCESS
   18279             :             | ACTION
   18280             :             | ADD_P
   18281             :             | ADMIN
   18282             :             | AFTER
   18283             :             | AGGREGATE
   18284             :             | ALL
   18285             :             | ALSO
   18286             :             | ALTER
   18287             :             | ALWAYS
   18288             :             | ANALYSE
   18289             :             | ANALYZE
   18290             :             | AND
   18291             :             | ANY
   18292             :             | ASC
   18293             :             | ASENSITIVE
   18294             :             | ASSERTION
   18295             :             | ASSIGNMENT
   18296             :             | ASYMMETRIC
   18297             :             | AT
   18298             :             | ATOMIC
   18299             :             | ATTACH
   18300             :             | ATTRIBUTE
   18301             :             | AUTHORIZATION
   18302             :             | BACKWARD
   18303             :             | BEFORE
   18304             :             | BEGIN_P
   18305             :             | BETWEEN
   18306             :             | BIGINT
   18307             :             | BINARY
   18308             :             | BIT
   18309             :             | BOOLEAN_P
   18310             :             | BOTH
   18311             :             | BREADTH
   18312             :             | BY
   18313             :             | CACHE
   18314             :             | CALL
   18315             :             | CALLED
   18316             :             | CASCADE
   18317             :             | CASCADED
   18318             :             | CASE
   18319             :             | CAST
   18320             :             | CATALOG_P
   18321             :             | CHAIN
   18322             :             | CHARACTERISTICS
   18323             :             | CHECK
   18324             :             | CHECKPOINT
   18325             :             | CLASS
   18326             :             | CLOSE
   18327             :             | CLUSTER
   18328             :             | COALESCE
   18329             :             | COLLATE
   18330             :             | COLLATION
   18331             :             | COLUMN
   18332             :             | COLUMNS
   18333             :             | COMMENT
   18334             :             | COMMENTS
   18335             :             | COMMIT
   18336             :             | COMMITTED
   18337             :             | COMPRESSION
   18338             :             | CONCURRENTLY
   18339             :             | CONDITIONAL
   18340             :             | CONFIGURATION
   18341             :             | CONFLICT
   18342             :             | CONNECTION
   18343             :             | CONSTRAINT
   18344             :             | CONSTRAINTS
   18345             :             | CONTENT_P
   18346             :             | CONTINUE_P
   18347             :             | CONVERSION_P
   18348             :             | COPY
   18349             :             | COST
   18350             :             | CROSS
   18351             :             | CSV
   18352             :             | CUBE
   18353             :             | CURRENT_P
   18354             :             | CURRENT_CATALOG
   18355             :             | CURRENT_DATE
   18356             :             | CURRENT_ROLE
   18357             :             | CURRENT_SCHEMA
   18358             :             | CURRENT_TIME
   18359             :             | CURRENT_TIMESTAMP
   18360             :             | CURRENT_USER
   18361             :             | CURSOR
   18362             :             | CYCLE
   18363             :             | DATA_P
   18364             :             | DATABASE
   18365             :             | DEALLOCATE
   18366             :             | DEC
   18367             :             | DECIMAL_P
   18368             :             | DECLARE
   18369             :             | DEFAULT
   18370             :             | DEFAULTS
   18371             :             | DEFERRABLE
   18372             :             | DEFERRED
   18373             :             | DEFINER
   18374             :             | DELETE_P
   18375             :             | DELIMITER
   18376             :             | DELIMITERS
   18377             :             | DEPENDS
   18378             :             | DEPTH
   18379             :             | DESC
   18380             :             | DETACH
   18381             :             | DICTIONARY
   18382             :             | DISABLE_P
   18383             :             | DISCARD
   18384             :             | DISTINCT
   18385             :             | DO
   18386             :             | DOCUMENT_P
   18387             :             | DOMAIN_P
   18388             :             | DOUBLE_P
   18389             :             | DROP
   18390             :             | EACH
   18391             :             | ELSE
   18392             :             | EMPTY_P
   18393             :             | ENABLE_P
   18394             :             | ENCODING
   18395             :             | ENCRYPTED
   18396             :             | END_P
   18397             :             | ENFORCED
   18398             :             | ENUM_P
   18399             :             | ERROR_P
   18400             :             | ESCAPE
   18401             :             | EVENT
   18402             :             | EXCLUDE
   18403             :             | EXCLUDING
   18404             :             | EXCLUSIVE
   18405             :             | EXECUTE
   18406             :             | EXISTS
   18407             :             | EXPLAIN
   18408             :             | EXPRESSION
   18409             :             | EXTENSION
   18410             :             | EXTERNAL
   18411             :             | EXTRACT
   18412             :             | FALSE_P
   18413             :             | FAMILY
   18414             :             | FINALIZE
   18415             :             | FIRST_P
   18416             :             | FLOAT_P
   18417             :             | FOLLOWING
   18418             :             | FORCE
   18419             :             | FOREIGN
   18420             :             | FORMAT
   18421             :             | FORWARD
   18422             :             | FREEZE
   18423             :             | FULL
   18424             :             | FUNCTION
   18425             :             | FUNCTIONS
   18426             :             | GENERATED
   18427             :             | GLOBAL
   18428             :             | GRANTED
   18429             :             | GREATEST
   18430             :             | GROUPING
   18431             :             | GROUPS
   18432             :             | HANDLER
   18433             :             | HEADER_P
   18434             :             | HOLD
   18435             :             | IDENTITY_P
   18436             :             | IF_P
   18437             :             | ILIKE
   18438             :             | IMMEDIATE
   18439             :             | IMMUTABLE
   18440             :             | IMPLICIT_P
   18441             :             | IMPORT_P
   18442             :             | IN_P
   18443             :             | INCLUDE
   18444             :             | INCLUDING
   18445             :             | INCREMENT
   18446             :             | INDENT
   18447             :             | INDEX
   18448             :             | INDEXES
   18449             :             | INHERIT
   18450             :             | INHERITS
   18451             :             | INITIALLY
   18452             :             | INLINE_P
   18453             :             | INNER_P
   18454             :             | INOUT
   18455             :             | INPUT_P
   18456             :             | INSENSITIVE
   18457             :             | INSERT
   18458             :             | INSTEAD
   18459             :             | INT_P
   18460             :             | INTEGER
   18461             :             | INTERVAL
   18462             :             | INVOKER
   18463             :             | IS
   18464             :             | ISOLATION
   18465             :             | JOIN
   18466             :             | JSON
   18467             :             | JSON_ARRAY
   18468             :             | JSON_ARRAYAGG
   18469             :             | JSON_EXISTS
   18470             :             | JSON_OBJECT
   18471             :             | JSON_OBJECTAGG
   18472             :             | JSON_QUERY
   18473             :             | JSON_SCALAR
   18474             :             | JSON_SERIALIZE
   18475             :             | JSON_TABLE
   18476             :             | JSON_VALUE
   18477             :             | KEEP
   18478             :             | KEY
   18479             :             | KEYS
   18480             :             | LABEL
   18481             :             | LANGUAGE
   18482             :             | LARGE_P
   18483             :             | LAST_P
   18484             :             | LATERAL_P
   18485             :             | LEADING
   18486             :             | LEAKPROOF
   18487             :             | LEAST
   18488             :             | LEFT
   18489             :             | LEVEL
   18490             :             | LIKE
   18491             :             | LISTEN
   18492             :             | LOAD
   18493             :             | LOCAL
   18494             :             | LOCALTIME
   18495             :             | LOCALTIMESTAMP
   18496             :             | LOCATION
   18497             :             | LOCK_P
   18498             :             | LOCKED
   18499             :             | LOGGED
   18500             :             | MAPPING
   18501             :             | MATCH
   18502             :             | MATCHED
   18503             :             | MATERIALIZED
   18504             :             | MAXVALUE
   18505             :             | MERGE
   18506             :             | MERGE_ACTION
   18507             :             | METHOD
   18508             :             | MINVALUE
   18509             :             | MODE
   18510             :             | MOVE
   18511             :             | NAME_P
   18512             :             | NAMES
   18513             :             | NATIONAL
   18514             :             | NATURAL
   18515             :             | NCHAR
   18516             :             | NESTED
   18517             :             | NEW
   18518             :             | NEXT
   18519             :             | NFC
   18520             :             | NFD
   18521             :             | NFKC
   18522             :             | NFKD
   18523             :             | NO
   18524             :             | NONE
   18525             :             | NORMALIZE
   18526             :             | NORMALIZED
   18527             :             | NOT
   18528             :             | NOTHING
   18529             :             | NOTIFY
   18530             :             | NOWAIT
   18531             :             | NULL_P
   18532             :             | NULLIF
   18533             :             | NULLS_P
   18534             :             | NUMERIC
   18535             :             | OBJECT_P
   18536             :             | OBJECTS_P
   18537             :             | OF
   18538             :             | OFF
   18539             :             | OIDS
   18540             :             | OLD
   18541             :             | OMIT
   18542             :             | ONLY
   18543             :             | OPERATOR
   18544             :             | OPTION
   18545             :             | OPTIONS
   18546             :             | OR
   18547             :             | ORDINALITY
   18548             :             | OTHERS
   18549             :             | OUT_P
   18550             :             | OUTER_P
   18551             :             | OVERLAY
   18552             :             | OVERRIDING
   18553             :             | OWNED
   18554             :             | OWNER
   18555             :             | PARALLEL
   18556             :             | PARAMETER
   18557             :             | PARSER
   18558             :             | PARTIAL
   18559             :             | PARTITION
   18560             :             | PASSING
   18561             :             | PASSWORD
   18562             :             | PATH
   18563             :             | PERIOD
   18564             :             | PLACING
   18565             :             | PLAN
   18566             :             | PLANS
   18567             :             | POLICY
   18568             :             | POSITION
   18569             :             | PRECEDING
   18570             :             | PREPARE
   18571             :             | PREPARED
   18572             :             | PRESERVE
   18573             :             | PRIMARY
   18574             :             | PRIOR
   18575             :             | PRIVILEGES
   18576             :             | PROCEDURAL
   18577             :             | PROCEDURE
   18578             :             | PROCEDURES
   18579             :             | PROGRAM
   18580             :             | PUBLICATION
   18581             :             | QUOTE
   18582             :             | QUOTES
   18583             :             | RANGE
   18584             :             | READ
   18585             :             | REAL
   18586             :             | REASSIGN
   18587             :             | RECURSIVE
   18588             :             | REF_P
   18589             :             | REFERENCES
   18590             :             | REFERENCING
   18591             :             | REFRESH
   18592             :             | REINDEX
   18593             :             | RELATIVE_P
   18594             :             | RELEASE
   18595             :             | RENAME
   18596             :             | REPEATABLE
   18597             :             | REPLACE
   18598             :             | REPLICA
   18599             :             | RESET
   18600             :             | RESTART
   18601             :             | RESTRICT
   18602             :             | RETURN
   18603             :             | RETURNS
   18604             :             | REVOKE
   18605             :             | RIGHT
   18606             :             | ROLE
   18607             :             | ROLLBACK
   18608             :             | ROLLUP
   18609             :             | ROUTINE
   18610             :             | ROUTINES
   18611             :             | ROW
   18612             :             | ROWS
   18613             :             | RULE
   18614             :             | SAVEPOINT
   18615             :             | SCALAR
   18616             :             | SCHEMA
   18617             :             | SCHEMAS
   18618             :             | SCROLL
   18619             :             | SEARCH
   18620             :             | SECURITY
   18621             :             | SELECT
   18622             :             | SEQUENCE
   18623             :             | SEQUENCES
   18624             :             | SERIALIZABLE
   18625             :             | SERVER
   18626             :             | SESSION
   18627             :             | SESSION_USER
   18628             :             | SET
   18629             :             | SETOF
   18630             :             | SETS
   18631             :             | SHARE
   18632             :             | SHOW
   18633             :             | SIMILAR
   18634             :             | SIMPLE
   18635             :             | SKIP
   18636             :             | SMALLINT
   18637             :             | SNAPSHOT
   18638             :             | SOME
   18639             :             | SOURCE
   18640             :             | SQL_P
   18641             :             | STABLE
   18642             :             | STANDALONE_P
   18643             :             | START
   18644             :             | STATEMENT
   18645             :             | STATISTICS
   18646             :             | STDIN
   18647             :             | STDOUT
   18648             :             | STORAGE
   18649             :             | STORED
   18650             :             | STRICT_P
   18651             :             | STRING_P
   18652             :             | STRIP_P
   18653             :             | SUBSCRIPTION
   18654             :             | SUBSTRING
   18655             :             | SUPPORT
   18656             :             | SYMMETRIC
   18657             :             | SYSID
   18658             :             | SYSTEM_P
   18659             :             | SYSTEM_USER
   18660             :             | TABLE
   18661             :             | TABLES
   18662             :             | TABLESAMPLE
   18663             :             | TABLESPACE
   18664             :             | TARGET
   18665             :             | TEMP
   18666             :             | TEMPLATE
   18667             :             | TEMPORARY
   18668             :             | TEXT_P
   18669             :             | THEN
   18670             :             | TIES
   18671             :             | TIME
   18672             :             | TIMESTAMP
   18673             :             | TRAILING
   18674             :             | TRANSACTION
   18675             :             | TRANSFORM
   18676             :             | TREAT
   18677             :             | TRIGGER
   18678             :             | TRIM
   18679             :             | TRUE_P
   18680             :             | TRUNCATE
   18681             :             | TRUSTED
   18682             :             | TYPE_P
   18683             :             | TYPES_P
   18684             :             | UESCAPE
   18685             :             | UNBOUNDED
   18686             :             | UNCOMMITTED
   18687             :             | UNCONDITIONAL
   18688             :             | UNENCRYPTED
   18689             :             | UNIQUE
   18690             :             | UNKNOWN
   18691             :             | UNLISTEN
   18692             :             | UNLOGGED
   18693             :             | UNTIL
   18694             :             | UPDATE
   18695             :             | USER
   18696             :             | USING
   18697             :             | VACUUM
   18698             :             | VALID
   18699             :             | VALIDATE
   18700             :             | VALIDATOR
   18701             :             | VALUE_P
   18702             :             | VALUES
   18703             :             | VARCHAR
   18704             :             | VARIADIC
   18705             :             | VERBOSE
   18706             :             | VERSION_P
   18707             :             | VIEW
   18708             :             | VIEWS
   18709             :             | VIRTUAL
   18710             :             | VOLATILE
   18711             :             | WHEN
   18712             :             | WHITESPACE_P
   18713             :             | WORK
   18714             :             | WRAPPER
   18715             :             | WRITE
   18716             :             | XML_P
   18717             :             | XMLATTRIBUTES
   18718             :             | XMLCONCAT
   18719             :             | XMLELEMENT
   18720             :             | XMLEXISTS
   18721             :             | XMLFOREST
   18722             :             | XMLNAMESPACES
   18723             :             | XMLPARSE
   18724             :             | XMLPI
   18725             :             | XMLROOT
   18726             :             | XMLSERIALIZE
   18727             :             | XMLTABLE
   18728             :             | YES_P
   18729             :             | ZONE
   18730             :         ;
   18731             : 
   18732             : %%
   18733             : 
   18734             : /*
   18735             :  * The signature of this function is required by bison.  However, we
   18736             :  * ignore the passed yylloc and instead use the last token position
   18737             :  * available from the scanner.
   18738             :  */
   18739             : static void
   18740         696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18741             : {
   18742         696 :     parser_yyerror(msg);
   18743             : }
   18744             : 
   18745             : static RawStmt *
   18746      808892 : makeRawStmt(Node *stmt, int stmt_location)
   18747             : {
   18748      808892 :     RawStmt    *rs = makeNode(RawStmt);
   18749             : 
   18750      808892 :     rs->stmt = stmt;
   18751      808892 :     rs->stmt_location = stmt_location;
   18752      808892 :     rs->stmt_len = 0;            /* might get changed later */
   18753      808892 :     return rs;
   18754             : }
   18755             : 
   18756             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18757             : static void
   18758      579310 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18759             : {
   18760             :     /*
   18761             :      * If we already set the length, don't change it.  This is for situations
   18762             :      * like "select foo ;; select bar" where the same statement will be last
   18763             :      * in the string for more than one semicolon.
   18764             :      */
   18765      579310 :     if (rs->stmt_len > 0)
   18766         642 :         return;
   18767             : 
   18768             :     /* OK, update length of RawStmt */
   18769      578668 :     rs->stmt_len = end_location - rs->stmt_location;
   18770             : }
   18771             : 
   18772             : static Node *
   18773     1798872 : makeColumnRef(char *colname, List *indirection,
   18774             :               int location, core_yyscan_t yyscanner)
   18775             : {
   18776             :     /*
   18777             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18778             :      * any subscripting in the specified indirection list.  However, any field
   18779             :      * selection at the start of the indirection list must be transposed into
   18780             :      * the "fields" part of the ColumnRef node.
   18781             :      */
   18782     1798872 :     ColumnRef  *c = makeNode(ColumnRef);
   18783     1798872 :     int         nfields = 0;
   18784             :     ListCell   *l;
   18785             : 
   18786     1798872 :     c->location = location;
   18787     2846124 :     foreach(l, indirection)
   18788             :     {
   18789     1057150 :         if (IsA(lfirst(l), A_Indices))
   18790             :         {
   18791        9898 :             A_Indirection *i = makeNode(A_Indirection);
   18792             : 
   18793        9898 :             if (nfields == 0)
   18794             :             {
   18795             :                 /* easy case - all indirection goes to A_Indirection */
   18796        7180 :                 c->fields = list_make1(makeString(colname));
   18797        7180 :                 i->indirection = check_indirection(indirection, yyscanner);
   18798             :             }
   18799             :             else
   18800             :             {
   18801             :                 /* got to split the list in two */
   18802        2718 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18803             :                                                                   nfields),
   18804             :                                                    yyscanner);
   18805        2718 :                 indirection = list_truncate(indirection, nfields);
   18806        2718 :                 c->fields = lcons(makeString(colname), indirection);
   18807             :             }
   18808        9898 :             i->arg = (Node *) c;
   18809        9898 :             return (Node *) i;
   18810             :         }
   18811     1047252 :         else if (IsA(lfirst(l), A_Star))
   18812             :         {
   18813             :             /* We only allow '*' at the end of a ColumnRef */
   18814        5514 :             if (lnext(indirection, l) != NULL)
   18815           0 :                 parser_yyerror("improper use of \"*\"");
   18816             :         }
   18817     1047252 :         nfields++;
   18818             :     }
   18819             :     /* No subscripting, so all indirection gets added to field list */
   18820     1788974 :     c->fields = lcons(makeString(colname), indirection);
   18821     1788974 :     return (Node *) c;
   18822             : }
   18823             : 
   18824             : static Node *
   18825      312924 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18826             : {
   18827      312924 :     TypeCast   *n = makeNode(TypeCast);
   18828             : 
   18829      312924 :     n->arg = arg;
   18830      312924 :     n->typeName = typename;
   18831      312924 :     n->location = location;
   18832      312924 :     return (Node *) n;
   18833             : }
   18834             : 
   18835             : static Node *
   18836       16326 : makeStringConstCast(char *str, int location, TypeName *typename)
   18837             : {
   18838       16326 :     Node       *s = makeStringConst(str, location);
   18839             : 
   18840       16326 :     return makeTypeCast(s, typename, -1);
   18841             : }
   18842             : 
   18843             : static Node *
   18844      385278 : makeIntConst(int val, int location)
   18845             : {
   18846      385278 :     A_Const    *n = makeNode(A_Const);
   18847             : 
   18848      385278 :     n->val.ival.type = T_Integer;
   18849      385278 :     n->val.ival.ival = val;
   18850      385278 :     n->location = location;
   18851             : 
   18852      385278 :     return (Node *) n;
   18853             : }
   18854             : 
   18855             : static Node *
   18856       11622 : makeFloatConst(char *str, int location)
   18857             : {
   18858       11622 :     A_Const    *n = makeNode(A_Const);
   18859             : 
   18860       11622 :     n->val.fval.type = T_Float;
   18861       11622 :     n->val.fval.fval = str;
   18862       11622 :     n->location = location;
   18863             : 
   18864       11622 :     return (Node *) n;
   18865             : }
   18866             : 
   18867             : static Node *
   18868       67056 : makeBoolAConst(bool state, int location)
   18869             : {
   18870       67056 :     A_Const    *n = makeNode(A_Const);
   18871             : 
   18872       67056 :     n->val.boolval.type = T_Boolean;
   18873       67056 :     n->val.boolval.boolval = state;
   18874       67056 :     n->location = location;
   18875             : 
   18876       67056 :     return (Node *) n;
   18877             : }
   18878             : 
   18879             : static Node *
   18880        4056 : makeBitStringConst(char *str, int location)
   18881             : {
   18882        4056 :     A_Const    *n = makeNode(A_Const);
   18883             : 
   18884        4056 :     n->val.bsval.type = T_BitString;
   18885        4056 :     n->val.bsval.bsval = str;
   18886        4056 :     n->location = location;
   18887             : 
   18888        4056 :     return (Node *) n;
   18889             : }
   18890             : 
   18891             : static Node *
   18892       66996 : makeNullAConst(int location)
   18893             : {
   18894       66996 :     A_Const    *n = makeNode(A_Const);
   18895             : 
   18896       66996 :     n->isnull = true;
   18897       66996 :     n->location = location;
   18898             : 
   18899       66996 :     return (Node *) n;
   18900             : }
   18901             : 
   18902             : static Node *
   18903        5260 : makeAConst(Node *v, int location)
   18904             : {
   18905             :     Node       *n;
   18906             : 
   18907        5260 :     switch (v->type)
   18908             :     {
   18909         218 :         case T_Float:
   18910         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18911         218 :             break;
   18912             : 
   18913        5042 :         case T_Integer:
   18914        5042 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18915        5042 :             break;
   18916             : 
   18917           0 :         default:
   18918             :             /* currently not used */
   18919             :             Assert(false);
   18920           0 :             n = NULL;
   18921             :     }
   18922             : 
   18923        5260 :     return n;
   18924             : }
   18925             : 
   18926             : /* makeRoleSpec
   18927             :  * Create a RoleSpec with the given type
   18928             :  */
   18929             : static RoleSpec *
   18930       33616 : makeRoleSpec(RoleSpecType type, int location)
   18931             : {
   18932       33616 :     RoleSpec   *spec = makeNode(RoleSpec);
   18933             : 
   18934       33616 :     spec->roletype = type;
   18935       33616 :     spec->location = location;
   18936             : 
   18937       33616 :     return spec;
   18938             : }
   18939             : 
   18940             : /* check_qualified_name --- check the result of qualified_name production
   18941             :  *
   18942             :  * It's easiest to let the grammar production for qualified_name allow
   18943             :  * subscripts and '*', which we then must reject here.
   18944             :  */
   18945             : static void
   18946      243876 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18947             : {
   18948             :     ListCell   *i;
   18949             : 
   18950      487752 :     foreach(i, names)
   18951             :     {
   18952      243876 :         if (!IsA(lfirst(i), String))
   18953           0 :             parser_yyerror("syntax error");
   18954             :     }
   18955      243876 : }
   18956             : 
   18957             : /* check_func_name --- check the result of func_name production
   18958             :  *
   18959             :  * It's easiest to let the grammar production for func_name allow subscripts
   18960             :  * and '*', which we then must reject here.
   18961             :  */
   18962             : static List *
   18963      126056 : check_func_name(List *names, core_yyscan_t yyscanner)
   18964             : {
   18965             :     ListCell   *i;
   18966             : 
   18967      378168 :     foreach(i, names)
   18968             :     {
   18969      252112 :         if (!IsA(lfirst(i), String))
   18970           0 :             parser_yyerror("syntax error");
   18971             :     }
   18972      126056 :     return names;
   18973             : }
   18974             : 
   18975             : /* check_indirection --- check the result of indirection production
   18976             :  *
   18977             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18978             :  * in the grammar, so do it here.
   18979             :  */
   18980             : static List *
   18981       82628 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18982             : {
   18983             :     ListCell   *l;
   18984             : 
   18985      110224 :     foreach(l, indirection)
   18986             :     {
   18987       27596 :         if (IsA(lfirst(l), A_Star))
   18988             :         {
   18989        1458 :             if (lnext(indirection, l) != NULL)
   18990           0 :                 parser_yyerror("improper use of \"*\"");
   18991             :         }
   18992             :     }
   18993       82628 :     return indirection;
   18994             : }
   18995             : 
   18996             : /* extractArgTypes()
   18997             :  * Given a list of FunctionParameter nodes, extract a list of just the
   18998             :  * argument types (TypeNames) for input parameters only.  This is what
   18999             :  * is needed to look up an existing function, which is what is wanted by
   19000             :  * the productions that use this call.
   19001             :  */
   19002             : static List *
   19003       18338 : extractArgTypes(List *parameters)
   19004             : {
   19005       18338 :     List       *result = NIL;
   19006             :     ListCell   *i;
   19007             : 
   19008       42032 :     foreach(i, parameters)
   19009             :     {
   19010       23694 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19011             : 
   19012       23694 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19013       23538 :             result = lappend(result, p->argType);
   19014             :     }
   19015       18338 :     return result;
   19016             : }
   19017             : 
   19018             : /* extractAggrArgTypes()
   19019             :  * As above, but work from the output of the aggr_args production.
   19020             :  */
   19021             : static List *
   19022         362 : extractAggrArgTypes(List *aggrargs)
   19023             : {
   19024             :     Assert(list_length(aggrargs) == 2);
   19025         362 :     return extractArgTypes((List *) linitial(aggrargs));
   19026             : }
   19027             : 
   19028             : /* makeOrderedSetArgs()
   19029             :  * Build the result of the aggr_args production (which see the comments for).
   19030             :  * This handles only the case where both given lists are nonempty, so that
   19031             :  * we have to deal with multiple VARIADIC arguments.
   19032             :  */
   19033             : static List *
   19034          32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19035             :                    core_yyscan_t yyscanner)
   19036             : {
   19037          32 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19038             :     Integer    *ndirectargs;
   19039             : 
   19040             :     /* No restriction unless last direct arg is VARIADIC */
   19041          32 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19042             :     {
   19043          16 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19044             : 
   19045             :         /*
   19046             :          * We ignore the names, though the aggr_arg production allows them; it
   19047             :          * doesn't allow default values, so those need not be checked.
   19048             :          */
   19049          16 :         if (list_length(orderedargs) != 1 ||
   19050          16 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19051          16 :             !equal(lastd->argType, firsto->argType))
   19052           0 :             ereport(ERROR,
   19053             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19054             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19055             :                      parser_errposition(firsto->location)));
   19056             : 
   19057             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19058          16 :         orderedargs = NIL;
   19059             :     }
   19060             : 
   19061             :     /* don't merge into the next line, as list_concat changes directargs */
   19062          32 :     ndirectargs = makeInteger(list_length(directargs));
   19063             : 
   19064          32 :     return list_make2(list_concat(directargs, orderedargs),
   19065             :                       ndirectargs);
   19066             : }
   19067             : 
   19068             : /* insertSelectOptions()
   19069             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19070             :  *
   19071             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19072             :  */
   19073             : static void
   19074       82928 : insertSelectOptions(SelectStmt *stmt,
   19075             :                     List *sortClause, List *lockingClause,
   19076             :                     SelectLimit *limitClause,
   19077             :                     WithClause *withClause,
   19078             :                     core_yyscan_t yyscanner)
   19079             : {
   19080             :     Assert(IsA(stmt, SelectStmt));
   19081             : 
   19082             :     /*
   19083             :      * Tests here are to reject constructs like
   19084             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19085             :      */
   19086       82928 :     if (sortClause)
   19087             :     {
   19088       73582 :         if (stmt->sortClause)
   19089           0 :             ereport(ERROR,
   19090             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19091             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19092             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19093       73582 :         stmt->sortClause = sortClause;
   19094             :     }
   19095             :     /* We can handle multiple locking clauses, though */
   19096       82928 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19097       82928 :     if (limitClause && limitClause->limitOffset)
   19098             :     {
   19099         844 :         if (stmt->limitOffset)
   19100           0 :             ereport(ERROR,
   19101             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19102             :                      errmsg("multiple OFFSET clauses not allowed"),
   19103             :                      parser_errposition(limitClause->offsetLoc)));
   19104         844 :         stmt->limitOffset = limitClause->limitOffset;
   19105             :     }
   19106       82928 :     if (limitClause && limitClause->limitCount)
   19107             :     {
   19108        4698 :         if (stmt->limitCount)
   19109           0 :             ereport(ERROR,
   19110             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19111             :                      errmsg("multiple LIMIT clauses not allowed"),
   19112             :                      parser_errposition(limitClause->countLoc)));
   19113        4698 :         stmt->limitCount = limitClause->limitCount;
   19114             :     }
   19115       82928 :     if (limitClause)
   19116             :     {
   19117             :         /* If there was a conflict, we must have detected it above */
   19118             :         Assert(!stmt->limitOption);
   19119        5148 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19120           6 :             ereport(ERROR,
   19121             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19122             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19123             :                      parser_errposition(limitClause->optionLoc)));
   19124        5142 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19125             :         {
   19126             :             ListCell   *lc;
   19127             : 
   19128           6 :             foreach(lc, stmt->lockingClause)
   19129             :             {
   19130           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19131             : 
   19132           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19133           6 :                     ereport(ERROR,
   19134             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19135             :                              errmsg("%s and %s options cannot be used together",
   19136             :                                     "SKIP LOCKED", "WITH TIES"),
   19137             :                              parser_errposition(limitClause->optionLoc)));
   19138             :             }
   19139             :         }
   19140        5136 :         stmt->limitOption = limitClause->limitOption;
   19141             :     }
   19142       82916 :     if (withClause)
   19143             :     {
   19144        2866 :         if (stmt->withClause)
   19145           0 :             ereport(ERROR,
   19146             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19147             :                      errmsg("multiple WITH clauses not allowed"),
   19148             :                      parser_errposition(exprLocation((Node *) withClause))));
   19149        2866 :         stmt->withClause = withClause;
   19150             :     }
   19151       82916 : }
   19152             : 
   19153             : static Node *
   19154       19300 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   19155             : {
   19156       19300 :     SelectStmt *n = makeNode(SelectStmt);
   19157             : 
   19158       19300 :     n->op = op;
   19159       19300 :     n->all = all;
   19160       19300 :     n->larg = (SelectStmt *) larg;
   19161       19300 :     n->rarg = (SelectStmt *) rarg;
   19162       19300 :     return (Node *) n;
   19163             : }
   19164             : 
   19165             : /* SystemFuncName()
   19166             :  * Build a properly-qualified reference to a built-in function.
   19167             :  */
   19168             : List *
   19169       19146 : SystemFuncName(char *name)
   19170             : {
   19171       19146 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19172             : }
   19173             : 
   19174             : /* SystemTypeName()
   19175             :  * Build a properly-qualified reference to a built-in type.
   19176             :  *
   19177             :  * typmod is defaulted, but may be changed afterwards by caller.
   19178             :  * Likewise for the location.
   19179             :  */
   19180             : TypeName *
   19181      120720 : SystemTypeName(char *name)
   19182             : {
   19183      120720 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19184             :                                                makeString(name)));
   19185             : }
   19186             : 
   19187             : /* doNegate()
   19188             :  * Handle negation of a numeric constant.
   19189             :  *
   19190             :  * Formerly, we did this here because the optimizer couldn't cope with
   19191             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19192             :  * and a unary minus operator applied to a constant didn't qualify.
   19193             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19194             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19195             :  * there's still a good reason for doing this here, which is that we can
   19196             :  * postpone committing to a particular internal representation for simple
   19197             :  * negative constants.  It's better to leave "-123.456" in string form
   19198             :  * until we know what the desired type is.
   19199             :  */
   19200             : static Node *
   19201        9252 : doNegate(Node *n, int location)
   19202             : {
   19203        9252 :     if (IsA(n, A_Const))
   19204             :     {
   19205        8242 :         A_Const    *con = (A_Const *) n;
   19206             : 
   19207             :         /* report the constant's location as that of the '-' sign */
   19208        8242 :         con->location = location;
   19209             : 
   19210        8242 :         if (IsA(&con->val, Integer))
   19211             :         {
   19212        7284 :             con->val.ival.ival = -con->val.ival.ival;
   19213        7284 :             return n;
   19214             :         }
   19215         958 :         if (IsA(&con->val, Float))
   19216             :         {
   19217         958 :             doNegateFloat(&con->val.fval);
   19218         958 :             return n;
   19219             :         }
   19220             :     }
   19221             : 
   19222        1010 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19223             : }
   19224             : 
   19225             : static void
   19226         978 : doNegateFloat(Float *v)
   19227             : {
   19228         978 :     char       *oldval = v->fval;
   19229             : 
   19230         978 :     if (*oldval == '+')
   19231           0 :         oldval++;
   19232         978 :     if (*oldval == '-')
   19233           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19234             :     else
   19235         978 :         v->fval = psprintf("-%s", oldval);
   19236         978 : }
   19237             : 
   19238             : static Node *
   19239      232330 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19240             : {
   19241             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19242      232330 :     if (IsA(lexpr, BoolExpr))
   19243             :     {
   19244      110432 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19245             : 
   19246      110432 :         if (blexpr->boolop == AND_EXPR)
   19247             :         {
   19248      107912 :             blexpr->args = lappend(blexpr->args, rexpr);
   19249      107912 :             return (Node *) blexpr;
   19250             :         }
   19251             :     }
   19252      124418 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19253             : }
   19254             : 
   19255             : static Node *
   19256       16002 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19257             : {
   19258             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19259       16002 :     if (IsA(lexpr, BoolExpr))
   19260             :     {
   19261        5638 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19262             : 
   19263        5638 :         if (blexpr->boolop == OR_EXPR)
   19264             :         {
   19265        4132 :             blexpr->args = lappend(blexpr->args, rexpr);
   19266        4132 :             return (Node *) blexpr;
   19267             :         }
   19268             :     }
   19269       11870 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19270             : }
   19271             : 
   19272             : static Node *
   19273       16226 : makeNotExpr(Node *expr, int location)
   19274             : {
   19275       16226 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19276             : }
   19277             : 
   19278             : static Node *
   19279        8132 : makeAArrayExpr(List *elements, int location, int location_end)
   19280             : {
   19281        8132 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19282             : 
   19283        8132 :     n->elements = elements;
   19284        8132 :     n->location = location;
   19285        8132 :     n->list_start = location;
   19286        8132 :     n->list_end = location_end;
   19287        8132 :     return (Node *) n;
   19288             : }
   19289             : 
   19290             : static Node *
   19291        2732 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19292             : {
   19293        2732 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19294             : 
   19295        2732 :     svf->op = op;
   19296             :     /* svf->type will be filled during parse analysis */
   19297        2732 :     svf->typmod = typmod;
   19298        2732 :     svf->location = location;
   19299        2732 :     return (Node *) svf;
   19300             : }
   19301             : 
   19302             : static Node *
   19303         596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19304             :             int location)
   19305             : {
   19306         596 :     XmlExpr    *x = makeNode(XmlExpr);
   19307             : 
   19308         596 :     x->op = op;
   19309         596 :     x->name = name;
   19310             : 
   19311             :     /*
   19312             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19313             :      * expression and name lists in transformXmlExpr().
   19314             :      */
   19315         596 :     x->named_args = named_args;
   19316         596 :     x->arg_names = NIL;
   19317         596 :     x->args = args;
   19318             :     /* xmloption, if relevant, must be filled in by caller */
   19319             :     /* type and typmod will be filled in during parse analysis */
   19320         596 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19321         596 :     x->location = location;
   19322         596 :     return (Node *) x;
   19323             : }
   19324             : 
   19325             : /*
   19326             :  * Merge the input and output parameters of a table function.
   19327             :  */
   19328             : static List *
   19329         194 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19330             : {
   19331             :     ListCell   *lc;
   19332             : 
   19333             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19334         394 :     foreach(lc, func_args)
   19335             :     {
   19336         200 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19337             : 
   19338         200 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19339           0 :             p->mode != FUNC_PARAM_IN &&
   19340           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19341           0 :             ereport(ERROR,
   19342             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19343             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19344             :                      parser_errposition(p->location)));
   19345             :     }
   19346             : 
   19347         194 :     return list_concat(func_args, columns);
   19348             : }
   19349             : 
   19350             : /*
   19351             :  * Determine return type of a TABLE function.  A single result column
   19352             :  * returns setof that column's type; otherwise return setof record.
   19353             :  */
   19354             : static TypeName *
   19355         194 : TableFuncTypeName(List *columns)
   19356             : {
   19357             :     TypeName   *result;
   19358             : 
   19359         194 :     if (list_length(columns) == 1)
   19360             :     {
   19361          62 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19362             : 
   19363          62 :         result = copyObject(p->argType);
   19364             :     }
   19365             :     else
   19366         132 :         result = SystemTypeName("record");
   19367             : 
   19368         194 :     result->setof = true;
   19369             : 
   19370         194 :     return result;
   19371             : }
   19372             : 
   19373             : /*
   19374             :  * Convert a list of (dotted) names to a RangeVar (like
   19375             :  * makeRangeVarFromNameList, but with position support).  The
   19376             :  * "AnyName" refers to the any_name production in the grammar.
   19377             :  */
   19378             : static RangeVar *
   19379        4736 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19380             : {
   19381        4736 :     RangeVar   *r = makeNode(RangeVar);
   19382             : 
   19383        4736 :     switch (list_length(names))
   19384             :     {
   19385        4646 :         case 1:
   19386        4646 :             r->catalogname = NULL;
   19387        4646 :             r->schemaname = NULL;
   19388        4646 :             r->relname = strVal(linitial(names));
   19389        4646 :             break;
   19390          90 :         case 2:
   19391          90 :             r->catalogname = NULL;
   19392          90 :             r->schemaname = strVal(linitial(names));
   19393          90 :             r->relname = strVal(lsecond(names));
   19394          90 :             break;
   19395           0 :         case 3:
   19396           0 :             r->catalogname = strVal(linitial(names));
   19397           0 :             r->schemaname = strVal(lsecond(names));
   19398           0 :             r->relname = strVal(lthird(names));
   19399           0 :             break;
   19400           0 :         default:
   19401           0 :             ereport(ERROR,
   19402             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19403             :                      errmsg("improper qualified name (too many dotted names): %s",
   19404             :                             NameListToString(names)),
   19405             :                      parser_errposition(position)));
   19406             :             break;
   19407             :     }
   19408             : 
   19409        4736 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19410        4736 :     r->location = position;
   19411             : 
   19412        4736 :     return r;
   19413             : }
   19414             : 
   19415             : /*
   19416             :  * Convert a relation_name with name and namelist to a RangeVar using
   19417             :  * makeRangeVar.
   19418             :  */
   19419             : static RangeVar *
   19420      243876 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19421             :                               core_yyscan_t yyscanner)
   19422             : {
   19423             :     RangeVar   *r;
   19424             : 
   19425      243876 :     check_qualified_name(namelist, yyscanner);
   19426      243876 :     r = makeRangeVar(NULL, NULL, location);
   19427             : 
   19428      243876 :     switch (list_length(namelist))
   19429             :     {
   19430      243876 :         case 1:
   19431      243876 :             r->catalogname = NULL;
   19432      243876 :             r->schemaname = name;
   19433      243876 :             r->relname = strVal(linitial(namelist));
   19434      243876 :             break;
   19435           0 :         case 2:
   19436           0 :             r->catalogname = name;
   19437           0 :             r->schemaname = strVal(linitial(namelist));
   19438           0 :             r->relname = strVal(lsecond(namelist));
   19439           0 :             break;
   19440           0 :         default:
   19441           0 :             ereport(ERROR,
   19442             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19443             :                     errmsg("improper qualified name (too many dotted names): %s",
   19444             :                            NameListToString(lcons(makeString(name), namelist))),
   19445             :                     parser_errposition(location));
   19446             :             break;
   19447             :     }
   19448             : 
   19449      243876 :     return r;
   19450             : }
   19451             : 
   19452             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19453             : static void
   19454       69342 : SplitColQualList(List *qualList,
   19455             :                  List **constraintList, CollateClause **collClause,
   19456             :                  core_yyscan_t yyscanner)
   19457             : {
   19458             :     ListCell   *cell;
   19459             : 
   19460       69342 :     *collClause = NULL;
   19461       89146 :     foreach(cell, qualList)
   19462             :     {
   19463       19804 :         Node       *n = (Node *) lfirst(cell);
   19464             : 
   19465       19804 :         if (IsA(n, Constraint))
   19466             :         {
   19467             :             /* keep it in list */
   19468       19042 :             continue;
   19469             :         }
   19470         762 :         if (IsA(n, CollateClause))
   19471             :         {
   19472         762 :             CollateClause *c = (CollateClause *) n;
   19473             : 
   19474         762 :             if (*collClause)
   19475           0 :                 ereport(ERROR,
   19476             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19477             :                          errmsg("multiple COLLATE clauses not allowed"),
   19478             :                          parser_errposition(c->location)));
   19479         762 :             *collClause = c;
   19480             :         }
   19481             :         else
   19482           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19483             :         /* remove non-Constraint nodes from qualList */
   19484         762 :         qualList = foreach_delete_current(qualList, cell);
   19485             :     }
   19486       69342 :     *constraintList = qualList;
   19487       69342 : }
   19488             : 
   19489             : /*
   19490             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19491             :  * in the output command node.  Pass NULL for any flags the particular
   19492             :  * command doesn't support.
   19493             :  */
   19494             : static void
   19495       17792 : processCASbits(int cas_bits, int location, const char *constrType,
   19496             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19497             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19498             : {
   19499             :     /* defaults */
   19500       17792 :     if (deferrable)
   19501       15734 :         *deferrable = false;
   19502       17792 :     if (initdeferred)
   19503       15734 :         *initdeferred = false;
   19504       17792 :     if (not_valid)
   19505        3836 :         *not_valid = false;
   19506       17792 :     if (is_enforced)
   19507        3364 :         *is_enforced = true;
   19508             : 
   19509       17792 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19510             :     {
   19511         230 :         if (deferrable)
   19512         230 :             *deferrable = true;
   19513             :         else
   19514           0 :             ereport(ERROR,
   19515             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19516             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19517             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19518             :                             constrType),
   19519             :                      parser_errposition(location)));
   19520             :     }
   19521             : 
   19522       17792 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19523             :     {
   19524         146 :         if (initdeferred)
   19525         146 :             *initdeferred = true;
   19526             :         else
   19527           0 :             ereport(ERROR,
   19528             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19529             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19530             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19531             :                             constrType),
   19532             :                      parser_errposition(location)));
   19533             :     }
   19534             : 
   19535       17792 :     if (cas_bits & CAS_NOT_VALID)
   19536             :     {
   19537         708 :         if (not_valid)
   19538         708 :             *not_valid = true;
   19539             :         else
   19540           0 :             ereport(ERROR,
   19541             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19542             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19543             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19544             :                             constrType),
   19545             :                      parser_errposition(location)));
   19546             :     }
   19547             : 
   19548       17792 :     if (cas_bits & CAS_NO_INHERIT)
   19549             :     {
   19550         244 :         if (no_inherit)
   19551         244 :             *no_inherit = true;
   19552             :         else
   19553           0 :             ereport(ERROR,
   19554             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19555             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19556             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19557             :                             constrType),
   19558             :                      parser_errposition(location)));
   19559             :     }
   19560             : 
   19561       17792 :     if (cas_bits & CAS_NOT_ENFORCED)
   19562             :     {
   19563         156 :         if (is_enforced)
   19564         150 :             *is_enforced = false;
   19565             :         else
   19566           6 :             ereport(ERROR,
   19567             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19568             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19569             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19570             :                             constrType),
   19571             :                      parser_errposition(location)));
   19572             : 
   19573             :         /*
   19574             :          * NB: The validated status is irrelevant when the constraint is set to
   19575             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19576             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19577             :          * will automatically be in the correct NOT VALIDATED state.
   19578             :          */
   19579         150 :         if (not_valid)
   19580         114 :             *not_valid = true;
   19581             :     }
   19582             : 
   19583       17786 :     if (cas_bits & CAS_ENFORCED)
   19584             :     {
   19585         102 :         if (is_enforced)
   19586          96 :             *is_enforced = true;
   19587             :         else
   19588           6 :             ereport(ERROR,
   19589             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19590             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19591             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19592             :                             constrType),
   19593             :                      parser_errposition(location)));
   19594             :     }
   19595       17780 : }
   19596             : 
   19597             : /*
   19598             :  * Parse a user-supplied partition strategy string into parse node
   19599             :  * PartitionStrategy representation, or die trying.
   19600             :  */
   19601             : static PartitionStrategy
   19602        5034 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19603             : {
   19604        5034 :     if (pg_strcasecmp(strategy, "list") == 0)
   19605        2540 :         return PARTITION_STRATEGY_LIST;
   19606        2494 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19607        2228 :         return PARTITION_STRATEGY_RANGE;
   19608         266 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19609         260 :         return PARTITION_STRATEGY_HASH;
   19610             : 
   19611           6 :     ereport(ERROR,
   19612             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19613             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19614             :              parser_errposition(location)));
   19615             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19616             : 
   19617             : }
   19618             : 
   19619             : /*
   19620             :  * Process pubobjspec_list to check for errors in any of the objects and
   19621             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19622             :  */
   19623             : static void
   19624        1644 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19625             : {
   19626             :     ListCell   *cell;
   19627             :     PublicationObjSpec *pubobj;
   19628        1644 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19629             : 
   19630        1644 :     if (!pubobjspec_list)
   19631           0 :         return;
   19632             : 
   19633        1644 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19634        1644 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19635          12 :         ereport(ERROR,
   19636             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19637             :                 errmsg("invalid publication object list"),
   19638             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19639             :                 parser_errposition(pubobj->location));
   19640             : 
   19641        3494 :     foreach(cell, pubobjspec_list)
   19642             :     {
   19643        1886 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19644             : 
   19645        1886 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19646         174 :             pubobj->pubobjtype = prevobjtype;
   19647             : 
   19648        1886 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19649             :         {
   19650             :             /* relation name or pubtable must be set for this type of object */
   19651        1442 :             if (!pubobj->name && !pubobj->pubtable)
   19652           6 :                 ereport(ERROR,
   19653             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19654             :                         errmsg("invalid table name"),
   19655             :                         parser_errposition(pubobj->location));
   19656             : 
   19657        1436 :             if (pubobj->name)
   19658             :             {
   19659             :                 /* convert it to PublicationTable */
   19660          58 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19661             : 
   19662          58 :                 pubtable->relation =
   19663          58 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19664          58 :                 pubobj->pubtable = pubtable;
   19665          58 :                 pubobj->name = NULL;
   19666             :             }
   19667             :         }
   19668         444 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19669          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19670             :         {
   19671             :             /* WHERE clause is not allowed on a schema object */
   19672         444 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19673           6 :                 ereport(ERROR,
   19674             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19675             :                         errmsg("WHERE clause not allowed for schema"),
   19676             :                         parser_errposition(pubobj->location));
   19677             : 
   19678             :             /* Column list is not allowed on a schema object */
   19679         438 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19680           6 :                 ereport(ERROR,
   19681             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19682             :                         errmsg("column specification not allowed for schema"),
   19683             :                         parser_errposition(pubobj->location));
   19684             : 
   19685             :             /*
   19686             :              * We can distinguish between the different type of schema objects
   19687             :              * based on whether name and pubtable is set.
   19688             :              */
   19689         432 :             if (pubobj->name)
   19690         402 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19691          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19692          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19693             :             else
   19694           6 :                 ereport(ERROR,
   19695             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19696             :                         errmsg("invalid schema name"),
   19697             :                         parser_errposition(pubobj->location));
   19698             :         }
   19699             : 
   19700        1862 :         prevobjtype = pubobj->pubobjtype;
   19701             :     }
   19702             : }
   19703             : 
   19704             : /*----------
   19705             :  * Recursive view transformation
   19706             :  *
   19707             :  * Convert
   19708             :  *
   19709             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19710             :  *
   19711             :  * to
   19712             :  *
   19713             :  *     CREATE VIEW relname (aliases) AS
   19714             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19715             :  *         SELECT aliases FROM relname
   19716             :  *
   19717             :  * Actually, just the WITH ... part, which is then inserted into the original
   19718             :  * view definition as the query.
   19719             :  * ----------
   19720             :  */
   19721             : static Node *
   19722          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19723             : {
   19724          14 :     SelectStmt *s = makeNode(SelectStmt);
   19725          14 :     WithClause *w = makeNode(WithClause);
   19726          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19727          14 :     List       *tl = NIL;
   19728             :     ListCell   *lc;
   19729             : 
   19730             :     /* create common table expression */
   19731          14 :     cte->ctename = relname;
   19732          14 :     cte->aliascolnames = aliases;
   19733          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19734          14 :     cte->ctequery = query;
   19735          14 :     cte->location = -1;
   19736             : 
   19737             :     /* create WITH clause and attach CTE */
   19738          14 :     w->recursive = true;
   19739          14 :     w->ctes = list_make1(cte);
   19740          14 :     w->location = -1;
   19741             : 
   19742             :     /*
   19743             :      * create target list for the new SELECT from the alias list of the
   19744             :      * recursive view specification
   19745             :      */
   19746          28 :     foreach(lc, aliases)
   19747             :     {
   19748          14 :         ResTarget  *rt = makeNode(ResTarget);
   19749             : 
   19750          14 :         rt->name = NULL;
   19751          14 :         rt->indirection = NIL;
   19752          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19753          14 :         rt->location = -1;
   19754             : 
   19755          14 :         tl = lappend(tl, rt);
   19756             :     }
   19757             : 
   19758             :     /*
   19759             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19760             :      * clause
   19761             :      */
   19762          14 :     s->withClause = w;
   19763          14 :     s->targetList = tl;
   19764          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19765             : 
   19766          14 :     return (Node *) s;
   19767             : }
   19768             : 
   19769             : /* parser_init()
   19770             :  * Initialize to parse one query string
   19771             :  */
   19772             : void
   19773      762774 : parser_init(base_yy_extra_type *yyext)
   19774             : {
   19775      762774 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19776      762774 : }

Generated by: LCOV version 1.16